Skip to content

Commit 67adb83

Browse files
committed
Change feature flag naming
1 parent 942b93e commit 67adb83

File tree

8 files changed

+125
-29
lines changed

8 files changed

+125
-29
lines changed

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ atat = { version = "*", features = ["heapless"] }
5252

5353

5454
[features]
55-
default = ["socket-udp", "socket-tcp", "async", "ublox-sockets"]
55+
default = ["socket-udp", "socket-tcp", "async"]
5656

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

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

examples/embassy-rp2040-example/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ static_cell = { version = "2.0", features = []}
3131
atat = { version = "0.21.0", features = ["derive", "bytes", "defmt"] }
3232
ublox-cellular-rs = {version = "0.4.0", path = "../..", features = ["lara-r6", "defmt", "async"]}
3333

34+
[features]
35+
ppp = ["ublox-cellular-rs/ppp"]
36+
internal-network-stack = ["ublox-cellular-rs/internal-network-stack"]
37+
3438
[patch.crates-io]
3539
ublox-sockets = { git = "https://github.com/BlackbirdHQ/ublox-sockets", branch = "feature/async-borrowed-sockets" }
3640
# atat = { git = "https://github.com/BlackbirdHQ/atat", branch = "master" }

examples/embassy-rp2040-example/src/bin/embassy-pdp-context.rs examples/embassy-rp2040-example/src/bin/embassy-internal-stack.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use embassy_rp::uart::BufferedUartTx;
1515
use embassy_rp::{bind_interrupts, peripherals::UART0, uart::BufferedInterruptHandler};
1616
use embassy_time::{Duration, Timer};
1717
use static_cell::StaticCell;
18+
use ublox_cellular::asynch::InternalRunner;
1819
use ublox_cellular::asynch::Resources;
19-
use ublox_cellular::asynch::UbloxRunner;
2020
use {defmt_rtt as _, panic_probe as _};
2121

