mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-25 03:16:51 +01:00
Bangle.js:actTrk: dataflow tweaks
This commit is contained in:
parent
d2e61c5fe8
commit
f3f9a75633
@ -69,7 +69,7 @@ class BangleJSActivityTrack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static JSONArray tracksList;
|
private static JSONArray tracksList;
|
||||||
static JSONArray handleActTrksList(JSONObject json, GBDevice device, Context context) throws JSONException {
|
static JSONObject handleActTrksList(JSONObject json, GBDevice device, Context context) throws JSONException {
|
||||||
stopAndRestartTimeout(device, context);
|
stopAndRestartTimeout(device, context);
|
||||||
tracksList = json.getJSONArray("list");
|
tracksList = json.getJSONArray("list");
|
||||||
LOG.debug("trksList says hi!");
|
LOG.debug("trksList says hi!");
|
||||||
@ -79,27 +79,17 @@ class BangleJSActivityTrack {
|
|||||||
signalFetchingEnded(device, context);
|
signalFetchingEnded(device, context);
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
return tracksList;
|
JSONObject requestTrackObj = BangleJSActivityTrack.compileTrackRequest(tracksList.getString(0), 1==tracksList.length());
|
||||||
|
tracksList.remove(0);
|
||||||
|
return requestTrackObj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSONObject compileTrackRequest(String id, Boolean isLastId) {
|
|
||||||
JSONObject o = new JSONObject();
|
|
||||||
try {
|
|
||||||
o.put("t", "fetchRec");
|
|
||||||
o.put("id", id);
|
|
||||||
o.put("last", String.valueOf(isLastId));
|
|
||||||
} catch (JSONException e) {
|
|
||||||
LOG.error("JSONException: " + e.getLocalizedMessage());
|
|
||||||
}
|
|
||||||
return o;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int lastPacketCount = -1;
|
private static int lastPacketCount = -1;
|
||||||
static JSONArray handleActTrk(JSONObject json, GBDevice device, Context context) throws JSONException {
|
static JSONObject handleActTrk(JSONObject json, GBDevice device, Context context) throws JSONException {
|
||||||
stopAndRestartTimeout(device, context);
|
stopAndRestartTimeout(device, context);
|
||||||
|
|
||||||
JSONArray returnArray;
|
JSONObject returnObj;
|
||||||
|
|
||||||
JSONObject stopObj = new JSONObject().put("t","fetchRec").put("id","stop");
|
JSONObject stopObj = new JSONObject().put("t","fetchRec").put("id","stop");
|
||||||
int currPacketCount;
|
int currPacketCount;
|
||||||
@ -111,10 +101,9 @@ class BangleJSActivityTrack {
|
|||||||
if (currPacketCount != lastPacketCount+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: " + lastPacketCount);
|
LOG.debug("packetCount Aborting: " + lastPacketCount);
|
||||||
returnArray = new JSONArray().put(stopObj);
|
|
||||||
signalFetchingEnded(device, context);
|
signalFetchingEnded(device, context);
|
||||||
stopTimeoutTask();
|
stopTimeoutTask();
|
||||||
return returnArray;
|
return stopObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.debug("actTrk says hi!");
|
LOG.debug("actTrk says hi!");
|
||||||
@ -126,9 +115,8 @@ class BangleJSActivityTrack {
|
|||||||
try {
|
try {
|
||||||
dir = FileUtils.getExternalFilesDir();
|
dir = FileUtils.getExternalFilesDir();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
returnArray = new JSONArray().put(null);
|
|
||||||
resetPacketCount();
|
resetPacketCount();
|
||||||
return returnArray;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!json.has("lines")) { // if no lines were sent with this json object, it signifies that the whole recorder log has been transmitted.
|
if (!json.has("lines")) { // if no lines were sent with this json object, it signifies that the whole recorder log has been transmitted.
|
||||||
@ -137,13 +125,13 @@ class BangleJSActivityTrack {
|
|||||||
if (tracksList.length()==0) {
|
if (tracksList.length()==0) {
|
||||||
signalFetchingEnded(device, context);
|
signalFetchingEnded(device, context);
|
||||||
LOG.debug("packetCount reset1: " + lastPacketCount);
|
LOG.debug("packetCount reset1: " + lastPacketCount);
|
||||||
returnArray = new JSONArray().put(null);
|
returnObj = null;
|
||||||
} 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);
|
||||||
resetPacketCount();
|
resetPacketCount();
|
||||||
LOG.debug("packetCount reset2: " + lastPacketCount);
|
LOG.debug("packetCount reset2: " + lastPacketCount);
|
||||||
returnArray = new JSONArray().put(requestTrackObj);
|
returnObj = requestTrackObj;
|
||||||
}
|
}
|
||||||
} 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.
|
||||||
|
|
||||||
@ -154,14 +142,10 @@ class BangleJSActivityTrack {
|
|||||||
|
|
||||||
lastPacketCount += 1;
|
lastPacketCount += 1;
|
||||||
LOG.debug("packetCount continue: " + lastPacketCount);
|
LOG.debug("packetCount continue: " + lastPacketCount);
|
||||||
returnArray = new JSONArray().put(null);
|
returnObj = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return returnArray;
|
return returnObj;
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
||||||
@ -650,6 +634,22 @@ class BangleJSActivityTrack {
|
|||||||
stopAndRestartTimeout(device,context);
|
stopAndRestartTimeout(device,context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void resetPacketCount() {
|
||||||
|
lastPacketCount = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static JSONObject compileTrackRequest(String id, Boolean isLastId) {
|
||||||
|
JSONObject o = new JSONObject();
|
||||||
|
try {
|
||||||
|
o.put("t", "fetchRec");
|
||||||
|
o.put("id", id);
|
||||||
|
o.put("last", String.valueOf(isLastId));
|
||||||
|
} catch (JSONException e) {
|
||||||
|
LOG.error("JSONException: " + e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
private static void signalFetchingStarted(GBDevice device, Context context) {
|
private static void signalFetchingStarted(GBDevice device, Context context) {
|
||||||
GB.updateTransferNotification(context.getString(R.string.activity_detail_start_label) + " : " + context.getString(R.string.busy_task_fetch_sports_details),"", true, 0, context);
|
GB.updateTransferNotification(context.getString(R.string.activity_detail_start_label) + " : " + context.getString(R.string.busy_task_fetch_sports_details),"", true, 0, context);
|
||||||
device.setBusyTask(context.getString(R.string.busy_task_fetch_sports_details));
|
device.setBusyTask(context.getString(R.string.busy_task_fetch_sports_details));
|
||||||
|
@ -563,15 +563,12 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
handleActivity(json);
|
handleActivity(json);
|
||||||
break;
|
break;
|
||||||
case "actTrksList":
|
case "actTrksList":
|
||||||
JSONArray tracksList = BangleJSActivityTrack.handleActTrksList(json, getDevice(), getContext());
|
JSONObject requestTrackObj = BangleJSActivityTrack.handleActTrksList(json, getDevice(), getContext());
|
||||||
if (tracksList!=null) {
|
|
||||||
JSONObject requestTrackObj = BangleJSActivityTrack.compileTrackRequest(tracksList.getString(0), 1==tracksList.length());
|
|
||||||
uartTxJSON("requestActivityTrackLog", requestTrackObj);
|
uartTxJSON("requestActivityTrackLog", requestTrackObj);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case "actTrk":
|
case "actTrk":
|
||||||
JSONArray returnArray = BangleJSActivityTrack.handleActTrk(json, getDevice(), getContext());
|
requestTrackObj = BangleJSActivityTrack.handleActTrk(json, getDevice(), getContext());
|
||||||
if (!returnArray.isNull(0)) uartTxJSON("requestActivityTrackLog", returnArray.getJSONObject(0));
|
if (requestTrackObj!=null) uartTxJSON("requestActivityTrackLog", requestTrackObj);
|
||||||
break;
|
break;
|
||||||
case "http":
|
case "http":
|
||||||
handleHttp(json);
|
handleHttp(json);
|
||||||
|
Loading…
Reference in New Issue
Block a user