Skip to content

Commit cfdb9fa

Browse files
authored
Merge pull request #225 from ShimmerEngineering/DEV-310
DEV-310 S3R extra BT status byte support
2 parents 440dc3c + 657118d commit cfdb9fa

2 files changed

Lines changed: 46 additions & 13 deletions

File tree

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

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,9 +1111,15 @@ protected void processInstreamResponse(boolean shouldClearCrcFromBuffer) {
11111111
}
11121112
}
11131113
else if(inStreamResponseCommand==STATUS_RESPONSE){
1114-
byte[] responseData = readBytes(1, inStreamResponseCommand);
1114+
int statusBytesToRead = 0;
1115+
if(isSupportedUSBPluggedInStatus()) {
1116+
statusBytesToRead = 2;
1117+
}else {
1118+
statusBytesToRead = 1;
1119+
}
1120+
byte[] responseData = readBytes(statusBytesToRead, inStreamResponseCommand);
11151121
if(responseData!=null){
1116-
parseStatusByte(responseData[0]);
1122+
parseStatusByte(responseData);
11171123

11181124
if(!isSupportedRtcStateInStatus()){
11191125
if(!mIsSensing && !isInitialised()){
@@ -2396,26 +2402,26 @@ protected byte[] readBytes(int numBytes, byte btCommand) {
23962402
/**
23972403
* @param statusByte
23982404
*/
2399-
protected void parseStatusByte(byte statusByte){
2405+
protected void parseStatusByte(byte[] statusByte){
24002406
Boolean savedDockedState = isDocked();
24012407

2402-
setIsDocked(((statusByte & (0x01 << 0)) > 0)? true:false);
2403-
setIsSensing(((statusByte & (0x01 << 1)) > 0)? true:false);
2408+
setIsDocked(((statusByte[0] & (0x01 << 0)) > 0)? true:false);
2409+
setIsSensing(((statusByte[0] & (0x01 << 1)) > 0)? true:false);
24042410
//reserved(((statusByte & (0x01 << 2)) > 0)? true:false);
24052411
if(isSupportedRtcStateInStatus()){
2406-
mIsRtcSet = ((statusByte & (0x01 << 2)) > 0)? true:false;
2412+
mIsRtcSet = ((statusByte[0] & (0x01 << 2)) > 0)? true:false;
24072413
}
2408-
setIsSDLogging(((statusByte & (0x01 << 3)) > 0)? true:false);
2409-
setIsStreaming(((statusByte & (0x01 << 4)) > 0)? true:false);
2414+
setIsSDLogging(((statusByte[0] & (0x01 << 3)) > 0)? true:false);
2415+
setIsStreaming(((statusByte[0] & (0x01 << 4)) > 0)? true:false);
24102416
if(isSupportedSdInfoInStatus()){
2411-
setIsSDPresent(((statusByte & (0x01 << 5)) > 0)? true:false);
2412-
setIsSDError(((statusByte & (0x01 << 6)) > 0)? true:false);
2417+
setIsSDPresent(((statusByte[0] & (0x01 << 5)) > 0)? true:false);
2418+
setIsSDError(((statusByte[0] & (0x01 << 6)) > 0)? true:false);
24132419
}
24142420
if(isSupportedRedLedStateInStatus()){
2415-
mIsRedLedOn = ((statusByte & (0x01 << 7)) > 0)? true:false;
2421+
mIsRedLedOn = ((statusByte[0] & (0x01 << 7)) > 0)? true:false;
24162422
}
2417-
2418-
consolePrintLn("\nStatus Response = \n" + UtilShimmer.byteToHexStringFormatted(statusByte)
2423+
2424+
consolePrintLn("\nStatus Response = \n" + UtilShimmer.byteToHexStringFormatted(statusByte[0])
24192425
+ "\t" + "IsDocked = " + isDocked()
24202426
+ "\t" + "IsSensing = " + mIsSensing
24212427
+ "\t" + "IsRtcSet = " + mIsRtcSet
@@ -2425,6 +2431,14 @@ protected void parseStatusByte(byte statusByte){
24252431
+ "\t" + "mIsSdPresent = " + isSDPresent()
24262432
+ "\t" + "mIsRedLedOn = " + mIsRedLedOn);
24272433

2434+
if(statusByte.length > 1) {
2435+
setIsUsbPluggedIn(((statusByte[1] & (0x01 << 0)) > 0)? true:false);
2436+
2437+
consolePrintLn("\nStatus Response = \n" + UtilShimmer.byteToHexStringFormatted(statusByte[1])
2438+
+ "\t" + "IsUsbPluggedIn = " + isUsbPluggedIn());
2439+
2440+
}
2441+
24282442
if(savedDockedState!=isDocked()){
24292443
dockedStateChange();
24302444
}
@@ -2442,6 +2456,10 @@ public boolean isSupportedSdInfoInStatus() {
24422456
return isThisVerCompatibleWith(FW_ID.LOGANDSTREAM, 0, 7, 12);
24432457
}
24442458

2459+
public boolean isSupportedUSBPluggedInStatus() {
2460+
return isThisVerCompatibleWith(HW_ID.SHIMMER_3R, FW_ID.LOGANDSTREAM, 1,0, 24);
2461+
}
2462+
24452463
protected boolean isSupportedInStreamCmds() {
24462464
if((getFirmwareIdentifier()==FW_ID.LOGANDSTREAM
24472465
|| isThisVerCompatibleWith(FW_ID.BTSTREAM, 0, 8, 1))&& getHardwareVersion()!=HW_ID.SHIMMER_2R){

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ public abstract class ShimmerDevice extends BasicProcessWithCallBack implements
148148
protected boolean mIsStreaming = false; // This is used to monitor whether the device is in streaming mode
149149
protected boolean mIsInitialised = false;
150150
private boolean mIsDocked = false;
151+
private boolean mIsUsbPluggedIn= false;
151152
protected boolean mHaveAttemptedToReadConfig = false;
152153

153154
//BSL related start
@@ -1048,6 +1049,16 @@ public boolean setIsDocked(boolean docked) {
10481049
}
10491050
return changed;
10501051
}
1052+
1053+
public boolean setIsUsbPluggedIn(boolean usbPluggedIn) {
1054+
boolean changed=false;
1055+
if (mIsUsbPluggedIn!=usbPluggedIn){
1056+
changed = true;
1057+
}
1058+
mIsUsbPluggedIn = usbPluggedIn;
1059+
return changed;
1060+
1061+
}
10511062

10521063
public void stateHandler(Object obj){
10531064

@@ -1059,6 +1070,10 @@ public void stateHandler(Object obj){
10591070
public boolean isDocked() {
10601071
return mIsDocked;
10611072
}
1073+
1074+
public boolean isUsbPluggedIn() {
1075+
return mIsUsbPluggedIn;
1076+
}
10621077

10631078
public void setIsConnected(boolean state) {
10641079
mIsConnected = state;

0 commit comments

Comments
 (0)