Skip to content

Commit

Permalink
Refactor AtUart::write function
Browse files Browse the repository at this point in the history
  • Loading branch information
lukipuki committed Nov 10, 2024
1 parent d059ab3 commit 419f19d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions nrf52840/src/at_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ impl AtUart {

pub async fn read(&mut self, timeout: Duration) -> Result<(), Error> {
loop {
let read_fut = CHANNEL.receive();
let line = with_timeout(timeout, read_fut)
let line = with_timeout(timeout, CHANNEL.receive())
.await
.map_err(|_| Error::TimeoutError)?;
let line = line?;
Expand All @@ -115,15 +114,18 @@ impl AtUart {
Ok(())
}

pub async fn call(&mut self, command: &str, timeout: Duration) -> Result<(), Error> {
async fn write(&mut self, command: &str) -> Result<(), Error> {
let mut command: String<AT_COMMAND_SIZE> = String::try_from(command).unwrap();
command.push('\r').unwrap();

self.tx
.write(command.as_bytes())
.await
.map_err(|_| Error::UartWriteError)?;
.map_err(|_| Error::UartWriteError)
}

pub async fn call(&mut self, command: &str, timeout: Duration) -> Result<(), Error> {
self.write(command).await?;
self.read(timeout).await
}
}
Expand Down

0 comments on commit 419f19d

Please sign in to comment.