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

Commit

Permalink
Simplify byte conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
myoung34 committed Mar 8, 2020
1 parent b2d3a8a commit 7d42a5a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 9 deletions.
5 changes: 0 additions & 5 deletions tests/test_blescan.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
from tilty import blescan


def test_number_packet():
assert blescan.number_packet(b'\x89=') == 35133
assert blescan.number_packet(b'\x98\xc7') == 39111


def test_string_packet():
assert blescan.string_packet(b'\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') == 'fe000000000000000000000000000000' # noqa
assert blescan.string_packet(b'\x93\xe2\xfdD\x1b\xafhOH\xef>mn\x91\xcb\x14') == '93e2fd441baf684f48ef3e6d6e91cb14' # noqa
Expand Down
5 changes: 1 addition & 4 deletions tilty/blescan.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ def string_packet(pkt):
# b'\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
# so len() is 16
# loop over each byte, get it to hex, build up the string (uuid is 32 chars, 16bytes) # noqa
_str = ""
for i in range(len(pkt)): # 0-16 loop
_str += "%02x" % struct.unpack("B", pkt[i:i+1])[0]
return _str
return ''.join(["%02x" % int.from_bytes(pkt[i:i+1], "big") for i in range(len(pkt))]) # noqa


def packed_bdaddr_to_string(bdaddr_packed):
Expand Down

0 comments on commit 7d42a5a

Please sign in to comment.