Own fork of MbedSmartRestMain

Dependencies:   C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed

Fork of MbedSmartRestMain by Cumulocity Official

Committer:
xinlei
Date:
Thu May 07 09:57:55 2015 +0000
Revision:
98:e369fc75c000
Parent:
97:9f2de96941c4
Child:
100:dbcd3bc51758
prepare for v2.1rc3.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vwochnik 67:c360a2b2c948 1 #include <stdio.h>
vwochnik 67:c360a2b2c948 2 #include <string.h>
xinlei 96:ea056f6be2e8 3 #include "MDM.h"
vwochnik 67:c360a2b2c948 4
vwochnik 67:c360a2b2c948 5 #define PLATFORM_CREDENTIALS_FILE "001_CREDENTIALS"
vwochnik 68:0dc778a16d0d 6 #define CONFIGURATION_FILE "002_CONFIGURATION"
xinlei 96:ea056f6be2e8 7 extern MDMSerial *pMdm;
vwochnik 67:c360a2b2c948 8
xinlei 98:e369fc75c000 9 bool loadCredentials(char *username, char *password, size_t len)
vwochnik 67:c360a2b2c948 10 {
xinlei 98:e369fc75c000 11 char buffer[len*2+3];
xinlei 96:ea056f6be2e8 12 int res = pMdm->readFile(PLATFORM_CREDENTIALS_FILE, buffer, sizeof(buffer));
xinlei 93:61d44636f020 13 if (res < 0)
vwochnik 67:c360a2b2c948 14 return false;
xinlei 98:e369fc75c000 15 else {
xinlei 98:e369fc75c000 16 buffer[res] = 0;
xinlei 98:e369fc75c000 17 int len2 = sscanf(buffer, "%s\n%s\n", username, password);
xinlei 98:e369fc75c000 18 return res==len2;
xinlei 98:e369fc75c000 19 }
vwochnik 67:c360a2b2c948 20 }
vwochnik 67:c360a2b2c948 21
xinlei 98:e369fc75c000 22 bool delCredentials()
xinlei 97:9f2de96941c4 23 {
xinlei 97:9f2de96941c4 24 return pMdm->delFile(PLATFORM_CREDENTIALS_FILE);
xinlei 97:9f2de96941c4 25 }
xinlei 97:9f2de96941c4 26
xinlei 98:e369fc75c000 27 bool saveCredentials(char *username, char *password, size_t len)
vwochnik 67:c360a2b2c948 28 {
xinlei 93:61d44636f020 29 char buffer[len*2+3];
xinlei 93:61d44636f020 30 int res = snprintf(buffer, sizeof(buffer), "%s\n%s\n", username, password);
xinlei 98:e369fc75c000 31 delCredentials();
xinlei 98:e369fc75c000 32 return pMdm->writeFile(PLATFORM_CREDENTIALS_FILE, buffer, res)==res;
vwochnik 67:c360a2b2c948 33 }
vwochnik 68:0dc778a16d0d 34
xinlei 98:e369fc75c000 35 bool loadConfigFile(char *cfg, size_t len)
vwochnik 68:0dc778a16d0d 36 {
xinlei 96:ea056f6be2e8 37 int res = pMdm->readFile(CONFIGURATION_FILE, cfg, len);
xinlei 93:61d44636f020 38 if (res < 0)
vwochnik 68:0dc778a16d0d 39 return false;
xinlei 98:e369fc75c000 40 else {
xinlei 98:e369fc75c000 41 cfg[res] = 0;
xinlei 98:e369fc75c000 42 return true;
xinlei 98:e369fc75c000 43 }
vwochnik 68:0dc778a16d0d 44 }
vwochnik 68:0dc778a16d0d 45
xinlei 98:e369fc75c000 46 bool delConfigFile()
vwochnik 68:0dc778a16d0d 47 {
xinlei 96:ea056f6be2e8 48 return pMdm->delFile(CONFIGURATION_FILE);
vwochnik 68:0dc778a16d0d 49 }
xinlei 97:9f2de96941c4 50
xinlei 98:e369fc75c000 51 bool saveConfigFile(char *cfg, size_t len)
xinlei 97:9f2de96941c4 52 {
xinlei 98:e369fc75c000 53 delConfigFile();
xinlei 98:e369fc75c000 54 return pMdm->writeFile(CONFIGURATION_FILE, cfg, len)==len;
xinlei 97:9f2de96941c4 55 }