GPS for Ecorun2017

Dependencies:   2bk0203_GPS_Logger01 mbed

Fork of 2bk0203_GPS_Logger01 by Takeuchi Kouichi

Committer:
knumber16
Date:
Wed Aug 30 01:23:40 2017 +0000
Revision:
1:61f0b0721aee
Parent:
0:c7278239bae6
Child:
2:cfab54820401
test;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
takeuchi 0:c7278239bae6 1 //GPS GT-720F Logger01
knumber16 1:61f0b0721aee 2 //program detail : http://www.oidenansho.com/elekijack/mbed/2bk0208_GPS_logger/GPS_logger.htm
knumber16 1:61f0b0721aee 3
takeuchi 0:c7278239bae6 4 #include "mbed.h"
takeuchi 0:c7278239bae6 5 #include "TextLCD0420.h"
takeuchi 0:c7278239bae6 6
takeuchi 0:c7278239bae6 7 #define ON 1
takeuchi 0:c7278239bae6 8 #define OFF 0
takeuchi 0:c7278239bae6 9
takeuchi 0:c7278239bae6 10 DigitalOut mled0(LED1);
takeuchi 0:c7278239bae6 11 DigitalOut mled1(LED2);
takeuchi 0:c7278239bae6 12 DigitalIn sw1(p5);
takeuchi 0:c7278239bae6 13
takeuchi 0:c7278239bae6 14 TextLCD lcd(p24, p25, p26, p27, p28, p29, p30,20,4); // rs, rw, e, d0, d1, d2, d3
takeuchi 0:c7278239bae6 15 Serial gps(p9,p10);
takeuchi 0:c7278239bae6 16 LocalFileSystem local("local");
takeuchi 0:c7278239bae6 17 Ticker flipper;
takeuchi 0:c7278239bae6 18 FILE *fp;
takeuchi 0:c7278239bae6 19 float g_hokui,g_tokei;
takeuchi 0:c7278239bae6 20 int fp_count=0;
takeuchi 0:c7278239bae6 21
takeuchi 0:c7278239bae6 22 void gps_rec() {
takeuchi 0:c7278239bae6 23 mled0=ON;
takeuchi 0:c7278239bae6 24 fprintf(fp,"%4.6f,%3.6f,\n",g_tokei,g_hokui);
takeuchi 0:c7278239bae6 25 wait(1.0);
takeuchi 0:c7278239bae6 26 mled0=OFF;
takeuchi 0:c7278239bae6 27 fp_count++;
takeuchi 0:c7278239bae6 28 }
takeuchi 0:c7278239bae6 29
takeuchi 0:c7278239bae6 30 int main() {
takeuchi 0:c7278239bae6 31
takeuchi 0:c7278239bae6 32 char c;
takeuchi 0:c7278239bae6 33 int i,rlock=0,stn=0;
takeuchi 0:c7278239bae6 34 char gps_data[256];
takeuchi 0:c7278239bae6 35 char ns,ew;
takeuchi 0:c7278239bae6 36 float time,hokui,tokei;
takeuchi 0:c7278239bae6 37
takeuchi 0:c7278239bae6 38 float d_hokui,m_hokui,d_tokei,m_tokei;
takeuchi 0:c7278239bae6 39 int h_time=0,m_time=0,s_time=0;
takeuchi 0:c7278239bae6 40 int rec_flag=0;
takeuchi 0:c7278239bae6 41
takeuchi 0:c7278239bae6 42 gps.baud(9600);
takeuchi 0:c7278239bae6 43 lcd.cls();
takeuchi 0:c7278239bae6 44 lcd.printf("*** GPS GT-720F ****\n");
takeuchi 0:c7278239bae6 45 lcd.locate(0,1);
takeuchi 0:c7278239bae6 46 lcd.printf("File open...\n");
takeuchi 0:c7278239bae6 47 wait(1.0);
takeuchi 0:c7278239bae6 48 fp=fopen("/local/GPS.txt","a");
takeuchi 0:c7278239bae6 49 if(!fp || sw1==0){
takeuchi 0:c7278239bae6 50 lcd.cls();
takeuchi 0:c7278239bae6 51 lcd.printf("Can't Loging ... \n");
takeuchi 0:c7278239bae6 52 lcd.printf("System close...\n");
takeuchi 0:c7278239bae6 53 lcd.printf(">\n");
takeuchi 0:c7278239bae6 54 exit(1);
takeuchi 0:c7278239bae6 55 }
takeuchi 0:c7278239bae6 56 lcd.printf("System start...\n");
takeuchi 0:c7278239bae6 57 lcd.printf("Loging ready ok...\n");
takeuchi 0:c7278239bae6 58 fprintf(fp,"\n");
takeuchi 0:c7278239bae6 59 wait(1.0);
takeuchi 0:c7278239bae6 60
takeuchi 0:c7278239bae6 61 while (1) {
takeuchi 0:c7278239bae6 62 if(sw1==0){
takeuchi 0:c7278239bae6 63 fclose(fp);
takeuchi 0:c7278239bae6 64 lcd.cls();
takeuchi 0:c7278239bae6 65 lcd.printf("System close...\n");
takeuchi 0:c7278239bae6 66 lcd.printf(">\n");
takeuchi 0:c7278239bae6 67 exit(1);
takeuchi 0:c7278239bae6 68 }
takeuchi 0:c7278239bae6 69
takeuchi 0:c7278239bae6 70 i=0;
takeuchi 0:c7278239bae6 71 while(gps.getc()!='$'){
takeuchi 0:c7278239bae6 72 }
takeuchi 0:c7278239bae6 73
takeuchi 0:c7278239bae6 74 while( (gps_data[i]=gps.getc()) != '\r'){
takeuchi 0:c7278239bae6 75 i++;
takeuchi 0:c7278239bae6 76 if(i==256){
takeuchi 0:c7278239bae6 77 lcd.printf("*** Data read Error! ***\n");
takeuchi 0:c7278239bae6 78 i=255;
takeuchi 0:c7278239bae6 79 break;
takeuchi 0:c7278239bae6 80 }
takeuchi 0:c7278239bae6 81 }
takeuchi 0:c7278239bae6 82 gps_data[i]='\0';
takeuchi 0:c7278239bae6 83
takeuchi 0:c7278239bae6 84 //test
takeuchi 0:c7278239bae6 85 /* Test data
takeuchi 0:c7278239bae6 86 rlock=1;
takeuchi 0:c7278239bae6 87 stn=3;
takeuchi 0:c7278239bae6 88 hokui=3532.25024; //=>35.537502
takeuchi 0:c7278239bae6 89 tokei=13751.86820;//=>137.864471
takeuchi 0:c7278239bae6 90 time=114107.046;
takeuchi 0:c7278239bae6 91 */
takeuchi 0:c7278239bae6 92 if( sscanf(gps_data, "GPGGA,%f,%f,%c,%f,%c,%d,%d",&time,&hokui,&ns,&tokei,&ew,&rlock,&stn) >= 1){
takeuchi 0:c7278239bae6 93 if(rlock >= 1){
takeuchi 0:c7278239bae6 94
takeuchi 0:c7278239bae6 95 //hokui
takeuchi 0:c7278239bae6 96 d_hokui=int(hokui/100);
takeuchi 0:c7278239bae6 97 m_hokui=(hokui-d_hokui*100)/60;
takeuchi 0:c7278239bae6 98 g_hokui=d_hokui+m_hokui;
takeuchi 0:c7278239bae6 99 //tokei
takeuchi 0:c7278239bae6 100 d_tokei=int(tokei/100);
takeuchi 0:c7278239bae6 101 m_tokei=(tokei-d_tokei*100)/60;
takeuchi 0:c7278239bae6 102 g_tokei=d_tokei+m_tokei;
takeuchi 0:c7278239bae6 103 //g_hokui=int(hokui/100)+(hokui-int(hokui/100))/60;
takeuchi 0:c7278239bae6 104 //g_tokei=int(tokei/100)+(tokei-int(tokei/100))/60;
takeuchi 0:c7278239bae6 105
takeuchi 0:c7278239bae6 106 //time set
takeuchi 0:c7278239bae6 107 h_time=int(time/10000);
takeuchi 0:c7278239bae6 108 m_time=int((time-h_time*10000)/100);
takeuchi 0:c7278239bae6 109 s_time=int(time-h_time*10000-m_time*100);
takeuchi 0:c7278239bae6 110 h_time=h_time+9;//UTC =>JST
takeuchi 0:c7278239bae6 111
takeuchi 0:c7278239bae6 112 // Record start
takeuchi 0:c7278239bae6 113 if(rec_flag==0){
takeuchi 0:c7278239bae6 114 flipper.attach(&gps_rec, 10.0);
takeuchi 0:c7278239bae6 115 rec_flag=1;
takeuchi 0:c7278239bae6 116 fprintf(fp,"JST %2d:%2d:%2d\n",h_time,m_time,s_time);
takeuchi 0:c7278239bae6 117 lcd.cls();
takeuchi 0:c7278239bae6 118 mled0=ON;
takeuchi 0:c7278239bae6 119 lcd.printf("Loging start....");
takeuchi 0:c7278239bae6 120 wait(5.0);
takeuchi 0:c7278239bae6 121 mled0=ON;
takeuchi 0:c7278239bae6 122 }
takeuchi 0:c7278239bae6 123
takeuchi 0:c7278239bae6 124 lcd.cls();
takeuchi 0:c7278239bae6 125 lcd.locate(0,0);
takeuchi 0:c7278239bae6 126 lcd.printf("*GPS JST %2d:%2d:%2d",h_time,m_time,s_time);
takeuchi 0:c7278239bae6 127 lcd.locate(0,1);
takeuchi 0:c7278239bae6 128 lcd.printf("Lk(%d),St(%d),%d",rlock,stn,fp_count);
takeuchi 0:c7278239bae6 129 //Latitude=Hokui
takeuchi 0:c7278239bae6 130 lcd.locate(0,2);
takeuchi 0:c7278239bae6 131 lcd.printf("Lat/d:%4.6f",g_hokui);
takeuchi 0:c7278239bae6 132 // Logitude=tokei
takeuchi 0:c7278239bae6 133 lcd.locate(0,3);
takeuchi 0:c7278239bae6 134 lcd.printf("Log/d:%4.6f",g_tokei);
takeuchi 0:c7278239bae6 135 }
takeuchi 0:c7278239bae6 136 else{
takeuchi 0:c7278239bae6 137 flipper.detach();
takeuchi 0:c7278239bae6 138 rec_flag=0;
takeuchi 0:c7278239bae6 139 lcd.cls();
takeuchi 0:c7278239bae6 140 lcd.locate(0,0);
takeuchi 0:c7278239bae6 141 lcd.printf("*** GPS GT-720F ***");
takeuchi 0:c7278239bae6 142 lcd.locate(0,1);
takeuchi 0:c7278239bae6 143 lcd.printf("Lk(%d),St(%d)",rlock,stn);
takeuchi 0:c7278239bae6 144 lcd.locate(0,2);
takeuchi 0:c7278239bae6 145 for(i=0;i<40;i++){
takeuchi 0:c7278239bae6 146 lcd.printf("%c",gps_data[i]);
takeuchi 0:c7278239bae6 147 }
takeuchi 0:c7278239bae6 148 }
takeuchi 0:c7278239bae6 149 }//if
takeuchi 0:c7278239bae6 150 }//while
takeuchi 0:c7278239bae6 151 }//main
takeuchi 0:c7278239bae6 152
takeuchi 0:c7278239bae6 153
takeuchi 0:c7278239bae6 154