Andrew Boyson
/
iot
Backing up an unused program in case of future need
Diff: esp.cpp
- Revision:
- 4:e076884ef8bd
- Parent:
- 3:accba7e07a0d
- Child:
- 6:be97d38e0b01
--- a/esp.cpp Sat Apr 23 20:00:04 2016 +0000 +++ b/esp.cpp Tue May 03 09:23:26 2016 +0000 @@ -23,9 +23,10 @@ char EspLine[LINE_LENGTH]; static char* pLineNext; //Initialised in init to EspLine -#define RESP_LENGTH 256 -char EspResp[RESP_LENGTH]; -static char* pRespNext; //Initialised at each request to EspResp +static char* pRespBuff; +static int lenRespBuff; +static char* pRespNext; //Initialised at each request to send a string + static int addRawCharToBuffer(char* pBuff, char** ppNext, int len, char c) { @@ -60,8 +61,8 @@ } static int addChar(char c) { - int r = addCharToBuffer(EspLine, &pLineNext, LINE_LENGTH, c, false); - addCharToBuffer(EspResp, &pRespNext, RESP_LENGTH, c, true ); + int r = addCharToBuffer(EspLine, &pLineNext, LINE_LENGTH, c, false); + addCharToBuffer(pRespBuff, &pRespNext, lenRespBuff, c, true ); return r; } //Unsolicited ntp or http requests @@ -79,7 +80,7 @@ int EspLengthToSend; const void * EspDataToSend; -void EspSendStringF(char *fmt, ...) +void EspSendStringF(char* respbuff, int resplen, char *fmt, ...) { va_list argptr; va_start(argptr, fmt); @@ -87,13 +88,15 @@ char snd[size + 1]; vsprintf(snd, fmt, argptr); va_end(argptr); - EspSendString(snd); + EspSendString(respbuff, resplen, snd); } -void EspSendString(char* p) +void EspSendString(char* respbuff, int resplen, char* p) { //Reset the response buffer - pRespNext = EspResp; - *pRespNext = '\0'; + pRespBuff = respbuff; + pRespNext = respbuff; + lenRespBuff = resplen; + *pRespNext = '\0'; //Send the string while(*p) UartSendPush(*p++); @@ -116,8 +119,9 @@ UartReset(); pLineNext = EspLine; *pLineNext = '\0'; - pRespNext = EspResp; - *pRespNext = '\0'; + pRespBuff = NULL; + *pRespNext = NULL; + lenRespBuff = 0; EspLengthToSend = 0; EspDataToSend = NULL; state = IDLE;