Skip to content

Commit 00a3f65

Browse files
marknolanclaude
andcommitted
DEV-1070: decode a GSR code below the reference as open on every range
The GSR amplifier equation, R = Rf / (V/Vref - 1), has no positive solution at or below the amplifier's reference. No skin resistance can pull the output under it, so a code there means the electrodes are open. Range 3 has long raised such a code to its open-circuit limit (683, or 1138 on gen-2 since DEV-1067). Ranges 0-2 did not, and in auto-range they see these codes too. When the electrodes come off, the device climbs one range at a time, and the firmware repeats the sample that triggered each switch through the 80 ms settling time, tagged with the range it was measured on. The equation gave those samples a negative resistance, which the ASM-2156 floor turned into 8 kOhm: 125 uS, the highest conductance the device can report, for an open circuit. On a fixed range they read the bottom of the window. DEV-793 B6 (ASM_PC Test_056, SR68-9 2511210195BC) shows it. Its raw range bits put 50 such samples on ranges 0-2. At the start of the recording there are range 0 at codes 0 and 1131, range 1 at 1131 and range 2 at 1132. As the 33 kOhm load comes off there is range 1 at 1137. The reference output reads all 50 as 125.000 uS. calibrateGsrDataToKOhmsWithOpenCircuitLimit now decodes any code below the front end's limit as range 3 at the limit, whatever range it was measured on. Both decode paths call it: SensorGSR.processDataCustom (Verisense, and the Shimmer3 and GQ sensor classes) and the legacy Shimmer3/GQ path in ShimmerObject. Only the resistance and conductance change. The range channel still reports the resistor in circuit, and the uncal values are as before. An open circuit now reads the same on every range as the settled range 3 does: about 4.0 GOhm on gen-2 (this driver divides by 0.5 V), and 4.5 GOhm on a Shimmer3, GQ or SR62. A fixed range still clamps to its own window, so there an open circuit now reads the top of it. Both limits are the first code above 0.5 V. So the rule moves exactly the codes that the equation decoded to a negative resistance, which are the samples ASM-2156's floor already moved. Every other code decodes as before, and none decodes below 8 kOhm, so the floor is now only a backstop. That keeps ASM-2156's promise to Shimmer3 customers: no valid reading changes. API_00019 checks the helper on all three front ends, over every code and range. It checks that exactly the codes that decoded negative change, and that auto-range never reaches the floor. Through processDataCustom it covers Test_056's codes on an SR68-9 and an SR61-5, the SR62, fixed ranges, the Shimmer3 and the ShimmerGQ. With the rule disabled, 8 of its 9 tests fail: 125 uS, and 8 kOhm on fixed range 0. The ShimmerDriver suite passes (117 tests). Stacked on DEV-1067, without which gen-2's limit of 1134 itself decodes negative. Replaying Test_056's raw words through this decode, which reproduces the reference to the last digit, changes exactly those 50 rows, from 125.000 to 0.000 uS, on top of DEV-1067's 3205. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent e8dd95c commit 00a3f65

4 files changed

