Own fork of MbedSmartRestMain
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
Diff: measurement/Location.cpp
- Revision:
- 123:311fa85af2b3
- Parent:
- 117:e831cdb799ab
- Child:
- 136:a52821cdb108
--- a/measurement/Location.cpp Wed May 27 09:22:24 2015 +0000 +++ b/measurement/Location.cpp Fri May 29 12:05:01 2015 +0000 @@ -8,6 +8,16 @@ // Timeout for forcing a sending even if readings are similar [seconds]. #define TIME_LIMIT_LOC 900 +static inline bool valueChanged(float *V0, float *V1) +{ + if (abs(V0[0]-V1[0]) <= abs(V0[0])*THRESHOLD_PERCENT_LOC && + abs(V0[1]-V1[1]) <= abs(V0[1])*THRESHOLD_PERCENT_LOC && + abs(V0[2]-V1[2]) <= abs(V0[2])*THRESHOLD_PERCENT_LOC) + return false; + else + return true; +} + 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"; @@ -15,17 +25,13 @@ if (!gpsTracker.position(&pos)) { return 0; } - float data[3] = { pos.altitude, pos.latitude, - pos.longitude }; + 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; - } + float t_interval = timer.read(); + if (!valueChanged(oldValues, data) && t_interval < TIME_LIMIT_LOC) { + return 0; } + size_t l = snprintf(buf, maxLen, fmt, deviceID, data[0], data[1], data[2], deviceID, data[0], data[1], data[2]); if (status) { @@ -35,6 +41,6 @@ oldValues[0] = data[0]; oldValues[1] = data[1]; oldValues[2] = data[2]; - t_start = time(NULL); + timer.reset(); return l; } \ No newline at end of file