Compare commits
No commits in common. "7e973af192c1cede32e2661264149730fb4698c2" and "2325645bb58b94aa919bac6786aeb96f98abaad3" have entirely different histories.
7e973af192
...
2325645bb5
|
@ -68,7 +68,7 @@ impl Atem {
|
||||||
AtemEvent::Connected => {
|
AtemEvent::Connected => {
|
||||||
log::info!("Atem connected");
|
log::info!("Atem connected");
|
||||||
}
|
}
|
||||||
AtemEvent::Disconnected => todo!("Disconnected"),
|
AtemEvent::Disconnected => todo!(),
|
||||||
AtemEvent::ReceivedCommands(commands) => {
|
AtemEvent::ReceivedCommands(commands) => {
|
||||||
self.mutate_state(&mut state, &mut status, commands).await
|
self.mutate_state(&mut state, &mut status, commands).await
|
||||||
}
|
}
|
||||||
|
@ -142,19 +142,14 @@ impl Atem {
|
||||||
for command in commands {
|
for command in commands {
|
||||||
match command.raw_name() {
|
match command.raw_name() {
|
||||||
DESERIALIZE_VERSION_RAW_NAME => {
|
DESERIALIZE_VERSION_RAW_NAME => {
|
||||||
log::debug!("Received version response");
|
|
||||||
*state = AtemState::default();
|
*state = AtemState::default();
|
||||||
*status = AtemConnectionStatus::Connecting
|
*status = AtemConnectionStatus::Connecting
|
||||||
}
|
}
|
||||||
DESERIALIZE_INIT_COMPLETE_RAW_NAME => {
|
DESERIALIZE_INIT_COMPLETE_RAW_NAME => *status = AtemConnectionStatus::Connected,
|
||||||
log::debug!("Received init complete from ATEM");
|
|
||||||
*status = AtemConnectionStatus::Connected
|
|
||||||
}
|
|
||||||
DESERIALIZE_TIME_RAW_NAME => {
|
DESERIALIZE_TIME_RAW_NAME => {
|
||||||
todo!("Time command")
|
todo!("Time command")
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
log::debug!("Applying {} to state", command.raw_name());
|
|
||||||
command.apply_to_state(state);
|
command.apply_to_state(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ pub struct AtemSocketCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AtemSocketCommand {
|
impl AtemSocketCommand {
|
||||||
pub fn new<C: BasicWritableCommand>(command: &C, version: &ProtocolVersion) -> Self {
|
pub fn new(command: &Box<dyn BasicWritableCommand>, version: &ProtocolVersion) -> Self {
|
||||||
Self {
|
Self {
|
||||||
payload: command.payload(version),
|
payload: command.payload(version),
|
||||||
raw_name: command.get_raw_name().to_string(),
|
raw_name: command.get_raw_name().to_string(),
|
||||||
|
@ -175,12 +175,9 @@ impl AtemSocket {
|
||||||
mut atem_message_rx: tokio::sync::mpsc::Receiver<AtemSocketMessage>,
|
mut atem_message_rx: tokio::sync::mpsc::Receiver<AtemSocketMessage>,
|
||||||
cancel: tokio_util::sync::CancellationToken,
|
cancel: tokio_util::sync::CancellationToken,
|
||||||
) {
|
) {
|
||||||
let mut interval = tokio::time::interval(Duration::from_millis(5));
|
|
||||||
while !cancel.is_cancelled() {
|
while !cancel.is_cancelled() {
|
||||||
let tick = interval.tick();
|
|
||||||
select! {
|
select! {
|
||||||
_ = cancel.cancelled() => {},
|
_ = cancel.cancelled() => {},
|
||||||
_ = tick => {},
|
|
||||||
message = atem_message_rx.recv() => {
|
message = atem_message_rx.recv() => {
|
||||||
match message {
|
match message {
|
||||||
Some(AtemSocketMessage::Connect {
|
Some(AtemSocketMessage::Connect {
|
||||||
|
@ -192,7 +189,6 @@ impl AtemSocket {
|
||||||
connected_callbacks.push(result_callback);
|
connected_callbacks.push(result_callback);
|
||||||
}
|
}
|
||||||
if self.connect(address).await.is_err() {
|
if self.connect(address).await.is_err() {
|
||||||
log::debug!("Connect failed");
|
|
||||||
let mut connected_callbacks = self.connected_callbacks.lock().await;
|
let mut connected_callbacks = self.connected_callbacks.lock().await;
|
||||||
for callback in connected_callbacks.drain(0..) {
|
for callback in connected_callbacks.drain(0..) {
|
||||||
let _ = callback.send(false);
|
let _ = callback.send(false);
|
||||||
|
@ -236,9 +232,9 @@ impl AtemSocket {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
self.tick().await;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.tick().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn connect(&mut self, address: SocketAddr) -> Result<(), io::Error> {
|
pub async fn connect(&mut self, address: SocketAddr) -> Result<(), io::Error> {
|
||||||
|
@ -397,7 +393,7 @@ impl AtemSocket {
|
||||||
self.connection_state = ConnectionState::Established;
|
self.connection_state = ConnectionState::Established;
|
||||||
self.last_received_packed_id = remote_packet_id;
|
self.last_received_packed_id = remote_packet_id;
|
||||||
self.send_ack(remote_packet_id).await;
|
self.send_ack(remote_packet_id).await;
|
||||||
self.on_connect().await;
|
self.on_connect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -547,9 +543,9 @@ impl AtemSocket {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn on_connect(&mut self) {
|
fn on_connect(&mut self) {
|
||||||
let _ = self.atem_event_tx.send(AtemEvent::Connected);
|
let _ = self.atem_event_tx.send(AtemEvent::Connected);
|
||||||
let mut connected_callbacks = self.connected_callbacks.lock().await;
|
let mut connected_callbacks = self.connected_callbacks.blocking_lock();
|
||||||
for callback in connected_callbacks.drain(0..) {
|
for callback in connected_callbacks.drain(0..) {
|
||||||
let _ = callback.send(false);
|
let _ = callback.send(false);
|
||||||
}
|
}
|
||||||
|
@ -560,7 +556,6 @@ impl AtemSocket {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_timers(&mut self) {
|
fn start_timers(&mut self) {
|
||||||
log::debug!("Starting timers");
|
|
||||||
self.start_reconnect_timer();
|
self.start_reconnect_timer();
|
||||||
self.start_retransmit_timer();
|
self.start_retransmit_timer();
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,43 +15,11 @@ pub trait SerializableCommand {
|
||||||
fn payload(&self, version: &ProtocolVersion) -> Vec<u8>;
|
fn payload(&self, version: &ProtocolVersion) -> Vec<u8>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C: SerializableCommand + ?Sized> SerializableCommand for Box<C> {
|
|
||||||
fn payload(&self, version: &ProtocolVersion) -> Vec<u8> {
|
|
||||||
(**self).payload(version)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<C: SerializableCommand + ?Sized> SerializableCommand for &'_ Box<C> {
|
|
||||||
fn payload(&self, version: &ProtocolVersion) -> Vec<u8> {
|
|
||||||
(**self).payload(version)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait BasicWritableCommand: SerializableCommand {
|
pub trait BasicWritableCommand: SerializableCommand {
|
||||||
fn get_raw_name(&self) -> &'static str;
|
fn get_raw_name(&self) -> &'static str;
|
||||||
fn get_minimum_version(&self) -> ProtocolVersion;
|
fn get_minimum_version(&self) -> ProtocolVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C: BasicWritableCommand + ?Sized> BasicWritableCommand for Box<C> {
|
|
||||||
fn get_raw_name(&self) -> &'static str {
|
|
||||||
(**self).get_raw_name()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_minimum_version(&self) -> ProtocolVersion {
|
|
||||||
(**self).get_minimum_version()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<C: BasicWritableCommand + ?Sized> BasicWritableCommand for &'_ Box<C> {
|
|
||||||
fn get_raw_name(&self) -> &'static str {
|
|
||||||
(**self).get_raw_name()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_minimum_version(&self) -> ProtocolVersion {
|
|
||||||
(**self).get_minimum_version()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait WritableCommand: BasicWritableCommand {
|
pub trait WritableCommand: BasicWritableCommand {
|
||||||
fn get_mask_flag(&self) -> HashMap<String, f64>;
|
fn get_mask_flag(&self) -> HashMap<String, f64>;
|
||||||
fn get_flag(&self) -> f64;
|
fn get_flag(&self) -> f64;
|
||||||
|
|
Loading…
Reference in New Issue