Skip to content

Commit

Permalink
Change feature flag naming
Browse files Browse the repository at this point in the history
  • Loading branch information
MathiasKoch committed Feb 21, 2024
1 parent 942b93e commit ed9e756
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 13 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ atat = { version = "*", features = ["heapless"] }


[features]
default = ["socket-udp", "socket-tcp", "async", "ublox-sockets"]
default = ["socket-udp", "socket-tcp", "async", "ppp"]

ppp = ["dep:embassy-at-cmux", "dep:embassy-net-ppp", "dep:embassy-net"]
internal-network-stack = ["dep:ublox-sockets"]

async = ["dep:embedded-nal-async", "dep:embassy-futures"]

Expand Down
3 changes: 3 additions & 0 deletions examples/embassy-rp2040-example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ static_cell = { version = "2.0", features = []}
atat = { version = "0.21.0", features = ["derive", "bytes", "defmt"] }
ublox-cellular-rs = {version = "0.4.0", path = "../..", features = ["lara-r6", "defmt", "async"]}

[features]
ppp = ["ublox-cellular-rs/ppp"]

[patch.crates-io]
ublox-sockets = { git = "https://github.com/BlackbirdHQ/ublox-sockets", branch = "feature/async-borrowed-sockets" }
# atat = { git = "https://github.com/BlackbirdHQ/atat", branch = "master" }
Expand Down
98 changes: 88 additions & 10 deletions src/asynch/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub mod control;
pub mod runner;
#[cfg(feature = "ublox-sockets")]
#[cfg(feature = "internal-network-stack")]
pub mod ublox_stack;

pub mod state;
Expand All @@ -9,9 +9,11 @@ use core::mem::MaybeUninit;

use crate::{
command::{
control::{types::FlowControl, SetFlowControl},
ipc::SetMultiplexing,
mobile_control::{
types::{Functionality, ResetMode},
SetModuleFunctionality,
types::{Functionality, ResetMode, TerminationErrorMode},
SetModuleFunctionality, SetReportMobileTerminationError,
},
psn::{DeactivatePDPContext, EnterPPP, SetPDPContextDefinition},
Urc,
Expand All @@ -24,7 +26,8 @@ use atat::{
};
use embassy_sync::{blocking_mutex::raw::NoopRawMutex, mutex::Mutex};
use embassy_time::{Duration, Instant, Timer};
use embedded_io_async::{BufRead, Write};
use embedded_io::Error;
use embedded_io_async::{BufRead, Read, Write};
use runner::Runner;

use self::control::Control;
Expand All @@ -42,17 +45,17 @@ pub type Resources<
const CMD_BUF_SIZE: usize,
const INGRESS_BUF_SIZE: usize,
const URC_CAPACITY: usize,
> = Resources<
> = UbxResources<
embassy_at_cmux::ChannelTx<'static, 256>,
CMD_BUF_SIZE,
INGRESS_BUF_SIZE,
URC_CAPACITY,
>;

// #[cfg(not(feature = "ppp"))]
// pub use self::Resources;
#[cfg(feature = "internal-network-stack")]
pub use self::UbxResources as Resources;

pub struct Resources<
pub struct UbxResources<
W: Write,
const CMD_BUF_SIZE: usize,
const INGRESS_BUF_SIZE: usize,
Expand All @@ -79,7 +82,7 @@ impl<
const CMD_BUF_SIZE: usize,
const INGRESS_BUF_SIZE: usize,
const URC_CAPACITY: usize,
> Resources<W, CMD_BUF_SIZE, INGRESS_BUF_SIZE, URC_CAPACITY>
> UbxResources<W, CMD_BUF_SIZE, INGRESS_BUF_SIZE, URC_CAPACITY>
{
pub fn new() -> Self {
Self {
Expand All @@ -101,6 +104,7 @@ impl<
}
}

#[cfg(feature = "internal-network-stack")]
pub fn new<
'a,
R: embedded_io_async::Read,
Expand Down Expand Up @@ -167,6 +171,7 @@ pub fn new<
(net_device, control, runner)
}

#[cfg(feature = "internal-network-stack")]
pub struct UbloxRunner<
'a,
R: embedded_io_async::Read,
Expand All @@ -180,6 +185,7 @@ pub struct UbloxRunner<
pub reader: R,
}

#[cfg(feature = "internal-network-stack")]
impl<
'a,
R: embedded_io_async::Read,
Expand Down Expand Up @@ -273,6 +279,28 @@ pub fn new_ppp<
(net_device, control, runner)
}

pub struct ReadWriteAdapter<R, W>(pub R, pub W);

impl<R, W> embedded_io_async::ErrorType for ReadWriteAdapter<R, W> {
type Error = embedded_io::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, 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())
}
}

#[cfg(feature = "ppp")]
pub struct PPPRunner<
'a,
Expand Down Expand Up @@ -327,16 +355,66 @@ impl<'a, C: CellularConfig<'a>, const INGRESS_BUF_SIZE: usize, const URC_CAPACIT
Ok(())
}

pub async fn run<R: BufRead, W: Write>(
async fn init<R: Read, W: Write>(rx: &mut R, tx: &mut W) -> Result<(), atat::Error> {
let mut buf = [0u8; 64];
let mut at_client = SimpleClient::new(
ReadWriteAdapter(rx, tx),
atat::AtDigester::<Urc>::new(),
&mut buf,
atat::Config::default(),
);

at_client
.send(&SetReportMobileTerminationError {
n: TerminationErrorMode::Enabled,
})
.await?;

at_client
.send(&SetFlowControl {
value: FlowControl::RtsCts,
})
.await?;

at_client
.send(&SetMultiplexing {
mode: 0,
subset: None,
port_speed: None,
n1: None,
t1: None,
n2: None,
t2: None,
t3: None,
k: None,
})
.await?;

Ok(())
}

pub async fn run<R: BufRead + Read, W: Write>(
&mut self,
mut rx: R,
mut tx: W,
stack: &embassy_net::Stack<embassy_net_ppp::Device<'a>>,
) -> ! {
loop {
// Reset modem
// if self.cellular_runner.init().await.is_err() {
// Timer::after(Duration::from_secs(5)).await;
// continue;
// }

// Timer::after(Duration::from_secs(5)).await;

// Do AT init and enter CMUX mode using interface
if Self::init(&mut rx, &mut tx).await.is_err() {
Timer::after(Duration::from_secs(5)).await;
continue;
};

Timer::after(Duration::from_secs(1)).await;

let ppp_fut = async {
let mut fails = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/asynch/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl<'d, AT: AtatClient, C: CellularConfig<'d>, const URC_CAPACITY: usize>
self.power_up().await?;
};
self.reset().await?;
self.is_alive().await?;
// self.is_alive().await?;

Ok(())
}
Expand Down Expand Up @@ -379,7 +379,7 @@ impl<'d, AT: AtatClient, C: CellularConfig<'d>, const URC_CAPACITY: usize>
Timer::after(reset_time()).await;
pin.set_high().ok();
Timer::after(boot_time()).await;
self.is_alive().await?;
// self.is_alive().await?;
} else {
warn!("No reset pin configured");
}
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
// #![cfg_attr(feature = "async", feature(async_fn_in_trait))]
// #![cfg_attr(feature = "async", feature(type_alias_impl_trait))]

#[cfg(all(feature = "ppp", feature = "internal-network-stack"))]
compile_error!("You may not enable both `ppp` and `internal-network-stack` features.");

// This mod MUST go first, so that the others see its macros.
pub(crate) mod fmt;

Expand Down

0 comments on commit ed9e756

Please sign in to comment.