From a85a6912edabe92c03ef94d9324932684d053250 Mon Sep 17 00:00:00 2001 From: pmithrandir Date: Sat, 23 Mar 2024 12:35:48 +0100 Subject: [PATCH 1/3] get status is not useful as post request send all data needed to calculate the status. --- source/GarminSDComms.mc | 81 ++++++++--------------------------------- 1 file changed, 15 insertions(+), 66 deletions(-) diff --git a/source/GarminSDComms.mc b/source/GarminSDComms.mc index c57fef2..12b8d06 100644 --- a/source/GarminSDComms.mc +++ b/source/GarminSDComms.mc @@ -33,11 +33,9 @@ class GarminSDComms { var mAccelHandler = null; var lastOnReceiveResponse = -1; var lastOnReceiveData = ""; - var lastOnSdStatusReceiveResponse = -1; var mDataRequestInProgress = 0; var mDataSendStartTime = Time.now(); var mSettingsRequestInProgress = 0; - var mStatusRequestInProgress = 0; var TIMEOUT = new Time.Duration(5); //var serverUrl = "http:192.168.43.1:8080"; var serverUrl = "http://127.0.0.1:8080"; @@ -47,7 +45,6 @@ class GarminSDComms { mAccelHandler = accelHandler; mDataRequestInProgress = 0; mSettingsRequestInProgress = 0; - mStatusRequestInProgress = 0; // Start a timer that calls timerCallback every half second mTimer = new Timer.Timer(); @@ -66,7 +63,7 @@ class GarminSDComms { var waitingTime = Time.now().subtract(mDataSendStartTime); if ((mDataRequestInProgress) && (waitingTime.lessThan(TIMEOUT))){ // Don't start another one. - writeLog(tagStr,"mDataRequestInProgress="+mDataRequestInProgress+", "+ mSettingsRequestInProgress+ ", " + mStatusRequestInProgress); + writeLog(tagStr,"mDataRequestInProgress="+mDataRequestInProgress+", "+ mSettingsRequestInProgress); } else { //writeLog(tagStr, "sendAccelData Start"); var dataObj = mAccelHandler.getDataJson(); @@ -103,32 +100,21 @@ class GarminSDComms { ); } - function getSdStatus() { - writeLog("SDComms.getSdStatus()", ""); - mStatusRequestInProgress = 1; - Comm.makeWebRequest( - serverUrl + "/data", - {}, - { - :method => Communications.HTTP_REQUEST_METHOD_GET, - :headers => { - "Content-Type" => Communications.REQUEST_CONTENT_TYPE_URL_ENCODED, - }, - :responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON, - }, - method(:onSdStatusReceive) - ); - //System.println("getSdStatus Exiting"); - } - - // Receive the data from the web request - should be a json string - function onSdStatusReceive(responseCode, data) { - var tagStr = "SDComms.onSdStatusReceive"; - writeLog(tagStr, "ResponseCode="+responseCode); + // Receive the response from the sendAccelData web request. + function onDataReceive(responseCode, data) { + var tagStr = "SDComms.onDataReceive()"; + var sendDuration = Time.now().subtract(mDataSendStartTime); + writeLog(tagStr, "sendAccelData End - Send Duration = " + sendDuration.value()); if (responseCode == 200) { - if (responseCode != lastOnSdStatusReceiveResponse) { - #writeLog(tagStr, "success - data =" + data); - writeLog(tagStr, "Status =" + data.get("alarmPhrase")); + writeLog(tagStr, "Success - data =" + data); + if (responseCode != lastOnReceiveResponse || data != lastOnReceiveData) { + writeLog(tagStr, "Success - data =" + data); + } else { + // Don't write repeated log entries. + } + if (data.equals("sendSettings")) { + //System.println("Sending Settings"); + sendSettings(); } mAccelHandler.mStatusStr = data.get("alarmPhrase"); if (data.get("alarmState") != 0) { @@ -164,37 +150,6 @@ class GarminSDComms { } else { mAccelHandler.mStatusStr = Ui.loadResource(Rez.Strings.Error_abbrev) + ": " + responseCode.toString(); - if (responseCode != lastOnSdStatusReceiveResponse) { - writeLog(tagStr, "Failue - code =" + responseCode); - writeLog(tagStr, "Failure - data =" + data); - } else { - // Don't write repeated log entries to save filling up the log file. - } - } - lastOnSdStatusReceiveResponse = responseCode; - mStatusRequestInProgress = 0; - } - - // Receive the response from the sendAccelData web request. - function onDataReceive(responseCode, data) { - var tagStr = "SDComms.onDataReceive()"; - var sendDuration = Time.now().subtract(mDataSendStartTime); - writeLog(tagStr, "sendAccelData End - Send Duration = " + sendDuration.value()); - if (responseCode == 200) { - if (responseCode != lastOnReceiveResponse || data != lastOnReceiveData) { - writeLog(tagStr, "Success - data =" + data); - } else { - // Don't write repeated log entries. - } - if (data.equals("sendSettings")) { - //System.println("Sending Settings"); - sendSettings(); - } else { - //System.println("getting sd status"); - getSdStatus(); - } - } else { - mAccelHandler.mStatusStr = "ERR: " + responseCode.toString(); var soundEnabled = Storage.getValue(MENUITEM_SOUND) ? true : false; if (Attention has :playTone && soundEnabled) { Attention.playTone(Attention.TONE_LOUD_BEEP); @@ -206,12 +161,6 @@ class GarminSDComms { ]; Attention.vibrate(vibeData); } - - if (responseCode != lastOnReceiveResponse) { - writeLog(tagStr, "Failure - code =" + responseCode); - } else { - // - } } lastOnReceiveResponse = responseCode; lastOnReceiveData = data; From 59a29c54af39ea51cd14291129a813c4e5b29096 Mon Sep 17 00:00:00 2001 From: pmithrandir Date: Sat, 23 Mar 2024 13:36:05 +0100 Subject: [PATCH 2/3] post status could send back something else than data... making sure we don't use it then. --- source/GarminSDComms.mc | 57 +++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/source/GarminSDComms.mc b/source/GarminSDComms.mc index 12b8d06..dbe933d 100644 --- a/source/GarminSDComms.mc +++ b/source/GarminSDComms.mc @@ -106,7 +106,6 @@ class GarminSDComms { var sendDuration = Time.now().subtract(mDataSendStartTime); writeLog(tagStr, "sendAccelData End - Send Duration = " + sendDuration.value()); if (responseCode == 200) { - writeLog(tagStr, "Success - data =" + data); if (responseCode != lastOnReceiveResponse || data != lastOnReceiveData) { writeLog(tagStr, "Success - data =" + data); } else { @@ -116,35 +115,37 @@ class GarminSDComms { //System.println("Sending Settings"); sendSettings(); } - mAccelHandler.mStatusStr = data.get("alarmPhrase"); - if (data.get("alarmState") != 0) { - try { - var lightEnabled = Storage.getValue(MENUITEM_LIGHT) ? true : false; - if (Attention has :backlight && lightEnabled) { - Attention.backlight(true); + else{ + mAccelHandler.mStatusStr = data.get("alarmPhrase"); + if (data.get("alarmState") != 0) { + try { + var lightEnabled = Storage.getValue(MENUITEM_LIGHT) ? true : false; + if (Attention has :backlight && lightEnabled) { + Attention.backlight(true); + } + } catch (ex) { + // We might get a Toybox.Attention.BacklightOnTooLongException + } + var soundEnabled = Storage.getValue(MENUITEM_SOUND) ? true : false; + if (Attention has :playTone && soundEnabled) { + Attention.playTone(Attention.TONE_ALERT_HI); } - } catch (ex) { - // We might get a Toybox.Attention.BacklightOnTooLongException - } - var soundEnabled = Storage.getValue(MENUITEM_SOUND) ? true : false; - if (Attention has :playTone && soundEnabled) { - Attention.playTone(Attention.TONE_ALERT_HI); } - } - if (data.get("alarmState") == 2) { - // ALARM - var vibrationEnabled = Storage.getValue(MENUITEM_VIBRATION) - ? true - : false; - if (Attention has :vibrate && vibrationEnabled) { - var vibeData = [ - new Attention.VibeProfile(50, 500), - new Attention.VibeProfile(0, 500), - new Attention.VibeProfile(50, 500), - new Attention.VibeProfile(0, 500), - new Attention.VibeProfile(50, 500), - ]; - Attention.vibrate(vibeData); + if (data.get("alarmState") == 2) { + // ALARM + var vibrationEnabled = Storage.getValue(MENUITEM_VIBRATION) + ? true + : false; + if (Attention has :vibrate && vibrationEnabled) { + var vibeData = [ + new Attention.VibeProfile(50, 500), + new Attention.VibeProfile(0, 500), + new Attention.VibeProfile(50, 500), + new Attention.VibeProfile(0, 500), + new Attention.VibeProfile(50, 500), + ]; + Attention.vibrate(vibeData); + } } } } else { From 3e46adfa55c418bfe76656df7ca19bbc28c1ce23 Mon Sep 17 00:00:00 2001 From: pmithrandir Date: Sat, 23 Mar 2024 13:50:54 +0100 Subject: [PATCH 3/3] post status could send back something else than data... making sure we don't use it then. --- source/GarminSDComms.mc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/GarminSDComms.mc b/source/GarminSDComms.mc index dbe933d..2a4cf10 100644 --- a/source/GarminSDComms.mc +++ b/source/GarminSDComms.mc @@ -106,6 +106,7 @@ class GarminSDComms { var sendDuration = Time.now().subtract(mDataSendStartTime); writeLog(tagStr, "sendAccelData End - Send Duration = " + sendDuration.value()); if (responseCode == 200) { + writeLog(tagStr, "Success - data =" + data); if (responseCode != lastOnReceiveResponse || data != lastOnReceiveData) { writeLog(tagStr, "Success - data =" + data); } else { @@ -115,7 +116,7 @@ class GarminSDComms { //System.println("Sending Settings"); sendSettings(); } - else{ + if (data has :alarmPhrase) { mAccelHandler.mStatusStr = data.get("alarmPhrase"); if (data.get("alarmState") != 0) { try {