From a45abd69ec3a944892c11a0ceddc1a791952e675 Mon Sep 17 00:00:00 2001 From: Marc Planard Date: Wed, 14 Aug 2024 18:41:47 +0200 Subject: [PATCH] fix: less warnings, better logging for helios broadcast --- src/device/etherdream.rs | 31 +++++++++++++++++++------------ src/device/helios.rs | 4 ++-- src/main.rs | 2 +- src/redis_ctrl.rs | 8 ++++---- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/device/etherdream.rs b/src/device/etherdream.rs index b9e3cab..8463f68 100644 --- a/src/device/etherdream.rs +++ b/src/device/etherdream.rs @@ -62,8 +62,15 @@ impl EtherdreamDevice { } Ok((dac, source_addr)) => { info!("Valid broadcast, source_addr: {}", source_addr); - if source_addr.is_ipv6() { return None; } - if &source_addr.ip().to_string() != ip { return None; } + if source_addr.is_ipv6() { + warn!("Broadcast ignored: ipv6 address."); + return None; + } + let src_ip = source_addr.ip().to_string(); + if &src_ip != ip { + warn!("Broadcast ignored: expected {ip}, got: {src_ip} "); + return None; + } Some(Ok((dac, source_addr))) } } @@ -168,11 +175,11 @@ impl Device for EtherdreamDevice { debug!("New chunk length: {:?}", chunk.len()); loop { let capacity = self.points_capacity(); - if chunk.len() > capacity as usize { + if chunk.len() > capacity { debug!("Sleep, capacity : {:?}", capacity); // Sleep for 1/100th of a sec sleep(Duration::new( 0, 10000000)); - self.ping(); + self.ping()?; } else { break; } @@ -181,9 +188,9 @@ impl Device for EtherdreamDevice { match self.stream .queue_commands() .data( - chunk.into_iter() + chunk.iter() .map(|point| (*point).into()) - .take(chunk_size as usize) + .take(chunk_size) ) .submit() { Err(err) => { @@ -233,8 +240,8 @@ impl Device for EtherdreamDevice { } fn grid(&mut self) -> Vec { - let dim_mid = 16000 as f32; - let dim_max = 32000 as f32; + let dim_mid = 16000.0; + let dim_max = 32000.0; let col_min = Color { r: 0, g: 0, b: 0 }; let col_max = Color { r: 255, g: 255, b: 255 }; @@ -275,10 +282,10 @@ impl Iterator for SineWave { let amp = (hz * (fract + phase) * 2.0 * std::f32::consts::PI).sin(); let (r, g, b) = match i { i if i == coloured_points_per_frame || i < 13 => (0, 0, 0), - _ => (std::u16::MAX, std::u16::MAX, std::u16::MAX), + _ => (u16::MAX, u16::MAX, u16::MAX), }; - let x_min = std::i16::MIN; - let x_max = std::i16::MAX; + let x_min = i16::MIN; + let x_max = i16::MAX; let x = (x_min as f32 + fract * (x_max as f32 - x_min as f32)) as i16; let y = (amp * x_max as f32) as i16; let control = 0; @@ -298,4 +305,4 @@ impl Iterator for SineWave { self.point += 1; Some(p) } -} \ No newline at end of file +} diff --git a/src/device/helios.rs b/src/device/helios.rs index 9106243..a1f6af4 100644 --- a/src/device/helios.rs +++ b/src/device/helios.rs @@ -85,8 +85,8 @@ impl Device for HeliosDevice { fn grid(&mut self) -> Vec { let dim_min = 0 as f32; - let dim_mid = 2047 as f32; - let dim_max = 4095 as f32; + let dim_mid = 2047.0; + let dim_max = 4095.0; let col_min = Color { r: 0, g: 0, b: 0 }; let col_max = Color { r: 255, g: 255, b: 255 }; diff --git a/src/main.rs b/src/main.rs index c1ba308..39e7e81 100644 --- a/src/main.rs +++ b/src/main.rs @@ -76,7 +76,7 @@ fn run_all() -> LJResult<()> { // Dispatch based on redis requests while running.load(Ordering::SeqCst) { rs.set_status(tracer.status())?; - let _ = framerate_handler.handle_time()?; + framerate_handler.handle_time()?; let order = rs.get_order(config.laser_id)?; match order { Order::Draw | Order::Black | Order::Grid => { diff --git a/src/redis_ctrl.rs b/src/redis_ctrl.rs index 03d7cba..4dc9722 100644 --- a/src/redis_ctrl.rs +++ b/src/redis_ctrl.rs @@ -98,10 +98,10 @@ impl RedisCtrl { pub fn init_world_state(&mut self) -> LJResult { Ok(WorldState { - client_key: self.get_client_key().unwrap(), - edh: self.get_edh().unwrap(), - kpps: self.get_int("kpps").unwrap().try_into().unwrap(), - intensity: self.get_int("intensity").unwrap().try_into().unwrap(), + client_key: self.get_client_key()?, + edh: self.get_edh()?, + kpps: self.get_int("kpps")?.try_into()?, + intensity: self.get_int("intensity")?.try_into()?, ..WorldState::default() }) }