![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Own fork of MbedSmartRestMain
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
MbedAgent.cpp
- Committer:
- xinlei
- Date:
- 2015-05-07
- Revision:
- 98:e369fc75c000
- Parent:
- 97:9f2de96941c4
- Child:
- 99:47ea098f8a47
File content as of revision 98:e369fc75c000:
#include "MbedAgent.h" #include "LCDDisplay.h" #include "logging.h" #include "watchdog.h" MbedAgent::MbedAgent(DeviceInfo& deviceInfo): _deviceId(0), _client(), _bootstrap(_client, deviceInfo), _integration(_client, _tpl, _deviceId, deviceInfo), _configSync(_client, _tpl, _deviceId), _signalQualityMeasurement(_client, _tpl, _deviceId, deviceInfo), _temperatureMeasurement(_client, _tpl, _deviceId, deviceInfo), _accelerationMeasurement(_client, _tpl, _deviceId, deviceInfo), _analogMeasurement(_client, _tpl, _deviceId, deviceInfo), _locationUpdate(_client, _tpl, _deviceId, deviceInfo), pool(), _operationSupport(_client, _tpl, _deviceId, pool) { } bool MbedAgent::init() { bool flag = true; if (!_integration.init()) { LCDDisplay::inst().setLines("Integrate init fail"); flag = false; } if (!_configSync.init()) { LCDDisplay::inst().setLines("ConfigSync init fail"); flag = false; } if (!_signalQualityMeasurement.init()) { LCDDisplay::inst().setLines("Signal init fail"); flag = false; } if (!_temperatureMeasurement.init()) { LCDDisplay::inst().setLines("Temp init fail"); flag = false; } if (!_accelerationMeasurement.init()) { LCDDisplay::inst().setLines("Acc init fail"); flag = false; } if (!_analogMeasurement.init()) { LCDDisplay::inst().setLines("Analog init fail"); flag = false; } if (!_locationUpdate.init()) { LCDDisplay::inst().setLines("Location init fail"); flag = false; } if (!_operationSupport.init()) { LCDDisplay::inst().setLines("Operation init fail"); flag = false; } return flag; } int MbedAgent::run() { // device bootstrapping process if (!_bootstrap.setUpCredentials()) return -1; setAuth(_bootstrap.username(), _bootstrap.password()); aInfo("Set auth: %s:%s (%s)\n", srUsername, srPassword, srAuthStr); Thread::wait(2000); LCDDisplay::inst().setLines("Connect to Cloud", srHost); if (!_integration.integrate()) { return -2; } setX_ID(_client.getIdentifier()); aInfo("Set id: %s\n", srX_ID); if (!_configSync.integrate()) { return -3; } return 0; } void MbedAgent::loop() { // ReportThread reportThread(pool); _operationSupport.run(); // PollThread pollThread(pool, _configSync); // pollThread.setChannel(_deviceId); Watchdog wdt; wdt.kick(60.0); // set a 60.0 seconds timeout on watchdog hardware timer while (true) { _configSync.run(); // _analogMeasurement.run(); // _signalQualityMeasurement.run(); // _temperatureMeasurement.run(); // _accelerationMeasurement.run(); // _locationUpdate.run(); // Thread::wait(30000); wdt.kick(); // reset watchdog timer } }