Own fork of MbedSmartRestMain

Dependencies:   C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed

Fork of MbedSmartRestMain by Cumulocity Official

Revision:
100:dbcd3bc51758
Parent:
98:e369fc75c000
Child:
102:ede6611e064e
diff -r 47ea098f8a47 -r dbcd3bc51758 io/DeviceMemory.cpp
--- a/io/DeviceMemory.cpp	Thu May 07 13:56:19 2015 +0000
+++ b/io/DeviceMemory.cpp	Fri May 08 12:19:57 2015 +0000
@@ -2,45 +2,46 @@
 #include <string.h>
 #include "MDM.h"
 
-#define PLATFORM_CREDENTIALS_FILE "001_CREDENTIALS"
+#define CREDENTIALS_FILE "001_CREDENTIALS"
 #define CONFIGURATION_FILE "002_CONFIGURATION"
 extern MDMSerial *pMdm;
 
-bool loadCredentials(char *username, char *password, size_t len)
+bool loadCredential(char *username, char *password, size_t len)
 {
     char buffer[len*2+3];
-    int res = pMdm->readFile(PLATFORM_CREDENTIALS_FILE, buffer, sizeof(buffer));
-    if (res < 0)
+    int res = pMdm->readFile(CREDENTIALS_FILE, buffer, sizeof(buffer));
+    if (res < 0) {
+        printf("Load credentials.\n");
         return false;
-    else {
+    } else {
         buffer[res] = 0;
-        int len2 = sscanf(buffer, "%s\n%s\n", username, password);
-        return res==len2;
+        int l = 0;
+        sscanf(buffer, "%s\n%s\n%n", username, password, &l);
+        printf("%d:%d\nload: %s\n", res, l, buffer);
+        return res==l;
     }
 }
 
-bool delCredentials()
+bool delCredential()
 {
-    return pMdm->delFile(PLATFORM_CREDENTIALS_FILE);
+    return pMdm->delFile(CREDENTIALS_FILE);
 }
 
-bool saveCredentials(char *username, char *password, size_t len)
+bool saveCredential(char *username, char *password, size_t len)
 {
-    char buffer[len*2+3]; 
+    char buffer[len*2+3];
     int res = snprintf(buffer, sizeof(buffer), "%s\n%s\n", username, password);
-    delCredentials();
-    return pMdm->writeFile(PLATFORM_CREDENTIALS_FILE, buffer, res)==res;
+    printf("save: %s\n", buffer);
+    delCredential();
+    return pMdm->writeFile(CREDENTIALS_FILE, buffer, res)==res;
 }
 
-bool loadConfigFile(char *cfg, size_t len)
+int loadConfigFile(char *cfg, size_t len)
 {
     int res = pMdm->readFile(CONFIGURATION_FILE, cfg, len);
-    if (res < 0)
-        return false;
-    else {
+    if (res >= 0)
         cfg[res] = 0;
-        return true;
-    }
+    return res;
 }
 
 bool delConfigFile()