test ver (get more data from GPS)
Dependents: sample_GPS_GYSFDMAXB_edite_by_asha GPSDRV8833CanSat
Diff: getGPS.cpp
- Revision:
- 2:4a3a10bc7309
- Parent:
- 0:030ffb18f36d
- Child:
- 3:0ad6cc87d7cd
--- a/getGPS.cpp Sat Jul 07 08:06:16 2018 +0000 +++ b/getGPS.cpp Sat Jun 12 21:16:25 2021 +0000 @@ -3,8 +3,14 @@ GPS::GPS(PinName gpstx,PinName gpsrx): _gps(gpstx,gpsrx) { - latitude = 0; - longitude = 0; + gpstime =0; //GPSから取得した時刻。 + longitude =0; + latitude =0; + hdop =0; //位置情報精度 + hight =0; //海抜高度 + //GPVTG + direction =0; //進行方向(真北基準) + speed =0; //対地速度kmph _gps.baud(GPSBAUD); _gps.printf("$PMTK314,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29"); } @@ -12,9 +18,13 @@ bool GPS::getgps() { char gps_data[256]; - int i; + char gpgga_data[256]; + char gpvtg_data[256]; - do { + int i; + int flag1 = 0; //GPGGA + int flag2 = 0; //GPVTG + for (int p=0; p<50; p++){ while(_gps.getc() != '$'); //$マークまで読み飛ばし i = 0; @@ -30,28 +40,53 @@ break; } } - } while(strstr(gps_data, "GPGGA") == NULL); //GGAセンテンスまで一行ずつ読み込み続ける - + if (strstr(gps_data, "GPGGA") != NULL){ + strcpy(gpgga_data,gps_data); + flag1=1; + } + if(strstr(gps_data, "GPVTG") != NULL){ + strcpy(gpvtg_data,gps_data); + flag2=1; + } + if (flag1 * flag2== 0){ + break; + } + } //GPGGAとGPVTGが取得できるまで1行ずつ読む + //For GPGGA================================================================ int rlock; char ns,ew; double w_time, raw_longitude, raw_latitude; int satnum; - double hdop; - 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) { - /* 座標1(度部分) */ + if(sscanf(gpgga_data, "GPGGA,%lf,%lf,%c,%lf,%c,%d,%d,%lf,%lf", &w_time, &raw_latitude, &ns, &raw_longitude, &ew, &rlock, &satnum, &hdop, &hight) > 1) { + /* 座標を求める (度と分で分割して度にする。intは切り捨て)*/ int latitude_dd = (int)(raw_latitude / 100); int longitude_dd = (int)(raw_longitude / 100); - - /* 座標2(分部分 → 度) */ int latitude_md = (raw_latitude - latitude_dd * 100) / 60; int longitude_md = (raw_longitude - longitude_dd * 100) / 60; - - /* 座標1 + 2 */ latitude = latitude_dd + latitude_md; longitude = longitude_dd + longitude_md; - + flag1 = 1; + }else{ + flag1 = 0; //GGAセンテンスの情報が欠けている時 + } + + //For GPVTG================================================================ + char c1, c2,c3; + double f1, f2, f3, f4; + if(sscanf(gpvtg_data, "GPVTG, %lf, %c, %lf, %c, %lf, %c, %lf", &f1, &c1, &f2, &c2, &f3, &c3, &f4)>1){ + direction = f1; + speed = f4; + flag2 = 1; + }else{ + flag2 = 0; + } + //return + if (flag1*flag2 ==1){ return true; - } else - return false; //GGAセンテンスの情報が欠けている時 + }else{ + return false; + } + + }