artnet_protocol/lib.rs
1//! Contains the [ArtCommand](struct.ArtCommand.html) enum which holds the entire ArtNet protocol v4, as per [https://artisticlicence.com/WebSiteMaster/User%20Guides/art-net.pdf](https://artisticlicence.com/WebSiteMaster/User%20Guides/art-net.pdf)
2//!
3//! ```rust,no_run
4//! use artnet_protocol::*;
5//! use std::net::{UdpSocket, ToSocketAddrs};
6//!
7//! let socket = UdpSocket::bind(("0.0.0.0", 6454)).unwrap();
8//! let broadcast_addr = ("255.255.255.255", 6454).to_socket_addrs().unwrap().next().unwrap();
9//! socket.set_broadcast(true).unwrap();
10//! let buff = ArtCommand::Poll(Poll::default()).write_to_buffer().unwrap();
11//! socket.send_to(&buff, &broadcast_addr).unwrap();
12//!
13//! loop {
14//! let mut buffer = [0u8; 1024];
15//! let (length, addr) = socket.recv_from(&mut buffer).unwrap();
16//! let command = ArtCommand::from_buffer(&buffer[..length]).unwrap();
17//!
18//! println!("Received {:?}", command);
19//! match command {
20//! ArtCommand::Poll(poll) => {
21//! // This will most likely be our own poll request, as this is broadcast to all devices on the network
22//! },
23//! ArtCommand::PollReply(reply) => {
24//! // This is an ArtNet node on the network. We can send commands to it like this:
25//! let command = ArtCommand::Output(Output {
26//! data: vec![1, 2, 3, 4, 5].into(), // The data we're sending to the node
27//! ..Output::default()
28//! });
29//! let bytes = command.write_to_buffer().unwrap();
30//! socket.send_to(&bytes, &addr).unwrap();
31//! },
32//! _ => {}
33//! }
34//! }
35//! ```
36#![deny(missing_docs)]
37
38/// Re-export of the bitflags crate that this library uses
39#[macro_use]
40pub extern crate bitflags;
41/// Re-export of the byteorder crate that this library uses
42pub extern crate byteorder;
43
44#[macro_use]
45mod macros;
46mod command;
47mod convert;
48mod enums;
49mod error;
50mod port_address;
51
52pub use crate::command::*;
53pub use crate::enums::ArtTalkToMe;
54pub use crate::error::*;
55pub use port_address::PortAddress;