Backing up an unused program in case of future need

Dependencies:   mbed

Committer:
andrewboyson
Date:
Wed Apr 13 09:21:02 2016 +0000
Revision:
0:09f915e6f9f6
Child:
2:06fa34661f19
Fixed memory allocation issues and added enumeration to log.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewboyson 0:09f915e6f9f6 1 #include "mbed.h"
andrewboyson 0:09f915e6f9f6 2 #include "log.h"
andrewboyson 0:09f915e6f9f6 3 #include "esp.h"
andrewboyson 0:09f915e6f9f6 4 #include "io.h"
andrewboyson 0:09f915e6f9f6 5 #include <stdarg.h>
andrewboyson 0:09f915e6f9f6 6
andrewboyson 0:09f915e6f9f6 7
andrewboyson 0:09f915e6f9f6 8 #define RECV_TIMEOUT_MS 5000
andrewboyson 0:09f915e6f9f6 9 static RawSerial esp(p9, p10); // tx, rx
andrewboyson 0:09f915e6f9f6 10
andrewboyson 0:09f915e6f9f6 11 //State
andrewboyson 0:09f915e6f9f6 12 #define LINE_LENGTH 256
andrewboyson 0:09f915e6f9f6 13 #define IDLE 0
andrewboyson 0:09f915e6f9f6 14 #define IN_LINE 1
andrewboyson 0:09f915e6f9f6 15 #define IPD_WAIT_START 2
andrewboyson 0:09f915e6f9f6 16 #define IPD_READ 3
andrewboyson 0:09f915e6f9f6 17 #define SEND_DATA 4
andrewboyson 0:09f915e6f9f6 18 static int state; //Initialised in init
andrewboyson 0:09f915e6f9f6 19
andrewboyson 0:09f915e6f9f6 20 //Solicited responses received
andrewboyson 0:09f915e6f9f6 21 //============================
andrewboyson 0:09f915e6f9f6 22 #define LINE_LENGTH 256
andrewboyson 0:09f915e6f9f6 23 int EspLineAvailable; //Initialised in init; can be one of the values defined in esp.h
andrewboyson 0:09f915e6f9f6 24 char EspLine[LINE_LENGTH];
andrewboyson 0:09f915e6f9f6 25 static char * pLineNext; //Initialised in init to EspLine
andrewboyson 0:09f915e6f9f6 26 int addToLine(char c)
andrewboyson 0:09f915e6f9f6 27 {
andrewboyson 0:09f915e6f9f6 28 if (pLineNext >= EspLine + LINE_LENGTH) return -1;
andrewboyson 0:09f915e6f9f6 29 switch (c)
andrewboyson 0:09f915e6f9f6 30 {
andrewboyson 0:09f915e6f9f6 31 case 0:
andrewboyson 0:09f915e6f9f6 32 *pLineNext = '\\';
andrewboyson 0:09f915e6f9f6 33 pLineNext++;
andrewboyson 0:09f915e6f9f6 34 *pLineNext = '0';
andrewboyson 0:09f915e6f9f6 35 pLineNext++;
andrewboyson 0:09f915e6f9f6 36 break;
andrewboyson 0:09f915e6f9f6 37 case '\r':
andrewboyson 0:09f915e6f9f6 38 case '\n':
andrewboyson 0:09f915e6f9f6 39 break;
andrewboyson 0:09f915e6f9f6 40 default:
andrewboyson 0:09f915e6f9f6 41 *pLineNext = c;
andrewboyson 0:09f915e6f9f6 42 pLineNext++;
andrewboyson 0:09f915e6f9f6 43 break;
andrewboyson 0:09f915e6f9f6 44 }
andrewboyson 0:09f915e6f9f6 45 *pLineNext = 0;
andrewboyson 0:09f915e6f9f6 46 return 0;
andrewboyson 0:09f915e6f9f6 47 }
andrewboyson 0:09f915e6f9f6 48
andrewboyson 0:09f915e6f9f6 49 //Unsolicited ntp or http requests
andrewboyson 0:09f915e6f9f6 50 //================================
andrewboyson 0:09f915e6f9f6 51 void *EspIpdBuffer[4];
andrewboyson 0:09f915e6f9f6 52 int EspIpdBufferLen[4];
andrewboyson 0:09f915e6f9f6 53 int EspIpdReserved[4];
andrewboyson 0:09f915e6f9f6 54 int EspIpdLength;
andrewboyson 0:09f915e6f9f6 55 int EspIpdId;
andrewboyson 0:09f915e6f9f6 56 int EspDataAvailable;
andrewboyson 0:09f915e6f9f6 57
andrewboyson 0:09f915e6f9f6 58 //Wrap around buffers
andrewboyson 0:09f915e6f9f6 59 //===================
andrewboyson 0:09f915e6f9f6 60 #define RECV_BUFFER_LENGTH 1024
andrewboyson 0:09f915e6f9f6 61 #define SEND_BUFFER_LENGTH 1024
andrewboyson 0:09f915e6f9f6 62 static char recvbuffer[RECV_BUFFER_LENGTH];
andrewboyson 0:09f915e6f9f6 63 static char sendbuffer[SEND_BUFFER_LENGTH];
andrewboyson 0:09f915e6f9f6 64 static char* pRecvPush; //Initialised in init
andrewboyson 0:09f915e6f9f6 65 static char* pRecvPull; //Initialised in init
andrewboyson 0:09f915e6f9f6 66 static char* pSendPush; //Initialised in init
andrewboyson 0:09f915e6f9f6 67 static char* pSendPull; //Initialised in init
andrewboyson 0:09f915e6f9f6 68
andrewboyson 0:09f915e6f9f6 69 static void incrementPushPullPointer(char** pp, char* buffer, int bufferLength)
andrewboyson 0:09f915e6f9f6 70 {
andrewboyson 0:09f915e6f9f6 71 (*pp)++; //increment the pointer by one
andrewboyson 0:09f915e6f9f6 72 if (*pp == buffer + bufferLength) *pp = buffer; //if the pointer is now beyond the end then point it back to the start
andrewboyson 0:09f915e6f9f6 73 }
andrewboyson 0:09f915e6f9f6 74 static void recvpush(void) //Called by the esp data received interrupt
andrewboyson 0:09f915e6f9f6 75 {
andrewboyson 0:09f915e6f9f6 76 while (esp.readable())
andrewboyson 0:09f915e6f9f6 77 {
andrewboyson 0:09f915e6f9f6 78 int c = esp.getc();
andrewboyson 0:09f915e6f9f6 79 *pRecvPush = c;
andrewboyson 0:09f915e6f9f6 80 incrementPushPullPointer(&pRecvPush, recvbuffer, RECV_BUFFER_LENGTH);
andrewboyson 0:09f915e6f9f6 81 }
andrewboyson 0:09f915e6f9f6 82 }
andrewboyson 0:09f915e6f9f6 83 static int recvpull(void) //Called every scan. Returns the next byte or EOF if no more are available
andrewboyson 0:09f915e6f9f6 84 {
andrewboyson 0:09f915e6f9f6 85 if (pRecvPull == pRecvPush) return EOF;
andrewboyson 0:09f915e6f9f6 86 char c = *pRecvPull;
andrewboyson 0:09f915e6f9f6 87 incrementPushPullPointer(&pRecvPull, recvbuffer, RECV_BUFFER_LENGTH);
andrewboyson 0:09f915e6f9f6 88 return c;
andrewboyson 0:09f915e6f9f6 89 }
andrewboyson 0:09f915e6f9f6 90 static void sendpush(char c) //Called whenever something needs to be sent
andrewboyson 0:09f915e6f9f6 91 {
andrewboyson 0:09f915e6f9f6 92 *pSendPush = c;
andrewboyson 0:09f915e6f9f6 93 incrementPushPullPointer(&pSendPush, sendbuffer, SEND_BUFFER_LENGTH);
andrewboyson 0:09f915e6f9f6 94 }
andrewboyson 0:09f915e6f9f6 95 static int sendpull(void) //Called every scan. Returns the next byte or EOF if no more are available
andrewboyson 0:09f915e6f9f6 96 {
andrewboyson 0:09f915e6f9f6 97 if (pSendPull == pSendPush) return EOF;
andrewboyson 0:09f915e6f9f6 98 char c = *pSendPull;
andrewboyson 0:09f915e6f9f6 99 incrementPushPullPointer(&pSendPull, sendbuffer, SEND_BUFFER_LENGTH);
andrewboyson 0:09f915e6f9f6 100 return c;
andrewboyson 0:09f915e6f9f6 101 }
andrewboyson 0:09f915e6f9f6 102
andrewboyson 0:09f915e6f9f6 103 //Stuff to send
andrewboyson 0:09f915e6f9f6 104 //=============
andrewboyson 0:09f915e6f9f6 105 int EspLengthToSend;
andrewboyson 0:09f915e6f9f6 106 const void * EspDataToSend;
andrewboyson 0:09f915e6f9f6 107
andrewboyson 0:09f915e6f9f6 108 void EspSendStringF(char *fmt, ...)
andrewboyson 0:09f915e6f9f6 109 {
andrewboyson 0:09f915e6f9f6 110 va_list argptr;
andrewboyson 0:09f915e6f9f6 111 va_start(argptr, fmt);
andrewboyson 0:09f915e6f9f6 112 int size = vsnprintf(NULL, 0, fmt, argptr);
andrewboyson 0:09f915e6f9f6 113 char snd[size + 1];
andrewboyson 0:09f915e6f9f6 114 vsprintf(snd, fmt, argptr);
andrewboyson 0:09f915e6f9f6 115 va_end(argptr);
andrewboyson 0:09f915e6f9f6 116 EspSendString(snd);
andrewboyson 0:09f915e6f9f6 117 }
andrewboyson 0:09f915e6f9f6 118 void EspSendString(char* p)
andrewboyson 0:09f915e6f9f6 119 {
andrewboyson 0:09f915e6f9f6 120 while(*p) sendpush(*p++);
andrewboyson 0:09f915e6f9f6 121 }
andrewboyson 0:09f915e6f9f6 122 void EspSendData(int length, const void * snd)
andrewboyson 0:09f915e6f9f6 123 {
andrewboyson 0:09f915e6f9f6 124 const char* p = (char*)snd;
andrewboyson 0:09f915e6f9f6 125 const char* e = (char*)snd + length;
andrewboyson 0:09f915e6f9f6 126 while (p < e) sendpush(*p++);
andrewboyson 0:09f915e6f9f6 127 }
andrewboyson 0:09f915e6f9f6 128
andrewboyson 0:09f915e6f9f6 129
andrewboyson 0:09f915e6f9f6 130 //Reset ESP8266 zone
andrewboyson 0:09f915e6f9f6 131 #define RESET_TIME_MS 250
andrewboyson 0:09f915e6f9f6 132 static DigitalOut espRunOnHighResetOnLow(p26);
andrewboyson 0:09f915e6f9f6 133 int reset; //Set to 1 by EspReset (and hence EspInit); set to 0 by EspReleasefromReset
andrewboyson 0:09f915e6f9f6 134 void EspResetAndStop()
andrewboyson 0:09f915e6f9f6 135 {
andrewboyson 0:09f915e6f9f6 136 reset = true;
andrewboyson 0:09f915e6f9f6 137 pRecvPush = recvbuffer;
andrewboyson 0:09f915e6f9f6 138 pRecvPull = recvbuffer;
andrewboyson 0:09f915e6f9f6 139 pSendPush = sendbuffer;
andrewboyson 0:09f915e6f9f6 140 pSendPull = sendbuffer;
andrewboyson 0:09f915e6f9f6 141 pLineNext = EspLine;
andrewboyson 0:09f915e6f9f6 142 *pLineNext = 0;
andrewboyson 0:09f915e6f9f6 143 EspLengthToSend = 0;
andrewboyson 0:09f915e6f9f6 144 EspDataToSend = NULL;
andrewboyson 0:09f915e6f9f6 145 state = IDLE;
andrewboyson 0:09f915e6f9f6 146 }
andrewboyson 0:09f915e6f9f6 147 void EspReleaseFromReset(void)
andrewboyson 0:09f915e6f9f6 148 {
andrewboyson 0:09f915e6f9f6 149 reset = false;
andrewboyson 0:09f915e6f9f6 150 }
andrewboyson 0:09f915e6f9f6 151 void pulseResetPin()
andrewboyson 0:09f915e6f9f6 152 {
andrewboyson 0:09f915e6f9f6 153 static Timer resetTimer;
andrewboyson 0:09f915e6f9f6 154
andrewboyson 0:09f915e6f9f6 155 if (reset)
andrewboyson 0:09f915e6f9f6 156 {
andrewboyson 0:09f915e6f9f6 157 resetTimer.stop();
andrewboyson 0:09f915e6f9f6 158 resetTimer.reset();
andrewboyson 0:09f915e6f9f6 159 espRunOnHighResetOnLow = 0;
andrewboyson 0:09f915e6f9f6 160 }
andrewboyson 0:09f915e6f9f6 161 else
andrewboyson 0:09f915e6f9f6 162 {
andrewboyson 0:09f915e6f9f6 163 resetTimer.start();
andrewboyson 0:09f915e6f9f6 164 if (resetTimer.read_ms() > RESET_TIME_MS)
andrewboyson 0:09f915e6f9f6 165 {
andrewboyson 0:09f915e6f9f6 166 resetTimer.stop();
andrewboyson 0:09f915e6f9f6 167 espRunOnHighResetOnLow = 1;
andrewboyson 0:09f915e6f9f6 168 }
andrewboyson 0:09f915e6f9f6 169 }
andrewboyson 0:09f915e6f9f6 170 }
andrewboyson 0:09f915e6f9f6 171 //General commands
andrewboyson 0:09f915e6f9f6 172 void EspInit()
andrewboyson 0:09f915e6f9f6 173 {
andrewboyson 0:09f915e6f9f6 174 EspResetAndStop();
andrewboyson 0:09f915e6f9f6 175 esp.attach(&recvpush, Serial::RxIrq);
andrewboyson 0:09f915e6f9f6 176 esp.baud(BAUD);
andrewboyson 0:09f915e6f9f6 177 for (int i = 0; i < 4; i++)
andrewboyson 0:09f915e6f9f6 178 {
andrewboyson 0:09f915e6f9f6 179 EspIpdBuffer[i] = NULL;
andrewboyson 0:09f915e6f9f6 180 EspIpdBufferLen[i] = 0;
andrewboyson 0:09f915e6f9f6 181 EspIpdReserved[i] = 0;
andrewboyson 0:09f915e6f9f6 182 }
andrewboyson 0:09f915e6f9f6 183 }
andrewboyson 0:09f915e6f9f6 184 void EspBaud(int baud)
andrewboyson 0:09f915e6f9f6 185 {
andrewboyson 0:09f915e6f9f6 186 esp.baud(baud);
andrewboyson 0:09f915e6f9f6 187 }
andrewboyson 0:09f915e6f9f6 188
andrewboyson 0:09f915e6f9f6 189 //Main loop zone
andrewboyson 0:09f915e6f9f6 190 int handleCharacter(char c)
andrewboyson 0:09f915e6f9f6 191 {
andrewboyson 0:09f915e6f9f6 192 //Static variables. Initialised on first load.
andrewboyson 0:09f915e6f9f6 193 static char ipdHeader[20];
andrewboyson 0:09f915e6f9f6 194 static char * pipdHeader; //Set to ipdHeader when a '+' is received
andrewboyson 0:09f915e6f9f6 195 static int bytesRcvd; //Set to 0 when the ':' following the +IPD is received
andrewboyson 0:09f915e6f9f6 196 static void * pData; //Set to EspIpdBuffer[EspIpdId] when the ':' following the +IPD is received
andrewboyson 0:09f915e6f9f6 197
andrewboyson 0:09f915e6f9f6 198 switch(state)
andrewboyson 0:09f915e6f9f6 199 {
andrewboyson 0:09f915e6f9f6 200 case IDLE:
andrewboyson 0:09f915e6f9f6 201 if (c == '+')
andrewboyson 0:09f915e6f9f6 202 {
andrewboyson 0:09f915e6f9f6 203 pipdHeader = ipdHeader;
andrewboyson 0:09f915e6f9f6 204 *pipdHeader = 0;
andrewboyson 0:09f915e6f9f6 205 state = IPD_WAIT_START;
andrewboyson 0:09f915e6f9f6 206 }
andrewboyson 0:09f915e6f9f6 207 else if (c == '>')
andrewboyson 0:09f915e6f9f6 208 {
andrewboyson 0:09f915e6f9f6 209 state = SEND_DATA;
andrewboyson 0:09f915e6f9f6 210 }
andrewboyson 0:09f915e6f9f6 211 else
andrewboyson 0:09f915e6f9f6 212 {
andrewboyson 0:09f915e6f9f6 213 pLineNext = EspLine;
andrewboyson 0:09f915e6f9f6 214 *pLineNext = 0;
andrewboyson 0:09f915e6f9f6 215 int r = addToLine(c);
andrewboyson 0:09f915e6f9f6 216 if (r)
andrewboyson 0:09f915e6f9f6 217 {
andrewboyson 0:09f915e6f9f6 218 EspLineAvailable = ESP_OVERFLOW;
andrewboyson 0:09f915e6f9f6 219 state = IDLE;
andrewboyson 0:09f915e6f9f6 220 }
andrewboyson 0:09f915e6f9f6 221 else
andrewboyson 0:09f915e6f9f6 222 {
andrewboyson 0:09f915e6f9f6 223 state = IN_LINE;
andrewboyson 0:09f915e6f9f6 224 }
andrewboyson 0:09f915e6f9f6 225 }
andrewboyson 0:09f915e6f9f6 226 break;
andrewboyson 0:09f915e6f9f6 227 case IN_LINE:
andrewboyson 0:09f915e6f9f6 228 if (c == '\n')
andrewboyson 0:09f915e6f9f6 229 {
andrewboyson 0:09f915e6f9f6 230 EspLineAvailable = ESP_AVAILABLE;
andrewboyson 0:09f915e6f9f6 231 state = IDLE;
andrewboyson 0:09f915e6f9f6 232 }
andrewboyson 0:09f915e6f9f6 233 else
andrewboyson 0:09f915e6f9f6 234 {
andrewboyson 0:09f915e6f9f6 235 int r = addToLine(c);
andrewboyson 0:09f915e6f9f6 236 if (r)
andrewboyson 0:09f915e6f9f6 237 {
andrewboyson 0:09f915e6f9f6 238 EspLineAvailable = ESP_OVERFLOW;
andrewboyson 0:09f915e6f9f6 239 state = IDLE;
andrewboyson 0:09f915e6f9f6 240 }
andrewboyson 0:09f915e6f9f6 241 }
andrewboyson 0:09f915e6f9f6 242 break;
andrewboyson 0:09f915e6f9f6 243 case IPD_WAIT_START:
andrewboyson 0:09f915e6f9f6 244 if (pipdHeader == ipdHeader && c != 'I') //If the first character after the '+' is not 'I' then start a line instead
andrewboyson 0:09f915e6f9f6 245 {
andrewboyson 0:09f915e6f9f6 246 pLineNext = EspLine;
andrewboyson 0:09f915e6f9f6 247 addToLine('+');
andrewboyson 0:09f915e6f9f6 248 addToLine(c);
andrewboyson 0:09f915e6f9f6 249 state = IN_LINE;
andrewboyson 0:09f915e6f9f6 250 }
andrewboyson 0:09f915e6f9f6 251 else
andrewboyson 0:09f915e6f9f6 252 {
andrewboyson 0:09f915e6f9f6 253 *pipdHeader++ = c;
andrewboyson 0:09f915e6f9f6 254 *pipdHeader = 0;
andrewboyson 0:09f915e6f9f6 255 if (c == ':')
andrewboyson 0:09f915e6f9f6 256 {
andrewboyson 0:09f915e6f9f6 257 sscanf(ipdHeader, "IPD,%d,%d:", &EspIpdId, &EspIpdLength);
andrewboyson 0:09f915e6f9f6 258 bytesRcvd = 0;
andrewboyson 0:09f915e6f9f6 259 pData = EspIpdBuffer[EspIpdId];
andrewboyson 0:09f915e6f9f6 260 state = IPD_READ;
andrewboyson 0:09f915e6f9f6 261 }
andrewboyson 0:09f915e6f9f6 262 }
andrewboyson 0:09f915e6f9f6 263 break;
andrewboyson 0:09f915e6f9f6 264 case IPD_READ:
andrewboyson 0:09f915e6f9f6 265 bytesRcvd++;
andrewboyson 0:09f915e6f9f6 266 if (bytesRcvd <= EspIpdBufferLen[EspIpdId])
andrewboyson 0:09f915e6f9f6 267 {
andrewboyson 0:09f915e6f9f6 268 *(char *)pData = c;
andrewboyson 0:09f915e6f9f6 269 pData = (char *)pData + 1;
andrewboyson 0:09f915e6f9f6 270 }
andrewboyson 0:09f915e6f9f6 271 if (bytesRcvd == EspIpdLength)
andrewboyson 0:09f915e6f9f6 272 {
andrewboyson 0:09f915e6f9f6 273 if (bytesRcvd <= EspIpdBufferLen[EspIpdId]) EspDataAvailable = ESP_AVAILABLE;
andrewboyson 0:09f915e6f9f6 274 else EspDataAvailable = ESP_OVERFLOW;
andrewboyson 0:09f915e6f9f6 275 state = IDLE;
andrewboyson 0:09f915e6f9f6 276 }
andrewboyson 0:09f915e6f9f6 277 break;
andrewboyson 0:09f915e6f9f6 278 case SEND_DATA:
andrewboyson 0:09f915e6f9f6 279 EspSendData(EspLengthToSend, EspDataToSend);
andrewboyson 0:09f915e6f9f6 280 state = IDLE;
andrewboyson 0:09f915e6f9f6 281 break;
andrewboyson 0:09f915e6f9f6 282 default:
andrewboyson 0:09f915e6f9f6 283 LogF("Unknown state %d\n\r", state);
andrewboyson 0:09f915e6f9f6 284 return -1;
andrewboyson 0:09f915e6f9f6 285 }
andrewboyson 0:09f915e6f9f6 286 return 0;
andrewboyson 0:09f915e6f9f6 287 }
andrewboyson 0:09f915e6f9f6 288 void sendAnyData()
andrewboyson 0:09f915e6f9f6 289 {
andrewboyson 0:09f915e6f9f6 290 while(esp.writeable())
andrewboyson 0:09f915e6f9f6 291 {
andrewboyson 0:09f915e6f9f6 292 int c = sendpull();
andrewboyson 0:09f915e6f9f6 293 if (c == EOF) break;
andrewboyson 0:09f915e6f9f6 294 esp.putc(c);
andrewboyson 0:09f915e6f9f6 295 }
andrewboyson 0:09f915e6f9f6 296 }
andrewboyson 0:09f915e6f9f6 297 int isTimeout()
andrewboyson 0:09f915e6f9f6 298 {
andrewboyson 0:09f915e6f9f6 299 static Timer receiveTimer;
andrewboyson 0:09f915e6f9f6 300
andrewboyson 0:09f915e6f9f6 301 if (state == IDLE)
andrewboyson 0:09f915e6f9f6 302 {
andrewboyson 0:09f915e6f9f6 303 receiveTimer.stop();
andrewboyson 0:09f915e6f9f6 304 receiveTimer.reset();
andrewboyson 0:09f915e6f9f6 305 }
andrewboyson 0:09f915e6f9f6 306 else
andrewboyson 0:09f915e6f9f6 307 {
andrewboyson 0:09f915e6f9f6 308 receiveTimer.start();
andrewboyson 0:09f915e6f9f6 309 if (receiveTimer.read_ms() > RECV_TIMEOUT_MS) return true;
andrewboyson 0:09f915e6f9f6 310 }
andrewboyson 0:09f915e6f9f6 311 return false;
andrewboyson 0:09f915e6f9f6 312 }
andrewboyson 0:09f915e6f9f6 313 int EspMain()
andrewboyson 0:09f915e6f9f6 314 {
andrewboyson 0:09f915e6f9f6 315 sendAnyData();
andrewboyson 0:09f915e6f9f6 316
andrewboyson 0:09f915e6f9f6 317 pulseResetPin();
andrewboyson 0:09f915e6f9f6 318
andrewboyson 0:09f915e6f9f6 319 //Reset line availability one shot
andrewboyson 0:09f915e6f9f6 320 EspLineAvailable = ESP_IDLE;
andrewboyson 0:09f915e6f9f6 321 EspDataAvailable = ESP_IDLE;
andrewboyson 0:09f915e6f9f6 322
andrewboyson 0:09f915e6f9f6 323 if (isTimeout())
andrewboyson 0:09f915e6f9f6 324 {
andrewboyson 0:09f915e6f9f6 325 if (state == IN_LINE) EspLineAvailable = ESP_TIMEOUT;
andrewboyson 0:09f915e6f9f6 326 else EspDataAvailable = ESP_TIMEOUT;
andrewboyson 0:09f915e6f9f6 327 state = IDLE;
andrewboyson 0:09f915e6f9f6 328 return 0;
andrewboyson 0:09f915e6f9f6 329 }
andrewboyson 0:09f915e6f9f6 330
andrewboyson 0:09f915e6f9f6 331 //Handle any incoming characters
andrewboyson 0:09f915e6f9f6 332 int c = recvpull();
andrewboyson 0:09f915e6f9f6 333 if (c != EOF)
andrewboyson 0:09f915e6f9f6 334 {
andrewboyson 0:09f915e6f9f6 335 LogPush(c);
andrewboyson 0:09f915e6f9f6 336 int r = handleCharacter(c); //This will set the EspAvailable one-shots
andrewboyson 0:09f915e6f9f6 337 if (r) return -1;
andrewboyson 0:09f915e6f9f6 338 }
andrewboyson 0:09f915e6f9f6 339
andrewboyson 0:09f915e6f9f6 340 return 0;
andrewboyson 0:09f915e6f9f6 341 }
andrewboyson 0:09f915e6f9f6 342
andrewboyson 0:09f915e6f9f6 343
andrewboyson 0:09f915e6f9f6 344