From 0d64efacb3427b3ae919785c0d3c07798a96bea6 Mon Sep 17 00:00:00 2001 From: logicog Date: Thu, 16 Oct 2025 20:02:44 +0200 Subject: [PATCH 1/8] Add EEE status query --- cmd_parser.c | 20 ++++++++++---- phy.h | 18 ++++++++++--- rtl837x_port.c | 73 +++++++++++++++++++++++++++++++++++++++++++++----- rtl837x_port.h | 2 ++ rtl837x_regs.h | 3 +++ 5 files changed, 101 insertions(+), 15 deletions(-) diff --git a/cmd_parser.c b/cmd_parser.c index 3a8ae3e..d355787 100644 --- a/cmd_parser.c +++ b/cmd_parser.c @@ -469,9 +469,16 @@ void cmd_parser(void) __banked print_string("Parsing command\n"); print_string_x(&cmd_buffer[0]); write_char('<'); write_char('\n'); + print_string("CMD-words: "); + print_byte(cmd_words_b[0]); write_char(' '); + print_byte(cmd_words_b[1]); write_char(' '); + print_byte(cmd_words_b[2]); write_char(' '); + print_byte(cmd_words_b[3]); write_char(' '); + print_byte(cmd_words_b[4]); write_char(' '); + print_byte(cmd_words_b[5]); write_char(' '); + print_byte(cmd_words_b[6]); write_char('\n'); #endif - signed char i = cmd_words_b[0]; - if (i >= 0 && cmd_words_b[1] >= 0) { + if (cmd_words_b[0] >= 0 && cmd_words_b[1] >= 0) { if (cmd_compare(0, "reset")) { print_string("\nRESET\n\n"); reset_chip(); @@ -636,23 +643,26 @@ void cmd_parser(void) __banked } if (cmd_compare(0, "eee")) { int8_t port = -1; - if (cmd_words_b[2] > 0) { + if (cmd_words_b[3] > 0) { port = cmd_buffer[cmd_words_b[2]] - '1'; if (!isRTL8373) port = phys_to_log_port[port]; } if (cmd_words_b[1] > 0 && cmd_compare(1, "on")) { - print_string("EEE enabled\n"); if (port >= 0) port_eee_enable(port); else port_eee_enable_all(); } else if (cmd_words_b[1] > 0 && cmd_compare(1, "off")) { - print_string("EEE disabled\n"); if (port >= 0) port_eee_disable(port); else port_eee_disable_all(); + } else if (cmd_words_b[1] > 0 && cmd_compare(1, "status")) { + if (port >= 0) + port_eee_status(port); + else + port_eee_status_all(); } } } diff --git a/phy.h b/phy.h index 3918415..e73edd4 100644 --- a/phy.h +++ b/phy.h @@ -12,15 +12,25 @@ * Define PHY pages */ #define PHY_MMD_AN 7 +#define PHY_SDS_CTRL 30 #define PHY_MMD_CTRL 31 /* * Define registers in Auto-Negotiation page */ -#define PHY_ANEG_CTRL 0x00 -#define PHY_EEE_ADV 0x3c -#define PHY_EEE_ABILITY 0x3d -#define PHY_EEE_ADV2 0x3e +#define PHY_ANEG_CTRL 0x00 +#define PHY_EEE_ADV 0x3c +#define PHY_EEE_LP_ABILITY 0x3d +#define PHY_EEE_ADV2 0x3e +#define PHY_EEE_LP_ABILITY2 0x3f +// Register bits for EEE capabilities at a given speed +#define PHY_EEE_BIT_2G5 0x01 +#define PHY_EEE_BIT_1G 0x04 +#define PHY_EEE_BIT_100M 0x02 +/* + * Define registers in Control page + */ +#define PHY_CTRL_5 0x7582 #endif diff --git a/rtl837x_port.c b/rtl837x_port.c index 0539ea5..b181cc6 100644 --- a/rtl837x_port.c +++ b/rtl837x_port.c @@ -484,13 +484,12 @@ void port_eee_enable(uint8_t port) __banked { if (is_sfp[port]) return; - - print_string("EEE on for "); print_byte(port); write_char('\n'); + REG_SET(RTL8373_EEE_CTRL_BASE + (port << 2), EEE_100 | EEE_1000 | EEE_2G5); // Enable EEE advertisement for 100/1000BASE-T via EEE Advertisement Reg - phy_write(port, PHY_MMD_AN, PHY_EEE_ADV, 6); // Bit 1: 100BASE-T, Bit 2: 1000BASE-T + phy_write(port, PHY_MMD_AN, PHY_EEE_ADV, PHY_EEE_BIT_1G | PHY_EEE_BIT_100M); // Enable EEE advertisement for 2.5GBASE-T via EEE Advertisement Reg 2 - phy_write(port, PHY_MMD_AN, PHY_EEE_ADV2, 1); + phy_write(port, PHY_MMD_AN, PHY_EEE_ADV2, PHY_EEE_BIT_2G5); phy_reset(port); } @@ -502,14 +501,69 @@ void port_eee_disable(uint8_t port) __banked print_string("EEE off for "); print_byte(port); write_char('\n'); REG_SET(RTL8373_EEE_CTRL_BASE + (port << 2), 0); - // Enable EEE advertisement for 100/1000BASE-T via EEE Advertisement Reg + // Disable EEE advertisement for 100/1000BASE-T via EEE Advertisement Reg phy_write(port, PHY_MMD_AN, PHY_EEE_ADV, 0); - // Enable EEE advertisement for 2.5GBASE-T via EEE Advertisement Reg 2 + // Disable EEE advertisement for 2.5GBASE-T via EEE Advertisement Reg 2 phy_write(port, PHY_MMD_AN, PHY_EEE_ADV2, 0); phy_reset(port); } +void port_eee_status(uint8_t port) __banked +{ + print_string("Port: "); write_char('0' + log_to_phys_port[port]); + print_string(": "); + if (is_sfp[port]) { + print_string("SFP\n"); + return; + } + + uint16_t v; + print_string("Advertising: "); + phy_read(port, PHY_MMD_AN, PHY_EEE_ADV2); + v = SFR_DATA_U16; + if (v & PHY_EEE_BIT_2G5) + print_string(" 2.5G"); + else + print_string(" "); + phy_read(port, PHY_MMD_AN, PHY_EEE_ADV); + v = SFR_DATA_U16; + if (v & PHY_EEE_BIT_1G) + print_string(" 1G "); + else + print_string(" "); + if (v & PHY_EEE_BIT_100M) + print_string(" 100M"); + else + print_string(" "); + + print_string(" Link Partner: "); + phy_read(port, PHY_MMD_AN, PHY_EEE_LP_ABILITY2); + v = SFR_DATA_U16; + if (v & PHY_EEE_BIT_2G5) + print_string(" 2.5G"); + else + print_string(" "); + phy_read(port, PHY_MMD_AN, PHY_EEE_LP_ABILITY); + v = SFR_DATA_U16; + if (v & PHY_EEE_BIT_1G) + print_string(" 1G "); + else + print_string(" "); + if (v & PHY_EEE_BIT_100M) + print_string(" 100M"); + else + print_string(" "); + + reg_read_m(RTL8373_PHY_EEE_ABLTY); + if (sfr_data[3] & (1 << port)) + print_string(" ACTIVE "); + else + print_string(" INACTIVE "); + write_char('\n'); +} + + void port_eee_enable_all(void) __banked { for (uint8_t i = minPort; i <= maxPort; i++) { @@ -526,6 +580,13 @@ void port_eee_disable_all(void) __banked } +void port_eee_status_all(void) __banked +{ + for (uint8_t i = minPort; i <= maxPort; i++) { + port_eee_status(i); + } +} + /* * Enable RLDP, Realtek's version of LLDP */ diff --git a/rtl837x_port.h b/rtl837x_port.h index 81eec4c..4b5f39b 100644 --- a/rtl837x_port.h +++ b/rtl837x_port.h @@ -29,6 +29,8 @@ void port_l2_setup(void) __banked; void trunk_set(uint8_t group, uint16_t mask) __banked; void port_eee_enable_all(void) __banked; void port_eee_disable_all(void) __banked; +void port_eee_status_all(void) __banked; void port_eee_enable(uint8_t port) __banked; void port_eee_disable(uint8_t port) __banked; +void port_eee_status(uint8_t port) __banked; #endif diff --git a/rtl837x_regs.h b/rtl837x_regs.h index b0e82bb..4c47761 100644 --- a/rtl837x_regs.h +++ b/rtl837x_regs.h @@ -158,6 +158,9 @@ /* * EEE */ +#define RTL837X_EEE_STATUS 0x125C +#define RTL837X_MAC_EEE_ABLTY 0x6404 +#define RTL8373_PHY_EEE_ABLTY 0x642C #define RTL8373_EEE_CTRL_BASE 0x606c #define EEE_100 0x01 #define EEE_1000 0x04 From 73b8335befe71debdedcd356e7f3891175e33a71 Mon Sep 17 00:00:00 2001 From: logicog Date: Sat, 18 Oct 2025 09:53:48 +0200 Subject: [PATCH 2/8] Add EEE html page --- html/eee.html | 26 ++++++++++++++++++++++++++ html/eee.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ html/eee_sub.js | 18 ++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 html/eee.html create mode 100644 html/eee.js create mode 100644 html/eee_sub.js diff --git a/html/eee.html b/html/eee.html new file mode 100644 index 0000000..5e2eb5e --- /dev/null +++ b/html/eee.html @@ -0,0 +1,26 @@ + + + + + + FreeSwitchOS Port Statistics + + + +
+
+

