Skip to content

DEV-1291: take an in-stream ACK that comes with no data packet before it (#133, to master) - #140

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

JongChern merged 2 commits into
masterfrom
DEV-1291_android_instream_ack_after_pause

Conversation

@JongChern

Copy link
Copy Markdown
Contributor

The same two commits as #133, this time to master. #133 merged into its base, #122's branch DEV-1149_instream_response_while_streaming, 51 s after #122 itself had merged to master. So the DEV-1291 port never reached master. This PR's diff against master is exactly #133's two commits; #122's commit is already there.

What it does (from #133)

Ports the driver's DEV-1291 fix to Android's own Classic streaming parser, Shimmer.processWhileStreaming():

  • an in-stream ACK that comes with no data packet before it, for example in the ~100 ms pause after STOP_LOGGING_ONLY_COMMAND, is taken instead of thrown away a byte at a time;
  • with no link CRC, a bare ACK straight after an unqueued battery or status read's reply is taken for the queued SET in flight.

AAPI_00005_StreamingAckAfterPauseTest covers both cases, in every CRC mode.

Verified (on #133, 24 Oct)

s3-be69 (Shimmer3, LogAndStream v1.1.7) over Classic, from an M2101K6G phone on Android 11, driver 0.11.11_beta, 1-byte CRC.

inStream master master + #122 + #133 (this code)
Battery replies 0 of 15 15 of 15
Status replies 0 of 15 15 of 15
Parser errors 6 0
SD logging stopped no, in any round yes

Master now has #122, so this is the build that was tested.

🤖 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 <[email protected]>
…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 <[email protected]>
@JongChern
JongChern merged commit 2f413b3 into master Oct 24, 2026
1 check passed
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