Skip to content

Commit 42323dd

Browse files
committed
Add fetching of configuration file and current cmd history
1 parent fbf69ee commit 42323dd

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

httpd/httpd.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,10 @@ void httpd_appcall(void)
455455
send_eee();
456456
} else if (is_word(q, "/mirror.json")) {
457457
send_mirror();
458+
} else if (is_word(q, "/config")) {
459+
send_config();
460+
} else if (is_word(q, "/cmd_log")) {
461+
send_cmd_log();
458462
} else {
459463
send_not_found();
460464
}

httpd/page_impl.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "../rtl837x_common.h"
55
#include "../rtl837x_regs.h"
66
#include "../rtl837x_port.h"
7+
#include "../rtl837x_flash.h"
78
#include "uip.h"
89
#include "../html_data.h"
910
#include <stdint.h>
@@ -14,6 +15,8 @@
1415

1516
extern __xdata uint8_t outbuf[TCP_OUTBUF_SIZE];
1617
extern __xdata uint16_t slen;
18+
extern __xdata uint16_t cont_len;
19+
extern __xdata uint32_t cont_addr;
1720
extern __code uint8_t * __code hex;
1821
extern __xdata uip_ipaddr_t uip_hostaddr, uip_draddr, uip_netmask;
1922
extern __code struct uip_eth_addr uip_ethaddr;
@@ -29,7 +32,13 @@ extern __xdata uint8_t isRTL8373;
2932
extern __xdata uint8_t sfp_pins_last;
3033
extern __xdata uint8_t vlan_names[VLAN_NAMES_SIZE];
3134

35+
extern __xdata uint8_t cmd_history[CMD_HISTORY_SIZE];
36+
extern __xdata uint16_t cmd_history_ptr;
37+
38+
extern __xdata struct flash_region_t flash_region;
39+
3240
__code uint8_t * __code HTTP_RESPONCE_JSON = "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n";
41+
__code uint8_t * __code HTTP_RESPONCE_TXT = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\n";
3342

3443
/* Convert only the lower nibble to ascii HEX char.
3544
For convenience the upper nibble is masked out.
@@ -369,3 +378,46 @@ void send_status(void)
369378
char_to_html(']');
370379
}
371380
}
381+
382+
383+
void send_config(void)
384+
{
385+
print_string("send_config called\n");
386+
__xdata uint32_t pos = CONFIG_START; // 70000 , 6c000 / 0xc000 = 9
387+
388+
extern __xdata uint16_t len_left = CONFIG_LEN;
389+
slen = strtox(outbuf, HTTP_RESPONCE_TXT);
390+
while (read_flash((CONFIG_START-CODE0_SIZE) / CODE_BANK_SIZE + 1,
391+
(__code uint8_t *) (((CONFIG_START + len_left - CODE0_SIZE) % CODE_BANK_SIZE) + CODE0_SIZE + len_left)) == 0xff) {
392+
print_short(len_left);
393+
len_left--;
394+
}
395+
len_left++;
396+
397+
if (len_left > (TCP_OUTBUF_SIZE - slen)) {
398+
cont_len = len_left - (TCP_OUTBUF_SIZE - slen);
399+
len_left = TCP_OUTBUF_SIZE - slen;
400+
cont_addr = len_left;
401+
}
402+
flash_region.addr = CONFIG_START;
403+
flash_region.len = len_left;
404+
flash_read_bulk(outbuf + slen);
405+
slen += len_left;
406+
}
407+
408+
void send_cmd_log(void)
409+
{
410+
print_string("send_cmd_log called\n");
411+
slen = strtox(outbuf, HTTP_RESPONCE_TXT);
412+
__xdata uint16_t p = (cmd_history_ptr + 1) & CMD_HISTORY_MASK;
413+
__xdata uint8_t found_begin = 0;
414+
print_string("History ptr: ");
415+
print_short(cmd_history_ptr); write_char('\n');
416+
while (p != cmd_history_ptr) {
417+
if (!cmd_history[p] || cmd_history[p] == '\n')
418+
found_begin = 1;
419+
if (found_begin && cmd_history[p])
420+
outbuf[slen++] = cmd_history[p];
421+
p = (p + 1) & CMD_HISTORY_MASK;
422+
}
423+
}

httpd/page_impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ void send_vlan(register uint16_t vlan);
77
void send_basic_info(void);
88
void send_eee(void);
99
void send_mirror(void);
10+
void send_config(void);
11+
void send_cmd_log(void);
1012

1113
#endif

0 commit comments

Comments
 (0)