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