Own fork of C027_Support

Dependents:   MbedSmartRestMain MbedSmartRestMain

Fork of C027_Support by u-blox

Files at this revision

API Documentation at this revision

Comitter:
mazgch
Date:
Fri Dec 06 09:28:43 2013 +0000
Parent:
15:5eda64e5b9d1
Child:
17:296d94a006b4
Commit message:
Added parsing helpers for AT interface

Changed in this revision

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/SerialPipe.cpp	Fri Nov 22 08:23:30 2013 +0000
+++ b/SerialPipe.cpp	Fri Dec 06 09:28:43 2013 +0000
@@ -131,3 +131,38 @@
         buffer[0] = '\0';
     return WAIT;
 }
+
+int SerialPipeEx::getResp(char* buffer, int length)
+{
+    return getResp(buffer, length, &_pipeRx);
+}
+
+int SerialPipeEx::getResp(char* buffer, int length, Pipe<char>* pipe)
+{
+    int o = 0;
+    int i = 0;
+    int l = pipe->start();
+    static const char erTxt[] = "ERROR\r\n";
+    static const char okTxt[] = "OK\r\n"; 
+    int er = 0;
+    int ok = 0;
+    while ((i < pipe->size()) && (o < length))
+    {
+        int t = pipe->next();
+        i ++;
+        buffer[o++] = t;
+        ok = (t == okTxt[ok]) ? ok + 1 : 0;
+        er = (t == erTxt[er]) ? er + 1 : 0;
+        if ((okTxt[ok] == '\0') || (erTxt[er] == '\0'))
+        {
+            pipe->done();
+            if (length > o)
+                buffer[o] = '\0';
+            return o;
+        }
+    }
+    o = 0;
+    if (length > 0)
+        buffer[0] = '\0';
+    return WAIT;
+}
--- a/SerialPipe.h	Fri Nov 22 08:23:30 2013 +0000
+++ b/SerialPipe.h	Fri Dec 06 09:28:43 2013 +0000
@@ -36,4 +36,6 @@
     SerialPipeEx(PinName tx, PinName rx, int rxSize = 128, int txSize = 128);
     int getLine(char* buffer, int length);
     static int getLine(char* buffer, int length, Pipe<char>* pipe);
+    int getResp(char* buffer, int length);
+    static int getResp(char* buffer, int length, Pipe<char>* pipe);
 };