Skip to content

Commit

Permalink
Merge pull request #3762 from embassy-rs/net-ppp-release
Browse files Browse the repository at this point in the history
net ppp release
  • Loading branch information
Dirbaio authored Jan 12, 2025
2 parents a991cd6 + 2ce56e9 commit dd4f576
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 69 deletions.
15 changes: 15 additions & 0 deletions embassy-net-ppp/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Changelog for embassy-net-ppp

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.2.0 - 2025-01-12

- Update `ppproto` to v0.2.
- Use `core::net` IP types for IPv4 configuration instead of a custom type.

## 0.1.0 - 2024-01-12

First release.
4 changes: 2 additions & 2 deletions embassy-net-ppp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "embassy-net-ppp"
version = "0.1.0"
version = "0.2.0"
description = "embassy-net driver for PPP over Serial"
keywords = ["embedded", "ppp", "embassy-net", "embedded-hal-async", "async"]
categories = ["embedded", "hardware-support", "no-std", "network-programming", "asynchronous"]
Expand All @@ -20,7 +20,7 @@ log = { version = "0.4.14", optional = true }
embedded-io-async = { version = "0.6.1" }
embassy-net-driver-channel = { version = "0.3.0", path = "../embassy-net-driver-channel" }
embassy-futures = { version = "0.1.0", path = "../embassy-futures" }
ppproto = { version = "0.2.0"}
ppproto = { version = "0.2.1"}
embassy-sync = { version = "0.6.1", path = "../embassy-sync" }

[package.metadata.embassy_docs]
Expand Down
2 changes: 1 addition & 1 deletion examples/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ embassy-executor = { version = "0.7.0", path = "../../embassy-executor", feature
embassy-time = { version = "0.4.0", path = "../../embassy-time", features = ["log", "std", ] }
embassy-net = { version = "0.6.0", path = "../../embassy-net", features=[ "log", "medium-ethernet", "medium-ip", "tcp", "udp", "dns", "dhcpv4", "proto-ipv6"] }
embassy-net-tuntap = { version = "0.1.0", path = "../../embassy-net-tuntap" }
embassy-net-ppp = { version = "0.1.0", path = "../../embassy-net-ppp", features = ["log"]}
embassy-net-ppp = { version = "0.2.0", path = "../../embassy-net-ppp", features = ["log"]}
embedded-io-async = { version = "0.6.1" }
embedded-io-adapters = { version = "0.6.1", features = ["futures-03"] }
critical-section = { version = "1.1", features = ["std"] }
Expand Down
52 changes: 1 addition & 51 deletions examples/std/src/bin/net_ppp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async fn net_task(mut runner: embassy_net::Runner<'static, embassy_net_ppp::Devi
async fn ppp_task(stack: Stack<'static>, mut runner: Runner<'static>, port: SerialPort) -> ! {
let port = Async::new(port).unwrap();
let port = BufReader::new(port);
let port = adapter::FromFutures::new(port);
let port = embedded_io_adapters::futures_03::FromFutures::new(port);

let config = embassy_net_ppp::Config {
username: b"myuser",
Expand Down Expand Up @@ -163,53 +163,3 @@ fn main() {
spawner.spawn(main_task(spawner)).unwrap();
});
}

mod adapter {
use core::future::poll_fn;
use core::pin::Pin;

use futures::AsyncBufReadExt;

/// Adapter from `futures::io` traits.
#[derive(Clone)]
pub struct FromFutures<T: ?Sized> {
inner: T,
}

impl<T> FromFutures<T> {
/// Create a new adapter.
pub fn new(inner: T) -> Self {
Self { inner }
}
}

impl<T: ?Sized> embedded_io_async::ErrorType for FromFutures<T> {
type Error = std::io::Error;
}

impl<T: futures::io::AsyncRead + Unpin + ?Sized> embedded_io_async::Read for FromFutures<T> {
async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
poll_fn(|cx| Pin::new(&mut self.inner).poll_read(cx, buf)).await
}
}

impl<T: futures::io::AsyncBufRead + Unpin + ?Sized> embedded_io_async::BufRead for FromFutures<T> {
async fn fill_buf(&mut self) -> Result<&[u8], Self::Error> {
self.inner.fill_buf().await
}

fn consume(&mut self, amt: usize) {
Pin::new(&mut self.inner).consume(amt)
}
}

impl<T: futures::io::AsyncWrite + Unpin + ?Sized> embedded_io_async::Write for FromFutures<T> {
async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
poll_fn(|cx| Pin::new(&mut self.inner).poll_write(cx, buf)).await
}

async fn flush(&mut self) -> Result<(), Self::Error> {
poll_fn(|cx| Pin::new(&mut self.inner).poll_flush(cx)).await
}
}
}
17 changes: 2 additions & 15 deletions examples/std/src/bin/tcp_accept.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use core::fmt::Write as _;

use clap::Parser;
use embassy_executor::{Executor, Spawner};
use embassy_net::tcp::TcpSocket;
Expand Down Expand Up @@ -28,16 +26,6 @@ async fn net_task(mut runner: embassy_net::Runner<'static, TunTapDevice>) -> ! {
runner.run().await
}

#[derive(Default)]
struct StrWrite(pub heapless::Vec<u8, 30>);

impl core::fmt::Write for StrWrite {
fn write_str(&mut self, s: &str) -> Result<(), core::fmt::Error> {
self.0.extend_from_slice(s.as_bytes()).unwrap();
Ok(())
}
}

#[embassy_executor::task]
async fn main_task(spawner: Spawner) {
let opts: Opts = Opts::parse();
Expand Down Expand Up @@ -85,9 +73,8 @@ async fn main_task(spawner: Spawner) {

// Write some quick output
for i in 1..=5 {
let mut w = StrWrite::default();
write!(w, "{}! ", i).unwrap();
let r = socket.write_all(&w.0).await;
let s = format!("{}! ", i);
let r = socket.write_all(s.as_bytes()).await;
if let Err(e) = r {
warn!("write error: {:?}", e);
return;
Expand Down

0 comments on commit dd4f576

Please sign in to comment.