diff --git a/ShimmerAndroidInstrumentDriver/ShimmerAndroidInstrumentDriver/src/main/java/com/shimmerresearch/android/Shimmer.java b/ShimmerAndroidInstrumentDriver/ShimmerAndroidInstrumentDriver/src/main/java/com/shimmerresearch/android/Shimmer.java index 8ae9faef..cc286b95 100644 --- a/ShimmerAndroidInstrumentDriver/ShimmerAndroidInstrumentDriver/src/main/java/com/shimmerresearch/android/Shimmer.java +++ b/ShimmerAndroidInstrumentDriver/ShimmerAndroidInstrumentDriver/src/main/java/com/shimmerresearch/android/Shimmer.java @@ -1700,7 +1700,15 @@ protected void hasStopStreaming() { protected void logAndStreamStatusChanged() { - + // While connecting, the connect sequence's own end (inquiryDone(), then + // isReadyForStreaming()) moves CONNECTING to CONNECTED, or to SDLOGGING for a + // unit that is logging. The sequence reads the status part way through, and if + // that reply did it, the app would be told the unit is ready while the rest of + // the sequence is still queued (DEV-1275). SDLOGGING also sets mIsInitialised. + if(mBluetoothRadioState==BT_STATE.CONNECTING){ + return; + } + // if(mCurrentCommand==START_LOGGING_ONLY_COMMAND){ // TODO this causing a problem Shimmer Bluetooth disconnects // setState(BT_STATE.SDLOGGING); diff --git a/ShimmerAndroidInstrumentDriver/ShimmerAndroidInstrumentDriver/src/test/java/com/shimmerresearch/bluetooth/AAPI_00004_ConnectReadyAfterConnectSequenceTest.java b/ShimmerAndroidInstrumentDriver/ShimmerAndroidInstrumentDriver/src/test/java/com/shimmerresearch/bluetooth/AAPI_00004_ConnectReadyAfterConnectSequenceTest.java new file mode 100644 index 00000000..3210f963 --- /dev/null +++ b/ShimmerAndroidInstrumentDriver/ShimmerAndroidInstrumentDriver/src/test/java/com/shimmerresearch/bluetooth/AAPI_00004_ConnectReadyAfterConnectSequenceTest.java @@ -0,0 +1,164 @@ +package com.shimmerresearch.bluetooth; + +import static org.junit.Assert.*; + +import android.content.Context; +import android.os.Handler; + +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Deque; +import java.util.List; + +import org.junit.Test; + +import com.shimmerresearch.android.Shimmer; +import com.shimmerresearch.bluetooth.ShimmerBluetooth.BT_STATE; +import com.shimmerresearch.driver.ShimmerObject; +import com.shimmerresearch.driverUtilities.ShimmerVerDetails.FW_ID; +import com.shimmerresearch.driverUtilities.ShimmerVerDetails.HW_ID; +import com.shimmerresearch.driverUtilities.ShimmerVerObject; + +/** + * DEV-1275: the connect sequence reads the unit's status part way through, before + * the battery, the calibration dump and the inquiry. Shimmer's + * logAndStreamStatusChanged() moved the state on that reply, from CONNECTING to + * CONNECTED, or to SDLOGGING (which also sets mIsInitialised) for a unit that is + * logging. So the app was told the unit was ready while the rest of the sequence + * was still queued, and whatever it did next went out in among it. The Java HIL + * found it on the driver's ShimmerPC (DEV-1269): a configure sent then cut a + * Shimmer3's calibration dump short and left its accel NaN. + *
+ * The sequence's own end, inquiryDone() and then isReadyForStreaming(), is what + * reports the unit ready. The driver fixed ShimmerPC (API_00031); Shimmer + * overrides the status handler, so it needs the same fix. + *
+ * No hardware: the status reply is read from an in-memory byte queue by the
+ * driver's own parser, as the IO thread does while not streaming.
+ */
+public class AAPI_00004_ConnectReadyAfterConnectSequenceTest {
+
+ /** Not docked, sensing or logging; RTC set */
+ private static final byte STATUS_IDLE = 0x04;
+
+ /** Sensing and SD logging; RTC set */
+ private static final byte STATUS_SD_LOGGING = 0x0E;
+
+ /** A Shimmer whose Bluetooth link is in memory, and which records every state it is set to */
+ private static class QueueShimmer extends Shimmer {
+ final Deque