1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 12:56:49 +01:00

Bangle.js:actTrk:fetch all logs, then parse them

This commit is contained in:
Ganblejs 2024-03-06 02:59:55 +01:00 committed by José Rebelo
parent d8172295cb
commit 46be3c47f9
2 changed files with 24 additions and 6 deletions

View File

@ -58,6 +58,15 @@ class BangleJSActivityTrack extends BangleJSDeviceSupport {
GB.toast(context.getString(R.string.activity_detail_end_label) + " : " + context.getString(R.string.busy_task_fetch_sports_details), Toast.LENGTH_SHORT, GB.INFO);
}
static JSONArray makeDeepCopyOfJSONArray(JSONArray tracksList) throws JSONException {
JSONArray tracksListIntact = new JSONArray();
String[] tmpTracksList = tracksList.join(",").replace("\"","").split(","); // Hacky way to get a sort of deep copy.
for (int i = 0; i<tmpTracksList.length; i++) {
tracksListIntact.put(tmpTracksList[i]);
}
return tracksListIntact;
}
private static Timer timeout;
private static TimerTask timeoutTask;
@ -186,7 +195,7 @@ class BangleJSActivityTrack extends BangleJSDeviceSupport {
return o;
}
static JSONArray handleActTrk(JSONObject json, JSONArray tracksList, int prevPacketCount, GBDevice device, Context context) throws JSONException {
static JSONArray handleActTrk(JSONObject json, JSONArray tracksList, JSONArray tracksListIntact, int prevPacketCount, GBDevice device, Context context) throws JSONException {
stopAndRestartTimeout(device, context);
JSONArray returnArray;
@ -221,8 +230,14 @@ class BangleJSActivityTrack extends BangleJSDeviceSupport {
if (!json.has("lines")) { // if no lines were sent with this json object, it signifies that the whole recorder log has been transmitted.
setLatestFetchedRecorderLog(dir, log);
parseFetchedRecorderCSV(dir, filename, log, device, context); // TODO: Parsing could be done after we fetched all recorder logs instead, making the fetching quicker and maybe less prone to user errors.
if (tracksList.length()==0) {
if (tracksList.length()==0) { // All data from all Recorder logs have been fetched.
LOG.warn("tracksListIntact:\n" + tracksListIntact);
for (int i = 0; i<tracksListIntact.length(); i++){
String currLog = tracksListIntact.getString(i);
LOG.info("currLog: " + currLog);
String currFilename = "recorder.log" + currLog + ".csv";
parseFetchedRecorderCSV(dir, currFilename, currLog, device, context);
}
signalFetchingEnded(device, context);
int resetPacketCount = -1;
LOG.info("packetCount reset1: " + resetPacketCount);
@ -230,6 +245,7 @@ class BangleJSActivityTrack extends BangleJSDeviceSupport {
} else {
JSONObject requestTrackObj = BangleJSActivityTrack.compileTrackRequest(tracksList.getString(0), 1==tracksList.length());
tracksList.remove(0);
LOG.warn("tracksListIntact2:\n" + tracksListIntact);
int resetPacketCount = -1;
LOG.info("packetCount reset2: " + resetPacketCount);
returnArray = new JSONArray().put(requestTrackObj).put(tracksList).put(resetPacketCount);

View File

@ -514,8 +514,9 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
}
}
JSONArray tracksList;
int packetCount;
private JSONArray tracksList;
private JSONArray tracksListIntact;
private int packetCount;
private void handleUartRxJSON(JSONObject json) throws JSONException {
String packetType = json.getString("t");
switch (packetType) {
@ -569,13 +570,14 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
if (tracksList!=null) {
JSONObject requestTrackObj = BangleJSActivityTrack.compileTrackRequest(tracksList.getString(0), 1==tracksList.length());
uartTxJSON("requestActivityTrackLog", requestTrackObj);
tracksListIntact = BangleJSActivityTrack.makeDeepCopyOfJSONArray(tracksList);
tracksList.remove(0);
packetCount = -1;
}
break;
case "actTrk":
LOG.info("packetCount1: " + packetCount);
JSONArray returnArray = BangleJSActivityTrack.handleActTrk(json, tracksList, packetCount, getDevice(), getContext());
JSONArray returnArray = BangleJSActivityTrack.handleActTrk(json, tracksList, tracksListIntact, packetCount, getDevice(), getContext());
if (!returnArray.isNull(0)) uartTxJSON("requestActivityTrackLog", returnArray.getJSONObject(0));
tracksList = returnArray.getJSONArray(1);
packetCount = returnArray.getInt(2);