Lines changed: 309 additions & 5 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2134,7 +2134,8 @@ else if (isEXGUsingDefaultThreeUnipolarConfiguration()){
21342134
if(currentGSRRange==3 && gsrAdcValueUnCal<SensorGSR.GSR_UNCAL_LIMIT_RANGE3) {
21352135
gsrAdcValueUnCal = SensorGSR.GSR_UNCAL_LIMIT_RANGE3;
21362136
}
2137-
gsrResistanceKOhms = SensorGSR.calibrateGsrDataToKOhmsUsingAmplifierEq(gsrAdcValueUnCal, currentGSRRange, MICROCONTROLLER_ADC_PROPERTIES.SHIMMER2R3_3V0, SensorGSR.SHIMMER3_GSR_REF_RESISTORS_KOHMS);
2137+
//An open circuit reads as open on ranges 0-2 too, where only the resistance changes (DEV-1070)
2138+
gsrResistanceKOhms = SensorGSR.calibrateGsrDataToKOhmsWithOpenCircuitLimit(gsrAdcValueUnCal, currentGSRRange, SensorGSR.GSR_UNCAL_LIMIT_RANGE3, MICROCONTROLLER_ADC_PROPERTIES.SHIMMER2R3_3V0, SensorGSR.SHIMMER3_GSR_REF_RESISTORS_KOHMS);
21382139
gsrResistanceKOhms = SensorGSR.nudgeGsrResistance(gsrResistanceKOhms, getGSRRange(), SensorGSR.SHIMMER3_GSR_RESISTANCE_MIN_MAX_KOHMS);
21392140
gsrConductanceUSiemens = (1.0/gsrResistanceKOhms)*1000;
21402141

‎ShimmerDriver/src/main/java/com/shimmerresearch/sensors/SensorGSR.java‎

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ public class SensorGSR extends AbstractSensor {
5252
{63.0, 220.0}, //Range 1
5353
{220.0, 680.0}, //Range 2
5454
{680.0, 4700.0}}; //Range 3
55-
public static final int GSR_UNCAL_LIMIT_RANGE3 = 683;
55+
/**
56+
* The first code above the 0.5 V amplifier reference at the Shimmer3's 3.0 V full scale (0.5 V is
57+
* code 682.5). A code below it, on any range, is an open circuit and decodes as range 3 at this
58+
* limit: see {@link #calibrateGsrDataToKOhmsWithOpenCircuitLimit}. Also used by the ShimmerGQ and
59+
* the Verisense GSR+ (SR62).
60+
*/
61+
public static final int GSR_UNCAL_LIMIT_RANGE3 = 683;
5662

5763
public class GuiLabelConfig{
5864
public static final String GSR_RANGE = "GSR Range";
@@ -354,7 +360,8 @@ public ObjectCluster processDataCustom(SensorDetails sensorDetails, byte[] senso
354360
}
355361
// gsrAdcValueUnCal = SensorGSR.nudgeGsrADC(gsrAdcValueUnCal, currentGSRRange);
356362

357-
gsrResistanceKOhms = SensorGSR.calibrateGsrDataToKOhmsUsingAmplifierEq(gsrAdcValueUnCal, currentGSRRange, microcontrollerAdcProperties, currentGsrRefResistorsKohms);
363+
//...and on ranges 0-2 too, where only the resistance changes (DEV-1070)
364+
gsrResistanceKOhms = SensorGSR.calibrateGsrDataToKOhmsWithOpenCircuitLimit(gsrAdcValueUnCal, currentGSRRange, currentGsrUncalLimitRange3, microcontrollerAdcProperties, currentGsrRefResistorsKohms);
358365
gsrResistanceKOhms = SensorGSR.nudgeGsrResistance(gsrResistanceKOhms, getGSRRange(), currentGsrResistanceKohmsMinMax);
359366
gsrConductanceUSiemens = SensorGSR.convertkOhmToUSiemens(gsrResistanceKOhms);
360367
// } else {
@@ -609,6 +616,37 @@ public static double calibrateGsrDataToKOhmsUsingAmplifierEq(double gsrUncalibra
609616
return rSource;
610617
}
611618

619+
/**
620+
* {@link #calibrateGsrDataToKOhmsUsingAmplifierEq}, reading an open circuit as open on every
621+
* range (DEV-1070).
622+
* <p>
623+
* The amplifier equation has no positive solution at or below the amplifier's reference: no skin
624+
* resistance can pull the output under it, so a code there means the electrodes are open. Range 3
625+
* has long raised such a code to its open-circuit limit, the first code above the reference, so
626+
* that an open circuit decodes as thousands of MOhm. Ranges 0-2 did not, and in auto-range they
627+
* see these codes too. When the electrodes come off, the device climbs one range at a time, and
628+
* the firmware repeats the sample that triggered each switch through the 80 ms settling time,
629+
* tagged with the range it was measured on. On ranges 0-2 the equation gave those samples a
630+
* negative resistance, which {@link #nudgeGsrResistance} floors at 8 kOhm: the highest
631+
* conductance the device can report, for an open circuit.
632+
* <p>
633+
* So a code below the limit is decoded as range 3 at the limit, whatever range it was measured
634+
* on, and an open circuit reads the same on every range as the settled range 3 does. The 8 kOhm
635+
* floor can then no longer be reached, because range 0 at full scale already decodes to just
636+
* above it (8.04 kOhm). Codes at or above the limit decode on their own range, as before. The
637+
* test compares codes rather than volts, so it does not depend on which reference the equation
638+
* divides by.
639+
*
640+
* @param gsrUncalLimitRange3 the front end's range-3 open-circuit limit: {@link #GSR_UNCAL_LIMIT_RANGE3},
641+
* or {@code SensorGSRVerisense.VERISENSE_PULSE_PLUS_GSR_UNCAL_LIMIT_RANGE3} on gen-2
642+
*/
643+
public static double calibrateGsrDataToKOhmsWithOpenCircuitLimit(double gsrUncalibratedData, int range, int gsrUncalLimitRange3, MICROCONTROLLER_ADC_PROPERTIES microcontrollerAdcProperties, double[] gsrRefResistorsKohms){
644+
if(gsrUncalibratedData<gsrUncalLimitRange3) {
645+
return calibrateGsrDataToKOhmsUsingAmplifierEq(gsrUncalLimitRange3, 3, microcontrollerAdcProperties, gsrRefResistorsKohms);
646+
}
647+
return calibrateGsrDataToKOhmsUsingAmplifierEq(gsrUncalibratedData, range, microcontrollerAdcProperties, gsrRefResistorsKohms);
648+
}
649+
612650
/**TODO test method no functioning properly yet
613651
* @param gsrkOhms
614652
* @return

‎ShimmerDriver/src/main/java/com/shimmerresearch/verisense/sensors/SensorGSRVerisense.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ public static GSR_RANGE getForConfigValue(int configValue) {
8787
562.0, //Range 2
8888
1740.0}; //Range 3
8989
/**
90-
* Range-3 codes below this are raised to it before calibration so that an open circuit reads
91-
* as open. It has to be the first code above the 0.5 V amplifier reference that
90+
* Codes below this, on any range, decode as range 3 at it so that an open circuit reads as open
91+
* ({@link SensorGSR#calibrateGsrDataToKOhmsWithOpenCircuitLimit}; range 3 only until DEV-1070).
92+
* It has to be the first code above the 0.5 V amplifier reference that
9293
* {@link SensorGSR#calibrateGsrDataToKOhmsUsingAmplifierEq} divides by: 0.5 V is code 1137.5 at
9394
* this front end's 1.8 V full scale, so 1138, as 683 is at the Shimmer3's 3.0 V. Anything lower
9495
* decodes to a negative resistance, which the auto-range nudge floors at 8 kOhm, reading an open
Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
package com.shimmerresearch.sensors;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertNotNull;
5+
import static org.junit.Assert.assertTrue;
6+
7+
import org.junit.Test;
8+
9+
import com.shimmerresearch.driver.Configuration;
10+
import com.shimmerresearch.driver.Configuration.COMMUNICATION_TYPE;
11+
import com.shimmerresearch.driver.Configuration.Verisense;
12+
import com.shimmerresearch.driver.ObjectCluster;
13+
import com.shimmerresearch.driverUtilities.ChannelDetails.CHANNEL_TYPE;
14+
import com.shimmerresearch.driverUtilities.ExpansionBoardDetails;
15+
import com.shimmerresearch.driverUtilities.SensorDetails;
16+
import com.shimmerresearch.driverUtilities.ShimmerVerDetails.FW_ID;
17+
import com.shimmerresearch.driverUtilities.ShimmerVerDetails.HW_ID;
18+
import com.shimmerresearch.driverUtilities.ShimmerVerObject;
19+
import com.shimmerresearch.sensors.SensorADC.MICROCONTROLLER_ADC_PROPERTIES;
20+
import com.shimmerresearch.sensors.SensorGSR.ObjectClusterSensorName;
21+
import com.shimmerresearch.verisense.VerisenseDevice;
22+
import com.shimmerresearch.verisense.sensors.SensorGSRVerisense;
23+
import com.shimmerresearch.verisense.sensors.SensorGSRVerisense.GSR_RANGE;
24+
25+
/**
26+
* A GSR code below the amplifier reference is an open circuit, and has to decode as one on every
27+
* range (DEV-1070).
28+
* <p>
29+
* No skin resistance can pull the amplifier's output under its reference, so the equation
30+
* R = Rf / (V / Vref - 1) goes negative there. Range 3 has long raised such codes to its
31+
* open-circuit limit. Ranges 0-2 did not, and in auto-range they see them: when the electrodes come
32+
* off, the device climbs one range at a time and repeats the sample that triggered each switch for
33+
* 80 ms, tagged with the range it was measured on. The auto-range nudge then floored the negative
34+
* resistance at 8 kOhm, so an open circuit read 125 uS, the highest conductance the device can
35+
* report. DEV-793 dataset B6 (ASM_PC Test_056, SR68-9 2511210195BC) has 50 such samples, and their
36+
* raw words carry these ranges and codes:
37+
* <ul>
38+
* <li>at the start of the recording: range 0 at codes 0 and 1131, range 1 at 1131, range 2 at
39+
* 1132</li>
40+
* <li>as the 33 kOhm load comes off: range 1 at 1137</li>
41+
* </ul>
42+
* Every code below the limit now decodes as range 3 at the limit. The rule is the same on every front
43+
* end: gen-2 (SR68, SR61-5/6, limit 1138), the Verisense GSR+ (SR62), and the Shimmer3 and ShimmerGQ
44+
* (limit 683).
45+
*/
46+
public class API_00019_GsrBelowReferenceReadsOpen {
47+
48+
/** Conductance below this reads as Disconnected in the C# API and the web SDK. */
49+
private static final double DISCONNECTED_BELOW_USIEMENS = 0.03;
50+
private static final double[][] WINDOWS_KOHMS = SensorGSR.SHIMMER3_GSR_RESISTANCE_MIN_MAX_KOHMS;
51+
private static final int AUTO_RANGE = 4;
52+
53+
/** The below-reference codes in Test_056, by the range they were measured on. */
54+
private static final int[][] TEST_056_CODES_BY_RANGE = new int[][] {
55+
{0, 1131},
56+
{1131, 1137},
57+
{1132}};
58+
59+
private enum FrontEnd {
60+
SHIMMER3(MICROCONTROLLER_ADC_PROPERTIES.SHIMMER2R3_3V0, SensorGSR.SHIMMER3_GSR_REF_RESISTORS_KOHMS,
61+
SensorGSR.GSR_UNCAL_LIMIT_RANGE3),
62+
VERISENSE_GSR_PLUS(MICROCONTROLLER_ADC_PROPERTIES.VERISENSE_3V0, SensorGSR.SHIMMER3_GSR_REF_RESISTORS_KOHMS,
63+
SensorGSR.GSR_UNCAL_LIMIT_RANGE3),
64+
VERISENSE_GEN2(MICROCONTROLLER_ADC_PROPERTIES.VERISENSE_1V8,
65+
SensorGSRVerisense.VERISENSE_PULSE_PLUS_GSR_REF_RESISTORS_KOHMS,
66+
SensorGSRVerisense.VERISENSE_PULSE_PLUS_GSR_UNCAL_LIMIT_RANGE3);
67+
68+
final MICROCONTROLLER_ADC_PROPERTIES adc;
69+
final double[] refResistorsKohms;
70+
final int limit;
71+
72+
FrontEnd(MICROCONTROLLER_ADC_PROPERTIES adc, double[] refResistorsKohms, int limit) {
73+
this.adc = adc;
74+
this.refResistorsKohms = refResistorsKohms;
75+
this.limit = limit;
76+
}
77+
78+
double equation(int code, int range) {
79+
return SensorGSR.calibrateGsrDataToKOhmsUsingAmplifierEq(code, range, adc, refResistorsKohms);
80+
}
81+
82+
double withOpenCircuitLimit(int code, int range) {
83+
return SensorGSR.calibrateGsrDataToKOhmsWithOpenCircuitLimit(code, range, limit, adc, refResistorsKohms);
84+
}
85+
86+
double openCircuitKohms() {
87+
return equation(limit, 3);
88+
}
89+
}
90+
91+
@Test
92+
public void test001_everyCodeBelowTheLimitDecodesAsRange3AtTheLimit() {
93+
for (FrontEnd frontEnd : FrontEnd.values()) {
94+
double open = frontEnd.openCircuitKohms();
95+
for (int range = 0; range <= 3; range++) {
96+
for (int code = 0; code < frontEnd.limit; code++) {
97+
assertEquals(frontEnd + " range " + range + " code " + code, open,
98+
frontEnd.withOpenCircuitLimit(code, range), 0.0);
99+
}
100+
}
101+
assertTrue(frontEnd + " reads an open circuit as " + (1000.0 / open) + " uS",
102+
1000.0 / open < DISCONNECTED_BELOW_USIEMENS);
103+
}
104+
}
105+
106+
/**
107+
* The limit is the first code above the 0.5 V reference on every front end, so the rule moves
108+
* exactly the codes that the equation decoded to a negative resistance, which are the samples
109+
* that ASM-2156's 8 kOhm floor already moved. Every other code decodes as it always has.
110+
*/
111+
@Test
112+
public void test002_onlyCodesTheEquationDecodedNegativeChange() {
113+
for (FrontEnd frontEnd : FrontEnd.values()) {
114+
for (int range = 0; range <= 3; range++) {
115+
for (int code = 0; code <= 4095; code++) {
116+
String context = frontEnd + " range " + range + " code " + code;
117+
double equation = frontEnd.equation(code, range);
118+
if (code < frontEnd.limit) {
119+
assertTrue(context + " decodes to " + equation + " kOhm", equation < 0);
120+
} else {
121+
assertTrue(context + " decodes to " + equation + " kOhm", equation > 0);
122+
assertEquals(context, equation, frontEnd.withOpenCircuitLimit(code, range), 0.0);
123+
}
124+
}
125+
}
126+
}
127+
}
128+
129+
/** Range 0 at full scale already decodes above 8 kOhm, so nothing reaches the auto-range floor. */
130+
@Test
131+
public void test003_theAutoRangeFloorIsNoLongerReached() {
132+
for (FrontEnd frontEnd : FrontEnd.values()) {
133+
for (int range = 0; range <= 3; range++) {
134+
for (int code = 0; code <= 4095; code++) {
135+
double kOhms = frontEnd.withOpenCircuitLimit(code, range);
136+
assertEquals(frontEnd + " range " + range + " code " + code, kOhms,
137+
SensorGSR.nudgeGsrResistance(kOhms, AUTO_RANGE, WINDOWS_KOHMS), 0.0);
138+
}
139+
}
140+
}
141+
}
142+
143+
@Test
144+
public void test004_sr68AutoRangeTransientFromTest056ReadsOpen() {
145+
SensorGSRVerisense sensorGsr = createVerisenseSensorGsr(HW_ID.VERISENSE_PULSE_PLUS, 9, GSR_RANGE.AUTO_RANGE);
146+
assertAutoRangeReadsOpen(sensorGsr, FrontEnd.VERISENSE_GEN2, TEST_056_CODES_BY_RANGE);
147+
}
148+
149+
@Test
150+
public void test005_sr61AutoRangeTransientFromTest056ReadsOpen() {
151+
SensorGSRVerisense sensorGsr = createVerisenseSensorGsr(HW_ID.VERISENSE_IMU, 5, GSR_RANGE.AUTO_RANGE);
152+
assertAutoRangeReadsOpen(sensorGsr, FrontEnd.VERISENSE_GEN2, TEST_056_CODES_BY_RANGE);
153+
}
154+
155+
@Test
156+
public void test006_sr62AutoRangeBelowReferenceReadsOpen() {
157+
SensorGSRVerisense sensorGsr = createVerisenseSensorGsr(HW_ID.VERISENSE_GSR_PLUS, 1, GSR_RANGE.AUTO_RANGE);
158+
assertAutoRangeReadsOpen(sensorGsr, FrontEnd.VERISENSE_GSR_PLUS, codesBelowLimit(FrontEnd.VERISENSE_GSR_PLUS));
159+
}
160+
161+
/**
162+
* A fixed range still clamps to its own window (DEV-1068), but an open circuit now pins it to
163+
* the top of the window, as fixed range 3 already did, instead of the bottom.
164+
*/
165+
@Test
166+
public void test007_verisenseFixedRangesReadTheTopOfTheirWindow() {
167+
GSR_RANGE[] fixedRanges = new GSR_RANGE[] {GSR_RANGE.RANGE_0, GSR_RANGE.RANGE_1, GSR_RANGE.RANGE_2, GSR_RANGE.RANGE_3};
168+
for (int range = 0; range <= 3; range++) {
169+
SensorGSRVerisense sr68 = createVerisenseSensorGsr(HW_ID.VERISENSE_PULSE_PLUS, 9, fixedRanges[range]);
170+
assertFixedRangeReadsTopOfWindow(sr68, range, codesBelowLimit(FrontEnd.VERISENSE_GEN2)[0]);
171+
SensorGSRVerisense sr62 = createVerisenseSensorGsr(HW_ID.VERISENSE_GSR_PLUS, 1, fixedRanges[range]);
172+
assertFixedRangeReadsTopOfWindow(sr62, range, codesBelowLimit(FrontEnd.VERISENSE_GSR_PLUS)[0]);
173+
}
174+
}
175+
176+
@Test
177+
public void test008_shimmer3BelowReferenceReadsOpen() {
178+
SensorGSR sensorGsr = new SensorGSR(new ShimmerVerObject(HW_ID.SHIMMER_3, FW_ID.LOGANDSTREAM, 0, 16, 0));
179+
sensorGsr.setGSRRange(AUTO_RANGE);
180+
assertAutoRangeReadsOpen(sensorGsr, FrontEnd.SHIMMER3, codesBelowLimit(FrontEnd.SHIMMER3));
181+
182+
for (int range = 0; range <= 3; range++) {
183+
sensorGsr.setGSRRange(range);
184+
assertFixedRangeReadsTopOfWindow(sensorGsr, range, codesBelowLimit(FrontEnd.SHIMMER3)[0]);
185+
}
186+
}
187+
188+
/** The ShimmerGQ decodes to a single channel, in uS. */
189+
@Test
190+
public void test009_shimmerGqBelowReferenceReadsOpen() {
191+
SensorGSR sensorGsr = new SensorGSR(new ShimmerVerObject(HW_ID.SHIMMER_GQ_802154_NR, FW_ID.GQ_802154, 0, 4, 1));
192+
sensorGsr.setGSRRange(AUTO_RANGE);
193+
double openUS = 1000.0 / FrontEnd.SHIMMER3.openCircuitKohms();
194+
int[][] codesByRange = codesBelowLimit(FrontEnd.SHIMMER3);
195+
for (int range = 0; range < codesByRange.length; range++) {
196+
for (int code : codesByRange[range]) {
197+
ObjectCluster ojc = decodeSample(sensorGsr, Configuration.Shimmer3.SENSOR_ID.SHIMMER_GSR, range, code);
198+
double uS = ojc.getFormatClusterValue(ObjectClusterSensorName.GSR_GQ, CHANNEL_TYPE.CAL.toString());
199+
assertEquals("GQ range " + range + " code " + code, openUS, uS, openUS * 1e-12);
200+
assertTrue("GQ range " + range + " code " + code + " read " + uS + " uS", uS < DISCONNECTED_BELOW_USIEMENS);
201+
}
202+
}
203+
}
204+
205+
private static void assertAutoRangeReadsOpen(SensorGSR sensorGsr, FrontEnd frontEnd, int[][] codesByRange) {
206+
double openKohms = frontEnd.openCircuitKohms();
207+
int sensorId = sensorId(sensorGsr);
208+
for (int range = 0; range < codesByRange.length; range++) {
209+
for (int code : codesByRange[range]) {
210+
ObjectCluster ojc = decodeSample(sensorGsr, sensorId, range, code);
211+
String context = frontEnd + " auto-range, range " + range + " code " + code;
212+
double kOhms = ojc.getFormatClusterValue(ObjectClusterSensorName.GSR_RESISTANCE, CHANNEL_TYPE.CAL.toString());
213+
double uS = ojc.getFormatClusterValue(ObjectClusterSensorName.GSR_CONDUCTANCE, CHANNEL_TYPE.CAL.toString());
214+
double reportedRange = ojc.getFormatClusterValue(ObjectClusterSensorName.GSR_RANGE, CHANNEL_TYPE.CAL.toString());
215+
216+
assertEquals(context, openKohms, kOhms, 0.0);
217+
assertTrue(context + " read " + uS + " uS", uS > 0 && uS < DISCONNECTED_BELOW_USIEMENS);
218+
// Only the resistance changes: the range channel still says which resistor was in circuit
219+
assertEquals(context, range, reportedRange, 0.0);
220+
}
221+
}
222+
}
223+
224+
private static void assertFixedRangeReadsTopOfWindow(SensorGSR sensorGsr, int range, int[] codes) {
225+
for (int code : codes) {
226+
ObjectCluster ojc = decodeSample(sensorGsr, sensorId(sensorGsr), range, code);
227+
double kOhms = ojc.getFormatClusterValue(ObjectClusterSensorName.GSR_RESISTANCE, CHANNEL_TYPE.CAL.toString());
228+
assertEquals("fixed range " + range + " code " + code, WINDOWS_KOHMS[range][1], kOhms, 0.0);
229+
}
230+
}
231+
232+
/** 0, and the last code below the limit, on each of ranges 0-2. */
233+
private static int[][] codesBelowLimit(FrontEnd frontEnd) {
234+
int[] codes = new int[] {0, frontEnd.limit - 1};
235+
return new int[][] {codes, codes, codes};
236+
}
237+
238+
private static int sensorId(SensorGSR sensorGsr) {
239+
return sensorGsr instanceof SensorGSRVerisense ? Verisense.SENSOR_ID.GSR : Configuration.Shimmer3.SENSOR_ID.SHIMMER_GSR;
240+
}
241+
242+
private static SensorGSRVerisense createVerisenseSensorGsr(int hwId, int hwRev, GSR_RANGE gsrRange) {
243+
ExpansionBoardDetails ebd = new ExpansionBoardDetails(hwId, hwRev, 0);
244+
VerisenseDevice verisenseDevice = new VerisenseDevice();
245+
verisenseDevice.setShimmerVersionObject(VerisenseDevice.FW_CHANGES.CCF21_010_3);
246+
verisenseDevice.setHardwareVersion(ebd.getExpansionBoardId());
247+
verisenseDevice.setExpansionBoardDetails(ebd);
248+
verisenseDevice.sensorAndConfigMapsCreate();
249+
250+
SensorGSRVerisense sensorGsr = verisenseDevice.getSensorGsr();
251+
assertNotNull("no GSR sensor registered for SR" + hwId + "-" + hwRev, sensorGsr);
252+
sensorGsr.setGsrRange(gsrRange);
253+
return sensorGsr;
254+
}
255+
256+
/** One GSR sample as the firmware sends it: range in bits 15-14 over the 12-bit code, LSB first. */
257+
private static ObjectCluster decodeSample(SensorGSR sensorGsr, int sensorId, int range, int code) {
258+
int raw = (range << 14) | code;
259+
byte[] sample = new byte[] {(byte) (raw & 0xFF), (byte) ((raw >> 8) & 0xFF)};
260+
SensorDetails sensorDetails = sensorGsr.getSensorDetails(sensorId);
261+
assertNotNull("no GSR sensor details", sensorDetails);
262+
return sensorGsr.processDataCustom(sensorDetails, sample, COMMUNICATION_TYPE.SD, new ObjectCluster(), false, 0);
263+
}
264+
}

0 commit comments

Comments
 (0)