@@ -236,7 +236,7 @@ def _cmd(self, cmd, arg=0, crc=0, response_buf=None, data_block=True, wait=True)
236
236
buf [4 ] = arg & 0xff
237
237
238
238
if (crc == 0 ):
239
- buf [5 ] = self . calculate_crc (buf [:- 1 ])
239
+ buf [5 ] = calculate_crc (buf [:- 1 ])
240
240
else :
241
241
buf [5 ] = crc
242
242
@@ -287,7 +287,7 @@ def _block_cmd(self, cmd, block, crc, response_buf=None):
287
287
buf [4 ] = 0
288
288
289
289
if (crc == 0 ):
290
- buf [5 ] = self . calculate_crc (buf [:- 1 ])
290
+ buf [5 ] = calculate_crc (buf [:- 1 ])
291
291
else :
292
292
buf [5 ] = crc
293
293
@@ -456,32 +456,32 @@ def writeblocks(self, start_block, buf):
456
456
self ._cmd_nodata (_TOKEN_STOP_TRAN , 0x0 )
457
457
return 0
458
458
459
- def calculate_crc (self , message ):
460
- """
461
- Calculate the CRC of a message.
462
- :param bytearray message: Where each index is a byte
463
- """
459
+ def calculate_crc (message ):
460
+ """
461
+ Calculate the CRC of a message.
462
+ :param bytearray message: Where each index is a byte
463
+ """
464
464
# Code converted from https://github.com/hazelnusse/crc7/blob/master/crc7.cc by devoh747
465
465
# With permission from Dale Lukas Peterson <hazelnusse@gmail.com>
466
466
# 8/6/2019
467
467
468
- crc_table = bytearray (256 )
468
+ crc_table = bytearray (256 )
469
469
470
- crc_poly = const (0x89 ) # the value of our CRC-7 polynomial
470
+ crc_poly = const (0x89 ) # the value of our CRC-7 polynomial
471
471
472
- # generate a table value for all 256 possible byte values
473
- for i in range (256 ):
474
- if (i & 0x80 ):
475
- crc_table [i ] = i ^ crc_poly
476
- else :
477
- crc_table [i ] = i
478
- for _ in range (1 , 8 ):
479
- crc_table [i ] = crc_table [i ] << 1
480
- if (crc_table [i ] & 0x80 ):
481
- crc_table [i ] = crc_table [i ] ^ crc_poly
472
+ # generate a table value for all 256 possible byte values
473
+ for i in range (256 ):
474
+ if (i & 0x80 ):
475
+ crc_table [i ] = i ^ crc_poly
476
+ else :
477
+ crc_table [i ] = i
478
+ for _ in range (1 , 8 ):
479
+ crc_table [i ] = crc_table [i ] << 1
480
+ if (crc_table [i ] & 0x80 ):
481
+ crc_table [i ] = crc_table [i ] ^ crc_poly
482
482
483
- crc = 0
484
- for i in range (len (message )):
485
- crc = crc_table [(crc << 1 ) ^ message [i ]]
483
+ crc = 0
484
+ for i in range (len (message )):
485
+ crc = crc_table [(crc << 1 ) ^ message [i ]]
486
486
487
- return ((crc << 1 ) | 1 )
487
+ return ((crc << 1 ) | 1 )
0 commit comments