@@ -206,8 +206,8 @@ def get_fpdata(self, buffer='char', slot=1):
206
206
raise RuntimeError ('Uknown buffer type' )
207
207
if self ._get_packet (12 )[0 ] == 0 :
208
208
res = self ._get_data (9 )
209
- #print('datasize: ' + str(len(res)))
210
- #print(res)
209
+ # print('datasize: ' + str(len(res)))
210
+ # print(res)
211
211
return res
212
212
213
213
def send_fpdata (self , data , buffer = 'char' , slot = 1 ):
@@ -224,8 +224,8 @@ def send_fpdata(self, data, buffer='char', slot=1):
224
224
raise RuntimeError ('Uknown buffer type' )
225
225
if self ._get_packet (12 )[0 ] == 0 :
226
226
self ._send_data (data )
227
- #print('datasize: ' + str(len(res)))
228
- #print(res)
227
+ # print('datasize: ' + str(len(res)))
228
+ # print(res)
229
229
return True
230
230
231
231
def empty_library (self ):
@@ -236,11 +236,13 @@ def empty_library(self):
236
236
237
237
def read_templates (self ):
238
238
"""Requests the sensor to list of all template locations in use and
239
- stores them in self.templates. Returns the packet error code or OK success"""
239
+ stores them in self.templates. Returns the packet error code or
240
+ OK success"""
241
+ import math
240
242
self .templates = []
241
243
self .read_sysparam ()
242
244
temp_r = [0x0c , ]
243
- for j in range (int (self .library_size / 256 )):
245
+ for j in range (math . ceil (self .library_size / 256 )):
244
246
self ._send_packet ([_TEMPLATEREAD , j ])
245
247
r = self ._get_packet (44 )
246
248
if r [0 ] == OK :
@@ -311,18 +313,18 @@ def _get_data(self, expected):
311
313
and _ENDDATAPACKET. Alternate method for getting data such
312
314
as fingerprint image, etc. Returns the data payload."""
313
315
res = self ._uart .read (expected )
314
- #print("Got", res)
316
+ # print("Got", res)
315
317
if (not res ) or (len (res ) != expected ):
316
318
raise RuntimeError ('Failed to read data from sensor' )
317
319
318
320
# first two bytes are start code
319
321
start = struct .unpack ('>H' , res [0 :2 ])[0 ]
320
- #print(start)
322
+ # print(start)
321
323
if start != _STARTCODE :
322
324
raise RuntimeError ('Incorrect packet data' )
323
325
# next 4 bytes are address
324
326
addr = [i for i in res [2 :6 ]]
325
- #print(addr)
327
+ # print(addr)
326
328
if addr != self .address :
327
329
raise RuntimeError ('Incorrect address' )
328
330
@@ -339,15 +341,15 @@ def _get_data(self, expected):
339
341
res = self ._uart .read (length - 2 )
340
342
# todo: we should really inspect the headers and checksum
341
343
reply = [i for i in res [0 :length ]]
342
- self ._uart .read (2 ) # disregard checksum but we really shouldn't
344
+ self ._uart .read (2 ) # disregard checksum but we really shouldn't
343
345
reply += self ._get_data (9 )
344
346
elif packet_type == _ENDDATAPACKET :
345
347
res = self ._uart .read (length - 2 )
346
348
# todo: we should really inspect the headers and checksum
347
349
reply = [i for i in res [0 :length ]]
348
- self ._uart .read (2 ) # disregard checksum but we really shouldn't
350
+ self ._uart .read (2 ) # disregard checksum but we really shouldn't
349
351
print (len (reply ))
350
- #print(reply)
352
+ # print(reply)
351
353
return reply
352
354
353
355
def _send_packet (self , data ):
@@ -384,57 +386,57 @@ def _send_data(self, data):
384
386
for i in range (int (len (data ) / (data_length - 2 ))):
385
387
start = i * (data_length - 2 )
386
388
end = (i + 1 ) * (data_length - 2 )
387
- #print(start)
388
- #print(end)
389
- #print(i)
389
+ # print(start)
390
+ # print(end)
391
+ # print(i)
390
392
391
393
packet = [_STARTCODE >> 8 , _STARTCODE & 0xFF ]
392
394
packet = packet + self .address
393
395
packet .append (_DATAPACKET )
394
396
length = len (data [start :end ]) + 2
395
- #print(length)
397
+ # print(length)
396
398
packet .append (length >> 8 )
397
399
packet .append (length & 0xFF )
398
400
checksum = _DATAPACKET + (length >> 8 ) + (length & 0xFF )
399
401
400
402
for j in range (len (data [start :end ])):
401
403
packet .append (data [j ])
402
- #packet.append(struct.pack('@B', data[j]))
404
+ # packet.append(struct.pack('@B', data[j]))
403
405
checksum += data [j ]
404
406
405
407
packet .append (checksum >> 8 )
406
408
packet .append (checksum & 0xFF )
407
409
408
- #print("Sending: ", [hex(i) for i in packet])
409
- #self._uart.write(bytearray(packet))
410
+ # print("Sending: ", [hex(i) for i in packet])
411
+ # self._uart.write(bytearray(packet))
410
412
self ._uart .write (packet )
411
- #print(i)
413
+ # print(i)
412
414
413
415
i += 1
414
416
start = i * (data_length - 2 )
415
417
end = (i + 1 ) * (data_length - 2 )
416
- #print(start)
417
- #print(end)
418
- #print(i)
418
+ # print(start)
419
+ # print(end)
420
+ # print(i)
419
421
420
422
packet = [_STARTCODE >> 8 , _STARTCODE & 0xFF ]
421
423
packet = packet + self .address
422
424
packet .append (_ENDDATAPACKET )
423
425
length = len (data [start :end ]) + 2
424
- #print(length)
426
+ # print(length)
425
427
packet .append (length >> 8 )
426
428
packet .append (length & 0xFF )
427
429
checksum = _DATAPACKET + (length >> 8 ) + (length & 0xFF )
428
430
429
431
for j in range (len (data [start :end ])):
430
432
packet .append (data [j ])
431
- #packet.append(struct.pack('@B', data[j]))
433
+ # packet.append(struct.pack('@B', data[j]))
432
434
checksum += data [j ]
433
435
434
436
packet .append (checksum >> 8 )
435
437
packet .append (checksum & 0xFF )
436
438
437
- #print("Sending: ", [hex(i) for i in packet])
438
- #self._uart.write(bytearray(packet))
439
+ # print("Sending: ", [hex(i) for i in packet])
440
+ # self._uart.write(bytearray(packet))
439
441
self ._uart .write (packet )
440
- #print(i)
442
+ # print(i)
0 commit comments