@@ -51,21 +51,21 @@ def returnnumberpacket(pkt):
51
51
myInteger = 0
52
52
multiple = 256
53
53
for c in pkt :
54
- myInteger += struct . unpack ( "B" , c )[ 0 ] * multiple
54
+ myInteger += c * multiple
55
55
multiple = 1
56
56
return myInteger
57
57
58
58
59
59
def returnstringpacket (pkt ):
60
60
myString = ""
61
61
for c in pkt :
62
- myString += "%02x" % struct . unpack ( "B" , c )[ 0 ]
62
+ myString += "%02x" % c
63
63
return myString
64
64
65
65
66
66
def printpacket (pkt ):
67
67
for c in pkt :
68
- sys .stdout .write ("%02x " % struct . unpack ( "B" , c )[ 0 ] )
68
+ sys .stdout .write ("%02x " % c )
69
69
70
70
71
71
def get_packed_bdaddr (bdaddr_string ):
@@ -141,14 +141,14 @@ def parse_events(sock, loop_count=100):
141
141
elif event == bluez .EVT_DISCONN_COMPLETE :
142
142
i = 0
143
143
elif event == LE_META_EVENT :
144
- subevent , = struct .unpack ("B" , pkt [3 ])
144
+ subevent , = struct .unpack ("B" , pkt [3 : 4 ])
145
145
pkt = pkt [4 :]
146
146
if subevent == EVT_LE_CONN_COMPLETE :
147
147
pass
148
148
# le_handle_connection_complete(pkt)
149
149
elif subevent == EVT_LE_ADVERTISING_REPORT :
150
150
# print "advertising report"
151
- num_reports = struct .unpack ("B" , pkt [0 ])[0 ]
151
+ num_reports = struct .unpack ("B" , pkt [0 : 1 ])[0 ]
152
152
report_pkt_offset = 0
153
153
for i in range (0 , num_reports ):
154
154
if (DEBUG ):
@@ -176,8 +176,8 @@ def parse_events(sock, loop_count=100):
176
176
pkt [report_pkt_offset - 6 : report_pkt_offset - 4 ])
177
177
minor = returnnumberpacket (
178
178
pkt [report_pkt_offset - 4 : report_pkt_offset - 2 ])
179
- txp , = struct . unpack ( "b" , pkt [report_pkt_offset - 2 ])
180
- rssi , = struct . unpack ( "b" , pkt [report_pkt_offset - 1 ])
179
+ txp , = ( pkt [report_pkt_offset - 2 ], )
180
+ rssi , = ( pkt [report_pkt_offset - 1 ], )
181
181
182
182
beac = {'uuid' : uuid , 'mac' : mac , 'major' : major ,
183
183
'minor' : minor , 'txp' : txp , 'rssi' : rssi }
0 commit comments