gpsのテスト
Dependencies: SDFileSystem mbed
Fork of 2bk0203_GPS_Logger01 by
main.cpp
- Committer:
- Joeatsumi
- Date:
- 2018-02-08
- Revision:
- 1:23d22ebf52c0
- Parent:
- 0:c7278239bae6
File content as of revision 1:23d22ebf52c0:
//GPS GT-720F Logger01 #include "mbed.h" #include "SDFileSystem.h" SDFileSystem sd(p5,p6,p7,p8,"sd"); FILE* fp; #define ON 1 #define OFF 0 DigitalOut mled0(LED1); DigitalOut mled1(LED2); DigitalIn sw1(p15); Serial pc(USBTX, USBRX); // tx, rx Serial gps(p9,p10); //LocalFileSystem local("local"); Ticker flipper; float g_hokui,g_tokei; int fp_count=0; int h_time=0,m_time=0,s_time=0; void gps_rec() { mled0=ON; if(fp == NULL) { error("Could not open file for write\n"); } fprintf(fp,"%4.6f,%3.6f\r\n",g_tokei,g_hokui); mled0=OFF; fp_count++; } int main() { char c; int i,rlock=0,stn=0; char gps_data[256]; char ns,ew; float time,hokui,tokei; float d_hokui,m_hokui,d_tokei,m_tokei; int h_time=0,m_time=0,s_time=0; int rec_flag=0; gps.baud(9600); fp = fopen("/sd/test.csv", "w"); // wait(1.0); flipper.attach(&gps_rec, 1.0); // fp = fopen("/sd/test.csv", "w"); // fp=fopen("/local/GPS.csv","w"); // fp=fopen("/local/GPS.csv","w"); //fclose(fp); //free(fp); // fprintf(fp,"\n"); //wait(1.0); while (1) { /* pc.putc(gps.getc()); */ if(sw1!=1){ fclose(fp); exit(1); } i=0; while(gps.getc()!='$'){ } while( (gps_data[i]=gps.getc()) != '\r'){ i++; if(i==256){ i=255; break; } } gps_data[i]='\0'; //test /* Test data rlock=1; stn=3; hokui=3532.25024; //=>35.537502 tokei=13751.86820;//=>137.864471 time=114107.046; */ if( sscanf(gps_data, "GPGGA,%f,%f,%c,%f,%c,%d,%d",&time,&hokui,&ns,&tokei,&ew,&rlock,&stn) >= 1){ if(rlock >= 1){ //hokui d_hokui=int(hokui/100); m_hokui=(hokui-d_hokui*100)/60; g_hokui=d_hokui+m_hokui; //tokei d_tokei=int(tokei/100); m_tokei=(tokei-d_tokei*100)/60; g_tokei=d_tokei+m_tokei; //g_hokui=int(hokui/100)+(hokui-int(hokui/100))/60; //g_tokei=int(tokei/100)+(tokei-int(tokei/100))/60; //time set h_time=int(time/10000); m_time=int((time-h_time*10000)/100); s_time=int(time-h_time*10000-m_time*100); h_time=h_time+9;//UTC =>JST // Record start if(rec_flag==0){ // flipper.attach(&gps_rec, 1.0); rec_flag=1; // fp=fopen("/local/GPS.csv","w"); // fprintf(fp,"%2d,%2d,%2d,%6.6f,%5.6f\r\n",h_time,m_time,s_time,g_tokei,g_hokui); //fclose(fp); //free(fp); mled0=ON; } else{ //fp=fopen("/local/GPS.csv","w"); // flipper.detach(); rec_flag=0; }//else } }//if }//while }//main