use std::collections::BTreeMap;
use async_trait::async_trait;
use rmpv::Value;
use super::{Bus, DriverResult, SampleStream};
#[derive(Debug, Clone, PartialEq)]
pub struct LidarCandidate {
pub driver_id: String,
pub device_id: String,
pub label: String,
pub bus: Bus,
pub vid_pid: Option<(u16, u16)>,
pub metadata: BTreeMap<String, Value>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct LidarCapabilities {
pub min_range_m: f32,
pub max_range_m: f32,
pub horizontal_fov_deg: f32,
pub vertical_fov_deg: f32,
pub points_per_frame: u32,
pub fps: f32,
pub has_intensity: bool,
pub has_dual_return: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub struct LidarPoint {
pub x: f32,
pub y: f32,
pub z: f32,
pub intensity: Option<f32>,
pub return_index: u8,
}
#[derive(Debug, Clone, PartialEq)]
pub struct LidarFrame {
pub timestamp_ns: i64,
pub sequence: u64,
pub points: Vec<LidarPoint>,
pub metadata: BTreeMap<String, Value>,
}
#[async_trait]
pub trait LidarDriver: Send + Sync {
type Session: Send + Sync;
async fn discover(&self) -> DriverResult<Vec<LidarCandidate>>;
async fn open(
&self,
candidate: &LidarCandidate,
config: &BTreeMap<String, Value>,
) -> DriverResult<Self::Session>;
async fn close(&self, session: Self::Session) -> DriverResult<()>;
fn capabilities(&self, session: &Self::Session) -> LidarCapabilities;
async fn frame_iterator(
&self,
session: &Self::Session,
) -> DriverResult<SampleStream<LidarFrame>>;
async fn set_param(
&self,
session: &Self::Session,
param: &str,
value: Value,
) -> DriverResult<()>;
}