Skip to content

Commit

Permalink
Control additions (#98)
Browse files Browse the repository at this point in the history
* add operator and signalstrength to control, make operator format controlable

* don't overwrite ublox-sockets

* update atat

* bump e-h to 1.0
  • Loading branch information
tarfu authored Jan 11, 2024
1 parent 07cd52a commit 458f6b3
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 12 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ name = "ublox_cellular"
doctest = false

[dependencies]
atat = { version = "0.20.0", features = ["derive", "bytes"] }
atat = { version = "0.21.0", features = ["derive", "bytes"] }
heapless = { version = "^0.8", features = ["serde"] }
nb = "^1"
serde = { version = "^1", default-features = false, features = ["derive"] }
Expand All @@ -36,7 +36,7 @@ futures-util = { version = "0.3.29", default-features = false }

embassy-futures = { version = "0.1", optional = true }

embedded-hal = "=1.0.0-rc.3"
embedded-hal = "1.0.0"
embedded-nal = "0.8"
embedded-nal-async = { version = "0.7", optional = true }

Expand All @@ -47,7 +47,7 @@ embedded-io-async = "0.6"
[features]
default = ["socket-udp", "socket-tcp", "async", "ublox-sockets"]

async = ["dep:embedded-nal-async", "dep:embassy-futures", "atat/async", "ublox-sockets?/async"]
async = ["dep:embedded-nal-async", "dep:embassy-futures", "ublox-sockets?/async"]

defmt = [
"dep:defmt",
Expand Down Expand Up @@ -88,7 +88,7 @@ exclude = ["examples"]
[patch.crates-io]
#ublox-sockets = { git = "https://github.com/BlackbirdHQ/ublox-sockets", branch = "feature/async-borrowed-sockets" }
no-std-net = { git = "https://github.com/rushmorem/no-std-net", branch = "issue-15" }
ublox-sockets = { path = "../ublox-sockets" }
#ublox-sockets = { path = "../ublox-sockets" }
atat = { git = "https://github.com/BlackbirdHQ/atat", branch = "master" }
embassy-time = { git = "https://github.com/embassy-rs/embassy", branch = "main" }
embassy-sync = { git = "https://github.com/embassy-rs/embassy", branch = "main" }
Expand Down
2 changes: 1 addition & 1 deletion examples/embassy-stm32-example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ panic-probe = { version = "0.3.1", features = ["print-defmt"] }

static_cell = { version = "2.0", features = []}

atat = { version = "0.20.0", features = ["derive", "bytes", "defmt"] }
atat = { version = "0.21.0", features = ["derive", "bytes", "defmt"] }
ublox-cellular-rs = {version = "0.4.0", path = "../..", features = ["sara-r5", "defmt", "async"]}

[patch.crates-io]
Expand Down
34 changes: 30 additions & 4 deletions examples/embassy-stm32-example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async fn main_task(spawner: Spawner) {
source: PllSource::HSI,
prediv: PllPreDiv::DIV4,
mul: PllMul::MUL50,
divp: Some(PllDiv::DIV2),
divp: Some(PllDiv::DIV2), //400mhz
divq: Some(PllDiv::DIV8), // 100mhz
divr: None,
});
Expand Down Expand Up @@ -171,21 +171,47 @@ 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 {
Timer::after(Duration::from_millis(1000)).await;
}

Timer::after(Duration::from_millis(5000)).await;
}

Expand Down
27 changes: 27 additions & 0 deletions src/asynch/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,31 @@ 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
}
}
2 changes: 1 addition & 1 deletion src/asynch/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 458f6b3

Please sign in to comment.