Skip to content

DEV-1275: Report a Shimmer ready only once its connect sequence has ended - #333

Merged
JongChern merged 1 commit into
masterfrom
DEV-1275_ready_after_connect_sequence
Oct 22, 2026
Merged

JongChern merged 1 commit into
masterfrom
DEV-1275_ready_after_connect_sequence

Conversation

@JongChern

Copy link
Copy Markdown
Contributor

The bug

The connect sequence reads the unit's status part way through. Battery, BT firmware version, the calibration dump and the inquiry are still to come at that point.

On that status reply, ShimmerPC.eventLogAndStreamStatusChanged() moved the state from CONNECTING to CONNECTED. ShimmerDeviceCallbackAdapter marks every CONNECTED as initialised. So an app waiting for CONNECTED and initialised was told the unit was ready while the rest of the sequence was still queued.

Whatever the app did next went out in among that sequence. The Java HIL (#331) hit two symptoms on real units:

  • Streaming started part way through the sequence. A reply from the connect sequence landed in the stream, the parser threw it away, and the stream went silent. Shimmer3R, 1 of 10 reconnects.
  • A configure cut the calibration dump short. It took over the queue while the dump was being transferred. Every calibrated accel sample from the Shimmer3 was then NaN: 7 of 9 runs, and 1 of 3 after the unit was recalibrated.

The fix

The sequence's own end already moves CONNECTING to CONNECTED and sends NOTIFICATION_SHIMMER_FULLY_INITIALIZED. That is inquiryDone(), then isReadyForStreaming(). A status reply now leaves CONNECTING to it. One condition in ShimmerPC.eventLogAndStreamStatusChanged():

if(!mIsStreaming && !isSDLogging() && isConnected()
        && mBluetoothRadioState!=BT_STATE.CONNECTED && mBluetoothRadioState!=BT_STATE.CONNECTING){

At CONNECTED, every read of the unit's configuration has been answered. The only thing that can still be queued is the RTC write that the status reply queues when the unit's clock isn't set. It runs before anything the app queues.

Behaviour change

CONNECTED now arrives a few hundred ms later than before: after the inquiry, not after the status read.

A connect whose inquiry reply never arrives now stays CONNECTING. Before, the status reply made it look ready, even though its packet format was never read.

Tests

  • API_00031_ConnectReadyAfterConnectSequenceTest (new) connects to the Shimmer3 simulator, whose sequence reads the status before the inquiry. It checks that CONNECTED comes only after isReadyForStreaming(), with no read of the connect sequence still queued. It fails without the fix.
  • ByteCommunicationSimulatorS3R now answers INQUIRY with a Shimmer3R's 11 bytes of settings. It inherited the Shimmer3's 8, which a Shimmer3R never parses, so the inquiry always timed out. Its 8 tests had only passed on the early CONNECTED, and they all failed with the fix until the simulator was corrected. The settings match the simulator's InfoMem.
  • ShimmerDriverPC: 67 of 67 pass.

On hardware

These runs used the Java HIL from #331, not yet merged, built locally together with this fix and the DEV-1291 fix (#332). The units were a Shimmer3 (RN4678, LogAndStream v1.1.7) and a Shimmer3R (v1.1.21), over Classic, with nothing else on the bench.

Before With the fix
Shimmer3 streamRest: calibration dump read before the configure 0 of 9 runs complete (0, 128 or 256 of 538 bytes) 5 of 5 runs complete, 340 of 340 bytes
Shimmer3 accel at rest NaN in 7 of 9 runs 9.88–9.89 m/s² in 5 of 5
Full HIL run, both units the Shimmer3's streamRest failed on NaN 8 of 8 scenarios pass

Other APIs

  • Android: its own Classic class Shimmer.java sets CONNECTED unconditionally on a status reply, in its logAndStreamStatusChanged(). It overrides this method, so this fix won't reach it. The port is a separate PR in ShimmerAndroidAPI.
  • C#: not affected through the status reply. It has a cousin, though: it reports CONNECTED at the inquiry, before the last steps of its LogAndStream connect (baud rate, pressure calibration, RTC write).
  • pyshimmer, shimmer-logandstream, Swift, web SDK: not affected. Each signals ready only once its whole handshake is done.

🤖 Generated with Claude Code

The connect sequence reads the unit's status part way through. On that
reply, ShimmerPC.eventLogAndStreamStatusChanged() moved the state from
CONNECTING to CONNECTED, and ShimmerDeviceCallbackAdapter marks every
CONNECTED as initialised. So an app waiting for CONNECTED and initialised
was told the unit was ready while the battery read, the calibration dump
and the inquiry were still queued.

Whatever the app did next went out in among that sequence:
- streaming started part way through it, and a reply from the connect
  sequence landed in the stream, which then went silent;
- a configure cut the calibration dump short, which left a Shimmer3's
  calibrated accel NaN in every sample (7 of 9 runs on the HIL).

The sequence's own end, inquiryDone() and then isReadyForStreaming(), already
moves CONNECTING to CONNECTED and sends NOTIFICATION_SHIMMER_FULLY_INITIALIZED.
A status reply now leaves CONNECTING to it.

The Shimmer3R simulator answered INQUIRY with the Shimmer3's 8-byte settings,
which never parse as a Shimmer3R's 11. Its tests had only ever passed on the
early CONNECTED, before the inquiry timed out. It now answers with settings
that match its own InfoMem.

API_00031 connects to the Shimmer3 simulator, whose sequence reads the status
before the inquiry. It checks that CONNECTED comes only after the sequence's
end, with nothing but the RTC write still queued. It fails without the fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JongChern

Copy link
Copy Markdown
Contributor Author

Combined hardware verification. This used the Java HIL from #331 on a local merge of #331, #332, #333 and #334. The units were a Shimmer3 (LogAndStream v1.1.7) and a Shimmer3R (v1.1.21) over Bluetooth Classic, with nothing else on the bench.

  • Default 1-byte CRC: all 10 scenario runs passed: streamRest, midStreamSet, reconnectLoop, inStream and queueStress, on both units. There were 0 parser errors and 0 command timeouts.
  • Unit tests on the same merge: ShimmerDriverPC 85 of 85, ShimmerDriver 177 of 177.
  • This fix (DEV-1275): DEV-1269: Java HIL v1, the driver on real Shimmer3/3R over Classic, and a release gate #331 now checks every connect directly. 0 of 18 connects reported CONNECTED before the connect sequence ended. Without this fix, the same check failed 5 of 5 connects on the Shimmer3R. The calibration dump was read in full on both units, and the Shimmer3 reads 9.885 m/s² at rest.

@JongChern
JongChern merged commit 0cfa28a into master Oct 22, 2026
2 checks passed
@JongChern
JongChern deleted the DEV-1275_ready_after_connect_sequence branch October 22, 2026 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant