Official reference client implementation for Cumulocity SmartREST on u-blox C027.

Dependencies:   C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed

Fork of MbedSmartRestMain by Vincent Wochnik

Files at this revision

API Documentation at this revision

Comitter:
xinlei
Date:
Mon Aug 10 14:18:05 2015 +0000
Parent:
134:fb53a2e461b2
Child:
136:94add01b668c
Commit message:
various clean-ups

Changed in this revision

MbedAgent.cpp Show annotated file Show diff for this revision Revisions of this file
MbedSmartRest.lib Show annotated file Show diff for this revision Revisions of this file
io/GPSTracker.cpp Show annotated file Show diff for this revision Revisions of this file
operation/ControlParser.cpp Show annotated file Show diff for this revision Revisions of this file
operation/PollThread.cpp Show annotated file Show diff for this revision Revisions of this file
operation/ReportThread.cpp Show annotated file Show diff for this revision Revisions of this file
util/SmartRestConf.cpp Show annotated file Show diff for this revision Revisions of this file
util/lex.h Show annotated file Show diff for this revision Revisions of this file
--- a/MbedAgent.cpp	Fri Aug 07 12:55:27 2015 +0000
+++ b/MbedAgent.cpp	Mon Aug 10 14:18:05 2015 +0000
@@ -103,7 +103,7 @@
     while (true) {
         int l = 0;
         for (size_t i = 0; i < N; ++i) {
-//            if (reporters[i] == &gps) {
+//            if (reporters[i] == &ConfigSync::inst()) {
             int l2 = reporters[i]->read(buf2+l, sizeof(buf2)-l, status, DISPLAY_LEN);
             if (l2) { // Refresh LCD display needed
                 LCDDisplay::inst().setThirdLine(status);
--- a/MbedSmartRest.lib	Fri Aug 07 12:55:27 2015 +0000
+++ b/MbedSmartRest.lib	Mon Aug 10 14:18:05 2015 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/users/xinlei/code/MbedSmartRest/#b8a080f5e578
+http://developer.mbed.org/users/xinlei/code/MbedSmartRest/#9c36af176d91
--- a/io/GPSTracker.cpp	Fri Aug 07 12:55:27 2015 +0000
+++ b/io/GPSTracker.cpp	Mon Aug 10 14:18:05 2015 +0000
@@ -3,6 +3,7 @@
 #include "GPSTracker.h"
 #include "logging.h"
 
+
 GPSTracker::GPSTracker() :
     _gps(),
     _thread(GPSTracker::thread_func, this),
@@ -11,6 +12,7 @@
     _gps.init();
 }
 
+
 bool GPSTracker::position(GPSTracker::Position *position)
 {
     bool result = false;
@@ -26,6 +28,7 @@
     return result;
 }
 
+
 void GPSTracker::thread()
 {
     char buf[256], chr; // needs to be that big otherwise mdm isn't working
@@ -39,7 +42,7 @@
         }        
         len = LENGTH(ret);
         if ((PROTOCOL(ret) != GPSParser::NMEA) || (len <= 6)) {
-            aWarning("GPS data is not in NMEA protocol!\r\n");
+            aWarning("GPS data is not in NMEA protocol!\n");
             continue;
         }
 
@@ -67,6 +70,7 @@
     }
 }
 
+
 void GPSTracker::thread_func(void const *arg)
 {
     GPSTracker *that;
--- a/operation/ControlParser.cpp	Fri Aug 07 12:55:27 2015 +0000
+++ b/operation/ControlParser.cpp	Mon Aug 10 14:18:05 2015 +0000
@@ -6,6 +6,7 @@
 #include "ConfigSync.h"
 #include "logging.h"
 
+
 void ControlParser::parse(const char *buf)
 {
         if (buf == NULL) return;
@@ -19,6 +20,7 @@
         } while (*p);
 }
 
+
 void ControlParser::parseGetOp(Token& tok)
 {
         if (tok.type == Token::INT && strncmp("211", tok.p, tok.len)==0) {
@@ -29,6 +31,7 @@
         }
 }
 
+
 void ControlParser::parseRowNumber(Token& tok)
 {
         if (tok.type == Token::INT) {
@@ -43,22 +46,23 @@
         }
 }
 
+
 void ControlParser::parseOpId(Token& tok)
 {
         if (tok.type == Token::INT) {
                 if (opType == 211) {
                         sscanf(tok.p, "%ld", &op.identifier);
                         ptrPF = &ControlParser::parseOpState;
-                } else if (opType >= 220 && opType <= 222){
+                        return;
+                } else if (opType >= 220 && opType <= 222) {
                         ptrPF = &ControlParser::parseOpData;
-                } else {
-                        parseError(tok);
+                        return;
                 }
-        } else {
-                parseError(tok);
         }
+        parseError(tok);
 }
 
+
 void ControlParser::parseOpState(Token& tok)
 {
         if (tok.type == Token::STRING) {
@@ -70,28 +74,26 @@
                                 opool.put(p);
                         }
                         ptrPF = &ControlParser::parseOpType;
-                } else {
-                        parseError(tok);
+                        return;
                 }
-        } else {
-                parseError(tok);
         }
+        parseError(tok);
 }
 
+
 void ControlParser::parseOpType(Token& tok)
 {
         if (tok.type == Token::INT) {
                 sscanf(tok.p, "%hu", &opType);
                 if (opType >= 220 && opType <= 222) {
                         ptrPF = &ControlParser::parseRowNumber;
-                } else {
-                        parseError(tok);
+                        return;
                 }
-        } else {
-                parseError(tok);
         }
+        parseError(tok);
 }
 
