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