Backing up an unused program in case of future need

Dependencies:   mbed

Revision:
3:accba7e07a0d
Parent:
2:06fa34661f19
Child:
4:e076884ef8bd
--- a/esp.cpp	Fri Apr 22 09:23:57 2016 +0000
+++ b/esp.cpp	Sat Apr 23 20:00:04 2016 +0000
@@ -3,11 +3,9 @@
 #include  "esp.h"
 #include   "io.h"
 #include  "cfg.h"
-#include <stdarg.h>
-
+#include "uart.h"
 
 #define RECV_TIMEOUT_MS 5000
-static RawSerial esp(p9, p10); // tx, rx
 
 //State
 #define LINE_LENGTH 256
@@ -75,50 +73,6 @@
 int   EspIpdId;
 int   EspDataAvailable;
 
-//Wrap around buffers
-//===================
-#define RECV_BUFFER_LENGTH 1024
-#define SEND_BUFFER_LENGTH 1024
-static char recvbuffer[RECV_BUFFER_LENGTH];
-static char sendbuffer[SEND_BUFFER_LENGTH];
-static char* pRecvPush; //Initialised in init
-static char* pRecvPull; //Initialised in init
-static char* pSendPush; //Initialised in init
-static char* pSendPull; //Initialised in init
-
-static void incrementPushPullPointer(char** pp, char* pbuffer, int bufferlength)
-{
-    ++*pp; //increment the pointer by one
-    if (*pp == pbuffer + bufferlength) *pp = pbuffer; //if the pointer is now beyond the end then point it back to the start
-}
-static void recvpush(void) //Called by the esp data received interrupt
-{
-    while (esp.readable())
-    {
-        int c = esp.getc();
-        *pRecvPush = c;
-        incrementPushPullPointer(&pRecvPush, recvbuffer, RECV_BUFFER_LENGTH);
-    }
-}
-static int recvpull(void) //Called every scan. Returns the next byte or EOF if no more are available
-{
-    if (pRecvPull == pRecvPush) return EOF;
-    char c = *pRecvPull;
-    incrementPushPullPointer(&pRecvPull, recvbuffer, RECV_BUFFER_LENGTH); 
-    return c;
-}
-static void sendpush(char c) //Called whenever something needs to be sent
-{
-    *pSendPush = c;
-    incrementPushPullPointer(&pSendPush, sendbuffer, SEND_BUFFER_LENGTH);
-}
-static int sendpull(void) //Called every scan. Returns the next byte or EOF if no more are available
-{
-    if (pSendPull == pSendPush) return EOF;
-    char c = *pSendPull;
-    incrementPushPullPointer(&pSendPull, sendbuffer, SEND_BUFFER_LENGTH);
-    return c;
-}
 
 //Stuff to send
 //=============
@@ -137,15 +91,18 @@
 }
 void EspSendString(char* p)
 {
-    pRespNext = EspResp;
+    //Reset the response buffer
+    pRespNext = EspResp; 
     *pRespNext = '\0';
-    while(*p) sendpush(*p++);
+    
+    //Send the string
+    while(*p) UartSendPush(*p++);
 }
 void EspSendData(int length, const void * snd)
 {
     const char* p = (char*)snd;
     const char* e = (char*)snd + length;
-    while (p < e) sendpush(*p++);
+    while (p < e) UartSendPush(*p++);
 }
 
 
@@ -156,10 +113,7 @@
 void EspResetAndStop()
 {
     reset = true;
-    pRecvPush = recvbuffer;
-    pRecvPull = recvbuffer;
-    pSendPush = sendbuffer;
-    pSendPull = sendbuffer;
+    UartReset();
     pLineNext = EspLine;
     *pLineNext = '\0';
     pRespNext = EspResp;
@@ -196,8 +150,7 @@
 int EspInit()
 {
     EspResetAndStop();
-    esp.attach(&recvpush, Serial::RxIrq);
-    esp.baud(CfgBaud);
+    UartBaud(CfgBaud);
     for (int i = 0; i < 4; i++)
     {
         EspIpdBuffer[i] = NULL;
@@ -206,10 +159,6 @@
     }
     return 0;
 }
-void EspBaud(int baud)
-{
-    esp.baud(baud);
-}
 
 //Main loop zone
 int handleCharacter(char c)
@@ -310,15 +259,6 @@
     }
     return 0;
 }
-void sendAnyData()
-{
-    while(esp.writeable())
-    {
-        int c = sendpull();
-        if (c == EOF) break;
-        esp.putc(c);
-    }
-}
 int isTimeout()
 {
     static Timer receiveTimer;
@@ -337,7 +277,6 @@
 }
 int EspMain()
 {
-    sendAnyData();
     
     pulseResetPin();
     
@@ -354,7 +293,7 @@
     }
     
     //Handle any incoming characters
-    int c = recvpull();
+    int c = UartRecvPull();
     if (c != EOF)
     {
         LogPush(c);