Skip to content

Commit

Permalink
Merge pull request #12 from ioull/master
Browse files Browse the repository at this point in the history
Add checksum and length check
  • Loading branch information
ISO-B authored Jan 25, 2018
2 parents ffe61da + a1d2431 commit 590dc76
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pyzigate/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,22 @@ def decode_data(self, data):
"""Interpret responses attributes"""
msg_data = data[5:]
msg_type = hexlify(data[0:2])
msg_length = int.from_bytes(data[2:4], byteorder='big', signed=False)
msg_crc = int.from_bytes(data[4:5], byteorder='big', signed=False)
msg_rssi = int.from_bytes(data[-1:], byteorder='big', signed=False)

if msg_length != len(msg_data) :
ZGT_LOG.error('BAD LENGTH {0} != {1}'.format(msg_length,len(msg_data)))
return

computed_crc = self.checksum(data[0:2], data[2:4], data[5:])
if msg_crc != computed_crc :
ZGT_LOG.error('BAD CRC {0} != {1}'.format(msg_crc,computed_crc))
return

# Do different things based on MsgType
ZGT_LOG.debug('--------------------------------------')

# Device Announce
if msg_type == b'004d':
struct = OrderedDict([('short_addr', 16), ('mac_addr', 64),
Expand Down

0 comments on commit 590dc76

Please sign in to comment.