programme GPS pour ERS4

Dependencies:   mbed

Fork of GPS_IUT_Nice by tito tito

main.cpp

Committer:
pierrick
Date:
2016-03-11
Revision:
2:addb687a4e73
Parent:
1:f24af888e699

File content as of revision 2:addb687a4e73:

#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;
    
    char ns, ew;
    int lock;
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", &time2, &latitude, &ns, &longitude, &ew, &lock )>=1)
            {          
                if(!lock) {
                    longitude = 0.0;
                    latitude = 0.0; 
                    pc.printf("long= %f %c  latitude= %f %c\n",&longitude, &ew, &latitude, &ns);   
                } 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\n",longitude, ew, latitude, ns);
              }//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"
*/