Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sensirion_driver_adapters/rx_tx_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ def unpack_dynamic_sized(self, data):
elif is_string: # a string
val = val[0].decode()
unpacked.append(val)
data_pos += field_len
else:
descriptor = f"{byte_order_specifier} {descriptor}"
unpacked.extend(struct.unpack_from(descriptor, data, data_pos))
data_pos += elem_size
data_pos += elem_size
match = self.field_match.match(self._descriptor, descriptor_pos)
return tuple(unpacked)
5 changes: 4 additions & 1 deletion tests/test_pack_unpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ def test_unpack(rx: RxData, data):

@pytest.mark.parametrize("rx, data", [(RxData(">HH"), (0xABCD, 1234)),
(RxData(">HH8B"), (0xABCD, 1234, (1, 2, 3, 4, 5, 6, 7, 8))),
(RxData(">I16s"), (0xABCD, 'hello world'))])
(RxData(">I16s"), (0xABCD, 'hello world')),
(RxData(">I8BHHH"), (0x0803028D,
(0x32, 0x32, 0x32, 0x38, 0x42, 0x44, 0x00, 0x00),
0x0C10, 0x1121, 0x0054))])
def test_dynamic_unpack(rx: RxData, data):
to_pack = []
for d in data:
Expand Down
Loading