Own fork of MbedSmartRestMain

Dependencies:   C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed

Fork of MbedSmartRestMain by Cumulocity Official

Committer:
xinlei
Date:
Wed Mar 04 09:36:03 2015 +0000
Revision:
78:bf32dfe6c47f
Parent:
77:f6717e4eccc4
Child:
81:4a7761914901
New version of ublox c207 firmware.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Cumulocity 41:804f6a0bda26 1 #include "MbedAgent.h"
Cumulocity 41:804f6a0bda26 2 #include "rtos.h"
xinlei 72:c5709ae7b193 3 #include "logging.h"
xinlei 76:b07effe83fb8 4 #include "watchdog.h"
Cumulocity 41:804f6a0bda26 5
vwochnik 67:c360a2b2c948 6 MbedAgent::MbedAgent(DeviceIO& io, MDMSerial& mdm, DeviceInfo& deviceInfo, DeviceMemory& deviceMemory) :
Cumulocity 42:104746744af8 7 _io(io),
Cumulocity 41:804f6a0bda26 8 _mdm(mdm),
Cumulocity 41:804f6a0bda26 9 _deviceInfo(deviceInfo),
vwochnik 67:c360a2b2c948 10 _deviceMemory(deviceMemory),
vwochnik 68:0dc778a16d0d 11 _configurationProperties(_deviceConfiguration),
xinlei 77:f6717e4eccc4 12 _client(MBED_AGENT_HOST, MBED_AGENT_PORT, MBED_AGENT_DEVICE_IDENTIFIER, mdm),
vwochnik 67:c360a2b2c948 13 _bootstrap(_client, _io, _deviceInfo, _deviceMemory),
Cumulocity 41:804f6a0bda26 14 _integration(_client, _tpl, _deviceId, _deviceInfo),
vwochnik 68:0dc778a16d0d 15 _configurationSynchronization(_client, _tpl, _deviceId, _deviceMemory, _deviceConfiguration, _configurationProperties),
xinlei 73:313975bfec96 16 _signalQualityMeasurement(_client, _tpl, _deviceId, _deviceInfo, io, _bootstrap),
xinlei 73:313975bfec96 17 _temperatureMeasurement(_client, _tpl, _deviceId, _io.temperatureSensor(), io, deviceInfo, _bootstrap),
xinlei 73:313975bfec96 18 _accelerationMeasurement(_client, _tpl, _deviceId, _io.accelerometer(), io, deviceInfo, _bootstrap),
xinlei 73:313975bfec96 19 _analogMeasurement(_client, _tpl, _deviceId, _io.analog1(), _io.analog2(), io, deviceInfo, _bootstrap),
xinlei 73:313975bfec96 20 _locationUpdate(_client, _tpl, _deviceId, _io.gpsTracker(), io, deviceInfo, _bootstrap),
vwochnik 68:0dc778a16d0d 21 _operationSupport(_client, _tpl, _deviceId, _configurationSynchronization, _io),
Cumulocity 41:804f6a0bda26 22 _deviceId(0)
Cumulocity 41:804f6a0bda26 23 {
Cumulocity 41:804f6a0bda26 24 }
Cumulocity 41:804f6a0bda26 25
Cumulocity 41:804f6a0bda26 26 bool MbedAgent::init()
Cumulocity 41:804f6a0bda26 27 {
xinlei 71:063c45e99578 28 bool flag = true;
xinlei 71:063c45e99578 29 if (!_integration.init()) {
xinlei 76:b07effe83fb8 30 aError("Init Device Integration failed.\r\n");
xinlei 71:063c45e99578 31 flag = false;
xinlei 71:063c45e99578 32 }
xinlei 71:063c45e99578 33 if (!_configurationSynchronization.init()) {
xinlei 76:b07effe83fb8 34 aError("Init Configuration Synchronization failed.\r\n");
xinlei 71:063c45e99578 35 flag = false;
xinlei 71:063c45e99578 36 }
xinlei 71:063c45e99578 37 if (!_signalQualityMeasurement.init()) {
xinlei 76:b07effe83fb8 38 aError("Init Signal Quality Measurement failed.\r\n");
xinlei 71:063c45e99578 39 flag = false;
xinlei 71:063c45e99578 40 }
xinlei 71:063c45e99578 41 if (!_temperatureMeasurement.init()) {
xinlei 76:b07effe83fb8 42 aError("Init Temperature Measurement failed.\r\n");
xinlei 71:063c45e99578 43 flag = false;
Cumulocity 41:804f6a0bda26 44 }
xinlei 71:063c45e99578 45 if (!_accelerationMeasurement.init()) {
xinlei 76:b07effe83fb8 46 aError("Init Acceleration Measurement failed.\r\n");
xinlei 71:063c45e99578 47 flag = false;
xinlei 71:063c45e99578 48 }
xinlei 71:063c45e99578 49 if (!_analogMeasurement.init()) {
xinlei 76:b07effe83fb8 50 aError("Init Analog Measurement failed.\r\n");
xinlei 71:063c45e99578 51 flag = false;
xinlei 71:063c45e99578 52 }
xinlei 71:063c45e99578 53 if (!_locationUpdate.init()) {
xinlei 76:b07effe83fb8 54 aError("Init Location Measurement failed.\r\n");
xinlei 71:063c45e99578 55 flag = false;
xinlei 71:063c45e99578 56 }
xinlei 71:063c45e99578 57 if (!_operationSupport.init()) {
xinlei 76:b07effe83fb8 58 aError("Init Operation Support failed.\r\n");
xinlei 71:063c45e99578 59 flag = false;
xinlei 71:063c45e99578 60 }
xinlei 71:063c45e99578 61 return flag;
Cumulocity 41:804f6a0bda26 62 }
Cumulocity 41:804f6a0bda26 63
Cumulocity 41:804f6a0bda26 64 bool MbedAgent::run()
Cumulocity 41:804f6a0bda26 65 {
Cumulocity 41:804f6a0bda26 66 // device bootstrapping process
vwochnik 52:8f1370084268 67 if (!_bootstrap.setUpCredentials())
Cumulocity 41:804f6a0bda26 68 return false;
vwochnik 52:8f1370084268 69
Cumulocity 46:f6976fd64387 70 Thread::wait(5000);
Cumulocity 41:804f6a0bda26 71
xinlei 71:063c45e99578 72 _io.lcdPrint("Connect to Cloud");
Cumulocity 41:804f6a0bda26 73 if (!_integration.integrate()) {
Cumulocity 41:804f6a0bda26 74 return false;
Cumulocity 41:804f6a0bda26 75 }
Cumulocity 41:804f6a0bda26 76
vwochnik 68:0dc778a16d0d 77 if (!_configurationSynchronization.integrate()) {
vwochnik 68:0dc778a16d0d 78 return false;
vwochnik 68:0dc778a16d0d 79 }
vwochnik 68:0dc778a16d0d 80
Cumulocity 41:804f6a0bda26 81 char status[60];
Cumulocity 41:804f6a0bda26 82 snprintf(status, sizeof(status), "ID: %ld", _deviceId);
xinlei 71:063c45e99578 83 _io.lcdPrint("Connected", status);
Cumulocity 41:804f6a0bda26 84
Cumulocity 41:804f6a0bda26 85 loop();
vwochnik 68:0dc778a16d0d 86
Cumulocity 41:804f6a0bda26 87 return true;
Cumulocity 41:804f6a0bda26 88 }
Cumulocity 41:804f6a0bda26 89
Cumulocity 41:804f6a0bda26 90 void MbedAgent::loop()
Cumulocity 41:804f6a0bda26 91 {
xinlei 76:b07effe83fb8 92 Watchdog wdt;
xinlei 77:f6717e4eccc4 93 DigitalIn joystickUp(A2);
xinlei 77:f6717e4eccc4 94 DigitalIn joystickDown(A3);
xinlei 77:f6717e4eccc4 95 // DigitalIn joystickLeft(A4);
xinlei 77:f6717e4eccc4 96 // AnalogIn joystickRight(A5);
xinlei 77:f6717e4eccc4 97
xinlei 76:b07effe83fb8 98 wdt.kick(60.0); // set a 60.0 seconds timeout on watchdog hardware timer
Cumulocity 41:804f6a0bda26 99 while (true) {
xinlei 77:f6717e4eccc4 100 if (joystickDown) {
xinlei 77:f6717e4eccc4 101 setLevel(A_INFO);
xinlei 77:f6717e4eccc4 102 _mdm.setDebug(1);
xinlei 77:f6717e4eccc4 103 printf("***Disabled debug mode.***\r\n");
xinlei 77:f6717e4eccc4 104 } else if (joystickUp) {
xinlei 77:f6717e4eccc4 105 setLevel(A_DEBUG);
xinlei 77:f6717e4eccc4 106 _mdm.setDebug(3);
xinlei 77:f6717e4eccc4 107 printf("***Enabled debug mode.***\r\n");
xinlei 77:f6717e4eccc4 108 }
xinlei 78:bf32dfe6c47f 109 _configurationSynchronization.run();
xinlei 77:f6717e4eccc4 110 // _operationSupport.run();
xinlei 78:bf32dfe6c47f 111 _signalQualityMeasurement.run();
xinlei 77:f6717e4eccc4 112 // _operationSupport.run();
xinlei 78:bf32dfe6c47f 113 _temperatureMeasurement.run();
xinlei 77:f6717e4eccc4 114 // _operationSupport.run();
xinlei 78:bf32dfe6c47f 115 _analogMeasurement.run();
xinlei 77:f6717e4eccc4 116 // _operationSupport.run();
xinlei 78:bf32dfe6c47f 117 _accelerationMeasurement.run();
xinlei 77:f6717e4eccc4 118 // _operationSupport.run();
xinlei 78:bf32dfe6c47f 119 _locationUpdate.run();
vwochnik 57:4af5f1bec3a6 120 _operationSupport.run();
xinlei 77:f6717e4eccc4 121
xinlei 76:b07effe83fb8 122 // if ((interval = _configurationProperties.readInterval()) < 0)
xinlei 76:b07effe83fb8 123 // break;
xinlei 76:b07effe83fb8 124 //
xinlei 76:b07effe83fb8 125 // while (timer.read() < interval) {
xinlei 76:b07effe83fb8 126 // Thread::yield();
xinlei 76:b07effe83fb8 127 // }
xinlei 76:b07effe83fb8 128 wdt.kick(); // reset watchdog timer
Cumulocity 41:804f6a0bda26 129 }
Cumulocity 41:804f6a0bda26 130 }