Skip to content

Commit

Permalink
Transition to core::net
Browse files Browse the repository at this point in the history
  • Loading branch information
MathiasKoch committed Oct 29, 2024
1 parent 6666302 commit e5afeee
Show file tree
Hide file tree
Showing 19 changed files with 34 additions and 38 deletions.
22 changes: 10 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ doctest = false
atat = { version = "0.23", features = ["derive", "bytes"] }

heapless = { version = "^0.8", features = ["serde"] }
no-std-net = { version = "0.6", features = ["serde"] }
serde = { version = "^1", default-features = false, features = ["derive"] }
# ublox-sockets = { version = "0.5", optional = true }
ublox-sockets = { git = "https://github.com/BlackbirdHQ/ublox-sockets", rev = "9f7fe54", optional = true }
Expand All @@ -32,7 +31,7 @@ embassy-time = "0.3"
embassy-sync = "0.6"
embassy-futures = "0.1"

embedded-nal-async = { version = "0.7" }
embedded-nal-async = { version = "0.8" }
futures-util = { version = "0.3.29", default-features = false }

embedded-io-async = "0.6"
Expand Down Expand Up @@ -83,16 +82,15 @@ exclude = ["examples"]


[patch.crates-io]
no-std-net = { git = "https://github.com/rushmorem/no-std-net", branch = "issue-15" }
atat = { git = "https://github.com/BlackbirdHQ/atat", rev = "a466836" }
# atat = { path = "../atat/atat" }

embassy-futures = { git = "https://github.com/embassy-rs/embassy", rev = "0ede847" }
embassy-time = { git = "https://github.com/embassy-rs/embassy", rev = "0ede847" }
embassy-time-driver = { git = "https://github.com/embassy-rs/embassy", rev = "0ede847" }
embassy-time-queue-driver = { git = "https://github.com/embassy-rs/embassy", rev = "0ede847" }
embassy-net = { git = "https://github.com/embassy-rs/embassy", rev = "0ede847" }
embassy-net-driver = { git = "https://github.com/embassy-rs/embassy", rev = "0ede847" }
embassy-net-driver-channel = { git = "https://github.com/embassy-rs/embassy", rev = "0ede847" }
embassy-net-ppp = { git = "https://github.com/embassy-rs/embassy", rev = "0ede847" }
embassy-sync = { git = "https://github.com/embassy-rs/embassy", rev = "0ede847" }
embassy-futures = { git = "https://github.com/embassy-rs/embassy", rev = "80cb2bc" }
embassy-time = { git = "https://github.com/embassy-rs/embassy", rev = "80cb2bc" }
embassy-time-driver = { git = "https://github.com/embassy-rs/embassy", rev = "80cb2bc" }
embassy-time-queue-driver = { git = "https://github.com/embassy-rs/embassy", rev = "80cb2bc" }
embassy-net = { git = "https://github.com/embassy-rs/embassy", rev = "80cb2bc" }
embassy-net-driver = { git = "https://github.com/embassy-rs/embassy", rev = "80cb2bc" }
embassy-net-driver-channel = { git = "https://github.com/embassy-rs/embassy", rev = "80cb2bc" }
embassy-net-ppp = { git = "https://github.com/embassy-rs/embassy", rev = "80cb2bc" }
embassy-sync = { git = "https://github.com/embassy-rs/embassy", rev = "80cb2bc" }
2 changes: 1 addition & 1 deletion examples/rpi-pico/src/bin/embassy-async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#![allow(incomplete_features)]

use core::fmt::Write as _;
use core::net::{Ipv4Addr, SocketAddr};
use embassy_executor::Spawner;
use embassy_futures::select::{select, Either};
use embassy_rp::gpio::{AnyPin, Input, Level, Output, Pull};
Expand All @@ -14,7 +15,6 @@ use embassy_rp::uart::{BufferedInterruptHandler, BufferedUartTx};
use embassy_rp::{bind_interrupts, uart};
use embassy_time::{Duration, Timer};
use embedded_io_async::Write;
use no_std_net::{Ipv4Addr, SocketAddr};
use static_cell::make_static;
use ublox_short_range::asynch::runner::Runner;
use ublox_short_range::asynch::ublox_stack::dns::DnsSocket;
Expand Down
2 changes: 1 addition & 1 deletion examples/rpi-pico/src/bin/embassy-perf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
#![feature(async_fn_in_trait)]
#![allow(incomplete_features)]

