Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ protected byte[] shimmerUartCommandTxRx(UART_PACKET_CMD packetCmd, UartComponent
private void txPacket(UART_PACKET_CMD packetCmd, UartComponentPropertyDetails msgArg, byte[] valueBuffer) throws DockException {
consolePrintTxPacketInfo(packetCmd, msgArg, valueBuffer);
byte[] txPacket = assembleTxPacket(packetCmd.toCmdByte(), msgArg, valueBuffer);
// System.out.println(UtilShimmer.bytesToHexStringWithSpacesFormatted(txPacket));
mUtilShimmer.consolePrintLn(mUniqueId + " TX(" + txPacket.length + ")" + UtilShimmer.bytesToHexStringWithSpacesFormatted(txPacket));
try {
mSerialPortInterface.txBytes(txPacket);
} catch (ShimmerException devE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.shimmerresearch.verisense.communication.ByteCommunicationListener;

import bolts.TaskCompletionSource;
import junit.framework.Test;

/**Driver for managing and configuring the Shimmer through the Dock using the
* Shimmer's dock connected UART.
Expand Down Expand Up @@ -88,92 +87,8 @@ public ShimmerVerObject readHwFwVersion() throws ExecutionException {
ShimmerVerObject shimmerVerDetails = new ShimmerVerObject(rxBuf);
return shimmerVerDetails;
}

public void addTestStringListener(StringListener stringTestListener) {
mStringTestListener = stringTestListener;
}
boolean ackNotReceivedForTestCommand = true;
/**
* @param timeoutInSeconds
* @return
* @throws ExecutionException
*/
public boolean readMainTest(UartComponentPropertyDetails details) throws ExecutionException {
int errorCode = ErrorCodesWiredProtocol.SHIMMERUART_CMD_ERR_VERSION_INFO_GET;
//rxBuf = processShimmerSetCommand(compPropDetails, txBuf, errorCode);(UartPacketDetails.UART_COMPONENT_AND_PROPERTY.DEVICE_TEST.MAIN_TEST, -1);
TaskCompletionSource tcs = new TaskCompletionSource<>();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ackNotReceivedForTestCommand = true;
setListener(new ByteCommunicationListener() {

@Override
public void eventNewBytesReceived(byte[] rxBytes) {
// TODO Auto-generated method stub
System.out.println("Test : " + UtilShimmer.bytesToHexString(rxBytes));
try {
outputStream.write(rxBytes);
String result = new String(outputStream.toByteArray());
if (ackNotReceivedForTestCommand) {
byte[] originalBytes = outputStream.toByteArray();
boolean match = UtilShimmer.doesFirstBytesMatch(originalBytes, TEST_ACK);
if (match) {
outputStream.reset();
outputStream.write(originalBytes, TEST_ACK.length, originalBytes.length - TEST_ACK.length);
result = new String(outputStream.toByteArray());
ackNotReceivedForTestCommand = false;
}


}

System.out.println(result);
if (mStringTestListener!=null){
mStringTestListener.eventNewStringRx(result);
}
if (result.contains(TEST_ENDING)) {
tcs.setResult(true);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
tcs.setResult(false);
}

}

@Override
public void eventDisconnected() {
// TODO Auto-generated method stub

}

@Override
public void eventConnected() {
// TODO Auto-generated method stub

}
});
// Parse response string
mTestStreaming = true;
//processShimmerSetCommandNoWait(UartPacketDetails.UART_COMPONENT_AND_PROPERTY.DEVICE_TEST.MAIN_TEST, errorCode, null);
processShimmerSetCommandNoWait(details, errorCode, null);
boolean completed = false;
try {
completed = tcs.getTask().waitForCompletion(TIMEOUT_IN_SHIMMER_TEST, TimeUnit.SECONDS);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
mTestStreaming = false;
return false;
}
mTestStreaming = false;
return completed;
}

public boolean isTestStreaming() {
return mTestStreaming;
}



/** Read the real time clock config time of the Shimmer
* @return long the Shimmer RTC configure time in milliseconds UNIX time (since 1970-Jan-01 00:00:00 UTC)
* @throws ExecutionException
Expand Down Expand Up @@ -354,6 +269,100 @@ public BluetoothModuleVersionDetails readBtFwVersion() throws ExecutionException
return bluetoothModuleVersionDetails;
}

public void addTestStringListener(StringListener stringTestListener) {
mStringTestListener = stringTestListener;
}
boolean ackNotReceivedForTestCommand = true;
/**
* @param timeoutInSeconds
* @return
* @throws ExecutionException
*/
public boolean readMainTest(UartComponentPropertyDetails details) throws ExecutionException {
int errorCode = ErrorCodesWiredProtocol.SHIMMERUART_CMD_ERR_VERSION_INFO_GET;
//rxBuf = processShimmerSetCommand(compPropDetails, txBuf, errorCode);(UartPacketDetails.UART_COMPONENT_AND_PROPERTY.DEVICE_TEST.MAIN_TEST, -1);
TaskCompletionSource tcs = new TaskCompletionSource<>();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ackNotReceivedForTestCommand = true;
setListener(new ByteCommunicationListener() {

@Override
public void eventNewBytesReceived(byte[] rxBytes) {
// TODO Auto-generated method stub
System.out.println("Test : " + UtilShimmer.bytesToHexString(rxBytes));
try {
outputStream.write(rxBytes);
String result = new String(outputStream.toByteArray());
if (ackNotReceivedForTestCommand) {
byte[] originalBytes = outputStream.toByteArray();
boolean match = UtilShimmer.doesFirstBytesMatch(originalBytes, TEST_ACK);
if (match) {
outputStream.reset();
outputStream.write(originalBytes, TEST_ACK.length, originalBytes.length - TEST_ACK.length);
result = new String(outputStream.toByteArray());
ackNotReceivedForTestCommand = false;
}


}

System.out.println(result);
if (mStringTestListener!=null){
mStringTestListener.eventNewStringRx(result);
}
if (result.contains(TEST_ENDING)) {
tcs.setResult(true);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
tcs.setResult(false);
}

}

@Override
public void eventDisconnected() {
// TODO Auto-generated method stub

}

@Override
public void eventConnected() {
// TODO Auto-generated method stub

}
});
// Parse response string
mTestStreaming = true;
//processShimmerSetCommandNoWait(UartPacketDetails.UART_COMPONENT_AND_PROPERTY.DEVICE_TEST.MAIN_TEST, errorCode, null);
processShimmerSetCommandNoWait(details, errorCode, null);
boolean completed = false;
try {
completed = tcs.getTask().waitForCompletion(TIMEOUT_IN_SHIMMER_TEST, TimeUnit.SECONDS);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
mTestStreaming = false;
return false;
}
mTestStreaming = false;
return completed;
}

public boolean isTestStreaming() {
return mTestStreaming;
}

/** Read the BT FW version
* @return String in bytes format
* @throws ExecutionException
*/
public void writeJumpToBootloaderMode(byte secondsDelay) throws ExecutionException {
int errorCode = ErrorCodesWiredProtocol.SHIMMERUART_CMD_ERR_ENTER_BOOTLOADER_SET;
processShimmerSetCommand(UartPacketDetails.UART_COMPONENT_AND_PROPERTY.MAIN_PROCESSOR.ENTER_BOOTLOADER, new byte[] {secondsDelay}, errorCode);
}

@Override
protected void processMsgFromCallback(ShimmerMsg shimmerMSG) {
// TODO Auto-generated method stub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public class ErrorCodesWiredProtocol extends AbstractErrorCodes {
public final static int SHIMMERUART_CMD_ERR_DAUGHTER_MEM_GET = (ERROR_CODES_ID*1000) + 29;
public final static int SHIMMERUART_CMD_ERR_INFOMEM_SET = (ERROR_CODES_ID*1000) + 32;
public final static int SHIMMERUART_CMD_ERR_INFOMEM_GET = (ERROR_CODES_ID*1000) + 31;

public final static int SHIMMERUART_CMD_ERR_BT_FW_VERSION_INFO_GET = (ERROR_CODES_ID*1000) + 37;
public final static int SHIMMERUART_CMD_ERR_ENTER_BOOTLOADER_SET = (ERROR_CODES_ID*1000) + 38;

//SR7 (802.15.4 radio) related errors
public final static int SHIMMERUART_CMD_ERR_RADIO_802154_SET_SETTINGS = (ERROR_CODES_ID*1000) + 33;
Expand Down Expand Up @@ -74,6 +76,9 @@ public class ErrorCodesWiredProtocol extends AbstractErrorCodes {
aMap.put(SHIMMERUART_CMD_ERR_INFOMEM_SET, "Error writing InfoMem");
aMap.put(SHIMMERUART_CMD_ERR_INFOMEM_GET, "Error reading InfoMem");

aMap.put(SHIMMERUART_CMD_ERR_BT_FW_VERSION_INFO_GET, "Error reading BT FW version info");
aMap.put(SHIMMERUART_CMD_ERR_ENTER_BOOTLOADER_SET, "Error writing enter bootloader command");

//SR7 (802.15.4 radio) related errors
aMap.put(SHIMMERUART_CMD_ERR_RADIO_802154_GET_SETTINGS, "Error reading 802.15.4 radio settings");
aMap.put(SHIMMERUART_CMD_ERR_RADIO_802154_SET_SETTINGS, "Error writing 802.15.4 radio settings");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,14 @@ public byte toCmdByte() {
public static ShimmerVerObject svoGq802154Shimmer2r = new ShimmerVerObject(HW_ID.SHIMMER_2R_GQ,ShimmerVerDetails.ANY_VERSION,ShimmerVerDetails.ANY_VERSION,ShimmerVerDetails.ANY_VERSION,ShimmerVerDetails.ANY_VERSION,ShimmerVerDetails.ANY_VERSION);
public static ShimmerVerObject svoS3Test = new ShimmerVerObject(HW_ID.SHIMMER_3,FW_ID.LOGANDSTREAM,0,16,7,ShimmerVerDetails.ANY_VERSION);
public static ShimmerVerObject svoS3RTest = new ShimmerVerObject(HW_ID.SHIMMER_3R,FW_ID.LOGANDSTREAM,0,1,0,ShimmerVerDetails.ANY_VERSION);
public static ShimmerVerObject svoS3RUsbComms = new ShimmerVerObject(HW_ID.SHIMMER_3R,FW_ID.LOGANDSTREAM,1,0,27,ShimmerVerDetails.ANY_VERSION);

//TODO improve
public static List<ShimmerVerObject> listOfCompatibleVersionInfoGqBle = Arrays.asList(svoGqBle);
public static List<ShimmerVerObject> listOfCompatibleVersionInfoGq802154 = Arrays.asList(svoGq802154NR, svoGq802154LR, svoGq802154Shimmer2r);
public static List<ShimmerVerObject> listOfCompatibleVersionInfoGq = Arrays.asList(svoGqBle, svoGq802154NR, svoGq802154LR, svoGq802154Shimmer2r);
public static List<ShimmerVerObject> listOfCompatibleVersionInfoTest = Arrays.asList(svoS3Test, svoS3RTest);
public static List<ShimmerVerObject> listOfCompatibleVersionInfoUsbDfu = Arrays.asList(svoS3RUsbComms);

/** Class listing all of the components and property combinations that can be used with the Shimmer UART commands */
public static class UART_COMPONENT_AND_PROPERTY {
Expand All @@ -105,6 +107,7 @@ public static class MAIN_PROCESSOR {
public static final UartComponentPropertyDetails INFOMEM = new UartComponentPropertyDetails(UART_COMPONENT.MAIN_PROCESSOR, 0x06, PERMISSION.READ_WRITE, listOfCompatibleVersionInfoGqBle, "INFOMEM");
public static final UartComponentPropertyDetails LED0_STATE = new UartComponentPropertyDetails(UART_COMPONENT.MAIN_PROCESSOR, 0x07, PERMISSION.READ_WRITE, listOfCompatibleVersionInfoGq802154, "LED_TOGGLE");
public static final UartComponentPropertyDetails DEVICE_BOOT = new UartComponentPropertyDetails(UART_COMPONENT.MAIN_PROCESSOR, 0x08, PERMISSION.READ_ONLY, listOfCompatibleVersionInfoGq802154, "DEVICE_BOOT");
public static final UartComponentPropertyDetails ENTER_BOOTLOADER = new UartComponentPropertyDetails(UART_COMPONENT.MAIN_PROCESSOR, 0x09, PERMISSION.WRITE_ONLY, listOfCompatibleVersionInfoUsbDfu, "ENTER_BOOTLOADER");
}
public static class BAT {
public static final UartComponentPropertyDetails ENABLE = new UartComponentPropertyDetails(UART_COMPONENT.BAT, 0x00, PERMISSION.READ_WRITE, listOfCompatibleVersionInfoGqBle, "ENABLE");
Expand Down
Loading