-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor async completely for a more intuitive API. URCs over PPP UDP…
… socket is still not working properly
- Loading branch information
1 parent
e96769a
commit 27ed97e
Showing
21 changed files
with
955 additions
and
1,058 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use embassy_net::{udp::UdpSocket, Ipv4Address}; | ||
use embedded_io_async::{Read, Write}; | ||
|
||
pub struct AtUdpSocket<'a>(pub(crate) UdpSocket<'a>); | ||
|
||
impl<'a> AtUdpSocket<'a> { | ||
pub(crate) const PPP_AT_PORT: u16 = 23; | ||
} | ||
|
||
impl<'a> embedded_io_async::ErrorType for &AtUdpSocket<'a> { | ||
type Error = core::convert::Infallible; | ||
} | ||
|
||
impl<'a> Read for &AtUdpSocket<'a> { | ||
async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> { | ||
let (len, _) = self.0.recv_from(buf).await.unwrap(); | ||
debug!("READ {} bytes: {=[u8]:a}", len, &buf[..len]); | ||
Ok(len) | ||
} | ||
} | ||
|
||
impl<'a> Write for &AtUdpSocket<'a> { | ||
async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> { | ||
self.0 | ||
.send_to( | ||
buf, | ||
(Ipv4Address::new(172, 30, 0, 251), AtUdpSocket::PPP_AT_PORT), | ||
) | ||
.await | ||
.unwrap(); | ||
|
||
Ok(buf.len()) | ||
} | ||
} | ||
|
||
impl<'a> embedded_io_async::ErrorType for AtUdpSocket<'a> { | ||
type Error = core::convert::Infallible; | ||
} | ||
|
||
impl<'a> Read for AtUdpSocket<'a> { | ||
async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> { | ||
let (len, _) = self.0.recv_from(buf).await.unwrap(); | ||
debug!("READ {} bytes: {=[u8]:a}", len, &buf[..len]); | ||
Ok(len) | ||
} | ||
} | ||
|
||
impl<'a> Write for AtUdpSocket<'a> { | ||
async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> { | ||
self.0 | ||
.send_to( | ||
buf, | ||
(Ipv4Address::new(172, 30, 0, 251), AtUdpSocket::PPP_AT_PORT), | ||
) | ||
.await | ||
.unwrap(); | ||
|
||
Ok(buf.len()) | ||
} | ||
} |
Oops, something went wrong.