Skip to content

Commit

Permalink
rename PowerState to OperationState
Browse files Browse the repository at this point in the history
  • Loading branch information
tarfu committed Dec 4, 2023
1 parent 032393a commit d8f41a2
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 57 deletions.
26 changes: 13 additions & 13 deletions examples/embassy-stm32-example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)");
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/asynch/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand All @@ -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;
}
}
32 changes: 16 additions & 16 deletions src/asynch/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)),
Expand All @@ -105,15 +105,15 @@ impl<
pub async fn has_power(&mut self) -> Result<bool, Error> {
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)
}
}
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -248,7 +248,7 @@ impl<
.await?;
}

self.ch.set_power_state(PowerState::Initialized);
self.ch.set_power_state(OperationState::Initialized);

Ok(())
}
Expand Down Expand Up @@ -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");
}
Expand All @@ -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) => {
Expand Down
48 changes: 24 additions & 24 deletions src/asynch/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -55,26 +55,26 @@ impl State {

struct StateInner {
shared: Mutex<NoopRawMutex, RefCell<Shared>>,
desired_state_pub_sub: PubSubChannel<NoopRawMutex, PowerState, 1, MAX_STATE_LISTENERS, 1>,
desired_state_pub_sub: PubSubChannel<NoopRawMutex, OperationState, 1, MAX_STATE_LISTENERS, 1>,
}

/// 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<NoopRawMutex, RefCell<Shared>>,
desired_state_pub_sub: &'d PubSubChannel<NoopRawMutex, PowerState, 1, MAX_STATE_LISTENERS, 1>,
desired_state_pub_sub: &'d PubSubChannel<NoopRawMutex, OperationState, 1, MAX_STATE_LISTENERS, 1>,
}

#[derive(Clone, Copy)]
pub struct StateRunner<'d> {
shared: &'d Mutex<NoopRawMutex, RefCell<Shared>>,
desired_state_pub_sub: &'d PubSubChannel<NoopRawMutex, PowerState, 1, MAX_STATE_LISTENERS, 1>,
desired_state_pub_sub: &'d PubSubChannel<NoopRawMutex, OperationState, 1, MAX_STATE_LISTENERS, 1>,
}

impl<'d> Runner<'d> {
Expand All @@ -93,15 +93,15 @@ 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;
s.waker.wake();
});
}

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;
Expand Down Expand Up @@ -130,15 +130,15 @@ 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;
s.waker.wake();
});
}

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());
Expand All @@ -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;
Expand All @@ -178,7 +178,7 @@ impl<'d> StateRunner<'d> {
.publish_immediate(ps);
}

pub async fn wait_for_desired_state(&mut self, ps: PowerState) -> Result<PowerState, Error> {
pub async fn wait_for_desired_state(&mut self, ps: OperationState) -> Result<OperationState, Error> {
if self.desired_state() == ps {
info!("Desired state already set to {:?}, returning", ps);
return Ok(ps);
Expand All @@ -195,7 +195,7 @@ impl<'d> StateRunner<'d> {
}
}

pub async fn wait_for_desired_state_change(&mut self) -> Result<PowerState, Error> {
pub async fn wait_for_desired_state_change(&mut self) -> Result<OperationState, Error> {
let mut sub = self
.desired_state_pub_sub
.subscriber()
Expand All @@ -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::<NoopRawMutex, PowerState, 1, MAX_STATE_LISTENERS, 1>::new(),
PubSubChannel::<NoopRawMutex, OperationState, 1, MAX_STATE_LISTENERS, 1>::new(),
});

(
Expand All @@ -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<NoopRawMutex, RefCell<Shared>>,
pub(crate) desired_state_pub_sub:
&'d PubSubChannel<NoopRawMutex, PowerState, 1, MAX_STATE_LISTENERS, 1>,
&'d PubSubChannel<NoopRawMutex, OperationState, 1, MAX_STATE_LISTENERS, 1>,
pub(crate) at: AtHandle<'d, AT>,
pub(crate) urc_subscription: UrcSubscription<'d, Urc, URC_CAPACITY, 2>,
}
Expand All @@ -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());
Expand All @@ -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;
Expand All @@ -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<PowerState, Error> {
pub async fn wait_for_desired_state(&mut self, ps: OperationState) -> Result<OperationState, Error> {
if self.desired_state() == ps {
return Ok(ps);
}
Expand Down

0 comments on commit d8f41a2

Please sign in to comment.