diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/banglejs/BangleJSActivityTrack.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/banglejs/BangleJSActivityTrack.java index 58eb43646..64b682989 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/banglejs/BangleJSActivityTrack.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/banglejs/BangleJSActivityTrack.java @@ -103,7 +103,28 @@ public class BangleJSActivityTrack extends BangleJSDeviceSupport { return o; } - public static JSONArray handleActTrk(JSONObject json, JSONArray tracksList, GBDevice device, Context context) throws JSONException { + private void stopFunc() { + + } + + public static JSONArray handleActTrk(JSONObject json, JSONArray tracksList, int prevPacketCount, GBDevice device, Context context) throws JSONException { + JSONArray returnArray; + + JSONObject stopObj = new JSONObject().put("t","fetchRec").put("id","stop"); + int currPacketCount; + if (json.has("cnt")) { + currPacketCount = json.getInt("cnt"); + } else { + currPacketCount = 0; + } + if (false && currPacketCount != prevPacketCount+1) { + LOG.error("Activity Track Packets came out of order - aborting."); + returnArray = new JSONArray().put(stopObj).put(tracksList).put(prevPacketCount); + device.unsetBusyTask(); + GB.updateTransferNotification(context.getString(R.string.busy_task_fetch_activity_data), "", false, 100, context); + return returnArray; + } + LOG.info("actTrk says hi!"); //GB.toast(context, "actTrk says hi!", Toast.LENGTH_LONG, GB.INFO); String log = json.getString("log"); @@ -112,7 +133,7 @@ public class BangleJSActivityTrack extends BangleJSDeviceSupport { try { dir = FileUtils.getExternalFilesDir(); } catch (IOException e) { - JSONArray returnArray = new JSONArray().put(null).put(tracksList); + returnArray = new JSONArray().put(null).put(tracksList).put(currPacketCount); return returnArray; } String filename = "recorder.log" + log + ".csv"; @@ -122,10 +143,12 @@ public class BangleJSActivityTrack extends BangleJSDeviceSupport { if (tracksList.length()==0) { device.unsetBusyTask(); GB.updateTransferNotification(context.getString(R.string.busy_task_fetch_activity_data), "", false, 100, context); + returnArray = new JSONArray().put(null).put(tracksList).put(-1); + return returnArray; } else { JSONObject requestTrackObj = BangleJSActivityTrack.compileTrackRequest(tracksList.getString(0), 1==tracksList.length()); tracksList.remove(0); - JSONArray returnArray = new JSONArray().put(requestTrackObj).put(tracksList); + returnArray = new JSONArray().put(requestTrackObj).put(tracksList).put(currPacketCount); return returnArray; } } else { // We received a lines of the csv, now we append it to the file in storage. @@ -153,7 +176,7 @@ public class BangleJSActivityTrack extends BangleJSDeviceSupport { } } - JSONArray returnArray = new JSONArray().put(null).put(tracksList); + returnArray = new JSONArray().put(null).put(tracksList).put(currPacketCount); return returnArray; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/banglejs/BangleJSDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/banglejs/BangleJSDeviceSupport.java index 850450bdb..e25f91892 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/banglejs/BangleJSDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/banglejs/BangleJSDeviceSupport.java @@ -515,6 +515,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport { } JSONArray tracksList; + int packetCount; private void handleUartRxJSON(JSONObject json) throws JSONException { String packetType = json.getString("t"); switch (packetType) { @@ -570,12 +571,15 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport { JSONObject requestTrackObj = BangleJSActivityTrack.compileTrackRequest(tracksList.getString(0), 1==tracksList.length()); uartTxJSON("requestActivityTrackLog", requestTrackObj); tracksList.remove(0); + packetCount = -1; } break; case "actTrk": - JSONArray returnArray = BangleJSActivityTrack.handleActTrk(json, tracksList, getDevice(), getContext()); + + JSONArray returnArray = BangleJSActivityTrack.handleActTrk(json, tracksList, packetCount, getDevice(), getContext()); if (!returnArray.isNull(0)) uartTxJSON("requestActivityTrackLog", returnArray.getJSONObject(0)); tracksList = returnArray.getJSONArray(1); + packetCount = returnArray.getInt(2); break; case "http": handleHttp(json);