GPS (time, longitude, latitude)

Dependencies:   mbed

Committer:
wasaco
Date:
Sat Apr 25 02:59:08 2015 +0000
Revision:
0:03a95da99c41
Child:
1:c9f46190f418
hokui, tokei

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wasaco 0:03a95da99c41 1 #include "mbed.h"
wasaco 0:03a95da99c41 2
wasaco 0:03a95da99c41 3 DigitalOut mled0(LED1);
wasaco 0:03a95da99c41 4 DigitalOut mled1(LED2);
wasaco 0:03a95da99c41 5
wasaco 0:03a95da99c41 6 Serial pc(SERIAL_TX, SERIAL_RX); // tx, rx
wasaco 0:03a95da99c41 7 Serial gps(PA_9, PA_10);// tx, rx
wasaco 0:03a95da99c41 8
wasaco 0:03a95da99c41 9 int main() {
wasaco 0:03a95da99c41 10
wasaco 0:03a95da99c41 11 int i,rlock;
wasaco 0:03a95da99c41 12 char gps_data[256];
wasaco 0:03a95da99c41 13 char ns,ew;
wasaco 0:03a95da99c41 14 float time,hokui,tokei;
wasaco 0:03a95da99c41 15
wasaco 0:03a95da99c41 16 gps.baud(4800);
wasaco 0:03a95da99c41 17 pc.printf("gps start! \r\n");
wasaco 0:03a95da99c41 18
wasaco 0:03a95da99c41 19
wasaco 0:03a95da99c41 20 while (1) {
wasaco 0:03a95da99c41 21 i=0;
wasaco 0:03a95da99c41 22 while(gps.getc()!='$'){
wasaco 0:03a95da99c41 23 }
wasaco 0:03a95da99c41 24
wasaco 0:03a95da99c41 25 while( (gps_data[i]=gps.getc()) != '\r'){
wasaco 0:03a95da99c41 26 i++;
wasaco 0:03a95da99c41 27 if(i==256){
wasaco 0:03a95da99c41 28 pc.printf("*** Div Error! ***\r\n");
wasaco 0:03a95da99c41 29 i=255;
wasaco 0:03a95da99c41 30 break;
wasaco 0:03a95da99c41 31 }
wasaco 0:03a95da99c41 32 }
wasaco 0:03a95da99c41 33 gps_data[i]='\0';
wasaco 0:03a95da99c41 34
wasaco 0:03a95da99c41 35 if( sscanf(gps_data, "GPGGA,%f,%f,%c,%f,%c,%d",&time,&hokui,&ns,&tokei,&ew,&rlock) >= 1){
wasaco 0:03a95da99c41 36 if(rlock==1){
wasaco 0:03a95da99c41 37 pc.printf("*** GPS received!! ***\r\n");
wasaco 0:03a95da99c41 38 pc.printf("Status:Lock(%d)\r\n",rlock);
wasaco 0:03a95da99c41 39 // logitude
wasaco 0:03a95da99c41 40 pc.printf("Tokei:%4.5f\r\n",tokei);
wasaco 0:03a95da99c41 41 // Latitude
wasaco 0:03a95da99c41 42 pc.printf("Hokui:%4.5f\r\n",hokui);
wasaco 0:03a95da99c41 43
wasaco 0:03a95da99c41 44 }
wasaco 0:03a95da99c41 45 else{
wasaco 0:03a95da99c41 46 pc.printf("Status:unLock(%d)\r\n",rlock);
wasaco 0:03a95da99c41 47 for(i=0;i<40;i++){
wasaco 0:03a95da99c41 48 pc.printf("%c",gps_data[i]);
wasaco 0:03a95da99c41 49 }
wasaco 0:03a95da99c41 50 }
wasaco 0:03a95da99c41 51 }//if
wasaco 0:03a95da99c41 52 }//while
wasaco 0:03a95da99c41 53 }//main
wasaco 0:03a95da99c41 54