use core::net::Ipv4Addr;
use embassy_executor::Spawner;
use embassy_futures::join::join;
use embassy_rp::gpio::{Level, Output};
use embassy_rp::peripherals::{PIN_26, UART1};
use embassy_rp::uart::BufferedInterruptHandler;
use embassy_rp::{bind_interrupts, uart};
use embassy_time::{with_timeout, Duration, Timer};
use no_std_net::Ipv4Addr;
use static_cell::make_static;
use ublox_short_range::asynch::runner::Runner;
use ublox_short_range::asynch::ublox_stack::tcp::TcpSocket;
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[toolchain]
channel = "1.79"
channel = "1.80"
components = [ "rust-src", "rustfmt", "llvm-tools" ]
targets = [
"thumbv6m-none-eabi",
Expand Down
2 changes: 1 addition & 1 deletion src/asynch/control.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use core::cell::Cell;
use core::net::Ipv4Addr;
use core::str::FromStr as _;

use atat::AtatCmd;
use atat::{asynch::AtatClient, response_slot::ResponseSlotGuard, UrcChannel};
use embassy_sync::{blocking_mutex::raw::NoopRawMutex, channel::Sender};
use embassy_time::{with_timeout, Duration, Timer};
use heapless::Vec;
use no_std_net::Ipv4Addr;

use crate::command::general::responses::SoftwareVersionResponse;
use crate::command::general::types::FirmwareVersion;
Expand Down
2 changes: 1 addition & 1 deletion src/asynch/network.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use atat::{asynch::AtatClient, UrcChannel, UrcSubscription};
use core::net::{Ipv4Addr, Ipv6Addr};
use core::str::FromStr as _;
use embassy_time::{with_timeout, Duration, Timer};
use embedded_hal::digital::OutputPin as _;
use no_std_net::{Ipv4Addr, Ipv6Addr};

use crate::{
command::{
Expand Down
8 changes: 2 additions & 6 deletions src/asynch/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,15 +419,11 @@ where
};
let mut dns_servers = heapless::Vec::new();
for s in ipv4.dns_servers.iter().flatten() {
let _ =
dns_servers.push(embassy_net::Ipv4Address::from_bytes(&s.0));
let _ = dns_servers.push(s.clone());

Check warning on line 422 in src/asynch/runner.rs

View workflow job for this annotation

GitHub Actions / clippy

using `clone` on type `Ipv4Address` which implements the `Copy` trait

warning: using `clone` on type `Ipv4Address` which implements the `Copy` trait --> src/asynch/runner.rs:422:58 | 422 | ... let _ = dns_servers.push(s.clone()); | ^^^^^^^^^ help: try dereferencing it: `*s` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy = note: `#[warn(clippy::clone_on_copy)]` on by default
}
let config =
embassy_net::ConfigV4::Static(embassy_net::StaticConfigV4 {
address: embassy_net::Ipv4Cidr::new(
embassy_net::Ipv4Address::from_bytes(&addr.0),
0,
),
address: embassy_net::Ipv4Cidr::new(addr, 0),
gateway: None,
dns_servers,
});
Expand Down
2 changes: 1 addition & 1 deletion src/asynch/ublox_stack/dns.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use core::{cell::RefCell, future::poll_fn, task::Poll};

use core::net::IpAddr;
use embassy_sync::waitqueue::WakerRegistration;
use embedded_nal_async::AddrType;
use no_std_net::IpAddr;

use crate::command::ping::types::PingError;

Expand Down
2 changes: 1 addition & 1 deletion src/asynch/ublox_stack/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ use self::dns::{DnsSocket, DnsState, DnsTable};

use super::control::ProxyClient;

use core::net::IpAddr;
use embassy_futures::select;
use embassy_sync::waitqueue::WakerRegistration;
use embassy_time::{Duration, Ticker};
use embedded_nal_async::SocketAddr;
use no_std_net::IpAddr;
use portable_atomic::{AtomicBool, AtomicU8, Ordering};
use ublox_sockets::{
AnySocket, ChannelId, PeerHandle, Socket, SocketHandle, SocketSet, SocketStorage,
Expand Down
2 changes: 1 addition & 1 deletion src/asynch/ublox_stack/peer_builder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::error::Error;
use core::fmt::Write;
use core::net::{IpAddr, SocketAddr};
use heapless::String;
use no_std_net::{IpAddr, SocketAddr};

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
Expand Down
4 changes: 2 additions & 2 deletions src/asynch/ublox_stack/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,13 +656,13 @@ pub mod client {
&self,
host: &str,
addr_type: embedded_nal_async::AddrType,
) -> Result<no_std_net::IpAddr, Self::Error> {
) -> Result<core::net::IpAddr, Self::Error> {
DnsSocket::new(self.stack).query(host, addr_type).await
}

async fn get_host_by_address(
&self,
_addr: no_std_net::IpAddr,
_addr: core::net::IpAddr,
_result: &mut [u8],
) -> Result<usize, Self::Error> {
unimplemented!()
Expand Down
6 changes: 3 additions & 3 deletions src/asynch/ublox_stack/tls.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use core::net::SocketAddr;
use embassy_time::Duration;
use no_std_net::SocketAddr;
use ublox_sockets::TcpState as State;

use super::peer_builder::SecurityCredentials;
Expand Down Expand Up @@ -301,13 +301,13 @@ pub mod client {
&self,
host: &str,
addr_type: embedded_nal_async::AddrType,
) -> Result<no_std_net::IpAddr, Self::Error> {
) -> Result<core::net::IpAddr, Self::Error> {
DnsSocket::new(self.stack).query(host, addr_type).await
}

async fn get_host_by_address(
&self,
_addr: no_std_net::IpAddr,
_addr: core::net::IpAddr,
_result: &mut [u8],
) -> Result<usize, Self::Error> {
unimplemented!()
Expand Down
2 changes: 1 addition & 1 deletion src/command/edm/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use core::net::{Ipv4Addr, Ipv6Addr};
use heapless::Vec;
use no_std_net::{Ipv4Addr, Ipv6Addr};
use serde::{Deserialize, Serialize};
use ublox_sockets::ChannelId;

Expand Down
2 changes: 1 addition & 1 deletion src/command/edm/urc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use super::types::*;
use super::Urc;
use atat::helpers::LossyStr;
use atat::AtatUrc;
use core::net::{Ipv4Addr, Ipv6Addr};
use heapless::Vec;
use no_std_net::{Ipv4Addr, Ipv6Addr};
use ublox_sockets::ChannelId;

#[allow(clippy::large_enum_variant)]
Expand Down
2 changes: 1 addition & 1 deletion src/command/ethernet/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Argument and parameter types used by Ethernet Commands and Responses
use atat::atat_derive::AtatEnum;
use no_std_net::Ipv4Addr;
use core::net::Ipv4Addr;

use crate::command::OnOff;

Expand Down
2 changes: 1 addition & 1 deletion src/command/ping/urc.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Responses for Ping Commands
use super::types::*;
use atat::atat_derive::AtatResp;
use core::net::IpAddr;
use heapless::String;
use no_std_net::IpAddr;
/// 16.1 Ping command +UPING
///
/// The ping command is the common method to know if a remote host is reachable on the Internet.
Expand Down
2 changes: 1 addition & 1 deletion src/command/wifi/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use crate::command::OnOff;
use atat::atat_derive::AtatEnum;
use atat::heapless_bytes::Bytes;
use core::net::{Ipv4Addr, Ipv6Addr};
use heapless::{String, Vec};
use no_std_net::{Ipv4Addr, Ipv6Addr};
use serde::Deserialize;

#[derive(Clone, PartialEq, AtatEnum)]
Expand Down
4 changes: 3 additions & 1 deletion src/connection.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use no_std_net::Ipv4Addr;
use core::net::Ipv4Addr;

use crate::network::{WifiMode, WifiNetwork};

Expand Down Expand Up @@ -50,13 +50,15 @@ impl WifiConnection {
}
}

#[allow(dead_code)]
pub fn is_station(&self) -> bool {
self.network
.as_ref()
.map(|n| n.mode == WifiMode::Station)
.unwrap_or_default()
}

#[allow(dead_code)]
pub fn is_access_point(&self) -> bool {
!self.is_station()
}
Expand Down
2 changes: 1 addition & 1 deletion src/options.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use core::net::Ipv4Addr;
use heapless::Vec;
use no_std_net::Ipv4Addr;

#[allow(dead_code)]
#[derive(Debug, Clone, Copy)]
Expand Down

0 comments on commit e5afeee

Please sign in to comment.