forked from M-Labs/humpback-dds
scpi: redesign sw
This commit is contained in:
parent
37b7cc71b7
commit
56cb6eb3fd
@ -15,8 +15,8 @@ stm32h7xx-hal = {version = "0.6.0", features = [ "stm32h743v", "rt", "unproven"
|
||||
stm32h7-ethernet = { version = "0.2.0", features = [ "phy_lan8742a", "stm32h743v" ] }
|
||||
smoltcp = { version = "0.6.0", default-features = false, features = [ "ethernet", "proto-ipv4", "proto-ipv6", "socket-raw" ] }
|
||||
nb = "1.0.0"
|
||||
scpi = { path = "../scpi-fork/scpi", version = "0.3.4" }
|
||||
# scpi = { git = "https://github.com/occheung/scpi-rs", branch = "issue-4" }
|
||||
# scpi = { path = "../scpi-fork/scpi", version = "0.3.4" }
|
||||
scpi = { git = "https://github.com/occheung/scpi-rs", branch = "issue-4" }
|
||||
|
||||
lexical-core = { version="0.7.1", features=["radix"], default-features=false }
|
||||
libm = "0.2.0"
|
||||
|
46
src/lib.rs
46
src/lib.rs
@ -53,6 +53,7 @@ pub enum Error<E> {
|
||||
DDSError,
|
||||
ConfigRegisterError,
|
||||
DDSCLKError,
|
||||
ParameterError,
|
||||
}
|
||||
|
||||
/*
|
||||
@ -142,7 +143,8 @@ where
|
||||
|
||||
pub trait UrukulTraits {
|
||||
type Error;
|
||||
fn switch(&mut self, channel: u32) -> Result<(), Self::Error>;
|
||||
fn get_channel_switch_status(&mut self, channel: u32) -> Result<bool, Self::Error>;
|
||||
fn set_channel_switch(&mut self, channel: u32, status: bool) -> Result<(), Self::Error>;
|
||||
}
|
||||
|
||||
impl<SPI, E> UrukulTraits for Urukul<SPI>
|
||||
@ -151,20 +153,52 @@ where
|
||||
{
|
||||
type Error = Error<E>;
|
||||
|
||||
fn switch(&mut self, channel: u32) -> Result<(), Self::Error>{
|
||||
if channel < 16 {
|
||||
let switch_set = channel | u32::from(self.config_register.get_status(StatusMask::RF_SW)?);
|
||||
fn get_channel_switch_status(&mut self, channel: u32) -> Result<bool, Self::Error> {
|
||||
if channel < 4 {
|
||||
match self.config_register.get_status(StatusMask::RF_SW) {
|
||||
Ok(val) => Ok((val & (1 << channel)) != 0),
|
||||
Err(_e) => Err(_e),
|
||||
}
|
||||
} else {
|
||||
Err(Error::ParameterError)
|
||||
}
|
||||
}
|
||||
|
||||
fn set_channel_switch(&mut self, channel: u32, status: bool) -> Result<(), Self::Error> {
|
||||
if channel < 4 {
|
||||
let prev = u32::from(self.config_register.get_status(StatusMask::RF_SW)?);
|
||||
let next = {
|
||||
if status {
|
||||
prev | (1 << channel)
|
||||
} else {
|
||||
prev & (!(1 << channel))
|
||||
}
|
||||
};
|
||||
match self.config_register.set_configurations(&mut [
|
||||
(CFGMask::RF_SW, switch_set),
|
||||
(CFGMask::RF_SW, next),
|
||||
]) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(_e) => Err(_e),
|
||||
}
|
||||
} else {
|
||||
Err(Error::ConfigRegisterError)
|
||||
Err(Error::ParameterError)
|
||||
}
|
||||
}
|
||||
|
||||
// fn switch_on(&mut self, channel: u32) -> Result<(), Self::Error>{
|
||||
// if channel < 16 {
|
||||
// let switch_set = channel | u32::from(self.config_register.get_status(StatusMask::RF_SW)?);
|
||||
|
||||
// match self.config_register.set_configurations(&mut [
|
||||
// (CFGMask::RF_SW, switch_set),
|
||||
// ]) {
|
||||
// Ok(_) => Ok(()),
|
||||
// Err(_e) => Err(_e),
|
||||
// }
|
||||
// } else {
|
||||
// Err(Error::ParameterError)
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
// /*
|
||||
|
@ -21,6 +21,7 @@ pub enum NetworkError {
|
||||
pub struct NetStorage {
|
||||
pub ip_addrs: [net::wire::IpCidr; 1],
|
||||
pub neighbor_cache: [Option<(net::wire::IpAddress, net::iface::Neighbor)>; 8],
|
||||
pub routes_cache: [Option<(net::wire::IpCidr, net::iface::Route)>; 8],
|
||||
}
|
||||
|
||||
pub type NetworkInterface =
|
||||
|
45
src/scpi.rs
45
src/scpi.rs
@ -31,7 +31,7 @@ use scpi::{
|
||||
use embedded_hal::blocking::spi::Transfer;
|
||||
use cortex_m_semihosting::hprintln;
|
||||
|
||||
use crate::{Urukul, UrukulTraits};
|
||||
use crate::{Urukul, UrukulTraits, Error as UrukulError};
|
||||
|
||||
// pub struct MyDevice;
|
||||
|
||||
@ -49,39 +49,38 @@ impl<T: Device> Command<T> for HelloWorldCommand {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SwitchOnCommand {}
|
||||
impl<T: Device + UrukulTraits> Command<T> for SwitchOnCommand {
|
||||
pub struct Channel1SwitchCommand {}
|
||||
impl<T: Device + UrukulTraits> Command<T> for Channel1SwitchCommand {
|
||||
nquery!();
|
||||
|
||||
fn event(&self, context: &mut Context<T>, args: &mut Tokenizer) -> Result<()> {
|
||||
let mut channel :u32 = 0;
|
||||
let mut channel_index = 0;
|
||||
while true {
|
||||
match args.next_data(channel_index != 0) {
|
||||
Ok(Some(token)) => {
|
||||
match u32::try_from(token) {
|
||||
Ok(shift) => {
|
||||
if shift >= 4 {
|
||||
return Err(ErrorCode::IllegalParameterValue.into());
|
||||
}
|
||||
channel |= (1 << shift);
|
||||
},
|
||||
match context.device.get_channel_switch_status(1) {
|
||||
Ok(status) => {
|
||||
let next_state: bool = match args.next_data(true) {
|
||||
Ok(Some(token)) => token.try_into()?,
|
||||
Ok(None) => !status,
|
||||
Err(_) => return Err(ErrorCode::IllegalParameterValue.into()),
|
||||
};
|
||||
match context.device.set_channel_switch(1, next_state) {
|
||||
Ok(()) => Ok(()),
|
||||
Err(T) => panic!("Switched an illegal channel!"),
|
||||
Err(_) => Err(Error::new(ErrorCode::HardwareError)),
|
||||
}
|
||||
},
|
||||
Ok(None) => break,
|
||||
Ok(_) => return Err(ErrorCode::MissingParameter.into()),
|
||||
Err(_e) => return Err(_e),
|
||||
};
|
||||
channel_index += 1;
|
||||
}
|
||||
match context.device.switch(channel) {
|
||||
Ok(()) => Ok(()),
|
||||
Err(_) => Err(Error::new(ErrorCode::HardwareError)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// pub struct SwitchCnannelCommand {}
|
||||
// impl<T: Device + UrukulTraits> Command<T> for SwitchChannelCommand {
|
||||
// nquery!();
|
||||
|
||||
// fn event(&self, context: &mut Context<T>, args: &mut Tokenizer) -> Result<()> {
|
||||
|
||||
// }
|
||||
// }
|
||||
|
||||
/*
|
||||
* Implement "Device" trait from SCPI
|
||||
* TODO: Implement mandatory commands
|
||||
|
Loading…
Reference in New Issue
Block a user