use bytes::BytesMut;
use std::fmt;
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Preamble {
pub version: String,
}
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
pub enum Present {
Yes,
#[default]
No,
NeedsUpdate,
}
impl fmt::Display for Present {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let v = match self {
Present::Yes => "true",
Present::No => "false",
Present::NeedsUpdate => "needs_update",
};
f.write_str(v)
}
}
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct UnknownKVPair {
pub key: String,
pub value: String,
}
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct DeviceInfo {
pub present: Option<Present>,
pub model_name: Option<String>,
pub friendly_name: Option<String>,
pub unique_id: Option<String>,
pub video_inputs: Option<u32>,
pub video_processing_units: Option<u32>,
pub video_outputs: Option<u32>,
pub video_monitoring_outputs: Option<u32>,
pub serial_ports: Option<u32>,
pub unknown_fields: Option<Vec<UnknownKVPair>>,
}
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct Label {
pub id: u32,
pub name: String,
}
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
pub struct Route {
pub from_input: u32,
pub to_output: u32,
}
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
pub enum LockState {
Owned,
Locked,
#[default]
Unlocked,
}
impl fmt::Display for LockState {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let s = match self {
LockState::Owned => "O",
LockState::Locked => "L",
LockState::Unlocked => "U",
};
f.write_str(s)
}
}
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
pub struct Lock {
pub id: u32,
pub state: LockState,
}
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
pub enum SerialPortDirectionState {
Control,
Slave,
#[default]
Auto,
}
impl fmt::Display for SerialPortDirectionState {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let d = match self {
SerialPortDirectionState::Control => "control",
SerialPortDirectionState::Slave => "slave",
SerialPortDirectionState::Auto => "auto",
};
f.write_str(d)
}
}
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
pub struct SerialPortDirection {
pub id: u32,
pub state: SerialPortDirectionState,
}
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub enum HardwarePortType {
#[default]
None,
BNC,
Optical,
Thunderbolt,
RS422,
Other(String),
}
impl fmt::Display for HardwarePortType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
HardwarePortType::Other(s) => f.write_str(s),
_ => fmt::Debug::fmt(self, f),
}
}
}
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct HardwarePort {
pub id: u32,
pub port_type: HardwarePortType,
}
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct Alarm {
pub name: String,
pub status: String,
}
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct Setting {
pub setting: String,
pub value: String,
}
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct UnknownMessage {
pub header: BytesMut,
pub body: BytesMut,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum VideohubMessage {
Preamble(Preamble),
DeviceInfo(DeviceInfo),
InputLabels(Vec<Label>),
OutputLabels(Vec<Label>),
MonitorOutputLabels(Vec<Label>),
SerialPortLabels(Vec<Label>),
FrameLabels(Vec<Label>),
VideoOutputRouting(Vec<Route>),
VideoMonitoringOutputRouting(Vec<Route>),
SerialPortRouting(Vec<Route>),
ProcessingUnitRouting(Vec<Route>),
FrameBufferRouting(Vec<Route>),
VideoOutputLocks(Vec<Lock>),
MonitoringOutputLocks(Vec<Lock>),
SerialPortLocks(Vec<Lock>),
ProcessingUnitLocks(Vec<Lock>),
FrameBufferLocks(Vec<Lock>),
VideoInputStatus(Vec<HardwarePort>),
VideoOutputStatus(Vec<HardwarePort>),
SerialPortStatus(Vec<HardwarePort>),
AlarmStatus(Vec<Alarm>),
Configuration(Vec<Setting>),
ACK,
NAK,
Ping,
EndPrelude,
UnknownMessage(BytesMut, BytesMut),
}