kenwood_thd75/protocol/
service.rs

1//! Service mode commands: 0G, 0Y, 0S, 0R, 0W, 1A, 1D, 1E, 1I, 1N, 1U, 1V, 1W, 1F, 9E, 9R, 2V, 1G, 1C.
2//!
3//! Provides parsing of responses for the 20 factory service mode commands
4//! discovered via Ghidra firmware reverse engineering of the TH-D75 V1.03.
5//! Serialization is handled inline by the main dispatcher.
6//!
7//! # Safety
8//!
9//! These commands are intended for factory use only. Service mode is entered
10//! by sending `0G KENWOOD` and exited with bare `0G`. While in service mode,
11//! the standard CAT command table is replaced with the service mode table.
12
13use crate::error::ProtocolError;
14
15use super::Response;
16
17/// Parse a service mode command response from mnemonic and payload.
18///
19/// Returns `None` if the mnemonic is not a service mode command.
20pub(crate) fn parse_service(
21    mnemonic: &str,
22    payload: &str,
23) -> Option<Result<Response, ProtocolError>> {
24    match mnemonic {
25        "0G" => Some(Ok(Response::ServiceMode {
26            data: payload.to_owned(),
27        })),
28        "0S" => Some(Ok(Response::ServiceCalibrationData {
29            data: payload.to_owned(),
30        })),
31        "1A" | "1D" | "1N" | "1E" | "1V" | "1W" | "1C" | "1U" => {
32            Some(Ok(Response::ServiceCalibrationParam {
33                mnemonic: mnemonic.to_owned(),
34                data: payload.to_owned(),
35            }))
36        }
37        "0R" => Some(Ok(Response::ServiceCalibrationWrite {
38            data: payload.to_owned(),
39        })),
40        "0W" => Some(Ok(Response::ServiceWriteConfig {
41            data: payload.to_owned(),
42        })),
43        "0Y" => Some(Ok(Response::ServiceBandSelect {
44            data: payload.to_owned(),
45        })),
46        "1I" => Some(Ok(Response::ServiceWriteId {
47            data: payload.to_owned(),
48        })),
49        "1F" => Some(Ok(Response::ServiceFlash {
50            data: payload.to_owned(),
51        })),
52        "9E" => Some(Ok(Response::ServiceEepromData {
53            data: payload.to_owned(),
54        })),
55        "9R" => Some(Ok(Response::ServiceEepromAddr {
56            data: payload.to_owned(),
57        })),
58        "2V" => Some(Ok(Response::ServiceVersion {
59            data: payload.to_owned(),
60        })),
61        "1G" => Some(Ok(Response::ServiceHardware {
62            data: payload.to_owned(),
63        })),
64        _ => None,
65    }
66}