From fee41758535ee413555cf29ead033d64fd844adb Mon Sep 17 00:00:00 2001 From: Kenneth Knudsen <98805797+KennethKnudsen97@users.noreply.github.com> Date: Thu, 23 Jan 2025 08:47:29 +0100 Subject: [PATCH] Feature: Add signal strength function (#93) * add function to get signal strength * handle error case in ublox and return i8 --- src/asynch/control.rs | 16 ++++++++++++++++ src/command/wifi/types.rs | 2 +- src/error.rs | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/asynch/control.rs b/src/asynch/control.rs index 0eaba53..84c424b 100644 --- a/src/asynch/control.rs +++ b/src/asynch/control.rs @@ -195,6 +195,22 @@ impl<'a, const INGRESS_BUF_SIZE: usize, const URC_CAPACITY: usize> } } + pub async fn get_signal_strength(&self) -> Result { + match (&self.at_client) + .send_retry(&GetWifiStatus { + status_id: StatusId::Rssi, + }) + .await? + .status_id + { + WifiStatus::Rssi(-32768) => Err(Error::NotConnected), + WifiStatus::Rssi(s) => s + .try_into() + .map_err(|_| Error::AT(atat::Error::InvalidResponse)), + _ => Err(Error::AT(atat::Error::InvalidResponse)), + } + } + pub async fn wait_for_link_state(&self, link_state: LinkState) { self.state_ch.wait_for_link_state(link_state).await } diff --git a/src/command/wifi/types.rs b/src/command/wifi/types.rs index 1b996ec..fb9ce5f 100644 --- a/src/command/wifi/types.rs +++ b/src/command/wifi/types.rs @@ -499,7 +499,7 @@ pub enum WifiStatus { /// The is the RSSI value of the current connection; will /// return-32768, if not connected. #[at_arg(value = 6)] - Rssi(u32), + Rssi(i16), /// The is the mobility domain of the last or current /// connection This tag is supported by ODIN-W2 from software version 6.0.0 /// onwards only. diff --git a/src/error.rs b/src/error.rs index fd38a1b..e454a41 100644 --- a/src/error.rs +++ b/src/error.rs @@ -34,6 +34,7 @@ pub enum Error { Timeout, ShadowStoreBug, AlreadyConnected, + NotConnected, _Unknown, }