Adding the console uart format support

Some of the MCU use format other than 8N1.
Adding the support for other format.
pull/163/head
Chris 9 years ago committed by Chris
parent 1bcdc62de3
commit 84157b221b
  1. 5
      esp-link/config.c
  2. 3
      esp-link/config.h
  3. 1
      esp-link/main.c
  4. 26
      html/console.html
  5. 32
      serial/console.c
  6. 1
      serial/console.h
  7. 2
      serial/uart.c
  8. 1
      serial/uart.h

@ -31,7 +31,10 @@ FlashConfig flashDefault = {
.rx_pullup = 1, .rx_pullup = 1,
.sntp_server = "us.pool.ntp.org\0", .sntp_server = "us.pool.ntp.org\0",
.syslog_host = "\0", .syslog_minheap = 8192, .syslog_filter = 7, .syslog_showtick = 1, .syslog_showdate = 0, .syslog_host = "\0", .syslog_minheap = 8192, .syslog_filter = 7, .syslog_showtick = 1, .syslog_showdate = 0,
.mdns_enable = 1, .mdns_servername = "http\0", .timezone_offset = 0 .mdns_enable = 1, .mdns_servername = "http\0", .timezone_offset = 0,
.data_bits = EIGHT_BITS,
.parity = NONE_BITS,
.stop_bits = ONE_STOP_BIT,
}; };
typedef union { typedef union {

@ -38,6 +38,9 @@ typedef struct {
char mdns_servername[32]; char mdns_servername[32];
int8_t timezone_offset; int8_t timezone_offset;
char mqtt_host[64]; // MQTT host we connect to, was 32-char mqtt_old_host char mqtt_host[64]; // MQTT host we connect to, was 32-char mqtt_old_host
int8_t data_bits;
int8_t parity;
int8_t stop_bits;
} FlashConfig; } FlashConfig;
extern FlashConfig flashConfig; extern FlashConfig flashConfig;

@ -74,6 +74,7 @@ HttpdBuiltInUrl builtInUrls[] = {
{ "/log/reset", cgiReset, NULL }, { "/log/reset", cgiReset, NULL },
{ "/console/reset", ajaxConsoleReset, NULL }, { "/console/reset", ajaxConsoleReset, NULL },
{ "/console/baud", ajaxConsoleBaud, NULL }, { "/console/baud", ajaxConsoleBaud, NULL },
{ "/console/fmt", ajaxConsoleFormat, NULL },
{ "/console/text", ajaxConsole, NULL }, { "/console/text", ajaxConsole, NULL },
{ "/console/send", ajaxConsoleSend, NULL }, { "/console/send", ajaxConsoleSend, NULL },
//Enable the line below to protect the WiFi configuration with an username/password combo. //Enable the line below to protect the WiFi configuration with an username/password combo.

@ -18,7 +18,17 @@
<option value="19200">19200</option> <option value="19200">19200</option>
<option value="9600">9600</option> <option value="9600">9600</option>
</select> </select>
&nbsp; Fmt: 8N1 &nbsp; Fmt:
<select id="fmt-sel" class="pure-button" href="#">
<option value="8N1">8N1</option>
<option value="8E1">8E1</option>
<option value="8N2">8N2</option>
<option value="8E2">8E2</option>
<option value="7N1">7N1</option>
<option value="7E1">7E1</option>
<option value="7N2">7N2</option>
<option value="7E2">7E2</option>
</select>
</p> </p>
<div class="pure-g"> <div class="pure-g">
<div class="pure-u-1-4"><legend><b>Console</b></legend></div> <div class="pure-u-1-4"><legend><b>Console</b></legend></div>
@ -93,6 +103,20 @@
); );
}); });
ajaxJson('GET', "/console/fmt",
function(data) { $("#fmt-sel").value = data.fmt; },
function(s, st) { showNotification(st); }
);
bnd($("#fmt-sel"), "change", function(ev) {
ev.preventDefault();
var fmt = $("#fmt-sel").value;
ajaxSpin('POST', "/console/fmt?fmt="+fmt,
function(resp) { showNotification("" + fmt + " format set"); },
function(s, st) { showWarning("Error setting format: " + st); }
);
});
consoleSendInit(); consoleSendInit();
addClass($('html')[0], "height100"); addClass($('html')[0], "height100");

