Repository navigation
DEV-976: refuse a Bluetooth CRC on Shimmer3R firmware that drops it when sensing stops - #211
Merged
Merged
Conversation
…hen sensing stops Shimmer3R LogAndStream 0.0.2 to 1.0.10 (November and December 2024) turn the Bluetooth CRC off by themselves whenever sensing stops: in S4Sens_stopSensing (s4_sensing.c:354 at LogAndStream_Shimmer3R_v1.00.010), and in S4Sens_checkStartStreamingConditions when a stream stops while logging carries on. Between them they cover STOP_STREAMING, STOP_SDBT and STOP_LOGGING, and the user button or docking ending SD logging, and nothing tells the host. The stop's own ACK still carries the CRC, but every reply after it is bare. StopStreaming and StopStreamingandLog never change BluetoothCRCMode, so the API went on taking CRC bytes out of replies that no longer had them. The first is the GET_STATUS that the LogAndStream StopStreaming sends straight after the stop, and a later stream on the same link had every packet read as PacketSize+N. shimmer3r-firmware c8016de3 removed the clears, so 1.0.11 is the first release that keeps the CRC. IsCRCSupported() was GetCompatibilityCode() >= 8, and every Shimmer3R LogAndStream gets code 8. It now also requires KeepsCRCWhenSensingStops(), a new public check that is false for Shimmer3R LogAndStream before 1.0.11. So: - WriteCRCMode(ONE_BYTE or TWO_BYTE) on those releases throws, sends nothing, and names 1.0.11. WriteCRCMode(OFF) is never refused where the command exists, so a caller that turns it off to be safe still can. - A constructor's CRC mode is applied while connecting, where an exception would fail the connection. So the device connects without a CRC, and a MSG_IDENTIFIER_NOTIFICATION_MESSAGE with MSG_WARNING says why. That step moves into WriteCRCModeToSetup() so it can be tested. On those releases the connect-time OFF write is no longer sent either. The firmware clears its CRC at startup and on every disconnect, so the link starts without one anyway. - ShimmerCapture's CRC checkbox follows IsCRCSupported(), so it is now hidden on those releases, as it is on firmware without the command. Refusing, rather than dropping the API's expectation after a stop, is the only answer that also covers the stops the device makes on its own. Shimmer3 and Shimmer3R version numbers overlap, and no Shimmer3 firmware clears the CRC at a stop, so the hardware version decides and Shimmer3 is unchanged. The hardware is taken as reported, which lets one build through: LogAndStream_Shimmer3R_v1.00.008, a side build for older Consensys, reports hardware 3 and cannot be told from a Shimmer3 on LogAndStream 1.0.8. The web SDK makes the same call (shimmer-web-sdk#178). ShimmerCrcFirmwareTest pins the boundary on a ShimmerLogAndStream with no connection: Shimmer3R LogAndStream 1.0.10 refused, 1.0.11 allowed, Shimmer3 LogAndStream 1.0.8 allowed, OFF never refused, and the constructor path warning instead of throwing. Restoring the old gate, moving the boundary to 1.0.10, or dropping the hardware check each fail 3 of its 7 tests. All 35 ShimmerBluetoothTests pass (Visual Studio's MSBuild, vstest.console). Derived from the firmware source. No Shimmer3R on 1.0.10 or earlier has been run against this change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The KeepsCRCWhenSensingStops comment said S4Sens_checkStartStreamingConditions also clears the CRC when a stream stops while logging carries on. No stop reaches that clear. BtUart_processCmd runs as TASK_BTPROCESS, and with USE_FREERTOS 0 the scheduler always runs the lowest pending task bit first, so TASK_STOPSENSING (bit 12) runs before TASK_SAVEDATA (bit 17). S4Sens_stopSensing resets btstreamCmd to IDLE before saveData can see the STOP that s4_sensing.c:199 waits for. With logging still on, the CRC stays on. So the clear that matters is S4Sens_stopSensing's (s4_sensing.c:354 at LogAndStream_Shimmer3R_v1.00.010), and it runs only once every active mode has been told to stop: on STOP_SDBT, on STOP_STREAMING while only streaming, and on STOP_LOGGING, the user button or docking while only logging. This is also how shimmer-web-sdk#178 reads the same source. Comment only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 4, 2026
Merged
JongChern
approved these changes
Oct 20, 2026
JongChern
left a comment
Contributor
There was a problem hiding this comment.
Verified against shimmer3r-firmware: setBtCrcMode(CRC_OFF) at s4_sensing.c:354 in LogAndStream_Shimmer3R_v1.00.010, removed by c8016de3, which v1.00.011 is the first tag to contain. The gate refuses exactly Shimmer3R LogAndStream < 1.0.11 (compareVersions is >=), matching Java #316 and web SDK #178. CI re-run against today's master: all green (unit tests 47/47, PublishNuGet pack).
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-976. The C# side of ShimmerResearch/shimmer-web-sdk#178 (merged) and ShimmerResearch/Shimmer-Java-Android-API#316 (open), which refuse a CRC on the same firmware.
Problem
Shimmer3R LogAndStream 0.0.2 to 1.0.10 (November and December 2024) turn the Bluetooth CRC (
SET_CRC_COMMAND, 0x8B) off by themselves when sensing stops, and nothing tells the host. In shimmer3r-firmware atLogAndStream_Shimmer3R_v1.00.010,S4Sens_stopSensingclears it (S3R_Production/S4_App/s4_sensing.c:354) once every active mode has been told to stop:The stop's own ACK still carries the CRC, but every reply after it is bare. shimmer3r-firmware c8016de3 removed the clears, so 1.0.11 is the first release that keeps the CRC. Every release also clears it at startup and on disconnect (
shimmer_bt_comms.c:1068and:2543).This API never notices:
IsCRCSupported()wasGetCompatibilityCode() >= 8, andSetCompatibilityCodegives every Shimmer3R LogAndStream code 8, so these releases passed.StopStreamingandStopStreamingandLogsleep and flush, but never changeBluetoothCRCMode.StopStreamingsends GET_STATUS 300 ms after the stop, and that is the first reply misread. From then on the parser takes N "CRC" bytes after each response. A later stream on the same link has every packet read as PacketSize+N, so its packets fail the CRC check. This lasts until a reconnect.A CRC is only on when the caller asked for one: the
CRCmodeconstructor argument, a directWriteCRCModecall, ShimmerCapture's CRC checkbox (ONE_BYTE), or ShimmerConsoleAppExample (TWO_BYTE).Fix
IsCRCSupported()now also requires the new publicKeepsCRCWhenSensingStops(), which is false for Shimmer3R LogAndStream before 1.0.11.IsCRCSupported()WriteCRCMode(ONE_BYTE / TWO_BYTE)WriteCRCMode(OFF)CRCmodeconstructor argumentMSG_IDENTIFIER_NOTIFICATION_MESSAGEwithMSG_WARNINGsays whySetupDeviceconstructors without a CRC mode)SET_CRCon these releases tooOn every other firmware, Shimmer3 included, nothing changes.
How a refusal surfaces. The constructor path warns rather than throws, because it runs inside
Connect().Connect()'s catch turns any exception into "Unable to connect to specified port" and gives up on the connection. AMSG_WARNINGnotification is howShimmerLogAndStreamalready reports problems that do not stop it, such as streaming-only mode on the dock. That step moves intoWriteCRCModeToSetup()so it can be tested. A directWriteCRCModecall throws, as it already does on firmware without the command. Callers that checkIsCRCSupported()first now skip the CRC instead of getting the exception.Why refuse. Refusing is the only answer that covers every stop. Dropping the API's own expectation after
StopStreamingwould miss the stops the device makes by itself (user button, docking), and nothing tells the host about those.Why the hardware is checked. Shimmer3 and Shimmer3R version numbers overlap, and no Shimmer3 firmware clears the CRC at a stop, so the hardware version decides. The hardware is taken as the device reports it, which lets one build through.
LogAndStream_Shimmer3R_v1.00.008is a side build for older Consensys: it setsOLD_CONSENSYS_SUPPORT 1, and soDEVICE_VER 3. It cannot be told from a Shimmer3 on LogAndStream 1.0.8. The web SDK and Java make the same call.A correction in the second commit. The first commit's message, and its version of the
KeepsCRCWhenSensingStopscomment, also creditS4Sens_checkStartStreamingConditions(s4_sensing.c:199) with a clear when a stream stops while logging carries on. No stop reaches that clear. WithUSE_FREERTOS 0the scheduler runs the lowest pending task bit first. SoTASK_STOPSENSING(bit 12) always runs beforeTASK_SAVEDATA(bit 17), andS4Sens_stopSensingresetsbtstreamCmdto IDLE beforesaveDatacan see the STOP that:199waits for. With logging still on, the CRC stays on. b24c2c4 corrects the comment. Behaviour is unchanged.Tests
ShimmerUnitTests/ShimmerCrcFirmwareTestruns on aShimmerLogAndStreamwith no connection behind it, which records what it would have sent:WriteCRCMode(ONE_BYTE)and(TWO_BYTE)throw naming 1.0.11, nothing is sent, and the mode stays OFF.8B 02.8B 01.WriteCRCMode(OFF)on 1.0.10 still sends8B 00.MSG_WARNING. On 1.0.11, and on a Shimmer3 on 1.0.8, it is sent with no warning.The test fails without the fix. Each row below is a separate build of the library, run against the same test:
ShimmerBluetooth.csandShimmerLogAndStream.cs, plus only the two members the test calls, behaving as master doesIsCRCSupported()back tocompat >= 8)Built with Visual Studio 2022's MSBuild (a full rebuild of
ShimmerAPITest.sln) and run undervstest.console, as CI does.Hardware: unverified. This rests on the firmware source and a recording test double. No Shimmer3R on LogAndStream 1.0.10 or earlier has been run against this change. To check on one: construct a
ShimmerLogAndStreamwithBTCRCMode.TWO_BYTEand connect. You should get theMSG_WARNING. Then start and stop streaming, and confirm the GET_STATUS after the stop is answered.Other copies in this repo
ShimmerCaptureXamarin/ShimmerBluetooth.csandShimmerAPI/TestSerialPort/Program.cshave no CRC code, so there is nothing to change. Xamarin carries only theSetCrcCommandvalue, in itsLiteProtocolInstructionSet.cs.ShimmerUnitTests/ShimmerBluetoothReadData.cshidesWriteCRCModewithnewand only setsBluetoothCRCMode, so the parser tests can force a CRC on. It sets no firmware version, so the realWriteCRCModewould already have thrown there before this change. It bypasses the gate by design and is unchanged. It only hides the method rather than overriding it, so library code that callsWriteCRCModestill reaches the gated one.Wrappers and consumers
ShimmerLabviewC#Wrapper/packages.config). It picks this change up only when it is rebuilt against a ShimmerAPI release that contains it. It is not exposed in the meantime.ShimmerBridge.csuses the two-argumentShimmerLogAndStreamSystemSerialPortconstructor, which leavesSetupDevicefalse, and never callsWriteCRCModeorIsCRCSupported. So it never turns a CRC on, and its traffic will not change when it is rebuilt.SET_CRC_COMMAND,WriteCRCModeorBTCRCMode, so it never turns a Shimmer3/3R link CRC on.Sibling APIs
isBtCrcModeSupported()is narrowed the same way, OFF is never refused, and the connect-timeSET_CRCis skipped on these releases. Java is the more exposed of the two, becauseinitializeShimmer3or3Rturns a one-byte CRC on at every connect by default.Shimmer3Protocol.connect()sendssendCRCCommand(crcMode: TWO_BYTE)before it has read the firmware version.Overlap with open PRs
Checked with
git merge-treeagainst this branch:IsCRCSupported,WriteCRCMode,SetCompatibilityCodeor the connect-time setup. DEV-1107: BMP581 pressure sensor support (Shimmer3R streaming + SD log) #208 and DEV-1123: read the pressure sensor ID from SD header byte 224 #210 addcompareVersionsgates for the pressure sensor only.BluetoothCRCMode. This PR leaves that OFF on the refused releases, so the two compose.ShimmerBluetooth.csandShimmerLogAndStream.cs, but it already conflicts with master.🤖 Generated with Claude Code