rb_lidar.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 (300)
  14. #define UDP_BUF_SIZE (1206)
  15. // 结构体对齐设置
  16. #pragma pack(push)
  17. #pragma pack(1)
  18. // 原始点数据结构
  19. typedef struct {
  20. uint16_t dist_0; // 第一个距离
  21. uint8_t rssi_0; // 第一个RSSI值
  22. uint16_t dist_1; // 第二个距离
  23. uint8_t rssi_1; // 第二个RSSI值
  24. } raw_point_t;
  25. // 子包结构
  26. typedef struct {
  27. uint16_t header; // 子包头
  28. uint16_t azimuth; // 方位角
  29. raw_point_t point[CONFIG_BLOCK_COUNT]; // 点数据数组
  30. } sub_packet_t;
  31. // UDP包结构
  32. typedef struct {
  33. sub_packet_t sub_packet[CONFIG_UDP_BLOCKS]; // 子包数组
  34. uint32_t timestamp; // 时间戳
  35. uint16_t factory_byte; // 工厂字节
  36. } udp_packet_t;
  37. // 点数据结构
  38. typedef struct {
  39. uint16_t azimuth; // 方位角
  40. uint16_t dist; // 距离
  41. uint16_t rssi; // RSSI值
  42. uint32_t timestamp; // 时间戳
  43. } point_data_t;
  44. // 帧数据结构
  45. typedef struct {
  46. point_data_t pointcloud[FRAME_POINT_COUNT]; // 深度数据点云
  47. } frame_data_t;
  48. #pragma pack(pop)
  49. // RBLidar 结构体
  50. typedef struct {
  51. char* ip;
  52. int port;
  53. callback_t callback;
  54. sub_packet_t buffer[2][SUBPKT_BUF_COUNT]; // 双缓冲区
  55. int current; // 当前缓冲区索引
  56. int valid_count[2]; // 每个缓冲区中有效数据的数量
  57. pthread_mutex_t mutex;
  58. pthread_cond_t cond;
  59. } RBLidar;
  60. // 创建 RBLidar 实例
  61. RBLidar* rblidar_create(const char* ip, int port, callback_t callback);
  62. // 释放 RBLidar 实例
  63. void rblidar_destroy(RBLidar* lidar);
  64. #ifdef __cplusplus
  65. }
  66. #endif
  67. #endif // RB_LIDAR_H