-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework pwr control and operation state logic. Also add AT command sup…
…port to control handle
- Loading branch information
1 parent
c7a1ef4
commit 5a4572a
Showing
24 changed files
with
960 additions
and
861 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,115 @@ | ||
use super::state::{self, LinkState, OperationState}; | ||
use atat::{ | ||
asynch::{AtatClient, SimpleClient}, | ||
AtDigester, | ||
}; | ||
|
||
use crate::{ | ||
command::{ | ||
general::{types::FirmwareVersion, GetFirmwareVersion}, | ||
gpio::{types::GpioMode, GetGpioConfiguration, SetGpioConfiguration}, | ||
network_service::{ | ||
responses::{OperatorSelection, SignalQuality}, | ||
GetOperatorSelection, GetSignalQuality, | ||
}, | ||
Urc, | ||
}, | ||
error::Error, | ||
}; | ||
|
||
use super::{ | ||
runner::CMUX_CHANNEL_SIZE, | ||
state::{self, LinkState, OperationState}, | ||
}; | ||
|
||
pub struct Control<'a> { | ||
state_ch: state::Runner<'a>, | ||
at_client: | ||
SimpleClient<'a, embassy_at_cmux::Channel<'a, CMUX_CHANNEL_SIZE>, atat::AtDigester<Urc>>, | ||
} | ||
|
||
impl<'a> Control<'a> { | ||
pub(crate) fn new(state_ch: state::Runner<'a>) -> Self { | ||
Self { state_ch } | ||
pub(crate) fn new( | ||
state_ch: state::Runner<'a>, | ||
at_client: SimpleClient< | ||
'a, | ||
embassy_at_cmux::Channel<'a, CMUX_CHANNEL_SIZE>, | ||
atat::AtDigester<Urc>, | ||
>, | ||
) -> Self { | ||
Self { | ||
state_ch, | ||
at_client, | ||
} | ||
} | ||
|
||
pub fn link_state(&mut self) -> LinkState { | ||
pub fn link_state(&self) -> LinkState { | ||
self.state_ch.link_state(None) | ||
} | ||
|
||
pub fn operation_state(&mut self) -> OperationState { | ||
pub fn operation_state(&self) -> OperationState { | ||
self.state_ch.operation_state(None) | ||
} | ||
|
||
pub fn desired_state(&mut self) -> OperationState { | ||
pub fn desired_state(&self) -> OperationState { | ||
self.state_ch.desired_state(None) | ||
} | ||
|
||
pub fn set_desired_state(&mut self, ps: OperationState) { | ||
pub fn set_desired_state(&self, ps: OperationState) { | ||
self.state_ch.set_desired_state(ps); | ||
} | ||
|
||
pub async fn wait_for_desired_state(&mut self, ps: OperationState) { | ||
pub async fn wait_for_desired_state(&self, ps: OperationState) { | ||
self.state_ch.wait_for_desired_state(ps).await | ||
} | ||
|
||
pub async fn wait_for_operation_state(&mut self, ps: OperationState) { | ||
pub async fn wait_for_operation_state(&self, ps: OperationState) { | ||
self.state_ch.wait_for_operation_state(ps).await | ||
} | ||
|
||
// pub async fn get_signal_quality( | ||
// &mut self, | ||
// ) -> Result<crate::command::network_service::responses::SignalQuality, Error> { | ||
// self.at | ||
// .send(&crate::command::network_service::GetSignalQuality) | ||
// .await | ||
// .map_err(|e| Error::Atat(e)) | ||
// } | ||
|
||
// pub async fn get_operator( | ||
// &mut self, | ||
// ) -> Result<crate::command::network_service::responses::OperatorSelection, Error> { | ||
// self.at | ||
// .send(&crate::command::network_service::GetOperatorSelection) | ||
// .await | ||
// .map_err(|e| Error::Atat(e)) | ||
// } | ||
|
||
// /// Send an AT command to the modem | ||
// /// This is usefull if you have special configuration but might break the drivers functionality if your settings interfere with the drivers settings | ||
// pub async fn send<Cmd: atat::AtatCmd>( | ||
// &mut self, | ||
// cmd: &Cmd, | ||
// ) -> Result<Cmd::Response, atat::Error> { | ||
// self.at.send::<Cmd>(cmd).await | ||
// } | ||
pub async fn get_signal_quality(&mut self) -> Result<SignalQuality, Error> { | ||
if self.operation_state() == OperationState::PowerDown { | ||
return Err(Error::Uninitialized); | ||
} | ||
|
||
Ok(self.at_client.send_retry(&GetSignalQuality).await?) | ||
} | ||
|
||
pub async fn get_operator(&mut self) -> Result<OperatorSelection, Error> { | ||
if self.operation_state() == OperationState::PowerDown { | ||
return Err(Error::Uninitialized); | ||
} | ||
|
||
Ok(self.at_client.send_retry(&GetOperatorSelection).await?) | ||
} | ||
|
||
pub async fn get_version(&mut self) -> Result<FirmwareVersion, Error> { | ||
if self.operation_state() == OperationState::PowerDown { | ||
return Err(Error::Uninitialized); | ||
} | ||
|
||
let res = self.at_client.send_retry(&GetFirmwareVersion).await?; | ||
Ok(res.version) | ||
} | ||
|
||
pub async fn set_gpio_configuration( | ||
&self, | ||
gpio_id: u8, | ||
gpio_mode: GpioMode, | ||
) -> Result<(), Error> { | ||
if self.operation_state() == OperationState::PowerDown { | ||
return Err(Error::Uninitialized); | ||
} | ||
|
||
self.at_client | ||
.send_retry(&SetGpioConfiguration { gpio_id, gpio_mode }) | ||
.await?; | ||
Ok(()) | ||
} | ||
|
||
/// Send an AT command to the modem This is usefull if you have special | ||
/// configuration but might break the drivers functionality if your settings | ||
/// interfere with the drivers settings | ||
pub async fn send<Cmd: atat::AtatCmd>(&mut self, cmd: &Cmd) -> Result<Cmd::Response, Error> { | ||
Ok(self.at_client.send_retry::<Cmd>(cmd).await?) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,12 @@ | ||
pub mod control; | ||
mod network; | ||
mod pwr; | ||
mod resources; | ||
pub mod runner; | ||
pub mod state; | ||
mod urc_handler; | ||
|
||
use embedded_io_async::{BufRead, Error as _, ErrorKind, Read, Write}; | ||
pub use resources::Resources; | ||
pub use runner::Runner; | ||
#[cfg(feature = "internal-network-stack")] | ||
pub use state::Device; | ||
|
||
pub struct ReadWriteAdapter<R, W>(pub R, pub W); | ||
|
||
impl<R, W> embedded_io_async::ErrorType for ReadWriteAdapter<R, W> { | ||
type Error = ErrorKind; | ||
} | ||
|
||
impl<R: Read, W> Read for ReadWriteAdapter<R, W> { | ||
async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> { | ||
self.0.read(buf).await.map_err(|e| e.kind()) | ||
} | ||
} | ||
|
||
impl<R: BufRead, W> BufRead for ReadWriteAdapter<R, W> { | ||
async fn fill_buf(&mut self) -> Result<&[u8], Self::Error> { | ||
self.0.fill_buf().await.map_err(|e| e.kind()) | ||
} | ||
|
||
fn consume(&mut self, amt: usize) { | ||
self.0.consume(amt) | ||
} | ||
} | ||
|
||
impl<R, W: Write> Write for ReadWriteAdapter<R, W> { | ||
async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> { | ||
self.1.write(buf).await.map_err(|e| e.kind()) | ||
} | ||
|
||
async fn flush(&mut self) -> Result<(), Self::Error> { | ||
self.1.flush().await.map_err(|e| e.kind()) | ||
} | ||
} |
Oops, something went wrong.