Skip to content

DEV-1431: a log start refused mid-stream ends at once - #153

Draft
marknolan wants to merge 1 commit into
masterfrom
DEV-1431_nack_refused_log_start
Draft

marknolan wants to merge 1 commit into
masterfrom
DEV-1431_nack_refused_log_start

Conversation

@marknolan

Copy link
Copy Markdown
Member

The Android half of DEV-1431: a log start the device refuses in the middle of a stream.

Draft, and it won't build in CI yet. It calls the driver's processNackFromCommand() and uses NACK_COMMAND_PROCESSED, which arrive with ShimmerResearch/Shimmer-Java-Android-API#293 and ShimmerResearch/Shimmer-Java-Android-API#345. The pinned driver, 0.11.12_beta, has neither. Once a Java API release carries both, rebase this onto (or fold it into) that release's driver_<version> bump PR. CI then runs it for real.

The problem

Firmware that cannot start a log (docked or on USB power, no SD card or a bad one, logging turned off in its configuration) is to NACK START_LOGGING_ONLY_COMMAND (ShimmerResearch/log-and-stream-common#228). Its rule doesn't look at streaming, so a 0x92 sent mid-stream is refused too, and the NACK comes between two data packets, followed by its own link CRC when the link has one (C5, or C5 56).

Shimmer.java has its own streaming parser (see AGENTS.md), so the driver's fix in #345 doesn't reach it. processPacket() had no NACK branch. It threw the NACK away a byte at a time along with the packet in front of it, and 2 s later the driver's ACK timer took the device for logging, a false success.

An idle refusal needs nothing here: when not streaming, Shimmer uses the driver's parser, and #345 handles it there.

The change

processPacket() gets the branch the driver's parser has in #345:

  • a data packet followed by a NACK waits for the NACK's CRC and checks it, as a bare ACK's already is;
  • exactly the packet, the NACK and its CRC are consumed;
  • a packet whose CRC fails is dropped without losing the NACK;
  • a 0xFE whose CRC does not match is not taken for a NACK;
  • the command in flight is failed by the driver's processNackFromCommand(). A refused log start is left not logging, and eventLogStartRefused() is called, which by default shows LOG_START_REFUSED_MESSAGE as a toast;
  • a NACK with no command in flight is ignored.

Tests

AAPI_00009_StreamingLogStartRefusedTest ports the driver's API_00037_StreamingLogStartRefusedTest, with every scenario replayed at every read size from 1 to 48 bytes:

  • a 0x92 refused between two packets, with no CRC, a 1-byte and a 2-byte CRC: refused at once, not logging, still streaming, every packet parsed, no bytes skipped;
  • a corrupt packet before the NACK, with a 1-byte and a 2-byte CRC;
  • a 0xFE whose CRC doesn't match;
  • a NACK with no command in flight.

Run locally against a build of #345's driver (-PdriverVersion pointed at it in the local Maven repository): the library's unit tests pass, 39/39, and assembleDebug builds the library and every example. Against master's Shimmer.java, 6 of the 7 new tests fail.

Not run on a phone, and not against firmware that NACKs.

DEV-1431

🤖 Generated with Claude Code

Firmware that cannot start a log (docked or on USB power, no SD card or a
bad one, logging turned off in its configuration) is to NACK
START_LOGGING_ONLY_COMMAND, including in the middle of a stream, the NACK
coming between two data packets with its own link CRC (C5, or C5 56).
Shimmer.processPacket() had no NACK branch: it threw the NACK away a byte
at a time with the packet before it, and 2 s later the driver's ACK timer
took the device for logging.

Ported from the driver's processPacket() (Shimmer-Java-Android-API #345,
DEV-1431, on top of #293's NACK handling): a data packet followed by a
NACK waits for the NACK's CRC and checks it, as a bare ACK's is; exactly
the packet, the NACK and its CRC are consumed; a packet whose CRC fails is
dropped without losing the NACK; a 0xFE whose CRC does not match is not a
NACK; and the command in flight is failed by the driver's
processNackFromCommand(), which leaves a refused log start not logging and
calls eventLogStartRefused (a toast here, by default). With no command in
flight a NACK is ignored. An idle refusal needs nothing here: it goes
through the driver's own parser.

Needs a driver release that has #293 and #345: processNackFromCommand()
and NACK_COMMAND_PROCESSED are not in 0.11.12_beta, so this does not
build against the current pin.

Test: AAPI_00009_StreamingLogStartRefusedTest, a port of the driver's
API_00037, every scenario at every read size from 1 to 48 bytes. Run
locally against a build of #345's driver: the library's unit tests
39/39, and assembleDebug builds the library and every example. Against
master's Shimmer.java 6 of the 7 new tests fail.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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