Skip to content

Commit

Permalink
add rssi command
Browse files Browse the repository at this point in the history
  • Loading branch information
liamkinne committed Sep 5, 2024
1 parent b8efb11 commit 1126b29
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/bin/telesto/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ enum Commands {
Echo,
/// Enter standby.
Standby,
/// Receive signal strength of last received packet.
Rssi,
}

#[tokio::main]
Expand Down Expand Up @@ -82,6 +84,16 @@ async fn main() {
}
},
Commands::Standby => radio.standby().await.unwrap(),
Commands::Rssi => {
let rssi = radio.rssi().await.unwrap();

if rssi == 0x80 {
println!("No RSSI available");
} else {
let rssi = rssi as i8;
println!("RSSI: {}dBm", rssi);
}
}
_ => todo!(),
}

Expand Down
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,18 @@ where
}
}

/// Gets the receive signal strength (RSSI) of the last packet received.
pub async fn rssi(&mut self) -> Result<u8, Error<(), W::Error>> {
let mut buf = [0; 224];
let size = command(&mut buf, command::Request::Rssi, &[]);
self.serial.write(&buf[..size]).await.map_err(Error::Io)?;

let response = self.poll_response().await;
let status = response.data[0];

Ok(status)
}

/// Poll until a response frame is received through the response channel.
async fn poll_response(&mut self) -> Frame<Response> {
poll_fn(|cx| {
Expand Down

0 comments on commit 1126b29

Please sign in to comment.