GPS_test
Dependencies: SDFileSystem mbed
main.cpp
00001 00002 //GPS GT-720F Logger01 00003 00004 #include "mbed.h" 00005 #include "SDFileSystem.h" 00006 #define ON 1 00007 #define OFF 0 00008 00009 DigitalOut mled0(LED1); 00010 DigitalOut mled1(LED2); 00011 DigitalIn sw1(p5); 00012 00013 SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board 00014 FILE *fp;//ポインタ指定 00015 00016 Serial gps(p9,p10); 00017 00018 Ticker flipper; 00019 00020 float g_hokui,g_tokei; 00021 int fp_count=0; 00022 00023 void gps_rec() { 00024 00025 fp = fopen("/sd/nmea.csv", "w"); 00026 if(fp == NULL) { 00027 error("Could not open file for write\n"); 00028 } 00029 fprintf(fp,"%4.6f,%3.6f,\n",g_tokei,g_hokui); 00030 fclose(fp); 00031 } 00032 00033 int main() { 00034 00035 00036 char c; 00037 int i,rlock=0,stn=0; 00038 char gps_data[256]; 00039 char ns,ew; 00040 float time,hokui,tokei; 00041 00042 float d_hokui,m_hokui,d_tokei,m_tokei; 00043 int h_time=0,m_time=0,s_time=0; 00044 int rec_flag=0; 00045 00046 gps.baud(9600);//GT-720Fボーレート 00047 00048 00049 00050 while (1) { 00051 00052 i=0; 00053 while(gps.getc()!='$'){ 00054 } 00055 00056 while( (gps_data[i]=gps.getc()) != '\r'){ 00057 i++; 00058 if(i==256){//上限文字数250文字 00059 i=255; 00060 break; 00061 } 00062 } 00063 gps_data[i]='\0'; 00064 00065 //test 00066 /* Test data 00067 rlock=1; 00068 stn=3; 00069 hokui=3532.25024; //=>35.537502 00070 tokei=13751.86820;//=>137.864471 00071 time=114107.046; 00072 */ 00073 00074 //正常に作動 00075 //GPGGAセンテンスを見つける 00076 if( sscanf(gps_data, "GPGGA,%f,%f,%c,%f,%c,%d,%d",&time,&hokui,&ns,&tokei,&ew,&rlock,&stn) >= 1){ 00077 if(rlock >= 1){//衛星ロック、緯度経度計測開始 00078 00079 //hokui 北緯の処理 00080 00081 d_hokui=int(hokui/100); 00082 m_hokui=(hokui-d_hokui*100)/60; 00083 g_hokui=d_hokui+m_hokui; 00084 //tokei 東経の処理 00085 00086 d_tokei=int(tokei/100); 00087 m_tokei=(tokei-d_tokei*100)/60; 00088 g_tokei=d_tokei+m_tokei; 00089 //g_hokui=int(hokui/100)+(hokui-int(hokui/100))/60; 00090 //g_tokei=int(tokei/100)+(tokei-int(tokei/100))/60; 00091 00092 //time set 00093 h_time=int(time/10000); 00094 m_time=int((time-h_time*10000)/100); 00095 s_time=int(time-h_time*10000-m_time*100); 00096 h_time=h_time+9;//UTC =>JST 00097 00098 00099 flipper.attach(&gps_rec, 1.0);//ロギング割り込み開始 00100 00101 }//if(rclock>1) 00102 00103 }//if sscanf 00104 }//while 00105 }//main 00106 00107
Generated on Wed Jul 27 2022 12:14:35 by
1.7.2