Own fork of MbedSmartRestMain

Dependencies:   C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed

Fork of MbedSmartRestMain by Cumulocity Official

Revision:
73:313975bfec96
Parent:
72:c5709ae7b193
Child:
74:ca3001991fdc
--- a/measurement/AnalogMeasurement.cpp	Mon Feb 16 13:15:52 2015 +0000
+++ b/measurement/AnalogMeasurement.cpp	Tue Feb 17 16:31:30 2015 +0000
@@ -6,14 +6,19 @@
 #include "logging.h"
 
 #define THRESHOLD_PERCENT_ANA 0.05       // Percentage cut-off for avoiding sending similar analog sensor data.
-#define TIME_LIMIT_ANA 900               // Time interval for forcing a sending even if analog sensor readings are constantly similar.
+// Time interval for forcing a sending even if analog sensor readings are constantly similar (in seconds).
+#define TIME_LIMIT_ANA 900               
 
-AnalogMeasurement::AnalogMeasurement(AbstractSmartRest& client, SmartRestTemplate& tpl, long& deviceId, AnalogIn& analog1, AnalogIn& analog2) :
+AnalogMeasurement::AnalogMeasurement(AbstractSmartRest& client, SmartRestTemplate& tpl, long& deviceId, AnalogIn& analog1,
+    AnalogIn& analog2, DeviceIO& io, DeviceInfo& deviceInfo, DeviceBootstrap& bootstrap) :
     _client(client),
     _tpl(tpl),
     _deviceId(deviceId),
     _analog1(analog1),
-    _analog2(analog2)
+    _analog2(analog2),
+    _io(io),
+    _deviceInfo(deviceInfo),
+   _bootstrap(bootstrap)
 {
     _init = false;
     oldValues[0] = 0;
@@ -40,16 +45,24 @@
     float data[2] = {0, 0};
     data[0] = _analog1.read()*100;
     data[1] = _analog2.read()*100;
+    char tenant[25] = {0};
+    snprintf(tenant, 25, "Tenant: %s", _bootstrap.username());
+    char signal[25] = {0};
+    snprintf(signal, 25, "Network: %d dBm", _deviceInfo.signalQuality()->rssi);
     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) {
-            aInfo("Similar analog readings found, no sending!\r\n");
+            aDebug("Similar analog readings found, no sending!\r\n");
+            _io.lcdPrint(tenant, signal);
             return true;
         } else {
-            aInfo("Sending timer of analog sensor timed out at %f s, a sending is forced.\r\n", sendingTimer.read());
+            aDebug("Sending timer of analog sensor timed out at %f s, a sending is forced.\r\n", sendingTimer.read());
         } 
     }
-
+    
+    char status[25] = {0};
+    snprintf(status, 25, "Sending Ana %.1f,%.1f", data[0], data[1]);
+    _io.lcdPrint(tenant, signal, status);
     ComposedRecord record;
     IntegerValue msgId(107);
     IntegerValue devId(_deviceId);
@@ -58,15 +71,17 @@
     if ((!record.add(msgId)) || (!record.add(devId)) || (!record.add(analog1)) || (!record.add(analog2)))
         return false;
 
+    float t_start = sendingTimer.read();
     if (_client.send(record) != SMARTREST_SUCCESS) {
         aError("Signal measurement failed.");
         _client.stop();
         return false;
     }
+    float t_end = sendingTimer.read();
     _client.stop();
+    aInfo("Acceleration readings sent in %.1f.\r\n", t_end-t_start);
     oldValues[0] = data[0];
     oldValues[1] = data[1];
     sendingTimer.reset();
-    aInfo("Analog readings sent.\r\n");    
     return true;
 }