Compare commits

..

No commits in common. "c30913f8233510c97a13a7e7bf84011ef541af63" and "9d872eecc9ec7b8ce3e9bfad575e92d8af3f7810" have entirely different histories.

5 changed files with 57 additions and 67 deletions

View File

@ -346,7 +346,7 @@ impl AtemSocketInner {
self.send_or_queue_ack().await;
if length > 12 {
self.on_commands_received(&packet[12..]);
self.on_command_received(&packet[12..]);
}
} else if self
.is_packet_covered_by_ack(self.last_received_packed_id, remote_packet_id)
@ -464,7 +464,7 @@ impl AtemSocketInner {
}
}
fn on_commands_received(&mut self, payload: &[u8]) {
fn on_command_received(&mut self, payload: &[u8]) {
let commands = deserialize_commands(payload);
}

View File

@ -1,13 +1,17 @@
use std::{collections::HashMap, fmt::Debug, sync::Arc};
use std::{collections::HashMap, sync::Arc};
use crate::{enums::ProtocolVersion, state::AtemState};
pub trait DeserializedCommand: Send + Sync + Debug {
pub trait DeserializedCommand: Send + Sync {
fn deserialize(buffer: &[u8]) -> Self
where
Self: Sized;
fn apply_to_state(&self, state: &mut AtemState) -> Vec<String>;
}
pub trait CommandDeserializer: Send + Sync {
fn deserialize(&self, buffer: &[u8]) -> Arc<dyn DeserializedCommand>;
pub trait DeserializableCommand: DeserializedCommand {
fn get_raw_name(&self) -> &'static str;
fn get_minimum_version(&self) -> ProtocolVersion;
}
pub trait SerializableCommand {
@ -15,7 +19,7 @@ pub trait SerializableCommand {
}
pub trait BasicWritableCommand: SerializableCommand {
fn get_raw_name() -> &'static str;
fn get_raw_name(&self) -> &'static str;
fn get_minimum_version(&self) -> ProtocolVersion;
}
@ -24,3 +28,5 @@ pub trait WritableCommand: BasicWritableCommand {
fn get_flag(&self) -> f64;
fn set_flag(&mut self, flag: f64);
}
pub trait SymmetricalCommand: DeserializableCommand + SerializableCommand {}

View File

@ -1,13 +1,9 @@
use std::sync::Arc;
use crate::commands::command_base::{BasicWritableCommand, SerializableCommand};
use crate::commands::command_base::{
BasicWritableCommand, CommandDeserializer, DeserializedCommand, SerializableCommand,
};
#[derive(Debug, new)]
#[derive(new)]
pub struct ProgramInput {
pub mix_effect: u8,
pub source: u16,
mix_effect: u8,
source: u16,
}
impl SerializableCommand for ProgramInput {
@ -21,7 +17,7 @@ impl SerializableCommand for ProgramInput {
}
impl BasicWritableCommand for ProgramInput {
fn get_raw_name() -> &'static str {
fn get_raw_name(&self) -> &'static str {
"CPgI"
}
@ -29,21 +25,3 @@ impl BasicWritableCommand for ProgramInput {
crate::enums::ProtocolVersion::Unknown
}
}
impl DeserializedCommand for ProgramInput {
fn apply_to_state(&self, state: &mut crate::state::AtemState) -> Vec<String> {
todo!()
}
}
#[derive(Default)]
pub struct ProgramInputDeserializer {}
impl CommandDeserializer for ProgramInputDeserializer {
fn deserialize(&self, buffer: &[u8]) -> Arc<dyn DeserializedCommand> {
let mix_effect = buffer[0];
let source = u16::from_be_bytes([buffer[2], buffer[3]]);
Arc::new(ProgramInput { mix_effect, source })
}
}

View File

@ -1,16 +1,15 @@
use std::{collections::VecDeque, sync::Arc};
use std::sync::Arc;
use super::{
command_base::{CommandDeserializer, DeserializedCommand},
mix_effects::program_input::ProgramInputDeserializer,
tally_by_source::TallyBySourceDeserializer,
};
use crate::commands::tally_by_source::TallyBySource;
pub fn deserialize_commands(payload: &[u8]) -> VecDeque<Arc<dyn DeserializedCommand>> {
let mut parsed_commands = VecDeque::new();
use super::command_base::DeserializedCommand;
pub fn deserialize_commands(payload: &[u8]) -> Vec<Arc<dyn DeserializedCommand>> {
let mut parsed_commands = vec![];
let mut head = 0;
while payload.len() > head + 8 {
// log::debug!("Head at {} out of {}", head, payload.len());
let length = u16::from_be_bytes([payload[head], payload[head + 1]]) as usize;
let Ok(name) = String::from_utf8(payload[(head + 4)..(head + 8)].to_vec()) else {
break;
@ -22,10 +21,19 @@ pub fn deserialize_commands(payload: &[u8]) -> VecDeque<Arc<dyn DeserializedComm
log::debug!("Received command {} with length {}", name, length);
if let Some(deserializer) = command_deserializer_from_string(name.as_str()) {
let deserialized_command = deserializer.deserialize(&payload[head + 8..head + length]);
log::debug!("Received {:?}", deserialized_command);
parsed_commands.push_back(deserialized_command);
match name.as_str() {
"TlSr" => {
let tally = TallyBySource::deserialize(&payload[head + 8..head + length]);
for (source, state) in tally.sources {
log::info!(
"Source {} Program: {}, Preview: {}",
source,
state.program,
state.preview
)
}
}
_ => {}
}
head += length;
@ -33,11 +41,3 @@ pub fn deserialize_commands(payload: &[u8]) -> VecDeque<Arc<dyn DeserializedComm
parsed_commands
}
fn command_deserializer_from_string(command_str: &str) -> Option<Box<dyn CommandDeserializer>> {
match command_str {
"PrgI" => Some(Box::<ProgramInputDeserializer>::default()),
"TlSr" => Some(Box::<TallyBySourceDeserializer>::default()),
_ => None,
}
}

View File

@ -1,29 +1,31 @@
use std::{collections::HashMap, sync::Arc};
use std::collections::HashMap;
use super::command_base::{CommandDeserializer, DeserializedCommand};
use crate::commands::command_base::{BasicWritableCommand, SerializableCommand};
use super::command_base::{DeserializableCommand, DeserializedCommand};
#[derive(Debug)]
pub struct TallySource {
pub program: bool,
pub preview: bool,
}
#[derive(Debug, new)]
#[derive(new)]
pub struct TallyBySource {
pub sources: HashMap<u16, TallySource>,
}
impl DeserializedCommand for TallyBySource {
fn apply_to_state(&self, state: &mut crate::state::AtemState) -> Vec<String> {
todo!()
impl DeserializableCommand for TallyBySource {
fn get_raw_name(&self) -> &'static str {
"TlSr"
}
fn get_minimum_version(&self) -> crate::enums::ProtocolVersion {
crate::enums::ProtocolVersion::Unknown
}
}
#[derive(Default)]
pub struct TallyBySourceDeserializer {}
impl CommandDeserializer for TallyBySourceDeserializer {
fn deserialize(&self, buffer: &[u8]) -> Arc<dyn DeserializedCommand> {
impl DeserializedCommand for TallyBySource {
fn deserialize(buffer: &[u8]) -> Self {
let source_count = u16::from_be_bytes([buffer[0], buffer[1]]) as usize;
log::debug!("{:?}", buffer);
@ -45,6 +47,10 @@ impl CommandDeserializer for TallyBySourceDeserializer {
);
}
Arc::new(TallyBySource { sources })
Self { sources }
}
fn apply_to_state(&self, state: &mut crate::state::AtemState) -> Vec<String> {
todo!()
}
}