mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-08-30 14:52:51 +08:00
Remove flash_read_bulk(), refactor website and execute_config().
flash_read_bulk() is kind of a printf function. But did not work as well. flash_read_bulk() was used in the http generation so this needed to be changed as well. For the website we decided that we are going to use CSR(Client Side Rendering). So every HTML and JS files are now static. Variables are fetched via json calls and output is render on the client side. Also usefull for the future when we want a REST like API. execute_config() was also using flash_read_bulk(). This have been replaced with flash_read_bulk() and parsing the flash_buf buffer.
This commit is contained in:
+9
-41
@@ -15,7 +15,6 @@
|
||||
#pragma codeseg BANK1
|
||||
|
||||
extern __code struct f_data f_data[];
|
||||
extern __code fcall_ptr f_calls[];
|
||||
extern __code char * __code mime_strings[];
|
||||
extern __xdata struct flash_region_t flash_region;
|
||||
|
||||
@@ -407,6 +406,8 @@ void httpd_appcall(void)
|
||||
print_string("Not file entry\n");
|
||||
if (!strcmp(q, "/status.json")) {
|
||||
send_status();
|
||||
} else if (!strcmp(q, "/information.json")) {
|
||||
send_basic_info();
|
||||
} else if (!strcmp(q, "/vlan.json")) {
|
||||
parse_short(q + 15);
|
||||
send_vlan(short_parsed);
|
||||
@@ -419,47 +420,14 @@ void httpd_appcall(void)
|
||||
print_string("Have entry\n");
|
||||
slen = strtox(outbuf, "HTTP/1.1 200 OK\r\nContent-Type: ");
|
||||
slen += strtox(outbuf + slen, mime_strings[f_data[entry].mime]);
|
||||
slen += strtox(outbuf + slen, "\r\nCache-Control: max-age=2592000");
|
||||
slen += strtox(outbuf + slen, "\r\n\r\n");
|
||||
slen += strtox(outbuf + slen, "\r\nCache-Control: max-age=2592000\r\n\r\n");
|
||||
len_left = f_data[entry].len;
|
||||
if (f_data[entry].mime == mime_HTML) {
|
||||
print_string("MIME is html len is "); print_short(len_left); write_char('\n');
|
||||
mpos = 0;
|
||||
flash_addr = f_data[entry].start;
|
||||
flash_find_mark("#{", len_left);
|
||||
print_string("mpos: "); print_short(mpos); write_char('\n');
|
||||
while (mpos != 0xffff) {
|
||||
print_string("Entry-len:"); print_short(len_left); write_char('\n');
|
||||
mpos = len_left - mpos;
|
||||
print_string("l/pos: "); print_short(mpos); write_char('\n');
|
||||
flash_addr = f_data[entry].start + f_data[entry].len - len_left;
|
||||
flash_read_bulk(outbuf + slen, mpos + CMARK_S); // call marker is e.g. #{001}
|
||||
slen += mpos;
|
||||
write_char('@'); write_char(outbuf[slen + 2]); write_char(outbuf[slen + 3]); write_char(outbuf[slen + 4]);
|
||||
fcall_ptr ptr = f_calls[(outbuf[slen + 2] - '0') * 100 + (outbuf[slen + 3]-'0') * 10 + outbuf[slen + 4] - '0'];
|
||||
slen -= CMARK_S; // Overwrite marker with generated html
|
||||
print_string("Call location is: "); print_short((uint16_t)ptr); write_char('\n');
|
||||
// f_calls[outbuf[slen + 2] * 100 + outbuf[slen + 3] * 10 + outbuf[slen + 4]]();
|
||||
ptr();
|
||||
print_string("call done\n");
|
||||
mpos += CMARK_S;
|
||||
len_left -= mpos;
|
||||
flash_region.addr = f_data[entry].start + mpos;
|
||||
flash_addr = f_data[entry].start + f_data[entry].len - len_left;
|
||||
flash_find_mark("#{");
|
||||
print_string("mpos now: "); print_short(mpos); write_char('\n');
|
||||
}
|
||||
print_string("At end mpos: "); print_short(mpos); write_char('\n');
|
||||
flash_addr = f_data[entry].start + f_data[entry].len - len_left;
|
||||
flash_read_bulk(outbuf + slen, len_left);
|
||||
slen += len_left;
|
||||
} else {
|
||||
print_string("MIME: "); print_string(mime_strings[f_data[entry].mime]); write_char('\n');
|
||||
flash_region.addr = f_data[entry].start;
|
||||
flash_region.len = len_left;
|
||||
flash_read_bulk(outbuf + slen, len_left);
|
||||
slen += len_left;
|
||||
}
|
||||
|
||||
print_string("MIME: "); print_string(mime_strings[f_data[entry].mime]); write_char('\n');
|
||||
flash_region.addr = f_data[entry].start;
|
||||
flash_region.len = len_left;
|
||||
flash_read_bulk(outbuf + slen);
|
||||
slen += len_left;
|
||||
}
|
||||
do_send:
|
||||
print_string("slen: "); print_short(slen); write_char('\n');
|
||||
|
||||
+13
-12
@@ -27,6 +27,7 @@ extern __xdata uint8_t isRTL8373;
|
||||
extern __xdata uint8_t sfp_pins_last;
|
||||
extern __xdata uint8_t vlan_names[VLAN_NAMES_SIZE];
|
||||
|
||||
__code uint8_t * __code HTTP_RESPONCE_JSON = "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n";
|
||||
|
||||
/* Convert only the lower nibble to ascii HEX char.
|
||||
For convenience the upper nibble is masked out.
|
||||
@@ -133,40 +134,40 @@ void reg_to_html(register uint16_t reg)
|
||||
sfr_data_to_html();
|
||||
}
|
||||
|
||||
|
||||
uint16_t html_index(void)
|
||||
void send_basic_info(void)
|
||||
{
|
||||
print_string("html_index called\n");
|
||||
slen += strtox(outbuf + slen, "<tr><td>IP Address</td><td>");
|
||||
slen = strtox(outbuf, HTTP_RESPONCE_JSON);
|
||||
print_string("send_basic_info called\n");
|
||||
slen += strtox(outbuf + slen, "{\"ip_address\":\"");
|
||||
itoa_html(uip_hostaddr[0]); char_to_html('.');
|
||||
itoa_html(uip_hostaddr[0] >> 8); char_to_html('.');
|
||||
itoa_html(uip_hostaddr[1]); char_to_html('.');
|
||||
itoa_html(uip_hostaddr[1] >> 8);
|
||||
slen += strtox(outbuf + slen, "</td></tr><tr><td>Gateway</td><td>");
|
||||
slen += strtox(outbuf + slen, "\",\"ip_gateway\":\"");
|
||||
itoa_html(uip_draddr[0]); char_to_html('.');
|
||||
itoa_html(uip_draddr[0] >> 8); char_to_html('.');
|
||||
itoa_html(uip_draddr[1]); char_to_html('.');
|
||||
itoa_html(uip_draddr[1] >> 8);
|
||||
slen += strtox(outbuf + slen, "</td></tr><tr><td>Netmask</td><td>");
|
||||
slen += strtox(outbuf + slen, "\",\"ip_netmask\":\"");
|
||||
itoa_html(uip_netmask[0]); char_to_html('.');
|
||||
itoa_html(uip_netmask[0] >> 8); char_to_html('.');
|
||||
itoa_html(uip_netmask[1]); char_to_html('.');
|
||||
itoa_html(uip_netmask[1] >> 8);
|
||||
slen += strtox(outbuf + slen, "</td></tr><tr><td>MAC Address</td><td>");
|
||||
slen += strtox(outbuf + slen, "\",\"mac_address\":\"");
|
||||
byte_to_html(uip_ethaddr.addr[0]); char_to_html(':');
|
||||
byte_to_html(uip_ethaddr.addr[1]); char_to_html(':');
|
||||
byte_to_html(uip_ethaddr.addr[2]); char_to_html(':');
|
||||
byte_to_html(uip_ethaddr.addr[3]); char_to_html(':');
|
||||
byte_to_html(uip_ethaddr.addr[4]); char_to_html(':');
|
||||
byte_to_html(uip_ethaddr.addr[5]);
|
||||
slen += strtox(outbuf + slen, "</td></tr>");
|
||||
return 0;
|
||||
slen += strtox(outbuf + slen, "\",\"sw_ver\":\"v0.1-ge4c48586\",\"hw_ver\":\"SWGT024-V2.0\"}");
|
||||
// slen += strtox(outbuf + slen, "\"}");
|
||||
}
|
||||
|
||||
|
||||
void send_vlan(__xdata uint16_t vlan)
|
||||
{
|
||||
slen = strtox(outbuf, "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n");
|
||||
slen = strtox(outbuf, HTTP_RESPONCE_JSON);
|
||||
print_string("sending VLAN\n");
|
||||
//{"members":"0x00060011"}
|
||||
slen += strtox(outbuf + slen, "{\"members\":\"0x");
|
||||
@@ -187,7 +188,7 @@ void send_vlan(__xdata uint16_t vlan)
|
||||
void send_counters(char port)
|
||||
{
|
||||
print_string("send_counters called: "); print_byte(port); write_char('\n');
|
||||
slen = strtox(outbuf, "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n");
|
||||
slen = strtox(outbuf, HTTP_RESPONCE_JSON);
|
||||
print_string("sending counters\n");
|
||||
|
||||
port--;
|
||||
@@ -209,7 +210,7 @@ void send_counters(char port)
|
||||
|
||||
void send_status(void)
|
||||
{
|
||||
slen = strtox(outbuf, "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n");
|
||||
slen = strtox(outbuf, HTTP_RESPONCE_JSON);
|
||||
print_string("sending status\n");
|
||||
char_to_html('[');
|
||||
|
||||
|
||||
@@ -4,5 +4,6 @@
|
||||
void send_counters(char port);
|
||||
void send_status(void);
|
||||
void send_vlan(register uint16_t vlan);
|
||||
void send_basic_info(void);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user