Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <novatel_gps_driver/parsers/header.h>
00031
00032 #include <ros/ros.h>
00033
00034 uint32_t novatel_gps_driver::HeaderParser::GetMessageId() const
00035 {
00036 return 0;
00037 }
00038
00039 const std::string novatel_gps_driver::HeaderParser::GetMessageName() const
00040 {
00041 return "HEADER";
00042 }
00043
00044 novatel_gps_msgs::NovatelMessageHeader novatel_gps_driver::HeaderParser::ParseBinary(
00045 const novatel_gps_driver::BinaryMessage& bin_msg) throw(ParseException)
00046 {
00047
00048
00049 novatel_gps_msgs::NovatelMessageHeader msg;
00050 msg.port = PORT_IDENTIFIERS[bin_msg.header_.port_address_];
00051 msg.sequence_num = bin_msg.header_.sequence_;
00052 msg.percent_idle_time = bin_msg.header_.idle_time_;
00053 switch (bin_msg.header_.time_status_)
00054 {
00055 case 20:
00056 msg.gps_time_status = "UNKNOWN";
00057 break;
00058 case 60:
00059 msg.gps_time_status = "APPROXIMATE";
00060 break;
00061 case 80:
00062 msg.gps_time_status = "COARSEADJUSTING";
00063 break;
00064 case 100:
00065 msg.gps_time_status = "COARSE";
00066 break;
00067 case 120:
00068 msg.gps_time_status = "COARSESTEERING";
00069 break;
00070 case 130:
00071 msg.gps_time_status = "FREEWHEELING";
00072 break;
00073 case 140:
00074 msg.gps_time_status = "FINEADJUSTING";
00075 break;
00076 case 160:
00077 msg.gps_time_status = "FINE";
00078 break;
00079 case 170:
00080 msg.gps_time_status = "FINEBACKUPSTEERING";
00081 break;
00082 case 180:
00083 msg.gps_time_status = "FINESTEERING";
00084 break;
00085 case 200:
00086 msg.gps_time_status = "SATTIME";
00087 break;
00088 default:
00089 {
00090 std::stringstream error;
00091 error << "Unknown GPS time status: " << bin_msg.header_.time_status_;
00092 throw ParseException(error.str());
00093 }
00094 }
00095 msg.gps_week_num = bin_msg.header_.week_;
00096 msg.gps_seconds = static_cast<double>(bin_msg.header_.gps_ms_) / 1000.0;
00097 GetNovatelReceiverStatusMessage(bin_msg.header_.receiver_status_, msg.receiver_status);
00098 msg.receiver_software_version = bin_msg.header_.receiver_sw_version_;
00099
00100 return msg;
00101 }
00102
00103 novatel_gps_msgs::NovatelMessageHeader novatel_gps_driver::HeaderParser::ParseAscii(
00104 const novatel_gps_driver::NovatelSentence& sentence) throw(ParseException)
00105 {
00106 if (sentence.header.size() != NOVATEL_MESSAGE_HEADER_LENGTH)
00107 {
00108 std::stringstream error;
00109 error <<"Novatel message header size wrong: expected "
00110 << NOVATEL_MESSAGE_HEADER_LENGTH
00111 << ", got %zu"<< sentence.header.size();
00112 throw ParseException(error.str());
00113 }
00114
00115 bool valid = true;
00116
00117 novatel_gps_msgs::NovatelMessageHeader msg;
00118 msg.message_name = sentence.header[0];
00119 msg.port = sentence.header[1];
00120 valid = valid && ParseUInt32(sentence.header[2], msg.sequence_num);
00121 valid = valid && ParseFloat(sentence.header[3], msg.percent_idle_time);
00122 msg.gps_time_status = sentence.header[4];
00123 valid = valid && ParseUInt32(sentence.header[5], msg.gps_week_num);
00124 valid = valid && ParseDouble(sentence.header[6], msg.gps_seconds);
00125
00126 uint32_t receiver_status_code = 0;
00127 valid = valid && ParseUInt32(sentence.header[7], receiver_status_code, 16);
00128 GetNovatelReceiverStatusMessage(receiver_status_code, msg.receiver_status);
00129
00130 valid = valid && ParseUInt32(sentence.header[9], msg.receiver_software_version);
00131
00132 if (!valid)
00133 {
00134 throw ParseException("Header was invalid.");
00135 }
00136 return msg;
00137 }