add support to reset slip communication

pull/196/head
Thorsten von Eicken 8 years ago
parent 3a16d3ee61
commit c67750ad18
  1. 8
      cmd/cmd.c
  2. 8
      cmd/cmd.h
  3. 10
      cmd/handlers.c

@ -13,8 +13,6 @@
#define DBG(format, ...) do { } while(0)
#endif
extern const CmdList commands[];
//===== ESP -> Serial responses
static void ICACHE_FLASH_ATTR
@ -128,7 +126,11 @@ cmdParsePacket(uint8_t *buf, short len) {
}
#endif
if (data_ptr <= data_limit) {
if (!cmdInSync && packet->cmd != CMD_SYNC) {
// we have not received a sync, perhaps we reset? Tell MCU to do a sync
cmdResponseStart(CMD_SYNC, 0, 0);
cmdResponseEnd();
} else if (data_ptr <= data_limit) {
cmdExec(commands, packet);
} else {
DBG("cmdParsePacket: packet length overrun, parsing arg %d\n", packet->argc);

@ -6,6 +6,9 @@
#define CMD_H
#include <esp8266.h>
// keep track of whether we received a sync command from uC
extern bool cmdInSync;
// Standard SLIP escape chars from RFC
#define SLIP_END 0300 // indicates end of packet
#define SLIP_ESC 0333 // indicates byte stuffing
@ -48,7 +51,7 @@ typedef enum {
CMD_REST_SETUP = 20,
CMD_REST_REQUEST,
CMD_REST_SETHEADER,
CMD_WEB_DATA = 30, // MCU pushes data using this command
CMD_WEB_REQ_CB, // esp-link WEB callback
} CmdName;
@ -61,6 +64,9 @@ typedef struct {
cmdfunc_t sc_function; // pointer to function
} CmdList;
// command dispatch table
extern const CmdList commands[];
#define CMD_CBNLEN 16
typedef struct {
char name[CMD_CBNLEN];

@ -5,6 +5,7 @@
#include "esp8266.h"
#include "sntp.h"
#include "cmd.h"
#include "uart.h"
#include <cgiwifi.h>
#ifdef MQTT
#include <mqtt_cmd.h>
@ -28,7 +29,10 @@ static void cmdAddCallback(CmdPacket *cmd);
// keep track of last status sent to uC so we can notify it when it changes
static uint8_t lastWifiStatus = wifiIsDisconnected;
// keep track of whether we have registered our cb handler with the wifi subsystem
static bool wifiCbAdded = false;
// keep track of whether we received a sync command from uC
bool cmdInSync = false;
// Command dispatch table for serial -> ESP commands
const CmdList commands[] = {
@ -53,7 +57,7 @@ const CmdList commands[] = {
//===== List of registered callbacks (to uC)
// WifiCb plus 10 for sensors
// WifiCb plus 10 for other stuff
#define MAX_CALLBACKS 12
CmdCallback callbacks[MAX_CALLBACKS]; // cleared in cmdSync
@ -118,6 +122,7 @@ cmdNull(CmdPacket *cmd) {
static void ICACHE_FLASH_ATTR
cmdSync(CmdPacket *cmd) {
CmdRequest req;
uart0_write_char(SLIP_END); // prefix with a SLIP END to ensure we get a clean start
cmdRequest(&req, cmd);
if(cmd->argc != 0 || cmd->value == 0) {
cmdResponseStart(CMD_RESP_V, 0, 0);
@ -128,6 +133,8 @@ cmdSync(CmdPacket *cmd) {
// clear callbacks table
os_memset(callbacks, 0, sizeof(callbacks));
// TODO: call other protocols back to tell them to reset
// register our callback with wifi subsystem
if (!wifiCbAdded) {
wifiAddStateChangeCb(cmdWifiCb);
@ -137,6 +144,7 @@ cmdSync(CmdPacket *cmd) {
// send OK response
cmdResponseStart(CMD_RESP_V, cmd->value, 0);
cmdResponseEnd();
cmdInSync = true;
// save the MCU's callback and trigger an initial callback
cmdAddCb("wifiCb", cmd->value);

Loading…
Cancel
Save