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; //getGPS.hで宣言した値を初期化 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() //GPSのデータを取得する関数の中身 00013 { 00014 char gps_data[256]; 00015 int i; 00016 00017 do { 00018 while(_gps.getc() != '$');//$マークまで読み飛ばし 00019 /*送ったリンクのサイトに『1つのセンテンスは、「$」で始まり、「(改行(\r\n))」で終わります。』 00020 とあるので、_gps.getc()が取得する値が$以外の場合は無視して、$が始まったところを探すためにループしている。*/ 00021 i = 0; 00022 00023 /* gpa_data初期化 */ 00024 for(int j = 0; j < 256; j++) 00025 gps_data[j] = '\0'; 00026 00027 /* NMEAから一行読み込み */ 00028 while((gps_data[i] = _gps.getc()) != '\r') {//受信したデータを配列に格納し、'\r'でない場合ループ 00029 i++; 00030 if(i == 256) { 00031 i = 255; 00032 return 0;; 00033 } 00034 } 00035 } while(strstr(gps_data, "GPGGA") == NULL); //GGAセンテンスまで一行ずつ読み込み続ける 00036 00037 int rlock; 00038 char ns,ew; 00039 double w_time, raw_longitude, raw_latitude; 00040 int satnum; 00041 double hdop; 00042 00043 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) { 00044 //取得したデータを読み込んでいる 詳しくはリンクを送ります 00045 /* 座標1(度部分) */ 00046 double latitude_dd = (double)(raw_latitude / 100); 00047 double longitude_dd = (double)(raw_longitude / 100); 00048 00049 /* 座標2(分部分 → 度) */ 00050 double latitude_md = (raw_latitude - latitude_dd * 100) / 60; 00051 double longitude_md = (raw_longitude - longitude_dd * 100) / 60; 00052 00053 /* 座標1 + 2 */ 00054 latitude = latitude_dd + latitude_md; 00055 longitude = longitude_dd + longitude_md; 00056 00057 return true; 00058 //ここまでgpsが受信する値は単位が度になっていないので、度に直している 00059 } else 00060 return false; //GGAセンテンスの情報が欠けている時 00061 }
Generated on Sun Aug 14 2022 16:01:16 by
1.7.2