Nucleo-F303K8とGPSモジュールを用いた緯度・経度の取得プログラム.

Dependencies:   mbed

Fork of Nucleo_GPS by Kosuke Furumoto

Committer:
Koob
Date:
Tue Aug 16 15:57:35 2016 +0000
Revision:
1:aec45e847ec3
Parent:
0:8889ed33c550
Child:
2:ee6862d07ae9
Nucleo_GPS_Serial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Koob 0:8889ed33c550 1 #include "mbed.h"
Koob 1:aec45e847ec3 2
Koob 1:aec45e847ec3 3 DigitalOut myled(LED1);
Koob 0:8889ed33c550 4 Serial gps(D1, D0); // tx, rx
Koob 0:8889ed33c550 5 Serial pc(USBTX, USBRX); // tx, rx
Koob 0:8889ed33c550 6
Koob 1:aec45e847ec3 7 void pc_rx() {
Koob 0:8889ed33c550 8
Koob 0:8889ed33c550 9 unsigned char c;
Koob 0:8889ed33c550 10 int i,rlock;
Koob 0:8889ed33c550 11 char gps_data[256],gps2_data[256];
Koob 0:8889ed33c550 12 char ns,ew;
Koob 0:8889ed33c550 13 float time,hokui,tokei;
Koob 0:8889ed33c550 14 float g_hokui,g_tokei;
Koob 0:8889ed33c550 15 float d_hokui,m_hokui,d_tokei,m_tokei;
Koob 0:8889ed33c550 16
Koob 0:8889ed33c550 17 gps.baud(9600);
Koob 0:8889ed33c550 18 pc.printf("*** GPS GT-720F ***");
Koob 0:8889ed33c550 19
Koob 0:8889ed33c550 20 while (1) {
Koob 0:8889ed33c550 21 i=0;
Koob 0:8889ed33c550 22 while(gps.getc()!='$'){
Koob 0:8889ed33c550 23 }
Koob 0:8889ed33c550 24
Koob 0:8889ed33c550 25 while((gps_data[i]=gps.getc()) != '\r'){
Koob 0:8889ed33c550 26 i++;
Koob 0:8889ed33c550 27 if(i==256){
Koob 0:8889ed33c550 28 pc.printf("*** Div Error! ***\n");
Koob 0:8889ed33c550 29 i=255;
Koob 0:8889ed33c550 30 break;
Koob 0:8889ed33c550 31 }
Koob 0:8889ed33c550 32 }
Koob 0:8889ed33c550 33 gps_data[i]='\0';
Koob 0:8889ed33c550 34
Koob 0:8889ed33c550 35 if( sscanf(gps_data, "GPGGA,%f,%f,%c,%f,%c,%d",&time,&hokui,&ns,&tokei,&ew,&rlock) >= 1){
Koob 0:8889ed33c550 36 if(rlock==1){
Koob 0:8889ed33c550 37 pc.printf("Status:Lock(%d)\n\r",rlock);
Koob 0:8889ed33c550 38 //logitude
Koob 0:8889ed33c550 39 d_tokei= int(tokei/100);
Koob 0:8889ed33c550 40 m_tokei= (tokei-d_tokei*100)/60;
Koob 0:8889ed33c550 41 g_tokei= d_tokei+m_tokei;
Koob 0:8889ed33c550 42 pc.printf("Log:%4.5f,",g_tokei);
Koob 0:8889ed33c550 43 //Latitude
Koob 0:8889ed33c550 44 d_hokui=int(hokui/100);
Koob 0:8889ed33c550 45 m_hokui=(hokui-d_hokui*100)/60;
Koob 0:8889ed33c550 46 g_hokui=d_hokui+m_hokui;
Koob 0:8889ed33c550 47 pc.printf("Lat:%4.5f\n\r",g_hokui);
Koob 0:8889ed33c550 48
Koob 0:8889ed33c550 49 }
Koob 0:8889ed33c550 50 else{
Koob 0:8889ed33c550 51 pc.printf("\n\rStatus:unLock(%d)\n\r",rlock);
Koob 0:8889ed33c550 52 for(i=0;i<40;i++){
Koob 0:8889ed33c550 53 pc.printf("%c",gps_data[i]);
Koob 0:8889ed33c550 54 }
Koob 0:8889ed33c550 55 }
Koob 0:8889ed33c550 56 }//if
Koob 0:8889ed33c550 57 }//while
Koob 1:aec45e847ec3 58 }
Koob 1:aec45e847ec3 59
Koob 1:aec45e847ec3 60 int main(){
Koob 1:aec45e847ec3 61 gps.attach(pc_rx,Serial::RxIrq);
Koob 1:aec45e847ec3 62 while(1) {
Koob 1:aec45e847ec3 63 myled = 1;
Koob 1:aec45e847ec3 64 wait(0.2);
Koob 1:aec45e847ec3 65 myled = 0;
Koob 1:aec45e847ec3 66 wait(0.2);
Koob 1:aec45e847ec3 67 }
Koob 1:aec45e847ec3 68 }