mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-08-30 14:52:51 +08:00
Add mirroring web-calls
This commit is contained in:
@@ -441,6 +441,8 @@ void httpd_appcall(void)
|
||||
send_counters(q[19]-'0');
|
||||
} else if (is_word(q, "/eee.json")) {
|
||||
send_eee();
|
||||
} else if (is_word(q, "/mirror.json")) {
|
||||
send_mirror();
|
||||
} else {
|
||||
send_not_found();
|
||||
}
|
||||
|
||||
+39
-1
@@ -217,7 +217,45 @@ void send_counters(char port)
|
||||
}
|
||||
|
||||
|
||||
void send_eee()
|
||||
void send_mirror(void)
|
||||
{
|
||||
print_string("send_eee called\n");
|
||||
slen = strtox(outbuf, HTTP_RESPONCE_JSON);
|
||||
print_string("sending EEE status\n");
|
||||
|
||||
reg_read_m(RTL837x_MIRROR_CTRL);
|
||||
uint8_t mPort = sfr_data[3];
|
||||
if (mPort & 1) {
|
||||
slen += strtox(outbuf + slen, "{\"enabled\":1,\"mPort\":");
|
||||
} else {
|
||||
slen += strtox(outbuf + slen, "{\"enabled\":0,\"mPort\":");
|
||||
}
|
||||
if (!isRTL8373)
|
||||
itoa_html(log_to_phys_port[mPort >> 1]);
|
||||
else
|
||||
itoa_html((mPort >> 1) + 1);
|
||||
|
||||
reg_read_m(RTL837x_MIRROR_CONF);
|
||||
uint16_t m = sfr_data[0];
|
||||
m = (m << 8) | sfr_data[1];
|
||||
slen += strtox(outbuf + slen, ",\"mirror_rx\":\"");
|
||||
for (uint8_t i = 0; i < 16; i++) {
|
||||
bool_to_html(m & 0x8000);
|
||||
m <<= 1;
|
||||
}
|
||||
m = sfr_data[2];
|
||||
m = (m << 8) | sfr_data[3];
|
||||
slen += strtox(outbuf + slen, "\",\"mirror_tx\":\"");
|
||||
for (uint8_t i = 0; i < 16; i++) {
|
||||
bool_to_html(m & 0x8000);
|
||||
m <<= 1;
|
||||
}
|
||||
char_to_html('\"');
|
||||
char_to_html('}');
|
||||
}
|
||||
|
||||
|
||||
void send_eee(void)
|
||||
{
|
||||
print_string("send_eee called\nsending EEE status\n");
|
||||
slen = strtox(outbuf, HTTP_RESPONCE_JSON);
|
||||
|
||||
@@ -6,5 +6,6 @@ void send_status(void);
|
||||
void send_vlan(register uint16_t vlan);
|
||||
void send_basic_info(void);
|
||||
void send_eee(void);
|
||||
void send_mirror(void);
|
||||
|
||||
#endif
|
||||
|
||||
+35
-5
@@ -146,9 +146,6 @@ void send_eee(int s)
|
||||
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();
|
||||
@@ -166,13 +163,41 @@ void send_eee(int s)
|
||||
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);
|
||||
json_object_put(ports);
|
||||
}
|
||||
|
||||
|
||||
void send_mirror(int s)
|
||||
{
|
||||
uint16_t mirror_tx, mirror_rx = 0;
|
||||
char mirror_tx_buf[20];
|
||||
char mirror_rx_buf[20];
|
||||
struct json_object *mirror;
|
||||
const char *jstring;
|
||||
char *header = "HTTP/1.1 200 OK\r\n"
|
||||
"Content-Type: application/json; charset=UTF-8\r\n\r\n";
|
||||
|
||||
mirror = json_object_new_object();
|
||||
json_object_object_add(mirror, "mPort", json_object_new_int(1));
|
||||
json_object_object_add(mirror, "enabled", json_object_new_int(1));
|
||||
|
||||
mirror_tx = 0b000110;
|
||||
mirror_rx = 0b000010;
|
||||
sprintf(mirror_tx_buf, "%016b", mirror_tx);
|
||||
sprintf(mirror_rx_buf, "%016b", mirror_rx);
|
||||
json_object_object_add(mirror, "mirror_tx", json_object_new_string(mirror_tx_buf));
|
||||
json_object_object_add(mirror, "mirror_rx", json_object_new_string(mirror_rx_buf));
|
||||
|
||||
write(s, header, strlen(header));
|
||||
|
||||
jstring = json_object_to_json_string_ext(mirror, JSON_C_TO_STRING_PLAIN);
|
||||
write(s, jstring, strlen(jstring));
|
||||
json_object_put(mirror);
|
||||
}
|
||||
|
||||
|
||||
@@ -303,6 +328,11 @@ void launch(struct Server *server)
|
||||
send_basic_info(new_socket);
|
||||
goto done;
|
||||
}
|
||||
if (!strncmp(&buffer[4], "/mirror.json", 12)) {
|
||||
printf("Mirror request\n");
|
||||
send_mirror(new_socket);
|
||||
goto done;
|
||||
}
|
||||
if (!strncmp(&buffer[4], "/vlan.json?vid=", 15)) {
|
||||
int vlan = atoi(&buffer[19]);
|
||||
printf("VLAN request for %d\n", vlan);
|
||||
|
||||
Reference in New Issue
Block a user