Skip to content

Commit 6b2c103

Browse files
committed
Merge branch 'master' into DEV-343_More_BT_cmd_support_for_S3R
2 parents 5746b0b + a9d430e commit 6b2c103

4 files changed

Lines changed: 105 additions & 88 deletions

File tree

ShimmerDriver/src/main/java/com/shimmerresearch/comms/wiredProtocol/AbstractCommsProtocolWired.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ protected byte[] shimmerUartCommandTxRx(UART_PACKET_CMD packetCmd, UartComponent
384384
private void txPacket(UART_PACKET_CMD packetCmd, UartComponentPropertyDetails msgArg, byte[] valueBuffer) throws DockException {
385385
consolePrintTxPacketInfo(packetCmd, msgArg, valueBuffer);
386386
byte[] txPacket = assembleTxPacket(packetCmd.toCmdByte(), msgArg, valueBuffer);
387-
// System.out.println(UtilShimmer.bytesToHexStringWithSpacesFormatted(txPacket));
387+
mUtilShimmer.consolePrintLn(mUniqueId + " TX(" + txPacket.length + ")" + UtilShimmer.bytesToHexStringWithSpacesFormatted(txPacket));
388388
try {
389389
mSerialPortInterface.txBytes(txPacket);
390390
} catch (ShimmerException devE) {

ShimmerDriver/src/main/java/com/shimmerresearch/comms/wiredProtocol/CommsProtocolWiredShimmerViaDock.java

Lines changed: 96 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import com.shimmerresearch.verisense.communication.ByteCommunicationListener;
1818

1919
import bolts.TaskCompletionSource;
20-
import junit.framework.Test;
2120

2221
/**Driver for managing and configuring the Shimmer through the Dock using the
2322
* Shimmer's dock connected UART.
@@ -88,92 +87,8 @@ public ShimmerVerObject readHwFwVersion() throws ExecutionException {
8887
ShimmerVerObject shimmerVerDetails = new ShimmerVerObject(rxBuf);
8988
return shimmerVerDetails;
9089
}
91-
92-
public void addTestStringListener(StringListener stringTestListener) {
93-
mStringTestListener = stringTestListener;
94-
}
95-
boolean ackNotReceivedForTestCommand = true;
96-
/**
97-
* @param timeoutInSeconds
98-
* @return
99-
* @throws ExecutionException
100-
*/
101-
public boolean readMainTest(UartComponentPropertyDetails details) throws ExecutionException {
102-
int errorCode = ErrorCodesWiredProtocol.SHIMMERUART_CMD_ERR_VERSION_INFO_GET;
103-
//rxBuf = processShimmerSetCommand(compPropDetails, txBuf, errorCode);(UartPacketDetails.UART_COMPONENT_AND_PROPERTY.DEVICE_TEST.MAIN_TEST, -1);
104-
TaskCompletionSource tcs = new TaskCompletionSource<>();
105-
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
106-
ackNotReceivedForTestCommand = true;
107-
setListener(new ByteCommunicationListener() {
108-
109-
@Override
110-
public void eventNewBytesReceived(byte[] rxBytes) {
111-
// TODO Auto-generated method stub
112-
System.out.println("Test : " + UtilShimmer.bytesToHexString(rxBytes));
113-
try {
114-
outputStream.write(rxBytes);
115-
String result = new String(outputStream.toByteArray());
116-
if (ackNotReceivedForTestCommand) {
117-
byte[] originalBytes = outputStream.toByteArray();
118-
boolean match = UtilShimmer.doesFirstBytesMatch(originalBytes, TEST_ACK);
119-
if (match) {
120-
outputStream.reset();
121-
outputStream.write(originalBytes, TEST_ACK.length, originalBytes.length - TEST_ACK.length);
122-
result = new String(outputStream.toByteArray());
123-
ackNotReceivedForTestCommand = false;
124-
}
125-
126-
127-
}
128-
129-
System.out.println(result);
130-
if (mStringTestListener!=null){
131-
mStringTestListener.eventNewStringRx(result);
132-
}
133-
if (result.contains(TEST_ENDING)) {
134-
tcs.setResult(true);
135-
}
136-
} catch (IOException e) {
137-
// TODO Auto-generated catch block
138-
e.printStackTrace();
139-
tcs.setResult(false);
140-
}
141-
142-
}
143-
144-
@Override
145-
public void eventDisconnected() {
146-
// TODO Auto-generated method stub
147-
148-
}
149-
150-
@Override
151-
public void eventConnected() {
152-
// TODO Auto-generated method stub
153-
154-
}
155-
});
156-
// Parse response string
157-
mTestStreaming = true;
158-
//processShimmerSetCommandNoWait(UartPacketDetails.UART_COMPONENT_AND_PROPERTY.DEVICE_TEST.MAIN_TEST, errorCode, null);
159-
processShimmerSetCommandNoWait(details, errorCode, null);
160-
boolean completed = false;
161-
try {
162-
completed = tcs.getTask().waitForCompletion(TIMEOUT_IN_SHIMMER_TEST, TimeUnit.SECONDS);
163-
} catch (InterruptedException e) {
164-
// TODO Auto-generated catch block
165-
e.printStackTrace();
166-
mTestStreaming = false;
167-
return false;
168-
}
169-
mTestStreaming = false;
170-
return completed;
171-
}
172-
173-
public boolean isTestStreaming() {
174-
return mTestStreaming;
175-
}
176-
90+
91+
17792
/** Read the real time clock config time of the Shimmer
17893
* @return long the Shimmer RTC configure time in milliseconds UNIX time (since 1970-Jan-01 00:00:00 UTC)
17994
* @throws ExecutionException
@@ -354,6 +269,100 @@ public BluetoothModuleVersionDetails readBtFwVersion() throws ExecutionException
354269
return bluetoothModuleVersionDetails;
355270
}
356271

272+
public void addTestStringListener(StringListener stringTestListener) {
273+
mStringTestListener = stringTestListener;
274+
}
275+
boolean ackNotReceivedForTestCommand = true;
276+
/**
277+
* @param timeoutInSeconds
278+
* @return
279+
* @throws ExecutionException
280+
*/
281+
public boolean readMainTest(UartComponentPropertyDetails details) throws ExecutionException {
282+
int errorCode = ErrorCodesWiredProtocol.SHIMMERUART_CMD_ERR_VERSION_INFO_GET;
283+
//rxBuf = processShimmerSetCommand(compPropDetails, txBuf, errorCode);(UartPacketDetails.UART_COMPONENT_AND_PROPERTY.DEVICE_TEST.MAIN_TEST, -1);
284+
TaskCompletionSource tcs = new TaskCompletionSource<>();
285+
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
286+
ackNotReceivedForTestCommand = true;
287+
setListener(new ByteCommunicationListener() {
288+
289+
@Override
290+
public void eventNewBytesReceived(byte[] rxBytes) {
291+
// TODO Auto-generated method stub
292+
System.out.println("Test : " + UtilShimmer.bytesToHexString(rxBytes));
293+
try {
294+
outputStream.write(rxBytes);
295+
String result = new String(outputStream.toByteArray());
296+
if (ackNotReceivedForTestCommand) {
297+
byte[] originalBytes = outputStream.toByteArray();
298+
boolean match = UtilShimmer.doesFirstBytesMatch(originalBytes, TEST_ACK);
299+
if (match) {
300+
outputStream.reset();
301+
outputStream.write(originalBytes, TEST_ACK.length, originalBytes.length - TEST_ACK.length);
302+
result = new String(outputStream.toByteArray());
303+
ackNotReceivedForTestCommand = false;
304+
}
305+
306+
307+
}
308+
309+
System.out.println(result);
310+
if (mStringTestListener!=null){
311+
mStringTestListener.eventNewStringRx(result);
312+
}
313+
if (result.contains(TEST_ENDING)) {
314+
tcs.setResult(true);
315+
}
316+
} catch (IOException e) {
317+
// TODO Auto-generated catch block
318+
e.printStackTrace();
319+
tcs.setResult(false);
320+
}
321+
322+
}
323+
324+
@Override
325+
public void eventDisconnected() {
326+
// TODO Auto-generated method stub
327+
328+
}
329+
330+
@Override
331+
public void eventConnected() {
332+
// TODO Auto-generated method stub
333+
334+
}
335+
});
336+
// Parse response string
337+
mTestStreaming = true;
338+
//processShimmerSetCommandNoWait(UartPacketDetails.UART_COMPONENT_AND_PROPERTY.DEVICE_TEST.MAIN_TEST, errorCode, null);
339+
processShimmerSetCommandNoWait(details, errorCode, null);
340+
boolean completed = false;
341+
try {
342+
completed = tcs.getTask().waitForCompletion(TIMEOUT_IN_SHIMMER_TEST, TimeUnit.SECONDS);
343+
} catch (InterruptedException e) {
344+
// TODO Auto-generated catch block
345+
e.printStackTrace();
346+
mTestStreaming = false;
347+
return false;
348+
}
349+
mTestStreaming = false;
350+
return completed;
351+
}
352+
353+
public boolean isTestStreaming() {
354+
return mTestStreaming;
355+
}
356+
357+
/** Read the BT FW version
358+
* @return String in bytes format
359+
* @throws ExecutionException
360+
*/
361+
public void writeJumpToBootloaderMode(byte secondsDelay) throws ExecutionException {
362+
int errorCode = ErrorCodesWiredProtocol.SHIMMERUART_CMD_ERR_ENTER_BOOTLOADER_SET;
363+
processShimmerSetCommand(UartPacketDetails.UART_COMPONENT_AND_PROPERTY.MAIN_PROCESSOR.ENTER_BOOTLOADER, new byte[] {secondsDelay}, errorCode);
364+
}
365+
357366
@Override
358367
protected void processMsgFromCallback(ShimmerMsg shimmerMSG) {
359368
// TODO Auto-generated method stub

ShimmerDriver/src/main/java/com/shimmerresearch/comms/wiredProtocol/ErrorCodesWiredProtocol.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ public class ErrorCodesWiredProtocol extends AbstractErrorCodes {
2828
public final static int SHIMMERUART_CMD_ERR_DAUGHTER_MEM_GET = (ERROR_CODES_ID*1000) + 29;
2929
public final static int SHIMMERUART_CMD_ERR_INFOMEM_SET = (ERROR_CODES_ID*1000) + 32;
3030
public final static int SHIMMERUART_CMD_ERR_INFOMEM_GET = (ERROR_CODES_ID*1000) + 31;
31+
3132
public final static int SHIMMERUART_CMD_ERR_BT_FW_VERSION_INFO_GET = (ERROR_CODES_ID*1000) + 37;
33+
public final static int SHIMMERUART_CMD_ERR_ENTER_BOOTLOADER_SET = (ERROR_CODES_ID*1000) + 38;
3234

3335
//SR7 (802.15.4 radio) related errors
3436
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 {
7476
aMap.put(SHIMMERUART_CMD_ERR_INFOMEM_SET, "Error writing InfoMem");
7577
aMap.put(SHIMMERUART_CMD_ERR_INFOMEM_GET, "Error reading InfoMem");
7678

79+
aMap.put(SHIMMERUART_CMD_ERR_BT_FW_VERSION_INFO_GET, "Error reading BT FW version info");
80+
aMap.put(SHIMMERUART_CMD_ERR_ENTER_BOOTLOADER_SET, "Error writing enter bootloader command");
81+
7782
//SR7 (802.15.4 radio) related errors
7883
aMap.put(SHIMMERUART_CMD_ERR_RADIO_802154_GET_SETTINGS, "Error reading 802.15.4 radio settings");
7984
aMap.put(SHIMMERUART_CMD_ERR_RADIO_802154_SET_SETTINGS, "Error writing 802.15.4 radio settings");

ShimmerDriver/src/main/java/com/shimmerresearch/comms/wiredProtocol/UartPacketDetails.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,14 @@ public byte toCmdByte() {
8585
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);
8686
public static ShimmerVerObject svoS3Test = new ShimmerVerObject(HW_ID.SHIMMER_3,FW_ID.LOGANDSTREAM,0,16,7,ShimmerVerDetails.ANY_VERSION);
8787
public static ShimmerVerObject svoS3RTest = new ShimmerVerObject(HW_ID.SHIMMER_3R,FW_ID.LOGANDSTREAM,0,1,0,ShimmerVerDetails.ANY_VERSION);
88+
public static ShimmerVerObject svoS3RUsbComms = new ShimmerVerObject(HW_ID.SHIMMER_3R,FW_ID.LOGANDSTREAM,1,0,27,ShimmerVerDetails.ANY_VERSION);
8889

8990
//TODO improve
9091
public static List<ShimmerVerObject> listOfCompatibleVersionInfoGqBle = Arrays.asList(svoGqBle);
9192
public static List<ShimmerVerObject> listOfCompatibleVersionInfoGq802154 = Arrays.asList(svoGq802154NR, svoGq802154LR, svoGq802154Shimmer2r);
9293
public static List<ShimmerVerObject> listOfCompatibleVersionInfoGq = Arrays.asList(svoGqBle, svoGq802154NR, svoGq802154LR, svoGq802154Shimmer2r);
9394
public static List<ShimmerVerObject> listOfCompatibleVersionInfoTest = Arrays.asList(svoS3Test, svoS3RTest);
95+
public static List<ShimmerVerObject> listOfCompatibleVersionInfoUsbDfu = Arrays.asList(svoS3RUsbComms);
9496

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

0 commit comments

Comments
 (0)