Add initial atem testing

This commit is contained in:
Sam W 2019-03-21 00:59:32 +00:00
parent ec03b72c7e
commit 01faf4b8c6
3 changed files with 60 additions and 1 deletions

1
Cargo.lock generated
View File

@ -789,6 +789,7 @@ dependencies = [
"actix 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)", "actix 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)",
"actix-net 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "actix-net 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"actix-web 0.7.18 (registry+https://github.com/rust-lang/crates.io-index)", "actix-web 0.7.18 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"ctrlc 3.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "ctrlc 3.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -16,3 +16,4 @@ edition = "2018"
ctrlc = "3.1.1" ctrlc = "3.1.1"
serde = { version = "1.0", features = ["derive"]} serde = { version = "1.0", features = ["derive"]}
serde_json = "1.0" serde_json = "1.0"
byteorder = "1.3.1"

57
src/bin/atem.rs Normal file
View File

@ -0,0 +1,57 @@
use byteorder::{BigEndian, WriteBytesExt};
use std::net::UdpSocket;
enum Command {
NoCommand = 0x0,
AckRequest = 0x1,
HelloPacket = 0x2,
Resend = 0x4,
Undefined = 0x8,
Ack = 0x10,
}
// much thanks to https://github.com/petersimonsson/libqatemcontrol/blob/master/qatemconnection.cpp
struct ATEMPacket {
raw: Vec<u8>,
}
impl ATEMPacket {
const HEADER_SIZE: u16 = 12;
fn new(cmd: Command, uid: u16, ack_id: u16, payload: Vec<u16>) -> ATEMPacket {
let mut a = ATEMPacket { raw: vec![] };
for word in vec![
((cmd as u16) << 11) | ((payload.len() as u16 * 2) + ATEMPacket::HEADER_SIZE),
uid,
ack_id,
0,
0,
0, // TODO: packageid
]
.into_iter()
.chain(payload.into_iter())
{
a.raw.write_u16::<BigEndian>(word).unwrap();
}
a
}
}
fn main() {
let mut sock = UdpSocket::bind("0.0.0.0:0").expect("Couldn't bind");
let a = ATEMPacket::new(
Command::HelloPacket,
0x1337,
0x0,
vec![0x100, 0x0, 0x0, 0x0],
);
sock.send_to(&a.raw[..], "192.168.0.240:9910")
.expect("Couldn't send data");
}
#[test]
fn test_newpacket() {
assert_eq!(
ATEMPacket::new(Command::Undefined, 0x1234, 0x5678, vec![0x1337, 0x0420]).raw,
vec![0x10, 0x40, 0x34, 0x12, 0x78, 0x56, 0x0, 0x0, 0x0, 0x0, 0x37, 0x13, 0x20, 0x04]
);
}