Skip to content

Commit

Permalink
perf(hw_interface): write packet data directly into the message (auto…
Browse files Browse the repository at this point in the history
…warefoundation#102)

Signed-off-by: M. Fatih Cırıt <mfc@leodrive.ai>
  • Loading branch information
xmfcx committed Dec 5, 2023
1 parent a1a2290 commit 9b239c6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,9 @@ void HesaiHwInterface::ReceiveCloudPacketCallback(const std::vector<uint8_t> & b
PrintDebug("Invalid Packet: " + std::to_string(buffer.size()));
return;
}
uint32_t buffer_size = buffer.size();
std::array<uint8_t, MTU_SIZE> packet_data{};
std::copy_n(std::make_move_iterator(buffer.begin()), buffer_size, packet_data.begin());
const uint32_t buffer_size = buffer.size();
pandar_msgs::msg::PandarPacket pandar_packet;
pandar_packet.data = packet_data;
std::copy_n(std::make_move_iterator(buffer.begin()), buffer_size, pandar_packet.data.begin());
pandar_packet.size = buffer_size;
auto now = std::chrono::system_clock::now();
auto now_secs = std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()).count();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,13 @@ Status VelodyneHwInterface::RegisterScanCallback(
void VelodyneHwInterface::ReceiveCloudPacketCallback(const std::vector<uint8_t> & buffer)
{
// Process current packet
uint32_t buffer_size = buffer.size();
std::array<uint8_t, 1206> packet_data{};
std::copy_n(std::make_move_iterator(buffer.begin()), buffer_size, packet_data.begin());
const uint32_t buffer_size = buffer.size();
velodyne_msgs::msg::VelodynePacket velodyne_packet;
std::copy_n(std::make_move_iterator(buffer.begin()), buffer_size, velodyne_packet.data.begin());
auto now = std::chrono::system_clock::now();
auto now_secs = std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()).count();
auto now_nanosecs =
std::chrono::duration_cast<std::chrono::nanoseconds>(now.time_since_epoch()).count();
velodyne_packet.data = packet_data;
velodyne_packet.stamp.sec = static_cast<int>(now_secs);
velodyne_packet.stamp.nanosec = static_cast<std::uint32_t>(now_nanosecs % 1'000'000'000);
scan_cloud_ptr_->packets.emplace_back(velodyne_packet);
Expand Down

0 comments on commit 9b239c6

Please sign in to comment.