Beispiel #1
0
    def ReadInfo_clicked(self):
        if not self._check_connection():
            return

        try:
            self.log("\n" +
                     self.tr("Read the card contained a base station state"))

            state = self.sportiduino.read_state_card()

            bs_state = BaseStation.State()
            bs_state.version = Sportiduino.Version(*state['version'])
            bs_state.config = BaseStation.Config.unpack(state['config'])

            bs_state.battery = BaseStation.Battery(state['battery'])
            bs_state.mode = state['mode']

            bs_state.timestamp = state['timestamp']
            bs_state.wakeuptime = state['wakeuptime']

            self._show_base_station_state(bs_state)

        except Exception as err:
            self._process_error(err)
            raise err
Beispiel #2
0
    def on_eraseLogButton_clicked(self):
        try:
            if QMessageBox.question(
                    self, self.tr('Erase log'),
                    self.
                    tr('Are you sure you want to erase the base station log permanently?'
                       )) != QMessageBox.Yes:
                return
            self.log("\n" + self.tr("Erase log of a base station by UART"))
            port = self.ui.cbUartPort.currentText()
            BaseStation.erase_log_by_serial(port)
            self.log(self.tr("Log has been erased successfully"))

        except Exception as err:
            self._process_error(err)
Beispiel #3
0
    def SerialWrite_clicked(self):
        try:
            self.log("\n" + self.tr(
                "Writes settings and password to a base station by UART"))
            port = self.ui.cbUartPort.currentText()

            bs_config = self._get_config_from_ui()
            bs_config.num = self.ui.sbStationNumByUart.value()
            wakeuptime = self._get_competion_datetime().toPyDateTime()

            password = (self.ui.sbCurPwd1.value(), self.ui.sbCurPwd2.value(),
                        self.ui.sbCurPwd3.value())
            BaseStation.write_settings_by_serial(port, password, bs_config,
                                                 wakeuptime)

            self.log(
                self.tr("Settings and password has been written successfully"))

        except Exception as err:
            self._process_error(err)
Beispiel #4
0
    def SerialRead_clicked(self):
        try:
            self.log("\n" + self.tr("Reads info about a base station by UART"))

            port = self.ui.cbUartPort.currentText()
            password = (self.ui.sbCurPwd1.value(), self.ui.sbCurPwd2.value(),
                        self.ui.sbCurPwd3.value())

            bs_state = BaseStation.read_info_by_serial(port, password)

            self._show_base_station_state(bs_state)

        except Exception as err:
            self._process_error(err)
Beispiel #5
0
    def _get_config_from_ui(self):
        bs_config = BaseStation.Config()
        bs_config.active_mode_duration = self.ui.cbActiveTime.currentIndex()
        bs_config.check_start_finish = self.ui.cbStartFinish.isChecked()
        bs_config.check_card_init_time = self.ui.cbCheckInitTime.isChecked()
        bs_config.fast_punch = self.ui.cbFastPunch.isChecked()
        bs_config.antenna_gain = self.ui.cbAntennaGain.currentIndex() + 2
        bs_config.password = [
            self.ui.sbNewPwd1.value(),
            self.ui.sbNewPwd2.value(),
            self.ui.sbNewPwd3.value()
        ]

        return bs_config
