![](/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@73:313975bfec96, 2015-02-17 (annotated)
- Committer:
- xinlei
- Date:
- Tue Feb 17 16:31:30 2015 +0000
- Revision:
- 73:313975bfec96
- Parent:
- 72:c5709ae7b193
- Child:
- 76:b07effe83fb8
measurements: displaying concrete information on LCD display, timing of sending operation.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Cumulocity | 41:804f6a0bda26 | 1 | #include "MbedAgent.h" |
Cumulocity | 41:804f6a0bda26 | 2 | #include "rtos.h" |
xinlei | 72:c5709ae7b193 | 3 | #include "logging.h" |
Cumulocity | 41:804f6a0bda26 | 4 | |
vwochnik | 67:c360a2b2c948 | 5 | MbedAgent::MbedAgent(DeviceIO& io, MDMSerial& mdm, DeviceInfo& deviceInfo, DeviceMemory& deviceMemory) : |
Cumulocity | 42:104746744af8 | 6 | _io(io), |
Cumulocity | 41:804f6a0bda26 | 7 | _mdm(mdm), |
Cumulocity | 41:804f6a0bda26 | 8 | _deviceInfo(deviceInfo), |
vwochnik | 67:c360a2b2c948 | 9 | _deviceMemory(deviceMemory), |
vwochnik | 68:0dc778a16d0d | 10 | _configurationProperties(_deviceConfiguration), |
Cumulocity | 41:804f6a0bda26 | 11 | _client(MBED_AGENT_HOST, MBED_AGENT_PORT, MBED_AGENT_DEVICE_IDENTIFIER), |
vwochnik | 67:c360a2b2c948 | 12 | _bootstrap(_client, _io, _deviceInfo, _deviceMemory), |
Cumulocity | 41:804f6a0bda26 | 13 | _integration(_client, _tpl, _deviceId, _deviceInfo), |
vwochnik | 68:0dc778a16d0d | 14 | _configurationSynchronization(_client, _tpl, _deviceId, _deviceMemory, _deviceConfiguration, _configurationProperties), |
xinlei | 73:313975bfec96 | 15 | _signalQualityMeasurement(_client, _tpl, _deviceId, _deviceInfo, io, _bootstrap), |
xinlei | 73:313975bfec96 | 16 | _temperatureMeasurement(_client, _tpl, _deviceId, _io.temperatureSensor(), io, deviceInfo, _bootstrap), |
xinlei | 73:313975bfec96 | 17 | _accelerationMeasurement(_client, _tpl, _deviceId, _io.accelerometer(), io, deviceInfo, _bootstrap), |
xinlei | 73:313975bfec96 | 18 | _analogMeasurement(_client, _tpl, _deviceId, _io.analog1(), _io.analog2(), io, deviceInfo, _bootstrap), |
xinlei | 73:313975bfec96 | 19 | _locationUpdate(_client, _tpl, _deviceId, _io.gpsTracker(), io, deviceInfo, _bootstrap), |
vwochnik | 68:0dc778a16d0d | 20 | _operationSupport(_client, _tpl, _deviceId, _configurationSynchronization, _io), |
Cumulocity | 41:804f6a0bda26 | 21 | _deviceId(0) |
Cumulocity | 41:804f6a0bda26 | 22 | { |
Cumulocity | 41:804f6a0bda26 | 23 | } |
Cumulocity | 41:804f6a0bda26 | 24 | |
Cumulocity | 41:804f6a0bda26 | 25 | bool MbedAgent::init() |
Cumulocity | 41:804f6a0bda26 | 26 | { |
xinlei | 71:063c45e99578 | 27 | bool flag = true; |
xinlei | 71:063c45e99578 | 28 | if (!_integration.init()) { |
xinlei | 72:c5709ae7b193 | 29 | aWarning("Init Device Integration failed.\r\n"); |
xinlei | 71:063c45e99578 | 30 | flag = false; |
xinlei | 71:063c45e99578 | 31 | } |
xinlei | 71:063c45e99578 | 32 | if (!_configurationSynchronization.init()) { |
xinlei | 72:c5709ae7b193 | 33 | aWarning("Init Configuration Synchronization failed.\r\n"); |
xinlei | 71:063c45e99578 | 34 | flag = false; |
xinlei | 71:063c45e99578 | 35 | } |
xinlei | 71:063c45e99578 | 36 | if (!_signalQualityMeasurement.init()) { |
xinlei | 72:c5709ae7b193 | 37 | aWarning("Init Signal Quality Measurement failed.\r\n"); |
xinlei | 71:063c45e99578 | 38 | flag = false; |
xinlei | 71:063c45e99578 | 39 | } |
xinlei | 71:063c45e99578 | 40 | if (!_temperatureMeasurement.init()) { |
xinlei | 72:c5709ae7b193 | 41 | aWarning("Init Temperature Measurement failed.\r\n"); |
xinlei | 71:063c45e99578 | 42 | flag = false; |
Cumulocity | 41:804f6a0bda26 | 43 | } |
xinlei | 71:063c45e99578 | 44 | if (!_accelerationMeasurement.init()) { |
xinlei | 72:c5709ae7b193 | 45 | aWarning("Init Acceleration Measurement failed.\r\n"); |
xinlei | 71:063c45e99578 | 46 | flag = false; |
xinlei | 71:063c45e99578 | 47 | } |
xinlei | 71:063c45e99578 | 48 | if (!_analogMeasurement.init()) { |
xinlei | 72:c5709ae7b193 | 49 | aWarning("Init Analog Measurement failed.\r\n"); |
xinlei | 71:063c45e99578 | 50 | flag = false; |
xinlei | 71:063c45e99578 | 51 | } |
xinlei | 71:063c45e99578 | 52 | if (!_locationUpdate.init()) { |
xinlei | 72:c5709ae7b193 | 53 | aWarning("Init Location Measurement failed.\r\n"); |
xinlei | 71:063c45e99578 | 54 | flag = false; |
xinlei | 71:063c45e99578 | 55 | } |
xinlei | 71:063c45e99578 | 56 | if (!_operationSupport.init()) { |
xinlei | 72:c5709ae7b193 | 57 | aWarning("Init Operation Support failed.\r\n"); |
xinlei | 71:063c45e99578 | 58 | flag = false; |
xinlei | 71:063c45e99578 | 59 | } |
xinlei | 71:063c45e99578 | 60 | return flag; |
Cumulocity | 41:804f6a0bda26 | 61 | } |
Cumulocity | 41:804f6a0bda26 | 62 | |
Cumulocity | 41:804f6a0bda26 | 63 | bool MbedAgent::run() |
Cumulocity | 41:804f6a0bda26 | 64 | { |
Cumulocity | 41:804f6a0bda26 | 65 | // device bootstrapping process |
vwochnik | 52:8f1370084268 | 66 | if (!_bootstrap.setUpCredentials()) |
Cumulocity | 41:804f6a0bda26 | 67 | return false; |
vwochnik | 52:8f1370084268 | 68 | |
Cumulocity | 46:f6976fd64387 | 69 | Thread::wait(5000); |
Cumulocity | 41:804f6a0bda26 | 70 | |
xinlei | 71:063c45e99578 | 71 | _io.lcdPrint("Connect to Cloud"); |
Cumulocity | 41:804f6a0bda26 | 72 | if (!_integration.integrate()) { |
Cumulocity | 41:804f6a0bda26 | 73 | return false; |
Cumulocity | 41:804f6a0bda26 | 74 | } |
Cumulocity | 41:804f6a0bda26 | 75 | |
vwochnik | 68:0dc778a16d0d | 76 | if (!_configurationSynchronization.integrate()) { |
vwochnik | 68:0dc778a16d0d | 77 | return false; |
vwochnik | 68:0dc778a16d0d | 78 | } |
vwochnik | 68:0dc778a16d0d | 79 | |
Cumulocity | 41:804f6a0bda26 | 80 | char status[60]; |
Cumulocity | 41:804f6a0bda26 | 81 | snprintf(status, sizeof(status), "ID: %ld", _deviceId); |
xinlei | 71:063c45e99578 | 82 | _io.lcdPrint("Connected", status); |
Cumulocity | 41:804f6a0bda26 | 83 | |
Cumulocity | 41:804f6a0bda26 | 84 | loop(); |
vwochnik | 68:0dc778a16d0d | 85 | |
Cumulocity | 41:804f6a0bda26 | 86 | return true; |
Cumulocity | 41:804f6a0bda26 | 87 | } |
Cumulocity | 41:804f6a0bda26 | 88 | |
Cumulocity | 41:804f6a0bda26 | 89 | void MbedAgent::loop() |
Cumulocity | 41:804f6a0bda26 | 90 | { |
vwochnik | 68:0dc778a16d0d | 91 | Timer timer; int interval; |
Cumulocity | 41:804f6a0bda26 | 92 | |
Cumulocity | 41:804f6a0bda26 | 93 | timer.start(); |
Cumulocity | 41:804f6a0bda26 | 94 | while (true) { |
Cumulocity | 41:804f6a0bda26 | 95 | timer.reset(); |
Cumulocity | 41:804f6a0bda26 | 96 | |
vwochnik | 68:0dc778a16d0d | 97 | _configurationSynchronization.run(); |
vwochnik | 65:a62dbef2f924 | 98 | _signalQualityMeasurement.run(); |
Cumulocity | 41:804f6a0bda26 | 99 | _temperatureMeasurement.run(); |
Cumulocity | 41:804f6a0bda26 | 100 | _accelerationMeasurement.run(); |
Cumulocity | 47:89ae46d5c466 | 101 | _analogMeasurement.run(); |
vwochnik | 65:a62dbef2f924 | 102 | _locationUpdate.run(); |
vwochnik | 57:4af5f1bec3a6 | 103 | _operationSupport.run(); |
Cumulocity | 41:804f6a0bda26 | 104 | |
vwochnik | 68:0dc778a16d0d | 105 | if ((interval = _configurationProperties.readInterval()) == 0) |
vwochnik | 68:0dc778a16d0d | 106 | break; |
vwochnik | 68:0dc778a16d0d | 107 | |
vwochnik | 68:0dc778a16d0d | 108 | while (timer.read() < interval) { |
Cumulocity | 41:804f6a0bda26 | 109 | Thread::yield(); |
Cumulocity | 41:804f6a0bda26 | 110 | } |
Cumulocity | 41:804f6a0bda26 | 111 | } |
Cumulocity | 41:804f6a0bda26 | 112 | } |