Repository navigation
DEV-1141: never send a 2-byte link CRC to Shimmer3R LogAndStream v1.00.024-v1.00.049 - #318
Merged
Merged
Conversation
…0.024-049 Those releases build the unsolicited status push in uint8_t selfcmd[6]. ACK + 0x8A 0x71 + two status bytes + a 2-byte CRC is seven bytes, so the sensor hardfaults the next time it pushes: on docking or undocking, the user button, a trial-duration expiry or a low battery (DEV-621, fixed in v1.00.050). writeBtCommsCrcMode is the only sender of SET_CRC_COMMAND, so the gate goes there. On those releases a 2-byte request returns false and queues nothing, and a 2-byte connect default (Consensys's "2-bytes CRC Enabled") falls back to 1 byte, the low byte of the same CRC. Other firmware is unchanged. The web SDK's route, turning the push's ACK prefix off with 0xA3 first, was not taken: this driver's in-stream parsers expect the prefix, so a push without it would be dropped when idle and resynced over while streaming. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 4, 2026
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 Java counterpart of the DEV-1141 fix in ShimmerResearch/shimmer-web-sdk#183. It keeps a 2-byte link CRC off the Shimmer3R firmware whose status push it overruns.
Defect
uint8_t selfcmd[6]inShimBt_instreamStatusRespSend(log-and-stream-commonComms/shimmer_bt_uart.c:2262at f39be8c1f).0x8A 0x71+ 2 status bytes. A 2-byte CRC makes it 7 bytes, and the 7th lands past the end of the buffer: the sensor hardfaults (DEV-621, fixed in v1.00.050).initializeShimmer3or3RsendsDEFAULT_BT_CRC_MODE_IF_SUPPORTEDat every connect. It is 1 byte by default, but Consensys's "2-bytes CRC Enabled" setting changes it throughsetDefaultBtCrcModeToUseIfFwSupported.enableBtCommsTwoByteCrc()andwriteBtCommsCrcMode(TWO_BYTE_CRC)send it directly. ShimmerAndroidAPI'sshimmerBasicExampleoffers it.Fix
isTwoByteCrcOverrunningStatusPush(). It isisSupportedUSBPluggedInStatus()and not v1.00.050 or later.isSupportedUSBPluggedInStatus()is the driver's existing gate for the second status byte (Shimmer3R LogAndStream v1.00.024 and later), so the two boundaries cannot drift apart.writeBtCommsCrcMode()refusesTWO_BYTE_CRCthere: it returns false and queues nothing. It is the only sender ofSET_CRC_COMMANDin the Java tree, so this covers both enable helpers and every consumer.getBtCrcModeToUseOnConnect()), with a debug log line. One byte is the low byte of the same CRC, so the link keeps its check. The static setting is left alone, so the next device still gets 2 bytes if it can take them.getDefaultBtCrcModeIfFwSupported()claimed it returned the mode in use once connected. It returns the setting, so the doc now says so.With #316's gate, the two combine as follows:
Why not the web SDK's route. The web SDK sends
SET_INSTREAM_RESPONSE_ACK_PREFIX_STATE(0xA3) with 0 before a 2-byte CRC, which makes the push 6 bytes. This driver's in-stream parsers assume the prefix is there:processBytesAvailableAndInstreamSupportedacts only on a leading0xFF, then clears the buffer.processPackettreats a bare0x8Aafter a data packet as a bad header.Teaching both of those, and the in-flight-command path, a prefix-less push would change parsing shared by every Shimmer3 and Shimmer3R. That would buy 2 bytes on 26 releases that already have a fixed successor.
Testing
New
API_00026_Shimmer3rTwoByteCrcGateTest(5 tests, in ShimmerDriverPC):writeBtCommsCrcMode()andenableBtCommsTwoByteCrc(), and nothing is queued. 1 byte and off are still queued.Proof the tests catch the bug: with the refusal and the fallback disabled (the predicate left in),
twoByteCrcIsRefusedWhereItOverrunsThePushandtwoByteDefaultFallsBackToOneByteWhenConnectingfail, and the other three pass.Full suites (JDK 11, Gradle 8.14.3):
cd ShimmerDriver && ./gradlew testcd ShimmerDriverPC && ./gradlew build -iNot verified on hardware
No Shimmer3R on v1.00.024 to v1.00.049 has been run against this. The fix rests on the firmware source, as read for DEV-1141, and on the instruction stack.
To check on one:
getCurrentBtCommsCrcMode()reports 1 byte.After merge: consumers
None of these picks this up on its own:
shimmerdriverandshimmerbluetoothmanagerat 0.11.7_beta.shimmerdriver0.11.8_beta is already published without this, so it needs a newshimmerdriverrelease and both pins bumped.shimmerBasicExampleignores the return ofenableBtCommsTwoByteCrc()(MainActivity.java:131). After the bump, a refused 2-byte choice would still show as selected, so that is worth fixing in the same change.libs/ShimmerJavaClass.jar. It is not exposed to this defect: none of its scripts choose a CRC mode, so it runs the 1-byte default. DEV-976: stop turning the link CRC on for Shimmer3R firmware that drops it at a stop #316 already needs that jar rebuilt, and rebuilding after both merge carries both fixes.Siblings (CLAUDE.md §4)
InitializeShimmer3SDBT()writes whatever CRC mode the caller passes, and the shipped console example passesTWO_BYTE.Shimmer3Protocol.connect()turns on a 2-byte CRC at every connect, before reading any version. Not changed here.🤖 Generated with Claude Code