Beispiel #6
0
    def __init__(self, config):
        super().__init__()
        self.ui = design.Ui_MainWindow()
        self.ui.setupUi(self)

        self.setWindowTitle(
            "SportiduinoPQ {}".format(sportiduinopq_version_string))

        self.config = config
        geometry = self.config.value('geometry')
        if geometry is not None:
            self.restoreGeometry(geometry)

        self.connected = False

        self.printer = QPrinter()
        printer_name = config.value('printer/name', self.printer.printerName())
        self.printer.setPrinterName(printer_name)
        outputfilename = config.value('printer/outputfilename',
                                      self.printer.outputFileName())
        self.printer.setOutputFileName(outputfilename)
        self.ui.printerName.setText(self.printer.printerName())

        init_time = datetime.now()
        self.cards_data_filename = os.path.join(
            'data', 'cards{:%Y%m%d}.csv'.format(init_time))
        if not os.path.exists(self.cards_data_filename):
            with open(self.cards_data_filename, 'w') as cards_data_file:
                cards_data_file.write(
                    'No.;Read at;Card no.;;;;;;;;;;;;;;;;Clear time;;;Check time;;;Start time;;;Finish time;No. of punches;;1.CP;;1.Time;2.CP;;2.Time;3.CP;;3.Time\n'
                )
        self.cards_data = []

        self._logger = self.Logger()
        self.log('{:%Y-%m-%d %H:%M:%S}'.format(init_time))

        self.timer = QTimer(self)
        self.timer.timeout.connect(self.poll_card)

        availablePorts = []
        if platform.system() == 'Linux':
            availablePorts = [
                os.path.join('/dev', f) for f in os.listdir('/dev')
                if re.match('ttyUSB.+', f)
            ]
            availablePorts.sort()
        elif platform.system() == 'Windows':
            availablePorts = ['COM' + str(i) for i in range(32)]
        self.ui.choiseCom.addItems(availablePorts)
        self.ui.cbUartPort.addItems(availablePorts)

        self.ui.Connect.clicked.connect(self.Connect_clicked)
        self.ui.ReadCard.clicked.connect(self.ReadCard_clicked)
        self.ui.InitCard.clicked.connect(self.InitCard_clicked)
        self.ui.SetTime.clicked.connect(self.SetTime_clicked)
        self.ui.SetNum.clicked.connect(self.SetNum_clicked)
        self.ui.SetStart.clicked.connect(self.SetStart_clicked)
        self.ui.SetFinish.clicked.connect(self.SetFinish_clicked)
        self.ui.CheckSt.clicked.connect(self.CheckSt_clicked)
        self.ui.ClearSt.clicked.connect(self.ClearSt_clicked)
        self.ui.LogCard.clicked.connect(self.LogCard_clicked)
        self.ui.ReadLog.clicked.connect(self.ReadLog_clicked)
        self.ui.SleepCard.clicked.connect(self.SleepCard_clicked)
        self.ui.PassCard.clicked.connect(self.PassCard_clicked)
        self.ui.SelectPrinter.clicked.connect(self.SelectPrinter_clicked)
        self.ui.Print.clicked.connect(self.Print_clicked)
        self.ui.btnApplyPwd.clicked.connect(self.ApplyPwd_clicked)
        self.ui.btnCreateInfoCard.clicked.connect(self.CreateInfo_clicked)
        self.ui.btnReadInfo.clicked.connect(self.ReadInfo_clicked)
        self.ui.btnUartRead.clicked.connect(self.SerialRead_clicked)
        self.ui.btnUartWrite.clicked.connect(self.SerialWrite_clicked)
        self.ui.btnClearText.clicked.connect(self.ClearText_clicked)
        self.ui.btnMsConfigRead.clicked.connect(self.btnMsConfigRead_clicked)
        self.ui.btnMsConfigWrite.clicked.connect(self.write_ms_config)
        self.ui.AutoRead.stateChanged.connect(self.autoread_change)

        bs_config = BaseStation.Config()
        for key, default_value in vars(bs_config).items():
            value_type = type(default_value)
            if isinstance(default_value, list):
                value_type = type(default_value[0])
            setattr(
                bs_config, key,
                self.config.value('settings/' + key,
                                  default_value,
                                  type=value_type))
        self._apply_settings(bs_config, datetime.now())

        self.ui.sbCurPwd1.setValue(bs_config.password[0])
        self.ui.sbCurPwd2.setValue(bs_config.password[1])
        self.ui.sbCurPwd3.setValue(bs_config.password[2])

        ianaIds = QTimeZone.availableTimeZoneIds()
        all_timezones = sorted(
            {QTimeZone(id).offsetFromUtc(datetime.now())
             for id in ianaIds})
        tzlocaloffset = time.localtime().tm_gmtoff
        tzlocalname = None
        for dt in all_timezones:
            tz = timezone(timedelta(seconds=dt))
            tzname = tz.tzname(None)
            if dt == tzlocaloffset:
                tzlocalname = tzname
            self.ui.cbTimeZone.addItem(tzname, dt)
        if tzlocalname is not None:
            self.ui.cbTimeZone.setCurrentText(tzlocalname)
        else:
            self.ui.cbTimeZone.setCurrentText(
                timezone(offset=timedelta(0)).tzname(None))
