use std::net::{SocketAddr, TcpStream}; use clap::Parser; use clap_derive::Subcommand; use packet::Packet; mod packet; #[derive(Parser, Debug)] #[command(version, about)] struct Args { #[arg(short, long)] connect: SocketAddr, #[command(subcommand)] command: Command, } #[derive(Subcommand, Debug)] enum Command { /// Set a constant brightness in Range 0.0..=1.0 Constant { brightness: f64 }, /// Sinusoidal curve with a period of 0.0.. seconds Sine { period: f64 }, /// Triangle curve with a period of 0.0.. seconds Triangle { period: f64 }, /// Sawtooth curve with a period of 0.0.. seconds Sawtooth { period: f64 }, /// Square curve witha period of 0.0.. seconds and a duty cycle of 0.0..1.0 Square { period: f64, duty: f64 }, } fn main() { let args = Args::parse(); let mut stream = TcpStream::connect(args.connect).expect("Unable to connect to server"); let packet = match args.command { Command::Constant { brightness } => Packet::Constant(brightness), Command::Sine { period } => Packet::Sine(period), Command::Triangle { period } => Packet::Triangle(period), Command::Sawtooth { period } => Packet::Sawtooth(period), Command::Square { period, duty } => Packet::Square { period, duty }, }; packet .write_to_stream(&mut stream) .expect("Unable to send packet"); }