From f0ee6a0444f4729d8bfa436c5c42c9492423431b Mon Sep 17 00:00:00 2001 From: Baud Date: Mon, 5 Feb 2024 20:43:27 +0000 Subject: [PATCH] feat: Program input command --- Cargo.lock | 41 +++++++++++++------ Cargo.toml | 2 +- atem-connection-rs/Cargo.toml | 2 +- .../src/commands/mix_effects.rs | 27 ++++++++++++ atem-connection-rs/src/commands/mod.rs | 1 + atem-test/src/main.rs | 29 +++++++++---- 6 files changed, 80 insertions(+), 22 deletions(-) create mode 100644 atem-connection-rs/src/commands/mix_effects.rs diff --git a/Cargo.lock b/Cargo.lock index cc778e5..2078298 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -138,18 +138,18 @@ checksum = "0c5905670fd9c320154f3a4a01c9e609733cd7b753f3c58777ab7d5ce26686b3" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.74", ] [[package]] name = "derive-new" -version = "0.5.9" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3418329ca0ad70234b9735dc4ceed10af4df60eff9c8e7b06cb5e520d92c3535" +checksum = "d150dea618e920167e5973d70ae6ece4385b7164e0d799fe7c122dd0a5d912ad" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.48", ] [[package]] @@ -352,18 +352,18 @@ checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" [[package]] name = "proc-macro2" -version = "1.0.28" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c7ed8b8c7b886ea3ed7dde405212185f423ab44682667c8c6dd14aa1d9f6612" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] name = "quote" -version = "1.0.9" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -441,6 +441,17 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "syn" +version = "2.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "termcolor" version = "1.1.2" @@ -467,7 +478,7 @@ checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.74", ] [[package]] @@ -507,7 +518,7 @@ checksum = "c9efc1aba077437943f7515666aa2b882dfabfbfdf89c819ea75a8d6e9eaba5e" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.74", ] [[package]] @@ -530,7 +541,7 @@ checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.74", ] [[package]] @@ -563,6 +574,12 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + [[package]] name = "unicode-xid" version = "0.2.2" diff --git a/Cargo.toml b/Cargo.toml index 1fa8b0e..ba56389 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] - +resolver = "2" members = [ "atem-connection-rs", "atem-test" diff --git a/atem-connection-rs/Cargo.toml b/atem-connection-rs/Cargo.toml index 96185cf..73ee78b 100644 --- a/atem-connection-rs/Cargo.toml +++ b/atem-connection-rs/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] derive-getters = "0.2.0" -derive-new = "0.5.9" +derive-new = "0.6.0" log = "0.4.14" thiserror = "1.0.30" tokio = { version = "1.13.0", features = ["full"] } diff --git a/atem-connection-rs/src/commands/mix_effects.rs b/atem-connection-rs/src/commands/mix_effects.rs new file mode 100644 index 0000000..b0a6e40 --- /dev/null +++ b/atem-connection-rs/src/commands/mix_effects.rs @@ -0,0 +1,27 @@ +use super::command_base::{BasicWritableCommand, SerializableCommand}; + +#[derive(new)] +pub struct ProgramInput { + mix_effect: u8, + source: u16, +} + +impl SerializableCommand for ProgramInput { + fn payload(&self, _version: crate::enums::ProtocolVersion) -> Vec { + let mut buf = vec![0; 4]; + buf[..1].copy_from_slice(&self.mix_effect.to_be_bytes()); + buf[2..].copy_from_slice(&self.source.to_be_bytes()); + + buf + } +} + +impl BasicWritableCommand for ProgramInput { + fn get_raw_name(&self) -> &'static str { + "CPgI" + } + + fn get_minimum_version(&self) -> crate::enums::ProtocolVersion { + crate::enums::ProtocolVersion::Unknown + } +} diff --git a/atem-connection-rs/src/commands/mod.rs b/atem-connection-rs/src/commands/mod.rs index 0ddc932..a95dff4 100644 --- a/atem-connection-rs/src/commands/mod.rs +++ b/atem-connection-rs/src/commands/mod.rs @@ -1 +1,2 @@ pub mod command_base; +pub mod mix_effects; diff --git a/atem-test/src/main.rs b/atem-test/src/main.rs index 7f8285e..3780807 100644 --- a/atem-test/src/main.rs +++ b/atem-test/src/main.rs @@ -1,6 +1,12 @@ use std::time::Duration; -use atem_connection_rs::atem_lib::atem_socket::AtemSocket; +use atem_connection_rs::{ + atem_lib::atem_socket::AtemSocket, + commands::{ + command_base::{BasicWritableCommand, SerializableCommand}, + mix_effects::ProgramInput, + }, +}; use color_eyre::Report; use tokio::time::sleep; @@ -9,9 +15,8 @@ use tokio::time::sleep; async fn main() { setup_logging().unwrap(); - let switch_raw_name: &str = "CPgI"; - let switch_source_to_1: [u8; 4] = [0, 0, 0, 1]; - let switch_source_to_2: [u8; 4] = [0, 0, 0, 2]; + let switch_to_source_1 = ProgramInput::new(0, 1); + let switch_to_source_2 = ProgramInput::new(0, 2); let mut atem = AtemSocket::new(); atem.connect("127.0.0.1".to_string(), 9910).await.ok(); @@ -19,12 +24,20 @@ async fn main() { let mut tracking_id = 0; loop { sleep(Duration::from_millis(5000)).await; - atem.send_command(&switch_source_to_1, switch_raw_name, tracking_id) - .await; + atem.send_command( + &switch_to_source_1.payload(atem_connection_rs::enums::ProtocolVersion::Unknown), + switch_to_source_1.get_raw_name(), + tracking_id, + ) + .await; tracking_id += 1; sleep(Duration::from_millis(5000)).await; - atem.send_command(&switch_source_to_2, switch_raw_name, tracking_id) - .await; + atem.send_command( + &switch_to_source_2.payload(atem_connection_rs::enums::ProtocolVersion::Unknown), + switch_to_source_2.get_raw_name(), + tracking_id, + ) + .await; tracking_id += 1; } }