Skip to content
This repository has been archived by the owner on Oct 5, 2024. It is now read-only.

Commit

Permalink
Release 0.40.9
Browse files Browse the repository at this point in the history
  • Loading branch information
doudz committed Sep 21, 2020
2 parents 2c0ee7d + 7c10fbf commit 3e3f228
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
6 changes: 3 additions & 3 deletions zigate/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
21 changes: 14 additions & 7 deletions zigate/flasher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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):
Expand All @@ -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)

Expand All @@ -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):
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -495,4 +501,5 @@ def main():


if __name__ == "__main__":
logging.basicConfig()
main()
2 changes: 1 addition & 1 deletion zigate/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
#


__version__ = '0.40.8'
__version__ = '0.40.9'

0 comments on commit 3e3f228

Please sign in to comment.