diff --git a/html/stat.js b/html/stat.js
index 661a2cd..8553093 100644
--- a/html/stat.js
+++ b/html/stat.js
@@ -23,4 +23,21 @@ 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);
diff --git a/httpd/page_impl.c b/httpd/page_impl.c
index eeddf52..b4c4a5c 100644
--- a/httpd/page_impl.c
+++ b/httpd/page_impl.c
@@ -6,6 +6,7 @@
#include "../rtl837x_port.h"
#include "uip.h"
#include "../html_data.h"
+#include
#pragma codeseg BANK1
@@ -15,6 +16,7 @@ extern __code uint8_t * __code hex;
extern __xdata uip_ipaddr_t uip_hostaddr, uip_draddr, uip_netmask;
extern __code uint8_t ownMAC[];
extern __code uint8_t log_to_phys_port[9];
+extern __code uint8_t phys_to_log_port[6];
extern __xdata uint8_t minPort;
extern __xdata uint8_t maxPort;
@@ -113,7 +115,7 @@ uint16_t html_index(void)
}
-uint16_t send_vlan(register uint16_t vlan)
+void send_vlan(register uint16_t vlan)
{
slen = strtox(outbuf, "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n");
print_string("sending VLAN\n");
@@ -122,11 +124,35 @@ uint16_t send_vlan(register uint16_t vlan)
vlan_get(vlan);
sfr_data_to_html();
slen += strtox(outbuf + slen, "\"}");
- return 0;
}
-uint16_t send_status(void)
+void send_counters(char port)
+{
+ slen = strtox(outbuf, "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n");
+ print_string("sending counters\n");
+
+ port--;
+ uint8_t i = isRTL8373 ? port : phys_to_log_port[port];
+ slen += strtox(outbuf + slen, "{\"portNum\":");
+ if (!isRTL8373)
+ itoa_html(log_to_phys_port[i]);
+ else
+ itoa_html(i + 1);
+ for (uint8_t j = 0; j < 0x3f; j++) {
+ STAT_GET(j, i);
+ slen += strtox(outbuf + slen, ",\"cnt_");
+ itoa_html(j);
+ slen += strtox(outbuf + slen, "\":\"0x");
+ reg_to_html(RTL837X_STAT_V_HIGH);
+ reg_to_html(RTL837X_STAT_V_LOW);
+ char_to_html('\"');
+ }
+ char_to_html('}');
+}
+
+
+void send_status(void)
{
slen = strtox(outbuf, "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n");
print_string("sending status\n");
@@ -195,5 +221,4 @@ uint16_t send_status(void)
else
char_to_html(']');
}
- return 0;
}
diff --git a/httpd/page_impl.h b/httpd/page_impl.h
index f92c759..c643140 100644
--- a/httpd/page_impl.h
+++ b/httpd/page_impl.h
@@ -1,7 +1,8 @@
#ifndef __PAGE_IMPL_H__
#define __PAGE_IMPL_H__
-uint16_t send_status(void);
-uint16_t send_vlan(register uint16_t vlan);
+void send_counters(char port);
+void send_status(void);
+void send_vlan(register uint16_t vlan);
#endif