Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapted [email protected] (main) #18

Merged
merged 2 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading