diff --git a/html/main.js b/html/main.js index badd491..116384d 100644 --- a/html/main.js +++ b/html/main.js @@ -90,11 +90,12 @@ function update(callback) { var iHTML = ""; iHTML += ""; if (p.isSFP) { - pAdvertised[n] = 0; + pAdvertised[n] = 0; + const hasExtendedStatus = p.sfp_options & 0x40; iHTML += ""; iHTML += ""; iHTML += ""; - if (p.sfp_options & 0x40) { + if (hasExtendedStatus) { iHTML += ""; iHTML += ""; iHTML += ""; @@ -103,35 +104,33 @@ function update(callback) { iHTML += ""; iHTML += ""; } - iHTML += "`; } - iHTML += ""; } else { pAdvertised[n] = parseInt(p.adv, 2); - } + }; iHTML += "
Link speed:" + linkS[p.link + 1] + "
Vendor:" + p.sfp_vendor + "
Model:" + p.sfp_model + "
Serial:" + p.sfp_serial + "
Temp:" + (Number(p.sfp_temp) >> 8) + "." + ((Number(p.sfp_temp) & 0xff)/256.0 * 100).toFixed(0) + " ℃
Vcc:" + (Number(p.sfp_vcc) / 10000.0).toFixed(2) + " V
TX-Fault:" + (Boolean(Number(p.sfp_state) & 0x4)) + "
TX-Power:" + (Number(p.sfp_txpower) / 10.0).toFixed(0) + " mW
RX-Power:" + (Number(p.sfp_rxpower) / 10.0).toFixed(0) + " mW
RX-LOS:" - var rx_los_pin = Boolean(Number(p.sfp_los)); - if (p.sfp_options & 0x40) { - var rx_los_module = Boolean(Number(p.sfp_state) & 0x2); - if (rx_los_module != rx_los_pin) { - iHTML += "pin=" + rx_los_pin + "
"; - iHTML += "mod=" + rx_los_module + "
"; - iHTML += "❗❗❗❗"; - } else { - iHTML += rx_los_pin; - } - } else { - iHTML += Boolean(Number(p.sfp_los)); + // Not all devices & modules have LOS pin... + const rx_los_pin = p.sfp_los !== null ? Boolean(Number(p.sfp_los)) : null; + const rx_los_module = hasExtendedStatus ? Boolean(Number(p.sfp_state) & 0x2) : null; + if (rx_los_module !== null || rx_los_pin !== null) { + iHTML += `
RX-LOS:${rxLosHTML(rx_los_pin, rx_los_module)}
"; tt.innerHTML = iHTML; - } - } - if (callback) - callback(); - } - }; - xhttp.open("GET", "/status.json", true); - xhttp.timeout = 5000; - sendXHTTP(xhttp); + }} + if (callback) + callback(); + }}; + xhttp.open("GET", "/status.json", true); + xhttp.timeout = 5000; + sendXHTTP(xhttp); +} + +function rxLosHTML(pinStatus, moduleStatus) { + if (moduleStatus !== null && pinStatus !== null && moduleStatus !== pinStatus) { + return `pin=${pinStatus}
mod=${moduleStatus}
❗❗❗❗`; + } + + // Returns first non null value + return moduleStatus ?? pinStatus; } function callbackXHTTP() diff --git a/httpd/page_impl.c b/httpd/page_impl.c index 56aa523..92aed11 100644 --- a/httpd/page_impl.c +++ b/httpd/page_impl.c @@ -656,7 +656,11 @@ void send_status(void) for (register uint8_t s = 0; s < 16; s++) outbuf[slen++] = sfp_module_serial[machine.is_sfp[i]-1][s]; slen += strtox(outbuf + slen,"\",\"sfp_los\":"); - bool_to_html(sfp_pins_last & (0x2 << (((machine.is_sfp[i]-1) << 2)))); + if (machine.sfp_port[machine.is_sfp[i]-1].pin_los == GPIO_NA) { + slen += strtox(outbuf + slen,"null"); + } else { + bool_to_html(sfp_pins_last & (0x2 << (((machine.is_sfp[i]-1) << 2)))); + } } else { bool_to_html(0); }