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

Dependents:   GPS_test EM_Logger

Revision:
0:42a334c405de
Child:
1:f4d3c59a4917
Child:
2:7870c69fa58c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nmea0813.cpp	Fri Mar 29 05:55:53 2013 +0000
@@ -0,0 +1,148 @@
+#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);
+    T.attach(this,&GPS::update_infomation,1.0);
+}
+ 
+ 
+void GPS::rxHandler(void){
+    char rxbuf;
+    rxbuf = getc();
+    GPSdata[count] = rxbuf;
+    if(rxbuf == '$'){       
+        count++;
+    }
+    else if(rxbuf == LF){
+        count++;
+        flg++;
+    }
+    else{
+        count++;
+    }
+    if(flg == 7){
+        flg = 0;
+        count=0;
+    }
+}
+
+void GPS::update_infomation() { //repeatedlly called function
+    get_GGA_RMC(GPSdata);
+    get_infomation(GPGGA,GPRMC);
+}
+
+void GPS::get_GGA_RMC(char* str){
+    int nullflg=0;
+    char *sp;
+
+    sp = (char*) strstr(str,"$GPGGA");
+    for(int i=0;i<80;i++){
+        if(nullflg ==0){
+            if(sp[i] != '\n'){
+                GPGGA[i] = sp[i];
+            }else{
+                GPGGA[i] = '\n';
+                nullflg = 1;
+            }
+        }else{
+            GPGGA[i] = '\n';
+        }           
+    }
+    nullflg = 0;
+    sp = (char*) strstr(str,"$GPRMC");
+    for(int i=0;i<80;i++){
+        if(nullflg ==0){
+            if(sp[i] != '\n'){
+                GPRMC[i] = sp[i];
+            }else{
+                GPRMC[i] = '\n';
+                nullflg = 1;
+            }
+        }else{
+            GPRMC[i] = '\n';
+        }           
+    }
+    nullflg = 0;
+}
+
+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[2]=':';
+    time_str[3]=gga[9];
+    time_str[4]=gga[10];
+    time_str[5]=':';
+    time_str[6]=gga[11];
+    time_str[7]=gga[12];
+    
+    states = rmc[18];
+    
+    for(int i=0;i<9;i++){
+        latitude_str[i]=gga[18+i];
+    }
+    for(int i=0;i<10;i++){
+        longitude_str[i]=gga[30+i];
+    }
+    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;
+    latitude = (float)(latitude_str[0]-0x30)*10.0+  \
+               (float)(latitude_str[1]-0x30)+       \
+               ((float)(latitude_str[2]-0x30)*10.0+ \
+               (float)(latitude_str[3]-0x30)+       \
+               (float)(latitude_str[5]-0x30)*0.1+   \
+               (float)(latitude_str[6]-0x30)*0.01+  \
+               (float)(latitude_str[7]-0x30)*0.001+ \
+               (float)(latitude_str[8]-0x30)*0.0001)/60.0;
+    longitude = (float)(longitude_str[0]-0x30)*100.0+ \
+               (float)(longitude_str[1]-0x30)*10.0+  \
+               (float)(longitude_str[2]-0x30)+       \
+               ((float)(longitude_str[3]-0x30)*10.0+ \
+               (float)(longitude_str[4]-0x30)+       \
+               (float)(longitude_str[6]-0x30)*0.1+   \
+               (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;
+}
+
+char* GPS::get_str_longitude(){
+    return longitude_str;
+}
+
+char GPS::get_states(){
+    return states;
+}
+
+float GPS::get_speed(){
+    return speed;
+}
\ No newline at end of file