diff --git a/examples/embassy-stm32-example/src/main.rs b/examples/embassy-stm32-example/src/main.rs index 1f00620..f089e55 100644 --- a/examples/embassy-stm32-example/src/main.rs +++ b/examples/embassy-stm32-example/src/main.rs @@ -29,7 +29,7 @@ use atat::asynch::AtatClient; use ublox_cellular::asynch::runner::Runner; use ublox_cellular::asynch::State; use ublox_cellular::command::{AT, Urc}; -use ublox_cellular::asynch::state::{LinkState, PowerState}; +use ublox_cellular::asynch::state::{LinkState, OperationState}; bind_interrupts!(struct Irqs { @@ -160,34 +160,34 @@ async fn main_task(spawner: Spawner) { // } // runner.init().await.unwrap(); match control.power_state() { - PowerState::PowerDown => { + OperationState::PowerDown => { info!("PowerState::PowerDown"); - control.set_desired_state(PowerState::PowerUp).await; + control.set_desired_state(OperationState::PowerUp).await; info!("set_desired_state(PowerState::PowerUp)"); } - PowerState::PowerUp => { + OperationState::PowerUp => { info!("PowerState::PowerUp"); - control.set_desired_state(PowerState::Alive).await; + control.set_desired_state(OperationState::Alive).await; info!("set_desired_state(PowerState::Alive)"); } - PowerState::Alive => { + OperationState::Alive => { info!("PowerState::Alive"); - control.set_desired_state(PowerState::Initialized).await; + control.set_desired_state(OperationState::Initialized).await; info!("set_desired_state(PowerState::Initialized)"); } - PowerState::Initialized => { + OperationState::Initialized => { info!("PowerState::Initialized"); - control.set_desired_state(PowerState::PowerDown).await; + control.set_desired_state(OperationState::PowerDown).await; info!("set_desired_state(PowerState::PowerDown)"); } - PowerState::Connected => { + OperationState::Connected => { info!("PowerState::Connected"); - control.set_desired_state(PowerState::PowerDown).await; + control.set_desired_state(OperationState::PowerDown).await; info!("set_desired_state(PowerState::PowerDown)"); } - PowerState::DataEstablished => { + OperationState::DataEstablished => { info!("PowerState::DataEstablished"); - control.set_desired_state(PowerState::PowerDown).await; + control.set_desired_state(OperationState::PowerDown).await; info!("set_desired_state(PowerState::PowerDown)"); } } diff --git a/src/asynch/control.rs b/src/asynch/control.rs index 39ad3fe..6c79d88 100644 --- a/src/asynch/control.rs +++ b/src/asynch/control.rs @@ -6,7 +6,7 @@ use embassy_time::{with_timeout, Duration}; use crate::error::Error; -use super::state::{LinkState, PowerState}; +use super::state::{LinkState, OperationState}; use super::{state, AtHandle}; pub struct Control<'a, AT: AtatClient> { @@ -32,15 +32,15 @@ impl<'a, AT: AtatClient> Control<'a, AT> { self.state_ch.link_state() } - pub fn power_state(&mut self) -> PowerState { + pub fn power_state(&mut self) -> OperationState { self.state_ch.power_state() } - pub fn desired_state(&mut self) -> PowerState { + pub fn desired_state(&mut self) -> OperationState { self.state_ch.desired_state() } - pub async fn set_desired_state(&mut self, ps: PowerState) { + pub async fn set_desired_state(&mut self, ps: OperationState) { self.state_ch.set_desired_state(ps).await; } } diff --git a/src/asynch/runner.rs b/src/asynch/runner.rs index 1ab7ac3..81a0ef1 100644 --- a/src/asynch/runner.rs +++ b/src/asynch/runner.rs @@ -3,8 +3,8 @@ use core::str::FromStr; use crate::{command::Urc, config::CellularConfig}; use super::state::{self, LinkState}; -use crate::asynch::state::PowerState; -use crate::asynch::state::PowerState::PowerDown; +use crate::asynch::state::OperationState; +use crate::asynch::state::OperationState::PowerDown; use crate::command::control::types::{Circuit108Behaviour, Circuit109Behaviour, FlowControl}; use crate::command::control::{SetCircuit108Behaviour, SetCircuit109Behaviour, SetFlowControl}; use crate::command::device_lock::responses::PinStatus; @@ -94,7 +94,7 @@ impl< let alive = match self.at.send(AT).await { Ok(_) => { - self.ch.set_power_state(PowerState::Alive); + self.ch.set_power_state(OperationState::Alive); Ok(true) } Err(err) => return Err(Error::Atat(err)), @@ -105,15 +105,15 @@ impl< pub async fn has_power(&mut self) -> Result { if let Some(pin) = self.config.vint_pin() { if pin.is_high().map_err(|_| Error::IoPin)? { - self.ch.set_power_state(PowerState::PowerUp); + self.ch.set_power_state(OperationState::PowerUp); Ok(true) } else { - self.ch.set_power_state(PowerState::PowerDown); + self.ch.set_power_state(OperationState::PowerDown); Ok(false) } } else { info!("No VInt pin configured"); - self.ch.set_power_state(PowerState::PowerUp); + self.ch.set_power_state(OperationState::PowerUp); Ok(true) } } @@ -124,7 +124,7 @@ impl< pin.set_low().map_err(|_| Error::IoPin)?; Timer::after(crate::module_timing::pwr_on_time()).await; pin.set_high().map_err(|_| Error::IoPin)?; - self.ch.set_power_state(PowerState::PowerUp); + self.ch.set_power_state(OperationState::PowerUp); debug!("Powered up"); Ok(()) } else { @@ -142,7 +142,7 @@ impl< pin.set_low().map_err(|_| Error::IoPin)?; Timer::after(crate::module_timing::pwr_off_time()).await; pin.set_high().map_err(|_| Error::IoPin)?; - self.ch.set_power_state(PowerState::PowerDown); + self.ch.set_power_state(OperationState::PowerDown); debug!("Powered down"); Ok(()) } else { @@ -248,7 +248,7 @@ impl< .await?; } - self.ch.set_power_state(PowerState::Initialized); + self.ch.set_power_state(OperationState::Initialized); Ok(()) } @@ -295,7 +295,7 @@ impl< Timer::after(reset_time()).await; pin.set_high().ok(); Timer::after(boot_time()).await; - self.ch.set_power_state(PowerState::PowerUp); + self.ch.set_power_state(OperationState::PowerUp); } else { warn!("No reset pin configured"); } @@ -317,22 +317,22 @@ impl< Either::First(desired_state) => { info!("Desired state: {:?}", desired_state); match desired_state { - Ok(PowerState::PowerDown) => { + Ok(OperationState::PowerDown) => { self.power_down().await.ok(); } - Ok(PowerState::PowerUp) => { + Ok(OperationState::PowerUp) => { self.power_up().await.ok(); } - Ok(PowerState::Initialized) => { + Ok(OperationState::Initialized) => { self.init_at().await.ok(); } - Ok(PowerState::Alive) => { + Ok(OperationState::Alive) => { self.is_alive().await.ok(); } - Ok(PowerState::Connected) => { + Ok(OperationState::Connected) => { todo!() } - Ok(PowerState::DataEstablished) => { + Ok(OperationState::DataEstablished) => { todo!() } Err(err) => { diff --git a/src/asynch/state.rs b/src/asynch/state.rs index 5dbab9f..e75ea2b 100644 --- a/src/asynch/state.rs +++ b/src/asynch/state.rs @@ -27,7 +27,7 @@ pub enum LinkState { /// If the celular modem is up and responding to AT. #[derive(PartialEq, Eq, Clone, Copy)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub enum PowerState { +pub enum OperationState { PowerDown, PowerUp, Alive, @@ -55,26 +55,26 @@ impl State { struct StateInner { shared: Mutex>, - desired_state_pub_sub: PubSubChannel, + desired_state_pub_sub: PubSubChannel, } /// State of the LinkState pub struct Shared { link_state: LinkState, - power_state: PowerState, - desired_state: PowerState, + power_state: OperationState, + desired_state: OperationState, waker: WakerRegistration, } pub struct Runner<'d> { shared: &'d Mutex>, - desired_state_pub_sub: &'d PubSubChannel, + desired_state_pub_sub: &'d PubSubChannel, } #[derive(Clone, Copy)] pub struct StateRunner<'d> { shared: &'d Mutex>, - desired_state_pub_sub: &'d PubSubChannel, + desired_state_pub_sub: &'d PubSubChannel, } impl<'d> Runner<'d> { @@ -93,7 +93,7 @@ impl<'d> Runner<'d> { }); } - pub fn set_power_state(&mut self, state: PowerState) { + pub fn set_power_state(&mut self, state: OperationState) { self.shared.lock(|s| { let s = &mut *s.borrow_mut(); s.power_state = state; @@ -101,7 +101,7 @@ impl<'d> Runner<'d> { }); } - pub fn set_desired_state(&mut self, ps: PowerState) { + pub fn set_desired_state(&mut self, ps: OperationState) { self.shared.lock(|s| { let s = &mut *s.borrow_mut(); s.desired_state = ps; @@ -130,7 +130,7 @@ impl<'d> StateRunner<'d> { }) } - pub fn set_power_state(&self, state: PowerState) { + pub fn set_power_state(&self, state: OperationState) { self.shared.lock(|s| { let s = &mut *s.borrow_mut(); s.power_state = state; @@ -138,7 +138,7 @@ impl<'d> StateRunner<'d> { }); } - pub fn power_state_poll_fn(&mut self, cx: &mut Context) -> PowerState { + pub fn power_state_poll_fn(&mut self, cx: &mut Context) -> OperationState { self.shared.lock(|s| { let s = &mut *s.borrow_mut(); s.waker.register(cx.waker()); @@ -153,21 +153,21 @@ impl<'d> StateRunner<'d> { }) } - pub fn power_state(&mut self) -> PowerState { + pub fn power_state(&mut self) -> OperationState { self.shared.lock(|s| { let s = &mut *s.borrow_mut(); s.power_state }) } - pub fn desired_state(&mut self) -> PowerState { + pub fn desired_state(&mut self) -> OperationState { self.shared.lock(|s| { let s = &mut *s.borrow_mut(); s.desired_state }) } - pub async fn set_desired_state(&mut self, ps: PowerState) { + pub async fn set_desired_state(&mut self, ps: OperationState) { self.shared.lock(|s| { let s = &mut *s.borrow_mut(); s.desired_state = ps; @@ -178,7 +178,7 @@ impl<'d> StateRunner<'d> { .publish_immediate(ps); } - pub async fn wait_for_desired_state(&mut self, ps: PowerState) -> Result { + pub async fn wait_for_desired_state(&mut self, ps: OperationState) -> Result { if self.desired_state() == ps { info!("Desired state already set to {:?}, returning", ps); return Ok(ps); @@ -195,7 +195,7 @@ impl<'d> StateRunner<'d> { } } - pub async fn wait_for_desired_state_change(&mut self) -> Result { + pub async fn wait_for_desired_state_change(&mut self) -> Result { let mut sub = self .desired_state_pub_sub .subscriber() @@ -221,12 +221,12 @@ pub fn new<'d, AT: AtatClient, const URC_CAPACITY: usize>( let state = unsafe { &mut *state_uninit }.write(StateInner { shared: Mutex::new(RefCell::new(Shared { link_state: LinkState::Down, - power_state: PowerState::PowerDown, - desired_state: PowerState::PowerDown, + power_state: OperationState::PowerDown, + desired_state: OperationState::PowerDown, waker: WakerRegistration::new(), })), desired_state_pub_sub: - PubSubChannel::::new(), + PubSubChannel::::new(), }); ( @@ -246,7 +246,7 @@ pub fn new<'d, AT: AtatClient, const URC_CAPACITY: usize>( pub struct Device<'d, AT: AtatClient, const URC_CAPACITY: usize> { pub(crate) shared: &'d Mutex>, pub(crate) desired_state_pub_sub: - &'d PubSubChannel, + &'d PubSubChannel, pub(crate) at: AtHandle<'d, AT>, pub(crate) urc_subscription: UrcSubscription<'d, Urc, URC_CAPACITY, 2>, } @@ -262,7 +262,7 @@ impl<'d, AT: AtatClient, const URC_CAPACITY: usize> }) } - pub fn power_state_poll_fn(&mut self, cx: &mut Context) -> PowerState { + pub fn power_state_poll_fn(&mut self, cx: &mut Context) -> OperationState { self.shared.lock(|s| { let s = &mut *s.borrow_mut(); s.waker.register(cx.waker()); @@ -277,21 +277,21 @@ impl<'d, AT: AtatClient, const URC_CAPACITY: usize> }) } - pub fn power_state(&mut self) -> PowerState { + pub fn power_state(&mut self) -> OperationState { self.shared.lock(|s| { let s = &mut *s.borrow_mut(); s.power_state }) } - pub fn desired_state(&mut self) -> PowerState { + pub fn desired_state(&mut self) -> OperationState { self.shared.lock(|s| { let s = &mut *s.borrow_mut(); s.desired_state }) } - pub fn set_desired_state(&mut self, ps: PowerState) { + pub fn set_desired_state(&mut self, ps: OperationState) { self.shared.lock(|s| { let s = &mut *s.borrow_mut(); s.desired_state = ps; @@ -302,7 +302,7 @@ impl<'d, AT: AtatClient, const URC_CAPACITY: usize> .publish_immediate(ps); } - pub async fn wait_for_desired_state(&mut self, ps: PowerState) -> Result { + pub async fn wait_for_desired_state(&mut self, ps: OperationState) -> Result { if self.desired_state() == ps { return Ok(ps); }