[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:
@@ -10,11 +10,11 @@ use tokio::sync::{mpsc, watch};
|
|||||||
use tokio::time::{self, Instant};
|
use tokio::time::{self, Instant};
|
||||||
use tracing::{info, warn};
|
use tracing::{info, warn};
|
||||||
|
|
||||||
use trx_core::client::{ClientCommand, ClientEnvelope, ClientResponse};
|
|
||||||
use trx_core::rig::request::RigRequest;
|
use trx_core::rig::request::RigRequest;
|
||||||
use trx_core::rig::state::RigState;
|
use trx_core::rig::state::RigState;
|
||||||
use trx_core::{RigError, RigResult};
|
use trx_core::{RigError, RigResult};
|
||||||
use trx_protocol::rig_command_to_client;
|
use trx_protocol::rig_command_to_client;
|
||||||
|
use trx_protocol::{ClientCommand, ClientEnvelope, ClientResponse};
|
||||||
|
|
||||||
pub struct RemoteClientConfig {
|
pub struct RemoteClientConfig {
|
||||||
pub addr: String,
|
pub addr: String,
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ edition = "2021"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
trx-core = { path = "../../../trx-core" }
|
trx-core = { path = "../../../trx-core" }
|
||||||
trx-frontend = { path = ".." }
|
trx-frontend = { path = ".." }
|
||||||
|
trx-protocol = { path = "../../../../src/trx-protocol" }
|
||||||
tokio = { workspace = true, features = ["full"] }
|
tokio = { workspace = true, features = ["full"] }
|
||||||
serde = { workspace = true, features = ["derive"] }
|
serde = { workspace = true, features = ["derive"] }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
|
|||||||
@@ -12,3 +12,4 @@ tokio = { workspace = true, features = ["full"] }
|
|||||||
tracing = { workspace = true }
|
tracing = { workspace = true }
|
||||||
trx-core = { path = "../../../trx-core" }
|
trx-core = { path = "../../../trx-core" }
|
||||||
trx-frontend = { path = ".." }
|
trx-frontend = { path = ".." }
|
||||||
|
trx-protocol = { path = "../../../../src/trx-protocol" }
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ use tokio::sync::{mpsc, oneshot, watch};
|
|||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
use tokio::time::timeout;
|
use tokio::time::timeout;
|
||||||
use tracing::{debug, error, info, warn};
|
use tracing::{debug, error, info, warn};
|
||||||
|
use trx_protocol::{mode_to_string, parse_mode};
|
||||||
|
|
||||||
use trx_core::radio::freq::Freq;
|
use trx_core::radio::freq::Freq;
|
||||||
use trx_core::rig::state::RigSnapshot;
|
use trx_core::rig::state::RigSnapshot;
|
||||||
@@ -252,26 +253,8 @@ fn current_snapshot(state_rx: &watch::Receiver<RigState>) -> Option<RigSnapshot>
|
|||||||
state_rx.borrow().snapshot()
|
state_rx.borrow().snapshot()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_mode(s: &str) -> RigMode {
|
|
||||||
match s.to_ascii_uppercase().as_str() {
|
|
||||||
"LSB" => RigMode::LSB,
|
|
||||||
"USB" => RigMode::USB,
|
|
||||||
"CW" => RigMode::CW,
|
|
||||||
"CWR" => RigMode::CWR,
|
|
||||||
"AM" => RigMode::AM,
|
|
||||||
"FM" => RigMode::FM,
|
|
||||||
"WFM" => RigMode::WFM,
|
|
||||||
"DIG" | "DIGI" => RigMode::DIG,
|
|
||||||
"PKT" | "PACKET" => RigMode::PKT,
|
|
||||||
other => RigMode::Other(other.to_string()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rig_mode_to_str(mode: &RigMode) -> String {
|
fn rig_mode_to_str(mode: &RigMode) -> String {
|
||||||
match mode {
|
mode_to_string(mode)
|
||||||
RigMode::Other(other) => other.clone(),
|
|
||||||
other => format!("{:?}", other),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dump_state_lines(_snapshot: &RigSnapshot) -> Vec<String> {
|
fn dump_state_lines(_snapshot: &RigSnapshot) -> Vec<String> {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// SPDX-License-Identifier: BSD-2-Clause
|
// SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
|
||||||
pub mod audio;
|
pub mod audio;
|
||||||
pub mod client;
|
|
||||||
pub mod decode;
|
pub mod decode;
|
||||||
pub mod math;
|
pub mod math;
|
||||||
pub mod radio;
|
pub mod radio;
|
||||||
@@ -11,7 +10,6 @@ pub mod rig;
|
|||||||
|
|
||||||
pub type DynResult<T> = Result<T, Box<dyn std::error::Error + Send + Sync>>;
|
pub type DynResult<T> = Result<T, Box<dyn std::error::Error + Send + Sync>>;
|
||||||
|
|
||||||
pub use client::{ClientCommand, ClientResponse};
|
|
||||||
pub use rig::command::RigCommand;
|
pub use rig::command::RigCommand;
|
||||||
pub use rig::request::RigRequest;
|
pub use rig::request::RigRequest;
|
||||||
pub use rig::response::{RigError, RigResult};
|
pub use rig::response::{RigError, RigResult};
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
use serde_json;
|
use serde_json;
|
||||||
|
|
||||||
use trx_core::client::{ClientCommand, ClientEnvelope};
|
|
||||||
use trx_core::rig::state::RigMode;
|
use trx_core::rig::state::RigMode;
|
||||||
|
use crate::types::{ClientCommand, ClientEnvelope};
|
||||||
|
|
||||||
/// Parse a mode string into a RigMode.
|
/// Parse a mode string into a RigMode.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -10,8 +10,10 @@
|
|||||||
pub mod auth;
|
pub mod auth;
|
||||||
pub mod codec;
|
pub mod codec;
|
||||||
pub mod mapping;
|
pub mod mapping;
|
||||||
|
pub mod types;
|
||||||
|
|
||||||
// Re-export commonly used items
|
// Re-export commonly used items
|
||||||
pub use auth::{NoAuthValidator, SimpleTokenValidator, TokenValidator};
|
pub use auth::{NoAuthValidator, SimpleTokenValidator, TokenValidator};
|
||||||
pub use codec::{mode_to_string, parse_envelope, parse_mode};
|
pub use codec::{mode_to_string, parse_envelope, parse_mode};
|
||||||
pub use mapping::{client_command_to_rig, rig_command_to_client};
|
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::radio::freq::Freq;
|
||||||
use trx_core::rig::command::RigCommand;
|
use trx_core::rig::command::RigCommand;
|
||||||
use trx_core::ClientCommand;
|
|
||||||
|
|
||||||
use crate::codec::{mode_to_string, parse_mode};
|
use crate::codec::{mode_to_string, parse_mode};
|
||||||
|
use crate::types::ClientCommand;
|
||||||
|
|
||||||
/// Convert a ClientCommand to a RigCommand.
|
/// Convert a ClientCommand to a RigCommand.
|
||||||
///
|
///
|
||||||
@@ -123,7 +123,7 @@ mod tests {
|
|||||||
fn test_client_command_to_rig_set_ptt() {
|
fn test_client_command_to_rig_set_ptt() {
|
||||||
let cmd = ClientCommand::SetPtt { ptt: true };
|
let cmd = ClientCommand::SetPtt { ptt: true };
|
||||||
if let RigCommand::SetPtt(ptt) = client_command_to_rig(cmd) {
|
if let RigCommand::SetPtt(ptt) = client_command_to_rig(cmd) {
|
||||||
assert_eq!(ptt, true);
|
assert!(ptt);
|
||||||
} else {
|
} else {
|
||||||
panic!("Expected SetPtt");
|
panic!("Expected SetPtt");
|
||||||
}
|
}
|
||||||
@@ -203,7 +203,7 @@ mod tests {
|
|||||||
fn test_client_command_to_rig_set_aprs_decode_enabled() {
|
fn test_client_command_to_rig_set_aprs_decode_enabled() {
|
||||||
let cmd = ClientCommand::SetAprsDecodeEnabled { enabled: true };
|
let cmd = ClientCommand::SetAprsDecodeEnabled { enabled: true };
|
||||||
if let RigCommand::SetAprsDecodeEnabled(enabled) = client_command_to_rig(cmd) {
|
if let RigCommand::SetAprsDecodeEnabled(enabled) = client_command_to_rig(cmd) {
|
||||||
assert_eq!(enabled, true);
|
assert!(enabled);
|
||||||
} else {
|
} else {
|
||||||
panic!("Expected SetAprsDecodeEnabled");
|
panic!("Expected SetAprsDecodeEnabled");
|
||||||
}
|
}
|
||||||
@@ -213,7 +213,7 @@ mod tests {
|
|||||||
fn test_client_command_to_rig_set_cw_decode_enabled() {
|
fn test_client_command_to_rig_set_cw_decode_enabled() {
|
||||||
let cmd = ClientCommand::SetCwDecodeEnabled { enabled: false };
|
let cmd = ClientCommand::SetCwDecodeEnabled { enabled: false };
|
||||||
if let RigCommand::SetCwDecodeEnabled(enabled) = client_command_to_rig(cmd) {
|
if let RigCommand::SetCwDecodeEnabled(enabled) = client_command_to_rig(cmd) {
|
||||||
assert_eq!(enabled, false);
|
assert!(!enabled);
|
||||||
} else {
|
} else {
|
||||||
panic!("Expected SetCwDecodeEnabled");
|
panic!("Expected SetCwDecodeEnabled");
|
||||||
}
|
}
|
||||||
@@ -223,7 +223,7 @@ mod tests {
|
|||||||
fn test_client_command_to_rig_set_cw_auto() {
|
fn test_client_command_to_rig_set_cw_auto() {
|
||||||
let cmd = ClientCommand::SetCwAuto { enabled: true };
|
let cmd = ClientCommand::SetCwAuto { enabled: true };
|
||||||
if let RigCommand::SetCwAuto(enabled) = client_command_to_rig(cmd) {
|
if let RigCommand::SetCwAuto(enabled) = client_command_to_rig(cmd) {
|
||||||
assert_eq!(enabled, true);
|
assert!(enabled);
|
||||||
} else {
|
} else {
|
||||||
panic!("Expected SetCwAuto");
|
panic!("Expected SetCwAuto");
|
||||||
}
|
}
|
||||||
@@ -253,7 +253,7 @@ mod tests {
|
|||||||
fn test_client_command_to_rig_set_ft8_decode_enabled() {
|
fn test_client_command_to_rig_set_ft8_decode_enabled() {
|
||||||
let cmd = ClientCommand::SetFt8DecodeEnabled { enabled: true };
|
let cmd = ClientCommand::SetFt8DecodeEnabled { enabled: true };
|
||||||
if let RigCommand::SetFt8DecodeEnabled(enabled) = client_command_to_rig(cmd) {
|
if let RigCommand::SetFt8DecodeEnabled(enabled) = client_command_to_rig(cmd) {
|
||||||
assert_eq!(enabled, true);
|
assert!(enabled);
|
||||||
} else {
|
} else {
|
||||||
panic!("Expected SetFt8DecodeEnabled");
|
panic!("Expected SetFt8DecodeEnabled");
|
||||||
}
|
}
|
||||||
@@ -333,7 +333,7 @@ mod tests {
|
|||||||
fn test_rig_command_to_client_set_ptt() {
|
fn test_rig_command_to_client_set_ptt() {
|
||||||
let cmd = RigCommand::SetPtt(true);
|
let cmd = RigCommand::SetPtt(true);
|
||||||
if let ClientCommand::SetPtt { ptt } = rig_command_to_client(cmd) {
|
if let ClientCommand::SetPtt { ptt } = rig_command_to_client(cmd) {
|
||||||
assert_eq!(ptt, true);
|
assert!(ptt);
|
||||||
} else {
|
} else {
|
||||||
panic!("Expected SetPtt");
|
panic!("Expected SetPtt");
|
||||||
}
|
}
|
||||||
@@ -413,7 +413,7 @@ mod tests {
|
|||||||
fn test_rig_command_to_client_set_aprs_decode_enabled() {
|
fn test_rig_command_to_client_set_aprs_decode_enabled() {
|
||||||
let cmd = RigCommand::SetAprsDecodeEnabled(true);
|
let cmd = RigCommand::SetAprsDecodeEnabled(true);
|
||||||
if let ClientCommand::SetAprsDecodeEnabled { enabled } = rig_command_to_client(cmd) {
|
if let ClientCommand::SetAprsDecodeEnabled { enabled } = rig_command_to_client(cmd) {
|
||||||
assert_eq!(enabled, true);
|
assert!(enabled);
|
||||||
} else {
|
} else {
|
||||||
panic!("Expected SetAprsDecodeEnabled");
|
panic!("Expected SetAprsDecodeEnabled");
|
||||||
}
|
}
|
||||||
@@ -423,7 +423,7 @@ mod tests {
|
|||||||
fn test_rig_command_to_client_set_cw_decode_enabled() {
|
fn test_rig_command_to_client_set_cw_decode_enabled() {
|
||||||
let cmd = RigCommand::SetCwDecodeEnabled(false);
|
let cmd = RigCommand::SetCwDecodeEnabled(false);
|
||||||
if let ClientCommand::SetCwDecodeEnabled { enabled } = rig_command_to_client(cmd) {
|
if let ClientCommand::SetCwDecodeEnabled { enabled } = rig_command_to_client(cmd) {
|
||||||
assert_eq!(enabled, false);
|
assert!(!enabled);
|
||||||
} else {
|
} else {
|
||||||
panic!("Expected SetCwDecodeEnabled");
|
panic!("Expected SetCwDecodeEnabled");
|
||||||
}
|
}
|
||||||
@@ -433,7 +433,7 @@ mod tests {
|
|||||||
fn test_rig_command_to_client_set_cw_auto() {
|
fn test_rig_command_to_client_set_cw_auto() {
|
||||||
let cmd = RigCommand::SetCwAuto(true);
|
let cmd = RigCommand::SetCwAuto(true);
|
||||||
if let ClientCommand::SetCwAuto { enabled } = rig_command_to_client(cmd) {
|
if let ClientCommand::SetCwAuto { enabled } = rig_command_to_client(cmd) {
|
||||||
assert_eq!(enabled, true);
|
assert!(enabled);
|
||||||
} else {
|
} else {
|
||||||
panic!("Expected SetCwAuto");
|
panic!("Expected SetCwAuto");
|
||||||
}
|
}
|
||||||
@@ -463,7 +463,7 @@ mod tests {
|
|||||||
fn test_rig_command_to_client_set_ft8_decode_enabled() {
|
fn test_rig_command_to_client_set_ft8_decode_enabled() {
|
||||||
let cmd = RigCommand::SetFt8DecodeEnabled(true);
|
let cmd = RigCommand::SetFt8DecodeEnabled(true);
|
||||||
if let ClientCommand::SetFt8DecodeEnabled { enabled } = rig_command_to_client(cmd) {
|
if let ClientCommand::SetFt8DecodeEnabled { enabled } = rig_command_to_client(cmd) {
|
||||||
assert_eq!(enabled, true);
|
assert!(enabled);
|
||||||
} else {
|
} else {
|
||||||
panic!("Expected SetFt8DecodeEnabled");
|
panic!("Expected SetFt8DecodeEnabled");
|
||||||
}
|
}
|
||||||
@@ -534,7 +534,7 @@ mod tests {
|
|||||||
let client_cmd = rig_command_to_client(rig_cmd);
|
let client_cmd = rig_command_to_client(rig_cmd);
|
||||||
|
|
||||||
if let ClientCommand::SetPtt { ptt } = client_cmd {
|
if let ClientCommand::SetPtt { ptt } = client_cmd {
|
||||||
assert_eq!(ptt, false);
|
assert!(!ptt);
|
||||||
} else {
|
} else {
|
||||||
panic!("Round trip failed");
|
panic!("Round trip failed");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,11 @@
|
|||||||
//
|
//
|
||||||
// SPDX-License-Identifier: BSD-2-Clause
|
// SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
|
||||||
|
//! Transport DTOs for the JSON line protocol.
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::rig::state::RigSnapshot;
|
use trx_core::rig::state::RigSnapshot;
|
||||||
|
|
||||||
/// Command received from network clients (JSON).
|
/// Command received from network clients (JSON).
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
//! JSON-over-TCP listener for trx-server.
|
//! JSON-over-TCP listener for trx-server.
|
||||||
//!
|
//!
|
||||||
//! Accepts client connections speaking the `ClientEnvelope`/`ClientResponse`
|
//! Accepts client connections speaking the `ClientEnvelope`/`ClientResponse`
|
||||||
//! protocol defined in `trx-core::client`.
|
//! protocol defined in `trx-protocol`.
|
||||||
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
@@ -19,11 +19,10 @@ use tracing::{error, info};
|
|||||||
use trx_core::rig::command::RigCommand;
|
use trx_core::rig::command::RigCommand;
|
||||||
use trx_core::rig::request::RigRequest;
|
use trx_core::rig::request::RigRequest;
|
||||||
use trx_core::rig::state::RigState;
|
use trx_core::rig::state::RigState;
|
||||||
use trx_core::ClientResponse;
|
|
||||||
|
|
||||||
use trx_protocol::codec::parse_envelope;
|
|
||||||
use trx_protocol::auth::{SimpleTokenValidator, TokenValidator};
|
use trx_protocol::auth::{SimpleTokenValidator, TokenValidator};
|
||||||
|
use trx_protocol::codec::parse_envelope;
|
||||||
use trx_protocol::mapping;
|
use trx_protocol::mapping;
|
||||||
|
use trx_protocol::ClientResponse;
|
||||||
|
|
||||||
/// Run the JSON TCP listener, accepting client connections.
|
/// Run the JSON TCP listener, accepting client connections.
|
||||||
pub async fn run_listener(
|
pub async fn run_listener(
|
||||||
@@ -179,4 +178,3 @@ async fn handle_client(
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user