Own fork of MbedSmartRestMain
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
io/DeviceMemory.cpp
- Committer:
- xinlei
- Date:
- 2015-04-27
- Revision:
- 97:9f2de96941c4
- Parent:
- 96:ea056f6be2e8
- Child:
- 98:e369fc75c000
File content as of revision 97:9f2de96941c4:
#include <stdio.h> #include <string.h> #include "MDM.h" #define PLATFORM_CREDENTIALS_FILE "001_CREDENTIALS" #define CONFIGURATION_FILE "002_CONFIGURATION" extern MDMSerial *pMdm; bool loadPlatformCredentials(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) return false; buffer[(size_t)res] = '\0'; int len2=0; sscanf(buffer, "%s\n%s\n%n", username, password, &len2); return res == len2; } 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 loadConfiguration(char *cfg, size_t len) { int res = pMdm->readFile(CONFIGURATION_FILE, cfg, len); if (res < 0) return false; cfg[(size_t)res] = '\0'; return true; } 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); }