From 109c10c3f25b19cddd197bb35d58c8e2cb508e47 Mon Sep 17 00:00:00 2001 From: Thorsten von Eicken Date: Sun, 24 Jan 2016 09:48:33 -0800 Subject: [PATCH] make new slip proto work --- cmd/cmd.h | 4 ++-- cmd/handlers.c | 17 ++++++----------- include/user_config.h | 2 +- serial/slip.c | 17 ++++++++--------- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/cmd/cmd.h b/cmd/cmd.h index 06486b5..d18d90d 100644 --- a/cmd/cmd.h +++ b/cmd/cmd.h @@ -20,7 +20,7 @@ typedef struct __attribute__((__packed__)) { typedef struct __attribute__((__packed__)) { uint16_t cmd; // command to perform, from CmdName enum uint32_t callback; // callback pointer to embed in response - uint32_t _return; // return value to embed in response (?) + uint32_t _return; // token to embed in response uint16_t argc; // number of arguments to command CmdArg args[0]; // really args[argc] } CmdPacket; @@ -33,7 +33,7 @@ typedef struct { typedef enum { CMD_NULL = 0, - CMD_RESET, // reset esp (not honored in this implementation) + CMD_SYNC, // synchronize and clear CMD_IS_READY, // health-check CMD_WIFI_CONNECT, // (3) connect to AP (not honored in this implementation) CMD_MQTT_SETUP, diff --git a/cmd/handlers.c b/cmd/handlers.c index 50af21d..62d2f94 100644 --- a/cmd/handlers.c +++ b/cmd/handlers.c @@ -19,8 +19,7 @@ #endif static uint32_t CMD_Null(CmdPacket *cmd); -static uint32_t CMD_IsReady(CmdPacket *cmd); -static uint32_t CMD_Reset(CmdPacket *cmd); +//static uint32_t CMD_Reset(CmdPacket *cmd); static uint32_t CMD_WifiConnect(CmdPacket *cmd); static uint32_t CMD_AddCallback(CmdPacket *cmd); @@ -30,9 +29,9 @@ static bool wifiCbAdded = false; // Command dispatch table for serial -> ESP commands const CmdList commands[] = { - {CMD_NULL, CMD_Null}, - {CMD_RESET, CMD_Reset}, - {CMD_IS_READY, CMD_IsReady}, + {CMD_NULL, CMD_Null}, // no-op + //{CMD_SYNC, CMD_Sync}, // synchronize + //{CMD_IS_READY, CMD_IsReady}, {CMD_WIFI_CONNECT, CMD_WifiConnect}, #ifdef MQTT {CMD_MQTT_SETUP, MQTTCMD_Setup}, @@ -55,18 +54,13 @@ const CmdList commands[] = { #define MAX_CALLBACKS 12 cmdCallback callbacks[MAX_CALLBACKS]; // cleared in CMD_Reset -// Command handler for IsReady (healthcheck) command -static uint32_t ICACHE_FLASH_ATTR -CMD_IsReady(CmdPacket *cmd) { - return 1; -} - // Command handler for Null command static uint32_t ICACHE_FLASH_ATTR CMD_Null(CmdPacket *cmd) { return 1; } +#if 0 // Command handler for Reset command, this was originally to reset the ESP but we don't want to // do that in esp-link. It is still good to clear any information the ESP has about the attached // uC. @@ -76,6 +70,7 @@ CMD_Reset(CmdPacket *cmd) { os_memset(callbacks, 0, sizeof(callbacks)); return 1; } +#endif static uint32_t ICACHE_FLASH_ATTR CMD_AddCb(char* name, uint32_t cb) { diff --git a/include/user_config.h b/include/user_config.h index 72fe1ac..a939533 100644 --- a/include/user_config.h +++ b/include/user_config.h @@ -27,7 +27,7 @@ #define RESTCMD_DBG #define SERBR_DBG #define SERLED_DBG -#undef SLIP_DBG +#define SLIP_DBG #define UART_DBG #define MDNS_DBG #define OPTIBOOT_DBG diff --git a/serial/slip.c b/serial/slip.c index 727f60c..cd88c1e 100644 --- a/serial/slip.c +++ b/serial/slip.c @@ -45,13 +45,12 @@ slip_process() { if (crc == rcv) { CMD_parse_packet((uint8_t*)slip_buf, slip_len-2); } else { - os_printf("SLIP: bad CRC, crc=%x rcv=%x\n", crc, rcv); + os_printf("SLIP: bad CRC, crc=%04x rcv=%04x len=%d\n", crc, rcv, slip_len); for (short i=0; i= ' ' && slip_buf[i] <= '~') { DBG("%c", slip_buf[i]); - } - else { + } else { DBG("\\%02X", slip_buf[i]); } } @@ -79,12 +78,12 @@ static void ICACHE_FLASH_ATTR slip_parse_char(char c) { if (c == SLIP_END) { // either start or end of packet, process whatever we may have accumulated + DBG("SLIP: start or end len=%d inpkt=%d\n", slip_len, slip_inpkt); if (slip_len > 0) { - if (slip_inpkt) slip_process(); else console_process(slip_buf, slip_len); + if (slip_len > 2 && slip_inpkt) slip_process(); + else console_process(slip_buf, slip_len); } slip_reset(); - //slip_inpkt = true; - DBG("SLIP: start or end\n"); } else if (slip_escaped) { // prev char was SLIP_ESC if (c == SLIP_ESC_END) c = SLIP_END; @@ -94,7 +93,7 @@ slip_parse_char(char c) { } else if (slip_inpkt && c == SLIP_ESC) { slip_escaped = true; } else { - if (slip_len == 0 && slip_printable(c)) { + if (slip_len == 1 && slip_printable(slip_buf[0]) && slip_printable(c)) { // start of packet and it's a printable character, we're gonna assume that this is console text slip_inpkt = false; } @@ -111,8 +110,8 @@ slip_parse_buf(char *buf, short length) { // if we're in-between packets (debug console) then print it now if (!slip_inpkt && length > 0) { - slip_process(); - slip_reset(); + console_process(slip_buf, slip_len); + slip_len = 0; } }