+
 void ControlParser::parseOpData(Token& tok)
 {
         bool ret = true;
@@ -130,6 +132,7 @@
         ptrPF = &ControlParser::parseGetOpOrBayeuxAdvice;
 }
 
+
 void ControlParser::parseGetOpOrBayeuxAdvice(Token& tok)
 {
         if (strncmp("211", tok.p, tok.len) == 0) {
@@ -141,6 +144,7 @@
         }
 }
 
+
 void ControlParser::parseBayeuxAdvice(Token& tok)
 {
         if (strncmp("86", tok.p, tok.len) == 0) {
@@ -151,6 +155,7 @@
         }
 }
 
+
 void ControlParser::parseAdviceTimeout(Token& tok)
 {
         if (tok.type == Token::NONE) {
@@ -164,6 +169,7 @@
         }
 }
 
+
 void ControlParser::parseAdviceInterval(Token& tok)
 {
         if (tok.type == Token::NONE) {
@@ -177,6 +183,7 @@
         }
 }
 
+
 void ControlParser::parseAdvicePolicy(Token& tok)
 {
         if (tok.type == Token::STRING) {
@@ -194,12 +201,14 @@
         }
 }
 
+
 void ControlParser::parseError(Token& tok)
 {
         aError("CtrlParse: %.*s[%d]\n", (int)tok.len, tok.p, tok.type);
         parseRecover(tok);
 }
 
+
 void ControlParser::parseRecover(Token& tok)
 {
         if (tok.type == Token::INT) {
--- a/operation/PollThread.cpp	Fri Aug 07 12:55:27 2015 +0000
+++ b/operation/PollThread.cpp	Mon Aug 10 14:18:05 2015 +0000
@@ -3,6 +3,7 @@
 #include "PollThread.h"
 #include "logging.h"
 
+
 bool PollThread::handshake()
 {
         int l = snprintf(buf2, sizeof(buf2), "%s", "80\r\n");
@@ -20,6 +21,7 @@
         return bayeuxId[0];
 }
 
+
 bool PollThread::subscribe()
 {
         int l = snprintf(buf2, sizeof(buf2), "81,%s,%s\r\n", bayeuxId, chn);
@@ -33,6 +35,7 @@
         return *p == 0;
 }
 
+
 bool PollThread::connect()
 {
         int l = snprintf(buf2, sizeof(buf2), "83,%s\r\n", bayeuxId);
@@ -52,25 +55,20 @@
         }
         // Avoid heartbeat message overflows the buffer
         l = 0;
-        for (unsigned short i = 0; i < 200; ++i) {
+        for (unsigned short i = 0; i < 300; ++i) {
                 int l2 = sock.receive(buf+l, sizeof(buf)-l);
-                printf("l2: %d\n", l2);
                 if (l2 > 0) {
-                        printf("poll: %.*s\n", l2, buf+l);
                         l += l2;
-                } else if (!sock.is_connected()) {
-                        break;
                 } else {
-                        l = l2;
                         break;
                 }
         }
-        if (l >= 0)
-                buf[l] = 0;
         sock.close();
+        buf[l] = 0;
         return l>0;
 }
 
+
 void PollThread::threadFunc()
 {
         unsigned short state = 1;
@@ -87,10 +85,9 @@
                         }
                 case 3: if(!connect()) {
                                 aCritical("Poll: connect fail!\n");
-                                state = 1;
                                 break;
                         }
-                default: parser.parse(buf);
+                        parser.parse(buf);
                         if (parser.getBayeuxAdvice() == BA_HANDSHAKE)
                                 state = 1;
                         else
--- a/operation/ReportThread.cpp	Fri Aug 07 12:55:27 2015 +0000
+++ b/operation/ReportThread.cpp	Mon Aug 10 14:18:05 2015 +0000
@@ -35,9 +35,9 @@
                 if (l2 < 0) {
                     aError("Report: op state\n");
                     Thread::wait(3000);
-                } else
-                    aInfo("[SEND] report: %d\n", l2);
+                } else {
                     break;
+                }
             }
         }
     }
--- a/util/SmartRestConf.cpp	Fri Aug 07 12:55:27 2015 +0000
+++ b/util/SmartRestConf.cpp	Mon Aug 10 14:18:05 2015 +0000
@@ -10,8 +10,8 @@
 //const char *srX_ID = "com_cumulocity_MbedAgent_1.5.2";
 const char *srX_ID = NULL;
 const char *srHost = "developer.cumulocity.com";
-//const char *srHost = "dev-b.cumulocity.com";
-//const char *srHost = "dev-d.cumulocity.com";
+//const char *srHost = "dev-a.cumulocity.com";
+//const char *srHost = "dev-c.cumulocity.com";
 //const char *srHost = "management.m2m-devicecloud.com";
 long deviceID = 0;
 char fmtSmartRest[200] = {0};
--- a/util/lex.h	Fri Aug 07 12:55:27 2015 +0000
+++ b/util/lex.h	Mon Aug 10 14:18:05 2015 +0000
@@ -4,7 +4,7 @@
 
 struct Token
 {
-        enum TokType { 
+        enum TokType {
                 INT, FLOAT, STRING,
                 ASSIGN, SEMICOLON,
                 NONE, ERROR