3131
3232import _pble_wire as wire
3333from _pble_central import PbleCentral , rsp_status , status_name
34- from _pble_bench import DownloadVerifier
34+ from _pble_bench import CommandIds , DownloadVerifier
3535
3636DEST = "/bench_roundtrip.bin"
3737GET_STALL_S = 10.0 # bench-side inactivity ceiling per chunk (diagnostic bound)
@@ -70,7 +70,7 @@ async def _hello(c, id_):
7070 return caps
7171
7272
73- async def _put (c , data , chunk , window ):
73+ async def _put (c , data , chunk , window , next_id ):
7474 """Windowed FILE_PUT sender honoring the ADVERTISED caps window (FR-FS-4).
7575
7676 Keeps up to `window` unacknowledged chunks in flight past the cumulative
@@ -84,7 +84,7 @@ async def _put(c, data, chunk, window):
8484 reporting ack/want on a true stall (the dropped-chunk diagnostic)."""
8585 t0 = time .monotonic ()
8686 rsp = await c .send_cmd (
87- wire .OP_FILE_PUT_BEGIN , 2 ,
87+ wire .OP_FILE_PUT_BEGIN , next_id () ,
8888 _u32 (len (data )) + _u32 (zlib .crc32 (data )) + _path_field (DEST ))
8989 if rsp_status (rsp ) != wire .ST_OK :
9090 raise SystemExit ("PUT_BEGIN: %s" % status_name (rsp_status (rsp )))
@@ -101,7 +101,7 @@ async def _put(c, data, chunk, window):
101101 # never more than `window` unacknowledged chunks in flight (AC-1).
102102 while next_off < total and (next_off - c .last_ack ) < win_bytes :
103103 piece = data [next_off :next_off + chunk ]
104- await c .send_cmd_no_rsp (wire .OP_FILE_PUT_DATA , 0 , _u32 (next_off ) + piece )
104+ await c .send_cmd_no_rsp (wire .OP_FILE_PUT_DATA , next_id () , _u32 (next_off ) + piece )
105105 next_off += len (piece )
106106 now = time .monotonic ()
107107 if c .last_ack > seen_ack :
@@ -117,20 +117,20 @@ async def _put(c, data, chunk, window):
117117 next_off = c .last_ack
118118 last_rewind = now
119119 await asyncio .sleep (0.002 )
120- rsp = await c .send_cmd (wire .OP_FILE_PUT_END , 3 , _u32 (zlib .crc32 (data )))
120+ rsp = await c .send_cmd (wire .OP_FILE_PUT_END , next_id () , _u32 (zlib .crc32 (data )))
121121 if rsp_status (rsp ) != wire .ST_OK :
122122 raise SystemExit ("PUT_END: %s" % status_name (rsp_status (rsp )))
123123 return time .monotonic () - t0
124124
125125
126- async def _get (c , expected ):
126+ async def _get (c , expected , next_id ):
127127 """GET_BEGIN then drain GET_DATA events until GET_END. Deadline-bounded."""
128128 expected = bytes (expected )
129129 expect_len = len (expected )
130130 verifier = DownloadVerifier (expected )
131131 c .events .clear ()
132132 t0 = time .monotonic ()
133- rsp = await c .send_cmd (wire .OP_FILE_GET_BEGIN , 4 , _u32 (0 ) + _path_field (DEST ))
133+ rsp = await c .send_cmd (wire .OP_FILE_GET_BEGIN , next_id () , _u32 (0 ) + _path_field (DEST ))
134134 if rsp_status (rsp ) != wire .ST_OK :
135135 raise SystemExit ("GET_BEGIN: %s" % status_name (rsp_status (rsp )))
136136 total = int .from_bytes (rsp .payload [1 :5 ], "little" )
@@ -178,7 +178,8 @@ async def run(args):
178178
179179 c = await PbleCentral .connect (args .address )
180180 try :
181- caps = await _hello (c , 1 )
181+ ids = CommandIds ()
182+ caps = await _hello (c , ids .next ())
182183 chip = caps .get ("chip" , "?" )
183184 caps_mtu = int (caps .get ("mtu" , "0" ) or 0 )
184185 if caps_mtu :
@@ -195,17 +196,17 @@ async def run(args):
195196 raise SystemExit ("wrong board: chip=%s (expected %s)" % (chip , args .expect_chip ))
196197
197198 data = os .urandom (args .size )
198- up_s = await _put (c , data , chunk , window )
199+ up_s = await _put (c , data , chunk , window , ids . next )
199200 print ("PUT %6d B in %5.2f s (%6.0f B/s)" % (len (data ), up_s , len (data ) / up_s ))
200201
201- got , end_crc , dn_s = await _get (c , data )
202+ got , end_crc , dn_s = await _get (c , data , ids . next )
202203 print ("GET %6d B in %5.2f s (%6.0f B/s)" % (len (got ), dn_s , len (got ) / dn_s ))
203204
204205 ok = got == data and end_crc == zlib .crc32 (data )
205206 print ("END crc=0x%08x match=%s bytes-equal=%s"
206207 % (end_crc , end_crc == zlib .crc32 (data ), got == data ))
207208 # Cleanup: remove the bench artifact from the board.
208- await c .send_cmd (wire .OP_FILE_DELETE , 5 , _path_field (DEST ))
209+ await c .send_cmd (wire .OP_FILE_DELETE , ids . next () , _path_field (DEST ))
209210 # Record the negotiated ATT MTU on the final line: it is the link fact the
210211 # OI-1 throughput numbers are read against (chunk = mtu - PBLE_CHUNK_OVERHEAD),
211212 # so the owner's measurement log captures the MTU the run actually saw.
0 commit comments