mod packet_retune;
use crate::bladerf1::hardware::lms6002d::{Band, Tune};
use crate::channel::Channel;
use crate::error::Result;
pub use packet_retune::{NiosPktRetuneRequest, NiosPktRetuneResponse};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct RetuneResult {
duration: u64,
}
impl RetuneResult {
pub fn new(duration: u64) -> Self {
Self { duration }
}
pub fn duration(&self) -> u64 {
self.duration
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RetuneTimestamp {
Now,
ClearQueue,
Scheduled(u64),
}
impl From<RetuneTimestamp> for u64 {
fn from(ts: RetuneTimestamp) -> u64 {
match ts {
RetuneTimestamp::Now => 0,
RetuneTimestamp::ClearQueue => u64::MAX,
RetuneTimestamp::Scheduled(ts) => ts,
}
}
}
impl From<u64> for RetuneTimestamp {
fn from(ts: u64) -> RetuneTimestamp {
match ts {
0 => RetuneTimestamp::Now,
u64::MAX => RetuneTimestamp::ClearQueue,
_ => RetuneTimestamp::Scheduled(ts),
}
}
}
#[allow(clippy::too_many_arguments)]
pub fn nios_encode_retune(
buf: &mut [u8],
channel: Channel,
timestamp: RetuneTimestamp,
nint: u16,
nfrac: u32,
freqsel: u8,
vcocap: u8,
band: Band,
tune: Tune,
xb_gpio: u8,
) -> Result<()> {
NiosPktRetuneRequest::new(buf)?.prepare(
channel,
timestamp.into(),
nint,
nfrac,
freqsel,
vcocap,
band,
tune,
xb_gpio,
)
}
pub fn nios_decode_retune(response: &[u8]) -> Result<NiosPktRetuneResponse<'_>> {
NiosPktRetuneResponse::new(response)
}