シリアル割り込みを使ったGPSデータ整理用ライブラリ

Dependents:   Sample_GPSlib

Files at this revision

API Documentation at this revision

Comitter:
mikawataru
Date:
Fri Jul 28 17:46:22 2017 +0000
Parent:
1:8425c3fba1c3
Commit message:
fix calculation

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
diff -r 8425c3fba1c3 -r 482c199ca6de GPS.cpp
--- a/GPS.cpp	Sat Jul 15 15:08:02 2017 +0000
+++ b/GPS.cpp	Fri Jul 28 17:46:22 2017 +0000
@@ -1,5 +1,5 @@
 #include "mbed.h"
-#include "string.h"
+#include "string"
 #include "GPS.h"
 
 GPS::GPS(PinName tx, PinName rx) : gps(tx,rx){
@@ -36,8 +36,8 @@
     char lat,lon;
     if(sscanf(gps_data,"GPGGA,%f,%f,%c,%f,%c,%d,%d",&world_time,&lat_north,&lat,&lon_east,&lon,&rlock,&sat_num)>=1){
       if(rlock==1){
-        lat_north = calcLatitude(lat_north);
-        lon_east = calcLongitude(lon_east);
+        lat_north = DMS2DEG(lat_north);
+        lon_east = DMS2DEG(lon_east);
         debug->printf("%s\n",gps_data);
         debug->printf("Lat:%f,Lon%f\r\ntime:%f,sat_num:%d\r\n",lat_north,lon_east,world_time,sat_num);
       }else{
@@ -55,15 +55,8 @@
   gps.attach(this,&GPS::getGPS,Serial::RxIrq);
 }
 
-float GPS::calcLatitude(float raw_data){
-        int lat_d = (int)(raw_data/100);
-        float lat_m = (raw_data - (float)lat_d*100);
-        return (float)lat_d + lat_m/60;
-} 
-float GPS::calcLongitude(float raw_data){
-        int lon_d = (int)(raw_data/100);
-        float lon_m = (raw_data - (float)lon_d*100);
-        return (float)lon_d + lon_m/60;
-}
-
-
+float GPS::DMS2DEG(float raw_data){
+        int d = (int)(raw_data/100);
+        float m = (raw_data - (float)d*100);
+        return (float)d + m/60;
+} 
\ No newline at end of file
diff -r 8425c3fba1c3 -r 482c199ca6de GPS.h
--- a/GPS.h	Sat Jul 15 15:08:02 2017 +0000
+++ b/GPS.h	Fri Jul 28 17:46:22 2017 +0000
@@ -14,8 +14,7 @@
    void rateUP();
    void getGPS();
    void LogStart(PinName tx, PinName rx);
-   float calcLatitude(float raw_data); 
-   float calcLongitude(float raw_data);
+   float DMS2DEG(float raw_data); 
 };
 
 #endif
\ No newline at end of file