GPS_test

Dependencies:   SDFileSystem mbed

Committer:
Joeatsumi
Date:
Tue Jan 16 08:20:39 2018 +0000
Revision:
0:8c3382ecf351
GPS2018_1_16test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Joeatsumi 0:8c3382ecf351 1
Joeatsumi 0:8c3382ecf351 2 //GPS GT-720F Logger01
Joeatsumi 0:8c3382ecf351 3
Joeatsumi 0:8c3382ecf351 4 #include "mbed.h"
Joeatsumi 0:8c3382ecf351 5 #include "SDFileSystem.h"
Joeatsumi 0:8c3382ecf351 6 #define ON 1
Joeatsumi 0:8c3382ecf351 7 #define OFF 0
Joeatsumi 0:8c3382ecf351 8
Joeatsumi 0:8c3382ecf351 9 DigitalOut mled0(LED1);
Joeatsumi 0:8c3382ecf351 10 DigitalOut mled1(LED2);
Joeatsumi 0:8c3382ecf351 11 DigitalIn sw1(p5);
Joeatsumi 0:8c3382ecf351 12
Joeatsumi 0:8c3382ecf351 13 SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
Joeatsumi 0:8c3382ecf351 14 FILE *fp;//ポインタ指定
Joeatsumi 0:8c3382ecf351 15
Joeatsumi 0:8c3382ecf351 16 Serial gps(p9,p10);
Joeatsumi 0:8c3382ecf351 17
Joeatsumi 0:8c3382ecf351 18 Ticker flipper;
Joeatsumi 0:8c3382ecf351 19
Joeatsumi 0:8c3382ecf351 20 float g_hokui,g_tokei;
Joeatsumi 0:8c3382ecf351 21 int fp_count=0;
Joeatsumi 0:8c3382ecf351 22
Joeatsumi 0:8c3382ecf351 23 void gps_rec() {
Joeatsumi 0:8c3382ecf351 24
Joeatsumi 0:8c3382ecf351 25 fp = fopen("/sd/nmea.csv", "w");
Joeatsumi 0:8c3382ecf351 26 if(fp == NULL) {
Joeatsumi 0:8c3382ecf351 27 error("Could not open file for write\n");
Joeatsumi 0:8c3382ecf351 28 }
Joeatsumi 0:8c3382ecf351 29 fprintf(fp,"%4.6f,%3.6f,\n",g_tokei,g_hokui);
Joeatsumi 0:8c3382ecf351 30 fclose(fp);
Joeatsumi 0:8c3382ecf351 31 }
Joeatsumi 0:8c3382ecf351 32
Joeatsumi 0:8c3382ecf351 33 int main() {
Joeatsumi 0:8c3382ecf351 34
Joeatsumi 0:8c3382ecf351 35
Joeatsumi 0:8c3382ecf351 36 char c;
Joeatsumi 0:8c3382ecf351 37 int i,rlock=0,stn=0;
Joeatsumi 0:8c3382ecf351 38 char gps_data[256];
Joeatsumi 0:8c3382ecf351 39 char ns,ew;
Joeatsumi 0:8c3382ecf351 40 float time,hokui,tokei;
Joeatsumi 0:8c3382ecf351 41
Joeatsumi 0:8c3382ecf351 42 float d_hokui,m_hokui,d_tokei,m_tokei;
Joeatsumi 0:8c3382ecf351 43 int h_time=0,m_time=0,s_time=0;
Joeatsumi 0:8c3382ecf351 44 int rec_flag=0;
Joeatsumi 0:8c3382ecf351 45
Joeatsumi 0:8c3382ecf351 46 gps.baud(9600);//GT-720Fボーレート
Joeatsumi 0:8c3382ecf351 47
Joeatsumi 0:8c3382ecf351 48
Joeatsumi 0:8c3382ecf351 49
Joeatsumi 0:8c3382ecf351 50 while (1) {
Joeatsumi 0:8c3382ecf351 51
Joeatsumi 0:8c3382ecf351 52 i=0;
Joeatsumi 0:8c3382ecf351 53 while(gps.getc()!='$'){
Joeatsumi 0:8c3382ecf351 54 }
Joeatsumi 0:8c3382ecf351 55
Joeatsumi 0:8c3382ecf351 56 while( (gps_data[i]=gps.getc()) != '\r'){
Joeatsumi 0:8c3382ecf351 57 i++;
Joeatsumi 0:8c3382ecf351 58 if(i==256){//上限文字数250文字
Joeatsumi 0:8c3382ecf351 59 i=255;
Joeatsumi 0:8c3382ecf351 60 break;
Joeatsumi 0:8c3382ecf351 61 }
Joeatsumi 0:8c3382ecf351 62 }
Joeatsumi 0:8c3382ecf351 63 gps_data[i]='\0';
Joeatsumi 0:8c3382ecf351 64
Joeatsumi 0:8c3382ecf351 65 //test
Joeatsumi 0:8c3382ecf351 66 /* Test data
Joeatsumi 0:8c3382ecf351 67 rlock=1;
Joeatsumi 0:8c3382ecf351 68 stn=3;
Joeatsumi 0:8c3382ecf351 69 hokui=3532.25024; //=>35.537502
Joeatsumi 0:8c3382ecf351 70 tokei=13751.86820;//=>137.864471
Joeatsumi 0:8c3382ecf351 71 time=114107.046;
Joeatsumi 0:8c3382ecf351 72 */
Joeatsumi 0:8c3382ecf351 73
Joeatsumi 0:8c3382ecf351 74 //正常に作動
Joeatsumi 0:8c3382ecf351 75 //GPGGAセンテンスを見つける
Joeatsumi 0:8c3382ecf351 76 if( sscanf(gps_data, "GPGGA,%f,%f,%c,%f,%c,%d,%d",&time,&hokui,&ns,&tokei,&ew,&rlock,&stn) >= 1){
Joeatsumi 0:8c3382ecf351 77 if(rlock >= 1){//衛星ロック、緯度経度計測開始
Joeatsumi 0:8c3382ecf351 78
Joeatsumi 0:8c3382ecf351 79 //hokui 北緯の処理
Joeatsumi 0:8c3382ecf351 80
Joeatsumi 0:8c3382ecf351 81 d_hokui=int(hokui/100);
Joeatsumi 0:8c3382ecf351 82 m_hokui=(hokui-d_hokui*100)/60;
Joeatsumi 0:8c3382ecf351 83 g_hokui=d_hokui+m_hokui;
Joeatsumi 0:8c3382ecf351 84 //tokei 東経の処理
Joeatsumi 0:8c3382ecf351 85
Joeatsumi 0:8c3382ecf351 86 d_tokei=int(tokei/100);
Joeatsumi 0:8c3382ecf351 87 m_tokei=(tokei-d_tokei*100)/60;
Joeatsumi 0:8c3382ecf351 88 g_tokei=d_tokei+m_tokei;
Joeatsumi 0:8c3382ecf351 89 //g_hokui=int(hokui/100)+(hokui-int(hokui/100))/60;
Joeatsumi 0:8c3382ecf351 90 //g_tokei=int(tokei/100)+(tokei-int(tokei/100))/60;
Joeatsumi 0:8c3382ecf351 91
Joeatsumi 0:8c3382ecf351 92 //time set
Joeatsumi 0:8c3382ecf351 93 h_time=int(time/10000);
Joeatsumi 0:8c3382ecf351 94 m_time=int((time-h_time*10000)/100);
Joeatsumi 0:8c3382ecf351 95 s_time=int(time-h_time*10000-m_time*100);
Joeatsumi 0:8c3382ecf351 96 h_time=h_time+9;//UTC =>JST
Joeatsumi 0:8c3382ecf351 97
Joeatsumi 0:8c3382ecf351 98
Joeatsumi 0:8c3382ecf351 99 flipper.attach(&gps_rec, 1.0);//ロギング割り込み開始
Joeatsumi 0:8c3382ecf351 100
Joeatsumi 0:8c3382ecf351 101 }//if(rclock>1)
Joeatsumi 0:8c3382ecf351 102
Joeatsumi 0:8c3382ecf351 103 }//if sscanf
Joeatsumi 0:8c3382ecf351 104 }//while
Joeatsumi 0:8c3382ecf351 105 }//main
Joeatsumi 0:8c3382ecf351 106
Joeatsumi 0:8c3382ecf351 107