Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
Diff: measurement/LocationUpdate.cpp
- Revision:
- 71:063c45e99578
- Parent:
- 58:4cc0ae5a7058
- Child:
- 72:c5709ae7b193
diff -r f489ca11f254 -r 063c45e99578 measurement/LocationUpdate.cpp
--- a/measurement/LocationUpdate.cpp Tue Feb 10 20:52:13 2015 +0000
+++ b/measurement/LocationUpdate.cpp Mon Feb 16 09:17:30 2015 +0000
@@ -5,6 +5,9 @@
#include "IntegerValue.h"
#include "FloatValue.h"
+#define THRESHOLD_PERCENT_LOC 0.05 // Percentage cut-off for avoiding sending similar acceleration sensor data.
+#define TIME_LIMIT_LOC 900 // Time interval for forcing a sending even if acceleration sensor readings are constantly similar.
+
LocationUpdate::LocationUpdate(AbstractSmartRest& client, SmartRestTemplate& tpl, long& deviceId, GPSTracker& gpsTracker) :
_client(client),
_tpl(tpl),
@@ -12,6 +15,10 @@
_gpsTracker(gpsTracker)
{
_init = false;
+ oldValues[0] = 0;
+ oldValues[1] = 0;
+ oldValues[2] = 0;
+ sendingTimer.start();
}
bool LocationUpdate::init()
@@ -41,9 +48,22 @@
puts("No GPS data available.");
return true;
}
+ float data[3] = { 0.0, 0.0, 0.0 };
+ data[0] = position.altitude;
+ data[1] = position.latitude;
+ data[2] = position.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) {
+ if (sendingTimer.read() < TIME_LIMIT_LOC) {
+ printf("Similar location readings found, no sending!\r\n");
+ return true;
+ } else {
+ printf("Sending timer of location sensor timed out at %f s, a sending is forced.\r\n", sendingTimer.read());
+ }
+ }
puts("Starting measurement sending.");
-
Aggregator aggregator;
ComposedRecord record1, record2;
IntegerValue msgId1(108);
@@ -67,5 +87,10 @@
}
_client.stop();
+ oldValues[0] = data[0];
+ oldValues[1] = data[1];
+ oldValues[2] = data[2];
+ sendingTimer.reset();
+ printf("Location readings sent.\r\n");
return true;
}

Cumulocity