mctp/echo: make crate minimal, remove pw refs
diff --git a/services/mctp/echo/BUILD.bazel b/services/mctp/echo/BUILD.bazel index 2a280d1..4cfe7a4 100644 --- a/services/mctp/echo/BUILD.bazel +++ b/services/mctp/echo/BUILD.bazel
@@ -11,7 +11,6 @@ visibility = ["//visibility:public"], deps = [ "//services/mctp/api:mctp_api", - "@pigweed//pw_log/rust:pw_log", ], )
diff --git a/services/mctp/echo/src/lib.rs b/services/mctp/echo/src/lib.rs index 0f811ed..3f5704f 100644 --- a/services/mctp/echo/src/lib.rs +++ b/services/mctp/echo/src/lib.rs
@@ -13,7 +13,7 @@ #![no_std] -use openprot_mctp_api::{MctpClient, MctpError, MctpReqChannel, MctpRespChannel, Stack, StackListener}; +use openprot_mctp_api::{MctpClient, MctpError, MctpRespChannel, Stack, StackListener}; /// Default MCTP message type used by the echo app. pub const ECHO_MSG_TYPE: u8 = 1; @@ -48,75 +48,3 @@ resp.send(msg) } -/// Run the echo loop forever, echoing received messages. -pub fn run<L>(listener: &mut L) -> ! -where - L: openprot_mctp_api::MctpListener, -{ - let mut buf = [0u8; 255]; - loop { - match echo_once(listener, &mut buf) { - Ok(()) => {} - Err(e) => { - if e.code as u32 != 4 { - // Suppress timeout (code 4) errors; only log other errors - pw_log::error!("echo recv failed: code={}", e.code as u32); - } - } - } - } -} - -/// Run the echo loop with periodic sends to a peer endpoint. -/// -/// This variant sends a test message every `send_interval` receive attempts, -/// allowing two passive listeners to bootstrap communication. -pub fn run_with_peer<C: MctpClient, L: openprot_mctp_api::MctpListener>( - stack: &Stack<C>, - peer_eid: u8, - listener: &mut L, -) -> ! { - run_with_peer_round_trip_limit(stack, peer_eid, listener, u32::MAX) -} - -/// Run the echo loop with periodic sends to a peer endpoint, stopping after -/// `max_round_trips` successful request/response exchanges. -pub fn run_with_peer_round_trip_limit<C: MctpClient, L: openprot_mctp_api::MctpListener>( - stack: &Stack<C>, - peer_eid: u8, - listener: &mut L, - max_round_trips: u32, -) -> ! { - let mut buf = [0u8; 255]; - let mut iteration: u32 = 0; - let mut completed_round_trips: u32 = 0; - let send_interval = 10; // Send every 10 iterations - - loop { - iteration = iteration.wrapping_add(1); - - // Periodically try to send a test message to the peer. - if iteration % send_interval == 0 - && completed_round_trips < max_round_trips - && let Ok(mut req) = stack.req(peer_eid, 100) - { - let test_msg = b"echo_test"; - let _ = req.send(ECHO_MSG_TYPE, test_msg); - // Try to receive response with a short timeout. - if req.recv(&mut buf).is_ok() { - completed_round_trips = completed_round_trips.saturating_add(1); - } - } - - // Listen for incoming messages and echo them back. - match echo_once(listener, &mut buf) { - Ok(()) => {} - Err(e) => { - if e.code as u32 != 4 { - // Suppress timeout (code 4) errors; only log other errors - pw_log::error!("echo recv failed: code={}", e.code as u32); - } - } - } - } -}