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 Apr 27 13:30:21 2015 +0000
Parent:
97:ea056f6be2e8
Child:
99:e369fc75c000
Commit message:
Get rid of useless DeviceMemory class wrapper

Changed in this revision

DeviceBootstrap.cpp Show annotated file Show diff for this revision Revisions of this file
DeviceBootstrap.h Show annotated file Show diff for this revision Revisions of this file
MbedAgent.cpp Show annotated file Show diff for this revision Revisions of this file
MbedAgent.h Show annotated file Show diff for this revision Revisions of this file
config/ConfigurationSynchronization.cpp Show annotated file Show diff for this revision Revisions of this file
config/ConfigurationSynchronization.h Show annotated file Show diff for this revision Revisions of this file
io/DeviceMemory.cpp Show annotated file Show diff for this revision Revisions of this file
io/DeviceMemory.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/DeviceBootstrap.cpp	Mon Apr 27 13:02:50 2015 +0000
+++ b/DeviceBootstrap.cpp	Mon Apr 27 13:30:21 2015 +0000
@@ -3,6 +3,7 @@
 #include <string.h>
 #include "DeviceBootstrap.h"
 #include "rtos.h"
+#include "DeviceMemory.h"
 #include "LCDDisplay.h"
 #include "ComposedRecord.h"
 #include "CharValue.h"
@@ -12,10 +13,9 @@
 #include "logging.h"
 
 DeviceBootstrap::DeviceBootstrap(AbstractSmartRest& client,
-    DeviceInfo& deviceInfo, DeviceMemory& deviceMemory) :
+    DeviceInfo& deviceInfo) :
     _client(client),
-    _deviceInfo(deviceInfo),
-    _deviceMemory(deviceMemory)
+    _deviceInfo(deviceInfo)
 {
     *_username = *_password = '\0';
 }
@@ -44,7 +44,7 @@
 
 bool DeviceBootstrap::obtainFromStorage()
 {
-    return _deviceMemory.loadPlatformCredentials(_username, _password, DEVICE_BOOTSTRAP_CREDENTIALS_LENGTH);
+    return loadPlatformCredentials(_username, _password, DEVICE_BOOTSTRAP_CREDENTIALS_LENGTH);
 }
 
 bool DeviceBootstrap::obtainFromPlatform()
@@ -99,7 +99,7 @@
 
 bool DeviceBootstrap::writeToStorage()
 {
-    return _deviceMemory.savePlatformCredentials(_username, _password, DEVICE_BOOTSTRAP_CREDENTIALS_LENGTH);
+    return savePlatformCredentials(_username, _password, DEVICE_BOOTSTRAP_CREDENTIALS_LENGTH);
 }
 
 void DeviceBootstrap::setCredentials(const char *tenant, const char *username, const char *password)
--- a/DeviceBootstrap.h	Mon Apr 27 13:02:50 2015 +0000
+++ b/DeviceBootstrap.h	Mon Apr 27 13:30:21 2015 +0000
@@ -2,7 +2,6 @@
 #define DEVICEBOOTSTRAP_H
 
 #include <stddef.h>
-#include "DeviceMemory.h"
 #include "AbstractSmartRest.h"
 #include "DeviceInfo.h"
 
@@ -17,8 +16,8 @@
 class DeviceBootstrap
 {
 public:
-    DeviceBootstrap(AbstractSmartRest&, DeviceInfo&, DeviceMemory&);
-    
+    DeviceBootstrap(AbstractSmartRest&, DeviceInfo&);
+
     bool setUpCredentials();
     const char * username();
     const char * password();
@@ -34,7 +33,6 @@
 private:
     AbstractSmartRest& _client;
     DeviceInfo& _deviceInfo;
-    DeviceMemory& _deviceMemory;
     char _username[DEVICE_BOOTSTRAP_CREDENTIALS_LENGTH];
     char _password[DEVICE_BOOTSTRAP_CREDENTIALS_LENGTH];
 };
--- a/MbedAgent.cpp	Mon Apr 27 13:02:50 2015 +0000
+++ b/MbedAgent.cpp	Mon Apr 27 13:30:21 2015 +0000
@@ -4,13 +4,12 @@
 #include "logging.h"
 #include "watchdog.h"
 
-MbedAgent::MbedAgent(GPSI2C& gps, DeviceInfo& deviceInfo,
-    DeviceMemory& deviceMemory) :
+MbedAgent::MbedAgent(GPSI2C& gps, DeviceInfo& deviceInfo):
     _deviceId(0),
     _client(),
-    _bootstrap(_client, deviceInfo, deviceMemory),
+    _bootstrap(_client, deviceInfo),
     _integration(_client, _tpl, _deviceId, deviceInfo),
