Repository navigation
DEV-1145: drop a bare ACK's link CRC while connected, so a stream started after a SET is seen - #213
Merged
Conversation
…rted after a SET is seen With a Bluetooth CRC on, the firmware frames every reply as the ACK, any response, then one CRC over both (ShimBt_sendRsp). So the reply to a SET command is a bare ACK followed at once by its CRC, which is always F4 65, or F4 in one-byte mode. While connected, ReadData drops a reply's CRC only after a first byte other than 0xFF, which is right for a response and never takes a bare ACK's CRC. F4 was read as a response code, and the CRC drop after it took the first byte of whatever arrived within ReadTimeout. When that was the ACK to START_STREAMING_COMMAND, mWaitingForStartStreamingACK never fired: the API stayed connected with no data while the device streamed. WriteAccelRange then StartStreaming delivered 0 of 66 packets with a one-byte CRC and 0 of 65 with two, against 64 of 65 with none. The connected ACK case now reads the byte after an ACK that neither the CRC switch nor START_STREAMING is waiting for. F4 is a bare ACK's CRC, and the rest of it is dropped. No response code is 0xF4 in any Shimmer3 or Shimmer3R firmware: every LogAndStream tag of shimmer3-firmware and shimmer3r-firmware, and log-and-stream-common's history, define 0xF4 only as a BMP180/280 register. Anything else is a response code, and the loop handles it next. It is held in a local rather than in UnalignedBytesReceived, which StartStreaming replaces from the caller's thread. ShimmerBareAckCrcTest drives the read loop against CrcLinkDevice: a stream started after one SET command and after three, in each CRC mode, and a reply read after a SET command. The stream cases fail without the fix. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 4, 2026
Merged
DEV-1147: consume a bare ACK's link CRC while streaming
ShimmerResearch/Shimmer-Java-Android-API#319
Merged
JongChern
approved these changes
Oct 20, 2026
JongChern
left a comment
Contributor
There was a problem hiding this comment.
Verified the premise the fix rests on: no response code is 0xF4, neither in log-and-stream-common's Comms/shimmer_bt_uart.h nor in any of this API's packet types (the only 0xF4 in the library is a trailing CRC in the S3 simulator's GET_STATUS reply). A bare ACK's CRC is F4 65 with ShimmerUartCrcCalc, so reading one byte after an ACK tells a bare ACK from a GET reply. The read-ahead runs only when neither the START_STREAMING nor #212's SET_CRC ACK is awaited, and the byte is kept in a read-thread local rather than UnalignedBytesReceived. CI on the merge with today's master (38ee5d0, which includes #214): unit tests 70/70, BLE tests and PublishNuGet pack green.
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.
DEV-1145.
The bug
With a Bluetooth CRC on, the firmware frames every reply as the ACK, then any response, then one CRC over the whole frame. See
ShimBt_sendRsp, log-and-stream-commonComms/shimmer_bt_uart.c:1827; the CRC is added at:2422-2426@ 599bd41.FF 04 lo hi <crc> <crc>FF F4 65The CRC of a bare ACK is a constant:
F4 65, orF4in one-byte mode. #212 hit this for the SET_CRC switch; this PR handles the general case.ReadData's connected-state loop drops a reply's CRC after the reply is handled, but only when its first byte was not0xFF. That is right for a GET, whose CRC follows its response. It never drops a bare ACK's CRC. What happens instead:F4is read as a response code and falls through toSDBT_switch's default.65, then the first byte of whatever arrives withinReadTimeout(1 s).START_STREAMING_COMMAND,mWaitingForStartStreamingACKnever fires. The API stays Connected and raises no data events while the device streams. The stream is then parsed as connected-state replies.The bug is on master already. Measured with
CrcLinkDevice,WriteAccelRange(1)thenStartStreaming():Who hits it: any caller that turns a CRC on, calls a
Write…setter, then callsStartStreaming(). The setters sleep 200–300 ms after sending, well inside the 1 s window.Who doesn't:
StartStreamingandLog, which sends GET_STATUS and sleeps 500 ms first.ShimmerConsoleAppExample, whoseWriteSensorsends with a calibration read and 1 s sleeps.The fix
With a CRC on, the connected-state ACK case now reads the byte after the ACK. It does this only when neither #212's CRC switch nor
START_STREAMINGis waiting for that ACK.F4is a bare ACK's CRC, and the rest of it is dropped.This works because no response code is
0xF4. I checked:Comms/shimmer_bt_uart.honmain, and its whole history, for a_COMMANDor_RESPONSEdefine of0xF4;LogAndStream*tag of shimmer3-firmware.The only
0xF4defines are BMP180/BMP280 chip registers (CTRL_MEAS), and this API has no packet type of0xF4. The web SDK'sShimmer3RClientrelies on the same fact: its framer recognises a bare ACK by checking a CRC over the ACK alone.The read never waits on anything but the link. The firmware hands each frame to the transmit path in one call (
ShimBt_writeToTxBufAndSend), so the byte after an ACK is always that same frame's next byte.Why a local variable and not
UnalignedBytesReceived. The loop does read that list first. ButStartStreaming,StartStreamingandLogandStartStreamingEXGSawtoothTestSignalreplace it from the caller's thread, which causes two problems:Count()check and[0]. That throws anArgumentOutOfRangeException, which the loop does not catch.A local in
ReadDatais touched only by the read thread.Unchanged:
Testing
ShimmerBareAckCrcTestruns the API's own read loop against #212'sCrcLinkDevice, which frames every reply as the firmware does.WriteAccelRange, one-byte CRCThe last test guards the new read-ahead, since every GET reply now goes through it. So do all of #212's switch tests, which read the sampling rate after each switch.
I ran the full
ShimmerAPITest.slnsuite in a fresh worktree, built with VS 2022 MSBuild and run under vstest.console as CI does: 51/51 pass. The build shows only the four pre-existing warnings, none in a changed file. No hardware test.Sibling implementations
None of them needs this fix:
Shimmer-Java-Android-API)mCurrentCommand), so it knows whether a response follows an ACK. It also clears the serial buffer before every write while not streaming.SwiftAPI)commandSent, and each bare-ACK branch removes the ACK and its CRC together.Shimmer3RClientframes by CRC, recognising a bare ACK from the CRC over the ACK alone.Shimmer3Clienthas no CRC support.TestSerialPortWrapper:
Shimmer-Labview-APIpins theShimmerAPINuGet package at 1.3.10, and this repo is at 1.3.11. It gets this fix only once a package that includes it is published and that pin is bumped.Related, not fixed here
ProcessNackFromCommand, and again in this same trailing drop, because0xFEis not0xFF. I've commented there.processPacketexpects0x00or0x8Aafter an ACK. Not yet reproduced.🤖 Generated with Claude Code