Own fork of MbedSmartRestMain

Dependencies:   C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed

Fork of MbedSmartRestMain by Cumulocity Official

Revision:
100:dbcd3bc51758
Child:
117:e831cdb799ab
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/measurement/Location.cpp	Fri May 08 12:19:57 2015 +0000
@@ -0,0 +1,42 @@
+#include <stdio.h>
+#include "Location.h"
+#include "SmartRestConf.h"
+#include "logging.h"
+
+// Percentage cut-off for avoiding sending similar sensor readings.
+#define THRESHOLD_PERCENT_LOC 0.05
+// Timeout for forcing a sending even if readings are similar [seconds].
+#define TIME_LIMIT_LOC 900
+
+size_t Location::read(char *buf, size_t maxLen, char *status, size_t num)
+{
+        static const char *fmt = "108,%ld,%.2f,%.6f,%.6f\r\n109,%ld,%.2f,%.6f,%.6f";
+        GPSTracker::Position pos;
+        if (!gpsTracker.position(&pos)) {
+                return 0;
+        }
+        float data[3] = { pos.altitude, pos.latitude,
+                          pos.longitude };
+
+        if (abs(oldValues[0]-data[0]) <= abs(oldValues[0])*THRESHOLD_PERCENT_LOC &&
+            abs(oldValues[1]-data[1]) <= abs(oldValues[1])*THRESHOLD_PERCENT_LOC &&
+            abs(oldValues[2]-data[2]) <= abs(oldValues[2])*THRESHOLD_PERCENT_LOC) {
+                time_t t_interval = time(NULL) - t_start;
+                if (t_interval < TIME_LIMIT_LOC) {
+                        return 0;
+                } else {
+                        aDebug("GPS: Timeout at %d s.\n", t_interval);
+                }
+        }
+        size_t l = snprintf(buf, maxLen, fmt, deviceID, data[0], data[1],
+                            data[2], deviceID, data[0], data[1], data[2]);
+        if (status) {
+                snprintf(status, num, "Send GPS %.1f,%.1f,%.1f",
+                         data[0], data[1], data[2]);
+        }
+        oldValues[0] = data[0];
+        oldValues[1] = data[1];
+        oldValues[2] = data[2];
+        t_start = time(NULL);
+        return l;
+}
\ No newline at end of file