feat: Program Input deserialization

This commit is contained in:
Baud 2024-02-23 11:40:57 +00:00
parent 9d872eecc9
commit c80d7643ca
2 changed files with 41 additions and 4 deletions

View File

@ -1,9 +1,11 @@
use crate::commands::command_base::{BasicWritableCommand, SerializableCommand}; use crate::commands::command_base::{
BasicWritableCommand, DeserializableCommand, DeserializedCommand, SerializableCommand,
};
#[derive(new)] #[derive(new)]
pub struct ProgramInput { pub struct ProgramInput {
mix_effect: u8, pub mix_effect: u8,
source: u16, pub source: u16,
} }
impl SerializableCommand for ProgramInput { impl SerializableCommand for ProgramInput {
@ -25,3 +27,29 @@ impl BasicWritableCommand for ProgramInput {
crate::enums::ProtocolVersion::Unknown 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<String> {
todo!()
}
}

View File

@ -1,6 +1,6 @@
use std::sync::Arc; 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; use super::command_base::DeserializedCommand;
@ -33,6 +33,15 @@ pub fn deserialize_commands(payload: &[u8]) -> Vec<Arc<dyn DeserializedCommand>>
) )
} }
} }
"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
);
}
_ => {} _ => {}
} }