rb_lidar.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #ifndef RB_LIDAR_H
  2. #define RB_LIDAR_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include <stdint.h> // 包含标准整数类型
  7. #include <pthread.h> // 用于线程支持
  8. typedef void (*callback_t)(const char* data, int length);
  9. // 配置常量
  10. #define CONFIG_BLOCK_COUNT (16)
  11. #define CONFIG_UDP_BLOCKS (12)
  12. #define FRAME_POINT_COUNT (3600)
  13. #define SUBPKT_BUF_COUNT (200)
  14. // 结构体对齐设置
  15. #pragma pack(push)
  16. #pragma pack(1)
  17. // 原始点数据结构
  18. typedef struct {
  19. uint16_t dist_0; // 第一个距离
  20. uint8_t rssi_0; // 第一个RSSI值
  21. uint16_t dist_1; // 第二个距离
  22. uint8_t rssi_1; // 第二个RSSI值
  23. } raw_point_t;
  24. // 子包结构
  25. typedef struct {
  26. uint16_t header; // 子包头
  27. uint16_t azimuth; // 方位角
  28. raw_point_t point[CONFIG_BLOCK_COUNT]; // 点数据数组
  29. } sub_packet_t;
  30. // UDP包结构
  31. typedef struct {
  32. sub_packet_t sub_packet[CONFIG_UDP_BLOCKS]; // 子包数组
  33. uint32_t timestamp; // 时间戳
  34. uint16_t factory_byte; // 工厂字节
  35. } udp_packet_t;
  36. // 点数据结构
  37. typedef struct {
  38. uint16_t azimuth; // 方位角
  39. uint16_t dist; // 距离
  40. uint16_t rssi; // RSSI值
  41. uint32_t timestamp; // 时间戳
  42. } point_data_t;
  43. // 帧数据结构
  44. typedef struct {
  45. point_data_t pointcloud[FRAME_POINT_COUNT]; // 深度数据点云
  46. } frame_data_t;
  47. #pragma pack(pop)
  48. // RBLidar 结构体
  49. typedef struct {
  50. char* ip;
  51. int port;
  52. callback_t callback;
  53. sub_packet_t* buffer[2]; // 双缓冲区
  54. int current; // 当前缓冲区索引
  55. int valid_count[2]; // 每个缓冲区中有效数据的数量
  56. pthread_mutex_t mutex;
  57. pthread_cond_t cond;
  58. } RBLidar;
  59. // 创建 RBLidar 实例
  60. RBLidar* rblidar_create(const char* ip, int port, callback_t callback);
  61. // 释放 RBLidar 实例
  62. void rblidar_destroy(RBLidar* lidar);
  63. #ifdef __cplusplus
  64. }
  65. #endif
  66. #endif // RB_LIDAR_H