Apollo 10.0
自动驾驶开放平台
input.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
18
19namespace apollo {
20namespace drivers {
21namespace velodyne {
22
24 const uint8_t* bytes) {
25 unsigned int gprmc_index = 206;
26
27 int field_count = 0;
28 int time_field_index = 0;
29 int validity_field_index = 0;
30 int date_field_index = 0;
31 while (++gprmc_index < POSITIONING_DATA_PACKET_SIZE - 6 &&
32 bytes[gprmc_index] != '*') {
33 if (bytes[gprmc_index] == ',') {
34 ++field_count;
35 if (field_count == 1 && time_field_index == 0) {
36 time_field_index = gprmc_index + 1;
37 } else if (field_count == 2 && validity_field_index == 0) {
38 validity_field_index = gprmc_index + 1;
39 if (bytes[validity_field_index] == 'V') {
40 AERROR << "NAV receiver warning, GPS info is invalid!";
41 return false;
42 }
43 } else if (field_count == 9 && date_field_index == 0) {
44 date_field_index = gprmc_index + 1;
45 break;
46 }
47 }
48 }
49
50 if (gprmc_index == POSITIONING_DATA_PACKET_SIZE - 6) {
51 return false;
52 }
53
54 nmea_time->year =
55 static_cast<uint16_t>((bytes[date_field_index + 4] - '0') * 10 +
56 (bytes[date_field_index + 5] - '0'));
57 nmea_time->mon =
58 static_cast<uint16_t>((bytes[date_field_index + 2] - '0') * 10 +
59 (bytes[date_field_index + 3] - '0'));
60 nmea_time->day = static_cast<uint16_t>((bytes[date_field_index] - '0') * 10 +
61 (bytes[date_field_index + 1] - '0'));
62 nmea_time->hour = static_cast<uint16_t>((bytes[time_field_index] - '0') * 10 +
63 (bytes[time_field_index + 1] - '0'));
64 nmea_time->min =
65 static_cast<uint16_t>((bytes[time_field_index + 2] - '0') * 10 +
66 (bytes[time_field_index + 3] - '0'));
67 nmea_time->sec =
68 static_cast<uint16_t>((bytes[time_field_index + 4] - '0') * 10 +
69 (bytes[time_field_index + 5] - '0'));
70
71 if (nmea_time->year < 0 || nmea_time->year > 99 || nmea_time->mon > 12 ||
72 nmea_time->mon < 1 || nmea_time->day > 31 || nmea_time->day < 1 ||
73 nmea_time->hour > 23 || nmea_time->hour < 0 || nmea_time->min > 59 ||
74 nmea_time->min < 0 || nmea_time->sec > 59 || nmea_time->sec < 0) {
75 AERROR << "Invalid GPS time: " << nmea_time->year << "-" << nmea_time->mon
76 << "-" << nmea_time->day << " " << nmea_time->hour << ":"
77 << nmea_time->min << ":" << nmea_time->sec
78 << ", make sure have connected to GPS device";
79 return false;
80 }
81 return true;
82}
83
84} // namespace velodyne
85} // namespace drivers
86} // namespace apollo
bool exract_nmea_time_from_packet(NMEATimePtr nmea_time, const uint8_t *bytes)
Definition input.cc:23
#define AERROR
Definition log.h:44
std::shared_ptr< NMEATime > NMEATimePtr
Definition input.h:46
class register implement
Definition arena_queue.h:37