kenwood_thd75/protocol/
bluetooth.rs

1//! Bluetooth commands: BT.
2//!
3//! Provides parsing of responses for the Bluetooth CAT protocol command.
4//! Serialization is handled inline by the main dispatcher.
5
6use crate::error::ProtocolError;
7
8use super::Response;
9
10/// Parse a Bluetooth command response from mnemonic and payload.
11///
12/// Returns `None` if the mnemonic is not a Bluetooth command.
13pub(crate) fn parse_bluetooth(
14    mnemonic: &str,
15    payload: &str,
16) -> Option<Result<Response, ProtocolError>> {
17    if mnemonic != "BT" {
18        return None;
19    }
20    Some(parse_bt(payload))
21}
22
23/// Parse BT (Bluetooth): "0" or "1".
24fn parse_bt(payload: &str) -> Result<Response, ProtocolError> {
25    match payload {
26        "0" => Ok(Response::Bluetooth { enabled: false }),
27        "1" => Ok(Response::Bluetooth { enabled: true }),
28        _ => Err(ProtocolError::FieldParse {
29            command: "BT".to_owned(),
30            field: "enabled".to_owned(),
31            detail: format!("expected 0 or 1, got {payload:?}"),
32        }),
33    }
34}