38 logger = logging.getLogger(
'rosout')
65 utc_struct = time.gmtime()
66 utc_list = list(utc_struct)
68 if not nmea_utc[0:2]
or not nmea_utc[2:4]
or not nmea_utc[4:6]:
71 hours = int(nmea_utc[0:2])
72 minutes = int(nmea_utc[2:4])
73 seconds = int(nmea_utc[4:6])
77 unix_time = calendar.timegm(tuple(utc_list))
82 if status_flag ==
"A":
84 elif status_flag ==
"V":
98 """Format for this is a sentence identifier (e.g. "GGA") as the key, with a 99 tuple of tuples where each tuple is a field name, conversion function and index 100 into the split sentence""" 103 (
"fix_type", int, 6),
104 (
"latitude", convert_latitude, 2),
105 (
"latitude_direction", str, 3),
106 (
"longitude", convert_longitude, 4),
107 (
"longitude_direction", str, 5),
108 (
"altitude", safe_float, 9),
109 (
"mean_sea_level", safe_float, 11),
110 (
"hdop", safe_float, 8),
111 (
"num_satellites", safe_int, 7),
112 (
"utc_time", convert_time, 1),
115 (
"utc_time", convert_time, 1),
116 (
"fix_valid", convert_status_flag, 2),
117 (
"latitude", convert_latitude, 3),
118 (
"latitude_direction", str, 4),
119 (
"longitude", convert_longitude, 5),
120 (
"longitude_direction", str, 6),
121 (
"speed", convert_knots_to_mps, 7),
122 (
"true_course", convert_deg_to_rads, 8),
129 if not re.match(
'(^\$GP|^\$GN|^\$GL).*\*[0-9A-Fa-f]{2}$', nmea_sentence):
130 logger.debug(
"Regex didn't match, sentence not valid NMEA? Sentence was: %s" 131 % repr(nmea_sentence))
133 fields = [field.strip(
',')
for field
in nmea_sentence.split(
',')]
136 sentence_type = fields[0][3:]
138 if not sentence_type
in parse_maps:
139 logger.debug(
"Sentence type %s not in parse map, ignoring." 140 % repr(sentence_type))
143 parse_map = parse_maps[sentence_type]
146 for entry
in parse_map:
147 parsed_sentence[entry[0]] = entry[1](fields[entry[2]])
149 return {sentence_type: parsed_sentence}
def convert_status_flag(status_flag)
def convert_time(nmea_utc)
def convert_deg_to_rads(degs)
def parse_nmea_sentence(nmea_sentence)
def convert_latitude(field)
def convert_longitude(field)
def convert_knots_to_mps(knots)