Skip to content

Commit

Permalink
Use latest atat, with new urc channel
Browse files Browse the repository at this point in the history
  • Loading branch information
MathiasKoch committed Aug 30, 2023
1 parent 6606365 commit 298f657
Show file tree
Hide file tree
Showing 12 changed files with 261 additions and 262 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ members = [ "ublox-short-range" ]


[patch.crates-io]
atat = { git = "https://github.com/BlackbirdHQ/atat", rev = "70283be" }
atat = { git = "https://github.com/BlackbirdHQ/atat", rev = "c5caaf7" }
7 changes: 5 additions & 2 deletions ublox-short-range/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@ doctest = false

[dependencies]
# atat = { version = "0.18.0", features = ["derive", "defmt", "bytes"] }
atat = { git = "https://github.com/BlackbirdHQ/atat", rev = "70283be", features = ["derive", "defmt", "bytes"] }
atat = { git = "https://github.com/BlackbirdHQ/atat", rev = "c5caaf7", features = ["derive", "defmt", "bytes"] }
heapless = { version = "^0.7", features = ["serde", "defmt-impl"] }
no-std-net = { version = "^0.5", features = ["serde"] }
serde = { version = "^1", default-features = false, features = ["derive"] }
ublox-sockets = { version = "0.5", features = ["defmt"] }
# ublox-sockets = { version = "0.5", features = ["defmt"] }
ublox-sockets = { git = "https://github.com/BlackbirdHQ/ublox-sockets", rev = "b1ff942", features = ["defmt"] }

hash32 = "^0.2.1"
hash32-derive = "^0.1.0"

defmt = { version = "0.3" }
embedded-hal = "=1.0.0-rc.1"
embedded-io = "0.5"
embedded-nal = "0.6.0"
fugit = { version = "0.3", features = ["defmt"] }
fugit-timer = "0.1.2"
Expand Down
376 changes: 192 additions & 184 deletions ublox-short-range/src/client.rs

Large diffs are not rendered by default.

10 changes: 0 additions & 10 deletions ublox-short-range/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ pub struct Config<RST> {
pub(crate) hostname: Option<String<20>>,
pub(crate) tls_in_buffer_size: Option<u16>,
pub(crate) tls_out_buffer_size: Option<u16>,
pub(crate) max_urc_attempts: u8,
pub(crate) network_up_bug: bool,
}

Expand All @@ -34,7 +33,6 @@ impl Default for Config<NoPin> {
hostname: None,
tls_in_buffer_size: None,
tls_out_buffer_size: None,
max_urc_attempts: 5,
network_up_bug: true,
}
}
Expand All @@ -50,7 +48,6 @@ where
hostname: None,
tls_in_buffer_size: None,
tls_out_buffer_size: None,
max_urc_attempts: 5,
network_up_bug: true,
}
}
Expand All @@ -69,13 +66,6 @@ where
}
}

pub fn max_urc_attempts(self, max_attempts: u8) -> Self {
Config {
max_urc_attempts: max_attempts,
..self
}
}

/// Experimental use of undocumented setting for TLS buffers
///
/// For Odin:
Expand Down
19 changes: 16 additions & 3 deletions ublox-short-range/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,27 @@ mod hex;

pub use atat;
pub use client::UbloxClient;
use client::{URC_CAPACITY, URC_SUBSCRIBERS};

pub mod command;
pub mod config;
pub mod error;
pub mod wifi;

#[cfg(test)]
mod test_helper;

use command::edm::urc::EdmEvent;
#[cfg(any(feature = "socket-udp", feature = "socket-tcp"))]
pub use wifi::tls::TLS;

pub type UbloxWifiBuffers<const INGRESS_BUF_SIZE: usize> =
atat::Buffers<EdmEvent, INGRESS_BUF_SIZE, URC_CAPACITY, URC_SUBSCRIBERS>;

pub type UbloxWifiIngress<'a, const INGRESS_BUF_SIZE: usize> = atat::Ingress<
'a,
command::custom_digest::EdmDigester,
EdmEvent,
INGRESS_BUF_SIZE,
URC_CAPACITY,
URC_SUBSCRIBERS,
>;

pub type UbloxWifiUrcChannel = atat::UrcChannel<EdmEvent, URC_CAPACITY, URC_SUBSCRIBERS>;
22 changes: 0 additions & 22 deletions ublox-short-range/src/test_helper.rs

