support library for C027 helper functions for Buffer Pipes, Buffered Serial Port (rtos capable) and GPS parsing. It includes modem APIs for USSD, SMS and Sockets.

Fork of C027_Support by u-blox

Revision:
9:e7a5959ffae1
Parent:
2:b6012cd91657
Child:
13:e2446fcdc246
--- a/SerialPipe.h	Sat Nov 09 13:31:49 2013 +0000
+++ b/SerialPipe.h	Sun Nov 10 16:39:42 2013 +0000
@@ -2,66 +2,34 @@
 
 #include "mbed.h"
 #include "Pipe.h"
-#include <ctype.h>
 
 class SerialPipe : public Serial
 {
-protected:
-    Pipe<char> _pipe;
+public:
+    SerialPipe(PinName tx, PinName rx, int rxSize = 128, int txSize = 128, const char* name = NULL);
+    virtual ~SerialPipe(void);
+    // tx channel
+    int put(const char* b, int s, bool t = false) ;
+    // rx channel
+    int readable(void);
+    int getc(void);
+    int get(char* b, int s, bool t = false);
 private:
-    void rxIrqBuf(void)
-    {
-        while (serial_readable(&_serial))
-            _pipe.putc(serial_getc(&_serial));
-    }
-public:
-    SerialPipe(PinName tx, PinName rx, int rxSize = 128, const char* name = NULL) 
-        : Serial(tx,rx,name), _pipe(rxSize)
-    {
-        attach(this, &SerialPipe::rxIrqBuf, RxIrq);
-    }
-    virtual ~SerialPipe(void)
-    {
-        attach(NULL, RxIrq);
-    }
-    // tx channel
-    int writeBuf(char* b, int s)    
-    { 
-        for (int i = 0; i < s; i ++)
-            putc(b[i]);
-        return s; 
-    }
-    // rx channel
-    int readable(void)              { return _pipe.readable() ? 1 : 0; } 
-    int getc(void)                  { return _pipe.getc(); } 
-    int readBuf(char* b, int s)     { return _pipe.get(b,s); }
+    void rxIrqBuf(void);
+    void txIrqBuf(void);
+protected:
+    Pipe<char> _pipeRx;
+    Pipe<char> _pipeTx;
+};
 
-    #define WAIT      -1
-    #define NOT_FOUND  0
+#define WAIT      -1
+#define NOT_FOUND  0
+
+// -----------------------------------------------------------------------
 
-    // special parsing
-    int getLine(char* b, int s)
-    {
-        int o = 0;
-        int i = 0;
-        int l = _pipe.start();
-        while ((i < l) && (o < s))
-        {
-            int t = _pipe.next();
-            i ++;
-            if (t == '\r')     // terminate commands with carriage return
-            {
-                 _pipe.done();
-                 return o;          // if enter send the zero char
-            }
-            else if (t == '\n')     // skip/filter new line 
-                 /* skip */;
-            else if (t != '\b')     // normal char (no backspace)
-                b[o++] = t;
-            else if (o > 0)         // backspace
-                o --;               // remove it
-        }
-        o = 0;
-        return WAIT;
-    }
+class SerialPipeEx : public SerialPipe
+{
+public:
+    SerialPipeEx(PinName tx, PinName rx, int rxSize = 128, int txSize = 128, const char* name = NULL);
+    int getLine(char* b, int s);
 };