示例#1
0
    def on_initCardButton_clicked(self):
        if not self._check_connection():
            return
        try:
            self.log("\n" + self.tr("Initialize the participant card"))

            card_num = self.ui.sbCardNumber.value()

            if (card_num < Sportiduino.MIN_CARD_NUM
                    or card_num > Sportiduino.MAX_CARD_NUM):
                raise Exception(self.tr("Incorrect card number"))

            enable_fast_punch = False
            if self.ui.cbFastPunchCard.isChecked():
                enable_fast_punch = True
            code, data = self.sportiduino.init_card(
                card_num, fast_punch=enable_fast_punch)
            if code == Sportiduino.RESP_OK:
                self.log(
                    self.
                    tr("The participant card No {} ({}) has been initialized successfully"
                       ).format(card_num, Sportiduino.card_name(data[0])))
                if self.ui.cbAutoIncriment.isChecked():
                    self.ui.sbCardNumber.setValue(card_num + 1)

        except Exception as err:
            self._process_error(err)
示例#2
0
    def InitCard_clicked(self):
        if not self._check_connection():
            return
        try:
            self.log("\n" + self.tr("Initialize the participant card"))

            card_num = 0
            text = self.ui.cardLine.text()
            if (text.isdigit()):
                card_num = int(text)

            if (card_num < Sportiduino.MIN_CARD_NUM
                    or card_num > Sportiduino.MAX_CARD_NUM):
                raise Exception(self.tr("Incorrect card number"))

            code, data = self.sportiduino.init_card(card_num)
            if code == Sportiduino.RESP_OK:
                self.log(
                    self.
                    tr("The participant card N{} ({}) has been initialized successfully"
                       ).format(card_num, Sportiduino.card_name(data[0])))

            if self.ui.AutoIncriment.isChecked():
                self.ui.cardLine.setText(str(card_num + 1))

        except Exception as err:
            self._process_error(err)
            raise err
示例#3
0
    def _show_card_data(self, data, card_type=None):
        if self.ui.AutoPrint.isChecked():
            self.ClearText_clicked()

        text = []
        if card_type is not None:
            card_name = Sportiduino.card_name(card_type)
            text.append(card_name)

        if 'master_card_flag' in data:
            # show master card info
            master_type = int2byte(data['master_card_type'])

            if master_type == Sportiduino.MASTER_CARD_GET_STATE:
                text.append(
                    self.tr("Master card to get info about a base station"))
            elif master_type == Sportiduino.MASTER_CARD_SET_TIME:
                text.append(
                    self.tr("Master card to set time of a base station"))
            elif master_type == Sportiduino.MASTER_CARD_SET_NUMBER:
                text.append(
                    self.tr("Master card to set number of a base station"))
            elif master_type == Sportiduino.MASTER_CARD_SLEEP:
                text.append(self.tr("Master card to sleep a base station"))
            elif master_type == Sportiduino.MASTER_CARD_READ_BACKUP:
                text.append(
                    self.tr(
                        "Master card to get punches log of a base station"))
            elif master_type == Sportiduino.MASTER_CARD_SET_PASS:
                text.append(
                    self.
                    tr("Master card to write password and settings to a base station"
                       ))
            else:
                text.append(self.tr("Uninitialized card"))

        else:
            # show participant card info
            card_number = data['card_number']
            init_time = -1
            if 'init_timestamp' in data:
                init_time = (data['init_timestamp'])

            if init_time != 0 and card_number >= Sportiduino.MIN_CARD_NUM and card_number <= Sportiduino.MAX_CARD_NUM:
                punches_count = 0

                text.append(
                    self.tr("Participant card No {}").format(card_number))
                if init_time > 0:
                    text.append(
                        self.tr("Init time {}").format(
                            datetime.fromtimestamp(init_time)))

                text.append(self.tr("Punches (Check point - Time):"))
                punch_str = "{:>5} - {}"
                if 'start' in data:
                    text.append(
                        punch_str.format(self.tr("Start"), data["start"]))

                punches = data['punches']
                for punch in punches:
                    punches_count += 1

                    cp = punch[0]
                    cp_time = punch[1]

                    text.append(punch_str.format(cp, cp_time))

                if 'finish' in data:
                    text.append(
                        punch_str.format(self.tr("Finish"), data["finish"]))

                if punches_count == 0:
                    text.append(self.tr("No punches"))
                else:
                    text.append(
                        self.tr("Total punches {}").format(punches_count))
            else:
                text.append(self.tr("Uninitialized card"))

        self.log('\n'.join(text))

        if self.ui.AutoPrint.isChecked():
            self.Print_clicked()