An application to log WiFi SSIDs for position lookup testing

Dependencies:   C027_Support SWO mbed-rtos mbed picojson

Fork of lpc4088_ebb_ublox_Cellular_PubNubDemo_rtos by EmbeddedArtists AB

Committer:
rosterloh84
Date:
Sun Feb 15 22:04:12 2015 +0000
Revision:
1:cac9b2960637
First working version. Lots to do still.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rosterloh84 1:cac9b2960637 1 #include "GPSTracker.h"
rosterloh84 1:cac9b2960637 2 #include <stdlib.h>
rosterloh84 1:cac9b2960637 3 #include <string.h>
rosterloh84 1:cac9b2960637 4
rosterloh84 1:cac9b2960637 5 GPSTracker::GPSTracker(GPSI2C& gps) :
rosterloh84 1:cac9b2960637 6 _gps(gps),
rosterloh84 1:cac9b2960637 7 _thread(GPSTracker::thread_func, this),
rosterloh84 1:cac9b2960637 8 _positionSet(false)
rosterloh84 1:cac9b2960637 9 {
rosterloh84 1:cac9b2960637 10 }
rosterloh84 1:cac9b2960637 11
rosterloh84 1:cac9b2960637 12 bool GPSTracker::position(GPSTracker::Position *position)
rosterloh84 1:cac9b2960637 13 {
rosterloh84 1:cac9b2960637 14 bool result;
rosterloh84 1:cac9b2960637 15
rosterloh84 1:cac9b2960637 16 _mutex.lock();
rosterloh84 1:cac9b2960637 17 if (_positionSet) {
rosterloh84 1:cac9b2960637 18 memcpy(position, &_position, sizeof(GPSTracker::Position));
rosterloh84 1:cac9b2960637 19 _positionSet = false;
rosterloh84 1:cac9b2960637 20 result = true;
rosterloh84 1:cac9b2960637 21 } else {
rosterloh84 1:cac9b2960637 22 result = false;
rosterloh84 1:cac9b2960637 23 }
rosterloh84 1:cac9b2960637 24 _mutex.unlock();
rosterloh84 1:cac9b2960637 25
rosterloh84 1:cac9b2960637 26 return result;
rosterloh84 1:cac9b2960637 27 }
rosterloh84 1:cac9b2960637 28
rosterloh84 1:cac9b2960637 29 void GPSTracker::thread()
rosterloh84 1:cac9b2960637 30 {
rosterloh84 1:cac9b2960637 31 char buf[256], chr; // needs to be that big otherwise mdm isn't working
rosterloh84 1:cac9b2960637 32 int ret, len, n;
rosterloh84 1:cac9b2960637 33 double altitude, latitude, longitude;
rosterloh84 1:cac9b2960637 34
rosterloh84 1:cac9b2960637 35 while (true) {
rosterloh84 1:cac9b2960637 36 ret = _gps.getMessage(buf, sizeof(buf));
rosterloh84 1:cac9b2960637 37 if (ret <= 0) {
rosterloh84 1:cac9b2960637 38 Thread::wait(100);
rosterloh84 1:cac9b2960637 39 continue;
rosterloh84 1:cac9b2960637 40 }
rosterloh84 1:cac9b2960637 41
rosterloh84 1:cac9b2960637 42 len = LENGTH(ret);
rosterloh84 1:cac9b2960637 43 if ((PROTOCOL(ret) != GPSParser::NMEA) || (len <= 6))
rosterloh84 1:cac9b2960637 44 continue;
rosterloh84 1:cac9b2960637 45
rosterloh84 1:cac9b2960637 46 // we're only interested in fixed GPS positions
rosterloh84 1:cac9b2960637 47 // we are not interested in invalid data
rosterloh84 1:cac9b2960637 48 if ((strncmp("$GPGGA", buf, 6) != 0) ||
rosterloh84 1:cac9b2960637 49 (!_gps.getNmeaItem(6, buf, len, n, 10)) || (n == 0))
rosterloh84 1:cac9b2960637 50 continue;
rosterloh84 1:cac9b2960637 51
rosterloh84 1:cac9b2960637 52 // get altitude, latitude and longitude
rosterloh84 1:cac9b2960637 53 if ((!_gps.getNmeaAngle(2, buf, len, latitude)) ||
rosterloh84 1:cac9b2960637 54 (!_gps.getNmeaAngle(4, buf, len, longitude)) ||
rosterloh84 1:cac9b2960637 55 (!_gps.getNmeaItem(9, buf, len, altitude)) ||
rosterloh84 1:cac9b2960637 56 (!_gps.getNmeaItem(10, buf, len, chr)) ||
rosterloh84 1:cac9b2960637 57 (chr != 'M'))
rosterloh84 1:cac9b2960637 58 continue;
rosterloh84 1:cac9b2960637 59
rosterloh84 1:cac9b2960637 60 _mutex.lock();
rosterloh84 1:cac9b2960637 61 _position.altitude = altitude;
rosterloh84 1:cac9b2960637 62 _position.latitude = latitude;
rosterloh84 1:cac9b2960637 63 _position.longitude = longitude;
rosterloh84 1:cac9b2960637 64 _positionSet = true;
rosterloh84 1:cac9b2960637 65 _mutex.unlock();
rosterloh84 1:cac9b2960637 66 }
rosterloh84 1:cac9b2960637 67 }
rosterloh84 1:cac9b2960637 68
rosterloh84 1:cac9b2960637 69 void GPSTracker::thread_func(void const *arg)
rosterloh84 1:cac9b2960637 70 {
rosterloh84 1:cac9b2960637 71 GPSTracker *that;
rosterloh84 1:cac9b2960637 72 that = (GPSTracker*)arg;
rosterloh84 1:cac9b2960637 73 that->thread();
rosterloh84 1:cac9b2960637 74 }