Skip to main content

mx_remote/runtime/
info.rs

1// Author: Lars Op den Kamp (lars@opdenkamp-it.nl)
2// Copyright (c) 2026 Op den Kamp IT Solutions
3
4//! Snapshots of a device and of a bay.
5//!
6//! State lives behind a lock and is read by the receive thread, so a caller is
7//! handed a copy rather than a borrow of it. The copy also matches how the C
8//! ABI reads state: a uid in, a struct filled out.
9
10use std::net::Ipv4Addr;
11use std::time::Instant;
12
13use crate::state::{Bay, Device, State};
14use crate::types::{
15    AmpZoneSettings, ArcStatus, BayMirrorStatus, BaySignalDetails, DeviceStatus, PowerStatus,
16    VolumeMuteStatus,
17};
18use crate::wire::{
19    BayFeatures, BayUid, DeviceFeature, DeviceUid, EdidProfile, MxrSignalType, RcType,
20};
21
22/// What a device is, and what it is doing.
23#[derive(Clone, Debug, PartialEq, Eq)]
24#[non_exhaustive]
25pub struct DeviceInfo {
26    /// The device's unique identifier.
27    pub uid: DeviceUid,
28    /// The name the device advertises, or `Unknown` before it has said.
29    pub name: String,
30    /// Serial number, or `Unknown` before the device has said.
31    pub serial: String,
32    /// A friendly model name derived from the advertised name and the bays the
33    /// device reports.
34    pub model: String,
35    /// Firmware version string from the hello frame.
36    pub version: String,
37    /// The highest protocol version the device can decode, or zero before it
38    /// has said.
39    pub supported_protocol: u16,
40    /// What the device says it can do.
41    pub features: DeviceFeature,
42    /// The address the device was last heard from.
43    pub address: Option<Ipv4Addr>,
44    /// Online, offline, booting or rebooting.
45    pub status: DeviceStatus,
46    /// Whether the device has been heard from recently enough to count as
47    /// present.
48    pub online: bool,
49    /// Whether every part of the device's configuration has arrived.
50    ///
51    /// A device that withholds its link configuration is reported complete
52    /// fifteen seconds after it was discovered, and keeps being asked for the
53    /// rest: an unreported link reads as no link, which is what a link coming
54    /// up later looks like anyway. Its bays, and a V2IP device's source list,
55    /// are waited for without limit - a caller names things after a bay, and a
56    /// name assigned to a placeholder outlives the frame that would have
57    /// corrected it. A management client has none of these to send and is
58    /// complete from its hello.
59    pub configuration_complete: bool,
60    /// Whether the device's firmware initialises the configuration it
61    /// broadcasts.
62    ///
63    /// Firmware without it builds some frames over uninitialised stack, so
64    /// those fields carry noise rather than values: the scaling flags and,
65    /// behind a spuriously set valid bit, the scaling mode and refresh; bay 0's
66    /// addresses in the V2IP sources frame; and the padding beside the
67    /// remote-control target.
68    pub config_initialised: bool,
69    /// Temperatures the device reports, in degrees Celsius, in its own order.
70    pub temperatures: Vec<u8>,
71    /// The mesh master this device follows, or the zero uid when it is in no
72    /// mesh.
73    pub mesh_master: DeviceUid,
74    /// How many HDBaseT outputs this model has.
75    pub hdbt_outputs: u8,
76    /// Whether installation was marked complete, `None` before the device
77    /// has said.
78    pub setup_done: Option<bool>,
79    /// The installer identifier the device carries, if it has reported one.
80    pub installer_id: Option<u16>,
81    /// A status code and message the device reports about itself.
82    pub system_status: Option<(u16, String)>,
83    /// Every bay on the device, in port order.
84    pub bays: Vec<BayUid>,
85}
86
87impl DeviceInfo {
88    pub(crate) fn of(device: &Device, now: Instant) -> Self {
89        Self {
90            uid: device.uid,
91            name: device.name().to_owned(),
92            serial: device.serial().to_owned(),
93            model: device.model_name().to_owned(),
94            version: device.hello.version.clone(),
95            supported_protocol: device.hello.supported_protocol,
96            features: device.hello.features,
97            address: device.hello.address,
98            status: device.status(now),
99            online: device.is_online(now),
100            configuration_complete: device.configuration_complete(now),
101            config_initialised: device.config_initialised(),
102            temperatures: device.temperatures.clone(),
103            mesh_master: device.mesh_master,
104            hdbt_outputs: device.hdbt_outputs(),
105            setup_done: device.setup_done,
106            installer_id: device.installer_id,
107            system_status: device.sys_status.clone(),
108            bays: device.bays.values().map(Bay::uid).collect(),
109        }
110    }
111}
112
113/// What a bay is, and what is connected to it.
114///
115/// A status this bay has never reported is `None`, which is not the same as
116/// the status being off: a device reports only what it has.
117#[derive(Clone, Debug, PartialEq)]
118#[non_exhaustive]
119pub struct BayInfo {
120    /// How the bay is addressed: its device and its port.
121    pub uid: BayUid,
122    /// The name the device gives the port, such as `Output 1`.
123    pub port_name: String,
124    /// The name the installer gave the bay, falling back to the port name.
125    pub user_name: String,
126    /// The bay number the device's own API and topology use.
127    pub bay_num: u8,
128    /// What the bay is wired for.
129    pub features: BayFeatures,
130    /// Whether the bay takes a signal in.
131    pub is_input: bool,
132    /// Whether the bay puts a signal out.
133    pub is_output: bool,
134    /// Whether the bay carries audio and no video.
135    pub is_audio: bool,
136    /// Whether the bay can decode Dolby.
137    pub has_dolby: bool,
138    /// Whether the bay is on this device rather than reached through the mesh.
139    pub is_local: bool,
140    /// The bay routed to this one for video.
141    pub video_source: Option<BayUid>,
142    /// The bay routed to this one for audio, which follows the video source
143    /// until the bay is told otherwise.
144    pub audio_source: Option<BayUid>,
145    /// Power state of what is connected.
146    pub power_status: Option<PowerStatus>,
147    /// Whether the bay is hidden from the installation's user interface.
148    pub hidden: Option<bool>,
149    /// Whether the device reports the bay as faulty.
150    pub faulty: Option<bool>,
151    /// Whether the bay is delivering power over the link.
152    pub poe_powered: Option<bool>,
153    /// Whether an HDBaseT link is up.
154    pub hdbt_connected: Option<bool>,
155    /// Whether a signal is present.
156    pub signal_detected: Option<bool>,
157    /// Whether hot-plug detect is asserted.
158    pub hpd_detected: Option<bool>,
159    /// Whether a CEC device answered.
160    pub cec_detected: Option<bool>,
161    /// Whether the bay's encoder is switched off.
162    pub encoder_disabled: Option<bool>,
163    /// Whether the bay's decoder is switched off.
164    pub decoder_disabled: Option<bool>,
165    /// The signal as the device describes it, such as `1080p60 444 8`.
166    pub signal_type: Option<String>,
167    /// The signal as the device measures it.
168    pub signal_details: Option<BaySignalDetails>,
169    /// The signal format the device reports for the bay.
170    pub signal_mode: MxrSignalType,
171    /// Whether audio return is active, and over which connector.
172    pub arc: ArcStatus,
173    /// Volume and mute, for a bay that has them.
174    ///
175    /// A bay with no volume control of its own reads its
176    /// [`linked_bay`](BayInfo::linked_bay)'s, because a link to an amplifier
177    /// zone is how the mesh says that zone is this bay's volume.
178    pub volume: Option<VolumeMuteStatus>,
179    /// The kind of remote control attached.
180    pub rc_type: Option<RcType>,
181    /// The EDID profile the bay presents.
182    pub edid_profile: Option<EdidProfile>,
183    /// Which bay this one mirrors, if any.
184    pub mirror: BayMirrorStatus,
185    /// The audio endpoint this bay feeds, on a device that has them.
186    pub audio_endpoint: Option<u8>,
187    /// Amplifier settings, on an amplifier zone.
188    pub amp_settings: Option<AmpZoneSettings>,
189    /// Devices whose signals this bay refuses.
190    pub filtered: Vec<DeviceUid>,
191    /// The bay on another device this one is linked to, once that bay has been
192    /// discovered.
193    ///
194    /// A link is mesh configuration rather than a route: it names the bay
195    /// elsewhere that belongs to this one, such as the amplifier zone carrying
196    /// a OneIP output's volume. [`BayInfo::volume`] is already read through it.
197    pub linked_bay: Option<BayUid>,
198    /// The source device a V2IP bay maps to, or the zero uid.
199    pub v2ip_uid: DeviceUid,
200}
201
202impl BayInfo {
203    pub(crate) fn of(state: &State, bay: &Bay) -> Self {
204        Self {
205            uid: bay.uid(),
206            port_name: bay.port_name.clone(),
207            user_name: bay.user_name().to_owned(),
208            bay_num: bay.bay_num(),
209            features: bay.features,
210            is_input: bay.is_input(),
211            is_output: bay.is_output(),
212            is_audio: bay.is_audio(),
213            has_dolby: bay.has_dolby(),
214            is_local: bay.is_local(),
215            video_source: bay.video_source,
216            audio_source: bay.effective_audio_source(),
217            power_status: bay.power_status,
218            hidden: bay.hidden,
219            faulty: bay.faulty,
220            poe_powered: bay.poe_powered,
221            hdbt_connected: bay.hdbt_connected,
222            signal_detected: bay.signal_detected,
223            hpd_detected: bay.hpd_detected,
224            cec_detected: bay.cec_detected,
225            encoder_disabled: bay.encoder_disabled,
226            decoder_disabled: bay.decoder_disabled,
227            signal_type: bay.signal_type.clone(),
228            signal_details: bay.signal_details,
229            signal_mode: bay.signal_mode,
230            arc: bay.arc,
231            volume: state
232                .bay(state.volume_bay(bay.uid()))
233                .and_then(|b| b.audio_volume),
234            rc_type: bay.rc_type,
235            edid_profile: bay.edid_profile,
236            mirror: bay.mirror,
237            audio_endpoint: bay.audio_endpoint,
238            amp_settings: bay.amp_settings,
239            filtered: bay.filtered.clone(),
240            linked_bay: state.linked_bay(bay.uid()),
241            v2ip_uid: bay.v2ip_uid,
242        }
243    }
244}