kenwood_thd75/protocol/
sd.rs

1//! SD card commands: SD.
2//!
3//! Provides parsing of responses for the SD card 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 boolean field ("0" or "1").
11fn parse_bool(payload: &str, cmd: &str) -> Result<bool, ProtocolError> {
12    match payload {
13        "0" => Ok(false),
14        "1" => Ok(true),
15        _ => Err(ProtocolError::FieldParse {
16            command: cmd.to_owned(),
17            field: "value".to_owned(),
18            detail: format!("expected 0 or 1, got {payload:?}"),
19        }),
20    }
21}
22
23/// Parse an SD card command response from mnemonic and payload.
24///
25/// Returns `None` if the mnemonic is not an SD command.
26pub(crate) fn parse_sd(mnemonic: &str, payload: &str) -> Option<Result<Response, ProtocolError>> {
27    if mnemonic != "SD" {
28        return None;
29    }
30    Some(parse_bool(payload, "SD").map(|present| Response::SdCard { present }))
31}