
Own fork of MbedSmartRestMain
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
Revision 90:423177e8a401, committed 2015-03-20
- Comitter:
- xinlei
- Date:
- Fri Mar 20 13:55:21 2015 +0000
- Parent:
- 89:0525121f307e
- Child:
- 91:48069375dffa
- Commit message:
- Code refactoring to ease coupling
Changed in this revision
--- a/MbedAgent.cpp Mon Mar 16 12:12:04 2015 +0000 +++ b/MbedAgent.cpp Fri Mar 20 13:55:21 2015 +0000 @@ -17,9 +17,9 @@ _displayInfo(), _configurationSynchronization(_client, _tpl, _deviceId, _deviceMemory, _deviceConfiguration, _configurationProperties), _signalQualityMeasurement(_client, _tpl, _deviceId, _deviceInfo, io, _displayInfo), - _temperatureMeasurement(_client, _tpl, _deviceId, _io.temperatureSensor(), io, deviceInfo, _displayInfo), - _accelerationMeasurement(_client, _tpl, _deviceId, _io.accelerometer(), io, deviceInfo, _displayInfo), - _analogMeasurement(_client, _tpl, _deviceId, _io.analog1(), _io.analog2(), io, deviceInfo, _displayInfo), + _temperatureMeasurement(_client, _tpl, _deviceId, io, deviceInfo, _displayInfo), + _accelerationMeasurement(_client, _tpl, _deviceId, io, deviceInfo, _displayInfo), + _analogMeasurement(_client, _tpl, _deviceId, io, deviceInfo, _displayInfo), _locationUpdate(_client, _tpl, _deviceId, _io.gpsTracker(), io, deviceInfo, _displayInfo), _operationSupport(_client, _tpl, _deviceId, _configurationSynchronization, _io, _displayInfo), _deviceId(0) @@ -123,7 +123,7 @@ _accelerationMeasurement.run(); _locationUpdate.run(); _operationSupport.run(); - + // if ((interval = _configurationProperties.readInterval()) < 0) // break; //
--- a/MbedAgent.h Mon Mar 16 12:12:04 2015 +0000 +++ b/MbedAgent.h Fri Mar 20 13:55:21 2015 +0000 @@ -20,8 +20,8 @@ #include "LocationUpdate.h" #include "OperationSupport.h" -//#define MBED_AGENT_HOST "management.m2m-devicecloud.com" -#define MBED_AGENT_HOST "developer.cumulocity.com" +#define MBED_AGENT_HOST "management.m2m-devicecloud.com" +//#define MBED_AGENT_HOST "developer.cumulocity.com" #define MBED_AGENT_PORT 80 #define MBED_AGENT_DEVICE_IDENTIFIER "com_cumulocity_MbedAgent_1.5.2"
--- a/io/DeviceFeedback.cpp Mon Mar 16 12:12:04 2015 +0000 +++ b/io/DeviceFeedback.cpp Fri Mar 20 13:55:21 2015 +0000 @@ -7,9 +7,9 @@ #define MSG_CLOSE_RELAY 3 #define MSG_OPEN_RELAY 4 -DeviceFeedback::DeviceFeedback(PwmOut speaker) : - _speaker(speaker), - _thread(DeviceFeedback::thread_func, this), +DeviceFeedback::DeviceFeedback() : + _speaker(D6), +// _thread(DeviceFeedback::thread_func, this), shieldLEDRed(D5), shieldLEDBlue(D8), shieldLEDGreen(D9) @@ -34,7 +34,7 @@ shieldLEDRed = 255; shieldLEDBlue = 255; shieldLEDGreen = 0; - sendMessage(MSG_CLOSE_RELAY); +// sendMessage(MSG_CLOSE_RELAY); } void DeviceFeedback::openRelay() @@ -42,7 +42,7 @@ shieldLEDRed = 255; shieldLEDBlue = 255; shieldLEDGreen = 255; - sendMessage(MSG_OPEN_RELAY); +// sendMessage(MSG_OPEN_RELAY); } void DeviceFeedback::sendMessage(uint8_t msg) @@ -80,26 +80,26 @@ } break; case MSG_CLOSE_RELAY: - if (!relayState) { - relayState = true; + relayState = true; +// if (!relayState) { // for (float i=2000.0; i<10000.0; i+=100) { // _speaker.period(1.0/i); // _speaker = 0.5; // Thread::wait(20); // } // _speaker = 0.0; - } +// } break; case MSG_OPEN_RELAY: - if (relayState) { - relayState = false; + relayState = false; +// if (relayState) { // for (float i=10000.0; i>2000.0; i-=100) { // _speaker.period(1.0/i); // _speaker = 0.5; // Thread::wait(20); // } // _speaker = 0.0; - } +// } break; } _mail.free(msg);
--- a/io/DeviceFeedback.h Mon Mar 16 12:12:04 2015 +0000 +++ b/io/DeviceFeedback.h Fri Mar 20 13:55:21 2015 +0000 @@ -8,8 +8,8 @@ class DeviceFeedback { public: - DeviceFeedback(PwmOut speaker); - + DeviceFeedback(); + void beepSuccess(); void beepFailure(); void closeRelay(); @@ -22,7 +22,7 @@ private: PwmOut _speaker; - Thread _thread; +// Thread _thread; /* LED lights on the application shield, consists of three colors: Red, Blue, Green. * Note: value 0 means fully on for a color, 255 means off.
--- a/io/DeviceIO.cpp Mon Mar 16 12:12:04 2015 +0000 +++ b/io/DeviceIO.cpp Fri Mar 20 13:55:21 2015 +0000 @@ -7,14 +7,9 @@ DeviceIO::DeviceIO(GPSI2C& gps) : _resetButton(D4), // fire button on arduino app shield - _analog1(A0), - _analog2(A1), - _speaker(D6), - _temperatureSensor(SDA,SCL), - _accelerometer(SDA,SCL), _lcd(D11, D13, D12, D7, D10), _gpsTracker(gps), - _deviceFeedback(_speaker) + _deviceFeedback() { } @@ -33,25 +28,6 @@ return _deviceFeedback; } -AnalogIn& DeviceIO::analog1() -{ - return _analog1; -} - -AnalogIn& DeviceIO::analog2() -{ - return _analog2; -} -LM75B& DeviceIO::temperatureSensor() -{ - return _temperatureSensor; -} - -MMA7660& DeviceIO::accelerometer() -{ - return _accelerometer; -} - void DeviceIO::lcdPrint(const char *line1, const char *line2, const char *line3) { aDebug(GRE "io::lcdPrint" DEF "\r\n");
--- a/io/DeviceIO.h Mon Mar 16 12:12:04 2015 +0000 +++ b/io/DeviceIO.h Fri Mar 20 13:55:21 2015 +0000 @@ -9,32 +9,6 @@ #include "GPSTracker.h" #include "DeviceFeedback.h" -#define A0 P0_23 -#define A1 P0_24 -#define A2 P0_25 -#define A3 P0_26 -#define A4 P0_30 -#define A5 P1_31 - -#define D0 P4_29 -#define D1 P4_28 -#define D2 P2_13 -#define D3 P2_0 -#define D4 P2_12 -#define D5 P2_1 -#define D6 P2_2 -#define D7 P2_11 - -#define D8 P2_4 -#define D9 P2_3 -#define D10 P1_21 -#define D11 P1_24 -#define D12 P1_23 -#define D13 P1_20 - -#define SDA P0_0 -#define SCL P0_1 - class DeviceIO { public: @@ -43,19 +17,10 @@ bool resetButtonPressed(); GPSTracker& gpsTracker(); DeviceFeedback& deviceFeedback(); - AnalogIn& analog1(); - AnalogIn& analog2(); - LM75B& temperatureSensor(); - MMA7660& accelerometer(); void lcdPrint(const char*, const char* = NULL, const char* = NULL); private: DigitalIn _resetButton; - AnalogIn _analog1; - AnalogIn _analog2; - PwmOut _speaker; - LM75B _temperatureSensor; - MMA7660 _accelerometer; C12832 _lcd; GPSTracker _gpsTracker; DeviceFeedback _deviceFeedback;
--- a/main.cpp Mon Mar 16 12:12:04 2015 +0000 +++ b/main.cpp Fri Mar 20 13:55:21 2015 +0000 @@ -37,7 +37,7 @@ MDMRtos<MDMSerial> mdm; GPSI2C gps; - DeviceIO io(gps); + DeviceIO io(gps); DigitalIn joystickUp(A2); DigitalIn joystickDown(A3);
--- a/measurement/AccelerationMeasurement.cpp Mon Mar 16 12:12:04 2015 +0000 +++ b/measurement/AccelerationMeasurement.cpp Fri Mar 20 13:55:21 2015 +0000 @@ -11,11 +11,11 @@ #define TIME_LIMIT_ACCE 900 AccelerationMeasurement::AccelerationMeasurement(AbstractSmartRest& client, SmartRestTemplate& tpl, long& deviceId, - MMA7660& sensor, DeviceIO& io, DeviceInfo& deviceInfo, DisplayInfo& displayInfo) : + DeviceIO& io, DeviceInfo& deviceInfo, DisplayInfo& displayInfo) : _client(client), _tpl(tpl), _deviceId(deviceId), - _sensor(sensor), + _sensor(SDA,SCL), _io(io), _deviceInfo(deviceInfo), _displayInfo(displayInfo)
--- a/measurement/AccelerationMeasurement.h Mon Mar 16 12:12:04 2015 +0000 +++ b/measurement/AccelerationMeasurement.h Fri Mar 20 13:55:21 2015 +0000 @@ -11,7 +11,7 @@ class AccelerationMeasurement { public: - AccelerationMeasurement(AbstractSmartRest&, SmartRestTemplate&, long&, MMA7660&, DeviceIO&, DeviceInfo&, DisplayInfo&); + AccelerationMeasurement(AbstractSmartRest&, SmartRestTemplate&, long&, DeviceIO&, DeviceInfo&, DisplayInfo&); bool init(); bool run(); @@ -21,7 +21,7 @@ long& _deviceId; SmartRestTemplate& _tpl; AbstractSmartRest& _client; - MMA7660& _sensor; + MMA7660 _sensor; float oldValues[3]; Timer sendingTimer; DeviceIO& _io;
--- a/measurement/AnalogMeasurement.cpp Mon Mar 16 12:12:04 2015 +0000 +++ b/measurement/AnalogMeasurement.cpp Fri Mar 20 13:55:21 2015 +0000 @@ -8,14 +8,19 @@ #define THRESHOLD_PERCENT_ANA 0.02 // Percentage cut-off for avoiding sending similar analog sensor data. // Time interval for forcing a sending even if analog sensor readings are constantly similar (in seconds). #define TIME_LIMIT_ANA 900 + +AnalogIn _analog1(A0); +AnalogIn _analog2(A1); -AnalogMeasurement::AnalogMeasurement(AbstractSmartRest& client, SmartRestTemplate& tpl, long& deviceId, AnalogIn& analog1, - AnalogIn& analog2, DeviceIO& io, DeviceInfo& deviceInfo, DisplayInfo& displayInfo) : +AnalogMeasurement::AnalogMeasurement(AbstractSmartRest& client, + SmartRestTemplate& tpl, + long& deviceId, + DeviceIO& io, + DeviceInfo& deviceInfo, + DisplayInfo& displayInfo) : + _deviceId(deviceId), + _tpl(tpl), _client(client), - _tpl(tpl), - _deviceId(deviceId), - _analog1(analog1), - _analog2(analog2), _io(io), _deviceInfo(deviceInfo), _displayInfo(displayInfo) @@ -43,8 +48,8 @@ bool AnalogMeasurement::run() { extern bool lastSensorReadingSent; - float data[2] = {_analog1.read()*100, _analog2.read()*100}; - + float data[2] = {(float)_analog1*100, (float)_analog2*100}; + if (abs(oldValues[0]-data[0]) <= abs(oldValues[0])*THRESHOLD_PERCENT_ANA && abs(oldValues[1]-data[1]) <= abs(oldValues[1])*THRESHOLD_PERCENT_ANA) { if (sendingTimer.read() < TIME_LIMIT_ANA) { @@ -57,9 +62,9 @@ return true; } else { aDebug("Analog sensor timed out at %f s, a sending is forced.\r\n", sendingTimer.read()); - } + } } - + // printf("[Y] %f, %f (%f, %f)\r\n", data[0], data[1], oldValues[0], oldValues[1]); char status[25] = {0}; snprintf(status, 25, "Sending Poti %.1f,%.1f", data[0], data[1]);
--- a/measurement/AnalogMeasurement.h Mon Mar 16 12:12:04 2015 +0000 +++ b/measurement/AnalogMeasurement.h Fri Mar 20 13:55:21 2015 +0000 @@ -11,7 +11,7 @@ class AnalogMeasurement { public: - AnalogMeasurement(AbstractSmartRest&, SmartRestTemplate&, long&, AnalogIn&, AnalogIn&, DeviceIO&, DeviceInfo&, DisplayInfo&); + AnalogMeasurement(AbstractSmartRest&, SmartRestTemplate&, long&, DeviceIO&, DeviceInfo&, DisplayInfo&); bool init(); bool run(); @@ -21,8 +21,6 @@ long& _deviceId; SmartRestTemplate& _tpl; AbstractSmartRest& _client; - AnalogIn& _analog1; - AnalogIn& _analog2; float oldValues[2]; Timer sendingTimer; DeviceIO& _io;
--- a/measurement/TemperatureMeasurement.cpp Mon Mar 16 12:12:04 2015 +0000 +++ b/measurement/TemperatureMeasurement.cpp Fri Mar 20 13:55:21 2015 +0000 @@ -9,12 +9,12 @@ // Time interval for forcing a sending even if analog sensor readings are constantly similar (in seconds). #define TIME_LIMIT_TEMP 900 -TemperatureMeasurement::TemperatureMeasurement(AbstractSmartRest& client, SmartRestTemplate& tpl, long& deviceId, LM75B& sensor, - DeviceIO& io, DeviceInfo& deviceInfo, DisplayInfo& displayInfo) : +TemperatureMeasurement::TemperatureMeasurement(AbstractSmartRest& client, SmartRestTemplate& tpl, + long& deviceId, DeviceIO& io, DeviceInfo& deviceInfo, DisplayInfo& displayInfo) : + _deviceId(deviceId), + _tpl(tpl), _client(client), - _tpl(tpl), - _deviceId(deviceId), - _sensor(sensor), + _sensor(D14,D15), oldValue(0), _io(io), _deviceInfo(deviceInfo),
--- a/measurement/TemperatureMeasurement.h Mon Mar 16 12:12:04 2015 +0000 +++ b/measurement/TemperatureMeasurement.h Fri Mar 20 13:55:21 2015 +0000 @@ -11,8 +11,8 @@ class TemperatureMeasurement { public: - TemperatureMeasurement(AbstractSmartRest&, SmartRestTemplate&, long&, LM75B&, DeviceIO&, DeviceInfo&, DisplayInfo&); - + TemperatureMeasurement(AbstractSmartRest&, SmartRestTemplate&, long&, DeviceIO&, DeviceInfo&, DisplayInfo&); + bool init(); bool run(); @@ -21,7 +21,7 @@ long& _deviceId; SmartRestTemplate& _tpl; AbstractSmartRest& _client; - LM75B& _sensor; + LM75B _sensor; float oldValue; Timer sendingTimer; DeviceIO& _io;
--- a/operation/OperationExecutor.cpp Mon Mar 16 12:12:04 2015 +0000 +++ b/operation/OperationExecutor.cpp Fri Mar 20 13:55:21 2015 +0000 @@ -139,7 +139,9 @@ // _io.lcdPrint(msg); extern bool lastSensorReadingSent; _displayInfo.setFirstLine(message); + puts("setted first line"); _io.lcdPrint(message); + puts("printed io message"); lastSensorReadingSent=true; return true; }
--- a/operation/OperationSupport.cpp Mon Mar 16 12:12:04 2015 +0000 +++ b/operation/OperationSupport.cpp Fri Mar 20 13:55:21 2015 +0000 @@ -89,6 +89,10 @@ if (!operationFromRecord(received, op)) continue; _store.enqueue(op); +// _store.takePending(op); +// updateOperation(op); +// bool b = _executor.executeOperation(op); +// _store.markAsDone(op, b); } _client.stop(); @@ -123,14 +127,14 @@ op.state = OPERATION_PENDING; else return false; - + return true; } bool OperationSupport::updateOperation(OperationStore::Operation& op) { ComposedRecord record; - ParsedRecord received; + ParsedRecord received; IntegerValue msgId(111); IntegerValue operationId(op.identifier); if ((!record.add(msgId)) || (!record.add(operationId)) || @@ -141,10 +145,9 @@ _client.stop(); return false; } - + puts("UP: sent record!"); bool found = false; - uint8_t ret; - while ((ret = _client.receive(received)) == SMARTREST_SUCCESS) { + while (_client.receive(received) == SMARTREST_SUCCESS) { if ((received.values() == 4) && (received.value(0).valueType() == VALUE_INTEGER) && (received.value(0).integerValue() == 211) && @@ -154,8 +157,8 @@ break; } } + puts("UP: received record!"); _client.stop(); - return found; } @@ -185,11 +188,13 @@ if (!_store.takePending(op)) { Thread::yield(); continue; - } - + } // printf("Thread 1: %l, %s, %u\r\n", op.identifier, op.descriptor, op.state); + puts("Updating op"); updateOperation(op); + puts("Updated op"); ret = _executor.executeOperation(op); + puts("Executed op"); _store.markAsDone(op, ret); } } @@ -222,6 +227,7 @@ continue; } + puts("Sending aggr"); if (_client.send(aggr) != SMARTREST_SUCCESS) { } _client.stop(); aggr.clear(); @@ -297,11 +303,22 @@ continue; } + puts("Receiving op"); while (_client.receive(received) == SMARTREST_SUCCESS) { if (!operationFromRecord(received, op)) continue; + puts("Parsed record"); // printf("Thread 3: %l, %s, %u\r\n", op.identifier, op.descriptor, op.state); _store.enqueue(op); + puts("Enqueued op"); +// _store.takePending(op); +// puts("Updating op"); +// updateOperation(op); +// puts("Updated op"); +// bool ret = _executor.executeOperation(op); +// puts("Executed op"); +// _store.markAsDone(op, ret); +// puts("Marked"); } //TODO: error checking
--- a/operation/OperationSupport.h Mon Mar 16 12:12:04 2015 +0000 +++ b/operation/OperationSupport.h Fri Mar 20 13:55:21 2015 +0000 @@ -41,7 +41,9 @@ AbstractSmartRest& _client; OperationStore _store; OperationExecutor _executor; - Thread _thread1, _thread2, _thread3; + Thread _thread1; + Thread _thread2; + Thread _thread3; }; extern CharValue aOperationStatePending;