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

Files at this revision

API Documentation at this revision

Comitter:
mazgch
Date:
Tue Nov 19 08:34:51 2013 +0000
Parent:
12:684b31d5482b
Child:
14:69c3e57ef0f5
Commit message:
stable version

Changed in this revision

GPS.h Show annotated file Show diff for this revision Revisions of this file
Pipe.h Show annotated file Show diff for this revision Revisions of this file
SerialPipe.cpp Show annotated file Show diff for this revision Revisions of this file
SerialPipe.h Show annotated file Show diff for this revision Revisions of this file
--- a/GPS.h	Fri Nov 15 13:33:39 2013 +0000
+++ b/GPS.h	Tue Nov 19 08:34:51 2013 +0000
@@ -41,7 +41,6 @@
 public:
     GPSSerial(PinName tx = GPSTXD, PinName rx = GPSRXD, int baudrate = GPSBAUD,
               int rxSize = RX_SIZE, int txSize = TX_SIZE);
-    
     virtual int getMessage(char* buf, int len);
 protected:
     virtual char next(void);
--- a/Pipe.h	Fri Nov 15 13:33:39 2013 +0000
+++ b/Pipe.h	Tue Nov 19 08:34:51 2013 +0000
@@ -20,7 +20,7 @@
         _b = b ? b : _a;
         _s = n;
     }    
-    virtual ~Pipe()
+    virtual ~Pipe(void)
     {
         if (_a) 
             delete [] _a;
@@ -37,7 +37,7 @@
             s += _s;
         return s - 1;
     }
-    void putc(T c)
+    T putc(T c)
     {
         int i = _w;
         int j = i;
@@ -45,7 +45,8 @@
         while (i == _r) // = !writeable() 
             /*wait for space*/;
         _b[j] = c;
-        _w = i;   
+        _w = i; 
+        return c;
     }
     int put(const T* p, int n, bool t = false)
     {
--- a/SerialPipe.cpp	Fri Nov 15 13:33:39 2013 +0000
+++ b/SerialPipe.cpp	Tue Nov 19 08:34:51 2013 +0000
@@ -16,31 +16,53 @@
 }
 
 // tx channel
-int SerialPipe::put(const char* b, int n, bool t)    
+int SerialPipe::writeable(void)    
+{
+    return _pipeTx.free();
+}
+
+int SerialPipe::putc(int c)    
+{
+    return _putc(c);
+}
+
+int SerialPipe::put(const void* buffer, int length, bool blocking)    
 { 
-    int c = n;
-    while (c && t)
+    int count = length;
+    const char* ptr = (const char*)buffer;
+    while (count && blocking)
     {
-        int i = _pipeTx.put(b, c, false);
-        b += i;
-        c -= i;
-        // give a chance to start tx
-        __disable_irq();
-        txIrqBuf();
-        __enable_irq();
+        int written = _pipeTx.put(ptr, count, false);
+        ptr += written;
+        count -= written;
+        txStart();
     }
-    return (n - c);
+    return (length - count);
+}
+
+int SerialPipe::_putc(int c)    
+{
+    c = _pipeTx.putc(c);
+    txStart();
+    return c;
 }
 
 void SerialPipe::txIrqBuf(void)
 {
-    while (serial_writable(&_serial) && _pipeTx.readable())
+    while (Serial::writeable() && _pipeTx.readable())
     {
-        char ch = _pipeTx.getc();
-        serial_putc(&_serial, ch);
+        char c = _pipeTx.getc();
+        Serial::_putc(c);
     }
 }
 
+void SerialPipe::txStart(void)
+{
+    __disable_irq();
+    txIrqBuf();
+    __enable_irq();
+}
+
 // rx channel
 int SerialPipe::readable(void)                      
 { 
@@ -49,21 +71,26 @@
 
 int SerialPipe::getc(void)                          
 { 
+    return _getc(); 
+} 
+
+int SerialPipe::get(void* buffer, int length, bool blocking) 
+{ 
+    return _pipeRx.get((char*)buffer,length,blocking); 
+}
+
+int SerialPipe::_getc(void)                          
+{ 
     return _pipeRx.getc(); 
 } 
 
-int SerialPipe::get(char* b, int s, bool t) 
-{ 
-    return _pipeRx.get(b,s,t); 
-}
-
 void SerialPipe::rxIrqBuf(void)
 {
-    while (serial_readable(&_serial))
+    while (Serial::readable())
     {
-        char ch = serial_getc(&_serial);
+        char c = Serial::_getc();
         if (_pipeRx.writeable())
-            _pipeRx.putc(ch);
+            _pipeRx.putc(c);
         else 
             /* overflow */;
     }
@@ -75,31 +102,31 @@
     : SerialPipe(tx,rx,rxSize,txSize,name)
 {}
 
-int SerialPipeEx::getLine(char* b, int s)
+int SerialPipeEx::getLine(char* buffer, int length)
 {
     int o = 0;
     int i = 0;
     int l = _pipeRx.start();
-    while ((i < l) && (o < s))
+    while ((i < l) && (o < length))
     {
         int t = _pipeRx.next();
         i ++;
         if (t == '\r')     // terminate commands with carriage return
         {
             _pipeRx.done();
-            if (s > o)
-                b[o] = '\0';
+            if (length > o)
+                buffer[o] = '\0';
             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;
+            buffer[o++] = t;
         else if (o > 0)         // backspace
             o --;               // remove it
     }
     o = 0;
-    if (s > 0)
-        b[0] = '\0';
+    if (length > 0)
+        buffer[0] = '\0';
     return WAIT;
 }
--- a/SerialPipe.h	Fri Nov 15 13:33:39 2013 +0000
+++ b/SerialPipe.h	Tue Nov 19 08:34:51 2013 +0000
@@ -9,27 +9,30 @@
     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) ;
+    int writeable(void);
+    int putc(int c); // blocking
+    int put(const void* buffer, int length, bool blocking = false);
     // rx channel
     int readable(void);
-    int getc(void);
-    int get(char* b, int s, bool t = false);
-private:
+    int getc(void); // blocking
+    int get(void* buffer, int length, bool blocking = false);
+protected:
+    virtual int _getc();
+    virtual int _putc(int c);
     void rxIrqBuf(void);
     void txIrqBuf(void);
-protected:
+    void txStart(void);
     Pipe<char> _pipeRx;
     Pipe<char> _pipeTx;
 };
 
+// -----------------------------------------------------------------------
 #define WAIT      -1
 #define NOT_FOUND  0
 
-// -----------------------------------------------------------------------
-
 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);
+    int getLine(char* buffer, int length);
 };