Repository navigation
DEV-1147: consume a bare ACK's link CRC while streaming - #319
Merged
Merged
Conversation
With a Bluetooth link CRC on, the firmware appends one to a bare ACK too, so a SET command sent while streaming is answered FF F4 65 (FF F4 in 1-byte mode). processPacket() expected the next packet's 0x00 or an in-stream response's 0x8A after the ACK. It took F4 for a parse error and resynced, throwing away the data packet before the ACK and the ACK itself. 2 s later the ACK timeout cleared the instruction queue, so startSDLogging() on a streaming device never sent START_LOGGING_ONLY_COMMAND, queued behind the SET_RWC_COMMAND whose ACK was lost. processPacket() now recognises the bare ACK's CRC, waits for all of it, consumes the packet, the ACK and its CRC exactly once, and processes the ACK. The packet is passed on if its own CRC checks out. checkCrc() no longer discards bytes itself. Its caller already does, so a 2-byte CRC that failed on its second byte was discarded twice, past the start of the next packet. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 4, 2026
Merged
marknolan
added a commit
to ShimmerResearch/ShimmerAndroidAPI
that referenced
this pull request
Oct 4, 2026
AGENTS.md said this repo has no parsing logic of its own, so a protocol fix never needs porting here. That is wrong for the Bluetooth stream parser. Shimmer overrides processPacket(), processWhileStreaming(), processInstreamResponse() and clearSingleDataPacketFromBuffers() from the driver's ShimmerBluetooth, so a streaming-parse fix in the driver never reaches it, even after a republish and pin bump. The bare-ACK link-CRC fix in ShimmerResearch/Shimmer-Java-Android-API#319 is one that needs its own port. Decoding (processDataPacket() -> buildMsg()) and checkCrc() are still the driver's, and Shimmer3BLEAndroid uses the driver's parser. The section now says both. Verified on master 44b9cbc against the pinned driver, API_v0.11.7_beta. Docs only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Fixes DEV-1147.
Defect
ShimBt_sendRsp, log-and-stream-commonComms/shimmer_bt_uart.c). The reply to a SET command is thereforeFF F4 65, orFF F4with a 1-byte CRC:F4 65is the CRC of the single byte0xFF.processPacket()expected the byte after an ACK to be the next packet's0x00or an in-stream response's0x8A. It tookF4for a parse error ("Unknown parsing error while streaming") and resynced to the next0x00or0xFF, usually one inside the packet's own payload:processAckFromSetCommand()never ran;checkForAckOrRespTask, seeing a stream, cleared the whole instruction queue.startSDLogging()queuesSET_RWC_COMMANDand thenSTART_LOGGING_ONLY_COMMAND. The RTC write's ACK is lost, the timeout clears the queue, and START_LOGGING is never sent, so the device never starts logging. Consensys's Live Data panel calls this on a streaming device. Reproduced against the real ACK timer: the queue went from 2 to 0 andisSDLogging()stayed false.stopSDLogging()lost a packet and finished only on the timeout, whose STOP_LOGGING_ONLY special case reports success anyway.FF 8A …) were fine, because their CRC comes at the end. So was a bare ACK with the CRC off, which is followed by0x00.A second defect on the same path.
checkCrc()discarded bytes itself when a 2-byte CRC failed on its second byte, andprocessPacket()then discarded again. The second discard skipped past the start of the next packet, so that packet was lost as well.Fix
processPacket(), data packet followed by an ACK. When the bytes after the ACK are the bare-ACK CRC (isBareAckCrcSoFar(), checked againstBARE_ACK_CRC), it waits for the whole CRC and then:clearBytesFromStartOfBuffers());processAckWhileStreaming(), shared with the no-CRC path, which is otherwise unchanged).0xF4in any Shimmer3 or Shimmer3R firmware, and an in-stream response starts0x8A.checkCrc()only checks. Its caller decides what to discard.Testing
New
API_00027_StreamingBareAckCrcTest(10 tests, in ShimmerDriverPC). It feeds the streaming parser one byte at a time from an in-memory queue, as the IO thread does.startSDLogging()while streaming, with a 1-byte CRC, a 2-byte CRC and none. Both ACKs are processed, START_LOGGING_ONLY is still queued after the RTC write, every packet is parsed once and in order, and the ACK timer is cancelled. The payloads include0x00and0xFF, the bytes a resync stops on.Proof the tests catch the bug.
checkCrc()'s own discard put back, only the 2-byte second-byte test fails.Full suites (JDK 11, Gradle 8.14.3):
cd ShimmerDriver && ./gradlew testcd ShimmerDriverPC && ./gradlew build -iThe ShimmerDriverPC run includes the byte-level simulator suites that stream through this parser:
_CRC_Streaming,_Throw_Bytes,_Throw_Bytes_2and the contiguity checks.Not verified on hardware
No device has been run against this. To check on one:
Alongside the other open PRs
This branch trial-merges cleanly with #293 (DEV-982), #316 (DEV-976), #318 (DEV-1141) and #279 (DEV-895).
discardBufferBytesToNextPacket(). Both are left untouched.checkCrc(), so it picks up the single discard too.After merge: consumers
Shimmer.javaoverridesprocessPacket()andprocessWhileStreaming()with its own copy of the parser, which has the same defect: onF4it throws the packet away a byte at a time and never processes the ACK. It needs its own fix there.checkCrc()and discards again itself, so the double discard goes once it is on a driver with this. It pinsshimmerdriver0.11.7_beta.libs/ShimmerJavaClass.jar, so the jar needs rebuilding and re-vendoring.Siblings (CLAUDE.md §4)
case ACK_COMMANDinReadDatareads the byte after the ACK. Because it is not0x8A, it drops the packet it is holding (KeepObjectCluster = null,ShimmerBluetooth.cs:1366-1369on master).0x00, the drop is not counted as packet loss, and nothing there waits for a streaming ACK.BuildMsgsends SET_BLINK_LED (0x30) as the battery crosses 3400 or 3000 mV, and firmware up to Shimmer3R v1.01.012 and Shimmer3 v1.01.003 ACKs 0x30.F4, read the rest of the CRC and keep the held packet. DEV-1145: drop a bare ACK's link CRC while connected, so a stream started after a SET is seen Shimmer-C-API#213 (DEV-1145) does the same in the connected state and does not touch the streaming branch.Shimmer3RClient: needs a fix.FF F4 (65)as junk, and recovers at the next packet._waitForAck, so the command rejects with "ACK timeout" after 1.5 s although the device ran it.setRtcTime()(SET_RWC) has no streaming guard, and theclearAnchor()after its await then never runs.Shimmer3Client: has no link CRC, so it cannot meet this case.Shimmer3Protocol.swift:606-625) neither checks a packet's header nor resyncs, so any non-data frame (a NACK, an unsolicited status push, a bare ACK) shifts every later packet for the rest of the session.timeoutInSecondsis unused.LiteProtocolhas its ownprocessPacket()but no CRC support.ShimmerGRPCandShimmerPCBTBCoveuseShimmerBluetooth's parser, so they get this fix.🤖 Generated with Claude Code