8 releases

0.4.3 Aug 19, 2024
0.4.2 Sep 26, 2023
0.4.1 Jan 18, 2022
0.4.0 Dec 28, 2021
0.1.1 Sep 19, 2018

#520 in Network programming

Download history 191/week @ 2024-08-16 51/week @ 2024-08-23 338/week @ 2024-08-30 159/week @ 2024-09-06 73/week @ 2024-09-13 365/week @ 2024-09-20 503/week @ 2024-09-27 1017/week @ 2024-10-04 140/week @ 2024-10-11 202/week @ 2024-10-18 20/week @ 2024-10-25 374/week @ 2024-11-01 364/week @ 2024-11-08 398/week @ 2024-11-15 210/week @ 2024-11-22 266/week @ 2024-11-29

1,250 downloads per month
Used in 8 crates (7 directly)

MIT license

51KB
949 lines

artnet_protocol

Contains the ArtCommand enum which holds the entire ArtNet protocol v4, as per https://artisticlicence.com/WebSiteMaster/User%20Guides/art-net.pdf

use artnet_protocol::*;
use std::net::{UdpSocket, ToSocketAddrs};

let socket = UdpSocket::bind(("0.0.0.0", 6454)).unwrap();
let broadcast_addr = ("255.255.255.255", 6454).to_socket_addrs().unwrap().next().unwrap();
socket.set_broadcast(true).unwrap();
let buff = ArtCommand::Poll(Poll::default()).write_to_buffer().unwrap();
socket.send_to(&buff, &broadcast_addr).unwrap();

loop {
    let mut buffer = [0u8; 1024];
    let (length, addr) = socket.recv_from(&mut buffer).unwrap();
    let command = ArtCommand::from_buffer(&buffer[..length]).unwrap();

    println!("Received {:?}", command);
    match command {
        ArtCommand::Poll(poll) => {
            // This will most likely be our own poll request, as this is broadcast to all devices on the network
        },
        ArtCommand::PollReply(reply) => {
            // This is an ArtNet node on the network. We can send commands to it like this:
            let command = ArtCommand::Output(Output {
                length: 5, // must match your data.len()
                data: vec![1, 2, 3, 4, 5], // The data we're sending to the node
                ..Output::default()
            });
            let bytes = command.write_to_buffer().unwrap();
            socket.send_to(&bytes, &addr).unwrap();
        },
        _ => {}
    }
}

License: MIT

Dependencies

~220KB