From 33289272f62b8a7c64cae4a9e6d621f4aa1aaa79 Mon Sep 17 00:00:00 2001 From: Mark Nolan Date: Tue, 24 Jun 2025 10:36:21 +0100 Subject: [PATCH] DEV-331 #time 15m dock/usb-c command to enter bootloader mode aftr delay --- .../AbstractCommsProtocolWired.java | 2 +- .../CommsProtocolWiredShimmerViaDock.java | 183 +++++++++--------- .../ErrorCodesWiredProtocol.java | 5 + .../wiredProtocol/UartPacketDetails.java | 3 + 4 files changed, 105 insertions(+), 88 deletions(-) diff --git a/ShimmerDriver/src/main/java/com/shimmerresearch/comms/wiredProtocol/AbstractCommsProtocolWired.java b/ShimmerDriver/src/main/java/com/shimmerresearch/comms/wiredProtocol/AbstractCommsProtocolWired.java index 95f02eac7..8a0d9ef2e 100644 --- a/ShimmerDriver/src/main/java/com/shimmerresearch/comms/wiredProtocol/AbstractCommsProtocolWired.java +++ b/ShimmerDriver/src/main/java/com/shimmerresearch/comms/wiredProtocol/AbstractCommsProtocolWired.java @@ -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) { diff --git a/ShimmerDriver/src/main/java/com/shimmerresearch/comms/wiredProtocol/CommsProtocolWiredShimmerViaDock.java b/ShimmerDriver/src/main/java/com/shimmerresearch/comms/wiredProtocol/CommsProtocolWiredShimmerViaDock.java index c391a05ec..9dfaaa797 100644 --- a/ShimmerDriver/src/main/java/com/shimmerresearch/comms/wiredProtocol/CommsProtocolWiredShimmerViaDock.java +++ b/ShimmerDriver/src/main/java/com/shimmerresearch/comms/wiredProtocol/CommsProtocolWiredShimmerViaDock.java @@ -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. @@ -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 @@ -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 diff --git a/ShimmerDriver/src/main/java/com/shimmerresearch/comms/wiredProtocol/ErrorCodesWiredProtocol.java b/ShimmerDriver/src/main/java/com/shimmerresearch/comms/wiredProtocol/ErrorCodesWiredProtocol.java index b552867b7..fa14c998c 100644 --- a/ShimmerDriver/src/main/java/com/shimmerresearch/comms/wiredProtocol/ErrorCodesWiredProtocol.java +++ b/ShimmerDriver/src/main/java/com/shimmerresearch/comms/wiredProtocol/ErrorCodesWiredProtocol.java @@ -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; @@ -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"); diff --git a/ShimmerDriver/src/main/java/com/shimmerresearch/comms/wiredProtocol/UartPacketDetails.java b/ShimmerDriver/src/main/java/com/shimmerresearch/comms/wiredProtocol/UartPacketDetails.java index b6ec14e3c..4a8fb0982 100644 --- a/ShimmerDriver/src/main/java/com/shimmerresearch/comms/wiredProtocol/UartPacketDetails.java +++ b/ShimmerDriver/src/main/java/com/shimmerresearch/comms/wiredProtocol/UartPacketDetails.java @@ -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 listOfCompatibleVersionInfoGqBle = Arrays.asList(svoGqBle); public static List listOfCompatibleVersionInfoGq802154 = Arrays.asList(svoGq802154NR, svoGq802154LR, svoGq802154Shimmer2r); public static List listOfCompatibleVersionInfoGq = Arrays.asList(svoGqBle, svoGq802154NR, svoGq802154LR, svoGq802154Shimmer2r); public static List listOfCompatibleVersionInfoTest = Arrays.asList(svoS3Test, svoS3RTest); + public static List 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 { @@ -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");