GPS受信機からの受信データを処理するサンプルコード。GPS受信機が即位できる屋外でテストして下さい。

Dependencies:   TimerExtended TinyGPS mbed

Committer:
morimoriYNCT
Date:
Mon Dec 08 12:30:18 2014 +0000
Revision:
0:cfd5cc72b38c
GPS???????????????????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
morimoriYNCT 0:cfd5cc72b38c 1 /**********************************
morimoriYNCT 0:cfd5cc72b38c 2 check: OK, ublox 5T
morimoriYNCT 0:cfd5cc72b38c 3 **********************************/
morimoriYNCT 0:cfd5cc72b38c 4 #include "mbed.h"
morimoriYNCT 0:cfd5cc72b38c 5 #include "TinyGPS.h"
morimoriYNCT 0:cfd5cc72b38c 6 #include "TimerExtended.h"
morimoriYNCT 0:cfd5cc72b38c 7
morimoriYNCT 0:cfd5cc72b38c 8 TinyGPS gpsr;
morimoriYNCT 0:cfd5cc72b38c 9
morimoriYNCT 0:cfd5cc72b38c 10 // serial
morimoriYNCT 0:cfd5cc72b38c 11 Serial serial_gps(p9, p10); // tx, rx
morimoriYNCT 0:cfd5cc72b38c 12 Serial serial_pc(USBTX, USBRX); // tx, rx
morimoriYNCT 0:cfd5cc72b38c 13
morimoriYNCT 0:cfd5cc72b38c 14 Timer timer;
morimoriYNCT 0:cfd5cc72b38c 15 TimerExtended timer2;
morimoriYNCT 0:cfd5cc72b38c 16 TimerExtended timer3;
morimoriYNCT 0:cfd5cc72b38c 17
morimoriYNCT 0:cfd5cc72b38c 18 void setup()
morimoriYNCT 0:cfd5cc72b38c 19 {
morimoriYNCT 0:cfd5cc72b38c 20 timer.start();
morimoriYNCT 0:cfd5cc72b38c 21 timer2.start();
morimoriYNCT 0:cfd5cc72b38c 22
morimoriYNCT 0:cfd5cc72b38c 23 serial_gps.baud(9600);
morimoriYNCT 0:cfd5cc72b38c 24 serial_pc.baud(115200);
morimoriYNCT 0:cfd5cc72b38c 25
morimoriYNCT 0:cfd5cc72b38c 26 serial_pc.printf("hello\n");
morimoriYNCT 0:cfd5cc72b38c 27 wait(3.0);
morimoriYNCT 0:cfd5cc72b38c 28
morimoriYNCT 0:cfd5cc72b38c 29 timer3.start();
morimoriYNCT 0:cfd5cc72b38c 30 }
morimoriYNCT 0:cfd5cc72b38c 31
morimoriYNCT 0:cfd5cc72b38c 32 void loop()
morimoriYNCT 0:cfd5cc72b38c 33 {
morimoriYNCT 0:cfd5cc72b38c 34 if(serial_gps.readable())
morimoriYNCT 0:cfd5cc72b38c 35 {
morimoriYNCT 0:cfd5cc72b38c 36 //serial_pc.printf("hoge\n");
morimoriYNCT 0:cfd5cc72b38c 37 char c = serial_gps.getc();
morimoriYNCT 0:cfd5cc72b38c 38 //serial_pc.putc(c);
morimoriYNCT 0:cfd5cc72b38c 39 bool gps_avairable = gpsr.encode(c);
morimoriYNCT 0:cfd5cc72b38c 40 if(gps_avairable)
morimoriYNCT 0:cfd5cc72b38c 41 {
morimoriYNCT 0:cfd5cc72b38c 42 //serial_pc.printf("fuga\n");
morimoriYNCT 0:cfd5cc72b38c 43 double lat, lon;
morimoriYNCT 0:cfd5cc72b38c 44 unsigned long age;
morimoriYNCT 0:cfd5cc72b38c 45 (void)gpsr.f_get_position(&lat, &lon, &age);
morimoriYNCT 0:cfd5cc72b38c 46
morimoriYNCT 0:cfd5cc72b38c 47 int year;
morimoriYNCT 0:cfd5cc72b38c 48 byte month, day, hour, minute, second;
morimoriYNCT 0:cfd5cc72b38c 49 (void)gpsr.crack_datetime(&year, &month, &day, &hour, &minute, &second);
morimoriYNCT 0:cfd5cc72b38c 50
morimoriYNCT 0:cfd5cc72b38c 51 double t = (double)timer.read_ms() / 1000.0;
morimoriYNCT 0:cfd5cc72b38c 52 serial_pc.printf("%f, ", t);
morimoriYNCT 0:cfd5cc72b38c 53 double t2 = (double)timer2.read_ms() / 1000.0;
morimoriYNCT 0:cfd5cc72b38c 54 serial_pc.printf("%f, ", t2);
morimoriYNCT 0:cfd5cc72b38c 55 double t3 = (double)timer3.read_ms() / 1000.0;
morimoriYNCT 0:cfd5cc72b38c 56 serial_pc.printf("%f, ", t3);
morimoriYNCT 0:cfd5cc72b38c 57 serial_pc.printf("%d-%02d-%02d %02d:%02d:%02d, ", year, month, day, hour, minute, second);
morimoriYNCT 0:cfd5cc72b38c 58 serial_pc.printf("%f, %f\n", lat, lon);
morimoriYNCT 0:cfd5cc72b38c 59 }
morimoriYNCT 0:cfd5cc72b38c 60 }
morimoriYNCT 0:cfd5cc72b38c 61 }
morimoriYNCT 0:cfd5cc72b38c 62
morimoriYNCT 0:cfd5cc72b38c 63 int main() {
morimoriYNCT 0:cfd5cc72b38c 64 setup();
morimoriYNCT 0:cfd5cc72b38c 65
morimoriYNCT 0:cfd5cc72b38c 66 while(1)
morimoriYNCT 0:cfd5cc72b38c 67 {
morimoriYNCT 0:cfd5cc72b38c 68 loop();
morimoriYNCT 0:cfd5cc72b38c 69 }
morimoriYNCT 0:cfd5cc72b38c 70 }