use le_stream::{FromLeStream, ToLeStream};
use num_traits::FromPrimitive;
use silizium::Status;
use crate::Error;
use crate::ezsp::network::scan::Type;
use crate::frame::Parameter;
use crate::frame::responds_with::RespondsWith;
use crate::types::VariableLengthU32;
const ID: u16 = 0x001A;
#[derive(Clone, Debug, Eq, PartialEq, ToLeStream)]
pub(crate) struct Command {
scan_type: u8,
channel_mask: u32,
duration: u8,
}
impl Command {
#[must_use]
pub fn new(scan_type: Type, channel_mask: u32, duration: u8) -> Self {
Self {
scan_type: scan_type.into(),
channel_mask,
duration,
}
}
}
impl Parameter for Command {
const ID: u16 = ID;
}
impl RespondsWith for Command {
type Response = Response;
}
#[derive(Clone, Debug, Eq, PartialEq, FromLeStream)]
pub struct Response {
status: VariableLengthU32,
}
impl Parameter for Response {
const ID: u16 = ID;
}
impl TryFrom<Response> for () {
type Error = Error;
fn try_from(response: Response) -> Result<Self, Self::Error> {
let status = response.status.into();
match Status::from_u32(status).ok_or(status) {
Ok(Status::Ok) => Ok(()),
other => Err(other.into()),
}
}
}