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.
58 pub configuration_complete: bool,
59 /// Whether the device's firmware initialises the configuration it
60 /// broadcasts.
61 ///
62 /// Firmware without it builds some frames over uninitialised stack, so
63 /// those fields carry noise rather than values: the scaling flags and,
64 /// behind a spuriously set valid bit, the scaling mode and refresh; bay 0's
65 /// addresses in the V2IP sources frame; and the padding beside the
66 /// remote-control target.
67 pub config_initialised: bool,
68 /// Temperatures the device reports, in degrees Celsius, in its own order.
69 pub temperatures: Vec<u8>,
70 /// The mesh master this device follows, or the zero uid when it is in no
71 /// mesh.
72 pub mesh_master: DeviceUid,
73 /// How many HDBaseT outputs this model has.
74 pub hdbt_outputs: u8,
75 /// Whether installation was marked complete, `None` before the device
76 /// has said.
77 pub setup_done: Option<bool>,
78 /// The installer identifier the device carries, if it has reported one.
79 pub installer_id: Option<u16>,
80 /// A status code and message the device reports about itself.
81 pub system_status: Option<(u16, String)>,
82 /// Every bay on the device, in port order.
83 pub bays: Vec<BayUid>,
84}
85
86impl DeviceInfo {
87 pub(crate) fn of(device: &Device, now: Instant) -> Self {
88 Self {
89 uid: device.uid,
90 name: device.name().to_owned(),
91 serial: device.serial().to_owned(),
92 model: device.model_name().to_owned(),
93 version: device.hello.version.clone(),
94 supported_protocol: device.hello.supported_protocol,
95 features: device.hello.features,
96 address: device.hello.address,
97 status: device.status(now),
98 online: device.is_online(now),
99 configuration_complete: device.configuration_complete(now),
100 config_initialised: device.config_initialised(),
101 temperatures: device.temperatures.clone(),
102 mesh_master: device.mesh_master,
103 hdbt_outputs: device.hdbt_outputs(),
104 setup_done: device.setup_done,
105 installer_id: device.installer_id,
106 system_status: device.sys_status.clone(),
107 bays: device.bays.values().map(Bay::uid).collect(),
108 }
109 }
110}
111
112/// What a bay is, and what is connected to it.
113///
114/// A status this bay has never reported is `None`, which is not the same as
115/// the status being off: a device reports only what it has.
116#[derive(Clone, Debug, PartialEq)]
117#[non_exhaustive]
118pub struct BayInfo {
119 /// How the bay is addressed: its device and its port.
120 pub uid: BayUid,
121 /// The name the device gives the port, such as `Output 1`.
122 pub port_name: String,
123 /// The name the installer gave the bay, falling back to the port name.
124 pub user_name: String,
125 /// The bay number the device's own API and topology use.
126 pub bay_num: u8,
127 /// What the bay is wired for.
128 pub features: BayFeatures,
129 /// Whether the bay takes a signal in.
130 pub is_input: bool,
131 /// Whether the bay puts a signal out.
132 pub is_output: bool,
133 /// Whether the bay carries audio and no video.
134 pub is_audio: bool,
135 /// Whether the bay can decode Dolby.
136 pub has_dolby: bool,
137 /// Whether the bay is on this device rather than reached through the mesh.
138 pub is_local: bool,
139 /// The bay routed to this one for video.
140 pub video_source: Option<BayUid>,
141 /// The bay routed to this one for audio, which follows the video source
142 /// until the bay is told otherwise.
143 pub audio_source: Option<BayUid>,
144 /// Power state of what is connected.
145 pub power_status: Option<PowerStatus>,
146 /// Whether the bay is hidden from the installation's user interface.
147 pub hidden: Option<bool>,
148 /// Whether the device reports the bay as faulty.
149 pub faulty: Option<bool>,
150 /// Whether the bay is delivering power over the link.
151 pub poe_powered: Option<bool>,
152 /// Whether an HDBaseT link is up.
153 pub hdbt_connected: Option<bool>,
154 /// Whether a signal is present.
155 pub signal_detected: Option<bool>,
156 /// Whether hot-plug detect is asserted.
157 pub hpd_detected: Option<bool>,
158 /// Whether a CEC device answered.
159 pub cec_detected: Option<bool>,
160 /// Whether the bay's encoder is switched off.
161 pub encoder_disabled: Option<bool>,
162 /// Whether the bay's decoder is switched off.
163 pub decoder_disabled: Option<bool>,
164 /// The signal as the device describes it, such as `1080p60 444 8`.
165 pub signal_type: Option<String>,
166 /// The signal as the device measures it.
167 pub signal_details: Option<BaySignalDetails>,
168 /// The signal format the device reports for the bay.
169 pub signal_mode: MxrSignalType,
170 /// Whether audio return is active, and over which connector.
171 pub arc: ArcStatus,
172 /// Volume and mute, for a bay that has them.
173 ///
174 /// A bay with no volume control of its own reads its
175 /// [`linked_bay`](BayInfo::linked_bay)'s, because a link to an amplifier
176 /// zone is how the mesh says that zone is this bay's volume.
177 pub volume: Option<VolumeMuteStatus>,
178 /// The kind of remote control attached.
179 pub rc_type: Option<RcType>,
180 /// The EDID profile the bay presents.
181 pub edid_profile: Option<EdidProfile>,
182 /// Which bay this one mirrors, if any.
183 pub mirror: BayMirrorStatus,
184 /// The audio endpoint this bay feeds, on a device that has them.
185 pub audio_endpoint: Option<u8>,
186 /// Amplifier settings, on an amplifier zone.
187 pub amp_settings: Option<AmpZoneSettings>,
188 /// Devices whose signals this bay refuses.
189 pub filtered: Vec<DeviceUid>,
190 /// The bay on another device this one is linked to, once that bay has been
191 /// discovered.
192 ///
193 /// A link is mesh configuration rather than a route: it names the bay
194 /// elsewhere that belongs to this one, such as the amplifier zone carrying
195 /// a OneIP output's volume. [`BayInfo::volume`] is already read through it.
196 pub linked_bay: Option<BayUid>,
197 /// The source device a V2IP bay maps to, or the zero uid.
198 pub v2ip_uid: DeviceUid,
199}
200
201impl BayInfo {
202 pub(crate) fn of(state: &State, bay: &Bay) -> Self {
203 Self {
204 uid: bay.uid(),
205 port_name: bay.port_name.clone(),
206 user_name: bay.user_name().to_owned(),
207 bay_num: bay.bay_num(),
208 features: bay.features,
209 is_input: bay.is_input(),
210 is_output: bay.is_output(),
211 is_audio: bay.is_audio(),
212 has_dolby: bay.has_dolby(),
213 is_local: bay.is_local(),
214 video_source: bay.video_source,
215 audio_source: bay.effective_audio_source(),
216 power_status: bay.power_status,
217 hidden: bay.hidden,
218 faulty: bay.faulty,
219 poe_powered: bay.poe_powered,
220 hdbt_connected: bay.hdbt_connected,
221 signal_detected: bay.signal_detected,
222 hpd_detected: bay.hpd_detected,
223 cec_detected: bay.cec_detected,
224 encoder_disabled: bay.encoder_disabled,
225 decoder_disabled: bay.decoder_disabled,
226 signal_type: bay.signal_type.clone(),
227 signal_details: bay.signal_details,
228 signal_mode: bay.signal_mode,
229 arc: bay.arc,
230 volume: state
231 .bay(state.volume_bay(bay.uid()))
232 .and_then(|b| b.audio_volume),
233 rc_type: bay.rc_type,
234 edid_profile: bay.edid_profile,
235 mirror: bay.mirror,
236 audio_endpoint: bay.audio_endpoint,
237 amp_settings: bay.amp_settings,
238 filtered: bay.filtered.clone(),
239 linked_bay: state.linked_bay(bay.uid()),
240 v2ip_uid: bay.v2ip_uid,
241 }
242 }
243}