Skip to content

Commit

Permalink
add operator and signalstrength to control, make operator format cont…
Browse files Browse the repository at this point in the history
…rolable
  • Loading branch information
tarfu committed Jan 4, 2024
1 parent 07cd52a commit 8503ea0
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 7 deletions.
31 changes: 28 additions & 3 deletions examples/embassy-stm32-example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,41 @@ async fn main_task(spawner: Spawner) {
.await;
// defmt::info!("{:?}", runner.init().await);
// control.set_desired_state(PowerState::Connected).await;
control
.send(&crate::command::network_service::SetOperatorSelection {
mode: crate::command::network_service::types::OperatorSelectionMode::Automatic,
format: Some(0),
})
.await;


defmt::unwrap!(spawner.spawn(cellular_task(runner)));
Timer::after(Duration::from_millis(1000)).await;
loop {
control.set_desired_state(OperationState::Initialized).await;
control.set_desired_state(OperationState::Connected).await;
info!("set_desired_state(PowerState::Alive)");
while control.power_state() != OperationState::Initialized {
while control.power_state() != OperationState::Connected {
Timer::after(Duration::from_millis(1000)).await;
}
Timer::after(Duration::from_millis(1000)).await;
Timer::after(Duration::from_millis(10000)).await;
loop {
Timer::after(Duration::from_millis(1000)).await;
let operator = control.get_operator().await;
info!("{}", operator);
let signal_quality = control.get_signal_quality().await;
info!("{}", signal_quality);
if let Ok(sq) = signal_quality {
if let Ok(op) = operator {
if op.oper == None {
continue;
}
}
if sq.rxlev > 0 && sq.rsrp != 255 {
break;
}
}
}
Timer::after(Duration::from_millis(10000)).await;
control.set_desired_state(OperationState::PowerDown).await;
info!("set_desired_state(PowerState::PowerDown)");
while control.power_state() != OperationState::PowerDown {
Expand Down
16 changes: 16 additions & 0 deletions src/asynch/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,20 @@ impl<'a, AT: AtatClient> Control<'a, AT> {
pub async fn set_desired_state(&mut self, ps: OperationState) {
self.state_ch.set_desired_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
}

}

4 changes: 2 additions & 2 deletions src/asynch/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ impl<'d, AT: AtatClient, C: CellularConfig, const URC_CAPACITY: usize>
self.enable_registration_urcs().await?;

// Set automatic operator selection, if not already set
let crate::command::network_service::responses::OperatorSelection { mode, .. } = self
let crate::command::network_service::responses::OperatorSelection { mode, ..} = self
.at
.send(&crate::command::network_service::GetOperatorSelection)
.await?;
Expand All @@ -285,7 +285,7 @@ impl<'d, AT: AtatClient, C: CellularConfig, const URC_CAPACITY: usize>
self.at
.send(&crate::command::network_service::SetOperatorSelection {
mode: crate::command::network_service::types::OperatorSelectionMode::Automatic,
format: Some(2),
format: Some(C::OPERATOR_FORMAT as u8),
})
.await?;
}
Expand Down
1 change: 1 addition & 0 deletions src/command/network_service/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub struct SignalQuality {

/// 7.5 Operator selection +COPS
#[derive(Clone, AtatResp)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct OperatorSelection {
#[at_arg(position = 0)]
pub mode: OperatorSelectionMode,
Expand Down
1 change: 1 addition & 0 deletions src/command/network_service/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ pub enum ThirdRadioAccessTechnology {
}

#[derive(Debug, Clone, PartialEq, Eq, AtatEnum)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum OperatorNameFormat {
#[at_arg(value = 0)]
Long(String<24>),
Expand Down
12 changes: 10 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,18 @@ pub trait CellularConfig {
type PowerPin: OutputPin;
type VintPin: InputPin;

const FLOW_CONTROL: bool;
const HEX_MODE: bool;
const FLOW_CONTROL: bool = false;
const HEX_MODE: bool = true;
const OPERATOR_FORMAT: OperatorFormat = OperatorFormat::Long;

fn reset_pin(&mut self) -> Option<&mut Self::ResetPin>;
fn power_pin(&mut self) -> Option<&mut Self::PowerPin>;
fn vint_pin(&mut self) -> Option<&mut Self::VintPin>;
}

#[repr(u8)]
pub enum OperatorFormat {
Long = 0,
Short = 1,
Numeric = 2,
}

0 comments on commit 8503ea0

Please sign in to comment.