Own fork of MbedSmartRestMain
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
io/DeviceMemory.cpp
- Committer:
- vwochnik
- Date:
- 2014-11-30
- Revision:
- 67:c360a2b2c948
- Child:
- 68:0dc778a16d0d
File content as of revision 67:c360a2b2c948:
#include "DeviceMemory.h" #include <stdlib.h> #include <stdio.h> #include <string.h> #define PLATFORM_CREDENTIALS_FILE "001_CREDENTIALS" DeviceMemory::DeviceMemory(MDMSerial& mdm) : _mdm(mdm) { } bool DeviceMemory::loadPlatformCredentials(char *username, char *password, size_t len) { char buffer[len*2+3]; int res, len2; if ((res = _mdm.readFile(PLATFORM_CREDENTIALS_FILE, buffer, sizeof(buffer))) < 0) return false; buffer[(size_t)res] = '\0'; sscanf(buffer, "%s\n%s\n%n", username, password, &len2); return res == len2; } bool DeviceMemory::savePlatformCredentials(char *username, char *password, size_t len) { char buffer[len*2+3]; int res; res = snprintf(buffer, sizeof(buffer), "%s\n%s\n", username, password); if ((res < 0) || (res >= sizeof(buffer))) return false; return res == _mdm.writeFile(PLATFORM_CREDENTIALS_FILE, buffer, res); } bool DeviceMemory::resetPlatformCredentials() { return _mdm.delFile(PLATFORM_CREDENTIALS_FILE); }