69 std::memset(&time, 0,
sizeof(tm));
70 time.tm_year = nmea_time->year + (2000 - 1900);
71 time.tm_mon = nmea_time->mon - 1;
72 time.tm_mday = nmea_time->day;
73 time.tm_hour = nmea_time->hour;
77 static_cast<uint32_t
>((nmea_time->min * 60 + nmea_time->sec) * 1e6);
79 AINFO <<
"Set base unix time : " << time.tm_year <<
"-" << time.tm_mon <<
"-"
80 << time.tm_mday <<
" " << time.tm_hour <<
":" << time.tm_min <<
":"
82 uint64_t unix_base =
static_cast<uint64_t
>(timegm(&time));
83 *basetime = unix_base *
static_cast<uint64_t
>(1e6);
89 int rc =
input_->get_positioning_data_packet(nmea_time);
111 std::this_thread::sleep_for(std::chrono::microseconds(100));
112 AWARN <<
"basetime is zero";
118 if (poll_result == SOCKET_TIMEOUT || poll_result == RECEIVE_FAIL) {
122 if (scan->firing_pkts().empty()) {
128 ADEBUG <<
"Publishing a full Velodyne scan.";
129 scan->mutable_header()->set_timestamp_sec(
cyber::Time().Now().ToSecond());
135 uint32_t current_secs = *(
reinterpret_cast<uint32_t*
>(
136 const_cast<char*
>(scan->firing_pkts(0).data().data() + 1200)));
156 int rc =
input_->get_firing_data_packet(packet);
180 time_t t = time(NULL);
181 struct tm current_time;
182 localtime_r(&t, ¤t_time);
183 nmea_time->year =
static_cast<uint16_t
>(current_time.tm_year - 100);
184 nmea_time->mon =
static_cast<uint16_t
>(current_time.tm_mon + 1);
185 nmea_time->day =
static_cast<uint16_t
>(current_time.tm_mday);
186 nmea_time->hour =
static_cast<uint16_t
>(current_time.tm_hour);
187 nmea_time->min =
static_cast<uint16_t
>(current_time.tm_min);
188 nmea_time->sec =
static_cast<uint16_t
>(current_time.tm_sec);
189 AINFO <<
"Get NMEA Time from local time :"
190 <<
"year:" << nmea_time->year <<
"mon:" << nmea_time->mon
191 <<
"day:" << nmea_time->day <<
"hour:" << nmea_time->hour
192 <<
"min:" << nmea_time->min <<
"sec:" << nmea_time->sec;
208 std::this_thread::sleep_for(std::chrono::milliseconds(1));
220 basetime_ +=
static_cast<uint64_t
>(3600 * 1e6);
222 <<
". current:" << current_time <<
", last time:" <<
last_gps_time_;
224 AWARN <<
"Current stamp:" << std::fixed << current_time
226 <<
". GPS time stamp maybe incorrect!";
233 const std::shared_ptr<::apollo::cyber::Node>& node,
const Config& config) {
234 auto new_config = config;
235 if (new_config.prefix_angle() > 35900 || new_config.prefix_angle() < 100) {
236 AWARN <<
"invalid prefix angle, prefix_angle must be between 100 and 35900";
237 if (new_config.prefix_angle() > 35900) {
238 new_config.set_prefix_angle(35900);
239 }
else if (new_config.prefix_angle() < 100) {
240 new_config.set_prefix_angle(100);
244 switch (config.
model()) {
281 AERROR <<
"invalid model, must be 64E_S2|64E_S3S"
282 <<
"|64E_S3D|VLP16|HDL32E|VLS128";
291 std::shared_ptr<VelodyneScan> scan = std::make_shared<VelodyneScan>();
292 bool ret =
Poll(scan);
294 apollo::common::util::FillHeader(
"velodyne", scan.get());
297 AWARN <<
"device poll failed";
Cyber has builtin time type Time.
std::shared_ptr< cyber::Node > node_
static VelodyneDriver * CreateDriver(const std::shared_ptr<::apollo::cyber::Node > &node, const Config &config)
std::unique_ptr< Input > positioning_input_
static uint64_t sync_counter
void SetBaseTimeFromNmeaTime(NMEATimePtr nmea_time, uint64_t *basetime)
std::unique_ptr< Input > input_
virtual void PollPositioningPacket()
void SetPacketRate(const double packet_rate)
virtual bool Poll(const std::shared_ptr< VelodyneScan > &scan)
poll the device
std::thread positioning_thread_
bool Init() override
Initialize the lidar driver.
virtual ~VelodyneDriver()
std::shared_ptr< apollo::cyber::Writer< VelodyneScan > > writer_
virtual int PollStandard(std::shared_ptr< VelodyneScan > scan)
void UpdateGpsTopHour(uint32_t current_time)
Some string util functions.
constexpr double PACKET_RATE_HDL64E_S2
std::shared_ptr< NMEATime > NMEATimePtr
constexpr double PACKET_RATE_HDL64E_S3D
constexpr double PACKET_RATE_VLP16
constexpr double PACKET_RATE_HDL32E
constexpr double PACKET_RATE_HDL64E_S3S
constexpr double PACKET_RATE_VLP32C
constexpr double PACKET_RATE_VLS128
optional bool use_poll_sync
optional int32 firing_data_port
optional bool is_main_frame
optional bool use_gps_time
optional string scan_channel
optional int32 positioning_data_port