diff --git a/html/stat.js b/html/stat.js index 2709eeb..0944d96 100644 --- a/html/stat.js +++ b/html/stat.js @@ -109,7 +109,7 @@ const mib_counters = [ function getCounters(port) { var xhttp = new XMLHttpRequest(); const popup = document.getElementById('popup'); - xhttp.onreadystatechange = function() { + xhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { const s = JSON.parse(xhttp.responseText); console.log("Counters: ", JSON.stringify(s)); @@ -118,16 +118,16 @@ function getCounters(port) { console.log("Counter 0: ", BigInt(s[0]).toString(), " length: ", s.length); var c = 0; for (i = 0; i < mib_counters.length; i += 4) { - console.log(i, " ", mib_counters[i], ": ", mib_counters[i+1]); + console.log(i, " ", mib_counters[i], ": ", mib_counters[i + 1]); if (mib_counters[i] == "" && mib_counters[i + 1] == 8) { console.log("c " + i + ": continue"); continue; } - var count = BigInt(s[i/4]); - if (mib_counters[i+1] == 8) { + var count = BigInt(s[i / 4]); + if (mib_counters[i + 1] == 8) { tableHtml += "" + mib_counters[i] + "" + count.toString() + ""; c += 1; - } else if (mib_counters[i+1] == 4) { + } else if (mib_counters[i + 1] == 4) { if (mib_counters[i] != "") { tableHtml += "" + mib_counters[i] + "" + (count >> 32n).toString() + ""; c += 1; @@ -136,8 +136,8 @@ function getCounters(port) { tableHtml += " "; c = 0; } - if (mib_counters[i+2] != "") { - tableHtml += "" + mib_counters[i+2] + "" + (count & 4294967295n).toString() + ""; + if (mib_counters[i + 2] != "") { + tableHtml += "" + mib_counters[i + 2] + "" + (count & 4294967295n).toString() + ""; c += 1; } } @@ -161,26 +161,26 @@ function fillStats() { return; if (tbl.rows.length > 1) { for (let i = 0; i < numPorts; i++) { - console.log("Table Update row: " + i + " state " + pState[i] + " is " + linkS[pState[i] +1]); - tbl.rows[i+1].cells[2].innerHTML = linkText(pState[i]+1); - tbl.rows[i+1].cells[3].innerHTML = `${txG[i]}` + t('common_pkts'); - tbl.rows[i+1].cells[4].innerHTML = `${txB[i]}` + t('common_pkts'); - tbl.rows[i+1].cells[5].innerHTML = `${rxG[i]}` + t('common_pkts'); - tbl.rows[i+1].cells[6].innerHTML = `${rxB[i]}` + t('common_pkts'); + console.log("Table Update row: " + i + " state " + pState[i] + " is " + linkS[pState[i] + 1]); + tbl.rows[i + 1].cells[2].innerHTML = linkText(pState[i] + 1); + tbl.rows[i + 1].cells[3].innerHTML = `${txG[i]}` + t('common_pkts'); + tbl.rows[i + 1].cells[4].innerHTML = `${txB[i]}` + t('common_pkts'); + tbl.rows[i + 1].cells[5].innerHTML = `${rxG[i]}` + t('common_pkts'); + tbl.rows[i + 1].cells[6].innerHTML = `${rxB[i]}` + t('common_pkts'); } } else { for (let i = 0; i < numPorts; i++) { console.log("Table row: " + i); const tr = tbl.insertRow(); - let td = tr.insertCell(); td.appendChild(document.createTextNode(t('common_port') + (i+1))); + let td = tr.insertCell(); td.appendChild(document.createTextNode(t('common_port') + (i + 1))); let portName = portNames[physToLogPort[i]] || ''; td = tr.insertCell(); td.appendChild(document.createTextNode(portName)); - td = tr.insertCell(); td.appendChild(document.createTextNode(linkText(pState[i]+1))); + td = tr.insertCell(); td.appendChild(document.createTextNode(linkText(pState[i] + 1))); td = tr.insertCell(); td.appendChild(document.createTextNode(`${txG[i]}` + t('common_pkts'))); - td = tr.insertCell();td.appendChild(document.createTextNode(`${txB[i]}` + t('common_pkts'))); - td = tr.insertCell();td.appendChild(document.createTextNode(`${rxG[i]}` + t('common_pkts'))); - td = tr.insertCell();td.appendChild(document.createTextNode(`${rxB[i]}` + t('common_pkts'))); - var button = ''; + td = tr.insertCell(); td.appendChild(document.createTextNode(`${txB[i]}` + t('common_pkts'))); + td = tr.insertCell(); td.appendChild(document.createTextNode(`${rxG[i]}` + t('common_pkts'))); + td = tr.insertCell(); td.appendChild(document.createTextNode(`${rxB[i]}` + t('common_pkts'))); + var button = ''; td = tr.insertCell(); td.innerHTML = button; } } @@ -197,8 +197,8 @@ window.addEventListener('click', (event) => { } }); -window.addEventListener("load", function() { - update( () => { +window.addEventListener("load", function () { + update(() => { update(); fillStats(); const stat = setInterval(fillStats, 1000); diff --git a/httpd/page_impl.c b/httpd/page_impl.c index 4bcf497..d55d4fe 100644 --- a/httpd/page_impl.c +++ b/httpd/page_impl.c @@ -290,11 +290,12 @@ void send_vlan(uint16_t vlan) } /* Send counters - * Only accepts physical port idx to 0-8. + * Only accepts physical port 1..9. * Returns an error if the port physical don't exists. */ -bool send_counters(uint8_t phys_port_idx) +bool send_counters(uint8_t phys_port) { + uint8_t phys_port_idx = phys_port - 1; if (phys_port_idx > 8) goto err; uint8_t log_port = machine.phys_to_log_port[phys_port_idx]; diff --git a/httpd/page_impl.h b/httpd/page_impl.h index 1cbd94e..02ed4eb 100644 --- a/httpd/page_impl.h +++ b/httpd/page_impl.h @@ -3,7 +3,7 @@ #include -bool send_counters(uint8_t phys_port_idx); +bool send_counters(uint8_t phys_port); void send_status(void); void send_vlan(uint16_t vlan); void send_basic_info(void);