Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
getGPS.cpp@5:9ff2f6cd54d2, 2019-12-08 (annotated)
- Committer:
- KINU
- Date:
- Sun Dec 08 13:28:08 2019 +0000
- Revision:
- 5:9ff2f6cd54d2
- Parent:
- 1:c142b1682312
GPSXBeecompleted
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| KINU | 1:c142b1682312 | 1 | #include "mbed.h" | 
| KINU | 1:c142b1682312 | 2 | #include "getGPS.h" | 
| KINU | 1:c142b1682312 | 3 | |
| KINU | 1:c142b1682312 | 4 | GPS::GPS(PinName gpstx,PinName gpsrx): _gps(gpstx,gpsrx) | 
| KINU | 1:c142b1682312 | 5 | { | 
| KINU | 1:c142b1682312 | 6 | latitude = 0; | 
| KINU | 1:c142b1682312 | 7 | longitude = 0; | 
| KINU | 1:c142b1682312 | 8 | _gps.baud(GPSBAUD); | 
| KINU | 1:c142b1682312 | 9 | _gps.printf("$PMTK314,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29"); | 
| KINU | 1:c142b1682312 | 10 | } | 
| KINU | 1:c142b1682312 | 11 | |
| KINU | 1:c142b1682312 | 12 | bool GPS::getgps() | 
| KINU | 1:c142b1682312 | 13 | { | 
| KINU | 1:c142b1682312 | 14 | char gps_data[256]; | 
| KINU | 1:c142b1682312 | 15 | int i; | 
| KINU | 1:c142b1682312 | 16 | |
| KINU | 1:c142b1682312 | 17 | do { | 
| KINU | 1:c142b1682312 | 18 | while(_gps.getc() != '$'); //$マークまで読み飛ばし | 
| KINU | 1:c142b1682312 | 19 | i = 0; | 
| KINU | 1:c142b1682312 | 20 | |
| KINU | 1:c142b1682312 | 21 | /* gpa_data初期化 */ | 
| KINU | 1:c142b1682312 | 22 | for(int j = 0; j < 256; j++) | 
| KINU | 1:c142b1682312 | 23 | gps_data[j] = '\0'; | 
| KINU | 1:c142b1682312 | 24 | |
| KINU | 1:c142b1682312 | 25 | /* NMEAから一行読み込み */ | 
| KINU | 1:c142b1682312 | 26 | while((gps_data[i] = _gps.getc()) != '\r') { | 
| KINU | 1:c142b1682312 | 27 | i++; | 
| KINU | 1:c142b1682312 | 28 | if(i == 256) { | 
| KINU | 1:c142b1682312 | 29 | i = 255; | 
| KINU | 1:c142b1682312 | 30 | break; | 
| KINU | 1:c142b1682312 | 31 | } | 
| KINU | 1:c142b1682312 | 32 | } | 
| KINU | 1:c142b1682312 | 33 | } while(strstr(gps_data, "GPGGA") == NULL); //GGAセンテンスまで一行ずつ読み込み続ける | 
| KINU | 1:c142b1682312 | 34 | |
| KINU | 1:c142b1682312 | 35 | int rlock; | 
| KINU | 1:c142b1682312 | 36 | char ns,ew; | 
| KINU | 1:c142b1682312 | 37 | double w_time, raw_longitude, raw_latitude; | 
| KINU | 1:c142b1682312 | 38 | int satnum; | 
| KINU | 1:c142b1682312 | 39 | double hdop; | 
| KINU | 1:c142b1682312 | 40 | |
| KINU | 1:c142b1682312 | 41 | if(sscanf(gps_data, "GPGGA, %lf, %lf, %c, %lf, %c, %d, %d, %lf", &w_time, &raw_latitude, &ns, &raw_longitude, &ew, &rlock, &satnum, &hdop) > 1) { | 
| KINU | 1:c142b1682312 | 42 | /* 座標1(度部分) */ | 
| KINU | 1:c142b1682312 | 43 | double latitude_dd = (double)(raw_latitude / 100); | 
| KINU | 1:c142b1682312 | 44 | double longitude_dd = (double)(raw_longitude / 100); | 
| KINU | 1:c142b1682312 | 45 | |
| KINU | 1:c142b1682312 | 46 | /* 座標2(分部分 → 度) */ | 
| KINU | 1:c142b1682312 | 47 | double latitude_md = (raw_latitude - latitude_dd * 100) / 60; | 
| KINU | 1:c142b1682312 | 48 | double longitude_md = (raw_longitude - longitude_dd * 100) / 60; | 
| KINU | 1:c142b1682312 | 49 | |
| KINU | 1:c142b1682312 | 50 | /* 座標1 + 2 */ | 
| KINU | 1:c142b1682312 | 51 | latitude = latitude_dd + latitude_md; | 
| KINU | 1:c142b1682312 | 52 | longitude = longitude_dd + longitude_md; | 
| KINU | 1:c142b1682312 | 53 | |
| KINU | 1:c142b1682312 | 54 | return true; | 
| KINU | 1:c142b1682312 | 55 | } else | 
| KINU | 1:c142b1682312 | 56 | return false; //GGAセンテンスの情報が欠けている時 | 
| KINU | 1:c142b1682312 | 57 | } | 
| KINU | 1:c142b1682312 | 58 |