Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/SmartMeshSDK/protocols/otap/GenStructs.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def parse_field(field, data, index = 0):
val = struct.unpack('!H', data[s:e])[0]
elif field.type is 'int' and field.len is 4:
try:
val = struct.unpack('!L', data[s:e])[0]
val = struct.unpack('!L', data[s:e])[0]
except TypeError:
aByte = data[s]
anInt = data[s:e]
Expand Down
7 changes: 7 additions & 0 deletions libs/SmartMeshSDK/protocols/otap/OTAPCommunicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,13 @@ def status_callback(self, mac, cmd_data):
log.info('Got Status response from %s' % print_mac(mac))
log.debug('Data: ' + ' '.join(['%02X' % ord(b) for b in cmd_data]))
os_resp = OtapStatusResp()

if isinstance(cmd_data, str):
# convert the str to bytes using latin-1, because all Unicode codepoints from 0x00 through to 0xFF
# are mapped one-on-one to bytes with the same value.
# This is equivalent to: `cmd_data = bytearray(map(ord, cmd_data))`
cmd_data = cmd_data.encode('latin-1')

os_resp.parse(cmd_data)
log.debug(str(os_resp))

Expand Down
18 changes: 9 additions & 9 deletions libs/SmartMeshSDK/protocols/otap/OTAPMic.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ def generate_mic(data):
0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78 ]

def calcFCS(msg):
fcs = 0xffff
for b in msg:
try:
c = struct.unpack('B', b)[0]
except TypeError:
c = struct.unpack('B', bytes([b]))[0]
fcs = (fcs >> 8) ^ crctab[(fcs ^ c) & 0xff]
fcs = 0xffff

for b in msg:
try:
c = struct.unpack('B', b)[0]
except TypeError:
c = struct.unpack('B', bytes([b]))[0]
fcs = (fcs >> 8) ^ crctab[(fcs ^ c) & 0xff]

return ~fcs & 0xFFFF
return ~fcs & 0xFFFF


def getFCS(msg):
Expand Down