Skip to content

Commit

Permalink
Allow control handle to query firmware version of device
Browse files Browse the repository at this point in the history
  • Loading branch information
MathiasKoch committed Jul 18, 2024
1 parent 5a4572a commit dc3ca79
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 62 deletions.
51 changes: 34 additions & 17 deletions src/asynch/control.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use atat::{
asynch::{AtatClient, SimpleClient},
AtDigester,
};
use atat::asynch::{AtatClient, SimpleClient};
use embassy_sync::{blocking_mutex::raw::RawMutex, mutex::Mutex};

use crate::{
command::{
general::{types::FirmwareVersion, GetFirmwareVersion},
gpio::{types::GpioMode, GetGpioConfiguration, SetGpioConfiguration},
gpio::{types::GpioMode, SetGpioConfiguration},
network_service::{
responses::{OperatorSelection, SignalQuality},
GetOperatorSelection, GetSignalQuality,
Expand All @@ -21,13 +19,15 @@ use super::{
state::{self, LinkState, OperationState},
};

pub struct Control<'a> {
pub struct Control<'a, M: RawMutex> {
state_ch: state::Runner<'a>,
at_client:
at_client: Mutex<
M,
SimpleClient<'a, embassy_at_cmux::Channel<'a, CMUX_CHANNEL_SIZE>, atat::AtDigester<Urc>>,
>,
}

impl<'a> Control<'a> {
impl<'a, M: RawMutex> Control<'a, M> {
pub(crate) fn new(
state_ch: state::Runner<'a>,
at_client: SimpleClient<
Expand All @@ -38,7 +38,7 @@ impl<'a> Control<'a> {
) -> Self {
Self {
state_ch,
at_client,
at_client: Mutex::new(at_client),
}
}

Expand Down Expand Up @@ -66,28 +66,43 @@ impl<'a> Control<'a> {
self.state_ch.wait_for_operation_state(ps).await
}

pub async fn get_signal_quality(&mut self) -> Result<SignalQuality, Error> {
pub async fn get_signal_quality(&self) -> Result<SignalQuality, Error> {
if self.operation_state() == OperationState::PowerDown {
return Err(Error::Uninitialized);
}

Ok(self.at_client.send_retry(&GetSignalQuality).await?)
Ok(self
.at_client
.lock()
.await
.send_retry(&GetSignalQuality)
.await?)
}

pub async fn get_operator(&mut self) -> Result<OperatorSelection, Error> {
pub async fn get_operator(&self) -> Result<OperatorSelection, Error> {
if self.operation_state() == OperationState::PowerDown {
return Err(Error::Uninitialized);
}

Ok(self.at_client.send_retry(&GetOperatorSelection).await?)
Ok(self
.at_client
.lock()
.await
.send_retry(&GetOperatorSelection)
.await?)
}

pub async fn get_version(&mut self) -> Result<FirmwareVersion, Error> {
pub async fn get_version(&self) -> Result<FirmwareVersion, Error> {
if self.operation_state() == OperationState::PowerDown {
return Err(Error::Uninitialized);
}

let res = self.at_client.send_retry(&GetFirmwareVersion).await?;
let res = self
.at_client
.lock()
.await
.send_retry(&GetFirmwareVersion)
.await?;
Ok(res.version)
}

Expand All @@ -101,6 +116,8 @@ impl<'a> Control<'a> {
}

self.at_client
.lock()
.await
.send_retry(&SetGpioConfiguration { gpio_id, gpio_mode })
.await?;
Ok(())
Expand All @@ -109,7 +126,7 @@ impl<'a> Control<'a> {
/// 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?)
pub async fn send<Cmd: atat::AtatCmd>(&self, cmd: &Cmd) -> Result<Cmd::Response, Error> {
Ok(self.at_client.lock().await.send_retry::<Cmd>(cmd).await?)
}
}
46 changes: 4 additions & 42 deletions src/asynch/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ use crate::{
},
device_lock::{responses::PinStatus, types::PinStatusCode, GetPinStatus},
general::{responses::FirmwareVersion, GetCCID, GetFirmwareVersion, GetModelId},
gpio::{
types::{GpioInPull, GpioMode, GpioOutValue},
SetGpioConfiguration,
},
ipc::SetMultiplexing,
mobile_control::{
types::{Functionality, TerminationErrorMode},
Expand All @@ -41,6 +37,7 @@ use atat::{
};

use embassy_futures::select::{select3, Either3};
use embassy_sync::blocking_mutex::raw::NoopRawMutex;
use embassy_time::{with_timeout, Duration, Instant, Timer};

pub(crate) const URC_SUBSCRIBERS: usize = 2;
Expand Down Expand Up @@ -98,7 +95,7 @@ where
transport: T,
resources: &'a mut Resources<CMD_BUF_SIZE, INGRESS_BUF_SIZE, URC_CAPACITY>,
config: C,
) -> (Self, Control<'a>) {
) -> (Self, Control<'a, NoopRawMutex>) {
let ch_runner = state::Runner::new(&mut resources.ch);

let ingress = atat::Ingress::new(
Expand Down Expand Up @@ -311,9 +308,9 @@ where

let FirmwareVersion { version } = at_client.send_retry(&GetFirmwareVersion).await?;
info!(
"Found module to be: {=[u8]:a}, {=[u8]:a}",
"Found module to be: {=[u8]:a}, {}",
model_id.model.as_slice(),
version.as_slice()
version
);

at_client
Expand All @@ -322,41 +319,6 @@ where
})
.await?;

// // FIXME: The following three GPIO settings should not be here!
let _ = at_client
.send_retry(&SetGpioConfiguration {
gpio_id: 23,
gpio_mode: GpioMode::NetworkStatus,
})
.await;

// Select SIM
at_client
.send_retry(&SetGpioConfiguration {
gpio_id: 25,
gpio_mode: GpioMode::Output(GpioOutValue::High),
})
.await?;

#[cfg(feature = "lara-r6")]
at_client
.send_retry(&SetGpioConfiguration {
gpio_id: 42,
gpio_mode: GpioMode::Input(GpioInPull::NoPull),
})
.await?;

// self.soft_reset(true).await?;

// self.wait_alive(
// self.ch
// .module()
// .map(|m| m.boot_wait())
// .unwrap_or(Generic.boot_wait())
// * 2,
// )
// .await?;

// Echo off
at_client
.send_retry(&SetEcho { enabled: Echo::Off })
Expand Down
12 changes: 9 additions & 3 deletions src/command/general/types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! Argument and parameter types used by General Commands and Responses

use core::fmt::Write as _;

use atat::atat_derive::AtatEnum;
use serde::{Deserialize, Deserializer, Serialize};
#[derive(Clone, PartialEq, Eq, AtatEnum)]
pub enum Snt {
/// (default value): International Mobile station Equipment Identity (IMEI)
Expand Down Expand Up @@ -75,7 +78,7 @@ impl Serialize for FirmwareVersion {
let mut str = heapless::String::<7>::new();
str.write_fmt(format_args!("{}.{}", self.major, self.minor))
.map_err(serde::ser::Error::custom)?;
serializer.serialize_str(&str)
serializer.serialize_bytes(str.as_bytes())
}
}

Expand All @@ -84,7 +87,10 @@ impl<'de> Deserialize<'de> for FirmwareVersion {
where
D: Deserializer<'de>,
{
let s = heapless::String::<7>::deserialize(deserializer)?;
core::str::FromStr::from_str(&s).map_err(serde::de::Error::custom)
let s = atat::heapless_bytes::Bytes::<7>::deserialize(deserializer)?;
core::str::FromStr::from_str(
&core::str::from_utf8(s.as_slice()).map_err(serde::de::Error::custom)?,
)
.map_err(serde::de::Error::custom)
}
}

0 comments on commit dc3ca79

Please sign in to comment.