EEE Status

+ + + +
Advertising Link-Partner advertises
Port 2.5G 1G 100M 2.5G 1G 100M Active?
+
+ + +
+ + +
+ + + diff --git a/html/eee.js b/html/eee.js new file mode 100644 index 0000000..0bb89b1 --- /dev/null +++ b/html/eee.js @@ -0,0 +1,48 @@ +function createEEE() { + var tbl = document.getElementById('eeetable'); + if (tbl.rows.length <= 2) { + console.log("CREATING TABLE ", tbl.rows.length); + for (let i = 2; i < 8; i++) { + console.log("Table row: " + i + "pState: " + pState[i-2]); + const tr = tbl.insertRow(); + let td = tr.insertCell(); td.appendChild(document.createTextNode(`Port ${i-1}`)); + for (let j = 0; j < 7; j++) { + td = tr.insertCell(); td.appendChild(document.createTextNode(" ")); + } + } + } +} + +function getEEE() { + var xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function() { + if (this.readyState == 4 && this.status == 200) { + const s = JSON.parse(xhttp.responseText); + console.log("EEE: ", JSON.stringify(s)); + var tbl = document.getElementById('eeetable'); + if (tbl.rows.length > 2) { + for (let i = 2; i < 8; i++) { + p = s[i-2]; + let n = p.portNum; + console.log("Table Update row: " + i + " portNum is " + n + ", pState is " + pState[i-2]); + let tr = tbl.rows[n+1]; + if (!p.isSFP) { + let eee = parseInt(p.eee,2); let lp = parseInt(p.eee_lp,2); + tr.cells[1].innerHTML = `${eee&4?"ON":"OFF"}`; tr.cells[2].innerHTML = `${eee&2?"ON":"OFF"}`; tr.cells[3].innerHTML = `${eee&1?"ON":"OFF"}`; + tr.cells[4].innerHTML = `${lp&4?"ON":"OFF"}`; tr.cells[5].innerHTML = `${lp&2?"ON":"OFF"}`; tr.cells[6].innerHTML = `${lp&1?"ON":"OFF"}`; + tr.cells[7].innerHTML = `${p.active}`; + tr.classList.toggle('disabled', pState[i-2] < 0); tr.classList.toggle('isNOK', !p.active); tr.classList.toggle('isOK', p.active); + } + tr.classList.toggle('isSFP', p.isSFP); + } + } + } + }; + xhttp.open("GET", "/eee.json", true); + xhttp.send(); +} + +window.addEventListener("load", function() { + const iCount = setInterval(getEEE, 1000); +}); +const stat = setInterval(createEEE, 500); diff --git a/html/eee_sub.js b/html/eee_sub.js new file mode 100644 index 0000000..6a72f92 --- /dev/null +++ b/html/eee_sub.js @@ -0,0 +1,18 @@ +async function eeeSub(port, enable) { + var cmd = "eee "; + if (enable) + cmd = cmd + "on"; + else + cmd = cmd + "off"; + console.log("eeeSub port " + port, ", value " + enable); + try { + const response = await fetch('/cmd', { + method: 'POST', + body: cmd + }); + console.log('Completed!', response); + } catch(err) { + console.error(`Error: ${err}`); + } +} + From aab4d334e53e315161c56797d65ba0900a171adc Mon Sep 17 00:00:00 2001 From: logicog Date: Sat, 18 Oct 2025 09:54:38 +0200 Subject: [PATCH 3/8] Formatting fix --- html/ports.js | 1 - 1 file changed, 1 deletion(-) diff --git a/html/ports.js b/html/ports.js index fab734d..a8f0392 100644 --- a/html/ports.js +++ b/html/ports.js @@ -17,6 +17,5 @@ function drawPorts() { l.id="port" + (i+1); f.appendChild(l); } - console.log("DRAWING DONE "); } From df1cd62518a5b9abd38ff9226941dc9031835b16 Mon Sep 17 00:00:00 2001 From: logicog Date: Sat, 18 Oct 2025 09:55:09 +0200 Subject: [PATCH 4/8] Add EEE style and navigation --- html/navigation.js | 2 +- html/style.css | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/html/navigation.js b/html/navigation.js index dc92450..92366c2 100644 --- a/html/navigation.js +++ b/html/navigation.js @@ -4,6 +4,6 @@ document.getElementById('sidebar').innerHTML = + "
  • VLAN
  • " + "
  • Mirroring
  • " + "
  • Port Aggregation
  • " - + "
  • Mirroring
  • " + + "
  • EEE
  • " + "
  • Firmware Update
  • "; diff --git a/html/style.css b/html/style.css index 40a0203..0805ce9 100644 --- a/html/style.css +++ b/html/style.css @@ -69,3 +69,8 @@ object { .cbgroup label { display: block; } + +.disabled{ opacity: .4; background-color: #f88; color: #000} +.isSFP{ opacity: .4; background-color: #660;} +.isNOK{ color: #900;} +.isOK{ color: #090;} From 726b421824fabad12ad738ee7481729579de4ae2 Mon Sep 17 00:00:00 2001 From: logicog Date: Sat, 18 Oct 2025 09:55:38 +0200 Subject: [PATCH 5/8] Add EEE httpd support --- httpd/httpd.c | 2 ++ httpd/page_impl.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++ httpd/page_impl.h | 1 + tools/httpd_sim.c | 49 ++++++++++++++++++++++++++++++-- 4 files changed, 122 insertions(+), 2 deletions(-) diff --git a/httpd/httpd.c b/httpd/httpd.c index 289308a..10d6089 100644 --- a/httpd/httpd.c +++ b/httpd/httpd.c @@ -422,6 +422,8 @@ void httpd_appcall(void) send_vlan(short_parsed); } else if (is_word(q, "/counters.json")) { send_counters(q[19]-'0'); + } else if (is_word(q, "/eee.json")) { + send_eee(); } else { send_not_found(); } diff --git a/httpd/page_impl.c b/httpd/page_impl.c index dce8843..d23a888 100644 --- a/httpd/page_impl.c +++ b/httpd/page_impl.c @@ -7,8 +7,10 @@ #include "uip.h" #include "../html_data.h" #include +#include "../phy.h" #pragma codeseg BANK1 +#pragma constseg BANK1 extern __xdata uint8_t outbuf[TCP_OUTBUF_SIZE]; extern __xdata uint16_t slen; @@ -208,6 +210,76 @@ void send_counters(char port) } +void send_eee() +{ + print_string("send_eee called\n"); + slen = strtox(outbuf, HTTP_RESPONCE_JSON); + print_string("sending EEE status\n"); + + reg_read_m(RTL8373_PHY_EEE_ABLTY); + uint8_t eee_ablty = sfr_data[3]; + char_to_html('['); + for (uint8_t i = minPort; i <= maxPort; i++) { + slen += strtox(outbuf + slen, "{\"portNum\":"); + if (!isRTL8373) + itoa_html(log_to_phys_port[i]); + else + itoa_html(i + 1); + if (IS_SFP(i)) { + slen += strtox(outbuf + slen, " ,\"isSFP\": 1"); + } else { + slen += strtox(outbuf + slen, " ,\"isSFP\": 0 "); + uint16_t v; + phy_read(i, PHY_MMD_AN, PHY_EEE_ADV2); + v = SFR_DATA_U16; + slen += strtox(outbuf + slen, ",\"eee\":\""); + if (v & PHY_EEE_BIT_2G5) + char_to_html('1'); + else + char_to_html('0'); + phy_read(i, PHY_MMD_AN, PHY_EEE_ADV); + v = SFR_DATA_U16; + if (v & PHY_EEE_BIT_1G) + char_to_html('1'); + else + char_to_html('0'); + if (v & PHY_EEE_BIT_100M) + char_to_html('1'); + else + char_to_html('0'); + + phy_read(i, PHY_MMD_AN, PHY_EEE_LP_ABILITY2); + v = SFR_DATA_U16; + slen += strtox(outbuf + slen, "\", \"eee_lp\":\""); + if (v & PHY_EEE_BIT_2G5) + char_to_html('1'); + else + char_to_html('0'); + phy_read(i, PHY_MMD_AN, PHY_EEE_LP_ABILITY); + v = SFR_DATA_U16; + if (v & PHY_EEE_BIT_1G) + char_to_html('1'); + else + char_to_html('0'); + if (v & PHY_EEE_BIT_100M) + char_to_html('1'); + else + char_to_html('0'); + slen += strtox(outbuf + slen, "\", \"active\": "); + if (eee_ablty & (1 << i)) + char_to_html('1'); + else + char_to_html('0'); + } + char_to_html('}'); + if (i < maxPort) + char_to_html(','); + else + char_to_html(']'); + } +} + + void send_status(void) { slen = strtox(outbuf, HTTP_RESPONCE_JSON); diff --git a/httpd/page_impl.h b/httpd/page_impl.h index 16f776e..9403023 100644 --- a/httpd/page_impl.h +++ b/httpd/page_impl.h @@ -5,5 +5,6 @@ void send_counters(char port); void send_status(void); void send_vlan(register uint16_t vlan); void send_basic_info(void); +void send_eee(void); #endif diff --git a/tools/httpd_sim.c b/tools/httpd_sim.c index 9c54444..424921c 100644 --- a/tools/httpd_sim.c +++ b/tools/httpd_sim.c @@ -139,6 +139,43 @@ void send_status(int s) } +void send_eee(int s) +{ + struct json_object *ports, *v; + const char *jstring; + char *header = "HTTP/1.1 200 OK\r\n" + "Content-Type: application/json; charset=UTF-8\r\n\r\n"; + + time_t now = time(NULL); + now = last_called ? last_called + 1 : now; // Make sure we don't divide by 0 for rates + + ports = json_object_new_array_ext(PORTS); + for (int i = 1; i <= PORTS; i++) { + v = json_object_new_object(); + json_object_object_add(v, "portNum", json_object_new_int(i)); + json_object_object_add(v, "isSFP", json_object_new_int(i < 5 ? 0 : 1)); + uint8_t eee = 0; + eee |= 0x02; + char eee_buf[20]; + sprintf(eee_buf, "%08b", eee); + json_object_object_add(v, "eee", json_object_new_string(eee_buf)); + uint8_t eee_lp = 0; + eee_lp |= 0x04; + sprintf(eee_buf, "%08b", eee_lp); + json_object_object_add(v, "eee_lp", json_object_new_string(eee_buf)); + json_object_object_add(v, "active", json_object_new_int((i % 2) ? 1 : 0)); + json_object_array_add(ports, v); + } + last_called = now; + + write(s, header, strlen(header)); + + jstring = json_object_to_json_string_ext(ports, JSON_C_TO_STRING_PLAIN); + write(s, jstring, strlen(jstring)); + json_object_put(v); +} + + struct Server serverConstructor(int port, void (*launch)(struct Server *server)) { struct Server server; @@ -256,6 +293,11 @@ void launch(struct Server *server) send_status(new_socket); goto done; } + if (!strncmp(&buffer[4], "/eee.json", 9)) { + printf("EEE request\n"); + send_eee(new_socket); + goto done; + } if (!strncmp(&buffer[4], "/information.json", 12)) { printf("Status request\n"); send_basic_info(new_socket); @@ -272,8 +314,11 @@ void launch(struct Server *server) i++; buffer[4+i] = '\0'; - printf("Serving file: >%s<\n", &buffer[5]); - inptr = fopen(&buffer[5], "rb"); + printf("Serving file: >%s<, name length %d\n", &buffer[5], i); + if (i > 1) + inptr = fopen(&buffer[5], "rb"); + else + inptr = fopen("/index.html", "rb"); if (inptr == NULL) { printf("Cannot open input file %s\n", &buffer[5]); send_not_found(new_socket); From 03fb3fe6b469ae3e39493ea50979ff5f1e194bdc Mon Sep 17 00:00:00 2001 From: logicog Date: Tue, 21 Oct 2025 17:47:38 +0200 Subject: [PATCH 6/8] Reduce PHY reset time to 20ms --- rtl837x_phy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rtl837x_phy.c b/rtl837x_phy.c index 633eef5..780f6d3 100644 --- a/rtl837x_phy.c +++ b/rtl837x_phy.c @@ -236,7 +236,7 @@ void phy_reset(uint8_t port) __banked // Disable PHY phy_write(port, PHY_MMD_CTRL, 0xa610, v | 0x0800); - delay(5); + delay(2); // Re-enable PHY phy_write(port, PHY_MMD_CTRL, 0xa610, v & 0xf7ff); } From ba902a68d4121d8d20137e70d5c80053af64e0ec Mon Sep 17 00:00:00 2001 From: logicog Date: Tue, 21 Oct 2025 18:05:33 +0200 Subject: [PATCH 7/8] Defer cmd execution for console and via http POST --- cmd_parser.c | 1 + cmd_parser.h | 1 + httpd/httpd.c | 5 ++--- rtlplayground.c | 21 +++++++++++++++++---- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/cmd_parser.c b/cmd_parser.c index d355787..21137a5 100644 --- a/cmd_parser.c +++ b/cmd_parser.c @@ -48,6 +48,7 @@ __xdata uint8_t hexvalue[4] = { 0 }; // Buffer for writing to flash 0x1fd000, copy to 0x1fe000 __xdata uint8_t cmd_buffer[SBUF_SIZE]; +__xdata uint8_t cmd_available; __xdata uint8_t l; __xdata uint8_t line_ptr; diff --git a/cmd_parser.h b/cmd_parser.h index b19e186..2314eab 100644 --- a/cmd_parser.h +++ b/cmd_parser.h @@ -6,6 +6,7 @@ #include "rtl837x_common.h" extern __xdata uint8_t cmd_buffer[SBUF_SIZE]; +extern __xdata uint8_t cmd_available; uint8_t cmd_tokenize(void) __banked; void cmd_parser(void) __banked; diff --git a/httpd/httpd.c b/httpd/httpd.c index 10d6089..9e53bb2 100644 --- a/httpd/httpd.c +++ b/httpd/httpd.c @@ -288,9 +288,8 @@ void handle_post(void) while (*p && *p != '\n' && *p != '\r') cmd_buffer[i++] = *p++; cmd_buffer[i] = '\0'; - - if (i && !cmd_tokenize()) - cmd_parser(); + if (i) + cmd_available = 1; } else if (is_word(request_path, "upload")) { print_string("POST upload request\n"); if (!boundary[0]) { diff --git a/rtlplayground.c b/rtlplayground.c index 5ce107c..01bdd47 100644 --- a/rtlplayground.c +++ b/rtlplayground.c @@ -67,7 +67,6 @@ __xdata volatile uint8_t sbuf_ptr; __xdata uint8_t sbuf[SBUF_SIZE]; __xdata uint8_t sfr_data[4]; -extern __xdata uint8_t cmd_buffer[SBUF_SIZE]; extern __xdata uint8_t gpio_last_value[8]; extern __xdata struct flash_region_t flash_region; @@ -1021,6 +1020,13 @@ void idle(void) stp_clock--; } } + // Check whether a command is waiting in the cmd_buffer and execute + if (cmd_available) { + cmd_available = 0; + if (!cmd_tokenize()) + cmd_parser(); + print_string("\n> "); + } } @@ -1805,8 +1811,12 @@ void bootloader(void) // printed out the entered characters __xdata uint8_t l = sbuf_ptr; // We have printed out entered characters until l __xdata uint8_t line_start = sbuf_ptr; // This is where the current line starts + cmd_available = 0; while (1) { while (l != sbuf_ptr) { + // If the command buffer is currently in use, we cannot copy to it + if (cmd_available) + break; write_char(sbuf[l]); // Check whether there is a full line: if (sbuf[l] == '\n' || sbuf[l] == '\r') { @@ -1819,9 +1829,12 @@ void bootloader(void) line_start++; line_start &= (SBUF_SIZE - 1); cmd_buffer[i] = '\0'; - if (i && !cmd_tokenize()) - cmd_parser(); - print_string("\n> "); + // If there is a command we print the prompt after execution + // otherwise immediately because there is nothing to execute + if (i) + cmd_available = 1; + else + print_string("\n> "); } l++; l &= (SBUF_SIZE - 1); From e5f5955f716ce569a17e0c581178f02785d6994b Mon Sep 17 00:00:00 2001 From: logicog Date: Tue, 21 Oct 2025 20:04:58 +0200 Subject: [PATCH 8/8] Add timeouts to XhttpGet requests --- html/eee.js | 7 ++++--- html/main.js | 4 ++-- html/stat.js | 19 +------------------ 3 files changed, 7 insertions(+), 23 deletions(-) diff --git a/html/eee.js b/html/eee.js index 0bb89b1..cb40329 100644 --- a/html/eee.js +++ b/html/eee.js @@ -39,10 +39,11 @@ function getEEE() { } }; xhttp.open("GET", "/eee.json", true); - xhttp.send(); + xhttp.timeout = 1500; xhttp.send(); } window.addEventListener("load", function() { - const iCount = setInterval(getEEE, 1000); + getEEE(); + const iCount = setInterval(getEEE, 2000); }); -const stat = setInterval(createEEE, 500); +const stat = setInterval(createEEE, 1000); diff --git a/html/main.js b/html/main.js index be073ba..27a8587 100644 --- a/html/main.js +++ b/html/main.js @@ -51,10 +51,10 @@ function update() { } }; xhttp.open("GET", "/status.json", true); - xhttp.send(); + xhttp.timeout = 5000; xhttp.send(); } window.addEventListener("load", function() { update(); - const interval = setInterval(update, 1000); + const interval = setInterval(update, 2000); }); diff --git a/html/stat.js b/html/stat.js index 8553093..da674b7 100644 --- a/html/stat.js +++ b/html/stat.js @@ -23,21 +23,4 @@ function fillStats() { } } -function getCounts() { - for (let port = 1; port <= numPorts; port++) { - var xhttp = new XMLHttpRequest(); - xhttp.onreadystatechange = function() { - if (this.readyState == 4 && this.status == 200) { - const s = JSON.parse(xhttp.responseText); - console.log("Counters: ", JSON.stringify(s)); - } - } - xhttp.open("GET", `/counters.json?port=${port}`, true); - xhttp.send(); - } -} - -window.addEventListener("load", function() { - const iCount = setInterval(getCounts, 1000); -}); -const stat = setInterval(fillStats, 500); +const stat = setInterval(fillStats, 1000);