![](/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-04-20
- Revision:
- 93:61d44636f020
- Parent:
- 92:0acd11870c6a
- Child:
- 94:010b0f7a0a1a
File content as of revision 93:61d44636f020:
#include "MbedAgent.h" #include "rtos.h" #include "logging.h" #include "watchdog.h" MbedAgent::MbedAgent(GPSI2C& gps, MDMSerial& mdm, LCDDisplay& lcdDisplay, DeviceInfo& deviceInfo, DeviceMemory& deviceMemory) : _deviceId(0), _mdm(mdm), _deviceInfo(deviceInfo), _deviceMemory(deviceMemory), _lcdDisplay(lcdDisplay), _configurationProperties(_deviceConfiguration), _client(mdm), _bootstrap(_client, lcdDisplay, _deviceInfo, _deviceMemory), _integration(_client, _tpl, _deviceId, _deviceInfo), _configurationSynchronization(_client, _tpl, _deviceId, _deviceMemory, _deviceConfiguration, _configurationProperties), _signalQualityMeasurement(_client, _tpl, _deviceId, _deviceInfo, _lcdDisplay), _temperatureMeasurement(_client, _tpl, _deviceId, deviceInfo, _lcdDisplay), _accelerationMeasurement(_client, _tpl, _deviceId, deviceInfo, _lcdDisplay), _analogMeasurement(_client, _tpl, _deviceId, deviceInfo, _lcdDisplay), _locationUpdate(_client, _tpl, _deviceId, gps, deviceInfo, _lcdDisplay), pool(), _operationSupport(_client, _tpl, _deviceId, pool) { } bool MbedAgent::init() { bool flag = true; if (!_integration.init()) { _lcdDisplay.setLines("Integration init failure"); flag = false; } if (!_configurationSynchronization.init()) { _lcdDisplay.setLines("Config Sync init failure"); flag = false; } if (!_signalQualityMeasurement.init()) { _lcdDisplay.setLines("Signal init failure"); flag = false; } if (!_temperatureMeasurement.init()) { _lcdDisplay.setLines("Temperature init failure"); flag = false; } if (!_accelerationMeasurement.init()) { _lcdDisplay.setLines("Acceleration init failure"); flag = false; } if (!_analogMeasurement.init()) { _lcdDisplay.setLines("Analog init failure"); flag = false; } if (!_locationUpdate.init()) { _lcdDisplay.setLines("Location init failure"); flag = false; } if (!_operationSupport.init()) { _lcdDisplay.setLines("Operation init failure"); 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", getUsername(), getPassword(), getAuthStr()); Thread::wait(5000); _lcdDisplay.setLines("Connect to Cloud", getHost()); if (!_integration.integrate()) { return -2; } setIdentifier(_client.getIdentifier()); aInfo("Set id: %s\n", getIdentifier()); if (!_configurationSynchronization.integrate()) { return -3; } char status[27]; snprintf(status, sizeof(status), "ID: %ld", _deviceId); _lcdDisplay.setLines("Connected", status); const char* user= getUsername(); int len = strchr(user, '/')-user+sizeof("Tenant: "); len = len <= 27 ? len : 27; snprintf(status, len, "Tenant: %s", user); _lcdDisplay.setFirstLine(status); return 0; } void MbedAgent::loop() { ReportThread reportThread(pool, _mdm); _operationSupport.run(); PollingThread pollingThread(pool, _mdm, _lcdDisplay, _configurationSynchronization); pollingThread.setChannel(_deviceId); Watchdog wdt; wdt.kick(60.0); // set a 60.0 seconds timeout on watchdog hardware timer while (true) { // _configurationSynchronization.run(); // _analogMeasurement.run(); // _signalQualityMeasurement.run(); // _temperatureMeasurement.run(); // _accelerationMeasurement.run(); // _locationUpdate.run(); Thread::wait(30000); // if ((interval = _configurationProperties.readInterval()) < 0) // break; // while (timer.read() < interval) { // Thread::yield(); // } wdt.kick(); // reset watchdog timer } }