Skip to content

Commit

Permalink
Better match_response
Browse files Browse the repository at this point in the history
  • Loading branch information
lukipuki committed Nov 11, 2024
1 parent d276686 commit 10301ea
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions nrf52840/src/at_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ async fn reader(
CHANNEL
.send(String::from_str(line).map_err(|_| Error::StringEncodingError))
.await;
debug!("Read: {}", line);
lines_count += 1;
if line == "OK" || line == "ERROR" {
CHANNEL.send(Ok(String::new())).await; // Mark a finished command
Expand Down Expand Up @@ -124,7 +123,8 @@ impl AtUart {
}

fn match_response<const S: usize>(lines: &[String<S>], command: &str) {
let prefix = &command[2..command.find("=").unwrap()];
let pos = command.find(['=', '?']).unwrap_or(command.len());
let prefix = &command[2..pos];
for line in lines {
if line.starts_with(prefix) {
info!("RETURN: {}", line.as_str());
Expand All @@ -137,8 +137,10 @@ impl AtUart {
debug!("{}", command);
let res = self.read(timeout).await?;
if let Some("OK") = res.last().map(String::as_str) {
Self::match_response(&res, command);
Ok(res)
} else {
error!("Fail: {}", command);
for line in res {
error!("{}", line.as_str());
}
Expand Down

0 comments on commit 10301ea

Please sign in to comment.