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

Dependents:   GPS_test EM_Logger

Committer:
YSB
Date:
Sun Jun 02 10:01:47 2013 +0000
Revision:
1:f4d3c59a4917
Parent:
0:42a334c405de
?????nmea0813?????????GPS?????????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
YSB 0:42a334c405de 1 #include "nmea0813.h"
YSB 0:42a334c405de 2
YSB 0:42a334c405de 3 GPS::GPS(PinName tx,PinName rx) : Serial(tx,rx){
YSB 0:42a334c405de 4 //time_str[8] = {'0','0',':','0','0',':','0','0'};
YSB 0:42a334c405de 5 //latitude_str[9] = {'0','0','0','0','.','0','0','0','0'};
YSB 0:42a334c405de 6 //longitude_str[10]= {'0','0','0','0','0','.','0','0','0','0'};
YSB 0:42a334c405de 7 flg = 0;
YSB 0:42a334c405de 8 count = 0;
YSB 0:42a334c405de 9 attach(this, &GPS::rxHandler,Serial::RxIrq);
YSB 0:42a334c405de 10 T.attach(this,&GPS::update_infomation,1.0);
YSB 0:42a334c405de 11 }
YSB 0:42a334c405de 12
YSB 0:42a334c405de 13
YSB 0:42a334c405de 14 void GPS::rxHandler(void){
YSB 1:f4d3c59a4917 15
YSB 0:42a334c405de 16 rxbuf = getc();
YSB 0:42a334c405de 17 GPSdata[count] = rxbuf;
YSB 0:42a334c405de 18 if(rxbuf == '$'){
YSB 0:42a334c405de 19 count++;
YSB 0:42a334c405de 20 }
YSB 0:42a334c405de 21 else if(rxbuf == LF){
YSB 0:42a334c405de 22 count++;
YSB 0:42a334c405de 23 flg++;
YSB 0:42a334c405de 24 }
YSB 0:42a334c405de 25 else{
YSB 0:42a334c405de 26 count++;
YSB 0:42a334c405de 27 }
YSB 0:42a334c405de 28 if(flg == 7){
YSB 0:42a334c405de 29 flg = 0;
YSB 0:42a334c405de 30 count=0;
YSB 0:42a334c405de 31 }
YSB 0:42a334c405de 32 }
YSB 0:42a334c405de 33
YSB 0:42a334c405de 34 void GPS::update_infomation() { //repeatedlly called function
YSB 1:f4d3c59a4917 35 set_GGA_RMC(GPSdata);
YSB 0:42a334c405de 36 }
YSB 0:42a334c405de 37
YSB 1:f4d3c59a4917 38 void GPS::set_GGA_RMC(char* str){
YSB 0:42a334c405de 39 int nullflg=0;
YSB 0:42a334c405de 40 char *sp;
YSB 0:42a334c405de 41
YSB 0:42a334c405de 42 sp = (char*) strstr(str,"$GPGGA");
YSB 0:42a334c405de 43 for(int i=0;i<80;i++){
YSB 0:42a334c405de 44 if(nullflg ==0){
YSB 0:42a334c405de 45 if(sp[i] != '\n'){
YSB 0:42a334c405de 46 GPGGA[i] = sp[i];
YSB 0:42a334c405de 47 }else{
YSB 0:42a334c405de 48 GPGGA[i] = '\n';
YSB 0:42a334c405de 49 nullflg = 1;
YSB 0:42a334c405de 50 }
YSB 0:42a334c405de 51 }else{
YSB 1:f4d3c59a4917 52 //break;
YSB 0:42a334c405de 53 GPGGA[i] = '\n';
YSB 0:42a334c405de 54 }
YSB 0:42a334c405de 55 }
YSB 0:42a334c405de 56 nullflg = 0;
YSB 0:42a334c405de 57 sp = (char*) strstr(str,"$GPRMC");
YSB 0:42a334c405de 58 for(int i=0;i<80;i++){
YSB 0:42a334c405de 59 if(nullflg ==0){
YSB 0:42a334c405de 60 if(sp[i] != '\n'){
YSB 0:42a334c405de 61 GPRMC[i] = sp[i];
YSB 0:42a334c405de 62 }else{
YSB 0:42a334c405de 63 GPRMC[i] = '\n';
YSB 0:42a334c405de 64 nullflg = 1;
YSB 0:42a334c405de 65 }
YSB 0:42a334c405de 66 }else{
YSB 1:f4d3c59a4917 67 //break;
YSB 0:42a334c405de 68 GPRMC[i] = '\n';
YSB 0:42a334c405de 69 }
YSB 0:42a334c405de 70 }
YSB 0:42a334c405de 71 nullflg = 0;
YSB 0:42a334c405de 72 }
YSB 0:42a334c405de 73
YSB 1:f4d3c59a4917 74 char* GPS::get_time(){
YSB 1:f4d3c59a4917 75 time_str[0]=GPGGA[7];
YSB 1:f4d3c59a4917 76 time_str[1]=GPGGA[8];
YSB 0:42a334c405de 77 time_str[2]=':';
YSB 1:f4d3c59a4917 78 time_str[3]=GPGGA[9];
YSB 1:f4d3c59a4917 79 time_str[4]=GPGGA[10];
YSB 0:42a334c405de 80 time_str[5]=':';
YSB 1:f4d3c59a4917 81 time_str[6]=GPGGA[11];
YSB 1:f4d3c59a4917 82 time_str[7]=GPGGA[12];
YSB 1:f4d3c59a4917 83 return time_str;
YSB 1:f4d3c59a4917 84 }
YSB 1:f4d3c59a4917 85
YSB 1:f4d3c59a4917 86 float GPS::get_latitude(){
YSB 0:42a334c405de 87 for(int i=0;i<9;i++){
YSB 1:f4d3c59a4917 88 latitude_str[i]=GPGGA[18+i];
YSB 0:42a334c405de 89 }
YSB 0:42a334c405de 90 latitude = (float)(latitude_str[0]-0x30)*10.0+ \
YSB 0:42a334c405de 91 (float)(latitude_str[1]-0x30)+ \
YSB 0:42a334c405de 92 ((float)(latitude_str[2]-0x30)*10.0+ \
YSB 0:42a334c405de 93 (float)(latitude_str[3]-0x30)+ \
YSB 0:42a334c405de 94 (float)(latitude_str[5]-0x30)*0.1+ \
YSB 0:42a334c405de 95 (float)(latitude_str[6]-0x30)*0.01+ \
YSB 0:42a334c405de 96 (float)(latitude_str[7]-0x30)*0.001+ \
YSB 0:42a334c405de 97 (float)(latitude_str[8]-0x30)*0.0001)/60.0;
YSB 1:f4d3c59a4917 98 return latitude;
YSB 1:f4d3c59a4917 99 }
YSB 1:f4d3c59a4917 100
YSB 1:f4d3c59a4917 101 char* GPS::get_str_latitude(){
YSB 1:f4d3c59a4917 102 for(int i=0;i<9;i++){
YSB 1:f4d3c59a4917 103 latitude_str[i]=GPGGA[18+i];
YSB 1:f4d3c59a4917 104 }
YSB 1:f4d3c59a4917 105 return latitude_str;
YSB 1:f4d3c59a4917 106 }
YSB 1:f4d3c59a4917 107
YSB 1:f4d3c59a4917 108 float GPS::get_longitude(){
YSB 1:f4d3c59a4917 109 for(int i=0;i<10;i++){
YSB 1:f4d3c59a4917 110 longitude_str[i]=GPGGA[30+i];
YSB 1:f4d3c59a4917 111 }
YSB 0:42a334c405de 112 longitude = (float)(longitude_str[0]-0x30)*100.0+ \
YSB 0:42a334c405de 113 (float)(longitude_str[1]-0x30)*10.0+ \
YSB 0:42a334c405de 114 (float)(longitude_str[2]-0x30)+ \
YSB 0:42a334c405de 115 ((float)(longitude_str[3]-0x30)*10.0+ \
YSB 0:42a334c405de 116 (float)(longitude_str[4]-0x30)+ \
YSB 0:42a334c405de 117 (float)(longitude_str[6]-0x30)*0.1+ \
YSB 0:42a334c405de 118 (float)(longitude_str[7]-0x30)*0.01+ \
YSB 0:42a334c405de 119 (float)(longitude_str[8]-0x30)*0.001+ \
YSB 0:42a334c405de 120 (float)(longitude_str[9]-0x30)*0.0001)/60.0;
YSB 0:42a334c405de 121 return longitude;
YSB 0:42a334c405de 122 }
YSB 0:42a334c405de 123
YSB 0:42a334c405de 124 char* GPS::get_str_longitude(){
YSB 1:f4d3c59a4917 125 for(int i=0;i<10;i++){
YSB 1:f4d3c59a4917 126 longitude_str[i]=GPGGA[30+i];
YSB 1:f4d3c59a4917 127 }
YSB 0:42a334c405de 128 return longitude_str;
YSB 0:42a334c405de 129 }
YSB 0:42a334c405de 130
YSB 1:f4d3c59a4917 131 char GPS::get_status(){
YSB 1:f4d3c59a4917 132 status = GPRMC[18];
YSB 1:f4d3c59a4917 133 return status;
YSB 0:42a334c405de 134 }
YSB 0:42a334c405de 135
YSB 0:42a334c405de 136 float GPS::get_speed(){
YSB 1:f4d3c59a4917 137 for(int i=0;i<5;i++){
YSB 1:f4d3c59a4917 138 speed_str[i]=GPRMC[51+i];
YSB 1:f4d3c59a4917 139 }
YSB 1:f4d3c59a4917 140 speed = (float)(speed_str[0]-0x30)*100.0+\
YSB 1:f4d3c59a4917 141 (float)(speed_str[1]-0x30)*10.0+\
YSB 1:f4d3c59a4917 142 (float)(speed_str[2]-0x30)*1.0+\
YSB 1:f4d3c59a4917 143 (float)(speed_str[4]-0x30)*0.1;
YSB 0:42a334c405de 144 return speed;
YSB 1:f4d3c59a4917 145 }
YSB 1:f4d3c59a4917 146
YSB 1:f4d3c59a4917 147 char GPS::get_satelite_number(){
YSB 1:f4d3c59a4917 148 number_of_satelite = GPGGA[46];
YSB 1:f4d3c59a4917 149 return number_of_satelite;
YSB 0:42a334c405de 150 }