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