GPS for Ecorun2017
Dependencies: 2bk0203_GPS_Logger01 mbed
Fork of 2bk0203_GPS_Logger01 by
main.cpp@2:cfab54820401, 2017-09-08 (annotated)
- Committer:
- knumber16
- Date:
- Fri Sep 08 13:30:55 2017 +0000
- Revision:
- 2:cfab54820401
- Parent:
- 1:61f0b0721aee
for Ecorun project
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
takeuchi | 0:c7278239bae6 | 1 | //GPS GT-720F Logger01 |
knumber16 | 2:cfab54820401 | 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" |
knumber16 | 2:cfab54820401 | 5 | #include <list> |
takeuchi | 0:c7278239bae6 | 6 | |
takeuchi | 0:c7278239bae6 | 7 | #define ON 1 |
takeuchi | 0:c7278239bae6 | 8 | #define OFF 0 |
takeuchi | 0:c7278239bae6 | 9 | |
knumber16 | 2:cfab54820401 | 10 | typedef struct { |
knumber16 | 2:cfab54820401 | 11 | int jst[3]; |
knumber16 | 2:cfab54820401 | 12 | float tokei; |
knumber16 | 2:cfab54820401 | 13 | float hokui; |
knumber16 | 2:cfab54820401 | 14 | } POINT; |
knumber16 | 2:cfab54820401 | 15 | |
takeuchi | 0:c7278239bae6 | 16 | DigitalOut mled0(LED1); |
takeuchi | 0:c7278239bae6 | 17 | DigitalOut mled1(LED2); |
knumber16 | 2:cfab54820401 | 18 | //DigitalIn sw1(p5); |
knumber16 | 2:cfab54820401 | 19 | InterruptIn sw(p5); |
takeuchi | 0:c7278239bae6 | 20 | |
knumber16 | 2:cfab54820401 | 21 | //Textpc pc(p24, p25, p26, p27, p28, p29, p30,20,4); // rs, rw, e, d0, d1, d2, d3 |
knumber16 | 2:cfab54820401 | 22 | Serial pc(USBTX,USBRX); |
knumber16 | 2:cfab54820401 | 23 | Serial gps(p28,p27); |
knumber16 | 2:cfab54820401 | 24 | //LocalFileSystem local("local"); |
takeuchi | 0:c7278239bae6 | 25 | Ticker flipper; |
takeuchi | 0:c7278239bae6 | 26 | FILE *fp; |
takeuchi | 0:c7278239bae6 | 27 | float g_hokui,g_tokei; |
takeuchi | 0:c7278239bae6 | 28 | int fp_count=0; |
knumber16 | 2:cfab54820401 | 29 | int h_time=0,m_time=0,s_time=0; |
knumber16 | 2:cfab54820401 | 30 | typedef std::list<POINT> LP; //構造体POINTのlistの型宣言 |
knumber16 | 2:cfab54820401 | 31 | LP points; //時刻と座標データのバッファ |
takeuchi | 0:c7278239bae6 | 32 | |
knumber16 | 2:cfab54820401 | 33 | void irq() //バッファからの読み出し,バッファが空になるまでteratermに表示させる |
knumber16 | 2:cfab54820401 | 34 | { |
knumber16 | 2:cfab54820401 | 35 | for(LP::iterator itr = points.begin(); !points.empty();) { |
knumber16 | 2:cfab54820401 | 36 | pc.printf("%02d:%02d:%02d,%f,%f\n",itr->jst[0],itr->jst[1],itr->jst[2],itr->tokei,itr->hokui); |
knumber16 | 2:cfab54820401 | 37 | itr = points.erase(itr); |
knumber16 | 2:cfab54820401 | 38 | } |
knumber16 | 2:cfab54820401 | 39 | } |
knumber16 | 2:cfab54820401 | 40 | |
knumber16 | 2:cfab54820401 | 41 | void gps_rec() //バッファにデータを格納する.Tickerで割り込まれているので,サンプル時間は任意に調整可能.現在5[s]置きでも受信可能 |
knumber16 | 2:cfab54820401 | 42 | { |
knumber16 | 2:cfab54820401 | 43 | static POINT p = {{0,0,0},0,0}; |
knumber16 | 2:cfab54820401 | 44 | mled0=ON; |
knumber16 | 2:cfab54820401 | 45 | p.jst[0]=h_time; |
knumber16 | 2:cfab54820401 | 46 | p.jst[1]=m_time; |
knumber16 | 2:cfab54820401 | 47 | p.jst[2]=s_time; |
knumber16 | 2:cfab54820401 | 48 | p.tokei = g_tokei; |
knumber16 | 2:cfab54820401 | 49 | p.hokui = g_hokui; |
knumber16 | 2:cfab54820401 | 50 | // pc.printf("%4.6f,%3.6f,\n",g_tokei,g_hokui); |
knumber16 | 2:cfab54820401 | 51 | points.push_back(p); |
knumber16 | 2:cfab54820401 | 52 | wait(1.0); |
knumber16 | 2:cfab54820401 | 53 | mled0=OFF; |
knumber16 | 2:cfab54820401 | 54 | fp_count++; |
takeuchi | 0:c7278239bae6 | 55 | } |
takeuchi | 0:c7278239bae6 | 56 | |
knumber16 | 2:cfab54820401 | 57 | int main() |
knumber16 | 2:cfab54820401 | 58 | { |
knumber16 | 2:cfab54820401 | 59 | sw.rise(&irq); |
knumber16 | 2:cfab54820401 | 60 | char c; |
knumber16 | 2:cfab54820401 | 61 | int i,rlock=0,stn=0; |
knumber16 | 2:cfab54820401 | 62 | char gps_data[256]; |
knumber16 | 2:cfab54820401 | 63 | char ns,ew; |
knumber16 | 2:cfab54820401 | 64 | float time,hokui,tokei; |
takeuchi | 0:c7278239bae6 | 65 | |
knumber16 | 2:cfab54820401 | 66 | float d_hokui,m_hokui,d_tokei,m_tokei; |
knumber16 | 2:cfab54820401 | 67 | int rec_flag=0; |
knumber16 | 2:cfab54820401 | 68 | |
knumber16 | 2:cfab54820401 | 69 | gps.baud(9600); |
knumber16 | 2:cfab54820401 | 70 | pc.printf("*** GPS GT-720F ****\n"); |
knumber16 | 2:cfab54820401 | 71 | pc.printf("File open...\n"); |
knumber16 | 2:cfab54820401 | 72 | wait(1.0); |
knumber16 | 2:cfab54820401 | 73 | // fp=fopen("/local/GPS.txt","a"); |
knumber16 | 2:cfab54820401 | 74 | pc.printf("System start...\n"); |
knumber16 | 2:cfab54820401 | 75 | pc.printf("Loging ready ok...\n"); |
knumber16 | 2:cfab54820401 | 76 | pc.printf("\n"); |
knumber16 | 2:cfab54820401 | 77 | wait(1.0); |
knumber16 | 2:cfab54820401 | 78 | |
takeuchi | 0:c7278239bae6 | 79 | while (1) { |
knumber16 | 2:cfab54820401 | 80 | i=0; |
knumber16 | 2:cfab54820401 | 81 | while(gps.getc()!='$') { |
knumber16 | 2:cfab54820401 | 82 | } |
knumber16 | 2:cfab54820401 | 83 | |
knumber16 | 2:cfab54820401 | 84 | while( (gps_data[i]=gps.getc()) != '\r') { |
knumber16 | 2:cfab54820401 | 85 | i++; |
knumber16 | 2:cfab54820401 | 86 | if(i==256) { |
knumber16 | 2:cfab54820401 | 87 | pc.printf("*** Data read Error! ***\n"); |
knumber16 | 2:cfab54820401 | 88 | i=255; |
knumber16 | 2:cfab54820401 | 89 | break; |
knumber16 | 2:cfab54820401 | 90 | } |
knumber16 | 2:cfab54820401 | 91 | } |
knumber16 | 2:cfab54820401 | 92 | gps_data[i]='\0'; |
knumber16 | 2:cfab54820401 | 93 | |
knumber16 | 2:cfab54820401 | 94 | //test |
knumber16 | 2:cfab54820401 | 95 | /* Test data |
knumber16 | 2:cfab54820401 | 96 | rlock=1; |
knumber16 | 2:cfab54820401 | 97 | stn=3; |
knumber16 | 2:cfab54820401 | 98 | hokui=3532.25024; //=>35.537502 |
knumber16 | 2:cfab54820401 | 99 | tokei=13751.86820;//=>137.864471 |
knumber16 | 2:cfab54820401 | 100 | time=114107.046; |
knumber16 | 2:cfab54820401 | 101 | */ |
knumber16 | 2:cfab54820401 | 102 | if( sscanf(gps_data, "GPGGA,%f,%f,%c,%f,%c,%d,%d",&time,&hokui,&ns,&tokei,&ew,&rlock,&stn) >= 1) { |
knumber16 | 2:cfab54820401 | 103 | if(rlock >= 1) { |
knumber16 | 2:cfab54820401 | 104 | |
knumber16 | 2:cfab54820401 | 105 | //hokui |
knumber16 | 2:cfab54820401 | 106 | d_hokui=int(hokui/100); |
knumber16 | 2:cfab54820401 | 107 | m_hokui=(hokui-d_hokui*100)/60; |
knumber16 | 2:cfab54820401 | 108 | g_hokui=d_hokui+m_hokui; |
knumber16 | 2:cfab54820401 | 109 | //tokei |
knumber16 | 2:cfab54820401 | 110 | d_tokei=int(tokei/100); |
knumber16 | 2:cfab54820401 | 111 | m_tokei=(tokei-d_tokei*100)/60; |
knumber16 | 2:cfab54820401 | 112 | g_tokei=d_tokei+m_tokei; |
knumber16 | 2:cfab54820401 | 113 | //g_hokui=int(hokui/100)+(hokui-int(hokui/100))/60; |
knumber16 | 2:cfab54820401 | 114 | //g_tokei=int(tokei/100)+(tokei-int(tokei/100))/60; |
takeuchi | 0:c7278239bae6 | 115 | |
knumber16 | 2:cfab54820401 | 116 | //time set |
knumber16 | 2:cfab54820401 | 117 | h_time=int(time/10000); |
knumber16 | 2:cfab54820401 | 118 | m_time=int((time-h_time*10000)/100); |
knumber16 | 2:cfab54820401 | 119 | s_time=int(time-h_time*10000-m_time*100); |
knumber16 | 2:cfab54820401 | 120 | h_time=h_time+9;//UTC =>JST |
knumber16 | 2:cfab54820401 | 121 | |
knumber16 | 2:cfab54820401 | 122 | // Record start |
knumber16 | 2:cfab54820401 | 123 | if(rec_flag==0) { |
knumber16 | 2:cfab54820401 | 124 | flipper.attach(&gps_rec, 5.0); |
knumber16 | 2:cfab54820401 | 125 | rec_flag=1; |
knumber16 | 2:cfab54820401 | 126 | pc.printf("JST %2d:%2d:%2d\n",h_time,m_time,s_time); |
knumber16 | 2:cfab54820401 | 127 | mled0=ON; |
knumber16 | 2:cfab54820401 | 128 | pc.printf("Loging start...."); |
knumber16 | 2:cfab54820401 | 129 | wait(5.0); |
knumber16 | 2:cfab54820401 | 130 | mled0=ON; |
knumber16 | 2:cfab54820401 | 131 | } |
takeuchi | 0:c7278239bae6 | 132 | |
knumber16 | 2:cfab54820401 | 133 | pc.printf("*GPS JST %2d:%2d:%2d,",h_time,m_time,s_time); |
knumber16 | 2:cfab54820401 | 134 | pc.printf("Lk(%d),St(%d),%d,",rlock,stn,fp_count); |
knumber16 | 2:cfab54820401 | 135 | //Latitude=Hokui |
knumber16 | 2:cfab54820401 | 136 | pc.printf("Lat/d:%4.6f,",g_hokui); |
knumber16 | 2:cfab54820401 | 137 | // Logitude=tokei |
knumber16 | 2:cfab54820401 | 138 | pc.printf("Log/d:%4.6f\n",g_tokei); |
knumber16 | 2:cfab54820401 | 139 | } else { |
knumber16 | 2:cfab54820401 | 140 | flipper.detach(); |
knumber16 | 2:cfab54820401 | 141 | rec_flag=0; |
knumber16 | 2:cfab54820401 | 142 | pc.printf("*** GPS GT-720F ***"); |
knumber16 | 2:cfab54820401 | 143 | pc.printf("Lk(%d),St(%d)\n",rlock,stn); |
knumber16 | 2:cfab54820401 | 144 | /* for(i=0;i<40;i++){ |
knumber16 | 2:cfab54820401 | 145 | pc.printf("%c",gps_data[i]); |
knumber16 | 2:cfab54820401 | 146 | }*/ |
knumber16 | 2:cfab54820401 | 147 | } |
knumber16 | 2:cfab54820401 | 148 | }//if |
takeuchi | 0:c7278239bae6 | 149 | }//while |
knumber16 | 2:cfab54820401 | 150 | }//main |