@@ -242,8 +242,8 @@ def read(self):
242
242
243
243
# determine report mode
244
244
245
- packet_len = int .from_bytes (self .port .read (2 ), byteorder = ' little' )
246
- report_mode = int .from_bytes (self .port .read (1 ), byteorder = ' little' )
245
+ packet_len = int .from_bytes (self .port .read (2 ), " little" )
246
+ report_mode = int .from_bytes (self .port .read (1 ), " little" )
247
247
248
248
# various mangled-read checks
249
249
if packet_len == PACKET_LEN_BASIC :
@@ -274,7 +274,7 @@ def read(self):
274
274
#print("End-of_Frame marker doesn't match.")
275
275
continue
276
276
277
- if packet [0 ].to_bytes () != PACKET_HEAD :
277
+ if packet [0 ].to_bytes (1 , "little" ) != PACKET_HEAD :
278
278
#print(f"Packet head {packet[0]} isn't right.")
279
279
continue
280
280
@@ -302,11 +302,11 @@ def read(self):
302
302
# byte -2: "tail" value of 55
303
303
# byte -1: "calibration" value of 00
304
304
305
- if packet [- 2 ].to_bytes () != PACKET_TAIL :
305
+ if packet [- 2 ].to_bytes (1 , "little" ) != PACKET_TAIL :
306
306
#print(f"Invalid packet tail value.")
307
307
continue
308
308
309
- if packet [- 1 ].to_bytes () != PACKET_CALIBRATION :
309
+ if packet [- 1 ].to_bytes (1 , "little" ) != PACKET_CALIBRATION :
310
310
#print(f"Invalid packet calibration value.")
311
311
continue
312
312
@@ -323,15 +323,15 @@ def read(self):
323
323
# todo: use lower of MAX_LEGIT_DISTANCE and distance resolution * gate limit
324
324
325
325
if self .motion_detected :
326
- self .motion_target_cm = int .from_bytes (packet [2 :4 ], byteorder = ' little' )
326
+ self .motion_target_cm = int .from_bytes (packet [2 :4 ], " little" )
327
327
self .motion_energy = int (packet [4 ])
328
328
if self .motion_target_cm > MAX_LEGIT_DISTANCE :
329
329
continue
330
330
if self .motion_energy > MAX_LEGIT_ENERGY :
331
331
continue
332
332
333
333
if self .static_detected :
334
- self .static_target_cm = int .from_bytes (packet [5 :7 ], byteorder = ' little' )
334
+ self .static_target_cm = int .from_bytes (packet [5 :7 ], " little" )
335
335
self .static_energy = int (packet [7 ])
336
336
337
337
if self .static_target_cm > MAX_LEGIT_DISTANCE :
@@ -340,7 +340,7 @@ def read(self):
340
340
continue
341
341
342
342
if target_state :
343
- self .detection_cm = int .from_bytes (packet [8 :10 ], byteorder = ' little' )
343
+ self .detection_cm = int .from_bytes (packet [8 :10 ], " little" )
344
344
if self .detection_cm > MAX_LEGIT_DISTANCE :
345
345
continue
346
346
@@ -422,7 +422,7 @@ def _send(self,command_data_bytes):
422
422
#print("Didn't find response header.")
423
423
continue
424
424
425
- packet_len = int .from_bytes (self .port .read (2 ), byteorder = ' little' )
425
+ packet_len = int .from_bytes (self .port .read (2 ), " little" )
426
426
427
427
# It would be more robust to check for the exact expected length
428
428
# for each particular command, but gets clunky. So, at least make
@@ -512,7 +512,7 @@ def _scan_for_header(self,header):
512
512
buffer .append (self .port .read (1 ))
513
513
if not buffer [- 1 ]: # timeout
514
514
break
515
- if buffer == [x .to_bytes () for x in header ]:
515
+ if buffer == [x .to_bytes (1 , "little" ) for x in header ]:
516
516
return True
517
517
self .serial_failures += 1
518
518
return False
@@ -584,7 +584,7 @@ def read_config(self):
584
584
585
585
586
586
# then last 2 are little-endian presence timeout
587
- presence_timeout = int .from_bytes (result [22 :], byteorder = ' little' )
587
+ presence_timeout = int .from_bytes (result [22 :], " little" )
588
588
if presence_timeout > MAX_LEGIT_PRESENCE_TIMEOUT :
589
589
continue
590
590
self .presence_timeout = presence_timeout
0 commit comments