Skip to content

Commit

Permalink
Start matching responses
Browse files Browse the repository at this point in the history
  • Loading branch information
lukipuki committed Nov 11, 2024
1 parent 0d1b829 commit d276686
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
17 changes: 13 additions & 4 deletions nrf52840/src/at_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ impl AtUart {
.map_err(|_| Error::UartWriteError)
}

fn match_response<const S: usize>(lines: &[String<S>], command: &str) {
let prefix = &command[2..command.find("=").unwrap()];
for line in lines {
if line.starts_with(prefix) {
info!("RETURN: {}", line.as_str());
}
}
}

pub async fn call(&mut self, command: &str, timeout: Duration) -> Result<Response, Error> {
self.write(command).await?;
debug!("{}", command);
Expand All @@ -143,11 +152,11 @@ impl AtUart {
call_timeout: Duration,
response_timeout: Duration,
) -> Result<Response, Error> {
// TODO: do minimum timeout here
let mut first = self.call(command, call_timeout).await?;
let mut lines = self.call(command, call_timeout).await?;
let second = self.read(response_timeout).await?;
first.extend(second);
Ok(first)
lines.extend(second);
Self::match_response(&lines, command);
Ok(lines)
}
}

Expand Down
8 changes: 3 additions & 5 deletions nrf52840/src/bg77.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ pub struct BG77 {
activation_timeout: Duration,
}

fn callback_dispatcher(prefix: &str, rest: &str) -> bool {
fn callback_dispatcher(prefix: &str, _rest: &str) -> bool {
// TODO: Improve this
match prefix {
"QMTSTAT" => true,
"QMTPUB" => true,
"QMTCONN" => rest.len() >= 4 && rest.as_bytes()[1] == 0x2c && rest.as_bytes()[3] == 0x2c,
//"QMTOPEN" => rest.as_bytes()[1] == 0x2c && rest.len() == 3,
_ => false,
}
}
Expand All @@ -38,8 +36,8 @@ impl BG77 {
spawner: &Spawner,
) -> Self {
let uart1 = AtUart::new(rx1, tx1, callback_dispatcher, spawner);
let activation_timeout = Duration::from_secs(14); // 140
let pkt_timeout = Duration::from_secs(8); // 30
let activation_timeout = Duration::from_secs(40); // 140
let pkt_timeout = Duration::from_secs(12); // 30
Self {
uart1,
_modem_pin: modem_pin,
Expand Down

0 comments on commit d276686

Please sign in to comment.