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

Revision:
67:c360a2b2c948
Parent:
65:a62dbef2f924
Child:
71:063c45e99578
--- a/DeviceBootstrap.cpp	Thu Oct 30 14:46:22 2014 +0000
+++ b/DeviceBootstrap.cpp	Sun Nov 30 19:34:49 2014 +0000
@@ -8,11 +8,11 @@
 #include "IntegerValue.h"
 #include "ParsedRecord.h"
 
-DeviceBootstrap::DeviceBootstrap(AbstractSmartRest& client, MDMSerial& mdm, DeviceIO& io, DeviceInfo& deviceInfo) :
+DeviceBootstrap::DeviceBootstrap(AbstractSmartRest& client, DeviceIO& io, DeviceInfo& deviceInfo, DeviceMemory& deviceMemory) :
     _client(client),
-    _mdm(mdm),
     _io(io),
-    _deviceInfo(deviceInfo)
+    _deviceInfo(deviceInfo),
+    _deviceMemory(deviceMemory)
 {
     *_username = *_password = '\0';
 }
@@ -44,22 +44,7 @@
 
 bool DeviceBootstrap::obtainFromStorage()
 {
-    char buf[DEVICE_BOOTSTRAP_CREDENTIALS_LENGTH*2+2], *ptr;
-    
-    int res = _mdm.readFile(CREDENTIALS_FILE, buf, sizeof(buf));
-    if (res < 0)
-        return false;
-        
-    buf[res] = '\0';
-    if ((ptr = strchr(buf, '\n')) == NULL)
-        return false;
-    *ptr = '\0';
-    
-    ptr = buf;
-    strcpy(_username, ptr);
-    ptr += strlen(ptr)+1;
-    strcpy(_password, ptr);
-    return true;
+    return _deviceMemory.loadPlatformCredentials(_username, _password, DEVICE_BOOTSTRAP_CREDENTIALS_LENGTH);
 }
 
 bool DeviceBootstrap::obtainFromPlatform()
@@ -125,23 +110,7 @@
 
 bool DeviceBootstrap::writeToStorage()
 {
-    char buf[DEVICE_BOOTSTRAP_CREDENTIALS_LENGTH*2+2], *ptr;
-    size_t len;
-
-    ptr = buf;
-    len = strlen(_username);
-    strcpy(ptr, _username);
-    ptr += len;
-    
-    *ptr++ = '\n';
-    len++;
-    
-    len += strlen(_password);
-    strcpy(ptr, _password);
-    
-    _mdm.delFile(CREDENTIALS_FILE);
-    _mdm.writeFile(CREDENTIALS_FILE, buf, len);
-    return true;
+    return _deviceMemory.savePlatformCredentials(_username, _password, DEVICE_BOOTSTRAP_CREDENTIALS_LENGTH);
 }
 
 void DeviceBootstrap::setCredentials(const char *tenant, const char *username, const char *password)