DEV-574 improved throw bytes performance and console prints#256
DEV-574 improved throw bytes performance and console prints#256
Conversation
There was a problem hiding this comment.
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.
ShimmerDriver/src/main/java/com/shimmerresearch/driver/ShimmerObject.java
Outdated
Show resolved
Hide resolved
ShimmerDriver/src/main/java/com/shimmerresearch/bluetooth/ShimmerBluetooth.java
Show resolved
Hide resolved
ShimmerDriver/src/main/java/com/shimmerresearch/driver/ObjectCluster.java
Outdated
Show resolved
Hide resolved
ShimmerDriver/src/main/java/com/shimmerresearch/bluetooth/ShimmerBluetooth.java
Outdated
Show resolved
Hide resolved
ShimmerDriver/src/main/java/com/shimmerresearch/bluetooth/ShimmerBluetooth.java
Outdated
Show resolved
Hide resolved
ShimmerDriver/src/main/java/com/shimmerresearch/driver/ShimmerObject.java
Outdated
Show resolved
Hide resolved
ShimmerDriver/src/main/java/com/shimmerresearch/driver/ShimmerObject.java
Outdated
Show resolved
Hide resolved
ShimmerDriver/src/main/java/com/shimmerresearch/bluetooth/ShimmerBluetooth.java
Outdated
Show resolved
Hide resolved
ShimmerDriver/src/main/java/com/shimmerresearch/driver/ShimmerObject.java
Outdated
Show resolved
Hide resolved
ShimmerDriver/src/main/java/com/shimmerresearch/driver/ShimmerObject.java
Outdated
Show resolved
Hide resolved
…merBluetooth.java Co-authored-by: Copilot <[email protected]>
…merBluetooth.java Co-authored-by: Copilot <[email protected]>
…luster.java Co-authored-by: Copilot <[email protected]>
…Object.java Co-authored-by: Copilot <[email protected]>
…merBluetooth.java Co-authored-by: Copilot <[email protected]>
|
@JongChern there are two aspects to this PR
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 |
|
@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. |
There was a problem hiding this comment.
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.
ShimmerDriver/src/main/java/com/shimmerresearch/bluetooth/ShimmerBluetooth.java
Outdated
Show resolved
Hide resolved
ShimmerDriver/src/main/java/com/shimmerresearch/bluetooth/ShimmerBluetooth.java
Outdated
Show resolved
Hide resolved
…merBluetooth.java Co-authored-by: Copilot <[email protected]>
…merBluetooth.java Co-authored-by: Copilot <[email protected]>
|
@JongChern the scope of this PR has reduced to the following and I think is worth merging:
|
|
@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) { |
There was a problem hiding this comment.
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.
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).
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.