Merge branch 'syncreset'

pull/196/head
Thorsten von Eicken 8 years ago
commit 4222cbf12a
  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) #define DBG(format, ...) do { } while(0)
#endif #endif
extern const CmdList commands[];
//===== ESP -> Serial responses //===== ESP -> Serial responses
static void ICACHE_FLASH_ATTR static void ICACHE_FLASH_ATTR
@ -128,7 +126,11 @@ cmdParsePacket(uint8_t *buf, short len) {
} }
#endif #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); cmdExec(commands, packet);
} else { } else {
DBG("cmdParsePacket: packet length overrun, parsing arg %d\n", packet->argc); DBG("cmdParsePacket: packet length overrun, parsing arg %d\n", packet->argc);

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

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

Loading…
Cancel
Save