mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-22 06:42:32 +00:00
Add closing if raw socket to handle re-attach
This commit is contained in:
parent
372e45dabc
commit
ccfa6264b0
@ -4,8 +4,8 @@ use core::str::FromStr;
|
|||||||
|
|
||||||
use at_commands::builder::CommandBuilder;
|
use at_commands::builder::CommandBuilder;
|
||||||
use at_commands::parser::CommandParser;
|
use at_commands::parser::CommandParser;
|
||||||
|
use embassy_time::{Duration, Timer};
|
||||||
use heapless::Vec;
|
use heapless::Vec;
|
||||||
use embassy_time::{Timer, Duration};
|
|
||||||
|
|
||||||
/// Provides a higher level API for controlling a given context.
|
/// Provides a higher level API for controlling a given context.
|
||||||
pub struct Control<'a> {
|
pub struct Control<'a> {
|
||||||
@ -129,8 +129,6 @@ impl<'a> Control<'a> {
|
|||||||
let n = self.control.at_command(op, &mut buf).await;
|
let n = self.control.at_command(op, &mut buf).await;
|
||||||
CommandParser::parse(&buf[..n]).expect_identifier(b"OK").finish()?;
|
CommandParser::parse(&buf[..n]).expect_identifier(b"OK").finish()?;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,13 +287,13 @@ impl<'a> Control<'a> {
|
|||||||
|
|
||||||
loop {
|
loop {
|
||||||
if !self.attached().await? {
|
if !self.attached().await? {
|
||||||
// TODO: self.control.close_raw_socket(fd).await;
|
self.control.close_raw_socket(fd).await;
|
||||||
self.attach().await?;
|
self.attach().await?;
|
||||||
while !self.attached().await? {
|
while !self.attached().await? {
|
||||||
Timer::after(Duration::from_secs(1)).await;
|
Timer::after(Duration::from_secs(1)).await;
|
||||||
}
|
}
|
||||||
let status = self.status().await?;
|
let status = self.status().await?;
|
||||||
// TODO: let mut fd = self.control.open_raw_socket().await;
|
fd = self.control.open_raw_socket().await;
|
||||||
reattach(&status);
|
reattach(&status);
|
||||||
}
|
}
|
||||||
Timer::after(Duration::from_secs(10)).await;
|
Timer::after(Duration::from_secs(10)).await;
|
||||||
|
@ -870,6 +870,21 @@ impl<'a> Control<'a> {
|
|||||||
trace!("got FD: {}", fd);
|
trace!("got FD: {}", fd);
|
||||||
fd
|
fd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn close_raw_socket(&self, fd: u32) {
|
||||||
|
let mut msg: Message = unsafe { mem::zeroed() };
|
||||||
|
msg.channel = 2; // data
|
||||||
|
msg.id = 0x7009_0004; // close socket
|
||||||
|
msg.param_len = 8;
|
||||||
|
msg.param[4..8].copy_from_slice(&fd.to_le_bytes());
|
||||||
|
|
||||||
|
self.request(&mut msg, &[], &mut []).await;
|
||||||
|
|
||||||
|
assert_eq!(msg.id, 0x80090004);
|
||||||
|
assert!(msg.param_len >= 12);
|
||||||
|
let status = u32::from_le_bytes(msg.param[8..12].try_into().unwrap());
|
||||||
|
assert_eq!(status, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Background runner for the driver.
|
/// Background runner for the driver.
|
||||||
|
@ -193,5 +193,7 @@ async fn main(spawner: Spawner) {
|
|||||||
info!("txd: {}", core::str::from_utf8(msg).unwrap());
|
info!("txd: {}", core::str::from_utf8(msg).unwrap());
|
||||||
Timer::after_secs(1).await;
|
Timer::after_secs(1).await;
|
||||||
}
|
}
|
||||||
|
// Test auto-attach
|
||||||
|
unwrap!(control.detach().await);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user