Skip to content

Commit 71b6dc9

Browse files
committed
rpc_wrappers: file_write_basic: print expected values
Print the expected data CRC and length if the returned response does not match. Signed-off-by: Jordan Yates <jordan@embeint.com>
1 parent 829ed0c commit 71b6dc9

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/infuse_iot/rpc_wrappers/file_write_basic.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,13 @@ def __init__(self, args):
8989

9090
with open(self.file, "rb") as f:
9191
self.payload = f.read()
92+
self._expected_crc = binascii.crc32(self.payload)
9293

9394
def auth_level(self):
9495
return Auth.NETWORK
9596

9697
def request_struct(self):
97-
return self.request(self.action, binascii.crc32(self.payload))
98+
return self.request(self.action, self._expected_crc)
9899

99100
def data_payload(self):
100101
print("Preparing for file upload...")
@@ -112,6 +113,11 @@ def handle_response(self, return_code, response):
112113
if return_code != 0:
113114
print(f"Failed to write file ({errno.strerror(-return_code)})")
114115
return
115-
print("File written")
116-
print(f"\tLength: {response.recv_len}")
117-
print(f"\t CRC: 0x{response.recv_crc:08x}")
116+
if (response.recv_len != len(self.payload)) or (response.recv_crc != self._expected_crc):
117+
print("Unexpected write contents")
118+
print(f"\tLength: {response.recv_len} (Expected {len(self.payload)})")
119+
print(f"\t CRC: 0x{response.recv_crc:08x} (Expected 0x{self._expected_crc:08x})")
120+
else:
121+
print("File written")
122+
print(f"\tLength: {response.recv_len}")
123+
print(f"\t CRC: 0x{response.recv_crc:08x}")

0 commit comments

Comments
 (0)