Own fork of MbedSmartRestMain

Dependencies:   C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed

Fork of MbedSmartRestMain by Cumulocity Official

Committer:
vwochnik
Date:
Thu Oct 30 13:38:20 2014 +0000
Revision:
65:a62dbef2f924
Parent:
60:3c822f97fc73
Child:
67:c360a2b2c948
operation support

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Cumulocity 41:804f6a0bda26 1 #include "MbedAgent.h"
Cumulocity 41:804f6a0bda26 2 #include "rtos.h"
Cumulocity 41:804f6a0bda26 3
Cumulocity 42:104746744af8 4 MbedAgent::MbedAgent(DeviceIO& io, MDMSerial& mdm, DeviceInfo& deviceInfo) :
Cumulocity 42:104746744af8 5 _io(io),
Cumulocity 41:804f6a0bda26 6 _mdm(mdm),
Cumulocity 41:804f6a0bda26 7 _deviceInfo(deviceInfo),
Cumulocity 41:804f6a0bda26 8 _client(MBED_AGENT_HOST, MBED_AGENT_PORT, MBED_AGENT_DEVICE_IDENTIFIER),
vwochnik 52:8f1370084268 9 _bootstrap(_client, _mdm, _io, _deviceInfo),
Cumulocity 41:804f6a0bda26 10 _integration(_client, _tpl, _deviceId, _deviceInfo),
Cumulocity 41:804f6a0bda26 11 _signalQualityMeasurement(_client, _tpl, _deviceId, _deviceInfo),
Cumulocity 41:804f6a0bda26 12 _temperatureMeasurement(_client, _tpl, _deviceId, _io.temperatureSensor()),
Cumulocity 41:804f6a0bda26 13 _accelerationMeasurement(_client, _tpl, _deviceId, _io.accelerometer()),
Cumulocity 47:89ae46d5c466 14 _analogMeasurement(_client, _tpl, _deviceId, _io.analog1(), _io.analog2()),
Cumulocity 47:89ae46d5c466 15 _locationUpdate(_client, _tpl, _deviceId, _io.gpsTracker()),
vwochnik 65:a62dbef2f924 16 _operationSupport(_client, _tpl, _deviceId, _io),
Cumulocity 41:804f6a0bda26 17 _deviceId(0)
Cumulocity 41:804f6a0bda26 18 {
Cumulocity 41:804f6a0bda26 19 }
Cumulocity 41:804f6a0bda26 20
Cumulocity 41:804f6a0bda26 21 bool MbedAgent::init()
Cumulocity 41:804f6a0bda26 22 {
Cumulocity 41:804f6a0bda26 23 if ((!_integration.init()) ||
Cumulocity 41:804f6a0bda26 24 (!_signalQualityMeasurement.init()) ||
Cumulocity 41:804f6a0bda26 25 (!_temperatureMeasurement.init()) ||
Cumulocity 47:89ae46d5c466 26 (!_accelerationMeasurement.init()) ||
Cumulocity 47:89ae46d5c466 27 (!_analogMeasurement.init()) ||
vwochnik 57:4af5f1bec3a6 28 (!_locationUpdate.init()) ||
vwochnik 57:4af5f1bec3a6 29 (!_operationSupport.init())) {
Cumulocity 41:804f6a0bda26 30 puts("Initialization failed.");
Cumulocity 41:804f6a0bda26 31 return false;
Cumulocity 41:804f6a0bda26 32 }
Cumulocity 41:804f6a0bda26 33 return true;
Cumulocity 41:804f6a0bda26 34 }
Cumulocity 41:804f6a0bda26 35
Cumulocity 41:804f6a0bda26 36 bool MbedAgent::run()
Cumulocity 41:804f6a0bda26 37 {
Cumulocity 41:804f6a0bda26 38 // device bootstrapping process
vwochnik 52:8f1370084268 39 if (!_bootstrap.setUpCredentials())
Cumulocity 41:804f6a0bda26 40 return false;
vwochnik 52:8f1370084268 41
Cumulocity 46:f6976fd64387 42 Thread::wait(5000);
Cumulocity 41:804f6a0bda26 43
Cumulocity 41:804f6a0bda26 44 _io.lcdPrint("INTEGRATION");
Cumulocity 41:804f6a0bda26 45 if (!_integration.integrate()) {
Cumulocity 41:804f6a0bda26 46 return false;
Cumulocity 41:804f6a0bda26 47 }
Cumulocity 41:804f6a0bda26 48
Cumulocity 41:804f6a0bda26 49 char status[60];
Cumulocity 41:804f6a0bda26 50 snprintf(status, sizeof(status), "ID: %ld", _deviceId);
Cumulocity 41:804f6a0bda26 51 _io.lcdPrint("INTEGRATED", status);
Cumulocity 41:804f6a0bda26 52
Cumulocity 41:804f6a0bda26 53 loop();
Cumulocity 41:804f6a0bda26 54 return true;
Cumulocity 41:804f6a0bda26 55 }
Cumulocity 41:804f6a0bda26 56
Cumulocity 41:804f6a0bda26 57 void MbedAgent::loop()
Cumulocity 41:804f6a0bda26 58 {
Cumulocity 41:804f6a0bda26 59 Timer timer;
Cumulocity 41:804f6a0bda26 60
Cumulocity 41:804f6a0bda26 61 timer.start();
Cumulocity 41:804f6a0bda26 62 while (true) {
Cumulocity 41:804f6a0bda26 63 timer.reset();
Cumulocity 41:804f6a0bda26 64
vwochnik 65:a62dbef2f924 65 _signalQualityMeasurement.run();
Cumulocity 41:804f6a0bda26 66 _temperatureMeasurement.run();
Cumulocity 41:804f6a0bda26 67 _accelerationMeasurement.run();
Cumulocity 47:89ae46d5c466 68 _analogMeasurement.run();
vwochnik 65:a62dbef2f924 69 _locationUpdate.run();
vwochnik 57:4af5f1bec3a6 70 _operationSupport.run();
Cumulocity 41:804f6a0bda26 71
vwochnik 65:a62dbef2f924 72 while (timer.read() < MBED_AGENT_INTERVAL) {
Cumulocity 41:804f6a0bda26 73 Thread::yield();
Cumulocity 41:804f6a0bda26 74 }
Cumulocity 41:804f6a0bda26 75 }
Cumulocity 41:804f6a0bda26 76 }