tito tito / Mbed 2 deprecated GPS_IUT_Nice

Dependencies:   mbed

Fork of GPS by Andre Pasechnyk

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 //#include "GPS.h"
00003 #include <Serial.h>
00004 #include "getline.h"
00005 #include <math.h>
00006 //#include "stream.h"
00007  
00008 Serial pc(USBTX, USBRX);
00009 //GPS gps(p13, p14);
00010  
00011 Serial uart1(p13, p14);
00012 char c;
00013  int event_callback_t ;
00014         int     event;
00015         unsigned char   char_match ;
00016  char msg[1000];
00017   /** The longitude (call sample() to set) */
00018     float longitude;
00019 
00020     /** The latitude (call sample() to set) */
00021     float latitude,time2;
00022     
00023     char ns, ew;
00024     int lock;
00025 int main() {
00026     uart1.baud(9600);
00027     printf("hello\n");
00028     while (1){
00029         if (uart1.readable())
00030          {
00031                 
00032              getline(uart1,msg,999);
00033             // pc.printf("\n %s",msg);
00034       //pc.printf("long= %f %c  latitude= %f %c\n",&longitude, &ew, &latitude, &ns);
00035         // Check if it is a GPGGA msg (matches both locked and non-locked msg)
00036             if ( sscanf(msg, "$GPGGA,%f,%f,%c,%f,%c,%d", &time2, &latitude, &ns, &longitude, &ew, &lock )>=1)
00037             {          
00038                 if(!lock) {
00039                 longitude = 0.0;
00040                 latitude = 0.0; 
00041                 pc.printf("long= %f %c  latitude= %f %c\n",&longitude, &ew, &latitude, &ns);   
00042                 //return 0;
00043                 } else {
00044                 if(ns == 'S') {    latitude  *= -1.0; }
00045                 if(ew == 'W') {    longitude *= -1.0; }
00046                 float degrees =(latitude / 100.0f);
00047                 float minutes = latitude - (degrees * 100.0f);
00048                 latitude = degrees + minutes / 60.0f;    
00049                 degrees = (longitude / 100.0f * 0.01f);
00050                 minutes = longitude - (degrees * 100.0f);
00051                 longitude = degrees + minutes / 60.0f;
00052                 printf("time = %f \n", time2);
00053                 pc.printf("long= %f %c  latitude= %f %c\n",longitude, ew, latitude, ns);
00054                 //return 1;
00055               }//end else
00056            }//end if
00057         }//end if
00058     }  //end while
00059 }  //end main      
00060 
00061              /*
00062          c=uart1.getc();
00063          pc.printf("%c",c);
00064       */
00065        /*  }
00066 
00067         
00068   */      
00069 /*      
00070     while(1) {
00071         //wait(1.0);
00072         //printf("hello bis\n");
00073         
00074         if(gps.sample()) {
00075             printf("I'm at %f, %f\n", gps.longitude, gps.latitude);
00076         } else {
00077             printf("Oh Dear! No lock :(\n");
00078         }
00079     }
00080 }
00081 
00082 
00083 // Print "Hello World" to the PC
00084  
00085 #include "mbed.h"
00086 */
00087