Skip to content

Commit 5925744

Browse files
committed
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 <jordan@embeint.com>
1 parent 36c2084 commit 5925744

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

src/infuse_iot/rpc_client.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ def __init__(
3131
self._id = infuse_id
3232
self._max_payload = max_payload
3333
self._rx_cb = rx_cb
34+
self.ack_period = 2
35+
self.no_ack_sleep = 0.01
3436

3537
def set_timeout(self, timeout: float):
3638
self._timeout = timeout
@@ -105,9 +107,8 @@ def _run_data_send_core(
105107
rsp_decoder: Callable[[bytes], ctypes.LittleEndianStructure],
106108
) -> tuple[rpc.ResponseHeader | None, ctypes.LittleEndianStructure | None]:
107109
self._request_id += 1
108-
ack_period = 2
109110
header = rpc.RequestHeader(self._request_id, cmd_id) # type: ignore
110-
data_hdr = rpc.RequestDataHeader(total_size, ack_period)
111+
data_hdr = rpc.RequestDataHeader(total_size, self.ack_period)
111112

112113
request_packet = bytes(header) + bytes(data_hdr) + params
113114
pkt = PacketOutput(
@@ -139,16 +140,20 @@ def _run_data_send_core(
139140
pkt_bytes,
140141
)
141142
self._client.send(GatewayRequestEpacketSend(pkt))
142-
ack_cnt += 1
143143

144-
# Wait for ACKs at the period
145-
if ack_cnt == ack_period:
146-
recv = self._wait_data_ack()
147-
if recv is None:
148-
return None, None
149-
if recv.ptype == InfuseType.RPC_RSP:
150-
return self._finalise_command(recv, rsp_decoder)
151-
ack_cnt = 0
144+
if self.ack_period:
145+
ack_cnt += 1
146+
# Wait for ACKs at the period
147+
if ack_cnt == self.ack_period:
148+
recv = self._wait_data_ack()
149+
if recv is None:
150+
return None, None
151+
if recv.ptype == InfuseType.RPC_RSP:
152+
return self._finalise_command(recv, rsp_decoder)
153+
ack_cnt = 0
154+
else:
155+
# Limit throughput to avoid blasting the entire file
156+
time.sleep(self.no_ack_sleep)
152157

153158
offset += len(chunk)
154159
if progress_cb:

0 commit comments

Comments
 (0)