Skip to content

Commit b279882

Browse files
authored
Merge pull request #95 from ShimmerEngineering/NOL-48
NOL-48
2 parents 0303c8a + c9ebb8b commit b279882

4 files changed

Lines changed: 40 additions & 10 deletions

File tree

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

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public abstract class ShimmerBluetooth extends ShimmerObject implements Serializ
129129
//region --------- CLASS VARIABLES AND ABSTRACT METHODS ---------
130130

131131
protected long mSetEnabledSensors = SENSOR_ACCEL; // Only used during the initialization process, see initialize();
132-
132+
133133
private int mNumberofTXRetriesCount=1;
134134
private final static int NUMBER_OF_TX_RETRIES_LIMIT = 0;
135135
private class DUMMY_READ_WAIT_TIME_MS {
@@ -249,6 +249,7 @@ public String toString() {
249249
transient protected Timer mTimerCheckAlive;
250250
transient protected Timer mTimerReadStatus;
251251
transient protected Timer mTimerReadBattStatus; //
252+
transient protected Timer mTimerConnecting;
252253
transient protected Timer mTimerCheckSerialPortClear;
253254

254255
private int mCountDeadConnection = 0;
@@ -1123,6 +1124,7 @@ else if(getHardwareVersion()==HW_ID.SHIMMER_3) {
11231124
initializeShimmer3();
11241125
}
11251126

1127+
stopTimerConnectingTimeout();
11261128
startTimerCheckIfAlive();
11271129
}
11281130

@@ -2802,6 +2804,7 @@ public void stopAllTimers(){
28022804
stopTimerCheckAlive();
28032805
stopTimerCheckForAckOrResp();
28042806
stopTimerReadBattStatus();
2807+
stopTimerConnectingTimeout();
28052808
}
28062809

28072810
public void stopTimerCheckForAckOrResp(){
@@ -3105,6 +3108,37 @@ public void restartTimersIfNull() {
31053108
}
31063109
}
31073110

3111+
public void startTimerConnectingTimeout() {
3112+
mTimerConnecting = new Timer();
3113+
mTimerConnecting.schedule(new connectingTimeoutTask(), LiteProtocol.TIMER_CONNECTING_TIMEOUT);
3114+
consolePrintLn("Started connecting timer...");
3115+
}
3116+
3117+
public void stopTimerConnectingTimeout() {
3118+
if(mTimerConnecting != null) {
3119+
consolePrintLn("Stopped connecting timer...");
3120+
try {
3121+
mTimerConnecting.cancel();
3122+
mTimerConnecting.purge();
3123+
} catch (NullPointerException npe) {
3124+
npe.printStackTrace();
3125+
}
3126+
mTimerConnecting = null;
3127+
}
3128+
}
3129+
3130+
private class connectingTimeoutTask extends TimerTask {
3131+
@Override
3132+
public void run() {
3133+
if(mBluetoothRadioState == BT_STATE.CONNECTING)
3134+
{
3135+
connectionLost();
3136+
stopTimerConnectingTimeout();
3137+
consolePrintLn("Connecting timer timed out, connection lost");
3138+
}
3139+
}
3140+
}
3141+
31083142
public void stopTimerCheckForSerialPortClear(){
31093143
//Terminate the timer thread
31103144
if(mTimerCheckSerialPortClear!=null){
@@ -3146,7 +3180,7 @@ public void run() {
31463180
connectionLost();
31473181
}
31483182
}
3149-
3183+
31503184
//endregion --------- TIMERS ---------
31513185

31523186

ShimmerDriver/src/main/java/com/shimmerresearch/comms/radioProtocol/LiteProtocol.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public class InstructionsGet{
7979
public static final int TIMER_READ_STATUS_PERIOD = 5000;
8080
public static final int TIMER_READ_BATT_STATUS_PERIOD = 60000; // Batt status is updated every 1min
8181
public static final int TIMER_CHECK_ALIVE_PERIOD = 2000;
82+
public static final int TIMER_CONNECTING_TIMEOUT = 20000;
8283

8384
transient protected Timer mTimerCheckForAckOrResp; // Timer variable used when waiting for an ack or response packet
8485
transient protected Timer mTimerCheckAlive;

ShimmerDriverPC/src/main/java/com/shimmerresearch/pcDriver/ShimmerPC.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@
8989
import jssc.SerialPortException;
9090
import jssc.SerialPortTimeoutException;
9191

92-
9392
public class ShimmerPC extends ShimmerBluetooth implements Serializable{
9493

9594
/** * */
@@ -350,6 +349,8 @@ public void run(){
350349
setBluetoothRadioState(BT_STATE.CONNECTING);
351350

352351
// mMyBluetoothAddress = address;
352+
startTimerConnectingTimeout();
353+
353354
setIamAlive(false);
354355
getListofInstructions().clear();
355356

@@ -416,7 +417,6 @@ public void run(){
416417
// }
417418
}
418419

419-
420420
@Override
421421
public boolean bytesAvailableToBeRead() {
422422
try {
@@ -616,14 +616,12 @@ private void closeConnection(){
616616
mIsInitialised = false;
617617

618618
setBluetoothRadioState(BT_STATE.DISCONNECTED);
619-
if (mSerialPort != null){
620-
619+
if (mSerialPort != null) {
621620
if (mSerialPort.isOpened()) {
622621
mSerialPort.purgePort(1);
623622
mSerialPort.purgePort(2);
624623
mSerialPort.closePort();
625624
}
626-
627625
}
628626
mSerialPort = null;
629627
} catch (Exception ex) {
@@ -934,4 +932,3 @@ public static void setDefaultCrcMode(BT_CRC_MODE defaultCrcMode) {
934932
}
935933

936934
}
937-

ShimmerDriverPC/src/main/java/com/shimmerresearch/pcDriver/ShimmerPCBTBCove.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,5 @@ public Set<Integer> getSensorIdsSet() {
595595
return null;
596596
}
597597

598-
599-
600598
}
601599

0 commit comments

Comments
 (0)