-    _configurationSynchronization(_client, _tpl, _deviceId, deviceMemory),
+    _configurationSynchronization(_client, _tpl, _deviceId),
     _signalQualityMeasurement(_client, _tpl, _deviceId, deviceInfo),
     _temperatureMeasurement(_client, _tpl, _deviceId, deviceInfo),
     _accelerationMeasurement(_client, _tpl, _deviceId, deviceInfo),
--- a/MbedAgent.h	Mon Apr 27 13:02:50 2015 +0000
+++ b/MbedAgent.h	Mon Apr 27 13:30:21 2015 +0000
@@ -5,7 +5,6 @@
 #include "SmartRest.h"
 #include "SmartRestTemplate.h"
 #include "DeviceInfo.h"
-#include "DeviceMemory.h"
 #include "DeviceBootstrap.h"
 #include "DeviceIntegration.h"
 #include "ConfigurationSynchronization.h"
@@ -22,7 +21,7 @@
 class MbedAgent
 {
 public:
-    MbedAgent(GPSI2C&, DeviceInfo&, DeviceMemory&);
+    MbedAgent(GPSI2C&, DeviceInfo&);
 
     bool init();
     int run();
--- a/config/ConfigurationSynchronization.cpp	Mon Apr 27 13:02:50 2015 +0000
+++ b/config/ConfigurationSynchronization.cpp	Mon Apr 27 13:30:21 2015 +0000
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include "ConfigurationSynchronization.h"
+#include "DeviceMemory.h"
 #include "ComposedRecord.h"
 #include "CharValue.h"
 #include "IntegerValue.h"
@@ -7,12 +8,11 @@
 
 ConfigurationSynchronization::ConfigurationSynchronization(
     AbstractSmartRest& client, SmartRestTemplate& tpl,
-    long& deviceId, DeviceMemory& deviceMemory) :
+    long& deviceId) :
     _init (false),
     _changed (false),
     _tpl(tpl),
     _client(client),
-    _deviceMemory(deviceMemory),
     _deviceId(deviceId),
     _deviceConfiguration(),
     _configurationProperties(_deviceConfiguration)
