Skip to content

Commit

Permalink
Change from a single URC subscriber to two
Browse files Browse the repository at this point in the history
  • Loading branch information
MathiasKoch committed Sep 26, 2023
1 parent cc45f97 commit d39c8bb
Showing 1 changed file with 32 additions and 35 deletions.
67 changes: 32 additions & 35 deletions ublox-cellular/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use atat::{blocking::AtatClient, AtatUrcChannel};
use atat::{blocking::AtatClient, AtatUrcChannel, UrcSubscription};
use embassy_time::Duration;
use ublox_sockets::SocketSet;

Expand Down Expand Up @@ -48,7 +48,7 @@ use psn::{
};

pub(crate) const URC_CAPACITY: usize = 3;
pub(crate) const URC_SUBSCRIBERS: usize = 1;
pub(crate) const URC_SUBSCRIBERS: usize = 2;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
Expand All @@ -65,6 +65,7 @@ pub struct Device<'buf, 'sub, AtCl, AtUrcCh, Config, const N: usize, const L: us
pub(crate) config: Config,
pub(crate) network: Network<'sub, AtCl>,
urc_channel: &'buf AtUrcCh,

Check warning on line 67 in ublox-cellular/src/client.rs

View workflow job for this annotation

GitHub Actions / clippy

field `urc_channel` is never read

warning: field `urc_channel` is never read --> ublox-cellular/src/client.rs:67:5 | 64 | pub struct Device<'buf, 'sub, AtCl, AtUrcCh, Config, const N: usize, const L: usize> { | ------ field in this struct ... 67 | urc_channel: &'buf AtUrcCh, | ^^^^^^^^^^^ | = note: `#[warn(dead_code)]` on by default
urc_subscription: UrcSubscription<'sub, Urc, URC_CAPACITY, URC_SUBSCRIBERS>,

pub(crate) state: State,
pub(crate) power_state: PowerState,
Expand Down Expand Up @@ -115,14 +116,15 @@ where
Config: CellularConfig,
{
pub fn new(client: AtCl, urc_channel: &'buf AtUrcCh, config: Config) -> Self {
let urc_subscription = urc_channel.subscribe().unwrap();
let network_urc_subscription = urc_channel.subscribe().unwrap();
Self {
config,
network: Network::new(AtTx::new(client, urc_subscription)),
network: Network::new(AtTx::new(client, network_urc_subscription)),
state: State::Off,
power_state: PowerState::Off,
sockets: None,
urc_channel,
urc_subscription: urc_channel.subscribe().unwrap(),
}
}
}
Expand Down Expand Up @@ -526,36 +528,35 @@ where

fn handle_urc_internal(&mut self) -> Result<(), Error> {
if let Some(ref mut sockets) = self.sockets.as_deref_mut() {
self.network
.at_tx
.handle_urc(|urc| {
match urc {
Urc::SocketClosed(ip_transport_layer::urc::SocketClosed { socket }) => {
info!("[URC] SocketClosed {}", socket.0);
if let Some((_, mut sock)) =
sockets.iter_mut().find(|(handle, _)| *handle == socket)
{
sock.closed_by_remote();
}
if let Some(urc) = self.urc_subscription.try_next_message_pure() {
match urc {
Urc::SocketClosed(ip_transport_layer::urc::SocketClosed { socket }) => {
info!("[URC] SocketClosed {}", socket.0);
if let Some((_, mut sock)) =
sockets.iter_mut().find(|(handle, _)| *handle == socket)
{
sock.closed_by_remote();
}
Urc::SocketDataAvailable(
ip_transport_layer::urc::SocketDataAvailable { socket, length },
)
| Urc::SocketDataAvailableUDP(
ip_transport_layer::urc::SocketDataAvailable { socket, length },
) => {
trace!("[Socket({})] {} bytes available", socket.0, length as u16);
if let Some((_, mut sock)) =
sockets.iter_mut().find(|(handle, _)| *handle == socket)
{
sock.set_available_data(length);
}
}
Urc::SocketDataAvailable(ip_transport_layer::urc::SocketDataAvailable {
socket,
length,
})
| Urc::SocketDataAvailableUDP(ip_transport_layer::urc::SocketDataAvailable {
socket,
length,
}) => {
trace!("[Socket({})] {} bytes available", socket.0, length as u16);
if let Some((_, mut sock)) =
sockets.iter_mut().find(|(handle, _)| *handle == socket)
{
sock.set_available_data(length);
}
_ => return false,
}
true
})
.map_err(Error::Network)
_ => {}
}
}
Ok(())
} else {
Ok(())
}
Expand All @@ -578,8 +579,4 @@ where
result => result.map_err(Error::from),
}
}

pub fn handle_urc<F: FnOnce(Urc) -> bool>(&mut self, f: F) -> Result<(), Error> {
self.network.at_tx.handle_urc(f).map_err(Error::Network)
}
}

0 comments on commit d39c8bb

Please sign in to comment.