Library for ublox neo 6m

Dependents:   Program

Committer:
sliackystefan
Date:
Wed Mar 20 11:17:37 2019 +0000
Revision:
1:7908d7196d1e
Parent:
0:8f2e256775d7
aaa

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fookies 0:8f2e256775d7 1 /* mbed EM-406 GPS Module Library
fookies 0:8f2e256775d7 2 * Copyright (c) 2008-2010, sford
fookies 0:8f2e256775d7 3 *
fookies 0:8f2e256775d7 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
fookies 0:8f2e256775d7 5 * of this software and associated documentation files (the "Software"), to deal
fookies 0:8f2e256775d7 6 * in the Software without restriction, including without limitation the rights
fookies 0:8f2e256775d7 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
fookies 0:8f2e256775d7 8 * copies of the Software, and to permit persons to whom the Software is
fookies 0:8f2e256775d7 9 * furnished to do so, subject to the following conditions:
fookies 0:8f2e256775d7 10 *
fookies 0:8f2e256775d7 11 * The above copyright notice and this permission notice shall be included in
fookies 0:8f2e256775d7 12 * all copies or substantial portions of the Software.
fookies 0:8f2e256775d7 13 *
fookies 0:8f2e256775d7 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
fookies 0:8f2e256775d7 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
fookies 0:8f2e256775d7 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
fookies 0:8f2e256775d7 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
fookies 0:8f2e256775d7 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
fookies 0:8f2e256775d7 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
fookies 0:8f2e256775d7 20 * THE SOFTWARE.
fookies 0:8f2e256775d7 21 */
fookies 0:8f2e256775d7 22
fookies 0:8f2e256775d7 23 #include "GPS.h"
fookies 0:8f2e256775d7 24
fookies 0:8f2e256775d7 25 GPS::GPS(PinName tx, PinName rx) : _gps(tx, rx) {
fookies 0:8f2e256775d7 26 //_gps.baud(4800);
fookies 0:8f2e256775d7 27 longitude = 0.0;
fookies 0:8f2e256775d7 28 latitude = 0.0;
sliackystefan 1:7908d7196d1e 29 longitudeA = 0.0;
sliackystefan 1:7908d7196d1e 30 latitudeB = 0.0;
fookies 0:8f2e256775d7 31 }
fookies 0:8f2e256775d7 32
fookies 0:8f2e256775d7 33 int GPS::sample() {
fookies 0:8f2e256775d7 34 float time;
fookies 0:8f2e256775d7 35 char ns, ew;
fookies 0:8f2e256775d7 36 int lock;
fookies 0:8f2e256775d7 37
fookies 0:8f2e256775d7 38 //return 1; //testing by Jigar
fookies 0:8f2e256775d7 39 while (1) {
fookies 0:8f2e256775d7 40 getline();
fookies 0:8f2e256775d7 41 //printf("\n\rentered the GPS.sample while loop \n\r %s\n\r", msg);
fookies 0:8f2e256775d7 42
fookies 0:8f2e256775d7 43
fookies 0:8f2e256775d7 44 // Check if it is a GPGGA msg (matches both locked and non-locked msg)
fookies 0:8f2e256775d7 45 // $GPGGA,000116.031,,,,,0,00,,,M,0.0,M,,0000*52
fookies 0:8f2e256775d7 46 /*
fookies 0:8f2e256775d7 47 eg3. $GPGGA,hhmmss.ss,llll.ll,a,yyyyy.yy,a,x,xx,x.x,x.x,M,x.x,M,x.x,xxxx*hh
fookies 0:8f2e256775d7 48 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
fookies 0:8f2e256775d7 49 1 = UTC of Position
fookies 0:8f2e256775d7 50 2 = Latitude
fookies 0:8f2e256775d7 51 3 = N or S
fookies 0:8f2e256775d7 52 4 = Longitude
fookies 0:8f2e256775d7 53 5 = E or W
fookies 0:8f2e256775d7 54 6 = GPS quality indicator (0=invalid; 1=GPS fix; 2=Diff. GPS fix)
fookies 0:8f2e256775d7 55 7 = Number of satellites in use [not those in view]
fookies 0:8f2e256775d7 56 8 = Horizontal dilution of position
fookies 0:8f2e256775d7 57 9 = Antenna altitude above/below mean sea level (geoid)
fookies 0:8f2e256775d7 58 10 = Meters (Antenna height unit)
fookies 0:8f2e256775d7 59 11 = Geoidal separation (Diff. between WGS-84 earth ellipsoid and
fookies 0:8f2e256775d7 60 mean sea level. -=geoid is below WGS-84 ellipsoid)
fookies 0:8f2e256775d7 61 12 = Meters (Units of geoidal separation)
fookies 0:8f2e256775d7 62 13 = Age in seconds since last update from diff. reference station
fookies 0:8f2e256775d7 63 14 = Diff. reference station ID#
fookies 0:8f2e256775d7 64 15 = Checksum
fookies 0:8f2e256775d7 65
fookies 0:8f2e256775d7 66 */
fookies 0:8f2e256775d7 67 // if (sscanf(msg, "GPGGA,%f,%f,%c,%f,%c,%*d,%*d, %*f,%*f,%*f,%*f,%*f,%*f,%d ", &time, &latitude, &ns, &longitude, &ew, &lock) >= 1) {
sliackystefan 1:7908d7196d1e 68 //fgets(msg, 256, stdin);
fookies 0:8f2e256775d7 69 if(sscanf(msg, "GPGGA,%f,%f,%c,%f,%c,%d", &time, &latitude, &ns, &longitude, &ew, &lock) >= 1) {
fookies 0:8f2e256775d7 70
fookies 0:8f2e256775d7 71 if (!lock)
fookies 0:8f2e256775d7 72 {
fookies 0:8f2e256775d7 73 longitude = 0.0;
fookies 0:8f2e256775d7 74 latitude = 0.0;
fookies 0:8f2e256775d7 75 utc=0.0;
fookies 0:8f2e256775d7 76 return 0;
fookies 0:8f2e256775d7 77 }
fookies 0:8f2e256775d7 78 else
fookies 0:8f2e256775d7 79 {
fookies 0:8f2e256775d7 80 if (ns == 'S') {
fookies 0:8f2e256775d7 81 latitude *= -1.0;
fookies 0:8f2e256775d7 82 }
fookies 0:8f2e256775d7 83 if (ew == 'W') {
fookies 0:8f2e256775d7 84 longitude *= -1.0;
fookies 0:8f2e256775d7 85 }
sliackystefan 1:7908d7196d1e 86 longitudeA = longitude / 100.000f;
sliackystefan 1:7908d7196d1e 87 latitudeB = latitude / 100.000f;
sliackystefan 1:7908d7196d1e 88 float degrees = trunc(latitude / 100.000f);
sliackystefan 1:7908d7196d1e 89 float minutes = latitude - (degrees * 100.000f);
sliackystefan 1:7908d7196d1e 90 latitude = degrees + minutes / 60.000f;
sliackystefan 1:7908d7196d1e 91 degrees = trunc(longitude / 100.000f ); //degrees = trunc(longitude / 100.0f * 0.01f);
sliackystefan 1:7908d7196d1e 92 minutes = longitude - (degrees * 100.000f);
sliackystefan 1:7908d7196d1e 93 longitude = degrees + minutes / 60.000f;
fookies 0:8f2e256775d7 94 utc=time;
fookies 0:8f2e256775d7 95 return 1;
fookies 0:8f2e256775d7 96 }
fookies 0:8f2e256775d7 97 }
fookies 0:8f2e256775d7 98 return 0;
fookies 0:8f2e256775d7 99 }
fookies 0:8f2e256775d7 100 }
fookies 0:8f2e256775d7 101
fookies 0:8f2e256775d7 102 float GPS::trunc(float v) {
sliackystefan 1:7908d7196d1e 103 /* if (v < 0.0) {
fookies 0:8f2e256775d7 104 v*= -1.0;
fookies 0:8f2e256775d7 105 v = floor(v);
fookies 0:8f2e256775d7 106 v*=-1.0;
fookies 0:8f2e256775d7 107 } else {
fookies 0:8f2e256775d7 108 v = floor(v);
sliackystefan 1:7908d7196d1e 109 }*/
fookies 0:8f2e256775d7 110 return v;
fookies 0:8f2e256775d7 111 }
fookies 0:8f2e256775d7 112
fookies 0:8f2e256775d7 113 void GPS::getline() {
fookies 0:8f2e256775d7 114 char c;
fookies 0:8f2e256775d7 115 while (c = _gps.getc() != '$'); // wait for the start of a line
fookies 0:8f2e256775d7 116 // printf("entered the getline loop\n\r");
fookies 0:8f2e256775d7 117 for (int i=0; i<256; i++) {
fookies 0:8f2e256775d7 118 msg[i] = _gps.getc();
fookies 0:8f2e256775d7 119 if (msg[i] == '\r') {
fookies 0:8f2e256775d7 120 msg[i] = 0;
fookies 0:8f2e256775d7 121 return;
fookies 0:8f2e256775d7 122 }
fookies 0:8f2e256775d7 123 }
fookies 0:8f2e256775d7 124 error("Overflowed message limit");
fookies 0:8f2e256775d7 125 }
fookies 0:8f2e256775d7 126
fookies 0:8f2e256775d7 127 /*
fookies 0:8f2e256775d7 128 $GPRMC,000115.039,V,,,,,,,291006,,*2C
fookies 0:8f2e256775d7 129 $GPGGA,000116.031,,,,,0,00,,,M,0.0,M,,0000*52
fookies 0:8f2e256775d7 130 $GPGSA,A,1,,,,,,,,,,,,,,,*1E
fookies 0:8f2e256775d7 131 $GPGSV,3,1,12,20,00,000,,10,00,000,,31,00,000,,27,00,000,*7C
fookies 0:8f2e256775d7 132 $GPGSV,3,2,12,19,00,000,,07,00,000,,04,00,000,,24,00,000,*76
fookies 0:8f2e256775d7 133 $GPGSV,3,3,12,16,00,000,,28,00,000,,26,00,000,,29,00,000,*78
fookies 0:8f2e256775d7 134 $GPRMC,000116.031,V,,,,,,,291006,,*27
fookies 0:8f2e256775d7 135 $GPGGA,000117.035,,,,,0,00,,,M,0.0,M,,0000*57
fookies 0:8f2e256775d7 136 $GPGSA,A,1,,,,,,,,,,,,,,,*1E
fookies 0:8f2e256775d7 137 $GPRMC,000117.035,V,,,,,,,291006,,*22
fookies 0:8f2e256775d7 138 $GPGGA,000118.039,,,,,0,00,,,M,0.0,M,,0000*54
fookies 0:8f2e256775d7 139 $GPGSA,A,1,,,,,,,,,,,,,,,*1E
fookies 0:8f2e256775d7 140 $GPRMC,000118.039,V,,,,,,,291006,,*21
fookies 0:8f2e256775d7 141 $GPGGA,000119.035,,,,,0,00,,,M,0.0,M,,0000*59
fookies 0:8f2e256775d7 142 $GPGSA,A,1,,,,,,,,,,,,,,,*1E
fookies 0:8f2e256775d7 143 $GPRMC,000119.035,V,,,,,,,291006,,*2C
fookies 0:8f2e256775d7 144 $GPGGA,000120.037,,,,,0,00,,,M,0.0,M,,0000*51
fookies 0:8f2e256775d7 145 $GPGSA,A,1,,,,,,,,,,,,,,,*1E
fookies 0:8f2e256775d7 146 $GPRMC,000120.037,V,,,,,,,291006,,*24
fookies 0:8f2e256775d7 147
fookies 0:8f2e256775d7 148 */