Support custom ports and all Midra 4K model identities
This commit is contained in:
parent
defc55a73e
commit
ed07d5c00d
|
|
@ -1,10 +1,14 @@
|
|||
//! Eikos snapshots. Explicit layer writes live in `device_send`.
|
||||
//! Midra 4K snapshots. Explicit layer writes live in `device_send`.
|
||||
use crate::{
|
||||
Geometry,
|
||||
import::{DetectedShape, ImportDocument},
|
||||
};
|
||||
use serde_json::Value;
|
||||
use std::{io::Read, net::IpAddr, time::Duration};
|
||||
use std::{
|
||||
io::Read,
|
||||
net::{IpAddr, SocketAddr},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
const MAX_RESPONSE: u64 = 32 * 1024 * 1024;
|
||||
|
||||
|
|
@ -51,9 +55,12 @@ fn number(v: &Value, path: &str) -> Result<f64, String> {
|
|||
impl Snapshot {
|
||||
pub fn parse(identity: &Value, raw: &Value) -> Result<Self, String> {
|
||||
let kind = text(identity, "/type")?;
|
||||
if kind != "Eikos 4K" {
|
||||
if !matches!(
|
||||
kind.as_str(),
|
||||
"Eikos 4K" | "Pulse 4K" | "QuickVu 4K" | "QuickMatrix 4K"
|
||||
) {
|
||||
return Err(format!(
|
||||
"Unsupported device {kind}; this adapter targets Eikos 4K."
|
||||
"Unsupported device {kind}; expected a Midra 4K switcher (Eikos, Pulse, QuickVu or QuickMatrix)."
|
||||
));
|
||||
}
|
||||
let version =
|
||||
|
|
@ -296,16 +303,22 @@ fn read_json(client: &reqwest::blocking::Client, url: &str) -> Result<Value, Str
|
|||
}
|
||||
serde_json::from_slice(&bytes).map_err(|e| format!("Invalid device JSON: {e}"))
|
||||
}
|
||||
/// Perform two GET requests, only on an explicit IP. Call from a worker thread.
|
||||
/// Parse an IP address with an optional TCP port (default 80).
|
||||
/// IPv6 with a port uses bracket notation: `[::1]:3000`.
|
||||
pub fn address(host: &str) -> Result<SocketAddr, String> {
|
||||
let host = host.trim();
|
||||
let address = host.parse::<IpAddr>().map(|ip| SocketAddr::new(ip, 80))
|
||||
.or_else(|_| host.parse::<SocketAddr>())
|
||||
.map_err(|_| "Enter a device IP address, optionally with a port, e.g. 192.168.10.146:3000 or [::1]:3000; omit http:// and paths.")?;
|
||||
if address.port() == 0 {
|
||||
return Err("Device port must be between 1 and 65535.".into());
|
||||
}
|
||||
Ok(address)
|
||||
}
|
||||
|
||||
/// Perform two GET requests on an explicit IP and optional port. Call from a worker thread.
|
||||
pub fn fetch(host: &str) -> Result<Snapshot, String> {
|
||||
let ip: IpAddr = host
|
||||
.trim()
|
||||
.parse()
|
||||
.map_err(|_| "Enter a device IP address, without http:// or a path.")?;
|
||||
let authority = match ip {
|
||||
IpAddr::V4(ip) => ip.to_string(),
|
||||
IpAddr::V6(ip) => format!("[{ip}]"),
|
||||
};
|
||||
let authority = address(host)?;
|
||||
let client = reqwest::blocking::Client::builder()
|
||||
.timeout(Duration::from_secs(15))
|
||||
.no_proxy()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
//! Explicit, bounded reads of WebRCS input snapshot PNGs.
|
||||
use crate::device::Snapshot;
|
||||
use std::{io::Read, net::IpAddr, time::Duration};
|
||||
use std::{io::Read, time::Duration};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Input {
|
||||
|
|
@ -49,14 +49,7 @@ pub fn capture(host: &str, input: u32) -> Result<Vec<u8>, String> {
|
|||
if !(1..=16).contains(&input) {
|
||||
return Err("Select an input between 1 and 16.".into());
|
||||
}
|
||||
let ip: IpAddr = host
|
||||
.trim()
|
||||
.parse()
|
||||
.map_err(|_| "Enter a device IP address.")?;
|
||||
let authority = match ip {
|
||||
IpAddr::V4(ip) => ip.to_string(),
|
||||
IpAddr::V6(ip) => format!("[{ip}]"),
|
||||
};
|
||||
let authority = crate::device::address(host)?;
|
||||
read_image(&format!(
|
||||
"http://{authority}/api/device/snapshots/inputs/{input}"
|
||||
))
|
||||
|
|
@ -102,10 +95,7 @@ mod tests {
|
|||
use std::io::{BufRead, BufReader, Write};
|
||||
fn response(status: &str, headers: &str, bytes: &[u8]) -> Result<Vec<u8>, String> {
|
||||
let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap();
|
||||
let url = format!(
|
||||
"http://{}/api/device/snapshots/inputs/3",
|
||||
listener.local_addr().unwrap()
|
||||
);
|
||||
let host = listener.local_addr().unwrap().to_string();
|
||||
let reply = format!("HTTP/1.1 {status}\r\nConnection: close\r\n{headers}\r\n");
|
||||
let bytes = bytes.to_vec();
|
||||
let server = std::thread::spawn(move || {
|
||||
|
|
@ -124,7 +114,7 @@ mod tests {
|
|||
stream.write_all(reply.as_bytes()).unwrap();
|
||||
let _ = stream.write_all(&bytes);
|
||||
});
|
||||
let result = read_image(&url);
|
||||
let result = capture(&host, 3);
|
||||
server.join().unwrap();
|
||||
result
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,7 @@ use crate::{
|
|||
device::{self, Snapshot},
|
||||
};
|
||||
use serde_json::{Value, json};
|
||||
use std::{
|
||||
collections::BTreeSet,
|
||||
net::{IpAddr, SocketAddr, TcpStream},
|
||||
time::Duration,
|
||||
};
|
||||
use std::{collections::BTreeSet, net::TcpStream, time::Duration};
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
||||
pub enum Target {
|
||||
|
|
@ -290,8 +286,7 @@ impl Transport for Connection {
|
|||
}
|
||||
fn write(&mut self, change: &Change) -> Result<(), String> {
|
||||
if self.socket.is_none() {
|
||||
let ip: IpAddr = self.host.parse().map_err(|_| "Invalid device IP")?;
|
||||
let address = SocketAddr::new(ip, 80);
|
||||
let address = device::address(&self.host)?;
|
||||
let stream = TcpStream::connect_timeout(&address, Duration::from_secs(5))
|
||||
.map_err(|e| e.to_string())?;
|
||||
stream
|
||||
|
|
@ -329,6 +324,33 @@ pub fn send(host: &str, plan: &Plan) -> Result<Snapshot, String> {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn websocket_writes_use_the_configured_port() {
|
||||
let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap();
|
||||
let host = listener.local_addr().unwrap().to_string();
|
||||
let server = std::thread::spawn(move || {
|
||||
let (stream, _) = listener.accept().unwrap();
|
||||
stream
|
||||
.set_read_timeout(Some(Duration::from_secs(5)))
|
||||
.unwrap();
|
||||
let mut socket = tungstenite::accept(stream).unwrap();
|
||||
let message = socket.read().unwrap();
|
||||
serde_json::from_str::<Value>(message.to_text().unwrap()).unwrap()
|
||||
});
|
||||
let mut connection = Connection { host, socket: None };
|
||||
connection
|
||||
.write(&Change {
|
||||
path: vec!["test".into()],
|
||||
before: json!(0),
|
||||
after: json!(123),
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
server.join().unwrap(),
|
||||
json!({"channel":"DEVICE","data":{"path":["test"],"value":123}})
|
||||
);
|
||||
}
|
||||
|
||||
fn snapshot() -> Snapshot {
|
||||
let layer = json!({"position":{"pp":{"posH":500,"posV":300}},"size":{"pp":{"sizeH":640,"sizeV":360}},"source":{"pp":{"input":"INPUT_4"}},"status":{"pp":{"contentWidth":1920,"contentHeight":1080}},"crop":{"pp":{"left":0,"right":0,"top":0,"bottom":0,"aspectOverride":"GLOBAL_SETTING"}},"mask":{"pp":{"left":0,"right":0,"top":0,"bottom":0}}});
|
||||
let raw = json!({"device": {"preconfig":{"status":{"stateList":{"items":{"CURRENT":{"screenList":{"items":{"1":{"pp":{"layerCount":2}}}}}}}}},"preset":{"control":{"pp":{"xUpdate":true,"enableAutoUpdate":false}}},"transition":{"screenList":{"items":{"1":{"status":{"pp":{"transition":"AT_DOWN"}}}}}},"screenList":{"items":{"1":{"canvas":{"status":{"size":{"pp":{"sizeH":1920,"sizeV":1080}}}},"presetList":{"items":{"UP":{"liveLayerList":{"items":{"1":layer,"2":layer}}},"DOWN":{"liveLayerList":{"items":{"1":layer,"2":layer}}}}}}}}}});
|
||||
|
|
|
|||
|
|
@ -606,8 +606,8 @@ impl Editor {
|
|||
let before = self.device.host.clone();
|
||||
egui::Window::new("Midra connection").open(&mut open).collapsible(false)
|
||||
.default_width(420.0).show(ctx, |ui| {
|
||||
ui.label("Device IP");
|
||||
if ui.add_enabled(self.device.pending.is_none(), egui::TextEdit::singleline(&mut self.device.host).hint_text("192.168.…")).changed() {
|
||||
ui.label("Device IP / port");
|
||||
if ui.add_enabled(self.device.pending.is_none(), egui::TextEdit::singleline(&mut self.device.host).hint_text("192.168.10.146:3000")).changed() {
|
||||
self.device.snapshot = None;
|
||||
self.device.input_edits.clear();
|
||||
self.device.reset_mappings();
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ impl Editor {
|
|||
ui.heading("Midra integration");
|
||||
ui.checkbox(&mut self.device.autoconnect_at_startup, "Try autoconnecting at startup");
|
||||
ui.checkbox(&mut self.device.allow_program, "Allow sending to Program");
|
||||
ui.label("Read Preview layer containers from an Eikos 4K and review their mapping before import.");
|
||||
ui.label("Read Preview layer containers from a Midra 4K switcher and review their mapping before import.");
|
||||
if ui.button("Open Midra connection…").clicked() { self.device.connection_open = true; }
|
||||
ui.weak("Read snapshots and explicitly send reviewed size, position and crop changes.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -229,7 +229,7 @@ mod tests {
|
|||
settings.show_toolbar_icon_names = true;
|
||||
settings.keep_aspect_ratio = false;
|
||||
settings.show_source_pattern = true;
|
||||
settings.midra_host = "192.168.10.143".into();
|
||||
settings.midra_host = "192.168.10.146:3000".into();
|
||||
settings.allow_sending_to_program = true;
|
||||
settings.autoconnect_at_startup = true;
|
||||
store.save(&settings);
|
||||
|
|
|
|||
|
|
@ -193,3 +193,83 @@ fn allocation_filters_firmware_slots_independently_of_input_routing() {
|
|||
assert!(Snapshot::parse(&identity, &raw).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn all_midra_4k_models_use_reported_layer_allocations() {
|
||||
let (mut identity, raw) = fixture();
|
||||
let expected = Snapshot::parse(&identity, &raw).unwrap();
|
||||
for model in ["Eikos 4K", "Pulse 4K", "QuickVu 4K", "QuickMatrix 4K"] {
|
||||
identity["type"] = json!(model);
|
||||
let parsed = Snapshot::parse(&identity, &raw).unwrap();
|
||||
assert!(parsed.identity.starts_with(model));
|
||||
assert_eq!(parsed.screens.len(), expected.screens.len());
|
||||
for (actual, expected) in parsed.screens.iter().zip(&expected.screens) {
|
||||
assert_eq!(actual.layers.len(), expected.layers.len());
|
||||
assert_eq!(actual.resolution, expected.resolution);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn device_addresses_support_ports_and_ipv6() {
|
||||
use midra_layout::device::address;
|
||||
for (input, expected) in [
|
||||
("192.168.10.146", "192.168.10.146:80"),
|
||||
(" 192.168.10.146:3000 ", "192.168.10.146:3000"),
|
||||
("::1", "[::1]:80"),
|
||||
("[::1]:3000", "[::1]:3000"),
|
||||
] {
|
||||
assert_eq!(address(input).unwrap().to_string(), expected);
|
||||
}
|
||||
for input in [
|
||||
"",
|
||||
"localhost",
|
||||
"http://127.0.0.1:3000",
|
||||
"127.0.0.1:0",
|
||||
"127.0.0.1:65536",
|
||||
"127.0.0.1:abc",
|
||||
"127.0.0.1:3000/path",
|
||||
] {
|
||||
assert!(address(input).is_err(), "{input}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fetch_uses_custom_port_for_identity_and_state() {
|
||||
use std::io::{BufRead, BufReader, Write};
|
||||
let (identity, raw) = fixture();
|
||||
let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap();
|
||||
let host = listener.local_addr().unwrap().to_string();
|
||||
let server = std::thread::spawn(move || {
|
||||
for (path, payload) in [
|
||||
("/api/tpp/v1/system", identity),
|
||||
("/api/stores/device", raw),
|
||||
] {
|
||||
let (mut stream, _) = listener.accept().unwrap();
|
||||
stream
|
||||
.set_read_timeout(Some(std::time::Duration::from_secs(5)))
|
||||
.unwrap();
|
||||
let mut reader = BufReader::new(stream.try_clone().unwrap());
|
||||
let mut line = String::new();
|
||||
reader.read_line(&mut line).unwrap();
|
||||
assert_eq!(line, format!("GET {path} HTTP/1.1\r\n"));
|
||||
loop {
|
||||
line.clear();
|
||||
reader.read_line(&mut line).unwrap();
|
||||
if line == "\r\n" {
|
||||
break;
|
||||
}
|
||||
}
|
||||
let body = payload.to_string();
|
||||
write!(
|
||||
stream,
|
||||
"HTTP/1.1 200 OK\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}",
|
||||
body.len()
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
});
|
||||
let result = midra_layout::device::fetch(&host);
|
||||
server.join().unwrap();
|
||||
assert!(result.unwrap().identity.starts_with("Eikos 4K"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,13 @@ Hardware evidence and usage: [Eikos check](../midra-layout/device-check.md).
|
|||
`--save-snapshot` writes UTF-8 JSON containing the raw object from
|
||||
`GET /api/stores/device`; the root key is `device`. No editor project version
|
||||
or custom wrapper is added. This is **vendor state**, not a Midra Layout project.
|
||||
The firmware owns its schema; compatibility was checked on Eikos 4K 3.3.10 only.
|
||||
The firmware owns its schema. The Rust adapter accepts Eikos 4K, Pulse 4K,
|
||||
QuickVu 4K and QuickMatrix 4K identities and validates the shared state fields.
|
||||
Reads were checked on Eikos 4K 3.3.10 hardware and the Pulse 4K 3.3.7 emulator
|
||||
(one 1920 × 1080 screen with four allocated layers). QuickVu and QuickMatrix
|
||||
have synthetic parser coverage; physical acceptance remains outstanding.
|
||||
The Rust connection accepts an IP with optional port, shared across HTTP and
|
||||
WebSocket; see [connection syntax](../midra-layout/guide/device.md#connect-a-device-or-emulator).
|
||||
`--snapshot` reads it offline, at most 32 MiB, and rejects missing required fields
|
||||
when extracting geometry. Unknown vendor fields are preserved on capture.
|
||||
Snapshots can contain private configuration. They are never sent back to a unit.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
# Midra reviewed layer exchange
|
||||
|
||||
The Rust adapter uses the configured IP and optional port for this endpoint
|
||||
(default 80), including emulator addresses such as `192.168.10.146:3000`.
|
||||
|
||||
This is a transient device protocol, not a project/save schema. Reference collections in project v10 do not change device layer mapping. Compatibility exercised: Eikos 4K firmware 3.3.10, installed WebRCS
|
||||
`app.e42fce4879f318b28cde.js`. Other firmware needs verification.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
# Midra input preview stills
|
||||
|
||||
The Rust adapter uses the configured IP and optional port for this endpoint
|
||||
(default 80), including emulator addresses such as `192.168.10.146:3000`.
|
||||
|
||||
This is a device-read interface, not a new project or export format. Verified on
|
||||
Eikos 4K firmware 3.3.10, WebRCS `app.e42fce4879f318b28cde.js`.
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ unknown theme names are rejected. There are no numeric coordinates or units.
|
|||
| `version` | Integer `7` |
|
||||
| `autoconnect_at_startup` | Boolean; default false. Try one background connection at application startup if the saved address is nonblank. |
|
||||
| `allow_sending_to_program` | Boolean; default false. Enables the Program destination in the exporter. Turning it off restores Preview; applies to quick Apply too. |
|
||||
| `midra_host` | Device IP address text; default `""`. Saved as typed, including incomplete drafts; validated when connecting. |
|
||||
| `midra_host` | Device IP address text with optional TCP port (e.g. `192.168.10.146:3000`, `[::1]:3000`; default port 80); default `""`. Saved as typed, including incomplete drafts; validated when connecting. |
|
||||
| `theme` | Theme ID from the catalog below; default `"midra"` |
|
||||
| `recent_themes` | 1–3 unique theme IDs, newest first; first must equal `theme`; default `["midra"]` |
|
||||
| `show_toolbar_icon_names` | Boolean; default false |
|
||||
|
|
@ -143,3 +143,7 @@ also appear in Settings → Editing as a separate Overlay grid section. The over
|
|||
artwork and reference pictures, below editable layers, clipped to the output.
|
||||
It is an editor guide, omitted from all project/export artwork. Preferences save
|
||||
immediately and survive project changes; v1–v6 migration does not alter geometry.
|
||||
|
||||
Custom ports use the existing `midra_host` string without a schema change. The
|
||||
port is shared by HTTP reads/captures and WebSocket writes, including startup
|
||||
autoconnection. Hostnames, URL schemes, paths and port 0 are rejected on use.
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
- Support optional device ports for HTTP state reads, input captures and WebSocket sends, preserving the address in preferences/autoconnect. Accept all four Midra 4K identities (Eikos, Pulse, QuickVu, QuickMatrix) with device-reported allocation. Read-checked Pulse 4K 3.3.7 at port 3000 (four layers); add address, model, capture and WebSocket port regressions. Other model hardware acceptance remains outstanding.
|
||||
|
||||
- Replace the layer-header Folder, Add image and Manage text buttons with compact vector icons, grouped on the right, with tooltips and accessible action names.
|
||||
|
||||
## v0.7.0 — 2026-11-14
|
||||
|
|
|
|||
|
|
@ -2,6 +2,22 @@
|
|||
|
||||
[Midra Layout](../README.md) · [Guide contents](README.md) · [Starter files](../../templates/midra-layout/README.md)
|
||||
|
||||
## Connect a device or emulator
|
||||
|
||||
Enter an IP address in **Device IP / port**, optionally followed by a TCP port:
|
||||
`192.168.10.146:3000`. Without a port, the app uses port 80. IPv6 addresses
|
||||
with a port use brackets, for example `[::1]:3000`. Omit URL schemes and paths.
|
||||
The same address is saved in preferences and used for reads, input snapshots,
|
||||
automatic reconnect and WebSocket sends.
|
||||
|
||||
The adapter accepts Eikos 4K, Pulse 4K, QuickVu 4K and QuickMatrix 4K and reads
|
||||
screen sizes and allocated layer counts from the device instead of assuming
|
||||
Eikos's configuration. This covers the Midra **4K** family, not earlier Midra
|
||||
products or the separate LivePremier/Alta families. Required firmware fields
|
||||
are still validated. Eikos 4K hardware and a Pulse 4K 3.3.7 emulator have been
|
||||
read successfully; QuickVu/QuickMatrix have parser regression coverage but
|
||||
still need individual emulator/hardware acceptance.
|
||||
|
||||
## Use folders as local Midra layouts
|
||||
|
||||
The Midra **Apply to** selector is shared by the status bar, Export menu, and
|
||||
|
|
|
|||
Loading…
Reference in New Issue