pub mod command_sender;
pub mod event_loop_state;
pub mod rx_dispatcher;
pub mod ww;
pub use command_sender::CommandSender;
use std::net::IpAddr;
pub use ww_client_server;
pub use ww_version;
use ww_version::FullVersionOwned;
use std::time::Duration;
use tokio::sync::{mpsc, oneshot};
use ww_client_server::StreamSidebandEvent;
pub enum Command {
Connect {
filter: DeviceFilter,
user_protocol_version: FullVersionOwned,
on_error: OnError,
connected_tx: Option<oneshot::Sender<Result<(), Error>>>,
},
DisconnectKeepStreams {
disconnected_tx: Option<oneshot::Sender<()>>,
},
DisconnectAndExit {
disconnected_tx: Option<oneshot::Sender<()>>,
},
SendMessage {
bytes: Vec<u8>,
},
LoopbackTest {
test_duration: Duration,
packet_size: Option<usize>,
progress_tx: mpsc::UnboundedSender<TestProgress>,
},
}
pub type SeqTy = u16;
const DEFAULT_REQUEST_TIMEOUT: Duration = Duration::from_secs(1);
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("Called a method that required event loop to be running")]
EventLoopNotRunning,
#[error("RX dispatcher exited due to previous error, cannot operate without it")]
RxDispatcherNotRunning,
#[error("No devices found to connect to")]
DeviceNotFound,
#[error("Timeout")]
Timeout,
#[error("LinkSetup was not received from device after several retries")]
LinkSetupTimeout,
#[error("shrink_wrap::Error {:?}", .0)]
ShrinkWrap(wire_weaver::shrink_wrap::Error),
#[error("Tried connecting to a device with incompatible protocol")]
IncompatibleDeviceProtocol,
#[error("Submitted a command requiring active connection, when there was none")]
Disconnected,
#[error("Remote device returned ww_client_server::Error: {:?}", .0)]
RemoteError(ww_client_server::Error),
#[error("All command senders were dropped")]
CmdTxDropped,
#[error("Exit command received")]
ExitRequested,
#[error("Transport specific error: {}", .0)]
Transport(String),
#[error("User error {}", .0)]
User(String),
#[error("User error {}", .0)]
Other(String),
}
impl From<wire_weaver::shrink_wrap::Error> for Error {
fn from(e: wire_weaver::shrink_wrap::Error) -> Self {
Error::ShrinkWrap(e)
}
}
#[derive(Copy, Clone, PartialEq, Eq)]
pub enum OnError {
ExitImmediately,
RetryFor {
timeout: Duration,
},
KeepRetrying,
}
impl OnError {
pub fn retry_for_secs(secs: u64) -> Self {
Self::RetryFor {
timeout: Duration::from_secs(secs),
}
}
}
impl Command {
pub fn disconnect_and_exit() -> (Self, oneshot::Receiver<()>) {
let (tx, rx) = oneshot::channel();
let cmd = Command::DisconnectAndExit {
disconnected_tx: Some(tx),
};
(cmd, rx)
}
}
#[derive(Clone, Debug)]
pub enum DeviceFilter {
WebSocket {
addr: IpAddr,
port: u16,
path: String,
},
UDP {
addr: IpAddr,
port: u16,
},
UsbVidPid {
vid: u16,
pid: u16,
},
UsbVidPidAndSerial {
vid: u16,
pid: u16,
serial: String,
},
Serial {
serial: String,
},
AnyVhrdTechCanBus,
AnyVhrdTechIo,
}
#[derive(PartialEq, Eq, Debug, Clone)]
pub enum StreamEvent {
Data(Vec<u8>),
Sideband(StreamSidebandEvent),
Connected,
Disconnected,
}
#[derive(Debug)]
pub enum TestProgress {
TestStarted(&'static str),
Completion(&'static str, f32),
TestCompleted(&'static str),
FatalError(String),
LoopbackReport {
tx_count: u64,
per_s: f32,
lost_count: u64,
data_corrupted_count: u64,
},
SpeedReport {
name: &'static str,
count: u64,
per_s: f32,
bytes_per_s: f32,
},
}