Β
#include <iostream> #include <boost/asio.hpp> #include "livox_lidar_api.h" #include "livox_lidar_def.h" using boost::asio::ip::udp; const std::string SERVER_IP = "192.168.0.102"; // μ€μ μλ² IP const int SERVER_PORT = 12345; // μ€μ μλ² ν¬νΈ // UDP μμΌ μ€μ boost::asio::io_context io_context; udp::socket socket(io_context, udp::endpoint(udp::v4(), 0)); udp::endpoint server_endpoint(boost::asio::ip::address::from_string(SERVER_IP), SERVER_PORT); // LiDAR λ°μ΄ν° μ½λ°± ν¨μ void PointCloudCallback(uint32_t handle, const uint8_t dev_type, LivoxLidarEthernetPacket* data, void* client_data) { if (data == nullptr || data->data_type != kLivoxLidarCartesianCoordinateHighData) { return; } auto* points = reinterpret_cast<const LivoxLidarCartesianHighRawPoint*>(data->data); size_t point_count = data->length / sizeof(LivoxLidarCartesianHighRawPoint); // λ°μ΄ν°λ₯Ό μ§λ ¬ννμ¬ μ μ‘ std::vector<uint8_t> serialized_data(reinterpret_cast<const uint8_t*>(points), reinterpret_cast<const uint8_t*>(points) + data->length); try { socket.send_to(boost::asio::buffer(serialized_data), server_endpoint); std::cout << "Sent " << serialized_data.size() << " bytes to server." << std::endl; } catch (std::exception& e) { std::cerr << "Error sending data: " << e.what() << std::endl; } } int main(int argc, const char* argv[]) { if (argc != 2) { std::cerr << "Usage: " << argv[0] << " <config_path>" << std::endl; return -1; } const std::string config_path = argv[1]; if (!LivoxLidarSdkInit(config_path.c_str())) { std::cerr << "Failed to initialize Livox SDK." << std::endl; return -1; } SetLivoxLidarPointCloudCallBack(PointCloudCallback, nullptr); std::this_thread::sleep_for(std::chrono::seconds(30)); LivoxLidarSdkUninit(); return 0; }
Β