Skip to content

Commit 38a8ab7

Browse files
committed
Move profile changes to heap.
Remove old unused code. Webpage never reports "profileNumber".
1 parent 2ba5589 commit 38a8ab7

File tree

3 files changed

+16
-30
lines changed

3 files changed

+16
-30
lines changed

Firmware/RTK_Surveyor/Form.ino

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ static void handleFirmwareFileUpload(AsyncWebServerRequest *request, String file
255255
//Events triggered by web sockets
256256
#ifdef COMPILE_WIFI
257257
#ifdef COMPILE_AP
258-
char *settingsCSV; //Push large array onto heap
259258

260259
void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len)
261260
{
@@ -492,18 +491,13 @@ void updateSettingWithValue(const char *settingName, const char* settingValueStr
492491
{
493492
#ifdef COMPILE_AP
494493
char* ptr;
495-
int newProfileNumber;
496494
double settingValue = strtod(settingValueStr, &ptr);
497495

498496
bool settingValueBool = false;
499497
if (strcmp(settingValueStr, "true") == 0) settingValueBool = true;
500498

501499
if (strcmp(settingName, "maxLogTime_minutes") == 0)
502-
{
503-
newAPSettings = true; //Mark settings as new to force record before reset
504500
settings.maxLogTime_minutes = settingValue;
505-
}
506-
507501
else if (strcmp(settingName, "maxLogLength_minutes") == 0)
508502
settings.maxLogLength_minutes = settingValue;
509503
else if (strcmp(settingName, "measurementRateHz") == 0)
@@ -560,19 +554,6 @@ void updateSettingWithValue(const char *settingName, const char* settingValueStr
560554
strcpy(settings.profileName, settingValueStr);
561555
setProfileName(profileNumber);
562556
}
563-
else if (strcmp(settingName, "profileNumber") == 0)
564-
{
565-
if ((sscanf(settingValueStr, "%d", &newProfileNumber) == 1)
566-
&& (newProfileNumber >= 1) && (newProfileNumber <= MAX_PROFILE_COUNT)
567-
&& (profileNumber != newProfileNumber))
568-
{
569-
profileNumber = newProfileNumber - 1;
570-
571-
//Switch to a new profile
572-
setSettingsFileName();
573-
recordProfileNumber(profileNumber);
574-
}
575-
}
576557
else if (strcmp(settingName, "enableNtripServer") == 0)
577558
settings.enableNtripServer = settingValueBool;
578559
else if (strcmp(settingName, "ntripServer_CasterHost") == 0)
@@ -657,11 +638,12 @@ void updateSettingWithValue(const char *settingName, const char* settingValueStr
657638
factoryReset();
658639
else if (strcmp(settingName, "exitAndReset") == 0)
659640
{
660-
if (newAPSettings == true) recordSystemSettings(); //If we've received settings, record before restart
641+
Serial.println("Reset after AP Config");
661642

662-
//Reboot the machine
663643
ESP.restart();
664644
}
645+
646+
665647
else if (strcmp(settingName, "setProfile") == 0)
666648
{
667649
//Change to new profile
@@ -670,12 +652,13 @@ void updateSettingWithValue(const char *settingName, const char* settingValueStr
670652
//Load new profile into system
671653
loadSettings();
672654

673-
//Send settings to browser
674-
char settingsCSV[AP_CONFIG_SETTING_SIZE];
675-
memset(settingsCSV, 0, sizeof(settingsCSV));
655+
//Send new settings to browser. Re-use settingsCSV to avoid stack.
656+
settingsCSV = (char*)malloc(AP_CONFIG_SETTING_SIZE);
657+
memset(settingsCSV, 0, AP_CONFIG_SETTING_SIZE); //Clear any garbage from settings array
676658
createSettingsString(settingsCSV);
677659
log_d("Sending command: %s\n\r", settingsCSV);
678660
ws.textAll(String(settingsCSV));
661+
free(settingsCSV);
679662
}
680663
else if (strcmp(settingName, "resetProfile") == 0)
681664
{
@@ -686,12 +669,13 @@ void updateSettingWithValue(const char *settingName, const char* settingValueStr
686669
//Get bitmask of active profiles
687670
activeProfiles = loadProfileNames();
688671

689-
//Send settings to browser
690-
char settingsCSV[AP_CONFIG_SETTING_SIZE];
691-
memset(settingsCSV, 0, sizeof(settingsCSV));
672+
//Send new settings to browser. Re-use settingsCSV to avoid stack.
673+
settingsCSV = (char*)malloc(AP_CONFIG_SETTING_SIZE);
674+
memset(settingsCSV, 0, AP_CONFIG_SETTING_SIZE); //Clear any garbage from settings array
692675
createSettingsString(settingsCSV);
693676
log_d("Sending command: %s\n\r", settingsCSV);
694677
ws.textAll(String(settingsCSV));
678+
free(settingsCSV);
695679
}
696680
else if (strcmp(settingName, "forgetEspNowPeers") == 0)
697681
{

Firmware/RTK_Surveyor/NVM.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void loadSettings()
2020
{
2121
//If we have a profile in both LFS and SD, the SD settings will overwrite LFS
2222
loadSystemSettingsFromFileLFS(settingsFileName, &settings);
23-
23+
2424
//Temp store any variables from LFS that should override SD
2525
int resetCount = settings.resetCount;
2626

@@ -261,6 +261,7 @@ void recordSystemSettingsToFile(File * settingsFile)
261261
settingsFile->printf("%s=%d\n\r", "enablePrintStates", settings.enablePrintStates);
262262
settingsFile->printf("%s=%d\n\r", "enablePrintDuplicateStates", settings.enablePrintDuplicateStates);
263263
settingsFile->printf("%s=%d\n\r", "radioType", settings.radioType);
264+
264265
//Record peer MAC addresses
265266
for (int x = 0 ; x < settings.espnowPeerCount ; x++)
266267
{

Firmware/RTK_Surveyor/RTK_Surveyor.ino

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,9 @@ unsigned long lastRockerSwitchChange = 0; //If quick toggle is detected (less th
349349

350350
AsyncWebServer server(80);
351351
AsyncWebSocket ws("/ws");
352+
353+
char *settingsCSV; //Push large array onto heap
354+
352355
#endif
353356
#endif
354357

@@ -446,8 +449,6 @@ uint32_t triggerCount = 0; //Global copy - TM2 event counter
446449
uint32_t towMsR = 0; //Global copy - Time Of Week of rising edge (ms)
447450
uint32_t towSubMsR = 0; //Global copy - Millisecond fraction of Time Of Week of rising edge in nanoseconds
448451

449-
bool newAPSettings = false; //Goes true when new setting is received via AP config. Allows us to record settings when combined with a reset.
450-
451452
unsigned int binBytesSent = 0; //Tracks firmware bytes sent over WiFi OTA update via AP config.
452453
int binBytesLastUpdate = 0; //Allows websocket notification to be sent every 100k bytes
453454
bool firstPowerOn = true; //After boot, apply new settings to ZED if user switches between base or rover

0 commit comments

Comments
 (0)