Skip to content

DEV-574 improved throw bytes performance and console prints#256

Merged
JongChern merged 16 commits intomasterfrom
DEV-574_corrupted_data_packed_passing_CRC
Jan 6, 2026
Merged

DEV-574 improved throw bytes performance and console prints#256
JongChern merged 16 commits intomasterfrom
DEV-574_corrupted_data_packed_passing_CRC

Conversation

@marknolan
Copy link
Copy Markdown
Member

  1. Even with checking for start 0x00/0xFF bytes on packets and with 2 byte CRC check, in bad conditions rare corrupted packets can slip through the net and appear as good packets. When this occurs, it can lead parsing to skip ahead 8.5mins as SW thinks a clock roll-over has mistakenly occurred. This PR adds a contiguous check to make sure packets are within 10 seconds of each other before parsing (number chosen arbitrarily).

  2. When issues occurred with packets, bytes were previously thrown one at a time looking for the next 0xFF or 0x00 bytes (i.e., the start of the next packet). This was not only inefficient but leads to significant console prints for each thrown byte. This PR scans for the index of the next 0xFF/0x00 and throws bytes up to that point all in one go.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds protection against corrupted data packets that pass CRC validation and improves the efficiency of byte discarding when packet synchronization errors occur. The changes address two main issues: (1) rare corrupted packets causing incorrect timestamp rollover detection, and (2) inefficient byte-by-byte discarding with excessive console output.

Key Changes

  • Added contiguous timestamp validation to reject packets with timestamps differing by more than 10 seconds from the previous packet
  • Replaced byte-by-byte discarding with bulk scanning to find the next packet start marker (0x00 or 0xFF)
  • Enhanced debug logging to include packet length information

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 11 comments.

File Description
ShimmerObject.java Added CONTIGUOUS_TIMESTAMP_TICKS_LIMIT constant and contiguous timestamp check logic to filter corrupted packets; added mLastReceivedTimeStampTicks field to track last valid timestamp
ObjectCluster.java Added successfullyParsed boolean flag to indicate when packets fail validation checks
ShimmerBluetooth.java Refactored discardFirstBufferByte() to discardBufferBytesToNextPacket() with bulk scanning; added findOffsetOfNextZeroOrFF() helper method; improved debug logging with packet lengths; added check to skip packets marked as unsuccessfully parsed

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@marknolan
Copy link
Copy Markdown
Member Author

@JongChern there are two aspects to this PR

  1. More efficient discarding of misaligned bytes and more efficient console prints related to this
  2. Contiguous packet check

I believe 1) is an improvement that's worthy of merging once reviewed.

Point 2 can be discussed if needed. I think it is an issue but it's only particularly prominent at the moment as the FW is dropping more bytes than usual due to an as yet to be determined bug.

I can separate out these points on two different PRs if needed.

@marknolan
Copy link
Copy Markdown
Member Author

@JongChern there are two aspects to this PR

  1. More efficient discarding of misaligned bytes and more efficient console prints related to this
  2. Contiguous packet check

I believe 1) is an improvement that's worthy of merging once reviewed.

Point 2 can be discussed if needed. I think it is an issue but it's only particularly prominent at the moment as the FW is dropping more bytes than usual due to an as yet to be determined bug.

I can separate out these points on two different PRs if needed.

I still believe point 1 is good. Please hold on point 2 until we resolve some issues with FW

@marknolan
Copy link
Copy Markdown
Member Author

@JongChern this PR is ready for review.

I've removed the contiguous check for the time being. There is still a chance that the fault can occur for which the contiguous check was aiming to catch but FW fixes have made it less of an issue. I was experiencing issues with the contiguous check so it would need further development which is a lower priority now that the chances of the issue occurring have been dramatically reduced.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

ShimmerDriver/src/main/java/com/shimmerresearch/bluetooth/ShimmerBluetooth.java:1321

  • @param tag "a" does not match any actual parameter of method "findOffsetOfNextZeroOrFF()".
	 * @param a byte array to search within

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@marknolan marknolan changed the title DEV-574 filter for corrupted data packed passing CRC and improved throw bytes performance DEV-574 improved throw bytes performance and console prints Dec 4, 2025
@marknolan marknolan self-assigned this Dec 16, 2025
@marknolan
Copy link
Copy Markdown
Member Author

@JongChern the scope of this PR has reduced to the following and I think is worth merging:

  1. More efficient discarding of misaligned bytes and more efficient console prints related to this

@JongChern
Copy link
Copy Markdown
Collaborator

@marknolan have added unit test, approving and merging now

{
double shimmerTimestampTicks = (double)newPacketInt[getSignalIndex(Configuration.Shimmer3.ObjectClusterSensorName.TIMESTAMP)];
if(mLastReceivedTimeStampTicks!=0
&& Math.abs(shimmerTimestampTicks - mLastReceivedTimeStampTicks) > CONTIGUOUS_TIMESTAMP_TICKS_LIMIT) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @marknolan i believe if we use Math.abs, the test will fail for legitimate overflow, I imagine if the current timestamp is FF FF FF and the next time stamp is 00 00 00, this test will fail. i suggest removing math.abs, either that or we can perhaps consider a multiples test. e.g. if the sampling rate is 51.2Hz the next packet timestamp should be x * 640 ticks.

@JongChern JongChern merged commit 7c1c0a7 into master Jan 6, 2026
1 of 3 checks passed
@JongChern JongChern deleted the DEV-574_corrupted_data_packed_passing_CRC branch January 6, 2026 06:17
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.

3 participants