GrabBag/Device/RsLidarDevice/Inc/IRsLidarDevice.h
2026-06-14 17:01:09 +08:00

139 lines
5.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef IRSLIDARDEVICE_H
#define IRSLIDARDEVICE_H
#include <functional>
#include <string>
#include <vector>
#include "RsLidarDevice_global.h"
#include "VZNL_Types.h" // SVzNLPointXYZI — 项目标准点格式mm, float
// ============================================================
// 自定义数据类型 — 完全不依赖 rs_driver SDK
// 使用内置类型(unsigned char/short/int)替代 stdint.h
// 以避免跨编译器的头文件兼容性问题
// ============================================================
/// 统一点云格式:与 CloudShow::CloudData 同型
/// Device 已完成 NaN→0 + 坐标修正 (X右Y下Z前) + 米→毫米 + 拆线
using RsCloudData = std::vector<std::pair<EVzResultDataType, SVzLaserLineData>>;
/// 帧元信息(与 CloudFrameInfo 字段一致,直接传递)
struct RsFrameInfo
{
uint32_t height = 0;
uint32_t width = 0;
bool isDense = false;
};
/// 原始数据包信息is_frame_begin=1 表示新一圈扫描起始)
struct RsPacketInfo
{
double timestamp = 0.0;
unsigned int seq = 0;
unsigned char is_difop = 0;
unsigned char is_frame_begin = 0; ///< =1 新一帧扫描开始
std::string frameId;
unsigned int dataSize = 0; ///< 原始数据字节数
};
/// 异常/错误信息
struct RsExceptionInfo
{
int code = 0;
std::string message;
};
/// LiDAR 配置参数
struct RsLidarConfig
{
std::string lidarType = "RSEM4"; ///< 雷达型号
std::string hostAddress = "0.0.0.0"; ///< 主机地址
unsigned short msopPort = 6699; ///< MSOP 数据端口
unsigned short difopPort = 7788; ///< DIFOP 数据端口
unsigned short imuPort = 0; ///< IMU 端口 (0=禁用)
float minDistance = 0.0f; ///< 最小距离(米) 0=不限
float maxDistance = 0.0f; ///< 最大距离(米) 0=不限
bool densePoints = false; ///< 丢弃 NaN 点
bool useLidarClock = false; ///< 使用雷达内部时钟
bool tsFirstPoint = false; ///< 时间戳取首点时刻
bool waitForDifop = false; ///< 等待 DIFOP 包
float startAngle = 0.0f; ///< 有效角度起始(度)
float endAngle = 360.0f; ///< 有效角度结束(度)
float splitAngle = 0.0f; ///< 帧分割角度(度)
std::string frameId = "rslidar"; ///< 帧标识字符串
unsigned int socketRecvBufBytes = 33554432; ///< socket 接收缓冲,默认 32MB低配机推荐 ≥16MB
};
/// 用户回调耗时统计(来自最近一个 5s 滚动窗口的快照)
struct RsCallbackStats
{
unsigned long long maxUs = 0; ///< 窗口内单次回调最大耗时(μs)
unsigned long long avgUs = 0; ///< 窗口内平均耗时(μs)
unsigned long long count = 0; ///< 窗口内回调次数
};
class RSLIDARDEVICE_EXPORT IRsLidarDevice
{
public:
using PointCloudCallback = std::function<void(const RsCloudData& cloudData, const RsFrameInfo& info)>;
using PacketCallback = std::function<void(const RsPacketInfo&)>;
using ExceptionCallback = std::function<void(const RsExceptionInfo&)>;
virtual ~IRsLidarDevice() = default;
/// 工厂方法
static int CreateObject(IRsLidarDevice** ppDevice);
/// 初始化 SDK 环境WSAStartup 等)
virtual int InitDevice() = 0;
/// 配置并打开设备
virtual int OpenDevice(const RsLidarConfig& config) = 0;
/// 关闭设备
virtual int CloseDevice() = 0;
/// 设备是否已打开
virtual bool IsOpened() const = 0;
/// 开始接收数据
virtual int Start() = 0;
/// 停止接收数据
virtual int Stop() = 0;
/// 是否正在运行
virtual bool IsRunning() const = 0;
/// 注册点云回调(每次回调 = 完整一圈扫描,已完成 NaN→0 + 坐标修正 + 米→毫米 + 拆线)
virtual int SetPointCloudCallback(PointCloudCallback callback) = 0;
/// 注册数据包回调is_frame_begin 标记帧起始)
virtual int SetPacketCallback(PacketCallback callback) = 0;
/// 注册异常回调
virtual int SetExceptionCallback(ExceptionCallback callback) = 0;
/// 获取驱动版本
virtual std::string GetVersion() = 0;
/// 获取包序号缺口/半包异常计数(用于判断接收或组包是否丢数据)
virtual uint64_t GetDroppedFrameCount() const = 0;
/// 获取当前就绪队列深度(待消费的帧数)
virtual size_t GetStuffedQueueDepth() const = 0;
/// 获取指定 SDK ErrCode 的累计触发次数(接受原始 SDK error_code如 0x40/0x48/0x49/0x42
virtual uint64_t GetExceptionCount(int errCode) const = 0;
/// 获取 Start 以来用户回调耗时累计统计
/// 注意:设备内部 5s 诊断日志会输出窗口增量,此接口保留累计快照以兼容旧调用
virtual RsCallbackStats GetCallbackLatencyStats() const = 0;
/// 获取就绪队列历史峰值深度Open 以来)
virtual size_t GetStuffedQueuePeak() const = 0;
};
#endif // IRSLIDARDEVICE_H