[refactor](trx-protocol): move transport dto out of core
Phase 5: relocate ClientCommand/Envelope/Response into trx-protocol and update call sites so trx-core remains domain-focused. Co-authored-by: Codex <codex@openai.com> Signed-off-by: Stanislaw Grams <stanislawgrams@gmail.com>
This commit is contained in:
@@ -6,8 +6,8 @@
|
||||
|
||||
use serde_json;
|
||||
|
||||
use trx_core::client::{ClientCommand, ClientEnvelope};
|
||||
use trx_core::rig::state::RigMode;
|
||||
use crate::types::{ClientCommand, ClientEnvelope};
|
||||
|
||||
/// Parse a mode string into a RigMode.
|
||||
///
|
||||
|
||||
@@ -10,8 +10,10 @@
|
||||
pub mod auth;
|
||||
pub mod codec;
|
||||
pub mod mapping;
|
||||
pub mod types;
|
||||
|
||||
// Re-export commonly used items
|
||||
pub use auth::{NoAuthValidator, SimpleTokenValidator, TokenValidator};
|
||||
pub use codec::{mode_to_string, parse_envelope, parse_mode};
|
||||
pub use mapping::{client_command_to_rig, rig_command_to_client};
|
||||
pub use types::{ClientCommand, ClientEnvelope, ClientResponse};
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
|
||||
use trx_core::radio::freq::Freq;
|
||||
use trx_core::rig::command::RigCommand;
|
||||
use trx_core::ClientCommand;
|
||||
|
||||
use crate::codec::{mode_to_string, parse_mode};
|
||||
use crate::types::ClientCommand;
|
||||
|
||||
/// Convert a ClientCommand to a RigCommand.
|
||||
///
|
||||
@@ -123,7 +123,7 @@ mod tests {
|
||||
fn test_client_command_to_rig_set_ptt() {
|
||||
let cmd = ClientCommand::SetPtt { ptt: true };
|
||||
if let RigCommand::SetPtt(ptt) = client_command_to_rig(cmd) {
|
||||
assert_eq!(ptt, true);
|
||||
assert!(ptt);
|
||||
} else {
|
||||
panic!("Expected SetPtt");
|
||||
}
|
||||
@@ -203,7 +203,7 @@ mod tests {
|
||||
fn test_client_command_to_rig_set_aprs_decode_enabled() {
|
||||
let cmd = ClientCommand::SetAprsDecodeEnabled { enabled: true };
|
||||
if let RigCommand::SetAprsDecodeEnabled(enabled) = client_command_to_rig(cmd) {
|
||||
assert_eq!(enabled, true);
|
||||
assert!(enabled);
|
||||
} else {
|
||||
panic!("Expected SetAprsDecodeEnabled");
|
||||
}
|
||||
@@ -213,7 +213,7 @@ mod tests {
|
||||
fn test_client_command_to_rig_set_cw_decode_enabled() {
|
||||
let cmd = ClientCommand::SetCwDecodeEnabled { enabled: false };
|
||||
if let RigCommand::SetCwDecodeEnabled(enabled) = client_command_to_rig(cmd) {
|
||||
assert_eq!(enabled, false);
|
||||
assert!(!enabled);
|
||||
} else {
|
||||
panic!("Expected SetCwDecodeEnabled");
|
||||
}
|
||||
@@ -223,7 +223,7 @@ mod tests {
|
||||
fn test_client_command_to_rig_set_cw_auto() {
|
||||
let cmd = ClientCommand::SetCwAuto { enabled: true };
|
||||
if let RigCommand::SetCwAuto(enabled) = client_command_to_rig(cmd) {
|
||||
assert_eq!(enabled, true);
|
||||
assert!(enabled);
|
||||
} else {
|
||||
panic!("Expected SetCwAuto");
|
||||
}
|
||||
@@ -253,7 +253,7 @@ mod tests {
|
||||
fn test_client_command_to_rig_set_ft8_decode_enabled() {
|
||||
let cmd = ClientCommand::SetFt8DecodeEnabled { enabled: true };
|
||||
if let RigCommand::SetFt8DecodeEnabled(enabled) = client_command_to_rig(cmd) {
|
||||
assert_eq!(enabled, true);
|
||||
assert!(enabled);
|
||||
} else {
|
||||
panic!("Expected SetFt8DecodeEnabled");
|
||||
}
|
||||
@@ -333,7 +333,7 @@ mod tests {
|
||||
fn test_rig_command_to_client_set_ptt() {
|
||||
let cmd = RigCommand::SetPtt(true);
|
||||
if let ClientCommand::SetPtt { ptt } = rig_command_to_client(cmd) {
|
||||
assert_eq!(ptt, true);
|
||||
assert!(ptt);
|
||||
} else {
|
||||
panic!("Expected SetPtt");
|
||||
}
|
||||
@@ -413,7 +413,7 @@ mod tests {
|
||||
fn test_rig_command_to_client_set_aprs_decode_enabled() {
|
||||
let cmd = RigCommand::SetAprsDecodeEnabled(true);
|
||||
if let ClientCommand::SetAprsDecodeEnabled { enabled } = rig_command_to_client(cmd) {
|
||||
assert_eq!(enabled, true);
|
||||
assert!(enabled);
|
||||
} else {
|
||||
panic!("Expected SetAprsDecodeEnabled");
|
||||
}
|
||||
@@ -423,7 +423,7 @@ mod tests {
|
||||
fn test_rig_command_to_client_set_cw_decode_enabled() {
|
||||
let cmd = RigCommand::SetCwDecodeEnabled(false);
|
||||
if let ClientCommand::SetCwDecodeEnabled { enabled } = rig_command_to_client(cmd) {
|
||||
assert_eq!(enabled, false);
|
||||
assert!(!enabled);
|
||||
} else {
|
||||
panic!("Expected SetCwDecodeEnabled");
|
||||
}
|
||||
@@ -433,7 +433,7 @@ mod tests {
|
||||
fn test_rig_command_to_client_set_cw_auto() {
|
||||
let cmd = RigCommand::SetCwAuto(true);
|
||||
if let ClientCommand::SetCwAuto { enabled } = rig_command_to_client(cmd) {
|
||||
assert_eq!(enabled, true);
|
||||
assert!(enabled);
|
||||
} else {
|
||||
panic!("Expected SetCwAuto");
|
||||
}
|
||||
@@ -463,7 +463,7 @@ mod tests {
|
||||
fn test_rig_command_to_client_set_ft8_decode_enabled() {
|
||||
let cmd = RigCommand::SetFt8DecodeEnabled(true);
|
||||
if let ClientCommand::SetFt8DecodeEnabled { enabled } = rig_command_to_client(cmd) {
|
||||
assert_eq!(enabled, true);
|
||||
assert!(enabled);
|
||||
} else {
|
||||
panic!("Expected SetFt8DecodeEnabled");
|
||||
}
|
||||
@@ -534,7 +534,7 @@ mod tests {
|
||||
let client_cmd = rig_command_to_client(rig_cmd);
|
||||
|
||||
if let ClientCommand::SetPtt { ptt } = client_cmd {
|
||||
assert_eq!(ptt, false);
|
||||
assert!(!ptt);
|
||||
} else {
|
||||
panic!("Round trip failed");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
// SPDX-FileCopyrightText: 2025 Stanislaw Grams <stanislawgrams@gmail.com>
|
||||
//
|
||||
// SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
//! Transport DTOs for the JSON line protocol.
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use trx_core::rig::state::RigSnapshot;
|
||||
|
||||
/// Command received from network clients (JSON).
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(tag = "cmd", rename_all = "snake_case")]
|
||||
pub enum ClientCommand {
|
||||
GetState,
|
||||
SetFreq { freq_hz: u64 },
|
||||
SetMode { mode: String },
|
||||
SetPtt { ptt: bool },
|
||||
PowerOn,
|
||||
PowerOff,
|
||||
ToggleVfo,
|
||||
Lock,
|
||||
Unlock,
|
||||
GetTxLimit,
|
||||
SetTxLimit { limit: u8 },
|
||||
SetAprsDecodeEnabled { enabled: bool },
|
||||
SetCwDecodeEnabled { enabled: bool },
|
||||
SetCwAuto { enabled: bool },
|
||||
SetCwWpm { wpm: u32 },
|
||||
SetCwToneHz { tone_hz: u32 },
|
||||
SetFt8DecodeEnabled { enabled: bool },
|
||||
ResetAprsDecoder,
|
||||
ResetCwDecoder,
|
||||
ResetFt8Decoder,
|
||||
}
|
||||
|
||||
/// Envelope for client commands with optional authentication token.
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct ClientEnvelope {
|
||||
pub token: Option<String>,
|
||||
#[serde(flatten)]
|
||||
pub cmd: ClientCommand,
|
||||
}
|
||||
|
||||
/// Response sent to network clients over TCP.
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct ClientResponse {
|
||||
pub success: bool,
|
||||
pub state: Option<RigSnapshot>,
|
||||
pub error: Option<String>,
|
||||
}
|
||||
Reference in New Issue
Block a user