From c80d7643cab78c7b73901aa1c3a0a523d5d7e724 Mon Sep 17 00:00:00 2001 From: Baud Date: Fri, 23 Feb 2024 11:40:57 +0000 Subject: [PATCH] feat: Program Input deserialization --- .../src/commands/mix_effects/program_input.rs | 34 +++++++++++++++++-- .../src/commands/parse_commands.rs | 11 +++++- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/atem-connection-rs/src/commands/mix_effects/program_input.rs b/atem-connection-rs/src/commands/mix_effects/program_input.rs index 2d8ec5e..5248152 100644 --- a/atem-connection-rs/src/commands/mix_effects/program_input.rs +++ b/atem-connection-rs/src/commands/mix_effects/program_input.rs @@ -1,9 +1,11 @@ -use crate::commands::command_base::{BasicWritableCommand, SerializableCommand}; +use crate::commands::command_base::{ + BasicWritableCommand, DeserializableCommand, DeserializedCommand, SerializableCommand, +}; #[derive(new)] pub struct ProgramInput { - mix_effect: u8, - source: u16, + pub mix_effect: u8, + pub source: u16, } impl SerializableCommand for ProgramInput { @@ -25,3 +27,29 @@ impl BasicWritableCommand for ProgramInput { crate::enums::ProtocolVersion::Unknown } } + +impl DeserializableCommand for ProgramInput { + fn get_raw_name(&self) -> &'static str { + "PrgI" + } + + fn get_minimum_version(&self) -> crate::enums::ProtocolVersion { + crate::enums::ProtocolVersion::Unknown + } +} + +impl DeserializedCommand for ProgramInput { + fn deserialize(buffer: &[u8]) -> Self + where + Self: Sized, + { + let mix_effect = buffer[0]; + let source = u16::from_be_bytes([buffer[2], buffer[3]]); + + Self { mix_effect, source } + } + + fn apply_to_state(&self, state: &mut crate::state::AtemState) -> Vec { + todo!() + } +} diff --git a/atem-connection-rs/src/commands/parse_commands.rs b/atem-connection-rs/src/commands/parse_commands.rs index 8bae3d3..3c2c25a 100644 --- a/atem-connection-rs/src/commands/parse_commands.rs +++ b/atem-connection-rs/src/commands/parse_commands.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use crate::commands::tally_by_source::TallyBySource; +use crate::commands::{mix_effects::program_input::ProgramInput, tally_by_source::TallyBySource}; use super::command_base::DeserializedCommand; @@ -33,6 +33,15 @@ pub fn deserialize_commands(payload: &[u8]) -> Vec> ) } } + "PrgI" => { + let program_input = ProgramInput::deserialize(&payload[head + 8..head + length]); + + log::info!( + "Mix Effect {} changed to source {}", + program_input.mix_effect, + program_input.source + ); + } _ => {} }