GPS (time, longitude, latitude)

Dependencies:   mbed

Revision:
0:03a95da99c41
Child:
1:c9f46190f418
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Apr 25 02:59:08 2015 +0000
@@ -0,0 +1,54 @@
+#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
+ 
\ No newline at end of file