diff --git a/zigate/core.py b/zigate/core.py index fce75a9e..e624e04d 100644 --- a/zigate/core.py +++ b/zigate/core.py @@ -2235,7 +2235,7 @@ def action_ias_warning(self, addr, endpoint, 'policepanic': '0100', 'firepanic': '0101', 'emergencypanic': '0110' }.get(mode, '0000') strobe = '01' if strobe else '00' - level = {'low': '00', 'medium': '01', 'high': '10', 'veryhigh': '11'}.get(level, '00') + level = {'low': '00', 'medium': '10', 'high': '01', 'veryhigh': '11'}.get(level, '00') warning_mode_strobe_level = int(mode + strobe + level, 2) strobe_level = {'low': 0, 'medium': 1, 'high': 2, 'veryhigh': 3}.get(strobe_level, 0) data = struct.pack('!B' + addr_fmt + 'BBBBHBHBB', addr_mode, addr, 1, @@ -2259,9 +2259,9 @@ def action_ias_squawk(self, addr, endpoint, addr_mode, addr_fmt = self._choose_addr_mode(addr) addr = self.__addr(addr) manufacturer_specific = manufacturer_code != 0 - mode = {'armed': '0000', 'disarmed': '1000'}.get(mode, '0000') + mode = {'armed': '0000', 'disarmed': '0001'}.get(mode, '0000') strobe = '1' if strobe else '0' - level = {'low': '00', 'medium': '01', 'high': '10', 'veryhigh': '11'}.get(level, '00') + level = {'low': '00', 'medium': '10', 'high': '01', 'veryhigh': '11'}.get(level, '00') squawk_mode_strobe_level = int(mode + strobe + '0' + level, 2) data = struct.pack('!B' + addr_fmt + 'BBBBHB', addr_mode, addr, 1, endpoint, diff --git a/zigate/flasher.py b/zigate/flasher.py index baccdd9e..bc93e6e3 100644 --- a/zigate/flasher.py +++ b/zigate/flasher.py @@ -35,7 +35,7 @@ def __getattr__(self, *args, **kwargs): import usb -logger = logging.getLogger(__name__) +logger = logging.getLogger('ZiGate Flasher') _responses = {} ZIGATE_CHIP_ID = 0x10408686 @@ -293,7 +293,7 @@ def write_flash_to_file(ser, filename): cur = ZIGATE_FLASH_START flash_end = ZIGATE_FLASH_END - print('reading old flash to %s' % filename) + logger.info('Backup firmware to %s', filename) with open(filename, 'wb') as fd: fd.write(ZIGATE_BINARY_VERSION) read_bytes = 128 @@ -308,11 +308,13 @@ def write_flash_to_file(ser, filename): if cur == 0: (flash_end,) = struct.unpack('>L', res.data[0x20:0x24]) fd.write(res.data) + print(int(cur*100/flash_end), '%', end='\r') cur += read_bytes + logger.info('Backup firmware done') def write_file_to_flash(ser, filename): - print('writing new flash from %s' % filename) + logger.info('Writing new firmware from %s', filename) with open(filename, 'rb') as fd: ser.write(req_flash_erase()) res = read_response(ser) @@ -338,7 +340,9 @@ def write_file_to_flash(ser, filename): if not res.ok: print('writing failed at 0x%08x, status: 0x%x, data: %s' % (cur, res.status, data.hex())) raise SystemExit(1) + print(int(cur*100/flash_end), '%', end='\r') cur += read_bytes + logger.info('Writing new firmware done') def erase_EEPROM(ser, pdm_only=False): @@ -365,7 +369,7 @@ def flash(serialport='auto', write=None, save=None, erase=False, pdm_only=False) check_chip_id(ser) flash_type = get_flash_type(ser) mac_address = get_mac(ser) - print('Found MAC-address: %s' % mac_address) + logger.info('Found MAC-address: %s', mac_address) if write or save or erase: select_flash(ser, flash_type) @@ -377,7 +381,7 @@ def flash(serialport='auto', write=None, save=None, erase=False, pdm_only=False) if erase: erase_EEPROM(ser, pdm_only) - change_baudrate(ser, 38400) + # change_baudrate(ser, 38400) def upgrade_firmware(port): @@ -418,6 +422,7 @@ def main(): parser.add_argument('--gpio', help='Configure GPIO for PiZiGate flash', action='store_true', default=False) parser.add_argument('--din', help='Configure USB for ZiGate DIN flash', action='store_true', default=False) args = parser.parse_args() + logger.setLevel(logging.INFO) if args.debug: logger.setLevel(logging.DEBUG) @@ -460,13 +465,13 @@ def main(): logger.exception("Could not open serial device %s", args.serialport) raise SystemExit(1) - atexit.register(change_baudrate, ser, 38400) + # atexit.register(change_baudrate, ser, 38400) change_baudrate(ser, 115200) check_chip_id(ser) flash_type = get_flash_type(ser) mac_address = get_mac(ser) - logger.info('Found MAC-address: %s' % mac_address) + logger.info('Found MAC-address: %s', mac_address) if args.write or args.save: # or args.erase: select_flash(ser, flash_type) @@ -479,6 +484,7 @@ def main(): # if args.erase: # erase_EEPROM(ser, args.pdm_only) + if args.gpio: logger.info('Put PiZiGate in running mode') GPIO.output(27, GPIO.HIGH) # GPIO2 @@ -495,4 +501,5 @@ def main(): if __name__ == "__main__": + logging.basicConfig() main() diff --git a/zigate/version.py b/zigate/version.py index 056f7767..3d7f98a5 100644 --- a/zigate/version.py +++ b/zigate/version.py @@ -6,4 +6,4 @@ # -__version__ = '0.40.8' +__version__ = '0.40.9'