Own fork of MbedSmartRestMain

Dependencies:   C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed

Fork of MbedSmartRestMain by Cumulocity Official

Committer:
xinlei
Date:
Fri May 08 12:19:57 2015 +0000
Revision:
100:dbcd3bc51758
Child:
117:e831cdb799ab
v2.1rc3

Who changed what in which revision?

UserRevisionLine numberNew contents of line
xinlei 100:dbcd3bc51758 1 #include <stdio.h>
xinlei 100:dbcd3bc51758 2 #include "Location.h"
xinlei 100:dbcd3bc51758 3 #include "SmartRestConf.h"
xinlei 100:dbcd3bc51758 4 #include "logging.h"
xinlei 100:dbcd3bc51758 5
xinlei 100:dbcd3bc51758 6 // Percentage cut-off for avoiding sending similar sensor readings.
xinlei 100:dbcd3bc51758 7 #define THRESHOLD_PERCENT_LOC 0.05
xinlei 100:dbcd3bc51758 8 // Timeout for forcing a sending even if readings are similar [seconds].
xinlei 100:dbcd3bc51758 9 #define TIME_LIMIT_LOC 900
xinlei 100:dbcd3bc51758 10
xinlei 100:dbcd3bc51758 11 size_t Location::read(char *buf, size_t maxLen, char *status, size_t num)
xinlei 100:dbcd3bc51758 12 {
xinlei 100:dbcd3bc51758 13 static const char *fmt = "108,%ld,%.2f,%.6f,%.6f\r\n109,%ld,%.2f,%.6f,%.6f";
xinlei 100:dbcd3bc51758 14 GPSTracker::Position pos;
xinlei 100:dbcd3bc51758 15 if (!gpsTracker.position(&pos)) {
xinlei 100:dbcd3bc51758 16 return 0;
xinlei 100:dbcd3bc51758 17 }
xinlei 100:dbcd3bc51758 18 float data[3] = { pos.altitude, pos.latitude,
xinlei 100:dbcd3bc51758 19 pos.longitude };
xinlei 100:dbcd3bc51758 20
xinlei 100:dbcd3bc51758 21 if (abs(oldValues[0]-data[0]) <= abs(oldValues[0])*THRESHOLD_PERCENT_LOC &&
xinlei 100:dbcd3bc51758 22 abs(oldValues[1]-data[1]) <= abs(oldValues[1])*THRESHOLD_PERCENT_LOC &&
xinlei 100:dbcd3bc51758 23 abs(oldValues[2]-data[2]) <= abs(oldValues[2])*THRESHOLD_PERCENT_LOC) {
xinlei 100:dbcd3bc51758 24 time_t t_interval = time(NULL) - t_start;
xinlei 100:dbcd3bc51758 25 if (t_interval < TIME_LIMIT_LOC) {
xinlei 100:dbcd3bc51758 26 return 0;
xinlei 100:dbcd3bc51758 27 } else {
xinlei 100:dbcd3bc51758 28 aDebug("GPS: Timeout at %d s.\n", t_interval);
xinlei 100:dbcd3bc51758 29 }
xinlei 100:dbcd3bc51758 30 }
xinlei 100:dbcd3bc51758 31 size_t l = snprintf(buf, maxLen, fmt, deviceID, data[0], data[1],
xinlei 100:dbcd3bc51758 32 data[2], deviceID, data[0], data[1], data[2]);
xinlei 100:dbcd3bc51758 33 if (status) {
xinlei 100:dbcd3bc51758 34 snprintf(status, num, "Send GPS %.1f,%.1f,%.1f",
xinlei 100:dbcd3bc51758 35 data[0], data[1], data[2]);
xinlei 100:dbcd3bc51758 36 }
xinlei 100:dbcd3bc51758 37 oldValues[0] = data[0];
xinlei 100:dbcd3bc51758 38 oldValues[1] = data[1];
xinlei 100:dbcd3bc51758 39 oldValues[2] = data[2];
xinlei 100:dbcd3bc51758 40 t_start = time(NULL);
xinlei 100:dbcd3bc51758 41 return l;
xinlei 100:dbcd3bc51758 42 }