8 个版本

0.4.3 2024 年 8 月 19 日
0.4.2 2023 年 9 月 26 日
0.4.1 2022 年 1 月 18 日
0.4.0 2021 年 12 月 28 日
0.1.1 2018 年 9 月 19 日

#201 in 网络编程

Download history 591/week @ 2024-04-30 203/week @ 2024-05-07 147/week @ 2024-05-14 289/week @ 2024-05-21 45/week @ 2024-05-28 107/week @ 2024-06-04 55/week @ 2024-06-11 53/week @ 2024-06-18 800/week @ 2024-06-25 849/week @ 2024-07-02 349/week @ 2024-07-09 576/week @ 2024-07-16 210/week @ 2024-07-23 1257/week @ 2024-07-30 893/week @ 2024-08-06 319/week @ 2024-08-13

2,742 个月下载量
用于 8 个 crates (7 个直接使用)

MIT 许可证

51KB
949

artnet_protocol

包含 ArtCommand 枚举,该枚举包含整个 ArtNet 协议 v4,如 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();
        },
        _ => {}
    }
}

许可证: MIT

依赖关系

~225KB