#ifndef CRSLIDARDEVICE_H #define CRSLIDARDEVICE_H #include "IRsLidarDevice.h" // SDK 内部以 uint8_t* 调用 recvfrom(),但 C++ 中 char*/unsigned char*/signed char* // 是三种独立类型,MSVC 拒绝 uint8_t*(=unsigned char*) → char* 的隐式转换。 // 此重载在 SDK 头文件之前定义,利用重载决议的精确匹配规则拦截调用并内部转型。 #ifdef _WIN32 #include #pragma comment(lib, "ws2_32.lib") inline int recvfrom(SOCKET s, unsigned char* buf, int len, int flags, sockaddr* from, int* fromlen) { return ::recvfrom(s, reinterpret_cast(buf), len, flags, from, fromlen); } #endif // SDK 依赖 std::array / int16_t / uint16_t,但其内部缺少对应的 #include, // 在 Linux 上通过 libstdc++ 间接包含可用,MSVC STL 不会间接拉入,需在此处显式引入。 #include #include // SDK 头文件全部放在私有层,不污染公共接口 #include #include #include #include #include #include #include #include #include using namespace robosense::lidar; class CRsLidarDevice : public IRsLidarDevice { public: CRsLidarDevice(); ~CRsLidarDevice(); int InitDevice() override; int OpenDevice(const RsLidarConfig& config) override; int CloseDevice() override; bool IsOpened() const override; int Start() override; int Stop() override; bool IsRunning() const override; int SetPointCloudCallback(PointCloudCallback callback) override; int SetPacketCallback(PacketCallback callback) override; int SetExceptionCallback(ExceptionCallback callback) override; std::string GetVersion() override; private: // SDK 内部类型别名 using SdkCloudMsg = PointCloudT; using SdkCloudPtr = std::shared_ptr; void processCloudThread(); SdkCloudPtr getFreeCloud(); void putStuffedCloud(SdkCloudPtr msg); /// 将 SDK Packet 转为 RsPacketInfo 后转发给用户 void onPacket(const Packet& pkt); /// 将 SDK Error 转为 RsExceptionInfo 后转发给用户 void onException(const Error& code); /// RsLidarConfig → RSDriverParam static RSDriverParam toDriverParam(const RsLidarConfig& config); bool m_bOpened = false; std::atomic m_bRunning{false}; std::atomic m_bStopProcess{false}; PointCloudCallback m_pointCloudCallback; PacketCallback m_packetCallback; ExceptionCallback m_exceptionCallback; std::mutex m_callbackMutex; std::unique_ptr> m_pDriver; std::thread m_processThread; SyncQueue m_freeQueue; SyncQueue m_stuffedQueue; RSDriverParam m_param; }; #endif // CRSLIDARDEVICE_H