diff --git a/html/config b/html/config
deleted file mode 120000
index f1a6cc6..0000000
--- a/html/config
+++ /dev/null
@@ -1 +0,0 @@
-../config.txt
\ No newline at end of file
diff --git a/html/config.js b/html/config.js
index 2d48021..0cb4bf1 100644
--- a/html/config.js
+++ b/html/config.js
@@ -49,7 +49,8 @@ async function fetchCmdLog() {
console.log("CMD-Log: ", response);
const t = await response.text();
return t;
- } catch(error) {
+ } catch(err) {
console.error("Error: ", err);
+ return "";
}
}
diff --git a/html/system.html b/html/system.html
index 57e6a74..749cd5f 100644
--- a/html/system.html
+++ b/html/system.html
@@ -24,6 +24,11 @@
When updating the above settings, remember to point your browser to the new IP afterwards:
+
+
+
+
+
Save all current settings to Flash:
diff --git a/html/system.js b/html/system.js
index 50beec5..69741b4 100644
--- a/html/system.js
+++ b/html/system.js
@@ -43,16 +43,27 @@ async function sendConfig(c) {
}
async function flashSave() {
- fetchConfig().then((s) => {
- parseConf(s);
- fetchCmdLog().then((s) => {
- parseConf(s);
- var body = "";
- for (const x of configuration) { body = body + x + "\n"; }
- console.log("CONFIGURATION to save: ", body);
- sendConfig(body);
- });
- });
+ var configContent = document.getElementById("config_display").value;
+ console.log("CONFIGURATION to save: ", configContent);
+ sendConfig(configContent);
+}
+
+function clearConfig() {
+ document.getElementById("config_display").value = "";
+
+ // Validate and populate with current IP settings
+ for (let i=0; i<3; i++) {
+ if (!checkIp(document.getElementById(ips[i]).value))
+ return;
+ }
+
+ var configLines = "";
+ for (let i=0; i<3; i++){
+ var cmd = ips[i]+' '+document.getElementById(ips[i]).value;
+ configLines += cmd + "\n";
+ }
+
+ document.getElementById("config_display").value = configLines;
}
function fetchIP() {
@@ -65,6 +76,17 @@ function fetchIP() {
document.getElementById("netmask").value=s.ip_netmask;
document.getElementById("gw").value=s.ip_gateway;
clearInterval(systemInterval);
+ // Fetch and populate the config textbox
+ fetchConfig().then((configText) => {
+ let fullConfig = configText;
+ // Fetch and append cmd_log
+ return fetchCmdLog().then((cmdLogText) => {
+ if (cmdLogText) {
+ fullConfig = fullConfig + cmdLogText;
+ }
+ document.getElementById("config_display").value = fullConfig;
+ });
+ });
}
}
xhttp.open("GET", `/information.json`, true);
diff --git a/httpd/page_impl.c b/httpd/page_impl.c
index 2362a00..b56cc29 100644
--- a/httpd/page_impl.c
+++ b/httpd/page_impl.c
@@ -664,26 +664,45 @@ void send_status(void)
void send_config(void)
{
dbg_string("send_config called\n");
- __xdata uint32_t pos = CONFIG_START; // 70000 , 6c000 / 0xc000 = 9
-
- extern __xdata uint16_t len_left = CONFIG_LEN;
+ __xdata uint32_t pos = CONFIG_START;
+ __xdata uint16_t valid_len = 0;
+ __xdata uint16_t len_left = CONFIG_LEN;
+ __xdata uint8_t flash_buf[256];
+
slen = strtox(outbuf, HTTP_RESPONCE_TXT);
- while (read_flash((CONFIG_START-CODE0_SIZE) / CODE_BANK_SIZE + 1,
- (__code uint8_t *) (((CONFIG_START + len_left - CODE0_SIZE) % CODE_BANK_SIZE) + CODE0_SIZE + len_left)) == 0xff) {
- dbg_short(len_left);
- len_left--;
- }
- len_left++;
-
- if (len_left > (TCP_OUTBUF_SIZE - slen)) {
- cont_len = len_left - (TCP_OUTBUF_SIZE - slen);
- len_left = TCP_OUTBUF_SIZE - slen;
- cont_addr = len_left;
+
+ // Scan through config to find the end of valid data (null terminator)
+ do {
+ flash_region.addr = pos;
+ flash_region.len = (len_left > 256) ? 256 : len_left;
+ flash_read_bulk(flash_buf);
+
+ // Look for null terminator in this chunk
+ for (uint16_t i = 0; i < flash_region.len; i++) {
+ if (flash_buf[i] == 0) {
+ // Found end of valid data
+ valid_len += i;
+ goto found_end;
+ }
+ }
+
+ valid_len += flash_region.len;
+ len_left -= flash_region.len;
+ pos += flash_region.len;
+ } while (len_left > 0);
+
+found_end:
+ // Now send the valid data
+ if (valid_len > (TCP_OUTBUF_SIZE - slen)) {
+ cont_len = valid_len - (TCP_OUTBUF_SIZE - slen);
+ valid_len = TCP_OUTBUF_SIZE - slen;
+ cont_addr = valid_len;
}
+
flash_region.addr = CONFIG_START;
- flash_region.len = len_left;
+ flash_region.len = valid_len;
flash_read_bulk(outbuf + slen);
- slen += len_left;
+ slen += valid_len;
}
void send_cmd_log(void)