Skip to content

Commit

Permalink
Adapted embedded-nal@0.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
marius-meissner committed Feb 8, 2024
1 parent 0efbccd commit 2b850a9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -13,7 +13,7 @@ documentation = "https://docs.rs/esp-at-nal"

[dependencies]
atat = "0.18.0"
embedded-nal = "0.6.0"
embedded-nal = "0.8.0"
nb = "1.0.0"
fugit = "0.3.6"
fugit-timer = "0.1.3"
Expand Down
25 changes: 17 additions & 8 deletions src/stack.rs
Expand Up @@ -39,7 +39,7 @@ use crate::commands::{
use crate::wifi::{Adapter, Session};
use atat::AtatClient;
use atat::Error as AtError;
use embedded_nal::{SocketAddr, TcpClientStack};
use embedded_nal::{SocketAddr, TcpClientStack, TcpError, TcpErrorKind};
use fugit_timer::Timer;
use heapless::Vec;

Expand Down Expand Up @@ -140,6 +140,15 @@ pub enum Error {
TimerError,
}

impl TcpError for Error {
fn kind(&self) -> TcpErrorKind {
match self {
Error::ClosingSocket => TcpErrorKind::PipeClosed,
_ => TcpErrorKind::Other,
}
}
}

impl<A: AtatClient, T: Timer<TIMER_HZ>, const TIMER_HZ: u32, const TX_SIZE: usize, const RX_SIZE: usize> TcpClientStack
for Adapter<A, T, TIMER_HZ, TX_SIZE, RX_SIZE>
{
Expand Down Expand Up @@ -192,13 +201,6 @@ impl<A: AtatClient, T: Timer<TIMER_HZ>, const TIMER_HZ: u32, const TX_SIZE: usiz
nb::Result::Ok(())
}

/// Returns true if the socket is currently connected. Connection aborts by the remote side are also taken into account.
/// The current implementation never returns a Error.
fn is_connected(&mut self, socket: &Self::TcpSocket) -> Result<bool, Self::Error> {
self.process_urc_messages();
Ok(self.session.is_socket_connected(socket))
}

/// Sends the given buffer and returns the length (in bytes) sent.
/// The data is divided into smaller blocks. The block size is determined by the generic constant TX_SIZE.
fn send(&mut self, socket: &mut Socket, buffer: &[u8]) -> nb::Result<usize, Error> {
Expand Down Expand Up @@ -280,6 +282,13 @@ impl<A: AtatClient, T: Timer<TIMER_HZ>, const TIMER_HZ: u32, const TX_SIZE: usiz
impl<A: AtatClient, T: Timer<TIMER_HZ>, const TIMER_HZ: u32, const TX_SIZE: usize, const RX_SIZE: usize>
Adapter<A, T, TIMER_HZ, TX_SIZE, RX_SIZE>
{
/// Returns true if the socket is currently connected. Connection aborts by the remote side are also taken into account.
/// The current implementation never returns a Error.
pub fn is_connected(&mut self, socket: &Socket) -> Result<bool, Error> {
self.process_urc_messages();
Ok(self.session.is_socket_connected(socket))
}

/// Sends a chunk of max. 256 bytes
fn send_chunk(&mut self, data: &[u8]) -> Result<(), Error> {
self.session.send_confirmed = None;
Expand Down

0 comments on commit 2b850a9

Please sign in to comment.