Own fork of MbedSmartRestMain
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
MbedAgent.cpp@98:e369fc75c000, 2015-05-07 (annotated)
- Committer:
- xinlei
- Date:
- Thu May 07 09:57:55 2015 +0000
- Revision:
- 98:e369fc75c000
- Parent:
- 97:9f2de96941c4
- Child:
- 99:47ea098f8a47
prepare for v2.1rc3.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Cumulocity | 41:804f6a0bda26 | 1 | #include "MbedAgent.h" |
xinlei | 95:5dfdc8568e9f | 2 | #include "LCDDisplay.h" |
xinlei | 72:c5709ae7b193 | 3 | #include "logging.h" |
xinlei | 76:b07effe83fb8 | 4 | #include "watchdog.h" |
Cumulocity | 41:804f6a0bda26 | 5 | |
xinlei | 98:e369fc75c000 | 6 | MbedAgent::MbedAgent(DeviceInfo& deviceInfo): |
xinlei | 93:61d44636f020 | 7 | _deviceId(0), |
xinlei | 96:ea056f6be2e8 | 8 | _client(), |
xinlei | 97:9f2de96941c4 | 9 | _bootstrap(_client, deviceInfo), |
xinlei | 95:5dfdc8568e9f | 10 | _integration(_client, _tpl, _deviceId, deviceInfo), |
xinlei | 98:e369fc75c000 | 11 | _configSync(_client, _tpl, _deviceId), |
xinlei | 95:5dfdc8568e9f | 12 | _signalQualityMeasurement(_client, _tpl, _deviceId, deviceInfo), |
xinlei | 95:5dfdc8568e9f | 13 | _temperatureMeasurement(_client, _tpl, _deviceId, deviceInfo), |
xinlei | 95:5dfdc8568e9f | 14 | _accelerationMeasurement(_client, _tpl, _deviceId, deviceInfo), |
xinlei | 95:5dfdc8568e9f | 15 | _analogMeasurement(_client, _tpl, _deviceId, deviceInfo), |
xinlei | 98:e369fc75c000 | 16 | _locationUpdate(_client, _tpl, _deviceId, deviceInfo), |
xinlei | 93:61d44636f020 | 17 | pool(), |
xinlei | 93:61d44636f020 | 18 | _operationSupport(_client, _tpl, _deviceId, pool) |
Cumulocity | 41:804f6a0bda26 | 19 | { |
Cumulocity | 41:804f6a0bda26 | 20 | } |
Cumulocity | 41:804f6a0bda26 | 21 | |
Cumulocity | 41:804f6a0bda26 | 22 | bool MbedAgent::init() |
Cumulocity | 41:804f6a0bda26 | 23 | { |
xinlei | 71:063c45e99578 | 24 | bool flag = true; |
xinlei | 71:063c45e99578 | 25 | if (!_integration.init()) { |
xinlei | 95:5dfdc8568e9f | 26 | LCDDisplay::inst().setLines("Integrate init fail"); |
xinlei | 71:063c45e99578 | 27 | flag = false; |
xinlei | 71:063c45e99578 | 28 | } |
xinlei | 98:e369fc75c000 | 29 | if (!_configSync.init()) { |
xinlei | 95:5dfdc8568e9f | 30 | LCDDisplay::inst().setLines("ConfigSync init fail"); |
xinlei | 71:063c45e99578 | 31 | flag = false; |
xinlei | 71:063c45e99578 | 32 | } |
xinlei | 71:063c45e99578 | 33 | if (!_signalQualityMeasurement.init()) { |
xinlei | 95:5dfdc8568e9f | 34 | LCDDisplay::inst().setLines("Signal init fail"); |
xinlei | 71:063c45e99578 | 35 | flag = false; |
xinlei | 71:063c45e99578 | 36 | } |
xinlei | 71:063c45e99578 | 37 | if (!_temperatureMeasurement.init()) { |
xinlei | 95:5dfdc8568e9f | 38 | LCDDisplay::inst().setLines("Temp init fail"); |
xinlei | 71:063c45e99578 | 39 | flag = false; |
Cumulocity | 41:804f6a0bda26 | 40 | } |
xinlei | 71:063c45e99578 | 41 | if (!_accelerationMeasurement.init()) { |
xinlei | 95:5dfdc8568e9f | 42 | LCDDisplay::inst().setLines("Acc init fail"); |
xinlei | 71:063c45e99578 | 43 | flag = false; |
xinlei | 71:063c45e99578 | 44 | } |
xinlei | 71:063c45e99578 | 45 | if (!_analogMeasurement.init()) { |
xinlei | 95:5dfdc8568e9f | 46 | LCDDisplay::inst().setLines("Analog init fail"); |
xinlei | 71:063c45e99578 | 47 | flag = false; |
xinlei | 71:063c45e99578 | 48 | } |
xinlei | 71:063c45e99578 | 49 | if (!_locationUpdate.init()) { |
xinlei | 95:5dfdc8568e9f | 50 | LCDDisplay::inst().setLines("Location init fail"); |
xinlei | 71:063c45e99578 | 51 | flag = false; |
xinlei | 71:063c45e99578 | 52 | } |
xinlei | 71:063c45e99578 | 53 | if (!_operationSupport.init()) { |
xinlei | 95:5dfdc8568e9f | 54 | LCDDisplay::inst().setLines("Operation init fail"); |
xinlei | 71:063c45e99578 | 55 | flag = false; |
xinlei | 71:063c45e99578 | 56 | } |
xinlei | 71:063c45e99578 | 57 | return flag; |
Cumulocity | 41:804f6a0bda26 | 58 | } |
Cumulocity | 41:804f6a0bda26 | 59 | |
xinlei | 92:0acd11870c6a | 60 | int MbedAgent::run() |
Cumulocity | 41:804f6a0bda26 | 61 | { |
Cumulocity | 41:804f6a0bda26 | 62 | // device bootstrapping process |
vwochnik | 52:8f1370084268 | 63 | if (!_bootstrap.setUpCredentials()) |
xinlei | 92:0acd11870c6a | 64 | return -1; |
xinlei | 93:61d44636f020 | 65 | setAuth(_bootstrap.username(), _bootstrap.password()); |
xinlei | 98:e369fc75c000 | 66 | aInfo("Set auth: %s:%s (%s)\n", srUsername, srPassword, srAuthStr); |
vwochnik | 52:8f1370084268 | 67 | |
xinlei | 98:e369fc75c000 | 68 | Thread::wait(2000); |
Cumulocity | 41:804f6a0bda26 | 69 | |
xinlei | 98:e369fc75c000 | 70 | LCDDisplay::inst().setLines("Connect to Cloud", srHost); |
Cumulocity | 41:804f6a0bda26 | 71 | if (!_integration.integrate()) { |
xinlei | 92:0acd11870c6a | 72 | return -2; |
Cumulocity | 41:804f6a0bda26 | 73 | } |
xinlei | 98:e369fc75c000 | 74 | setX_ID(_client.getIdentifier()); |
xinlei | 98:e369fc75c000 | 75 | aInfo("Set id: %s\n", srX_ID); |
xinlei | 93:61d44636f020 | 76 | |
xinlei | 98:e369fc75c000 | 77 | if (!_configSync.integrate()) { |
xinlei | 92:0acd11870c6a | 78 | return -3; |
vwochnik | 68:0dc778a16d0d | 79 | } |
xinlei | 92:0acd11870c6a | 80 | return 0; |
Cumulocity | 41:804f6a0bda26 | 81 | } |
Cumulocity | 41:804f6a0bda26 | 82 | |
Cumulocity | 41:804f6a0bda26 | 83 | void MbedAgent::loop() |
Cumulocity | 41:804f6a0bda26 | 84 | { |
xinlei | 98:e369fc75c000 | 85 | // ReportThread reportThread(pool); |
xinlei | 93:61d44636f020 | 86 | _operationSupport.run(); |
xinlei | 98:e369fc75c000 | 87 | // PollThread pollThread(pool, _configSync); |
xinlei | 98:e369fc75c000 | 88 | // pollThread.setChannel(_deviceId); |
xinlei | 93:61d44636f020 | 89 | |
xinlei | 76:b07effe83fb8 | 90 | Watchdog wdt; |
xinlei | 76:b07effe83fb8 | 91 | wdt.kick(60.0); // set a 60.0 seconds timeout on watchdog hardware timer |
Cumulocity | 41:804f6a0bda26 | 92 | while (true) { |
xinlei | 98:e369fc75c000 | 93 | _configSync.run(); |
xinlei | 98:e369fc75c000 | 94 | // _analogMeasurement.run(); |
xinlei | 98:e369fc75c000 | 95 | // _signalQualityMeasurement.run(); |
xinlei | 98:e369fc75c000 | 96 | // _temperatureMeasurement.run(); |
xinlei | 98:e369fc75c000 | 97 | // _accelerationMeasurement.run(); |
xinlei | 98:e369fc75c000 | 98 | // _locationUpdate.run(); |
xinlei | 94:010b0f7a0a1a | 99 | // Thread::wait(30000); |
xinlei | 76:b07effe83fb8 | 100 | wdt.kick(); // reset watchdog timer |
Cumulocity | 41:804f6a0bda26 | 101 | } |
Cumulocity | 41:804f6a0bda26 | 102 | } |