Skip to content

Commit b2fdcd5

Browse files
committed
Web Config: During save, transmit only the settings that have changed
1 parent 310b46a commit b2fdcd5

File tree

2 files changed

+67
-13
lines changed

2 files changed

+67
-13
lines changed

Firmware/RTK_Everywhere/AP-Config/src/main.js

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ const CoordinateTypes = {
7878
var convertedCoordinate = 0.0;
7979
var coordinateInputType = CoordinateTypes.COORDINATE_INPUT_TYPE_DD;
8080

81+
var initialSettings = {};
82+
8183
function parseIncoming(msg) {
8284
//console.log("Incoming message: " + msg);
8385

@@ -329,7 +331,7 @@ function parseIncoming(msg) {
329331
hide("logToSDCard"); //No SD card on Torch
330332

331333
hide("constellationSbas"); //Not supported on LG290P
332-
show("constellationNavic");
334+
show("constellationNavic");
333335
show("galileoHasSetting");
334336
show("lg290pGnssSettings");
335337
hide("tiltConfig"); //Not supported on Torch X2
@@ -724,7 +726,36 @@ function parseIncoming(msg) {
724726
dhcpEthernet();
725727
updateLatLong();
726728
updateCorrectionsPriorities();
729+
730+
// Create copy of settings, send only changes when 'Save Configuration' is pressed
731+
saveInitialSettings();
732+
}
733+
}
734+
735+
// Save the current state of settings
736+
function saveInitialSettings() {
737+
initialSettings = {}; // Clear previous settings
738+
739+
// Save input boxes and dropdowns
740+
var clsElements = document.querySelectorAll(".form-control, .form-dropdown");
741+
for (let x = 0; x < clsElements.length; x++) {
742+
initialSettings[clsElements[x].id] = clsElements[x].value;
743+
}
744+
745+
// Save checkboxes and radio buttons
746+
clsElements = document.querySelectorAll(".form-check-input:not(.fileManagerCheck), .form-radio");
747+
for (let x = 0; x < clsElements.length; x++) {
748+
// Store boolean values for easy comparison
749+
initialSettings[clsElements[x].id] = clsElements[x].checked.toString();
750+
}
751+
752+
// Save corrections priorities
753+
for (let x = 0; x < numCorrectionsSources; x++) {
754+
initialSettings["correctionsPriority_" + correctionsSourceNames[x]] = correctionsSourcePriorities[x].toString();
727755
}
756+
757+
// Note: recordsECEF and recordsGeodetic change very little so instead
758+
// of creating copy here, we will resend any entered coordinates every time.
728759
}
729760

730761
function hide(id) {
@@ -742,39 +773,62 @@ function isElementShown(id) {
742773
return (false);
743774
}
744775

745-
//Create CSV of all setting data
776+
//Create CSV of all setting data that has changed from the original given to us
746777
function sendData() {
747778
var settingCSV = "";
779+
var changedCount = 0;
748780

749-
//Input boxes
781+
// Check input boxes and dropdowns
750782
var clsElements = document.querySelectorAll(".form-control, .form-dropdown");
751783
for (let x = 0; x < clsElements.length; x++) {
752-
settingCSV += clsElements[x].id + "," + clsElements[x].value + ",";
784+
var id = clsElements[x].id;
785+
var currentValue = clsElements[x].value;
786+
if (initialSettings[id] !== currentValue) {
787+
settingCSV += id + "," + currentValue + ",";
788+
changedCount++;
789+
}
753790
}
754791

755-
//Check boxes, radio buttons
756-
//Remove file manager files
792+
// Check boxes, radio buttons
757793
clsElements = document.querySelectorAll(".form-check-input:not(.fileManagerCheck), .form-radio");
758794
for (let x = 0; x < clsElements.length; x++) {
759-
settingCSV += clsElements[x].id + "," + clsElements[x].checked + ",";
795+
var id = clsElements[x].id;
796+
// Store boolean as string 'true'/'false' for consistent comparison with initialSettings
797+
var currentValue = clsElements[x].checked.toString();
798+
if (initialSettings[id] !== currentValue) {
799+
settingCSV += id + "," + currentValue + ",";
800+
changedCount++;
801+
}
760802
}
761803

804+
// Records (ECEF and Geodetic) - For simplicity, we send the full list if any list element exists.
762805
for (let x = 0; x < recordsECEF.length; x++) {
763806
settingCSV += "stationECEF" + x + ',' + recordsECEF[x] + ",";
764807
}
765-
766808
for (let x = 0; x < recordsGeodetic.length; x++) {
767809
settingCSV += "stationGeodetic" + x + ',' + recordsGeodetic[x] + ",";
768810
}
769811

812+
// Corrections Priorities
770813
for (let x = 0; x < correctionsSourceNames.length; x++) {
771-
settingCSV += "correctionsPriority_" + correctionsSourceNames[x] + ',' + correctionsSourcePriorities[x] + ",";
814+
var id = "correctionsPriority_" + correctionsSourceNames[x];
815+
var currentValue = correctionsSourcePriorities[x].toString();
816+
if (initialSettings[id] !== currentValue) {
817+
settingCSV += id + ',' + currentValue + ",";
818+
changedCount++;
819+
}
772820
}
773821

774-
console.log("Sending: " + settingCSV);
775-
websocket.send(settingCSV);
822+
console.log("Sending " + changedCount + " changed settings: " + settingCSV);
776823

777-
sendDataTimeout = setTimeout(sendData, 2000);
824+
// Only send if there are changes (plus the always-sent records)
825+
if (settingCSV.length > 0) {
826+
websocket.send(settingCSV);
827+
sendDataTimeout = setTimeout(sendData, 2000);
828+
} else {
829+
// If nothing changed, immediately report success.
830+
showSuccess('saveBtn', "No changes detected.");
831+
}
778832
}
779833

780834
function showError(id, errorText) {

Firmware/RTK_Everywhere/States.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ void stateUpdate()
439439
case (STATE_WEB_CONFIG): {
440440
if (incomingSettingsSpot > 0)
441441
{
442-
// Allow for 750ms before we parse buffer for all data to arrive
442+
// Allow for 250ms before we parse buffer for all data to arrive
443443
if ((millis() - timeSinceLastIncomingSetting) > 250)
444444
{
445445
// Confirm receipt so the web interface stops sending the config blob

0 commit comments

Comments
 (0)