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

fix: EdmEvent connectEvent insert channel only for event protocol type #70

Merged
merged 2 commits into from
Oct 30, 2023
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
12 changes: 6 additions & 6 deletions ublox-short-range/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@
config: Config<RST>,
) -> (UbloxWifiIngress<INGRESS_BUF_SIZE>, Self) {
let (ingress, client) =
buffers.split_blocking(tx, EdmDigester::default(), atat::Config::default());

Check warning on line 200 in ublox-short-range/src/client.rs

View workflow job for this annotation

GitHub Actions / clippy

use of `default` to create a unit struct

warning: use of `default` to create a unit struct --> ublox-short-range/src/client.rs:200:51 | 200 | buffers.split_blocking(tx, EdmDigester::default(), atat::Config::default()); | ^^^^^^^^^^^ help: remove this call to `default` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#default_constructed_unit_structs = note: `#[warn(clippy::default_constructed_unit_structs)]` on by default

(
ingress,
Expand Down Expand Up @@ -727,8 +727,8 @@
}
} else {
for (h, s) in sockets.iter_mut() {
match event.protocol {
Protocol::TCP => {
match (&event.protocol, s.get_type()) {
(Protocol::TCP, SocketType::Tcp) => {
let mut tcp = TcpSocket::downcast(s)?;
if tcp.endpoint() == Some(endpoint) {
self.socket_map
Expand All @@ -737,7 +737,7 @@
tcp.set_state(TcpState::Connected(endpoint));
}
}
Protocol::UDP => {
(Protocol::UDP, SocketType::Udp) => {
let mut udp = UdpSocket::downcast(s)?;
if udp.endpoint() == Some(endpoint) {
self.socket_map
Expand Down Expand Up @@ -772,8 +772,8 @@
}
} else {
for (h, s) in sockets.iter_mut() {
match event.protocol {
Protocol::TCP => {
match (&event.protocol, s.get_type()) {
(Protocol::TCP, SocketType::Tcp) => {
let mut tcp = TcpSocket::downcast(s)?;
if tcp.endpoint() == Some(endpoint) {
self.socket_map
Expand All @@ -782,7 +782,7 @@
tcp.set_state(TcpState::Connected(endpoint));
}
}
Protocol::UDP => {
(Protocol::UDP, SocketType::Udp) => {
let mut udp = UdpSocket::downcast(s)?;
if udp.endpoint() == Some(endpoint) {
self.socket_map
Expand Down
19 changes: 18 additions & 1 deletion ublox-short-range/src/wifi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ pub struct SocketMap {
peer_map: heapless::FnvIndexMap<PeerHandle, SocketHandle, 4>,
}

impl defmt::Format for SocketMap {
fn format(&self, fmt: defmt::Formatter) {
defmt::write!(fmt, "ChannelMap:\n");
for (channel, socket) in self.channel_map.iter() {
defmt::write!(fmt, "channelId: {}, Handle: {}\n", channel.0, socket.0)
}
defmt::write!(fmt, "PeerMap:\n");
for (peer, socket) in self.peer_map.iter() {
defmt::write!(fmt, "PeerId: {}, Handle: {}\n", peer.0, socket.0)
}
}
}

impl Default for SocketMap {
fn default() -> Self {
Self::new()
Expand All @@ -57,7 +70,10 @@ impl SocketMap {
defmt::trace!("[SOCK_MAP] {:?} tied to {:?}", socket_handle, channel_id);
match self.channel_map.insert(channel_id, socket_handle) {
Ok(_) => Ok(()),
Err(_) => Err(SocketMapError::Full),
Err(_) => {
defmt::error!("Failed inserting channel SocketMap full");
Err(SocketMapError::Full)
}
}
}

Expand All @@ -83,6 +99,7 @@ impl SocketMap {
) -> Result<(), SocketMapError> {
defmt::trace!("[SOCK_MAP] {:?} tied to {:?}", socket_handle, peer);
if self.peer_map.insert(peer, socket_handle).is_err() {
defmt::error!("Insert peer failed SocketMap is FULL");
return Err(SocketMapError::Full);
};
Ok(())
Expand Down
22 changes: 17 additions & 5 deletions ublox-short-range/src/wifi/udp_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
socket: &mut Self::UdpSocket,
remote: SocketAddr,
) -> Result<(), Self::Error> {
let mut peer_handle = crate::command::PeerHandle(0);

Check warning on line 64 in ublox-short-range/src/wifi/udp_stack.rs

View workflow job for this annotation

GitHub Actions / clippy

value assigned to `peer_handle` is never read

warning: value assigned to `peer_handle` is never read --> ublox-short-range/src/wifi/udp_stack.rs:64:17 | 64 | let mut peer_handle = crate::command::PeerHandle(0); | ^^^^^^^^^^^ | = help: maybe it is overwritten before being read? = note: `#[warn(unused_assignments)]` on by default

if self.sockets.is_none() {
defmt::error!("[UDP] Connecting socket Error: Missing socket set");
return Err(Error::Illegal);
Expand All @@ -86,10 +88,13 @@
.send_internal(&EdmAtCmdWrapper(ConnectPeer { url: &url }), true)
.map_err(|_| Error::Unaddressable)
{
Ok(resp) => self
.socket_map
.insert_peer(resp.peer_handle, *socket)
.map_err(|_| Error::InvalidSocket)?,
Ok(resp) => {
peer_handle = resp.peer_handle;

self.socket_map
.insert_peer(resp.peer_handle, *socket)
.map_err(|_| Error::InvalidSocket)?
}

Err(e) => {
let mut udp = self
Expand All @@ -109,7 +114,14 @@
.state()
== UdpState::Closed
{
self.spin().map_err(|_| Error::Illegal)?;
match self.spin() {
Ok(_) => {}
Err(_) => {
defmt::error!("ERROR connection UDP removing peer");
self.socket_map.remove_peer(&peer_handle);
return Err(Error::Illegal);
}
};
}
Ok(())
}
Expand Down
Loading