first working version

This commit is contained in:
Vinzenz Schroeter 2024-05-09 23:30:18 +02:00
commit db8370e642
8 changed files with 240 additions and 0 deletions

22
src/connection.rs Normal file
View file

@ -0,0 +1,22 @@
use std::net::{ToSocketAddrs, UdpSocket};
use crate::{Command, Packet};
pub struct Connection {
socket: UdpSocket,
}
impl Connection {
/// Open a new UDP socket and create a display instance
pub fn open(addr: impl ToSocketAddrs) -> std::io::Result<Self> {
let socket = UdpSocket::bind("0.0.0.0:0")?;
socket.connect(addr)?;
Ok(Self { socket })
}
/// Send a command to the display
pub fn send(&self, command: Command) -> std::io::Result<()> {
let packet: Packet = command.into();
self.socket.send(&packet)?;
Ok(())
}
}