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.
Revision 2:578f518a6a05, committed 2018-06-08
- Comitter:
- Tomo073
- Date:
- Fri Jun 08 13:08:05 2018 +0000
- Parent:
- 1:2f131675f872
- Child:
- 3:940fe222bab0
- Commit message:
- a;
Changed in this revision
| GPS.cpp | Show annotated file Show diff for this revision Revisions of this file |
| GPS.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/GPS.cpp Fri May 04 15:16:02 2018 +0000
+++ b/GPS.cpp Fri Jun 08 13:08:05 2018 +0000
@@ -1,7 +1,5 @@
#include "mbed.h"
#include "GPS.h"
-#include "math.h"
-#include "stdio.h"
GPS::GPS(PinName gpstx,PinName gpsrx): serial(gpstx,gpsrx){
@@ -25,11 +23,7 @@
serial.baud(GPSBAUD);
- NVIC_SetPriority(UART2_IRQn,0);
-
- info = 1;
- reasonable = false;
-
+ //NVIC_SetPriority(UART2_IRQn,0);
//serial.attach(this,ExtractionData,Serial::RxIrq);
}
@@ -69,7 +63,7 @@
datadefault = serial.getc();
}
-void GPS::ExtractionData(){
+void GPS::GetData(){
Initialization();
@@ -77,20 +71,24 @@
if(datadefault == '$'){
- char DATA[20] = "\0";
+ char DATA[20] = "\0";
+
Initialization();
getstring(DATA);
if(!strcmp(DATA, "GPGGA")){
- //int info;
- for(info = 1; info < 6;info++){
+
+ int info;
+
+ for(info=1;info<11;info++){
+
getstring(DATA);
+
switch(info){
case 1:
time = strtof(DATA, NULL) + 90000.0;
break;
case 2:
- //latitude = strtof(DATA, NULL);
fMinutes = modff(strtof(DATA, NULL), &latitude)*60.0;
latitude = latitude*100.0 + fMinutes;
break;
@@ -99,8 +97,7 @@
latitude = latitude*-1.0;
}
break;
- case 4:
- //longtitude = strtof(DATA, NULL);
+ case 4:
fMinutes = modff(strtof(DATA, NULL), &longtitude)*60.0;
longtitude = longtitude*100.0 + fMinutes;
break;
@@ -116,40 +113,33 @@
if(strcmp(DATA, "M")){
altitude = altitude*-1.0;
}
- //m = 1;
readable = true;
break;
}
+
}
}
}
}
-void GPS::ExtractionData_FULL(){
-
- char DATA[20] = "\0";
-
+/*void GPS::ExtractionData_FULL(){
+
Initialization();
- if(!reasonable){
datadefault = serial.getc();
- if(datadefault == '$'){
-
- getstring(DATA);
+ if(datadefault == '$'){
- if(!strcmp(DATA, "GPGGA")){
- reasonable = true;
- }
- }
-
- }else{
-
+ char DATA[20] = "\0";
Initialization();
getstring(DATA);
- switch(info){
- case 1:
+ if(!strcmp(DATA, "GPGGA")){
+ int info;
+ for(info=1;info<11;info++){
+ getstring(DATA);
+ switch(info){
+ case 1:
Seconds = modff((strtof(DATA, NULL) + 90000.0)/100.0, &fHours)*100;
fMinutes = modff(fHours/100.0, &fHours)*100;
Hours = fHours;
@@ -181,16 +171,14 @@
break;
case 10:
sprintf(altitudeFULL, "%s%s", altitudeFULL, DATA);
- info = 0;
reasonable = false;
readable = true;
break;
- }
-
- info++;
- //sizeof
- }
-}
+ }
+ }
+ }
+ }
+}*/
void GPS::getstring(char a[]){
int n;
@@ -206,19 +194,20 @@
void GPS::Initialization(){
readable = false;
- Degrees = -1;
+ /*Degrees = -1;
Minutes = -1;
- Hours = -1;
+ Hours = -1;*/
longtitude = -1.0;
latitude = -1.0;
altitude = -1.0;
time = -1.0;
- fDegrees = -1.0;
+ //fDegrees = -1.0;
fMinutes = -1.0;
- Seconds = -1.0;
- fHours = -1.0;
- longtitudeFULL = "\0";
+ //Seconds = -1.0;
+ //fHours = -1.0;
+ /*longtitudeFULL = "\0";
latitudeFULL = "\0";
timeFULL = "\0";
- altitudeFULL = "\0";
+ altitudeFULL = "\0";*/
}
+
--- a/GPS.h Fri May 04 15:16:02 2018 +0000
+++ b/GPS.h Fri Jun 08 13:08:05 2018 +0000
@@ -2,11 +2,12 @@
GYSFDMAXB(GPS受信機1pps出力付きみちびき対応)用ライブラリ
written by ST
+ 緯度、経度、海抜、時間を出力
他の処理と並行するなら割り込み処理を使用すべし
ex:NVIC_SetPriority(UART2_IRQn,0); //0の部分で優先順位を決定
readable == true のとき正しいデータが出力
- ※経度、緯度、時間の読み方
+ ※経度、緯度、海抜、時間の読み方
lon,lat:ddmm.mmmm
dd:度
mm.mmmm:分(上一桁:10分、下一桁:1/10000分)
@@ -16,12 +17,14 @@
mm.分
ss.秒
+ alt:mm.mmmm
+
※機能
・GPS(TX,RX); コンストラクタ、ピン宣言
・GPS::attach(関数名); 割り込み処理設定
・GPS::GetDefault(); 編集前データ出力(char)
- ・gps.ExtractionData(); 編集データ出力(float gps.longtitude, float gps.latitude, float gps.timedefault)
- ・gps.ExtractionData_FULL(); 編集データ出力(書式は下記のサンプルプログラム参照)
+ ・gps.GetData(); 編集データ出力(float gps.longtitude, float gps.latitude, float gps.time)
+ ・gps.ExtractionData_FULL(); 編集データ出力(char* gps.longtitude, char* gps.latitude, char* gps.time)※未実装
@code
//----------------------------------------------------------------------------------------------------------------------------------------------------------
@@ -35,13 +38,14 @@
void getGPS(){
//NVIC_SetPriority(UART2_IRQn,0); //割り込み優先順位(必要に応じて)
- gps.ExtractionData_FULL(); //データ抽出
+ gps.GetData(); //データ抽出
if(gps.readable == true){
- //pc.printf("longtitude:%f latitude:%f time:%f\r\n", gps.longtitude, gps.latitude, gps.time); //gps.ExtractionData(); 書き込み(経度、緯度、時間)
+ pc.printf("longtitude:%f latitude:%f altitude:%f time:%f\r\n", gps.longtitude, gps.latitude, gps.altitude, gps.time); //書き込み(経度、緯度、時間)
}
}
int main(){
+ //pc.baud(115200); //mbedのボーレート(必要に応じて)
gps.attach(getGPS); //割り込み(関数名)
while(1){
//gps.GetDefault(); //元のデータ
@@ -67,20 +71,19 @@
bool readable;
char datadefault;
- char *longtitudeFULL, *latitudeFULL, *timeFULL, *altitudeFULL;
+ //char *longtitudeFULL, *latitudeFULL, *timeFULL, *altitudeFULL;
float longtitude, latitude, time, altitude, times;
void GPS::attach(void(*fn)());
void GetDefault();
- void ExtractionData();
- void ExtractionData_FULL();
+ void GetData();
+ //void ExtractionData_FULL();
private:
Serial serial;
- bool reasonable;
char buf[100];
- int info, Degrees, Minutes, Hours;
- float fDegrees, fMinutes, Seconds, fHours;
+ //int Degrees, Minutes, Hours;
+ float /*fDegrees,*/ fMinutes/*, Seconds, fHours*/;
void gpscmd(char *command);
void getstring(char DATA[]);
void Initialization();