![](/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@97:9f2de96941c4, 2015-04-27 (annotated)
- Committer:
- xinlei
- Date:
- Mon Apr 27 13:30:21 2015 +0000
- Revision:
- 97:9f2de96941c4
- Parent:
- 96:ea056f6be2e8
- Child:
- 98:e369fc75c000
Get rid of useless DeviceMemory class wrapper
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 | 95:5dfdc8568e9f | 3 | #include "LCDDisplay.h" |
xinlei | 72:c5709ae7b193 | 4 | #include "logging.h" |
xinlei | 76:b07effe83fb8 | 5 | #include "watchdog.h" |
Cumulocity | 41:804f6a0bda26 | 6 | |
xinlei | 97:9f2de96941c4 | 7 | MbedAgent::MbedAgent(GPSI2C& gps, DeviceInfo& deviceInfo): |
xinlei | 93:61d44636f020 | 8 | _deviceId(0), |
xinlei | 96:ea056f6be2e8 | 9 | _client(), |
xinlei | 97:9f2de96941c4 | 10 | _bootstrap(_client, deviceInfo), |
xinlei | 95:5dfdc8568e9f | 11 | _integration(_client, _tpl, _deviceId, deviceInfo), |
xinlei | 97:9f2de96941c4 | 12 | _configurationSynchronization(_client, _tpl, _deviceId), |
xinlei | 95:5dfdc8568e9f | 13 | _signalQualityMeasurement(_client, _tpl, _deviceId, deviceInfo), |
xinlei | 95:5dfdc8568e9f | 14 | _temperatureMeasurement(_client, _tpl, _deviceId, deviceInfo), |
xinlei | 95:5dfdc8568e9f | 15 | _accelerationMeasurement(_client, _tpl, _deviceId, deviceInfo), |
xinlei | 95:5dfdc8568e9f | 16 | _analogMeasurement(_client, _tpl, _deviceId, deviceInfo), |
xinlei | 95:5dfdc8568e9f | 17 | _locationUpdate(_client, _tpl, _deviceId, gps, deviceInfo), |
xinlei | 93:61d44636f020 | 18 | pool(), |
xinlei | 93:61d44636f020 | 19 | _operationSupport(_client, _tpl, _deviceId, pool) |
Cumulocity | 41:804f6a0bda26 | 20 | { |
Cumulocity | 41:804f6a0bda26 | 21 | } |
Cumulocity | 41:804f6a0bda26 | 22 | |
Cumulocity | 41:804f6a0bda26 | 23 | bool MbedAgent::init() |
Cumulocity | 41:804f6a0bda26 | 24 | { |
xinlei | 71:063c45e99578 | 25 | bool flag = true; |
xinlei | 71:063c45e99578 | 26 | if (!_integration.init()) { |
xinlei | 95:5dfdc8568e9f | 27 | LCDDisplay::inst().setLines("Integrate init fail"); |
xinlei | 71:063c45e99578 | 28 | flag = false; |
xinlei | 71:063c45e99578 | 29 | } |
xinlei | 71:063c45e99578 | 30 | if (!_configurationSynchronization.init()) { |
xinlei | 95:5dfdc8568e9f | 31 | LCDDisplay::inst().setLines("ConfigSync init fail"); |
xinlei | 71:063c45e99578 | 32 | flag = false; |
xinlei | 71:063c45e99578 | 33 | } |
xinlei | 71:063c45e99578 | 34 | if (!_signalQualityMeasurement.init()) { |
xinlei | 95:5dfdc8568e9f | 35 | LCDDisplay::inst().setLines("Signal init fail"); |
xinlei | 71:063c45e99578 | 36 | flag = false; |
xinlei | 71:063c45e99578 | 37 | } |
xinlei | 71:063c45e99578 | 38 | if (!_temperatureMeasurement.init()) { |
xinlei | 95:5dfdc8568e9f | 39 | LCDDisplay::inst().setLines("Temp init fail"); |
xinlei | 71:063c45e99578 | 40 | flag = false; |
Cumulocity | 41:804f6a0bda26 | 41 | } |
xinlei | 71:063c45e99578 | 42 | if (!_accelerationMeasurement.init()) { |
xinlei | 95:5dfdc8568e9f | 43 | LCDDisplay::inst().setLines("Acc init fail"); |
xinlei | 71:063c45e99578 | 44 | flag = false; |
xinlei | 71:063c45e99578 | 45 | } |
xinlei | 71:063c45e99578 | 46 | if (!_analogMeasurement.init()) { |
xinlei | 95:5dfdc8568e9f | 47 | LCDDisplay::inst().setLines("Analog init fail"); |
xinlei | 71:063c45e99578 | 48 | flag = false; |
xinlei | 71:063c45e99578 | 49 | } |
xinlei | 71:063c45e99578 | 50 | if (!_locationUpdate.init()) { |
xinlei | 95:5dfdc8568e9f | 51 | LCDDisplay::inst().setLines("Location init fail"); |
xinlei | 71:063c45e99578 | 52 | flag = false; |
xinlei | 71:063c45e99578 | 53 | } |
xinlei | 71:063c45e99578 | 54 | if (!_operationSupport.init()) { |
xinlei | 95:5dfdc8568e9f | 55 | LCDDisplay::inst().setLines("Operation init fail"); |
xinlei | 71:063c45e99578 | 56 | flag = false; |
xinlei | 71:063c45e99578 | 57 | } |
xinlei | 71:063c45e99578 | 58 | return flag; |
Cumulocity | 41:804f6a0bda26 | 59 | } |
Cumulocity | 41:804f6a0bda26 | 60 | |
xinlei | 92:0acd11870c6a | 61 | int MbedAgent::run() |
Cumulocity | 41:804f6a0bda26 | 62 | { |
Cumulocity | 41:804f6a0bda26 | 63 | // device bootstrapping process |
vwochnik | 52:8f1370084268 | 64 | if (!_bootstrap.setUpCredentials()) |
xinlei | 92:0acd11870c6a | 65 | return -1; |
xinlei | 93:61d44636f020 | 66 | setAuth(_bootstrap.username(), _bootstrap.password()); |
xinlei | 93:61d44636f020 | 67 | aInfo("Set auth: %s:%s (%s)\n", getUsername(), getPassword(), getAuthStr()); |
vwochnik | 52:8f1370084268 | 68 | |
Cumulocity | 46:f6976fd64387 | 69 | Thread::wait(5000); |
Cumulocity | 41:804f6a0bda26 | 70 | |
xinlei | 95:5dfdc8568e9f | 71 | LCDDisplay::inst().setLines("Connect to Cloud", getHost()); |
Cumulocity | 41:804f6a0bda26 | 72 | if (!_integration.integrate()) { |
xinlei | 92:0acd11870c6a | 73 | return -2; |
Cumulocity | 41:804f6a0bda26 | 74 | } |
xinlei | 93:61d44636f020 | 75 | setIdentifier(_client.getIdentifier()); |
xinlei | 93:61d44636f020 | 76 | aInfo("Set id: %s\n", getIdentifier()); |
xinlei | 93:61d44636f020 | 77 | |
vwochnik | 68:0dc778a16d0d | 78 | if (!_configurationSynchronization.integrate()) { |
xinlei | 92:0acd11870c6a | 79 | return -3; |
vwochnik | 68:0dc778a16d0d | 80 | } |
xinlei | 92:0acd11870c6a | 81 | return 0; |
Cumulocity | 41:804f6a0bda26 | 82 | } |
Cumulocity | 41:804f6a0bda26 | 83 | |
Cumulocity | 41:804f6a0bda26 | 84 | void MbedAgent::loop() |
Cumulocity | 41:804f6a0bda26 | 85 | { |
xinlei | 96:ea056f6be2e8 | 86 | ReportThread reportThread(pool); |
xinlei | 93:61d44636f020 | 87 | _operationSupport.run(); |
xinlei | 96:ea056f6be2e8 | 88 | PollThread pollThread(pool, _configurationSynchronization); |
xinlei | 95:5dfdc8568e9f | 89 | pollThread.setChannel(_deviceId); |
xinlei | 93:61d44636f020 | 90 | |
xinlei | 76:b07effe83fb8 | 91 | Watchdog wdt; |
xinlei | 76:b07effe83fb8 | 92 | wdt.kick(60.0); // set a 60.0 seconds timeout on watchdog hardware timer |
Cumulocity | 41:804f6a0bda26 | 93 | while (true) { |
xinlei | 94:010b0f7a0a1a | 94 | _configurationSynchronization.run(); |
xinlei | 94:010b0f7a0a1a | 95 | _analogMeasurement.run(); |
xinlei | 94:010b0f7a0a1a | 96 | _signalQualityMeasurement.run(); |
xinlei | 94:010b0f7a0a1a | 97 | _temperatureMeasurement.run(); |
xinlei | 94:010b0f7a0a1a | 98 | _accelerationMeasurement.run(); |
xinlei | 94:010b0f7a0a1a | 99 | _locationUpdate.run(); |
xinlei | 94:010b0f7a0a1a | 100 | // Thread::wait(30000); |
xinlei | 76:b07effe83fb8 | 101 | wdt.kick(); // reset watchdog timer |
Cumulocity | 41:804f6a0bda26 | 102 | } |
Cumulocity | 41:804f6a0bda26 | 103 | } |