@ -80,6 +80,38 @@ ajaxConsoleBaud(HttpdConnData *connData) {
httpdSend(connData, buff, -1); httpdSend(connData, buff, -1);
return HTTPD_CGI_DONE; return HTTPD_CGI_DONE;
} }
int ICACHE_FLASH_ATTR
ajaxConsoleFormat(HttpdConnData *connData) {
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
char buff[16];
int len, status = 400;
extern UartDevice UartDev;
len = httpdFindArg(connData->getArgs, "fmt", buff, sizeof(buff));
if (len >= 3) {
int c = buff[0];
if (c >= '5' && c <= '8')
flashConfig.data_bits = UartDev.data_bits = c - '5' + FIVE_BITS;
if (buff[1] == 'N' || buff[1] == 'E')
flashConfig.parity = UartDev.parity = buff[1] == 'E' ? EVEN_BITS : NONE_BITS;
if (buff[2] == '1' || buff[2] == '2')
flashConfig.stop_bits = UartDev.stop_bits = buff[2] == '2' ? TWO_STOP_BIT : ONE_STOP_BIT;
UartDev.baut_rate = flashConfig.baud_rate;
uart_config(0);
status = configSave() ? 200 : 400;
} else if (connData->requestType == HTTPD_METHOD_GET) {
status = 200;
}
jsonHeader(connData, status);
os_sprintf(buff, "{\"fmt\": \"%c%c%c\"}",
flashConfig.data_bits + '5',
flashConfig.parity ? 'E' : 'N',
flashConfig.stop_bits ? '2': '1');
httpdSend(connData, buff, -1);
return HTTPD_CGI_DONE;
}
int ICACHE_FLASH_ATTR int ICACHE_FLASH_ATTR
ajaxConsoleSend(HttpdConnData *connData) { ajaxConsoleSend(HttpdConnData *connData) {

@ -8,6 +8,7 @@ void ICACHE_FLASH_ATTR console_write_char(char c);
int ajaxConsole(HttpdConnData *connData); int ajaxConsole(HttpdConnData *connData);
int ajaxConsoleReset(HttpdConnData *connData); int ajaxConsoleReset(HttpdConnData *connData);
int ajaxConsoleBaud(HttpdConnData *connData); int ajaxConsoleBaud(HttpdConnData *connData);
int ajaxConsoleFormat(HttpdConnData *connData);
int ajaxConsoleSend(HttpdConnData *connData); int ajaxConsoleSend(HttpdConnData *connData);
int tplConsole(HttpdConnData *connData, char *token, void **arg); int tplConsole(HttpdConnData *connData, char *token, void **arg);

@ -44,7 +44,7 @@ static void uart0_rx_intr_handler(void *para);
* Parameters : uart_no, use UART0 or UART1 defined ahead * Parameters : uart_no, use UART0 or UART1 defined ahead
* Returns : NONE * Returns : NONE
*******************************************************************************/ *******************************************************************************/
static void ICACHE_FLASH_ATTR void ICACHE_FLASH_ATTR
uart_config(uint8 uart_no) uart_config(uint8 uart_no)
{ {
if (uart_no == UART1) { if (uart_no == UART1) {

@ -27,5 +27,6 @@ void uart_add_recv_cb(UartRecv_cb cb);
uint16_t uart0_rx_poll(char *buff, uint16_t nchars, uint32_t timeout_us); uint16_t uart0_rx_poll(char *buff, uint16_t nchars, uint32_t timeout_us);
void uart0_baud(int rate); void uart0_baud(int rate);
void uart_config(uint8 uart_no);
#endif /* __UART_H__ */ #endif /* __UART_H__ */

Loading…
Cancel
Save