Own fork of MbedSmartRestMain

Dependencies:   C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed

Fork of MbedSmartRestMain by Cumulocity Official

Committer:
xinlei
Date:
Thu May 07 13:56:19 2015 +0000
Revision:
99:47ea098f8a47
Parent:
98:e369fc75c000
Child:
100:dbcd3bc51758
prepare for v2.1rc3.

Who changed what in which revision?

UserRevisionLine numberNew 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 99:47ea098f8a47 7 _client(), tpl(), _bootstrap(_client, deviceInfo),
xinlei 99:47ea098f8a47 8 _integration(_client, _tpl, deviceInfo), lcdThirdLineBlank(true),
xinlei 99:47ea098f8a47 9 signal(), temp(), poti(), gps(), acc(), conf(), sock(),
xinlei 99:47ea098f8a47 10 pool(), _operationSupport(_client, _tpl, pool)
Cumulocity 41:804f6a0bda26 11 {
xinlei 99:47ea098f8a47 12 reporters[0] = &signal;
xinlei 99:47ea098f8a47 13 reporters[1] = &temp;
xinlei 99:47ea098f8a47 14 reporters[2] = &poti;
xinlei 99:47ea098f8a47 15 reporters[3] = &gps;
xinlei 99:47ea098f8a47 16 reporters[4] = &acc;
xinlei 99:47ea098f8a47 17 reporters[5] = &conf;
Cumulocity 41:804f6a0bda26 18 }
Cumulocity 41:804f6a0bda26 19
Cumulocity 41:804f6a0bda26 20 bool MbedAgent::init()
Cumulocity 41:804f6a0bda26 21 {
xinlei 71:063c45e99578 22 bool flag = true;
xinlei 71:063c45e99578 23 if (!_integration.init()) {
xinlei 95:5dfdc8568e9f 24 LCDDisplay::inst().setLines("Integrate init fail");
xinlei 71:063c45e99578 25 flag = false;
xinlei 71:063c45e99578 26 }
xinlei 71:063c45e99578 27 if (!_operationSupport.init()) {
xinlei 95:5dfdc8568e9f 28 LCDDisplay::inst().setLines("Operation init fail");
xinlei 71:063c45e99578 29 flag = false;
xinlei 71:063c45e99578 30 }
xinlei 71:063c45e99578 31 return flag;
Cumulocity 41:804f6a0bda26 32 }
Cumulocity 41:804f6a0bda26 33
xinlei 92:0acd11870c6a 34 int MbedAgent::run()
Cumulocity 41:804f6a0bda26 35 {
Cumulocity 41:804f6a0bda26 36 // device bootstrapping process
vwochnik 52:8f1370084268 37 if (!_bootstrap.setUpCredentials())
xinlei 92:0acd11870c6a 38 return -1;
xinlei 93:61d44636f020 39 setAuth(_bootstrap.username(), _bootstrap.password());
xinlei 98:e369fc75c000 40 aInfo("Set auth: %s:%s (%s)\n", srUsername, srPassword, srAuthStr);
vwochnik 52:8f1370084268 41
xinlei 98:e369fc75c000 42 Thread::wait(2000);
Cumulocity 41:804f6a0bda26 43
xinlei 98:e369fc75c000 44 LCDDisplay::inst().setLines("Connect to Cloud", srHost);
Cumulocity 41:804f6a0bda26 45 if (!_integration.integrate()) {
xinlei 92:0acd11870c6a 46 return -2;
Cumulocity 41:804f6a0bda26 47 }
xinlei 98:e369fc75c000 48 setX_ID(_client.getIdentifier());
xinlei 98:e369fc75c000 49 aInfo("Set id: %s\n", srX_ID);
xinlei 93:61d44636f020 50
xinlei 98:e369fc75c000 51 if (!_configSync.integrate()) {
xinlei 92:0acd11870c6a 52 return -3;
vwochnik 68:0dc778a16d0d 53 }
xinlei 92:0acd11870c6a 54 return 0;
Cumulocity 41:804f6a0bda26 55 }
Cumulocity 41:804f6a0bda26 56
Cumulocity 41:804f6a0bda26 57 void MbedAgent::loop()
Cumulocity 41:804f6a0bda26 58 {
xinlei 98:e369fc75c000 59 // ReportThread reportThread(pool);
xinlei 93:61d44636f020 60 _operationSupport.run();
xinlei 98:e369fc75c000 61 // PollThread pollThread(pool, _configSync);
xinlei 98:e369fc75c000 62 // pollThread.setChannel(_deviceId);
xinlei 93:61d44636f020 63
xinlei 76:b07effe83fb8 64 Watchdog wdt;
xinlei 76:b07effe83fb8 65 wdt.kick(60.0); // set a 60.0 seconds timeout on watchdog hardware timer
Cumulocity 41:804f6a0bda26 66 while (true) {
xinlei 98:e369fc75c000 67 _configSync.run();
xinlei 98:e369fc75c000 68 // _analogMeasurement.run();
xinlei 98:e369fc75c000 69 // _signalQualityMeasurement.run();
xinlei 98:e369fc75c000 70 // _temperatureMeasurement.run();
xinlei 98:e369fc75c000 71 // _accelerationMeasurement.run();
xinlei 98:e369fc75c000 72 // _locationUpdate.run();
xinlei 94:010b0f7a0a1a 73 // Thread::wait(30000);
xinlei 76:b07effe83fb8 74 wdt.kick(); // reset watchdog timer
Cumulocity 41:804f6a0bda26 75 }
Cumulocity 41:804f6a0bda26 76 }