Mbed library to get location informatiuon from GYSFDMAXB
Dependents: nucleo_GPS_rev3 STM32_MR_include_IM_rev2
秋月電子のGPS受信機キット 1PPS出力付き 「みちびき」対応からデータを取得するためのライブラリです クラスを宣言した後、変数のlongtitude,latitudeを読むことでデータを取得できます。更新は自動です。 googleで検索できるdd.dddd°表記となっています。
Diff: GPS.cpp
- Revision:
- 2:bd69260c2bd1
- Parent:
- 1:68601d2af8a5
--- a/GPS.cpp Fri Jun 10 07:57:28 2016 +0000 +++ b/GPS.cpp Mon Jul 25 07:40:37 2016 +0000 @@ -63,8 +63,9 @@ int counter; char sample=0x00; - int point1=0; - int point2=0; + + + for(counter=0;counter<18;counter++){ @@ -76,26 +77,31 @@ //初期化 latitude=0; longtitude=0; + speed=0; + direction=0; //データ取得 + for(int i=0;i<4;i++){ + point[i]=0; + } + + int pointnum=0; for(counter=0;sample!='\n';counter++){ sample=_gps.getc(); buf[counter]=sample; - if(buf[counter]=='.'&&point1==0){ - point1=counter; + if(buf[counter]=='.'){ + point[pointnum]=counter; + pointnum++; } - if(counter>8&&buf[counter]=='.'&&point2==0){ - point2=counter; - } } //緯度計算 - for(counter=1;counter<point1-2;counter++){ + for(counter=1;counter<point[0]-2;counter++){ float num=1; - for(int i=point1-counter-3;i>0;i--){ + for(int i=point[0]-counter-3;i>0;i--){ num=num*10; } @@ -104,13 +110,13 @@ float minute=0; - minute+=(buf[point1-2]-48)*10; - minute+=(buf[point1-1]-48); + minute+=(buf[point[0]-2]-48)*10; + minute+=(buf[point[0]-1]-48); - for(counter=point1+1;counter<point1+5;counter++){ + for(counter=point[0]+1;counter<point[0]+5;counter++){ float num=1; - for(int i=counter-point1;i>0;i--){ + for(int i=counter-point[0];i>0;i--){ num=num*0.1f; } @@ -121,10 +127,10 @@ //経度計算 - for(counter=point1+8;counter<point2-2;counter++){ + for(counter=point[0]+8;counter<point[1]-2;counter++){ float num=1; - for(int i=point2-counter-3;i>0;i--){ + for(int i=point[1]-counter-3;i>0;i--){ num=num*10; } @@ -133,13 +139,13 @@ minute=0; - minute+=(buf[point2-2]-48)*10; - minute+=(buf[point2-1]-48); + minute+=(buf[point[1]-2]-48)*10; + minute+=(buf[point[1]-1]-48); - for(counter=point2+1;counter<point2+5;counter++){ + for(counter=point[1]+1;counter<point[1]+5;counter++){ float num=1; - for(int i=counter-point2;i>0;i--){ + for(int i=counter-point[1];i>0;i--){ num=num*0.1f; } @@ -149,6 +155,40 @@ longtitude+=minute/60; + //速度計算 + for(counter=point[1]+9;counter<point[1];counter++){ + + float num=1; + for(int i=point[2]-counter-1;i>0;i--){ + num=num*10; + } + + speed+=(float)num*(buf[counter]-48); + } + + + speed+=(buf[point[2]+2]-48)*0.01; + speed+=(buf[point[2]+1]-48)*0.1; + + speed/=0.51444; + + //方位計算 + for(counter=point[2]+4;counter<point[3];counter++){ + + float num=1; + for(int i=point[3]-counter-1;i>0;i--){ + num=num*10; + } + + direction+=(float)num*(buf[counter]-48); + } + + + direction+=(buf[point[3]+2]-48)*0.01; + direction+=(buf[point[3]+1]-48)*0.1; + + + result=true; }