From c7013d04d6bdc81cbc31707252e174bfa2879ab2 Mon Sep 17 00:00:00 2001 From: Marius Meissner Date: Thu, 8 Feb 2024 14:46:31 +0100 Subject: [PATCH] Adapted embedded-nal@0.8.0 --- Cargo.toml | 2 +- src/stack.rs | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4acea1d..175ddf6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ documentation = "https://docs.rs/esp-at-nal" [dependencies] atat = "0.17.0" -embedded-nal = "0.6.0" +embedded-nal = "0.8.0" nb = "1.0.0" fugit = "0.3.6" fugit-timer = "0.1.3" diff --git a/src/stack.rs b/src/stack.rs index a60a2bc..3305f6e 100644 --- a/src/stack.rs +++ b/src/stack.rs @@ -39,7 +39,7 @@ use crate::commands::{ use crate::wifi::Adapter; 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; @@ -124,6 +124,15 @@ pub enum Error { TimerError, } +impl TcpError for Error { + fn kind(&self) -> TcpErrorKind { + match self { + Error::ClosingSocket => TcpErrorKind::PipeClosed, + _ => TcpErrorKind::Other, + } + } +} + impl, const TIMER_HZ: u32, const TX_SIZE: usize, const RX_SIZE: usize> TcpClientStack for Adapter { @@ -176,13 +185,6 @@ impl, 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 { - self.process_urc_messages(); - Ok(self.sockets[socket.link_id] == SocketState::Connected) - } - /// 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 { @@ -259,6 +261,13 @@ impl, const TIMER_HZ: u32, const TX_SIZE: usiz impl, const TIMER_HZ: u32, const TX_SIZE: usize, const RX_SIZE: usize> Adapter { + /// 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 { + self.process_urc_messages(); + Ok(self.sockets[socket.link_id] == SocketState::Connected) + } + /// Sends a chunk of max. 256 bytes fn send_chunk(&mut self, data: &[u8]) -> Result<(), Error> { self.send_confirmed = None;