This file was deleted.

7 changes: 4 additions & 3 deletions ublox-short-range/src/wifi/ap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ use embedded_hal::digital::OutputPin;

use super::connection::{WiFiState, WifiConnection};

impl<C, CLK, RST, const TIMER_HZ: u32, const N: usize, const L: usize>
UbloxClient<C, CLK, RST, TIMER_HZ, N, L>
impl<'buf, 'sub, AtCl, AtUrcCh, CLK, RST, const TIMER_HZ: u32, const N: usize, const L: usize>
UbloxClient<'buf, 'sub, AtCl, AtUrcCh, CLK, RST, TIMER_HZ, N, L>
where
C: AtatClient,
'buf: 'sub,
AtCl: AtatClient,
CLK: fugit_timer::Timer<TIMER_HZ>,
RST: OutputPin,
{
Expand Down
7 changes: 4 additions & 3 deletions ublox-short-range/src/wifi/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ use heapless::String;
use crate::{command::ping::*, UbloxClient};
use ublox_sockets::Error;

impl<C, CLK, RST, const TIMER_HZ: u32, const N: usize, const L: usize> Dns
for UbloxClient<C, CLK, RST, TIMER_HZ, N, L>
impl<'buf, 'sub, AtCl, AtUrcCh, CLK, RST, const TIMER_HZ: u32, const N: usize, const L: usize> Dns
for UbloxClient<'buf, 'sub, AtCl, AtUrcCh, CLK, RST, TIMER_HZ, N, L>
where
C: atat::blocking::AtatClient,
'buf: 'sub,
AtCl: atat::blocking::AtatClient,
CLK: fugit_timer::Timer<TIMER_HZ>,
RST: OutputPin,
{
Expand Down
9 changes: 5 additions & 4 deletions ublox-short-range/src/wifi/supplicant.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use atat::blocking::AtatClient;
use heapless::Vec;

use crate::{
Expand Down Expand Up @@ -50,15 +51,15 @@ use defmt::debug;
/// supplicant.remove_connection(0)
///
///
pub struct Supplicant<'a, C, const N: usize> {
pub(crate) client: &'a mut C,
pub struct Supplicant<'a, AtCl, const N: usize> {
pub(crate) client: &'a mut AtCl,
pub(crate) wifi_connection: &'a mut Option<WifiConnection>,
pub(crate) active_on_startup: &'a mut Option<u8>,
}

impl<'a, C, const N: usize> Supplicant<'a, C, N>
impl<'a, AtCl, const N: usize> Supplicant<'a, AtCl, N>
where
C: atat::blocking::AtatClient,
AtCl: AtatClient,
{
fn send_at<A: atat::AtatCmd<LEN>, const LEN: usize>(
&mut self,
Expand Down
25 changes: 13 additions & 12 deletions ublox-short-range/src/wifi/tcp_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ use ublox_sockets::{Error, SocketHandle, TcpSocket, TcpState};

use super::EGRESS_CHUNK_SIZE;

impl<C, CLK, RST, const TIMER_HZ: u32, const N: usize, const L: usize> TcpClientStack
for UbloxClient<C, CLK, RST, TIMER_HZ, N, L>
impl<'buf, 'sub, AtCl, AtUrcCh, CLK, RST, const TIMER_HZ: u32, const N: usize, const L: usize>
TcpClientStack for UbloxClient<'buf, 'sub, AtCl, AtUrcCh, CLK, RST, TIMER_HZ, N, L>
where
C: atat::blocking::AtatClient,
'buf: 'sub,
AtCl: atat::blocking::AtatClient,
CLK: fugit_timer::Timer<TIMER_HZ>,
RST: OutputPin,
{
Expand All @@ -35,7 +36,7 @@ where
if sockets.len() >= sockets.capacity() {
// Check if there are any sockets closed by remote, and close it
// if it has exceeded its timeout, in order to recycle it.
if !sockets.recycle(self.timer.now()) {
if !sockets.recycle() {
return Err(Error::SocketSetFull);
}
}
Expand Down Expand Up @@ -88,7 +89,7 @@ where
.sockets
.as_mut()
.unwrap()
.get::<TcpSocket<TIMER_HZ, L>>(*socket)
.get::<TcpSocket<L>>(*socket)
.map_err(Self::Error::from)?;

tcp.set_state(TcpState::WaitingForConnect(remote));
Expand All @@ -106,7 +107,7 @@ where
.sockets
.as_mut()
.unwrap()
.get::<TcpSocket<TIMER_HZ, L>>(*socket)
.get::<TcpSocket<L>>(*socket)
.map_err(Self::Error::from)?;
tcp.set_state(TcpState::Created);
return Err(nb::Error::Other(e));
Expand All @@ -122,7 +123,7 @@ where
self.sockets
.as_mut()
.unwrap()
.get::<TcpSocket<TIMER_HZ, L>>(*socket)
.get::<TcpSocket<L>>(*socket)
.map_err(Self::Error::from)?
.state(),
TcpState::WaitingForConnect(_)
Expand All @@ -137,7 +138,7 @@ where
fn is_connected(&mut self, socket: &Self::TcpSocket) -> Result<bool, Self::Error> {
self.connected_to_network().map_err(|_| Error::Illegal)?;
if let Some(ref mut sockets) = self.sockets {
let tcp = sockets.get::<TcpSocket<TIMER_HZ, L>>(*socket)?;
let tcp = sockets.get::<TcpSocket<L>>(*socket)?;
Ok(tcp.is_connected())
} else {
Err(Error::Illegal)
Expand All @@ -154,7 +155,7 @@ where
self.connected_to_network().map_err(|_| Error::Illegal)?;
if let Some(ref mut sockets) = self.sockets {
let tcp = sockets
.get::<TcpSocket<TIMER_HZ, L>>(*socket)
.get::<TcpSocket<L>>(*socket)
.map_err(nb::Error::Other)?;

if !tcp.is_connected() {
Expand Down Expand Up @@ -191,10 +192,10 @@ where
self.spin().map_err(|_| nb::Error::Other(Error::Illegal))?;
if let Some(ref mut sockets) = self.sockets {
// Enable detecting closed socket from receive function
sockets.recycle(self.timer.now());
sockets.recycle();

let mut tcp = sockets
.get::<TcpSocket<TIMER_HZ, L>>(*socket)
.get::<TcpSocket<L>>(*socket)
.map_err(Self::Error::from)?;

Ok(tcp.recv_slice(buffer).map_err(Self::Error::from)?)
Expand All @@ -208,7 +209,7 @@ where
if let Some(ref mut sockets) = self.sockets {
defmt::debug!("[TCP] Closing socket: {:?}", socket);
// If the socket is not found it is already removed
if let Ok(ref tcp) = sockets.get::<TcpSocket<TIMER_HZ, L>>(socket) {
if let Ok(ref tcp) = sockets.get::<TcpSocket<L>>(socket) {
// If socket is not closed that means a connection excists which has to be closed
if !matches!(
tcp.state(),
Expand Down
7 changes: 4 additions & 3 deletions ublox-short-range/src/wifi/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ pub trait TLS {
) -> Result<(), Error>;
}

impl<C, CLK, RST, const TIMER_HZ: u32, const N: usize, const L: usize> TLS
for UbloxClient<C, CLK, RST, TIMER_HZ, N, L>
impl<'buf, 'sub, AtCl, AtUrcCh, CLK, RST, const TIMER_HZ: u32, const N: usize, const L: usize> TLS
for UbloxClient<'buf, 'sub, AtCl, AtUrcCh, CLK, RST, TIMER_HZ, N, L>
where
C: atat::blocking::AtatClient,
'buf: 'sub,
AtCl: atat::blocking::AtatClient,
CLK: fugit_timer::Timer<TIMER_HZ>,
RST: OutputPin,
{
Expand Down
32 changes: 17 additions & 15 deletions ublox-short-range/src/wifi/udp_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ use ublox_sockets::{Error, SocketHandle, UdpSocket, UdpState};

use super::EGRESS_CHUNK_SIZE;

impl<C, CLK, RST, const TIMER_HZ: u32, const N: usize, const L: usize> UdpClientStack
for UbloxClient<C, CLK, RST, TIMER_HZ, N, L>
impl<'buf, 'sub, AtCl, AtUrcCh, CLK, RST, const TIMER_HZ: u32, const N: usize, const L: usize>
UdpClientStack for UbloxClient<'buf, 'sub, AtCl, AtUrcCh, CLK, RST, TIMER_HZ, N, L>
where
C: atat::blocking::AtatClient,
'buf: 'sub,
AtCl: atat::blocking::AtatClient,
CLK: fugit_timer::Timer<TIMER_HZ>,
RST: OutputPin,
{
Expand All @@ -36,7 +37,7 @@ where
if sockets.len() >= sockets.capacity() {
// Check if there are any sockets closed by remote, and close it
// if it has exceeded its timeout, in order to recycle it.
if sockets.recycle(self.timer.now()) {
if !sockets.recycle() {
return Err(Error::SocketSetFull);
}
}
Expand Down Expand Up @@ -77,7 +78,7 @@ where
.sockets
.as_mut()
.unwrap()
.get::<UdpSocket<TIMER_HZ, L>>(*socket)?;
.get::<UdpSocket<L>>(*socket)?;
udp.bind(remote)?;

// Then connect modem
Expand All @@ -95,7 +96,7 @@ where
.sockets
.as_mut()
.unwrap()
.get::<UdpSocket<TIMER_HZ, L>>(*socket)?;
.get::<UdpSocket<L>>(*socket)?;
udp.close();
return Err(e);
}
Expand All @@ -104,7 +105,7 @@ where
.sockets
.as_mut()
.unwrap()
.get::<UdpSocket<TIMER_HZ, L>>(*socket)?
.get::<UdpSocket<L>>(*socket)?
.state()
== UdpState::Closed
{
Expand All @@ -123,7 +124,7 @@ where
}

let udp = sockets
.get::<UdpSocket<TIMER_HZ, L>>(*socket)
.get::<UdpSocket<L>>(*socket)
.map_err(Self::Error::from)?;

if !udp.is_open() {
Expand Down Expand Up @@ -175,7 +176,7 @@ where

if let Some(ref mut sockets) = self.sockets {
let mut udp = sockets
.get::<UdpSocket<TIMER_HZ, L>>(*connection_handle)
.get::<UdpSocket<L>>(*connection_handle)
.map_err(|_| Self::Error::InvalidSocket)?;

let bytes = udp.recv_slice(buffer).map_err(Self::Error::from)?;
Expand All @@ -187,7 +188,7 @@ where
// Handle reciving for udp normal sockets
} else if let Some(ref mut sockets) = self.sockets {
let mut udp = sockets
.get::<UdpSocket<TIMER_HZ, L>>(*socket)
.get::<UdpSocket<L>>(*socket)
.map_err(Self::Error::from)?;

let bytes = udp.recv_slice(buffer).map_err(Self::Error::from)?;
Expand Down Expand Up @@ -255,7 +256,7 @@ where
} else if let Some(ref mut sockets) = self.sockets {
defmt::debug!("[UDP] Closing socket: {:?}", socket);
// If no sockets exists, nothing to close.
if let Ok(ref mut udp) = sockets.get::<UdpSocket<TIMER_HZ, L>>(socket) {
if let Ok(ref mut udp) = sockets.get::<UdpSocket<L>>(socket) {
defmt::trace!("[UDP] Closing socket state: {:?}", udp.state());
match udp.state() {
UdpState::Closed => {
Expand Down Expand Up @@ -293,10 +294,11 @@ where
/// - The driver has to call send_to after reciving data, to release the socket bound by remote host,
/// even if just sending no bytes. Else these sockets will be held open until closure of server socket.
///
impl<C, CLK, RST, const TIMER_HZ: u32, const N: usize, const L: usize> UdpFullStack
for UbloxClient<C, CLK, RST, TIMER_HZ, N, L>
impl<'buf, 'sub, AtCl, AtUrcCh, CLK, RST, const TIMER_HZ: u32, const N: usize, const L: usize>
UdpFullStack for UbloxClient<'buf, 'sub, AtCl, AtUrcCh, CLK, RST, TIMER_HZ, N, L>
where
C: atat::blocking::AtatClient,
'buf: 'sub,
AtCl: atat::blocking::AtatClient,
CLK: fugit_timer::Timer<TIMER_HZ>,
RST: OutputPin,
{
Expand Down Expand Up @@ -352,7 +354,7 @@ where
}

let udp = sockets
.get::<UdpSocket<TIMER_HZ, L>>(connection_socket)
.get::<UdpSocket<L>>(connection_socket)
.map_err(Self::Error::from)?;

if !udp.is_open() {
Expand Down

0 comments on commit 298f657

Please sign in to comment.