Beispiel #7
0
    def __init__(self, config):
        super().__init__()
        self.ui = design.Ui_MainWindow()
        self.ui.setupUi(self)

        self.setWindowTitle(
            "SportiduinoPQ {}".format(sportiduinopq_version_string))

        self.config = config
        geometry = self.config.value('geometry')
        if geometry is not None:
            self.restoreGeometry(geometry)

        self.connected = False

        self.printer = QPrinter()
        printer_name = config.value('printer/name', self.printer.printerName())
        self.printer.setPrinterName(printer_name)
        outputfilename = config.value('printer/outputfilename',
                                      self.printer.outputFileName())
        self.printer.setOutputFileName(outputfilename)
        self.ui.printerName.setText(self.printer.printerName())

        init_time = datetime.now()
        self.cards_data_filename = os.path.join(
            'data', 'cards{:%Y%m%d%H%M%S}.json'.format(init_time))
        self.cards_data = []

        self._logger = self.Logger()
        self.log('{:%Y-%m-%d %H:%M:%S}'.format(init_time))

        availablePorts = []
        if platform.system() == 'Linux':
            availablePorts = [
                os.path.join('/dev', f) for f in os.listdir('/dev')
                if re.match('ttyUSB.+', f)
            ]
            availablePorts.sort()
        elif platform.system() == 'Windows':
            availablePorts = ['COM' + str(i) for i in range(32)]
        self.ui.choiseCom.addItems(availablePorts)
        self.ui.cbUartPort.addItems(availablePorts)

        self.ui.Connect.clicked.connect(self.Connect_clicked)
        self.ui.ReadCard.clicked.connect(self.ReadCard_clicked)
        self.ui.InitCard.clicked.connect(self.InitCard_clicked)
        self.ui.SetTime.clicked.connect(self.SetTime_clicked)
        self.ui.SetNum.clicked.connect(self.SetNum_clicked)
        self.ui.SetStart.clicked.connect(self.SetStart_clicked)
        self.ui.SetFinish.clicked.connect(self.SetFinish_clicked)
        self.ui.CheckSt.clicked.connect(self.CheckSt_clicked)
        self.ui.ClearSt.clicked.connect(self.ClearSt_clicked)
        self.ui.LogCard.clicked.connect(self.LogCard_clicked)
        self.ui.ReadLog.clicked.connect(self.ReadLog_clicked)
        self.ui.SleepCard.clicked.connect(self.SleepCard_clicked)
        self.ui.PassCard.clicked.connect(self.PassCard_clicked)
        self.ui.SelectPrinter.clicked.connect(self.SelectPrinter_clicked)
        self.ui.Print.clicked.connect(self.Print_clicked)
        self.ui.btnApplyPwd.clicked.connect(self.ApplyPwd_clicked)
        self.ui.btnCreateInfoCard.clicked.connect(self.CreateInfo_clicked)
        self.ui.btnReadInfo.clicked.connect(self.ReadInfo_clicked)
        self.ui.btnUartRead.clicked.connect(self.SerialRead_clicked)
        self.ui.btnUartWrite.clicked.connect(self.SerialWrite_clicked)
        self.ui.btnClearText.clicked.connect(self.ClearText_clicked)
        self.ui.btnMsConfigRead.clicked.connect(self.btnMsConfigRead_clicked)
        self.ui.btnMsConfigWrite.clicked.connect(self.write_ms_config)

        bs_config = BaseStation.Config()
        for key, default_value in vars(bs_config).items():
            value_type = type(default_value)
            if isinstance(default_value, list):
                value_type = type(default_value[0])
            setattr(
                bs_config, key,
                self.config.value('settings/' + key,
                                  default_value,
                                  type=value_type))
        self._apply_settings(bs_config, datetime.now())

        self.ui.sbCurPwd1.setValue(bs_config.password[0])
        self.ui.sbCurPwd2.setValue(bs_config.password[1])
        self.ui.sbCurPwd3.setValue(bs_config.password[2])