Own fork of MbedSmartRestMain
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
io/Storage.cpp
- Committer:
- xinlei
- Date:
- 2015-05-15
- Revision:
- 110:ee9ae4a5e55c
- Parent:
- 103:a3703ca4a4a4
- Child:
- 112:3872569be2af
File content as of revision 110:ee9ae4a5e55c:
#include <stdio.h> #include <string.h> #include "MDM.h" #define CREDENTIALS_FILE "001_CREDENTIALS" #define CONFIGURATION_FILE "002_CONFIGURATION" extern MDMSerial *pMdm; bool loadCredential(char *username, char *password, size_t len) { char buffer[len*2+3]; int res = pMdm->readFile(CREDENTIALS_FILE, buffer, sizeof(buffer)); if (res <= 0) { return false; } else { buffer[res] = 0; int l = sscanf(buffer, "%s\n%s\n", username, password); return l==2; } } bool resetCredential() { return pMdm->delFile(CREDENTIALS_FILE); } bool saveCredential(char *username, char *password, size_t len) { char buffer[len*2+3]; int res = snprintf(buffer, sizeof(buffer), "%s\n%s\n", username, password); pMdm->delFile(CREDENTIALS_FILE); return pMdm->writeFile(CREDENTIALS_FILE, buffer, res)==res; } int loadConfigFile(char *cfg, size_t len) { int res = pMdm->readFile(CONFIGURATION_FILE, cfg, len); if (res >= 0) cfg[res] = 0; return res; } bool saveConfigFile(char *cfg, size_t len) { pMdm->delFile(CONFIGURATION_FILE); return pMdm->writeFile(CONFIGURATION_FILE, cfg, len)==len; }