fix flip
This commit is contained in:
@ -404,12 +404,12 @@ class Protocol:
|
|||||||
def get_int_word(num: int) -> int:
|
def get_int_word(num: int) -> int:
|
||||||
return int(get_word(num), 16)
|
return int(get_word(num), 16)
|
||||||
|
|
||||||
# CRC check: XOR over words 1..13, compare with word 14
|
# CRC check: XOR over words 1..13 (wire order), compare with word 14 (wire order)
|
||||||
crc_words = [hex_str[i:i+4] for i in range(4, len(hex_str)-4, 4)]
|
crc_words = [hex_str[i:i+4] for i in range(4, len(hex_str)-4, 4)]
|
||||||
computed = int(crc_words[0], 16)
|
computed = int(crc_words[0], 16)
|
||||||
for w in crc_words[1:]:
|
for w in crc_words[1:]:
|
||||||
computed ^= int(w, 16)
|
computed ^= int(w, 16)
|
||||||
stored = get_int_word(14)
|
stored = int(hex_str[56:60], 16)
|
||||||
if computed != stored:
|
if computed != stored:
|
||||||
raise CRCError(expected=computed, received=stored)
|
raise CRCError(expected=computed, received=stored)
|
||||||
|
|
||||||
|
|||||||
@ -76,8 +76,8 @@ def make_valid_response(
|
|||||||
for w in crc_words[1:]:
|
for w in crc_words[1:]:
|
||||||
crc_val ^= int(w, 16)
|
crc_val ^= int(w, 16)
|
||||||
|
|
||||||
# Replace CRC word
|
# Replace CRC word (stored in wire order, no flipfour)
|
||||||
hex_str = hex_str[:56] + _flipfour(_int_to_hex4(crc_val))
|
hex_str = hex_str[:56] + _int_to_hex4(crc_val)
|
||||||
return bytes.fromhex(hex_str)
|
return bytes.fromhex(hex_str)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user