GPS with altitudes

Dependencies:   mbed

Fork of GPS by tito tito

Committer:
hokyung
Date:
Fri Mar 18 09:45:06 2016 +0000
Revision:
3:702fee8fe3a0
Parent:
2:addb687a4e73
For Imran

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dreday20 0:2c0686a07ab8 1 #include "mbed.h"
pierrick 1:f24af888e699 2 #include <Serial.h>
pierrick 1:f24af888e699 3 #include "getline.h"
pierrick 2:addb687a4e73 4
dreday20 0:2c0686a07ab8 5 Serial pc(USBTX, USBRX);
pierrick 1:f24af888e699 6 //GPS gps(p13, p14);
dreday20 0:2c0686a07ab8 7
pierrick 2:addb687a4e73 8 Serial uart1(p13, p14); //pin RX et TX du GPS
pierrick 1:f24af888e699 9 char c;
pierrick 1:f24af888e699 10 int event_callback_t ;
pierrick 1:f24af888e699 11 int event;
pierrick 1:f24af888e699 12 unsigned char char_match ;
pierrick 1:f24af888e699 13 char msg[1000];
pierrick 1:f24af888e699 14 /** The longitude (call sample() to set) */
pierrick 1:f24af888e699 15 float longitude;
pierrick 1:f24af888e699 16
pierrick 1:f24af888e699 17 /** The latitude (call sample() to set) */
hokyung 3:702fee8fe3a0 18 float latitude,time2,altitude, precision;
pierrick 1:f24af888e699 19
pierrick 1:f24af888e699 20 char ns, ew;
hokyung 3:702fee8fe3a0 21 int lock, satellites;
hokyung 3:702fee8fe3a0 22
dreday20 0:2c0686a07ab8 23 int main() {
pierrick 2:addb687a4e73 24 uart1.baud(9600); //vitesse de transmission de informations
pierrick 2:addb687a4e73 25 printf("hello\n"); //test
pierrick 1:f24af888e699 26 while (1){
pierrick 1:f24af888e699 27 if (uart1.readable())
pierrick 1:f24af888e699 28 {
pierrick 1:f24af888e699 29
pierrick 1:f24af888e699 30 getline(uart1,msg,999);
hokyung 3:702fee8fe3a0 31 if ( sscanf(msg, "$GPGGA,%f,%f,%c,%f,%c,%d,%d,%f,%f", &time2, &latitude, &ns, &longitude, &ew, &lock , &satellites, &precision, &altitude)>=1)
pierrick 1:f24af888e699 32 {
pierrick 1:f24af888e699 33 if(!lock) {
pierrick 2:addb687a4e73 34 longitude = 0.0;
pierrick 2:addb687a4e73 35 latitude = 0.0;
hokyung 3:702fee8fe3a0 36 altitude = 0.0;
hokyung 3:702fee8fe3a0 37 pc.printf("long= %f %c latitude= %f %c altitude= %f\n",longitude, ew, latitude, ns, altitude);
pierrick 1:f24af888e699 38 } else {
pierrick 2:addb687a4e73 39 if(ns == 'S') { latitude *= -1.0; }
pierrick 2:addb687a4e73 40 if(ew == 'W') { longitude *= -1.0; }
pierrick 2:addb687a4e73 41 float degrees =(latitude / 100.0f);
pierrick 2:addb687a4e73 42 float minutes = latitude - (degrees * 100.0f);
pierrick 2:addb687a4e73 43 latitude = degrees + minutes / 60.0f;
pierrick 2:addb687a4e73 44 degrees = (longitude / 100.0f * 0.01f);
pierrick 2:addb687a4e73 45 minutes = longitude - (degrees * 100.0f);
pierrick 2:addb687a4e73 46 longitude = degrees + minutes / 60.0f;
pierrick 2:addb687a4e73 47 pc.printf("time = %f \n", time2);
hokyung 3:702fee8fe3a0 48 pc.printf("long= %f %c latitude= %f %c altitude= %f(meters) number of satellites= %d precision= %f\n",longitude, ew, latitude, ns, altitude, satellites, precision);
pierrick 1:f24af888e699 49 }//end else
pierrick 1:f24af888e699 50 }//end if
pierrick 1:f24af888e699 51 }//end if
pierrick 1:f24af888e699 52 } //end while
pierrick 1:f24af888e699 53 } //end main
pierrick 1:f24af888e699 54
pierrick 1:f24af888e699 55 /*
pierrick 1:f24af888e699 56 c=uart1.getc();
pierrick 1:f24af888e699 57 pc.printf("%c",c);
pierrick 1:f24af888e699 58 */
pierrick 1:f24af888e699 59 /* }
pierrick 1:f24af888e699 60
pierrick 1:f24af888e699 61
pierrick 1:f24af888e699 62 */
pierrick 1:f24af888e699 63 /*
dreday20 0:2c0686a07ab8 64 while(1) {
pierrick 1:f24af888e699 65 //wait(1.0);
pierrick 1:f24af888e699 66 //printf("hello bis\n");
pierrick 1:f24af888e699 67
dreday20 0:2c0686a07ab8 68 if(gps.sample()) {
pierrick 1:f24af888e699 69 printf("I'm at %f, %f\n", gps.longitude, gps.latitude);
dreday20 0:2c0686a07ab8 70 } else {
pierrick 1:f24af888e699 71 printf("Oh Dear! No lock :(\n");
dreday20 0:2c0686a07ab8 72 }
dreday20 0:2c0686a07ab8 73 }
pierrick 1:f24af888e699 74 }
pierrick 1:f24af888e699 75
pierrick 1:f24af888e699 76
pierrick 1:f24af888e699 77 // Print "Hello World" to the PC
pierrick 1:f24af888e699 78
pierrick 1:f24af888e699 79 #include "mbed.h"
pierrick 1:f24af888e699 80 */
pierrick 1:f24af888e699 81