2222
use ublox_cellular::config::{Apn, CellularConfig};
@@ -95,7 +95,7 @@ async fn main(spawner: Spawner) {
9595
Resources<BufferedUartTx<UART0>, CMD_BUF_SIZE, INGRESS_BUF_SIZE, URC_CAPACITY>,
9696
> = StaticCell::new();
9797

98-
let (_net_device, mut control, runner) = ublox_cellular::asynch::new(
98+
let (_net_device, mut control, runner) = ublox_cellular::asynch::new_internal(
9999
uart_rx,
100100
uart_tx,
101101
RESOURCES.init(Resources::new()),
@@ -175,7 +175,7 @@ async fn main(spawner: Spawner) {
175175

176176
#[embassy_executor::task]
177177
async fn cell_task(
178-
mut runner: UbloxRunner<
178+
mut runner: InternalRunner<
179179
'static,
180180
BufferedUartRx<'static, UART0>,
181181
BufferedUartTx<'static, UART0>,

src/asynch/mod.rs

+93-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pub mod control;
22
pub mod runner;
3-
#[cfg(feature = "ublox-sockets")]
3+
#[cfg(feature = "internal-network-stack")]
44
pub mod ublox_stack;
55

66
pub mod state;
@@ -9,9 +9,11 @@ use core::mem::MaybeUninit;
99

1010
use crate::{
1111
command::{
12+
control::{types::FlowControl, SetFlowControl},
13+
ipc::SetMultiplexing,
1214
mobile_control::{
13-
types::{Functionality, ResetMode},
14-
SetModuleFunctionality,
15+
types::{Functionality, ResetMode, TerminationErrorMode},
16+
SetModuleFunctionality, SetReportMobileTerminationError,
1517
},
1618
psn::{DeactivatePDPContext, EnterPPP, SetPDPContextDefinition},
1719
Urc,
@@ -24,7 +26,8 @@ use atat::{
2426
};
2527
use embassy_sync::{blocking_mutex::raw::NoopRawMutex, mutex::Mutex};
2628
use embassy_time::{Duration, Instant, Timer};
27-
use embedded_io_async::{BufRead, Write};
29+
use embedded_io::Error;
30+
use embedded_io_async::{BufRead, Read, Write};
2831
use runner::Runner;
2932

3033
use self::control::Control;
@@ -42,17 +45,17 @@ pub type Resources<
4245
const CMD_BUF_SIZE: usize,
4346
const INGRESS_BUF_SIZE: usize,
4447
const URC_CAPACITY: usize,
45-
> = Resources<
48+
> = UbxResources<
4649
embassy_at_cmux::ChannelTx<'static, 256>,
4750
CMD_BUF_SIZE,
4851
INGRESS_BUF_SIZE,
4952
URC_CAPACITY,
5053
>;
5154

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

55-
pub struct Resources<
58+
pub struct UbxResources<
5659
W: Write,
5760
const CMD_BUF_SIZE: usize,
5861
const INGRESS_BUF_SIZE: usize,
@@ -79,7 +82,7 @@ impl<
7982
const CMD_BUF_SIZE: usize,
8083
const INGRESS_BUF_SIZE: usize,
8184
const URC_CAPACITY: usize,
82-
> Resources<W, CMD_BUF_SIZE, INGRESS_BUF_SIZE, URC_CAPACITY>
85+
> UbxResources<W, CMD_BUF_SIZE, INGRESS_BUF_SIZE, URC_CAPACITY>
8386
{
8487
pub fn new() -> Self {
8588
Self {
@@ -101,7 +104,8 @@ impl<
101104
}
102105
}
103106

104-
pub fn new<
107+
#[cfg(feature = "internal-network-stack")]
108+
pub fn new_internal<
105109
'a,
106110
R: embedded_io_async::Read,
107111
W: embedded_io_async::Write,
@@ -117,7 +121,7 @@ pub fn new<
117121
) -> (
118122
state::Device<'a, Client<'a, W, INGRESS_BUF_SIZE>, URC_CAPACITY>,
119123
Control<'a, Client<'a, W, INGRESS_BUF_SIZE>>,
120-
UbloxRunner<'a, R, W, C, INGRESS_BUF_SIZE, URC_CAPACITY>,
124+
InternalRunner<'a, R, W, C, INGRESS_BUF_SIZE, URC_CAPACITY>,
121125
) {
122126
// safety: this is a self-referential struct, however:
123127
// - it can't move while the `'a` borrow is active.
@@ -158,7 +162,7 @@ pub fn new<
158162
&resources.urc_channel,
159163
);
160164

161-
let runner = UbloxRunner {
165+
let runner = InternalRunner {
162166
cellular_runner: runner,
163167
ingress,
164168
reader,
@@ -167,7 +171,8 @@ pub fn new<
167171
(net_device, control, runner)
168172
}
169173

170-
pub struct UbloxRunner<
174+
#[cfg(feature = "internal-network-stack")]
175+
pub struct InternalRunner<
171176
'a,
172177
R: embedded_io_async::Read,
173178
W: embedded_io_async::Write,
@@ -180,14 +185,15 @@ pub struct UbloxRunner<
180185
pub reader: R,
181186
}
182187

188+
#[cfg(feature = "internal-network-stack")]
183189
impl<
184190
'a,
185191
R: embedded_io_async::Read,
186192
W: embedded_io_async::Write,
187193
C: CellularConfig<'a>,
188194
const INGRESS_BUF_SIZE: usize,
189195
const URC_CAPACITY: usize,
190-
> UbloxRunner<'a, R, W, C, INGRESS_BUF_SIZE, URC_CAPACITY>
196+
> InternalRunner<'a, R, W, C, INGRESS_BUF_SIZE, URC_CAPACITY>
191197
{
192198
pub async fn run(&mut self) -> ! {
193199
embassy_futures::join::join(
@@ -273,6 +279,28 @@ pub fn new_ppp<
273279
(net_device, control, runner)
274280
}
275281

282+
pub struct ReadWriteAdapter<R, W>(pub R, pub W);
283+
284+
impl<R, W> embedded_io_async::ErrorType for ReadWriteAdapter<R, W> {
285+
type Error = embedded_io::ErrorKind;
286+
}
287+
288+
impl<R: Read, W> Read for ReadWriteAdapter<R, W> {
289+
async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
290+
self.0.read(buf).await.map_err(|e| e.kind())
291+
}
292+
}
293+
294+
impl<R, W: Write> Write for ReadWriteAdapter<R, W> {
295+
async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
296+
self.1.write(buf).await.map_err(|e| e.kind())
297+
}
298+
299+
async fn flush(&mut self) -> Result<(), Self::Error> {
300+
self.1.flush().await.map_err(|e| e.kind())
301+
}
302+
}
303+
276304
#[cfg(feature = "ppp")]
277305
pub struct PPPRunner<
278306
'a,
@@ -327,16 +355,66 @@ impl<'a, C: CellularConfig<'a>, const INGRESS_BUF_SIZE: usize, const URC_CAPACIT
327355
Ok(())
328356
}
329357

330-
pub async fn run<R: BufRead, W: Write>(
358+
async fn init<R: Read, W: Write>(rx: &mut R, tx: &mut W) -> Result<(), atat::Error> {
359+
let mut buf = [0u8; 64];
360+
let mut at_client = SimpleClient::new(
361+
ReadWriteAdapter(rx, tx),
362+
atat::AtDigester::<Urc>::new(),
363+
&mut buf,
364+
atat::Config::default(),
365+
);
366+
367+
at_client
368+
.send(&SetReportMobileTerminationError {
369+
n: TerminationErrorMode::Enabled,
370+
})
371+
.await?;
372+
373+
at_client
374+
.send(&SetFlowControl {
375+
value: FlowControl::RtsCts,
376+
})
377+
.await?;
378+
379+
at_client
380+
.send(&SetMultiplexing {
381+
mode: 0,
382+
subset: None,
383+
port_speed: None,
384+
n1: None,
385+
t1: None,
386+
n2: None,
387+
t2: None,
388+
t3: None,
389+
k: None,
390+
})
391+
.await?;
392+
393+
Ok(())
394+
}
395+
396+
pub async fn run<R: BufRead + Read, W: Write>(
331397
&mut self,
332398
mut rx: R,
333399
mut tx: W,
334400
stack: &embassy_net::Stack<embassy_net_ppp::Device<'a>>,
335401
) -> ! {
336402
loop {
337403
// Reset modem
404+
// if self.cellular_runner.init().await.is_err() {
405+
// Timer::after(Duration::from_secs(5)).await;
406+
// continue;
407+
// }
408+
409+
// Timer::after(Duration::from_secs(5)).await;
338410

339411
// Do AT init and enter CMUX mode using interface
412+
if Self::init(&mut rx, &mut tx).await.is_err() {
413+
Timer::after(Duration::from_secs(5)).await;
414+
continue;
415+
};
416+
417+
Timer::after(Duration::from_secs(1)).await;
340418

341419
let ppp_fut = async {
342420
let mut fails = 0;

src/asynch/runner.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ use crate::command::device_lock::GetPinStatus;
1414
use crate::command::general::{GetCCID, GetFirmwareVersion, GetModelId};
1515
use crate::command::gpio::types::{GpioInPull, GpioMode, GpioOutValue};
1616
use crate::command::gpio::SetGpioConfiguration;
17-
use crate::command::ip_transport_layer::types::HexMode;
18-
use crate::command::ip_transport_layer::SetHexMode;
1917
use crate::command::mobile_control::types::{Functionality, ResetMode, TerminationErrorMode};
2018
use crate::command::mobile_control::{SetModuleFunctionality, SetReportMobileTerminationError};
2119
use crate::command::psn::responses::GPRSAttached;
@@ -74,7 +72,7 @@ impl<'d, AT: AtatClient, C: CellularConfig<'d>, const URC_CAPACITY: usize>
7472
self.power_up().await?;
7573
};
7674
self.reset().await?;
77-
self.is_alive().await?;
75+
// self.is_alive().await?;
7876

7977
Ok(())
8078
}
@@ -205,16 +203,17 @@ impl<'d, AT: AtatClient, C: CellularConfig<'d>, const URC_CAPACITY: usize>
205203
})
206204
.await?;
207205

206+
#[cfg(feature = "internal-network-stack")]
208207
if C::HEX_MODE {
209208
self.at
210-
.send(&SetHexMode {
211-
hex_mode_disable: HexMode::Enabled,
209+
.send(&crate::command::ip_transport_layer::SetHexMode {
210+
hex_mode_disable: crate::command::ip_transport_layer::types::HexMode::Enabled,
212211
})
213212
.await?;
214213
} else {
215214
self.at
216-
.send(&SetHexMode {
217-
hex_mode_disable: HexMode::Disabled,
215+
.send(&crate::command::ip_transport_layer::SetHexMode {
216+
hex_mode_disable: crate::command::ip_transport_layer::types::HexMode::Disabled,
218217
})
219218
.await?;
220219
}
@@ -379,7 +378,7 @@ impl<'d, AT: AtatClient, C: CellularConfig<'d>, const URC_CAPACITY: usize>
379378
Timer::after(reset_time()).await;
380379
pin.set_high().ok();
381380
Timer::after(boot_time()).await;
382-
self.is_alive().await?;
381+
// self.is_alive().await?;
383382
} else {
384383
warn!("No reset pin configured");
385384
}
@@ -617,10 +616,13 @@ impl<'d, AT: AtatClient, C: CellularConfig<'d>, const URC_CAPACITY: usize>
617616
Urc::MobileStationDeactivate => warn!("Mobile station deactivated"),
618617
Urc::NetworkPDNDeactivate => warn!("Network PDN deactivated"),
619618
Urc::MobileStationPDNDeactivate => warn!("Mobile station PDN deactivated"),
619+
#[cfg(feature = "internal-network-stack")]
620620
Urc::SocketDataAvailable(_) => warn!("Socket data available"),
621+
#[cfg(feature = "internal-network-stack")]
621622
Urc::SocketDataAvailableUDP(_) => warn!("Socket data available UDP"),
622623
Urc::DataConnectionActivated(_) => warn!("Data connection activated"),
623624
Urc::DataConnectionDeactivated(_) => warn!("Data connection deactivated"),
625+
#[cfg(feature = "internal-network-stack")]
624626
Urc::SocketClosed(_) => warn!("Socket closed"),
625627
Urc::MessageWaitingIndication(_) => warn!("Message waiting indication"),
626628
Urc::ExtendedPSNetworkRegistration(_) => warn!("Extended PS network registration"),

src/command/mod.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub mod file_system;
1010
pub mod general;
1111
pub mod gpio;
1212
pub mod http;
13+
#[cfg(feature = "internal-network-stack")]
1314
pub mod ip_transport_layer;
1415
pub mod ipc;
1516
pub mod mobile_control;
@@ -42,16 +43,20 @@ pub enum Urc {
4243
#[at_urc("+CGEV: ME PDN DEACT")]
4344
MobileStationPDNDeactivate,
4445

46+
#[cfg(feature = "internal-network-stack")]
4547
#[at_urc("+UUSORD")]
4648
SocketDataAvailable(ip_transport_layer::urc::SocketDataAvailable),
49+
#[cfg(feature = "internal-network-stack")]
4750
#[at_urc("+UUSORF")]
4851
SocketDataAvailableUDP(ip_transport_layer::urc::SocketDataAvailable),
52+
#[cfg(feature = "internal-network-stack")]
53+
#[at_urc("+UUSOCL")]
54+
SocketClosed(ip_transport_layer::urc::SocketClosed),
55+
4956
#[at_urc("+UUPSDA")]
5057
DataConnectionActivated(psn::urc::DataConnectionActivated),
5158
#[at_urc("+UUPSDD")]
5259
DataConnectionDeactivated(psn::urc::DataConnectionDeactivated),
53-
#[at_urc("+UUSOCL")]
54-
SocketClosed(ip_transport_layer::urc::SocketClosed),
5560

5661
#[at_urc("+UMWI")]
5762
MessageWaitingIndication(sms::urc::MessageWaitingIndication),

src/config.rs

+3
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ pub trait CellularConfig<'a> {
7878
// const URC_CAPACITY: usize;
7979

8080
const FLOW_CONTROL: bool = false;
81+
82+
#[cfg(feature = "internal-network-stack")]
8183
const HEX_MODE: bool = true;
84+
8285
const OPERATOR_FORMAT: OperatorFormat = OperatorFormat::Long;
8386

8487
const PROFILE_ID: ProfileId = ProfileId(1);

src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
// #![cfg_attr(feature = "async", feature(async_fn_in_trait))]
55
// #![cfg_attr(feature = "async", feature(type_alias_impl_trait))]
66

7+
#[cfg(all(feature = "ppp", feature = "internal-network-stack"))]
8+
compile_error!("You may not enable both `ppp` and `internal-network-stack` features.");
9+
710
// This mod MUST go first, so that the others see its macros.
811
pub(crate) mod fmt;
912

0 commit comments

Comments
 (0)