Git Product home page Git Product logo

artnet_protocol's Introduction

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

artnet_protocol's People

Contributors

victorkoenders avatar firionus avatar dependabot-preview[bot] avatar thijsc avatar max298 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.