![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Own fork of MbedSmartRestMain
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
measurement/Location.cpp@138:f8ab852e83e7, 2016-08-08 (annotated)
- Committer:
- xinlei
- Date:
- Mon Aug 08 11:05:57 2016 +0000
- Revision:
- 138:f8ab852e83e7
- Parent:
- 136:a52821cdb108
Etisalat and Teleena APN.
Who changed what in which revision?
User | Revision | Line number | New 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 | 123:311fa85af2b3 | 11 | static inline bool valueChanged(float *V0, float *V1) |
xinlei | 123:311fa85af2b3 | 12 | { |
xinlei | 123:311fa85af2b3 | 13 | if (abs(V0[0]-V1[0]) <= abs(V0[0])*THRESHOLD_PERCENT_LOC && |
xinlei | 123:311fa85af2b3 | 14 | abs(V0[1]-V1[1]) <= abs(V0[1])*THRESHOLD_PERCENT_LOC && |
xinlei | 123:311fa85af2b3 | 15 | abs(V0[2]-V1[2]) <= abs(V0[2])*THRESHOLD_PERCENT_LOC) |
xinlei | 123:311fa85af2b3 | 16 | return false; |
xinlei | 123:311fa85af2b3 | 17 | else |
xinlei | 123:311fa85af2b3 | 18 | return true; |
xinlei | 123:311fa85af2b3 | 19 | } |
xinlei | 123:311fa85af2b3 | 20 | |
xinlei | 136:a52821cdb108 | 21 | int Location::read(char *buf, size_t maxLen, char *status, size_t num) |
xinlei | 100:dbcd3bc51758 | 22 | { |
xinlei | 100:dbcd3bc51758 | 23 | static const char *fmt = "108,%ld,%.2f,%.6f,%.6f\r\n109,%ld,%.2f,%.6f,%.6f"; |
xinlei | 100:dbcd3bc51758 | 24 | GPSTracker::Position pos; |
xinlei | 100:dbcd3bc51758 | 25 | if (!gpsTracker.position(&pos)) { |
xinlei | 100:dbcd3bc51758 | 26 | return 0; |
xinlei | 100:dbcd3bc51758 | 27 | } |
xinlei | 123:311fa85af2b3 | 28 | float data[3] = { pos.altitude, pos.latitude, pos.longitude }; |
xinlei | 100:dbcd3bc51758 | 29 | |
xinlei | 123:311fa85af2b3 | 30 | float t_interval = timer.read(); |
xinlei | 123:311fa85af2b3 | 31 | if (!valueChanged(oldValues, data) && t_interval < TIME_LIMIT_LOC) { |
xinlei | 123:311fa85af2b3 | 32 | return 0; |
xinlei | 100:dbcd3bc51758 | 33 | } |
xinlei | 123:311fa85af2b3 | 34 | |
xinlei | 100:dbcd3bc51758 | 35 | size_t l = snprintf(buf, maxLen, fmt, deviceID, data[0], data[1], |
xinlei | 100:dbcd3bc51758 | 36 | data[2], deviceID, data[0], data[1], data[2]); |
xinlei | 100:dbcd3bc51758 | 37 | if (status) { |
xinlei | 100:dbcd3bc51758 | 38 | snprintf(status, num, "Send GPS %.1f,%.1f,%.1f", |
xinlei | 100:dbcd3bc51758 | 39 | data[0], data[1], data[2]); |
xinlei | 100:dbcd3bc51758 | 40 | } |
xinlei | 100:dbcd3bc51758 | 41 | oldValues[0] = data[0]; |
xinlei | 100:dbcd3bc51758 | 42 | oldValues[1] = data[1]; |
xinlei | 100:dbcd3bc51758 | 43 | oldValues[2] = data[2]; |
xinlei | 123:311fa85af2b3 | 44 | timer.reset(); |
xinlei | 100:dbcd3bc51758 | 45 | return l; |
xinlei | 100:dbcd3bc51758 | 46 | } |