NMEA0813フォーマットのGPSから情報を取り出すプログラムです。
Dependents: GPS_test EM_Logger
Revision 1:f4d3c59a4917, committed 2013-06-02
- Comitter:
- YSB
- Date:
- Sun Jun 02 10:01:47 2013 +0000
- Parent:
- 0:42a334c405de
- Commit message:
- ?????nmea0813?????????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 Sun Jun 02 10:01:47 2013 +0000 @@ -12,7 +12,7 @@ void GPS::rxHandler(void){ - char rxbuf; + rxbuf = getc(); GPSdata[count] = rxbuf; if(rxbuf == '$'){ @@ -32,11 +32,10 @@ } void GPS::update_infomation() { //repeatedlly called function - get_GGA_RMC(GPSdata); - get_infomation(GPGGA,GPRMC); + set_GGA_RMC(GPSdata); } -void GPS::get_GGA_RMC(char* str){ +void GPS::set_GGA_RMC(char* str){ int nullflg=0; char *sp; @@ -50,6 +49,7 @@ nullflg = 1; } }else{ + //break; GPGGA[i] = '\n'; } } @@ -64,42 +64,29 @@ nullflg = 1; } }else{ + //break; 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; - } +char* GPS::get_time(){ + time_str[0]=GPGGA[7]; + time_str[1]=GPGGA[8]; time_str[2]=':'; - time_str[3]=gga[9]; - time_str[4]=gga[10]; + time_str[3]=GPGGA[9]; + time_str[4]=GPGGA[10]; time_str[5]=':'; - time_str[6]=gga[11]; - time_str[7]=gga[12]; - - states = rmc[18]; - + time_str[6]=GPGGA[11]; + time_str[7]=GPGGA[12]; + return time_str; +} + +float GPS::get_latitude(){ for(int i=0;i<9;i++){ - latitude_str[i]=gga[18+i]; + latitude_str[i]=GPGGA[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+ \ @@ -108,6 +95,20 @@ (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(){ + for(int i=0;i<9;i++){ + latitude_str[i]=GPGGA[18+i]; + } + return latitude_str; +} + +float GPS::get_longitude(){ + for(int i=0;i<10;i++){ + longitude_str[i]=GPGGA[30+i]; + } longitude = (float)(longitude_str[0]-0x30)*100.0+ \ (float)(longitude_str[1]-0x30)*10.0+ \ (float)(longitude_str[2]-0x30)+ \ @@ -117,32 +118,33 @@ (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(){ + for(int i=0;i<10;i++){ + longitude_str[i]=GPGGA[30+i]; + } return longitude_str; } -char GPS::get_states(){ - return states; +char GPS::get_status(){ + status = GPRMC[18]; + return status; } float GPS::get_speed(){ + for(int i=0;i<5;i++){ + speed_str[i]=GPRMC[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; return speed; +} + +char GPS::get_satelite_number(){ + number_of_satelite = GPGGA[46]; + return number_of_satelite; } \ No newline at end of file
--- a/nmea0813.h Fri Mar 29 05:55:53 2013 +0000 +++ b/nmea0813.h Sun Jun 02 10:01:47 2013 +0000 @@ -14,8 +14,9 @@ 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: @@ -27,17 +28,17 @@ float latitude; char longitude_str[10]; float longitude; - char states; + char status; char number_of_satelite; char speed_str[5]; float speed; int flg,count;//for rx_func() + char rxbuf; void rxHandler(void); void update_infomation(); - void get_GGA_RMC(char* str); - void get_infomation(char* gga,char* rmc); + void set_GGA_RMC(char* str); Ticker T; };