GPS (time, longitude, latitude)

Dependencies:   mbed

main.cpp

Committer:
wasaco
Date:
2015-04-25
Revision:
0:03a95da99c41
Child:
1:c9f46190f418

File content as of revision 0:03a95da99c41:

#include "mbed.h"
 
DigitalOut mled0(LED1);
DigitalOut mled1(LED2);
 
Serial pc(SERIAL_TX, SERIAL_RX); // tx, rx 
Serial gps(PA_9, PA_10);// tx, rx
 
int main() {
 
      int i,rlock;
      char gps_data[256];
      char ns,ew;
      float time,hokui,tokei;
      
      gps.baud(4800);
      pc.printf("gps start! \r\n");

 
    while (1) {
      i=0;
      while(gps.getc()!='$'){
      }
      
      while( (gps_data[i]=gps.getc()) != '\r'){
        i++;
        if(i==256){
           pc.printf("*** Div Error! ***\r\n");
           i=255;
           break;
         }
      }
      gps_data[i]='\0';
      
      if( sscanf(gps_data, "GPGGA,%f,%f,%c,%f,%c,%d",&time,&hokui,&ns,&tokei,&ew,&rlock) >= 1){
        if(rlock==1){
          pc.printf("*** GPS received!! ***\r\n"); 
          pc.printf("Status:Lock(%d)\r\n",rlock);  
         // logitude 
          pc.printf("Tokei:%4.5f\r\n",tokei);
         // Latitude
          pc.printf("Hokui:%4.5f\r\n",hokui);
          
        }
        else{
          pc.printf("Status:unLock(%d)\r\n",rlock);
          for(i=0;i<40;i++){
            pc.printf("%c",gps_data[i]);
          }
        }
      }//if
    }//while
}//main