mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-08-30 14:52:51 +08:00
Add startup config editor.
This commit is contained in:
@@ -1 +0,0 @@
|
|||||||
../config.txt
|
|
||||||
+2
-1
@@ -49,7 +49,8 @@ async function fetchCmdLog() {
|
|||||||
console.log("CMD-Log: ", response);
|
console.log("CMD-Log: ", response);
|
||||||
const t = await response.text();
|
const t = await response.text();
|
||||||
return t;
|
return t;
|
||||||
} catch(error) {
|
} catch(err) {
|
||||||
console.error("Error: ", err);
|
console.error("Error: ", err);
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,11 @@
|
|||||||
<br/><br/>
|
<br/><br/>
|
||||||
When updating the above settings, remember to point your browser to the new IP afterwards:<br/>
|
When updating the above settings, remember to point your browser to the new IP afterwards:<br/>
|
||||||
<input style="width:40%;" class="action" id="ip_sub" onclick="ipSub();" type="button" value="Update Settings"><br/>
|
<input style="width:40%;" class="action" id="ip_sub" onclick="ipSub();" type="button" value="Update Settings"><br/>
|
||||||
|
<br/>
|
||||||
|
<div class="lcol"> <label for="ip">Startup configuration:</label></div>
|
||||||
|
<textarea id="config_display" rows="8" cols="60"></textarea>
|
||||||
|
<br/>
|
||||||
|
<input style="width:40%;" class="action" id="clear_config" onclick="clearConfig();" type="button" value="Clear Config">
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
Save all current settings to Flash:<br/>
|
Save all current settings to Flash:<br/>
|
||||||
<input style="width:40%;" class="action" id="flash_sub" onclick="flashSave();" type="button" value="Save Settings to Flash">
|
<input style="width:40%;" class="action" id="flash_sub" onclick="flashSave();" type="button" value="Save Settings to Flash">
|
||||||
|
|||||||
+32
-10
@@ -43,16 +43,27 @@ async function sendConfig(c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function flashSave() {
|
async function flashSave() {
|
||||||
fetchConfig().then((s) => {
|
var configContent = document.getElementById("config_display").value;
|
||||||
parseConf(s);
|
console.log("CONFIGURATION to save: ", configContent);
|
||||||
fetchCmdLog().then((s) => {
|
sendConfig(configContent);
|
||||||
parseConf(s);
|
}
|
||||||
var body = "";
|
|
||||||
for (const x of configuration) { body = body + x + "\n"; }
|
function clearConfig() {
|
||||||
console.log("CONFIGURATION to save: ", body);
|
document.getElementById("config_display").value = "";
|
||||||
sendConfig(body);
|
|
||||||
});
|
// 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() {
|
function fetchIP() {
|
||||||
@@ -65,6 +76,17 @@ function fetchIP() {
|
|||||||
document.getElementById("netmask").value=s.ip_netmask;
|
document.getElementById("netmask").value=s.ip_netmask;
|
||||||
document.getElementById("gw").value=s.ip_gateway;
|
document.getElementById("gw").value=s.ip_gateway;
|
||||||
clearInterval(systemInterval);
|
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);
|
xhttp.open("GET", `/information.json`, true);
|
||||||
|
|||||||
+33
-14
@@ -664,26 +664,45 @@ void send_status(void)
|
|||||||
void send_config(void)
|
void send_config(void)
|
||||||
{
|
{
|
||||||
dbg_string("send_config called\n");
|
dbg_string("send_config called\n");
|
||||||
__xdata uint32_t pos = CONFIG_START; // 70000 , 6c000 / 0xc000 = 9
|
__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];
|
||||||
|
|
||||||
extern __xdata uint16_t len_left = CONFIG_LEN;
|
|
||||||
slen = strtox(outbuf, HTTP_RESPONCE_TXT);
|
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)) {
|
// Scan through config to find the end of valid data (null terminator)
|
||||||
cont_len = len_left - (TCP_OUTBUF_SIZE - slen);
|
do {
|
||||||
len_left = TCP_OUTBUF_SIZE - slen;
|
flash_region.addr = pos;
|
||||||
cont_addr = len_left;
|
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.addr = CONFIG_START;
|
||||||
flash_region.len = len_left;
|
flash_region.len = valid_len;
|
||||||
flash_read_bulk(outbuf + slen);
|
flash_read_bulk(outbuf + slen);
|
||||||
slen += len_left;
|
slen += valid_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
void send_cmd_log(void)
|
void send_cmd_log(void)
|
||||||
|
|||||||
Reference in New Issue
Block a user