
Own fork of MbedSmartRestMain
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
Revision 96:ea056f6be2e8, committed 2015-04-27
- Comitter:
- xinlei
- Date:
- Mon Apr 27 13:02:50 2015 +0000
- Parent:
- 95:5dfdc8568e9f
- Child:
- 97:9f2de96941c4
- Commit message:
- MDMSerial now singleton
Changed in this revision
--- a/DeviceInfo.cpp Mon Apr 27 10:50:21 2015 +0000 +++ b/DeviceInfo.cpp Mon Apr 27 13:02:50 2015 +0000 @@ -3,8 +3,7 @@ #include "DeviceInfo.h" #include "logging.h" -DeviceInfo::DeviceInfo(MDMSerial& mdm, MDMParser::DevStatus& devStatus) : - _mdm(mdm) +DeviceInfo::DeviceInfo(MDMParser::DevStatus& devStatus) { *_cellId = '\0'; memcpy(&_devStatus, &devStatus, sizeof(MDMParser::DevStatus)); @@ -61,5 +60,6 @@ bool DeviceInfo::refreshNetStatus() { - return _mdm.checkNetStatus(&_netStatus); + extern MDMSerial *pMdm; + return pMdm->checkNetStatus(&_netStatus); }
--- a/DeviceInfo.h Mon Apr 27 10:50:21 2015 +0000 +++ b/DeviceInfo.h Mon Apr 27 13:02:50 2015 +0000 @@ -1,14 +1,12 @@ #ifndef DEVICEINFO_H #define DEVICEINFO_H -#include <stddef.h> -#include <stdint.h> #include "MDM.h" class DeviceInfo { public: - DeviceInfo(MDMSerial& mdm, MDMParser::DevStatus& devStatus); + DeviceInfo(MDMParser::DevStatus& devStatus); typedef struct { int rssi; // RSSI in dBm @@ -25,7 +23,6 @@ bool refreshNetStatus(); private: - MDMSerial& _mdm; MDMParser::DevStatus _devStatus; MDMParser::NetStatus _netStatus; char _cellId[9];
--- a/MbedAgent.cpp Mon Apr 27 10:50:21 2015 +0000 +++ b/MbedAgent.cpp Mon Apr 27 13:02:50 2015 +0000 @@ -4,11 +4,10 @@ #include "logging.h" #include "watchdog.h" -MbedAgent::MbedAgent(GPSI2C& gps, MDMSerial& mdm, - DeviceInfo& deviceInfo, DeviceMemory& deviceMemory) : +MbedAgent::MbedAgent(GPSI2C& gps, DeviceInfo& deviceInfo, + DeviceMemory& deviceMemory) : _deviceId(0), - _mdm(mdm), - _client(mdm), + _client(), _bootstrap(_client, deviceInfo, deviceMemory), _integration(_client, _tpl, _deviceId, deviceInfo), _configurationSynchronization(_client, _tpl, _deviceId, deviceMemory), @@ -85,9 +84,9 @@ void MbedAgent::loop() { - ReportThread reportThread(pool, _mdm); + ReportThread reportThread(pool); _operationSupport.run(); - PollThread pollThread(pool, _mdm, _configurationSynchronization); + PollThread pollThread(pool, _configurationSynchronization); pollThread.setChannel(_deviceId); Watchdog wdt;
--- a/MbedAgent.h Mon Apr 27 10:50:21 2015 +0000 +++ b/MbedAgent.h Mon Apr 27 13:02:50 2015 +0000 @@ -2,7 +2,6 @@ #define MBEDAGENT_H #include <stddef.h> -#include "MDM.h" #include "SmartRest.h" #include "SmartRestTemplate.h" #include "DeviceInfo.h" @@ -23,7 +22,7 @@ class MbedAgent { public: - MbedAgent(GPSI2C&, MDMSerial&, DeviceInfo&, DeviceMemory&); + MbedAgent(GPSI2C&, DeviceInfo&, DeviceMemory&); bool init(); int run(); @@ -33,7 +32,6 @@ private: long _deviceId; - MDMSerial& _mdm; SmartRest _client; SmartRestTemplate _tpl; DeviceBootstrap _bootstrap;
--- a/MbedSmartRest.lib Mon Apr 27 10:50:21 2015 +0000 +++ b/MbedSmartRest.lib Mon Apr 27 13:02:50 2015 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/users/xinlei/code/MbedSmartRest/#832cb27c28f9 +http://developer.mbed.org/users/xinlei/code/MbedSmartRest/#0529d6779ab1
--- a/io/DeviceMemory.cpp Mon Apr 27 10:50:21 2015 +0000 +++ b/io/DeviceMemory.cpp Mon Apr 27 13:02:50 2015 +0000 @@ -1,20 +1,17 @@ -#include "DeviceMemory.h" #include <stdlib.h> #include <stdio.h> #include <string.h> +#include "MDM.h" +#include "DeviceMemory.h" #define PLATFORM_CREDENTIALS_FILE "001_CREDENTIALS" #define CONFIGURATION_FILE "002_CONFIGURATION" - -DeviceMemory::DeviceMemory(MDMSerial& mdm) : - _mdm(mdm) -{ -} +extern MDMSerial *pMdm; bool DeviceMemory::loadPlatformCredentials(char *username, char *password, size_t len) { char buffer[len*2+3]; - int res = _mdm.readFile(PLATFORM_CREDENTIALS_FILE, buffer, sizeof(buffer)); + int res = pMdm->readFile(PLATFORM_CREDENTIALS_FILE, buffer, sizeof(buffer)); if (res < 0) return false; @@ -31,18 +28,18 @@ if (res<0 || res>=sizeof(buffer)) return false; - return ((resetPlatformCredentials()) && (res == _mdm.writeFile(PLATFORM_CREDENTIALS_FILE, buffer, res))); + return ((resetPlatformCredentials()) && (res == pMdm->writeFile(PLATFORM_CREDENTIALS_FILE, buffer, res))); } bool DeviceMemory::resetPlatformCredentials() { - return _mdm.delFile(PLATFORM_CREDENTIALS_FILE); + return pMdm->delFile(PLATFORM_CREDENTIALS_FILE); } bool DeviceMemory::loadConfiguration(char *cfg, size_t len) { - int res = _mdm.readFile(CONFIGURATION_FILE, cfg, len); + int res = pMdm->readFile(CONFIGURATION_FILE, cfg, len); if (res < 0) return false; @@ -53,10 +50,10 @@ bool DeviceMemory::saveConfiguration(char *cfg) { size_t len = strlen(cfg); - return ((resetConfiguration()) && (_mdm.writeFile(CONFIGURATION_FILE, cfg, len) == len)); + return ((resetConfiguration()) && (pMdm->writeFile(CONFIGURATION_FILE, cfg, len) == len)); } bool DeviceMemory::resetConfiguration() { - return _mdm.delFile(CONFIGURATION_FILE); + return pMdm->delFile(CONFIGURATION_FILE); }
--- a/io/DeviceMemory.h Mon Apr 27 10:50:21 2015 +0000 +++ b/io/DeviceMemory.h Mon Apr 27 13:02:50 2015 +0000 @@ -2,7 +2,6 @@ #define DEVICEMEMORY_H #include <stddef.h> -#include "MDM.h" /** * Device Memory storage handler @@ -10,7 +9,7 @@ class DeviceMemory { public: - DeviceMemory(MDMSerial&); + DeviceMemory() {} /** loads credentials from persistent memory */ bool loadPlatformCredentials(char*, char*, size_t); @@ -31,7 +30,6 @@ bool resetConfiguration(); private: - MDMSerial& _mdm; }; #endif \ No newline at end of file
--- a/main.cpp Mon Apr 27 10:50:21 2015 +0000 +++ b/main.cpp Mon Apr 27 13:02:50 2015 +0000 @@ -23,7 +23,8 @@ //#define SIM_APN "" //#define SIM_USER "" //#define SIM_PASS "" -MDMRtos<MDMSerial> *pMdm = NULL; +//MDMRtos<MDMSerial> *pMdm; +MDMSerial* pMdm; unsigned short getMNCLen(const char *imsi) { @@ -72,7 +73,7 @@ joystickUp.rise(&enableDebug); joystickDown.rise(&disableDebug); - DeviceMemory deviceMemory(mdm); + DeviceMemory deviceMemory; DigitalIn fireButton(D4); if (fireButton) { @@ -114,8 +115,8 @@ } { - DeviceInfo deviceInfo(mdm, devStatus); - MbedAgent agent(gps, mdm, deviceInfo, deviceMemory); + DeviceInfo deviceInfo(devStatus); + MbedAgent agent(gps, deviceInfo, deviceMemory); LCDDisplay::inst().setLines("Agent Init"); if (!agent.init()) {
--- a/operation/PollThread.h Mon Apr 27 10:50:21 2015 +0000 +++ b/operation/PollThread.h Mon Apr 27 13:02:50 2015 +0000 @@ -8,9 +8,9 @@ class PollThread { public: - PollThread(OperationPool& pool, MDMSerial& m, + PollThread(OperationPool& pool, ConfigurationSynchronization& configSync): - sock(m), parser(pool, configSync), + sock(), parser(pool, configSync), thread(PollThread::threadWrapper, this) { strncpy(uri, "/devicecontrol/notifications", sizeof(uri)); sock.set_blocking(true);
--- a/operation/ReportThread.h Mon Apr 27 10:50:21 2015 +0000 +++ b/operation/ReportThread.h Mon Apr 27 13:02:50 2015 +0000 @@ -7,7 +7,7 @@ class ReportThread { public: - ReportThread(OperationPool& pool, MDMSerial& m) : ipool(pool), sock(m), + ReportThread(OperationPool& pool) : ipool(pool), sock(), thread(ReportThread::threadWrapper, this) { strncpy(uri, "/s", sizeof(uri)); }
--- a/util/SmartRestSocket.cpp Mon Apr 27 10:50:21 2015 +0000 +++ b/util/SmartRestSocket.cpp Mon Apr 27 13:02:50 2015 +0000 @@ -7,11 +7,12 @@ int SmartRestSocket::connect() { + extern MDMSerial *pMdm; int n = -1; ipLock.lock(); for (size_t i = 0; i < 3; ++i) { if (cachedIP[0] == '\0') { - MDMParser::IP ip = mdm.gethostbyname(getHost()); + MDMParser::IP ip = pMdm->gethostbyname(getHost()); if (ip == NOIP) continue; const unsigned char *c = (const unsigned char*)&ip;
--- a/util/SmartRestSocket.h Mon Apr 27 10:50:21 2015 +0000 +++ b/util/SmartRestSocket.h Mon Apr 27 13:02:50 2015 +0000 @@ -1,20 +1,18 @@ #ifndef SMARTRESTSOCKET_H #define SMARTRESTSOCKET_H -#include "MDM.h" #include "TCPSocketConnection.h" #include "rtos.h" class SmartRestSocket : public TCPSocketConnection { public: - SmartRestSocket(MDMSerial& m): TCPSocketConnection(), mdm(m) {} + SmartRestSocket(): TCPSocketConnection() {} virtual ~SmartRestSocket() {} int connect(); int sendOnly(char *buf, int size); int sendAndReceive(char *buf, int size, int maxSize); private: static char cachedIP[16]; - MDMSerial& mdm; Mutex ipLock; };