Repository navigation
DEV-1291: Take an in-stream ACK that comes with no data packet before it - #332
Merged
Merged
Conversation
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's CRC, with no data packet before it. processPacket() only looks for an ACK after a data packet, so it threw the reply away. The command then timed out, and while streaming the timeout clears every queued instruction, so whatever the user asked for next (including Stop Streaming) was silently dropped. The Java HIL found it on a Shimmer3 and a Shimmer3R: up to 4 of 5 status and battery requests sent after a logging stop were lost. processWhileStreaming() now looks for an ACK at the very start of the buffer first. It takes one only while a command waits for its ACK, and only when the bytes after it are what that command expects: - for a GET command, its own in-stream reply (FF 8A, then its response opcode); - for a SET command, a bare ACK whose link CRC checks out. So a 0xFF data byte the parser resyncs onto is not taken for one. It looks at no more than 3 bytes, fewer than processPacket() needs, so nothing else changes. Without a link CRC the case can't arise: the previous ACK isn't processed until the stream resumes, so the next command never goes out during the pause. API_00032 feeds the parser the bytes a logging stop produces, then a status reply, a battery reply, or a SET command's bare ACK in the pause, with 1- and 2-byte CRCs. Without the fix, all six of those cases fail. Two more check that an ACK at the start of the buffer is not taken for a different command. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Combined hardware verification. This used the Java HIL from #331 on a local merge of #331, #332, #333 and #334. The units were a Shimmer3 (LogAndStream v1.1.7) and a Shimmer3R (v1.1.21) over Bluetooth Classic, with nothing else on the bench.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 straight after the previous ACK's CRC, with no data packet before it:processPacket()only looks for an ACK after a data packet, so it threw the reply away:The command then timed out after 2 s. While streaming, the timeout calls
clearAllInstructions(), so whatever was queued behind it was silently dropped. That includes a Stop Streaming, which goes through the same queue.The Java HIL (#331) found it on a Shimmer3 (LogAndStream v1.1.7) and a Shimmer3R (v1.1.21). In each overlap, the HIL stops logging while streaming, then asks for status and battery at once. Up to 4 of 5 overlaps per run lost their replies.
The fix
Before
processPacket(),processWhileStreaming()now looks for an ACK at the very start of the buffer (processAckAtStartOfBuffer()). It takes one only while a command waits for its ACK, and only when the bytes after it are what that command expects:FF 8Athen its response opcode, matched as in DEV-1262. The rest of the reply and its CRC are read from the port as in the existing in-stream branch.So a 0xFF data byte that the parser resyncs onto is not taken for one. It never looks at more than 3 bytes, fewer than
processPacket()needs, so nothing else changes.Without a link CRC the case can't arise. The previous ACK isn't processed until the stream resumes, so the next command never goes out during the pause.
Tests
API_00032_StreamingAckAfterPauseTest(new, 8 tests) feeds the parser the bytes a logging stop produces, one at a time as the IO thread does. That is, a data packet and theSTOP_LOGGING_ONLYACK, then in the pause:each with a 1-byte and a 2-byte CRC. All 6 fail without the fix.
ShimmerDriverPC: 74 of 74 pass.ShimmerDriver: 177 of 177 pass.On hardware
These runs used the Java HIL from #331, not yet merged, built locally together with this fix and the DEV-1275 fix (#333). The units were a Shimmer3 and a Shimmer3R over Classic, with nothing else on the bench.
inStream: overlaps whose replies were lostinStreaminStreamfailed on bothOther APIs
Shimmer.javahas the same gap (TODO: ACK in bufferTemp[0] not handled). It overrides the driver's parser, so this fix won't reach it. The port is a separate PR in ShimmerAndroidAPI.🤖 Generated with Claude Code