mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-08-30 14:52:51 +08:00
+16
-5
@@ -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;
|
||||
@@ -469,9 +470,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 +644,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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<script src="/ports.js"></script>
|
||||
<script src="/main.js"></script>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<title>FreeSwitchOS Port Statistics</title>
|
||||
</head>
|
||||
<body>
|
||||
<nav id="sidebar"></nav>
|
||||
<div style="margin-left:16%;padding:1px 16px;height:1000px;">
|
||||
<div id="ports"></div>
|
||||
<h1>EEE Status</h1>
|
||||
<table id="eeetable">
|
||||
<tr> <th> </th> <th colspan="3"> Advertising </th> <th colspan="3">Link-Partner advertises</th> <th></th></tr>
|
||||
<tr> <th>Port</th> <th>2.5G</th> <th>1G</th> <th>100M</th> <th>2.5G</th> <th>1G</th> <th>100M</th> <th>Active?</th></tr>
|
||||
</table>
|
||||
<div>
|
||||
<input style="width:20%;padding: 8px 16px;margin-top: 2em;margin-right: 3em;" id="eee_enable" onclick="eeeSub(0, 1);" type="button" value="Enable EEE">
|
||||
<input style="width:20%;padding: 8px 16px;margin-top: 2em;" id="eee_enable" onclick="eeeSub(0, 0);" type="button" value="Disable EEE">
|
||||
</div>
|
||||
<script src="/eee.js"></script>
|
||||
<script src="/eee_sub.js"></script>
|
||||
</div>
|
||||
<script src="/navigation.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
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.timeout = 1500; xhttp.send();
|
||||
}
|
||||
|
||||
window.addEventListener("load", function() {
|
||||
getEEE();
|
||||
const iCount = setInterval(getEEE, 2000);
|
||||
});
|
||||
const stat = setInterval(createEEE, 1000);
|
||||
@@ -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}`);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -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);
|
||||
});
|
||||
|
||||
+1
-1
@@ -4,6 +4,6 @@ document.getElementById('sidebar').innerHTML =
|
||||
+ "<li><a href='vlan.html'>VLAN</a></li>"
|
||||
+ "<li><a href='mirror.html'>Mirroring</a></li>"
|
||||
+ "<li><a href='trunk.html'>Port Aggregation</a></li>"
|
||||
+ "<li><a href='mirror.html'>Mirroring</a></li>"
|
||||
+ "<li><a href='eee.html'>EEE</a></li>"
|
||||
+ "<li><a href='update.html'>Firmware Update</a></li></ul>";
|
||||
|
||||
|
||||
@@ -17,6 +17,5 @@ function drawPorts() {
|
||||
l.id="port" + (i+1);
|
||||
f.appendChild(l);
|
||||
}
|
||||
|
||||
console.log("DRAWING DONE ");
|
||||
}
|
||||
|
||||
+1
-18
@@ -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);
|
||||
|
||||
@@ -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;}
|
||||
|
||||
+4
-3
@@ -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]) {
|
||||
@@ -422,6 +421,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();
|
||||
}
|
||||
|
||||
@@ -7,8 +7,10 @@
|
||||
#include "uip.h"
|
||||
#include "../html_data.h"
|
||||
#include <stdint.h>
|
||||
#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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
+1
-1
@@ -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);
|
||||
}
|
||||
|
||||
+67
-6
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
+17
-4
@@ -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);
|
||||
|
||||
+47
-2
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user