@@ -119,7 +119,7 @@
 {
     char buf[256];
     
-    if (!_deviceMemory.loadConfiguration(buf, sizeof(buf))) {
+    if (!::loadConfiguration(buf, sizeof(buf))) {
         aError("Load device config.\n");
         return false;
     }
@@ -138,7 +138,7 @@
         aError("Write device config.\n");
         return false;
     }
-    if (!_deviceMemory.saveConfiguration(buf)) {
+    if (!::saveConfiguration(buf)) {
         aError("Save device config.\n");
         return false;
     }
--- a/config/ConfigurationSynchronization.h	Mon Apr 27 13:02:50 2015 +0000
+++ b/config/ConfigurationSynchronization.h	Mon Apr 27 13:30:21 2015 +0000
@@ -3,13 +3,12 @@
 
 #include "AbstractSmartRest.h"
 #include "SmartRestTemplate.h"
-#include "DeviceMemory.h"
 #include "ConfigurationProperties.h"
 
 class ConfigurationSynchronization
 {
 public:
-    ConfigurationSynchronization(AbstractSmartRest&, SmartRestTemplate&, long&, DeviceMemory&);
+    ConfigurationSynchronization(AbstractSmartRest&, SmartRestTemplate&, long&);
     
     bool init();
     bool integrate();
@@ -27,7 +26,6 @@
     bool _changed;
     SmartRestTemplate& _tpl;
     AbstractSmartRest& _client;
-    DeviceMemory& _deviceMemory;
     long& _deviceId;
     DeviceConfiguration _deviceConfiguration;
     ConfigurationProperties _configurationProperties;
--- a/io/DeviceMemory.cpp	Mon Apr 27 13:02:50 2015 +0000
+++ b/io/DeviceMemory.cpp	Mon Apr 27 13:30:21 2015 +0000
@@ -1,14 +1,12 @@
-#include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include "MDM.h"
-#include "DeviceMemory.h"
 
 #define PLATFORM_CREDENTIALS_FILE "001_CREDENTIALS"
 #define CONFIGURATION_FILE "002_CONFIGURATION"
 extern MDMSerial *pMdm;
 
-bool DeviceMemory::loadPlatformCredentials(char *username, char *password, size_t len)
+bool loadPlatformCredentials(char *username, char *password, size_t len)
 {
     char buffer[len*2+3]; 
     int res = pMdm->readFile(PLATFORM_CREDENTIALS_FILE, buffer, sizeof(buffer));
@@ -21,23 +19,24 @@
     return res == len2;
 }
 
-bool DeviceMemory::savePlatformCredentials(char *username, char *password, size_t len)
+bool resetPlatformCredentials()
+{
+    return pMdm->delFile(PLATFORM_CREDENTIALS_FILE);
+}
+
+bool savePlatformCredentials(char *username, char *password, size_t len)
 {
     char buffer[len*2+3]; 
     int res = snprintf(buffer, sizeof(buffer), "%s\n%s\n", username, password);
     if (res<0 || res>=sizeof(buffer))
         return false;
 
-    return ((resetPlatformCredentials()) && (res == pMdm->writeFile(PLATFORM_CREDENTIALS_FILE, buffer, res)));
-}
-
-bool DeviceMemory::resetPlatformCredentials()
-{
-    return pMdm->delFile(PLATFORM_CREDENTIALS_FILE);
+    return (resetPlatformCredentials() && res==pMdm->writeFile(PLATFORM_CREDENTIALS_FILE, buffer, res));
 }
 
 
-bool DeviceMemory::loadConfiguration(char *cfg, size_t len)
+
+bool loadConfiguration(char *cfg, size_t len)
 {
     int res = pMdm->readFile(CONFIGURATION_FILE, cfg, len);
     if (res < 0)
@@ -47,13 +46,14 @@
     return true;
 }
 
-bool DeviceMemory::saveConfiguration(char *cfg)
-{
-    size_t len = strlen(cfg);
-    return ((resetConfiguration()) && (pMdm->writeFile(CONFIGURATION_FILE, cfg, len) == len));
-}
-
-bool DeviceMemory::resetConfiguration()
+bool resetConfiguration()
 {
     return pMdm->delFile(CONFIGURATION_FILE);
 }
+
+bool saveConfiguration(char *cfg)
+{
+    size_t len = strlen(cfg);
+    return (resetConfiguration() && pMdm->writeFile(CONFIGURATION_FILE, cfg, len)==len);
+}
+
--- a/io/DeviceMemory.h	Mon Apr 27 13:02:50 2015 +0000
+++ b/io/DeviceMemory.h	Mon Apr 27 13:30:21 2015 +0000
@@ -3,33 +3,22 @@
 
 #include <stddef.h>
 
-/**
- * Device Memory storage handler
- */
-class DeviceMemory
-{
-public:
-    DeviceMemory() {}
-    
-    /** loads credentials from persistent memory */
-    bool loadPlatformCredentials(char*, char*, size_t);
-    
-    /** saves credentials to persistent memory */
-    bool savePlatformCredentials(char*, char*, size_t);
-    
-    /** removes credentials from persistent memory */
-    bool resetPlatformCredentials();
-    
-    /** loads configuration from persistent memory */
-    bool loadConfiguration(char*, size_t);
-    
-    /** saves configuration to persistent memory */
-    bool saveConfiguration(char*);
-    
-    /** removes configuration from persistent memory */
-    bool resetConfiguration();
+/** loads credentials from persistent memory */
+bool loadPlatformCredentials(char*, char*, size_t);
+
+/** saves credentials to persistent memory */
+bool savePlatformCredentials(char*, char*, size_t);
+
+/** removes credentials from persistent memory */
+bool resetPlatformCredentials();
 
-private:
-};
+/** loads configuration from persistent memory */
+bool loadConfiguration(char*, size_t);
+
+/** saves configuration to persistent memory */
+bool saveConfiguration(char*);
+
+/** removes configuration from persistent memory */
+bool resetConfiguration();
 
 #endif
\ No newline at end of file
--- a/main.cpp	Mon Apr 27 13:02:50 2015 +0000
+++ b/main.cpp	Mon Apr 27 13:30:21 2015 +0000
@@ -73,12 +73,11 @@
     joystickUp.rise(&enableDebug);
     joystickDown.rise(&disableDebug);
 
-    DeviceMemory deviceMemory;
     DigitalIn fireButton(D4);
 
     if (fireButton) {
         LCDDisplay::inst().setLines("Factory Reset");
-        if (deviceMemory.resetPlatformCredentials()) {
+        if (resetPlatformCredentials()) {
             LCDDisplay::inst().setLines("Reset Success");
         } else {
             LCDDisplay::inst().setLines("Reset Failure");
@@ -116,7 +115,7 @@
 
     {
         DeviceInfo deviceInfo(devStatus);
-        MbedAgent agent(gps, deviceInfo, deviceMemory);
+        MbedAgent agent(gps, deviceInfo);
 
         LCDDisplay::inst().setLines("Agent Init");
         if (!agent.init()) {