Skip to content

Commit 74210e8

Browse files
committed
updates for 3r parsing
1 parent cc74eab commit 74210e8

3 files changed

Lines changed: 145 additions & 6 deletions

File tree

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

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,11 @@ public ObjectCluster buildMsg(byte[] newPacket, COMMUNICATION_TYPE fwType, boole
841841
numAdditionalChannels += 1;
842842
}
843843
else {
844+
if (fwType == COMMUNICATION_TYPE.SD && getHardwareVersion()==HW_ID.SHIMMER_3R) {
845+
//plus 1 because of: timestamp, because we are no longer relying on interpretdatapacketformat within ShimmerSDLog
846+
numAdditionalChannels += 1;
847+
}
848+
844849
if (!isRtcDifferenceSet()){
845850
//sd log time stamp already included in mnChannels
846851
}
@@ -2922,23 +2927,47 @@ protected int getSignalIndex(String signalName) {
29222927
public void interpretDataPacketFormat(int numChannels, byte[] signalId){
29232928
String [] signalNameArray=new String[MAX_NUMBER_OF_SIGNALS];
29242929
String [] signalDataTypeArray=new String[MAX_NUMBER_OF_SIGNALS];
2930+
int packetSize=mTimeStampPacketByteSize; // Time stamp
2931+
2932+
int iTS=0;
2933+
2934+
if (getHardwareVersion()==HW_ID.SHIMMER_3R && this.getClass().getSimpleName().equals("ShimmerSDLog") ) {
2935+
mNChannels = numChannels;
2936+
if (isSyncWhenLogging()
2937+
&& (getFirmwareIdentifier()==FW_ID.SDLOG || getFirmwareIdentifier()==FW_ID.GQ_802154
2938+
||(UtilShimmer.compareVersions(getShimmerVerObject(),Configuration.Shimmer3.CompatibilityInfoForMaps.svoShimmer3LogAndStreamWithSDLogSyncSupport))
2939+
||(UtilShimmer.compareVersions(getShimmerVerObject(),Configuration.Shimmer3.CompatibilityInfoForMaps.svoShimmer3RLogAndStreamWithSDLogSyncSupport)))){
2940+
signalNameArray[iTS]=SensorShimmerClock.ObjectClusterSensorName.TIMESTAMP_OFFSET;
2941+
if (OFFSET_LENGTH==5){
2942+
signalDataTypeArray[iTS]="u32signed";
2943+
mNChannels += 1;
2944+
packetSize+=5;
2945+
} else if (OFFSET_LENGTH==9){
2946+
signalDataTypeArray[iTS]="u72";
2947+
mNChannels += 1;
2948+
packetSize+=9;
2949+
}
2950+
iTS++;
2951+
}
2952+
}
2953+
29252954

29262955
if (getHardwareVersion()==HW_ID.SHIMMER_SR30 || getHardwareVersion()==HW_ID.SHIMMER_3 || getHardwareVersion() == HW_ID.SHIMMER_3R){
2927-
signalNameArray[0]=Configuration.Shimmer3.ObjectClusterSensorName.TIMESTAMP;
2956+
signalNameArray[iTS]=Configuration.Shimmer3.ObjectClusterSensorName.TIMESTAMP;
29282957
}
29292958
else{
2930-
signalNameArray[0]=Configuration.Shimmer2.ObjectClusterSensorName.TIMESTAMP;
2959+
signalNameArray[iTS]=Configuration.Shimmer2.ObjectClusterSensorName.TIMESTAMP;
29312960
}
29322961

2933-
int packetSize=mTimeStampPacketByteSize; // Time stamp
2962+
29342963
if (mTimeStampPacketByteSize==2){
2935-
signalDataTypeArray[0]="u16";
2964+
signalDataTypeArray[iTS]="u16";
29362965
} else if (mTimeStampPacketByteSize==3) {
2937-
signalDataTypeArray[0]="u24";
2966+
signalDataTypeArray[iTS]="u24";
29382967
}
29392968

29402969
int enabledSensors= 0x00;
2941-
for (int i=0;i<numChannels;i++) {
2970+
for (int i=iTS;i<numChannels+iTS;i++) {
29422971
if ((byte)signalId[i]==(byte)0x00){
29432972
if (getHardwareVersion()==HW_ID.SHIMMER_SR30 || getHardwareVersion()==HW_ID.SHIMMER_3 || getHardwareVersion()==HW_ID.SHIMMER_3R){
29442973
signalNameArray[i+1]=Shimmer3.ObjectClusterSensorName.ACCEL_LN_X;

ShimmerDriver/src/main/java/com/shimmerresearch/driverUtilities/UtilParseData.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,4 +308,53 @@ public static long calculatetwoscomplement(long signedData, int bitLength){
308308

309309
return newData;
310310
}
311+
312+
public static int countBytesFromDataTypes(String[] dataType) {
313+
int totalBytes = 0;
314+
315+
for (String type : dataType) {
316+
if(type==null) {
317+
continue;
318+
}
319+
switch (type) {
320+
case "u8":
321+
case "i8":
322+
totalBytes += 1;
323+
break;
324+
case "u12":
325+
case "u14":
326+
case "i12>":
327+
case "i12*>":
328+
case "u16":
329+
case "u16r":
330+
case "i16":
331+
case "i16r":
332+
totalBytes += 2;
333+
break;
334+
case "u24":
335+
case "u24r":
336+
case "i24r":
337+
totalBytes += 3;
338+
break;
339+
case "u32":
340+
case "u32r":
341+
case "i32":
342+
case "i32r":
343+
totalBytes += 4;
344+
break;
345+
case "u32signed":
346+
totalBytes += 5;
347+
break;
348+
case "u72":
349+
totalBytes += 9;
350+
break;
351+
default:
352+
throw new IllegalArgumentException("Unknown data type: " + type);
353+
}
354+
}
355+
356+
return totalBytes;
357+
}
358+
359+
311360
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.shimmerresearch.driverUtilities;
2+
import static org.junit.Assert.*;
3+
4+
import org.junit.Test;
5+
6+
public class API_XXXXX_UtilParseData {
7+
@Test
8+
public void testSingleByteTypes() {
9+
String[] types = {"u8", "i8"};
10+
assertEquals(2, UtilParseData.countBytesFromDataTypes(types));
11+
}
12+
13+
@Test
14+
public void testTwoByteTypes() {
15+
String[] types = {"u12", "u14", "i12>", "i12*>", "u16", "u16r", "i16", "i16r"};
16+
assertEquals(2 * types.length, UtilParseData.countBytesFromDataTypes(types));
17+
}
18+
19+
@Test
20+
public void testThreeByteTypes() {
21+
String[] types = {"u24", "u24r", "i24r"};
22+
assertEquals(9, UtilParseData.countBytesFromDataTypes(types));
23+
}
24+
25+
@Test
26+
public void testFourByteTypes() {
27+
String[] types = {"u32", "u32r", "i32", "i32r"};
28+
assertEquals(4 * types.length, UtilParseData.countBytesFromDataTypes(types));
29+
}
30+
31+
@Test
32+
public void testFiveByteType() {
33+
String[] types = {"u32signed"};
34+
assertEquals(5, UtilParseData.countBytesFromDataTypes(types));
35+
}
36+
37+
@Test
38+
public void testNineByteType() {
39+
String[] types = {"u72"};
40+
assertEquals(9, UtilParseData.countBytesFromDataTypes(types));
41+
}
42+
43+
@Test
44+
public void testMixedTypes() {
45+
String[] types = {"u8", "i8", "u16", "u24", "u32signed", "u72"};
46+
int expected = 1 + 1 + 2 + 3 + 5 + 9;
47+
assertEquals(expected, UtilParseData.countBytesFromDataTypes(types));
48+
}
49+
50+
@Test
51+
public void testEmptyInput() {
52+
String[] types = {};
53+
assertEquals(0, UtilParseData.countBytesFromDataTypes(types));
54+
}
55+
56+
@Test(expected = IllegalArgumentException.class)
57+
public void testUnknownTypeThrows() {
58+
String[] types = {"u8", "invalidType"};
59+
UtilParseData.countBytesFromDataTypes(types);
60+
}
61+
}

0 commit comments

Comments
 (0)