Final

Dependencies:   DebounceIn NokiaLCD WiflyInterface mbed

Fork of Websocket_Wifly_HelloWorld by Samuel Mokrani

Committer:
Ifrah
Date:
Fri Dec 14 15:40:21 2012 +0000
Revision:
5:c4c66c630011
Parent:
3:3c7906d60f89
Final

Who changed what in which revision?

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