Trangar / artnet_protocol

A 1:1 implementation of the ArtNet protocol, in Rust
MIT License
22 stars 18 forks source link

Flashes and then disapears #29

Open piemanau opened 1 year ago

piemanau commented 1 year ago

Hey there. I am using an Ode Mk 2 and I am trying to communicate to it with art-net (and this crate) but when I run my code it flashes what I want however it should stay. Is it because I'm not responding to the Poll? This is what the protocol says (pulled from the ArtPoll packet summary): The Controller may assume a maximum timeout of 3 seconds between sending ArtPoll and receiving all ArtPollReply packets. If the Controller does not receive a response in this time, it should consider the Node to have disconnected. Is this the issue or is it something else that I am missing?

Here is my code:

fn main() {
let socket = UdpSocket::bind(("0.0.0.0", 6454)).unwrap();
let broadcast_addr = ("192.168.1.2", 6454).to_socket_addrs().unwrap().next().unwrap();
socket.set_broadcast(false).unwrap();
let buff = ArtCommand::Poll(Poll {
    ..Default::default()
});
let buff = buff.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 {
            port_address: 0.into(),
            data: PaddedData::from([255u8; 512].to_vec()), // The data we're sending to the node
            ..Output::default()
        });
        println!("{:?}", command);
        let bytes = command.write_to_buffer().unwrap();
        socket.send_to(&bytes, &addr).unwrap();
    }
}

This is just the example code but modified slightly