Repository navigation
DEV-1452: decode a Shimmer3's alternative accel and mag (0x14-0x19) - #233
Merged
Merged
Conversation
InterpretDataPacketFormat gave channels 0x14-0x19 a name, data type, size and enabled-sensor bit only on a Shimmer3R. On a Shimmer3 they took no bytes, so a stream with the alternative accelerometer or magnetometer on was framed 6 bytes short per sensor from the first packet. On a Shimmer3, 0x14-0x16 are the MPU-9150/9250 or ICM-20948 accelerometer (int16 big-endian) and 0x17-0x19 its AK8975/AK8963/AK09916 magnetometer (int16 little-endian), packed after the magnetometer and before the pressure sensor. They now decode as "Alternative Accelerometer X/Y/Z" and "Alt Magnetometer X/Y/Z", RAW only, as the API holds no Shimmer3 calibration for them. On a Shimmer3 they no longer count toward the 3D orientation, since they are uncalibrated there. The Shimmer3R's high-g accel and alt mag decode as before. ShimmerSDLog had the same gap for Shimmer3 files, which carry no channel list: the record layout it built from the header's sensor bits left both sensors out, so a file with either on was mis-framed, and BuildMsg reported "High G Accelerometer" and "Alt Magnetometer" values read from the timestamp. It now adds them in the firmware's order. 12 new tests, 10 of which fail on the old code. VSTest 136/136. Co-Authored-By: Claude Opus 5.5 <[email protected]>
JongChern
approved these changes
Nov 17, 2026
JongChern
left a comment
Contributor
There was a problem hiding this comment.
Approved. I made no changes.
What I checked:
- The rule matches the Java driver's fix (ShimmerResearch/Shimmer-Java-Android-API#347): on a Shimmer3, 0x14-0x16 are int16 big-endian and 0x17-0x19 are int16 little-endian, two bytes each, raw only.
- The SD file change sits inside the Shimmer3-only layout, so a Shimmer3R file is read as before.
- The orientation gate: a Shimmer3's uncalibrated alternative sensors no longer count toward it.
- CI runs the unit test project and passes. I did not build the solution locally.
One thing to know, not blocking: the channel names differ from the Java driver's. This API uses "Alternative Accelerometer X" and reuses the Shimmer3R's "Alt Magnetometer X". The Java driver uses Accel_MPU_X and Mag_MPU_X. The two APIs already name channels differently, so I am leaving it.
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-1452. A Shimmer3 streaming with the alternative accelerometer or the alternative magnetometer on was mis-framed from the first packet, and a Shimmer3 SD file with either on was mis-read.
The defect
InterpretDataPacketFormatgave channels 0x14-0x19 a name, a data type, 2 packet bytes and an enabled-sensor bit only underShimmerVersion.SHIMMER3R. On aSHIMMER3the arms matched but did nothing, so each channel took 0 bytes: the packet size was 6 bytes short per sensor, every channel after them was read from the wrong offset, and the read loop lost framing.ShimmerSDLoghas the same gap for Shimmer3 files. They carry no channel list, so the reader builds the record layout from the header's enabled-sensor bits, and it had no entries for bit 22 (alt accel) or bit 21 (alt mag). A file with either on was read 6 bytes short per record per sensor. Worse, those header bits are the same asSENSOR_ACCEL_ALT/SENSOR_MAG_ALT, soBuildMsgwent into the Shimmer3R blocks, could not find the High G or Alt Magnetometer channels, andgetSignalIndexfell back to index 0: it reported "High G Accelerometer X/Y/Z" and "Alt Magnetometer X/Y/Z" as the timestamp, calibrated with the Shimmer3R ADXL371 and LIS3MDL defaults. Checked on the old code with a three-record file: packet size 14 instead of 26, and every one of those six channels read RAW 4096, the first timestamp.What a Shimmer3 sends
From shimmer3-firmware
LogAndStream_Shimmer3/i2c.c(I2C_configureChannels, and the copy into the data buffer in the same file) and log-and-stream-commondocs/SHIMMER3_STREAMING_DATA_FORMAT.md(the channel table, section 4.1 rows 14-15, section 5.2):ACCEL_XOUT_HHXLPacket order: LN accel 0x00-0x02, VBATT 0x03, ADCs, gyro 0x0A-0x0C, WR accel 0x04-0x06, mag 0x07-0x09, alt accel 0x14-0x16, alt mag 0x17-0x19, BMP 0x1A/0x1B, ExG. The SD record is the same bytes as the streamed packet, without the packet type. Enabled-sensor bits are the Shimmer3R's:
SENSOR_ACCEL_ALT0x400000,SENSOR_MAG_ALT0x200000.The fix
InterpretDataPacketFormat: each of the six arms gets aSHIMMER3branch. 2 bytes,i16rfor 0x14-0x16 andi16for 0x17-0x19, and the enabled-sensor bit. The accelerometer gets new names,Shimmer3Configuration.SignalNames.ALTERNATIVE_ACCELEROMETER_X/Y/Z("Alternative Accelerometer X/Y/Z"), because the existing High G names are the Shimmer3R's ADXL371. The magnetometer reusesALT_MAGNETOMETER_X/Y/Z.BuildMsg: the existing alt accel and alt mag blocks, which calibrate with Shimmer3R matrices, now run only on a Shimmer3R. A Shimmer3 gets RAW only, no CAL, since the API holds no Shimmer3 calibration for these sensors. On a Shimmer3 they don't writeaccelerometer[]/magnetometer[]and don't count toward the 3D-orientation condition, since they are uncalibrated there.ShimmerSDLog: a Shimmer3 file's layout gets the alt accel (bit 22,i16r) and alt mag (bit 21,i16) after the magnetometer and before the pressure sensor, the firmware's order.i12*>High G, 0x17-0x19i16Alt Magnetometer, both calibrated, and both still count toward the orientation.Tests
ShimmerUnitTests/ShimmerAltAccelMagDecodeTest.cs, 12 tests throughInterpretDataPacketFormat+BuildMsg, orShimmerSDLogfor the file. The main fixture is the one the Java driver's fix (DEV-1451) uses: an ICM-20948 board with no LSM303 fitted, so the alt accel carries the same chip reading as the WR accel (which the firmware byte-swaps to little-endian and negates in Y) and the alt mag the same reading as the mag (negated in Z). 19 channels, 41 bytes after the packet type.u16r, 0x1Bu24r) is read at the right offset.i12*>/i16, High G and Alt Magnetometer names, CAL present.Run against the old
ShimmerBluetooth.csandShimmerSDLog.cs, with only the three new name constants added so that the tests compile, 10 of the 12 fail. Packet sizes come out 29 / 9 / 9 / 9 / 8 where 41 / 15 / 15 / 21 / 20 are expected, the enabled bits come out 0, and the alt channels are missing. The SD test fails too. The two Shimmer3R tests pass on both. Removing only the orientation gate makes the Shimmer3 orientation test fail.Whole VSTest project (
ShimmerBluetoothTests.dll): 124/124 on master before, 136/136 after.The same logic elsewhere in this repo
ShimmerAPI/ShimmerAPI/ShimmerSDLog.cs: same defect, fixed and tested here (above).Shimmer32FeetAPI: no parser of its own.Shimmer32Feet,ShimmerLogAndStream32FeetandShimmerLogAndStream32FeetBLEextendShimmerBluetooth/ShimmerLogAndStream, so they get this fix.ShimmerCaptureXamarin/ShimmerCaptureXamarin/ShimmerBluetooth.cs: not the same defect. It has no arms for 0x14-0x19 at all (it goes from 0x13 at line 2401 to 0x1A at line 2411), so they fall to the unknown-IDelseat line 2559, which gives each one 2 unnamed bytes. Framing is right and the values are dropped. Not changed: that copy is abandoned and has no Shimmer3R support.ShimmerAPI/TestSerialPort/Program.cs: no channel-list parser.Bench check, 16 Nov 2026
Two Shimmer3s on LogAndStream v1.01.009, both boards where the ICM-20948 stands in for the LSM303 (SR49-3-1 and SR31-9-1, RN4678 radios). On these boards the firmware fills the wide-range accel and the mag from the same ICM-20948 reading the alternative accel and mag carry, in the other byte order, so every sample can be checked exactly.
AltSensorDecoder(InterpretDataPacketFormat, thenBuildMsgper packet), framed at itsPacketSize(46 after the header), with no framing errors. That covers the pressure and temperature after the alternative mag too. Every raw value matched that layout, on every channel it decodes, in all 503 packets from each unit.🤖 Generated with Claude Code