forked from M-Labs/humpback-dds
scpi: add attenuator command
This commit is contained in:
parent
43ccb86697
commit
f94528ae2a
78
src/scpi.rs
78
src/scpi.rs
@ -7,26 +7,9 @@ use scpi::NumericValues;
|
|||||||
|
|
||||||
use core::convert::{TryFrom, TryInto};
|
use core::convert::{TryFrom, TryInto};
|
||||||
use core::str;
|
use core::str;
|
||||||
use core::str::Utf8Error;
|
|
||||||
use scpi::ieee488::commands::*;
|
|
||||||
use scpi::scpi::commands::*;
|
|
||||||
use scpi::{
|
use scpi::{
|
||||||
ieee488_cls,
|
|
||||||
ieee488_ese,
|
|
||||||
ieee488_esr,
|
|
||||||
ieee488_idn,
|
|
||||||
ieee488_opc,
|
|
||||||
ieee488_rst,
|
|
||||||
ieee488_sre,
|
|
||||||
ieee488_stb,
|
|
||||||
ieee488_tst,
|
|
||||||
ieee488_wai,
|
|
||||||
nquery,
|
nquery,
|
||||||
//Helpers
|
|
||||||
qonly,
|
qonly,
|
||||||
scpi_crate_version,
|
|
||||||
scpi_status,
|
|
||||||
scpi_system,
|
|
||||||
};
|
};
|
||||||
use scpi::suffix::{Amplitude, Db};
|
use scpi::suffix::{Amplitude, Db};
|
||||||
use uom::si::frequency::{gigahertz, hertz, kilohertz, megahertz, Frequency};
|
use uom::si::frequency::{gigahertz, hertz, kilohertz, megahertz, Frequency};
|
||||||
@ -147,6 +130,10 @@ pub struct Channel2SwitchCommand {}
|
|||||||
pub struct Channel3SwitchCommand {}
|
pub struct Channel3SwitchCommand {}
|
||||||
pub struct ClockSourceCommand {}
|
pub struct ClockSourceCommand {}
|
||||||
pub struct ClockDivisionCommand {}
|
pub struct ClockDivisionCommand {}
|
||||||
|
pub struct Channel0AttenuationCommand {}
|
||||||
|
pub struct Channel1AttenuationCommand {}
|
||||||
|
pub struct Channel2AttenuationCommand {}
|
||||||
|
pub struct Channel3AttenuationCommand {}
|
||||||
|
|
||||||
impl<T: Device + UrukulTraits> Command<T> for Channel0SwitchCommand {
|
impl<T: Device + UrukulTraits> Command<T> for Channel0SwitchCommand {
|
||||||
nquery!();
|
nquery!();
|
||||||
@ -270,14 +257,65 @@ impl<T:Device + UrukulTraits> Command<T> for ClockDivisionCommand {
|
|||||||
.map_or(Err(Error::new(ErrorCode::IllegalParameterValue)),
|
.map_or(Err(Error::new(ErrorCode::IllegalParameterValue)),
|
||||||
|token| token.try_into())?;
|
|token| token.try_into())?;
|
||||||
trace!("Received master clock division factor: {}", div);
|
trace!("Received master clock division factor: {}", div);
|
||||||
match div {
|
if div == 1.0 || div == 2.0 || div == 4.0 {
|
||||||
1.0 | 2.0 | 4.0 => {
|
|
||||||
debug!("Set master clock division as {}", div);
|
debug!("Set master clock division as {}", div);
|
||||||
context.device.set_clock_division(div as u8)
|
context.device.set_clock_division(div as u8)
|
||||||
.map_err(|_| Error::new(ErrorCode::HardwareError))
|
.map_err(|_| Error::new(ErrorCode::HardwareError))
|
||||||
|
} else {
|
||||||
|
Err(Error::new(ErrorCode::IllegalParameterValue))
|
||||||
}
|
}
|
||||||
_ => Err(Error::new(ErrorCode::IllegalParameterValue)),
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T:Device + UrukulTraits> Command<T> for Channel0AttenuationCommand {
|
||||||
|
nquery!();
|
||||||
|
|
||||||
|
fn event(&self, context: &mut Context<T>, args: &mut Tokenizer) -> Result<()> {
|
||||||
|
let attenuation: f32 = args.next_data(false)?
|
||||||
|
.map_or(Err(Error::new(ErrorCode::IllegalParameterValue)),
|
||||||
|
|token| token.try_into())?;
|
||||||
|
trace!("Received channel 0 attenuation input: {}", attenuation);
|
||||||
|
context.device.set_channel_attenuation(0, attenuation)
|
||||||
|
.map_err(|_| Error::new(ErrorCode::HardwareError))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T:Device + UrukulTraits> Command<T> for Channel1AttenuationCommand {
|
||||||
|
nquery!();
|
||||||
|
|
||||||
|
fn event(&self, context: &mut Context<T>, args: &mut Tokenizer) -> Result<()> {
|
||||||
|
let attenuation: f32 = args.next_data(false)?
|
||||||
|
.map_or(Err(Error::new(ErrorCode::IllegalParameterValue)),
|
||||||
|
|token| token.try_into())?;
|
||||||
|
trace!("Received channel 1 attenuation input: {}", attenuation);
|
||||||
|
context.device.set_channel_attenuation(1, attenuation)
|
||||||
|
.map_err(|_| Error::new(ErrorCode::HardwareError))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T:Device + UrukulTraits> Command<T> for Channel2AttenuationCommand {
|
||||||
|
nquery!();
|
||||||
|
|
||||||
|
fn event(&self, context: &mut Context<T>, args: &mut Tokenizer) -> Result<()> {
|
||||||
|
let attenuation: f32 = args.next_data(false)?
|
||||||
|
.map_or(Err(Error::new(ErrorCode::IllegalParameterValue)),
|
||||||
|
|token| token.try_into())?;
|
||||||
|
trace!("Received channel 2 attenuation input: {}", attenuation);
|
||||||
|
context.device.set_channel_attenuation(2, attenuation)
|
||||||
|
.map_err(|_| Error::new(ErrorCode::HardwareError))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T:Device + UrukulTraits> Command<T> for Channel3AttenuationCommand {
|
||||||
|
nquery!();
|
||||||
|
|
||||||
|
fn event(&self, context: &mut Context<T>, args: &mut Tokenizer) -> Result<()> {
|
||||||
|
let attenuation: f32 = args.next_data(false)?
|
||||||
|
.map_or(Err(Error::new(ErrorCode::IllegalParameterValue)),
|
||||||
|
|token| token.try_into())?;
|
||||||
|
trace!("Received channel 3 attenuation input: {}", attenuation);
|
||||||
|
context.device.set_channel_attenuation(3, attenuation)
|
||||||
|
.map_err(|_| Error::new(ErrorCode::HardwareError))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user