Edward Ho Wee Jin
/
GPS
GPS with altitudes
Fork of GPS by
main.cpp
- Committer:
- hokyung
- Date:
- 2016-03-18
- Revision:
- 3:702fee8fe3a0
- Parent:
- 2:addb687a4e73
File content as of revision 3:702fee8fe3a0:
#include "mbed.h" #include <Serial.h> #include "getline.h" Serial pc(USBTX, USBRX); //GPS gps(p13, p14); Serial uart1(p13, p14); //pin RX et TX du GPS char c; int event_callback_t ; int event; unsigned char char_match ; char msg[1000]; /** The longitude (call sample() to set) */ float longitude; /** The latitude (call sample() to set) */ float latitude,time2,altitude, precision; char ns, ew; int lock, satellites; int main() { uart1.baud(9600); //vitesse de transmission de informations printf("hello\n"); //test while (1){ if (uart1.readable()) { getline(uart1,msg,999); if ( sscanf(msg, "$GPGGA,%f,%f,%c,%f,%c,%d,%d,%f,%f", &time2, &latitude, &ns, &longitude, &ew, &lock , &satellites, &precision, &altitude)>=1) { if(!lock) { longitude = 0.0; latitude = 0.0; altitude = 0.0; pc.printf("long= %f %c latitude= %f %c altitude= %f\n",longitude, ew, latitude, ns, altitude); } else { if(ns == 'S') { latitude *= -1.0; } if(ew == 'W') { longitude *= -1.0; } float degrees =(latitude / 100.0f); float minutes = latitude - (degrees * 100.0f); latitude = degrees + minutes / 60.0f; degrees = (longitude / 100.0f * 0.01f); minutes = longitude - (degrees * 100.0f); longitude = degrees + minutes / 60.0f; pc.printf("time = %f \n", time2); 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); }//end else }//end if }//end if } //end while } //end main /* c=uart1.getc(); pc.printf("%c",c); */ /* } */ /* while(1) { //wait(1.0); //printf("hello bis\n"); if(gps.sample()) { printf("I'm at %f, %f\n", gps.longitude, gps.latitude); } else { printf("Oh Dear! No lock :(\n"); } } } // Print "Hello World" to the PC #include "mbed.h" */