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.
getGPS.cpp
00001 #include "mbed.h" 00002 #include "getGPS.h" 00003 00004 GPS::GPS(PinName gpstx,PinName gpsrx): _gps(gpstx,gpsrx) 00005 { 00006 latitude = 0; 00007 longitude = 0; 00008 _gps.baud(GPSBAUD); 00009 _gps.printf("$PMTK314,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29"); 00010 } 00011 00012 bool GPS::getgps() 00013 { 00014 char gps_data[256]; 00015 int i; 00016 00017 do { 00018 while(_gps.getc() != '$'); //$マークまで読み飛ばし 00019 i = 0; 00020 00021 /* gpa_data初期化 */ 00022 for(int j = 0; j < 256; j++) 00023 gps_data[j] = '\0'; 00024 00025 /* NMEAから一行読み込み */ 00026 while((gps_data[i] = _gps.getc()) != '\r') { 00027 i++; 00028 if(i == 256) { 00029 i = 255; 00030 break; 00031 } 00032 } 00033 } while(strstr(gps_data, "GPGGA") == NULL); //GGAセンテンスまで一行ずつ読み込み続ける 00034 00035 int rlock; 00036 char ns,ew; 00037 double w_time, raw_longitude, raw_latitude; 00038 int satnum; 00039 double hdop; 00040 00041 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) { 00042 /* 座標1(度部分) */ 00043 double latitude_dd = (double)(raw_latitude / 100); 00044 double longitude_dd = (double)(raw_longitude / 100); 00045 00046 /* 座標2(分部分 → 度) */ 00047 double latitude_md = (raw_latitude - latitude_dd * 100) / 60; 00048 double longitude_md = (raw_longitude - longitude_dd * 100) / 60; 00049 00050 /* 座標1 + 2 */ 00051 latitude = latitude_dd + latitude_md; 00052 longitude = longitude_dd + longitude_md; 00053 00054 return true; 00055 } else 00056 return false; //GGAセンテンスの情報が欠けている時 00057 } 00058
Generated on Mon Jul 18 2022 23:53:13 by
