Skip to content

Commit 242362b

Browse files
Merge pull request #75 from ShimmerEngineering/AA-303
AA-303
2 parents 4591304 + 7bc7283 commit 242362b

File tree

3 files changed

+32
-3
lines changed
  • ShimmerAndroidInstrumentDriver
    • ShimmerAndroidInstrumentDriver/src/main/java/com/shimmerresearch/android
    • efficientDataArrayExample/src/main/java/com/shimmerresearch/efficientdataarrayexample
    • shimmerServiceExample/src/main/java/com/shimmerresearch/shimmerserviceexample

3 files changed

+32
-3
lines changed

ShimmerAndroidInstrumentDriver/ShimmerAndroidInstrumentDriver/src/main/java/com/shimmerresearch/android/Shimmer.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -745,11 +745,17 @@ protected void clearSingleDataPacketFromBuffers(byte[] bufferTemp, int packetSiz
745745
}
746746

747747
}
748-
749748
@Override
750749
protected void processPacket() {
751750
setIamAlive(true);
752751
byte[] allBytes = mByteArrayOutputStream.toByteArray();
752+
//consolePrintLn("Byte Array Size: " + allBytes.length);
753+
if (mByteArrayOutputStream.size()>10000){
754+
mByteArrayOutputStream.reset();
755+
mListofPCTimeStamps.clear();
756+
consolePrintLn("Byte Array Size (reset): " + mByteArrayOutputStream.size());
757+
return;
758+
}
753759
byte[] bufferTemp = new byte[getPacketSizeWithCrc()+2];
754760
System.arraycopy(allBytes,0,bufferTemp,0,bufferTemp.length);
755761
//Data packet followed by another data packet
@@ -864,6 +870,7 @@ protected void processInstreamResponse() {
864870
consolePrintLn("In-stream received = " + btCommandToString(inStreamResponseCommand));
865871

866872
if (inStreamResponseCommand == DIR_RESPONSE) {
873+
printLogDataForDebugging("IN STREAM: DIR_RESPONSE");
867874
//byte[] responseData = readBytes(1, inStreamResponseCommand);
868875
bufferTemp = getDataFromArrayOutputStream(5);
869876
if (bufferTemp != null) {
@@ -880,6 +887,7 @@ protected void processInstreamResponse() {
880887
clearSingleDataPacketFromBuffers(bufferTemp, bufferTemp.length + mBtCommsCrcModeCurrent.getNumCrcBytes());
881888
}
882889
} else if (inStreamResponseCommand == STATUS_RESPONSE) {
890+
printLogDataForDebugging("IN STREAM: STATUS_RESPONSE");
883891
bufferTemp = getDataFromArrayOutputStream(5);
884892
if (bufferTemp != null) {
885893
byte[] responseData = new byte[1];
@@ -903,6 +911,7 @@ protected void processInstreamResponse() {
903911
}
904912
}
905913
} else if (inStreamResponseCommand == VBATT_RESPONSE) {
914+
printLogDataForDebugging("IN STREAM: VBATT_RESPONSE");
906915
bufferTemp = getDataFromArrayOutputStream(7);
907916
if (bufferTemp != null) {
908917
byte[] responseData = new byte[3];
@@ -922,6 +931,8 @@ protected void processInstreamResponse() {
922931
} else {
923932
discardFirstBufferByte();
924933
}
934+
} else {
935+
printLogDataForDebugging("IN STREAM: buffer temp is null, byte array output stream size is " + mByteArrayOutputStream.size());
925936
}
926937
}
927938
}
@@ -932,7 +943,10 @@ protected void processWhileStreaming() {
932943
byte[] byteBuffer = readBytes(availableBytes());
933944
if(byteBuffer!=null){
934945
try {
935-
mByteArrayOutputStream.write(byteBuffer);
946+
if (byteBuffer.length>0) {
947+
//consolePrintLn("Byte Array Size put in : " + byteBuffer.length);
948+
mByteArrayOutputStream.write(byteBuffer);
949+
}
936950
} catch (IOException e) {
937951
throw new RuntimeException(e);
938952
}
@@ -948,11 +962,18 @@ protected void processWhileStreaming() {
948962
}
949963

950964
//If there is a full packet and the subsequent sequence number of following packet
951-
if(mByteArrayOutputStream.size()>=getPacketSizeWithCrc()+2){ // +2 because there are two acks
965+
int size = mByteArrayOutputStream.size();
966+
while(mByteArrayOutputStream.size()>=getPacketSizeWithCrc()+2){ // +2 because there are two acks
952967
processPacket();
968+
int newSize = mByteArrayOutputStream.size();
969+
if (size == newSize){
970+
consolePrintLn("processWhileStreaming: Leaving while loop");
971+
break;
972+
}
953973
}
954974
}
955975

976+
956977
/**this is to clear the buffer
957978
*
958979
*/

ShimmerAndroidInstrumentDriver/efficientDataArrayExample/src/main/java/com/shimmerresearch/efficientdataarrayexample/MainActivity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ public void startStreaming(View v) {
141141
setupCSV();
142142
//Disable PC timestamps for better performance. Disabling this takes the timestamps on every full packet received instead of on every byte received.
143143
shimmer.enablePCTimeStamps(false);
144+
//Disable timers for better performance.
145+
shimmer.stopAllTimers();
144146
//Enable the arrays data structure. Note that enabling this will disable the Multimap/FormatCluster data structure
145147
shimmer.enableArraysDataStructure(true);
146148
try {

ShimmerAndroidInstrumentDriver/shimmerServiceExample/src/main/java/com/shimmerresearch/shimmerserviceexample/MainActivity.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ public boolean onOptionsItemSelected(MenuItem item) {
238238
if(selectedDeviceAddress != null) {
239239

240240
ShimmerDevice mDevice = mService.getShimmer(selectedDeviceAddress);
241+
if (mDevice instanceof ShimmerBluetooth) {
242+
//Disable PC timestamps for better performance. Disabling this takes the timestamps on every full packet received instead of on every byte received.
243+
((ShimmerBluetooth) mDevice).enablePCTimeStamps(false);
244+
//Disable timers for better performance.
245+
((ShimmerBluetooth) mDevice).stopAllTimers();
246+
}
241247
try {
242248
mDevice.startStreaming();
243249
mViewPager.setCurrentItem(mDevice instanceof VerisenseDevice ? 5 : 4);

0 commit comments

Comments
 (0)