From 36c2084fedc8d467fe3775c491c6134a6a5ae6ca Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Tue, 24 Feb 2026 17:28:17 +1000 Subject: [PATCH 1/2] rpc_client: fix ACK counter start value Start the ACK counter at 0, not negative. This prevents the possibility of too many buffers pending on the receiving device, which would cause buffers to drop and hence the upload to fail. This slightly reduces write throughput. Signed-off-by: Jordan Yates --- src/infuse_iot/rpc_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/infuse_iot/rpc_client.py b/src/infuse_iot/rpc_client.py index 5ac46ad..2734989 100644 --- a/src/infuse_iot/rpc_client.py +++ b/src/infuse_iot/rpc_client.py @@ -127,7 +127,7 @@ def _run_data_send_core( return self._finalise_command(recv, rsp_decoder) # Send data payloads chunked as requested - ack_cnt = -ack_period + ack_cnt = 0 offset = 0 for chunk_id, chunk in enumerate(data): hdr = rpc.DataHeader(self._request_id, chunk_id if packet_idx else offset) From 59257440cdad6141fb9f542061937ea14fe176ff Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Tue, 24 Feb 2026 17:33:37 +1000 Subject: [PATCH 2/2] rpc_client: reduce harcoding Move the hardcoded ack period to a class variable that can be updated, and support an ack period of 0 without blasting the entire file as quickly as possible. Signed-off-by: Jordan Yates --- src/infuse_iot/rpc_client.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/infuse_iot/rpc_client.py b/src/infuse_iot/rpc_client.py index 2734989..4ef07d3 100644 --- a/src/infuse_iot/rpc_client.py +++ b/src/infuse_iot/rpc_client.py @@ -31,6 +31,8 @@ def __init__( self._id = infuse_id self._max_payload = max_payload self._rx_cb = rx_cb + self.ack_period = 2 + self.no_ack_sleep = 0.01 def set_timeout(self, timeout: float): self._timeout = timeout @@ -105,9 +107,8 @@ def _run_data_send_core( rsp_decoder: Callable[[bytes], ctypes.LittleEndianStructure], ) -> tuple[rpc.ResponseHeader | None, ctypes.LittleEndianStructure | None]: self._request_id += 1 - ack_period = 2 header = rpc.RequestHeader(self._request_id, cmd_id) # type: ignore - data_hdr = rpc.RequestDataHeader(total_size, ack_period) + data_hdr = rpc.RequestDataHeader(total_size, self.ack_period) request_packet = bytes(header) + bytes(data_hdr) + params pkt = PacketOutput( @@ -139,16 +140,20 @@ def _run_data_send_core( pkt_bytes, ) self._client.send(GatewayRequestEpacketSend(pkt)) - ack_cnt += 1 - # Wait for ACKs at the period - if ack_cnt == ack_period: - recv = self._wait_data_ack() - if recv is None: - return None, None - if recv.ptype == InfuseType.RPC_RSP: - return self._finalise_command(recv, rsp_decoder) - ack_cnt = 0 + if self.ack_period: + ack_cnt += 1 + # Wait for ACKs at the period + if ack_cnt == self.ack_period: + recv = self._wait_data_ack() + if recv is None: + return None, None + if recv.ptype == InfuseType.RPC_RSP: + return self._finalise_command(recv, rsp_decoder) + ack_cnt = 0 + else: + # Limit throughput to avoid blasting the entire file + time.sleep(self.no_ack_sleep) offset += len(chunk) if progress_cb: