NMEA0813フォーマットのGPSから情報を取り出すプログラムです。

Dependents:   GPS_test EM_Logger

Files at this revision

API Documentation at this revision

Comitter:
YSB
Date:
Fri Jul 05 04:17:36 2013 +0000
Parent:
0:42a334c405de
Child:
3:84d63345eb80
Child:
4:7be9581d0734
Commit message:
GPS

Changed in this revision

nmea0813.cpp Show annotated file Show diff for this revision Revisions of this file
nmea0813.h Show annotated file Show diff for this revision Revisions of this file
--- a/nmea0813.cpp	Fri Mar 29 05:55:53 2013 +0000
+++ b/nmea0813.cpp	Fri Jul 05 04:17:36 2013 +0000
@@ -1,9 +1,6 @@
 #include "nmea0813.h"
  
 GPS::GPS(PinName tx,PinName rx) : Serial(tx,rx){
-    //time_str[8] = {'0','0',':','0','0',':','0','0'};
-    //latitude_str[9] = {'0','0','0','0','.','0','0','0','0'};
-    //longitude_str[10]= {'0','0','0','0','0','.','0','0','0','0'};
     flg = 0;
     count = 0;
     attach(this, &GPS::rxHandler,Serial::RxIrq);
@@ -71,21 +68,19 @@
 }
 
 void GPS::get_infomation(char* gga,char* rmc){
-    if(gga[8]=='0'){
-        time_str[0]=gga[7];
-        time_str[1]=gga[8]+0x09;
-    }else{
-        time_str[0]=gga[7]+0x01;
-        time_str[1]=gga[8]-0x01;
-    }
+    time_str[0]=gga[7];
+    time_str[1]=gga[8];
     time_str[2]=':';
     time_str[3]=gga[9];
     time_str[4]=gga[10];
     time_str[5]=':';
     time_str[6]=gga[11];
     time_str[7]=gga[12];
+    //time_str[8]='\n';
     
-    states = rmc[18];
+    status = rmc[18];
+    
+    number_of_satelite = gga[46];
     
     for(int i=0;i<9;i++){
         latitude_str[i]=gga[18+i];
@@ -96,10 +91,13 @@
     for(int i=0;i<5;i++){
         speed_str[i]=rmc[51+i];
     }
-    speed = (float)(speed_str[0]-0x30)*100.0+\
-            (float)(speed_str[1]-0x30)*10.0+\
-            (float)(speed_str[2]-0x30)*1.0+\
-            (float)(speed_str[4]-0x30)*0.1;
+}
+
+char* GPS::get_time(){
+    return time_str;
+}
+
+float GPS::get_latitude(){
     latitude = (float)(latitude_str[0]-0x30)*10.0+  \
                (float)(latitude_str[1]-0x30)+       \
                ((float)(latitude_str[2]-0x30)*10.0+ \
@@ -108,6 +106,14 @@
                (float)(latitude_str[6]-0x30)*0.01+  \
                (float)(latitude_str[7]-0x30)*0.001+ \
                (float)(latitude_str[8]-0x30)*0.0001)/60.0;
+    return latitude;
+}
+
+char* GPS::get_str_latitude(){
+    return latitude_str;
+}
+
+float GPS::get_longitude(){
     longitude = (float)(longitude_str[0]-0x30)*100.0+ \
                (float)(longitude_str[1]-0x30)*10.0+  \
                (float)(longitude_str[2]-0x30)+       \
@@ -117,21 +123,6 @@
                (float)(longitude_str[7]-0x30)*0.01+  \
                (float)(longitude_str[8]-0x30)*0.001+ \
                (float)(longitude_str[9]-0x30)*0.0001)/60.0;
-}
-
-char* GPS::get_time(){
-    return time_str;
-}
-
-float GPS::get_latitude(){
-    return latitude;
-}
-
-char* GPS::get_str_latitude(){
-    return latitude_str;
-}
-
-float GPS::get_longitude(){
     return longitude;
 }
 
@@ -139,10 +130,18 @@
     return longitude_str;
 }
 
-char GPS::get_states(){
-    return states;
+char GPS::get_status(){
+    return status;
 }
 
 float GPS::get_speed(){
+    speed = (float)(speed_str[0]-0x30)*100.0+\
+            (float)(speed_str[1]-0x30)*10.0+\
+            (float)(speed_str[2]-0x30)*1.0+\
+            (float)(speed_str[4]-0x30)*0.1;
     return speed;
+}
+
+char GPS::get_satelite_number(){
+    return number_of_satelite;
 }
\ No newline at end of file
--- a/nmea0813.h	Fri Mar 29 05:55:53 2013 +0000
+++ b/nmea0813.h	Fri Jul 05 04:17:36 2013 +0000
@@ -14,20 +14,20 @@
     char* get_str_latitude();
     float get_longitude();
     char* get_str_longitude();
-    char get_states();
+    char get_status();
     float get_speed();
+    char get_satelite_number();
     
 private:
-
     char GPSdata[1000];  //gps_data_buffer
     char GPGGA[100];//GPGGA_data
     char GPRMC[100];//GPRMC_data
-    char time_str[8];
+    char time_str[9];
     char latitude_str[9];
     float latitude;
     char longitude_str[10];
     float longitude;
-    char states;
+    char status;
     char number_of_satelite;
     char speed_str[5];
     float speed;