mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-08-24 16:21:16 +02:00
Bangle.js:actTrk: move package count inside class
This commit is contained in:
parent
6eb97eeb15
commit
1660f4b7fa
@ -94,22 +94,23 @@ class BangleJSActivityTrack {
|
||||
return o;
|
||||
}
|
||||
|
||||
static JSONArray handleActTrk(JSONObject json, JSONArray tracksList, int prevPacketCount, GBDevice device, Context context) throws JSONException {
|
||||
private static int lastPacketCount = -1;
|
||||
static JSONArray handleActTrk(JSONObject json, JSONArray tracksList, GBDevice device, Context context) throws JSONException {
|
||||
stopAndRestartTimeout(device, context);
|
||||
|
||||
JSONArray returnArray;
|
||||
|
||||
JSONObject stopObj = new JSONObject().put("t","fetchRec").put("id","stop");
|
||||
int currPacketCount;
|
||||
if (json.has("cnt")) {
|
||||
currPacketCount = json.getInt("cnt");
|
||||
} else {
|
||||
if (!json.has("cnt")) {
|
||||
currPacketCount = 0;
|
||||
} else {
|
||||
currPacketCount = json.getInt("cnt");
|
||||
}
|
||||
if (currPacketCount != prevPacketCount+1) {
|
||||
if (currPacketCount != lastPacketCount+1) {
|
||||
LOG.error("Activity Track Packets came out of order - aborting.");
|
||||
LOG.debug("packetCount Aborting: " + prevPacketCount);
|
||||
returnArray = new JSONArray().put(stopObj).put(tracksList).put(prevPacketCount);
|
||||
LOG.debug("packetCount Aborting: " + lastPacketCount);
|
||||
returnArray = new JSONArray().put(stopObj).put(tracksList);
|
||||
signalFetchingEnded(device, context);
|
||||
stopTimeoutTask();
|
||||
return returnArray;
|
||||
@ -124,7 +125,8 @@ class BangleJSActivityTrack {
|
||||
try {
|
||||
dir = FileUtils.getExternalFilesDir();
|
||||
} catch (IOException e) {
|
||||
returnArray = new JSONArray().put(null).put(tracksList).put(currPacketCount);
|
||||
returnArray = new JSONArray().put(null).put(tracksList);
|
||||
resetPacketCount();
|
||||
return returnArray;
|
||||
}
|
||||
|
||||
@ -133,15 +135,14 @@ class BangleJSActivityTrack {
|
||||
parseFetchedRecorderCSV(dir, filename, log, device, context); // I tried refactoring to parse all fetched logs in one go at the end instead. But that only gave me more troubles. This seems like a more stable approach at least in the Bangle.js case.
|
||||
if (tracksList.length()==0) {
|
||||
signalFetchingEnded(device, context);
|
||||
int resetPacketCount = -1;
|
||||
LOG.debug("packetCount reset1: " + resetPacketCount);
|
||||
returnArray = new JSONArray().put(null).put(tracksList).put(resetPacketCount);
|
||||
LOG.debug("packetCount reset1: " + lastPacketCount);
|
||||
returnArray = new JSONArray().put(null).put(tracksList);
|
||||
} else {
|
||||
JSONObject requestTrackObj = BangleJSActivityTrack.compileTrackRequest(tracksList.getString(0), 1==tracksList.length());
|
||||
tracksList.remove(0);
|
||||
int resetPacketCount = -1;
|
||||
LOG.debug("packetCount reset2: " + resetPacketCount);
|
||||
returnArray = new JSONArray().put(requestTrackObj).put(tracksList).put(resetPacketCount);
|
||||
resetPacketCount();
|
||||
LOG.debug("packetCount reset2: " + lastPacketCount);
|
||||
returnArray = new JSONArray().put(requestTrackObj).put(tracksList);
|
||||
}
|
||||
} else { // We received a lines of the csv, now we append it to the file in storage.
|
||||
|
||||
@ -150,13 +151,18 @@ class BangleJSActivityTrack {
|
||||
|
||||
writeToRecorderCSV(lines, dir, filename);
|
||||
|
||||
LOG.debug("packetCount continue: " + currPacketCount);
|
||||
returnArray = new JSONArray().put(null).put(tracksList).put(currPacketCount);
|
||||
lastPacketCount += 1;
|
||||
LOG.debug("packetCount continue: " + lastPacketCount);
|
||||
returnArray = new JSONArray().put(null).put(tracksList);
|
||||
}
|
||||
|
||||
return returnArray;
|
||||
}
|
||||
|
||||
private static void resetPacketCount() {
|
||||
lastPacketCount = -1;
|
||||
}
|
||||
|
||||
private static void parseFetchedRecorderCSV(File dir, String filename, String log, GBDevice device, Context context) {
|
||||
stopTimeoutTask(); // Parsing can take a while if there are many data. Restart at end of parsing.
|
||||
|
||||
@ -651,6 +657,7 @@ class BangleJSActivityTrack {
|
||||
|
||||
private static void signalFetchingEnded(GBDevice device, Context context) {
|
||||
stopTimeoutTask();
|
||||
resetPacketCount();
|
||||
device.unsetBusyTask();
|
||||
device.sendDeviceUpdateIntent(context);
|
||||
GB.updateTransferNotification(null, "", false, 100, context);
|
||||
|
@ -515,7 +515,6 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
|
||||
private JSONArray tracksList;
|
||||
private int packetCount;
|
||||
private void handleUartRxJSON(JSONObject json) throws JSONException {
|
||||
String packetType = json.getString("t");
|
||||
switch (packetType) {
|
||||
@ -570,16 +569,12 @@ 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":
|
||||
LOG.debug("packetCount1: " + packetCount);
|
||||
JSONArray returnArray = BangleJSActivityTrack.handleActTrk(json, tracksList, packetCount, getDevice(), getContext());
|
||||
JSONArray returnArray = BangleJSActivityTrack.handleActTrk(json, tracksList, getDevice(), getContext());
|
||||
if (!returnArray.isNull(0)) uartTxJSON("requestActivityTrackLog", returnArray.getJSONObject(0));
|
||||
tracksList = returnArray.getJSONArray(1);
|
||||
packetCount = returnArray.getInt(2);
|
||||
LOG.debug("packetCount2: " + packetCount);
|
||||
break;
|
||||
case "http":
|
||||
handleHttp(json);
|
||||
|
Loading…
Reference in New Issue
Block a user