mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-13 03:07:32 +01: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;
|
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);
|
stopAndRestartTimeout(device, context);
|
||||||
|
|
||||||
JSONArray returnArray;
|
JSONArray returnArray;
|
||||||
|
|
||||||
JSONObject stopObj = new JSONObject().put("t","fetchRec").put("id","stop");
|
JSONObject stopObj = new JSONObject().put("t","fetchRec").put("id","stop");
|
||||||
int currPacketCount;
|
int currPacketCount;
|
||||||
if (json.has("cnt")) {
|
if (!json.has("cnt")) {
|
||||||
currPacketCount = json.getInt("cnt");
|
|
||||||
} else {
|
|
||||||
currPacketCount = 0;
|
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.error("Activity Track Packets came out of order - aborting.");
|
||||||
LOG.debug("packetCount Aborting: " + prevPacketCount);
|
LOG.debug("packetCount Aborting: " + lastPacketCount);
|
||||||
returnArray = new JSONArray().put(stopObj).put(tracksList).put(prevPacketCount);
|
returnArray = new JSONArray().put(stopObj).put(tracksList);
|
||||||
signalFetchingEnded(device, context);
|
signalFetchingEnded(device, context);
|
||||||
stopTimeoutTask();
|
stopTimeoutTask();
|
||||||
return returnArray;
|
return returnArray;
|
||||||
@ -124,7 +125,8 @@ class BangleJSActivityTrack {
|
|||||||
try {
|
try {
|
||||||
dir = FileUtils.getExternalFilesDir();
|
dir = FileUtils.getExternalFilesDir();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
returnArray = new JSONArray().put(null).put(tracksList).put(currPacketCount);
|
returnArray = new JSONArray().put(null).put(tracksList);
|
||||||
|
resetPacketCount();
|
||||||
return returnArray;
|
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.
|
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) {
|
if (tracksList.length()==0) {
|
||||||
signalFetchingEnded(device, context);
|
signalFetchingEnded(device, context);
|
||||||
int resetPacketCount = -1;
|
LOG.debug("packetCount reset1: " + lastPacketCount);
|
||||||
LOG.debug("packetCount reset1: " + resetPacketCount);
|
returnArray = new JSONArray().put(null).put(tracksList);
|
||||||
returnArray = new JSONArray().put(null).put(tracksList).put(resetPacketCount);
|
|
||||||
} else {
|
} else {
|
||||||
JSONObject requestTrackObj = BangleJSActivityTrack.compileTrackRequest(tracksList.getString(0), 1==tracksList.length());
|
JSONObject requestTrackObj = BangleJSActivityTrack.compileTrackRequest(tracksList.getString(0), 1==tracksList.length());
|
||||||
tracksList.remove(0);
|
tracksList.remove(0);
|
||||||
int resetPacketCount = -1;
|
resetPacketCount();
|
||||||
LOG.debug("packetCount reset2: " + resetPacketCount);
|
LOG.debug("packetCount reset2: " + lastPacketCount);
|
||||||
returnArray = new JSONArray().put(requestTrackObj).put(tracksList).put(resetPacketCount);
|
returnArray = new JSONArray().put(requestTrackObj).put(tracksList);
|
||||||
}
|
}
|
||||||
} else { // We received a lines of the csv, now we append it to the file in storage.
|
} 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);
|
writeToRecorderCSV(lines, dir, filename);
|
||||||
|
|
||||||
LOG.debug("packetCount continue: " + currPacketCount);
|
lastPacketCount += 1;
|
||||||
returnArray = new JSONArray().put(null).put(tracksList).put(currPacketCount);
|
LOG.debug("packetCount continue: " + lastPacketCount);
|
||||||
|
returnArray = new JSONArray().put(null).put(tracksList);
|
||||||
}
|
}
|
||||||
|
|
||||||
return returnArray;
|
return returnArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void resetPacketCount() {
|
||||||
|
lastPacketCount = -1;
|
||||||
|
}
|
||||||
|
|
||||||
private static void parseFetchedRecorderCSV(File dir, String filename, String log, GBDevice device, Context context) {
|
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.
|
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) {
|
private static void signalFetchingEnded(GBDevice device, Context context) {
|
||||||
stopTimeoutTask();
|
stopTimeoutTask();
|
||||||
|
resetPacketCount();
|
||||||
device.unsetBusyTask();
|
device.unsetBusyTask();
|
||||||
device.sendDeviceUpdateIntent(context);
|
device.sendDeviceUpdateIntent(context);
|
||||||
GB.updateTransferNotification(null, "", false, 100, context);
|
GB.updateTransferNotification(null, "", false, 100, context);
|
||||||
|
@ -515,7 +515,6 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private JSONArray tracksList;
|
private JSONArray tracksList;
|
||||||
private int packetCount;
|
|
||||||
private void handleUartRxJSON(JSONObject json) throws JSONException {
|
private void handleUartRxJSON(JSONObject json) throws JSONException {
|
||||||
String packetType = json.getString("t");
|
String packetType = json.getString("t");
|
||||||
switch (packetType) {
|
switch (packetType) {
|
||||||
@ -570,16 +569,12 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
JSONObject requestTrackObj = BangleJSActivityTrack.compileTrackRequest(tracksList.getString(0), 1==tracksList.length());
|
JSONObject requestTrackObj = BangleJSActivityTrack.compileTrackRequest(tracksList.getString(0), 1==tracksList.length());
|
||||||
uartTxJSON("requestActivityTrackLog", requestTrackObj);
|
uartTxJSON("requestActivityTrackLog", requestTrackObj);
|
||||||
tracksList.remove(0);
|
tracksList.remove(0);
|
||||||
packetCount = -1;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "actTrk":
|
case "actTrk":
|
||||||
LOG.debug("packetCount1: " + packetCount);
|
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));
|
if (!returnArray.isNull(0)) uartTxJSON("requestActivityTrackLog", returnArray.getJSONObject(0));
|
||||||
tracksList = returnArray.getJSONArray(1);
|
tracksList = returnArray.getJSONArray(1);
|
||||||
packetCount = returnArray.getInt(2);
|
|
||||||
LOG.debug("packetCount2: " + packetCount);
|
|
||||||
break;
|
break;
|
||||||
case "http":
|
case "http":
|
||||||
handleHttp(json);
|
handleHttp(json);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user