Skip to content

DEV-1291: take an in-stream ACK that comes with no data packet before it - #133

Merged
JongChern merged 2 commits into
DEV-1149_instream_response_while_streamingfrom
DEV-1291_android_instream_ack_after_pause
Oct 24, 2026
Merged

JongChern merged 2 commits into
DEV-1149_instream_response_while_streamingfrom
DEV-1291_android_instream_ack_after_pause

Conversation

@JongChern

Copy link
Copy Markdown
Contributor

DEV-1291, ported from the Java driver's fix (ShimmerResearch/Shimmer-Java-Android-API#332). Shimmer overrides the streaming parser, so the driver's fix doesn't reach Android. Stacked on #122 (DEV-1149), whose in-stream parser this builds on; review and merge #122 first.

The bug

After STOP_LOGGING_ONLY_COMMAND the unit stops sending data packets for about 100 ms while it closes its SD file. A command sent in that pause is answered at once, so its ACK comes with no data packet before it. processPacket() only looks for an ACK after a data packet, so it threw the reply away a byte at a time. A queued command then timed out, and while streaming the timeout clears every queued instruction.

Android meets a second case the driver doesn't: readBattery() and readStatusLogAndStream() write their reads straight to the socket, unqueued, so with no link CRC a queued SET's bare ACK can come straight after a read's reply.

The fix

  • processWhileStreaming() now looks for an ACK at the start of the buffer first, and takes one only while a reply is due and only when the bytes after it are that reply: an in-stream reply (FF 8A then the opcode) to the queued GET in flight or to an unqueued battery or status read, or, for the queued SET in flight, a bare ACK whose link CRC checks out. Shimmer now keeps the opcodes its unqueued reads await.
  • With no link CRC, a bare ACK at the start of the buffer is taken only for the queued SET in flight, and only when the bytes after it are a data packet and the start of the next frame, the check processPacket() makes of a packet.
  • An ACK followed by another ACK, rather than a packet, is now taken as the next frame instead of a parse error.
  • processWhileStreaming() no longer logs "Leaving while loop" on every pass while it waits for the rest of a frame.

Tested

  • AAPI_00005_StreamingAckAfterPauseTest replays a logging stop, then a status reply, a battery reply, a queued GET's reply or a queued SET's bare ACK in the pause, in every link CRC mode that can send it and in reads of every size. Without the fix all four cases fail, and the unqueued-read case fails with the CRC off. A fifth checks that a reply that isn't due is not taken.
  • Android HIL on a Shimmer3 (3E36, Classic, from a phone), with the inStream scenario from the HIL scenarios PR:
    • without the fix (DEV-1149: handle in-stream responses once, whole, and by opcode #122 + master): 2 of 15 status replies lost, 10 parser errors;
    • with it: every run that finished decoded all its replies with no parser error.
    • Not explained yet: with the CRC off, 1 of 5 runs had a logging-stop timeout although every reply was decoded; with the 2-byte CRC, one run decoded 14 of 15 battery replies with no parser error, which looks like DEV-1248 but isn't proven.
    • 5 of 12 inStream runs hung in the DEV-1266 lock-order deadlock, which is in the driver and fixed in 0.11.11_beta. Android is still pinned to 0.11.7_beta; the HIL will be rerun after the pin bump.

🤖 Generated with Claude Code

JongChern and others added 2 commits October 22, 2026 13:38
After STOP_LOGGING_ONLY_COMMAND the unit stops sending data packets for about
100 ms while it closes its SD file. A command sent in that pause is answered
at once, so its ACK comes straight after the previous ACK, with no data packet
before it. processPacket() only looks for an ACK after a data packet, so it
threw the reply away a byte at a time. A queued command then timed out, and
while streaming the timeout clears every queued instruction. The Java HIL
found it on a Shimmer3 and a Shimmer3R (DEV-1269).

This ports the driver's DEV-1291 fix. Shimmer overrides the streaming parser,
so the driver's fix doesn't reach it. processWhileStreaming() now looks for an
ACK at the start of the buffer first. It takes one only while a reply is due,
and only when the bytes after it are that reply:
- an in-stream reply (FF 8A, then the response opcode) to the queued GET
  command in flight, or to a read that readBattery() or
  readStatusLogAndStream() wrote straight to the socket. Those two are not
  queued, so Shimmer now keeps the response opcodes they await;
- for the queued SET command in flight, a bare ACK whose link CRC checks out.
So a 0xFF data byte the parser resyncs onto is not taken for one. An in-stream
reply is parsed whole from the buffer by DEV-1149's parser, which now takes
the ACK's position.

Unlike the driver, Shimmer can send a read in the pause without a link CRC,
because it doesn't queue the read. The ACK before the reply is then followed by
another ACK rather than a packet, which processPacket() took for a parse error.
It now treats it as the next frame.

AAPI_00005 replays a logging stop, then a status reply, a battery reply, a
queued GET's reply or a queued SET's bare ACK in the pause, in each link CRC
mode that can send it and in reads of every size. Without the fix, all four
fail. A fifth checks that a reply that is not due is not taken.

Stacked on DEV-1149 (#122), whose in-stream parser this builds on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…h no link CRC

The Android HIL found it on a Shimmer3 with the link CRC off. readBattery()
and readStatusLogAndStream() write their reads straight to the socket, so a
queued command's ACK can come straight after a read's reply, with no data
packet between them. With a link CRC on, the ACK's own CRC shows what it is,
and processAckAtStartOfBuffer() already took it. With none, it threw the ACK
away; STOP_LOGGING_ONLY_COMMAND then timed out, and the timeout cleared the
instruction queue.

Without a CRC, a bare ACK at the start of the buffer is now taken only for
the queued SET command in flight. The bytes after it must also be a data
packet and the start of the next frame, the same check processPacket()
makes of a packet.

processWhileStreaming() no longer logs "Leaving while loop" on every pass
while it waits for the rest of such an ACK's frame.

AAPI_00005 adds the case in every link CRC mode; without this change it fails
with the CRC off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JongChern

Copy link
Copy Markdown
Contributor Author

Verified with #122 on current master (24 Oct)

s3-be69 (Shimmer3, LogAndStream v1.1.7) over Classic, from an M2101K6G phone on Android 11. Current master (driver 0.11.11_beta), 1-byte link CRC. "Master + #122 + #133" is this branch merged into master.

Scenario master master + #122 + #133
inStream fails 2 of 2: 0 of 15 battery and 0 of 15 status replies decoded, 6 parser errors, and SD logging didn't stop in any round passes 2 of 2: 15 of 15 battery and 15 of 15 status replies, 0 parser errors, no command timeouts. 1 and 2 replies came in a pause and were taken
midStreamSet passes 2 of 2 passes 1 of 2

The midStreamSet failure isn't a parser problem. There were 0 parser errors, and all 4 gaps follow a startSDLogging(). One of them, 62 packets while the unit opened its SD file, began 1004 ms after the start. The HIL only forgives a gap within 1000 ms of a logging start, so it counted that one as loss elsewhere (1.23 %, against a 1 % limit).

Driver 0.11.11's DEV-1266 fix also removed the hangs that interrupted 5 of 12 inStream runs before.

🤖 Generated with Claude Code

@JongChern
JongChern merged commit 6da8bc0 into DEV-1149_instream_response_while_streaming Oct 24, 2026
JongChern added a commit that referenced this pull request Oct 24, 2026
…m_ack_after_pause

DEV-1291: take an in-stream ACK that comes with no data packet before it (#133, to master)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant