From f532d83bb34463aac9979e49446029e89e8fa149 Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Tue, 24 Oct 2023 12:28:43 +0700 Subject: [PATCH] More inner udp source timeout locations --- README.md | 12 ++++++ .../src/bc_protocol/connection/udpsource.rs | 6 +-- src/mqtt/mod.rs | 37 +++++++++++-------- 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 14c854d..786c6ca 100644 --- a/README.md +++ b/README.md @@ -219,6 +219,9 @@ Control messages: - `/control/ptz/preset [id]` Move the camera to a PTZ preset - `/control/ptz/assign [id] [name]` Set the current PTZ position to a preset ID and name +- `/control/zoom (amount)` Zoom the camera to the specified amount. Example: 1.0 + for normal and 3.5 for 3.5x zoom factor. This only works on cameras that support + zoom - `/control/pir [on|off]` - `control/wakeup (mins)` For cameras that are using `idle_disconnect` this will force a wakeup for at least the given minutes @@ -538,6 +541,15 @@ neolink ptz --config=config.toml CameraName preset 0 neolink ptz --config=config.toml CameraName assign 0 PresetName ``` +To change the zoom level use the following: + +```bash +# Zoom the camera to 2.5x +neolink ptz --config=config.toml CameraName zoom 2.5 +``` + +With 1.0 being normal and 2.5 being 2.5x zoom + ## License Neolink is free software, released under the GNU Affero General Public License diff --git a/crates/core/src/bc_protocol/connection/udpsource.rs b/crates/core/src/bc_protocol/connection/udpsource.rs index b0ad7f9..367333a 100644 --- a/crates/core/src/bc_protocol/connection/udpsource.rs +++ b/crates/core/src/bc_protocol/connection/udpsource.rs @@ -355,7 +355,7 @@ impl UdpPayloadInner { let packet = packet.ok_or(Error::DroppedConnection)??; recv_timeout.as_mut().reset(Instant::now() + Duration::from_secs(TIME_OUT)); // let packet = socket_rx.next().await.ok_or(Error::DroppedConnection)??; - socket_out_tx.send(packet).await?; + tokio::time::timeout(tokio::time::Duration::from_millis(250), socket_out_tx.send(packet)).await.map_err(|_| Error::DroppedConnection)??; continue; }, packet = socket_in_rx.next() => { @@ -369,8 +369,8 @@ impl UdpPayloadInner { // Seems to happen with network reconnects like over // a lossy cellular network log::debug!("Quick reconnect: Due to socket timeout"); - let stream = Arc::new(connect_try_port(inner.inner.get_ref().local_addr()?.port()).await?); - inner = BcUdpSource::new_from_socket(stream, inner.addr).await?; + let stream = Arc::new(tokio::time::timeout(tokio::time::Duration::from_millis(250), connect_try_port(inner.inner.get_ref().local_addr()?.port())).await.map_err(|_| Error::DroppedConnection)??); + inner = tokio::time::timeout(tokio::time::Duration::from_millis(250), BcUdpSource::new_from_socket(stream, inner.addr)).await.map_err(|_| Error::DroppedConnection)??; // Inform the camera that we are the same client // diff --git a/src/mqtt/mod.rs b/src/mqtt/mod.rs index ca9f1c9..dafca57 100644 --- a/src/mqtt/mod.rs +++ b/src/mqtt/mod.rs @@ -374,24 +374,31 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R v = async { let (tx, mut rx) = mpsc(100); let v = tokio::select! { - v = camera_floodlight.run_passive_task(|cam| { - let tx = tx.clone(); - Box::pin( - async move { - let mut reciever = tokio_stream::wrappers::ReceiverStream::new(cam.listen_on_flightlight().await?); - while let Some(flights) = reciever.next().await { - for flight in flights.floodlight_status_list.iter() { - if flight.status == 0 { - tx.send(false).await?; - } else { - tx.send(true).await?; + v = async { + loop { + let r = camera_floodlight.run_passive_task(|cam| { + let tx = tx.clone(); + Box::pin( + async move { + let mut reciever = tokio_stream::wrappers::ReceiverStream::new(cam.listen_on_flightlight().await?); + while let Some(flights) = reciever.next().await { + for flight in flights.floodlight_status_list.iter() { + if flight.status == 0 { + tx.send(false).await?; + } else { + tx.send(true).await?; + } + } } + AnyResult::Ok(()) } - } - AnyResult::Ok(()) + ) + }).await; + if r.is_err() { + break r; } - ) - }) => v, + } + } => v, v = async { while let Some(on) = rx.recv().await { if on {