Skip to content

Commit 834c5bc

Browse files
committed
DEV-574 #time 10m applying PR comments
1 parent 322ef02 commit 834c5bc

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2818,6 +2818,7 @@ public void startStreaming() throws ShimmerException {
28182818

28192819
initialiseStreaming();
28202820

2821+
super.mLastReceivedTimeStampTicks = 0;
28212822
mByteArrayOutputStream.reset();
28222823
mListofPCTimeStamps.clear();
28232824
writeInstruction(START_STREAMING_COMMAND);

ShimmerDriver/src/main/java/com/shimmerresearch/driver/ShimmerObject.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,22 @@ public class BTStream {
494494
public static final int MAX_NUMBER_OF_SIGNALS = 77;//50; //used to be 11 but now 13 because of the SR30 + 8 for 3d orientation
495495
public static final int MAX_INQUIRY_PACKET_SIZE = 47;
496496

497-
public static int CONTIGUOUS_TIMESTAMP_TICKS_LIMIT = (10*32768); // 10 seconds worth of ticks. Set to 0 to disable the feature
497+
/**
498+
* Maximum allowed gap between consecutive packet timestamps in ticks (10 seconds at 32768 Hz).
499+
* Used to detect corrupted packets that pass CRC checks.
500+
* <p>
501+
* Why 10 seconds: Empirically chosen to balance between catching data corruption and allowing for
502+
* occasional transmission delays. This value can be tuned based on expected packet arrival rates.
503+
* <p>
504+
* Setting to 0 disables this check entirely.
505+
* <p>
506+
* Relationship to timestamp rollover: This value must be less than half the timestamp rollover period
507+
* (i.e., the maximum value before the timestamp counter wraps) to avoid false positives due to rollover.
508+
* <p>
509+
* Sampling rate: The value is calculated for a 32768 Hz sampling rate. If a different sampling rate is used,
510+
* this value should be adjusted accordingly (ticks = seconds * sampling rate).
511+
*/
512+
public static int CONTIGUOUS_TIMESTAMP_TICKS_LIMIT = (10*32768);
498513

499514
public enum TEST_MODE {
500515
MAIN_TEST((byte)0, "Main Test"),
@@ -788,7 +803,10 @@ public String toString() {
788803

789804
// ---------- GSR end ------------------
790805

791-
private double mLastReceivedTimeStampTicks = 0;
806+
/**
807+
* Stores the last received timestamp in ticks (for detecting corrupted packets).
808+
*/
809+
protected double mLastReceivedTimeStampTicks = 0;
792810

793811
public ObjectCluster setLSLTimeIfAvailable(ObjectCluster ojc) {
794812
return ojc;
@@ -937,8 +955,8 @@ public ObjectCluster buildMsg(byte[] newPacket, COMMUNICATION_TYPE fwType, boole
937955
if (fwType == COMMUNICATION_TYPE.BLUETOOTH && CONTIGUOUS_TIMESTAMP_TICKS_LIMIT != 0)
938956
{
939957
double shimmerTimestampTicks = (double)newPacketInt[getSignalIndex(Configuration.Shimmer3.ObjectClusterSensorName.TIMESTAMP)];
940-
if(mLastReceivedTimeStampTicks!=0 && Math.abs(shimmerTimestampTicks - mLastReceivedTimeStampTicks) > CONTIGUOUS_TIMESTAMP_TICKS_LIMIT) {
941-
mLastReceivedTimeStampTicks = shimmerTimestampTicks;
958+
if(mLastReceivedTimeStampTicks!=0
959+
&& Math.abs(shimmerTimestampTicks - mLastReceivedTimeStampTicks) > CONTIGUOUS_TIMESTAMP_TICKS_LIMIT) {
942960
objectCluster.successfullyParsed = false;
943961
return objectCluster; //discard packet
944962
}

0 commit comments

Comments
 (0)