|
|
|
@ -1,5 +1,6 @@ |
|
|
|
|
#include <esp8266.h> |
|
|
|
|
#include "uart.h" |
|
|
|
|
#include "cgi.h" |
|
|
|
|
#include "console.h" |
|
|
|
|
|
|
|
|
|
// Web console for the esp8266 to replace outputting to uart1.
|
|
|
|
@ -13,12 +14,13 @@ static int console_wr, console_rd; |
|
|
|
|
static void ICACHE_FLASH_ATTR |
|
|
|
|
console_write(char c) { |
|
|
|
|
int wr = (console_wr+1)%BUF_MAX; |
|
|
|
|
if (wr != console_rd) { |
|
|
|
|
if (wr == console_rd) |
|
|
|
|
console_rd = (console_rd+1) % BUF_MAX; // full, eat first char
|
|
|
|
|
console_buf[console_wr] = c; |
|
|
|
|
console_wr = wr; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#if 0 |
|
|
|
|
static char ICACHE_FLASH_ATTR |
|
|
|
|
console_read(void) { |
|
|
|
|
char c = 0; |
|
|
|
@ -28,10 +30,11 @@ console_read(void) { |
|
|
|
|
} |
|
|
|
|
return c; |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
static void ICACHE_FLASH_ATTR |
|
|
|
|
console_write_char(char c) { |
|
|
|
|
//uart0_write_char(c);
|
|
|
|
|
uart0_write_char(c); |
|
|
|
|
if (c == '\n') console_write('\r'); |
|
|
|
|
console_write(c); |
|
|
|
|
} |
|
|
|
@ -40,18 +43,18 @@ console_write_char(char c) { |
|
|
|
|
int ICACHE_FLASH_ATTR |
|
|
|
|
tplConsole(HttpdConnData *connData, char *token, void **arg) { |
|
|
|
|
if (token==NULL) return HTTPD_CGI_DONE; |
|
|
|
|
char buff[256]; |
|
|
|
|
|
|
|
|
|
if (os_strcmp(token, "console") == 0) { |
|
|
|
|
char buf[128]; |
|
|
|
|
int n = 0; |
|
|
|
|
while (console_rd != console_wr) { |
|
|
|
|
buf[n++] = console_read(); |
|
|
|
|
if (n == 128) { |
|
|
|
|
httpdSend(connData, buf, n); |
|
|
|
|
n = 0; |
|
|
|
|
} |
|
|
|
|
if (console_wr > console_rd) { |
|
|
|
|
httpdSend(connData, console_buf+console_rd, console_wr-console_rd); |
|
|
|
|
} else if (console_rd != console_wr) { |
|
|
|
|
httpdSend(connData, console_buf+console_rd, BUF_MAX-console_rd); |
|
|
|
|
httpdSend(connData, console_buf, console_wr); |
|
|
|
|
} |
|
|
|
|
if (n > 0) httpdSend(connData, buf, n); |
|
|
|
|
} else if (os_strcmp(token, "topnav")==0) { |
|
|
|
|
printNav(buff); |
|
|
|
|
httpdSend(connData, buff, -1); |
|
|
|
|
} else { |
|
|
|
|
httpdSend(connData, "Unknown\n", -1); |
|
|
|
|
} |
|
|
|
|