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:
Wed Apr 22 11:22:25 2015 +0000
Parent:
94:61d44636f020
Child:
96:5dfdc8568e9f
Commit message:
v2.1rc2

Changed in this revision

MbedAgent.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/ControlParser.h Show annotated file Show diff for this revision Revisions of this file
operation/Opeartion.cpp Show annotated file Show diff for this revision Revisions of this file
operation/Operation.h 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	Mon Apr 20 15:04:23 2015 +0000
+++ b/MbedAgent.cpp	Wed Apr 22 11:22:25 2015 +0000
@@ -106,13 +106,13 @@
     Watchdog wdt;
     wdt.kick(60.0);    // set a 60.0 seconds timeout on watchdog hardware timer
     while (true) {
-//        _configurationSynchronization.run();
-//        _analogMeasurement.run();
-//        _signalQualityMeasurement.run();
-//        _temperatureMeasurement.run();
-//        _accelerationMeasurement.run();
-//        _locationUpdate.run();
-        Thread::wait(30000);
+        _configurationSynchronization.run();
+        _analogMeasurement.run();
+        _signalQualityMeasurement.run();
+        _temperatureMeasurement.run();
+        _accelerationMeasurement.run();
+        _locationUpdate.run();
+//        Thread::wait(30000);
 //        if ((interval = _configurationProperties.readInterval()) < 0)
 //            break;
 //        while (timer.read() < interval) {
--- a/operation/ControlParser.cpp	Mon Apr 20 15:04:23 2015 +0000
+++ b/operation/ControlParser.cpp	Wed Apr 22 11:22:25 2015 +0000
@@ -71,7 +71,7 @@
 void ControlParser::parseOpType(Token& tok)
 {
         if (tok.type == Token::INT) {
-                sscanf(tok.p, "%u", &opType);
+                sscanf(tok.p, "%hu", &opType);
                 if (opType >= 220 && opType <= 222) {
                         ptrPF = &ControlParser::parseDeviceId;
                 } else {
@@ -103,7 +103,7 @@
                         strncpy(line, tok.p, num);
                 _lcdDisplay.setFirstLine(line);
         } else if (opType == 222) {
-                char config[128];
+                char config[128] = {0};
                 size_t num = tok.len<128 ? tok.len : 128;
                 strncpy(config, tok.p, num);
                 ret = _configSync.updateConfiguration(config);
@@ -112,9 +112,11 @@
                 return;
         }
         Operation *p = opool.alloc();
-        p->identifier = op.identifier;
-        p->state = ret ? OPERATION_SUCCESSFUL : OPERATION_FAILED;
-        opool.put(p);
+        if (p) {
+                p->identifier = op.identifier;
+                p->state = ret ? OPERATION_SUCCESSFUL : OPERATION_FAILED;
+                opool.put(p);
+        }
         ptrPF = &ControlParser::parseGetOpOrBayeuxAdvice;
 }
 
--- a/operation/ControlParser.h	Mon Apr 20 15:04:23 2015 +0000
+++ b/operation/ControlParser.h	Wed Apr 22 11:22:25 2015 +0000
@@ -38,7 +38,7 @@
         void parseRecover(Token& tok);
         void parseUnknownInt(Token& tok);
 private:
-        uint8_t opType;
+        unsigned short opType;
         Operation op;
         BayeuxAdvice bayeuxAdvice;
         int bayeuxTimeout;
--- a/operation/Opeartion.cpp	Mon Apr 20 15:04:23 2015 +0000
+++ b/operation/Opeartion.cpp	Wed Apr 22 11:22:25 2015 +0000
@@ -1,9 +1,9 @@
 #include "Operation.h"
 
-const char strPending[] = "PENDING";
-const char strExecuting[] = "EXECUTING";
-const char strSuccessful[] = "SUCCESSFUL";
-const char strFailed[] = "FAILED";
+const char *strPending = "PENDING";
+const char *strExecuting = "EXECUTING";
+const char *strSuccessful = "SUCCESSFUL";
+const char *strFailed = "FAILED";
 
 const char* strOperationState(OperationState state)
 {
--- a/operation/Operation.h	Mon Apr 20 15:04:23 2015 +0000
+++ b/operation/Operation.h	Wed Apr 22 11:22:25 2015 +0000
@@ -18,9 +18,9 @@
 typedef Mail<Operation, POOL_SIZE> OperationPool;
 
 const char* strOperationState(OperationState state);
-extern const char strPending[];
-extern const char strExecuting[];
-extern const char strSuccessful[];
-extern const char strFailed[];
+extern const char *strPending;
+extern const char *strExecuting;
+extern const char *strSuccessful;
+extern const char *strFailed;
 
 #endif
--- a/operation/ReportThread.cpp	Mon Apr 20 15:04:23 2015 +0000
+++ b/operation/ReportThread.cpp	Wed Apr 22 11:22:25 2015 +0000
@@ -1,7 +1,7 @@
 #include "ReportThread.h"
 #include "logging.h"
 
-const char fmt2[] = "111,%ld,%s\r\n";
+const char *fmt2 = "111,%ld,%s\r\n";
 
 void ReportThread::threadFunc()
 {
@@ -13,10 +13,22 @@
             OperationState state = op->state;
             ipool.free(op);
             int l = snprintf(buf2, sizeof(buf2), fmt2, id, strOperationState(state));
+            for (unsigned short i = 0; i < 10; ++i) {
+                osEvent e = ipool.get(200);
+                if (e.status == osEventMail) {
+                    op = (Operation*)e.value.p;
+                    id = op->identifier;
+                    OperationState state = op->state;
+                    ipool.free(op);
+                    l += snprintf(buf2+l, SMARRESTBODY_SIZE-l, fmt2, id, strOperationState(state));
+                } else {
+                    break;
+                }
+            }
             l = snprintf(buf, sizeof(buf), getSmartRestFmt(), uri, l, buf2);
             l = sock.sendOnly(buf, l);
             if (l < 0) {
-                    aError("Report: <%ld, %s>\n", id, strOperationState(state));
+                aError("Report: <%ld, %s>\n", id, strOperationState(state));
             }
         }
     }
--- a/util/SmartRestConf.cpp	Mon Apr 20 15:04:23 2015 +0000
+++ b/util/SmartRestConf.cpp	Wed Apr 22 11:22:25 2015 +0000
@@ -2,12 +2,12 @@
 #include <stdio.h>
 #include "b64.h"
 
-const char* _username = NULL;
-const char* _password = NULL;
+const char *_username = NULL;
+const char *_password = NULL;
 char _authStr[100] = {0};
 const char *_identifier = "com_cumulocity_MbedAgent_1.5.2";
-const char _host[] = "developer.cumulocity.com";
-// const char _host[] = "management.m2m-devicecloud.com"
+const char *_host = "developer.cumulocity.com";
+// const char *_host = "management.m2m-devicecloud.com"
 const int _port = 80;
 char fmtSmartRest[200] = {0};
 
--- a/util/lex.h	Mon Apr 20 15:04:23 2015 +0000
+++ b/util/lex.h	Wed Apr 22 11:22:25 2015 +0000
@@ -4,7 +4,7 @@
 
 struct Token
 {
-        enum TokType{
+        enum TokType {
                 INT,
                 FLOAT,
                 STRING,