kenwood_thd75/radio/
scan.rs1use crate::error::{Error, ProtocolError};
9use crate::protocol::{Command, Response};
10use crate::transport::Transport;
11use crate::types::{Band, ScanResumeMethod, StepSize};
12
13use super::Radio;
14
15impl<T: Transport> Radio<T> {
16 pub async fn set_scan_resume(&mut self, mode: ScanResumeMethod) -> Result<(), Error> {
28 tracing::info!(?mode, "setting scan resume mode (SR)");
29 let response = self.execute(Command::SetScanResume { mode }).await?;
30 match response {
31 Response::Ok => Ok(()),
32 other => Err(Error::Protocol(ProtocolError::UnexpectedResponse {
33 expected: "Ok".into(),
34 actual: format!("{other:?}").into_bytes(),
35 })),
36 }
37 }
38
39 pub async fn get_step_size(&mut self, band: Band) -> Result<(Band, StepSize), Error> {
47 tracing::debug!(?band, "reading step size");
48 let response = self.execute(Command::GetStepSize { band }).await?;
49 match response {
50 Response::StepSize {
51 band: resp_band,
52 step,
53 } => Ok((resp_band, step)),
54 other => Err(Error::Protocol(ProtocolError::UnexpectedResponse {
55 expected: "StepSize".into(),
56 actual: format!("{other:?}").into_bytes(),
57 })),
58 }
59 }
60
61 pub async fn set_step_size(&mut self, band: Band, step: StepSize) -> Result<(), Error> {
69 tracing::info!(?band, ?step, "setting step size");
70 let response = self.execute(Command::SetStepSize { band, step }).await?;
71 match response {
72 Response::StepSize { .. } => Ok(()),
73 other => Err(Error::Protocol(ProtocolError::UnexpectedResponse {
74 expected: "StepSize".into(),
75 actual: format!("{other:?}").into_bytes(),
76 })),
77 }
78 }
79
80 pub async fn get_band_scope(&mut self, band: Band) -> Result<Band, Error> {
88 tracing::debug!(?band, "reading band scope");
89 let response = self.execute(Command::GetBandScope { band }).await?;
90 match response {
91 Response::BandScope { band: scope_band } => Ok(scope_band),
92 other => Err(Error::Protocol(ProtocolError::UnexpectedResponse {
93 expected: "BandScope".into(),
94 actual: format!("{other:?}").into_bytes(),
95 })),
96 }
97 }
98
99 pub async fn set_band_scope(&mut self, band: Band, value: u8) -> Result<(), Error> {
110 tracing::info!(?band, value, "setting band scope configuration");
111 let response = self.execute(Command::SetBandScope { band, value }).await?;
112 match response {
113 Response::BandScope { .. } => Ok(()),
114 other => Err(Error::Protocol(ProtocolError::UnexpectedResponse {
115 expected: "BandScope".into(),
116 actual: format!("{other:?}").into_bytes(),
117 })),
118 }
119 }
120}