From aee14bb4111d8a6b6e2db96bb2846aafb5046598 Mon Sep 17 00:00:00 2001 From: Daniel Kaiser Date: Sat, 13 May 2023 10:17:32 +0200 Subject: [PATCH 1/4] Add PTZ presets and PTZ command line --- crates/core/src/bc/model.rs | 4 ++ crates/core/src/bc/xml.rs | 38 ++++++++++- crates/core/src/bc_protocol/ptz.rs | 105 +++++++++++++++++++++++++++++ dissector/baichuan.lua | 1 + dissector/messages.md | 50 +++++++++++++- src/cmdline.rs | 1 + src/main.rs | 4 ++ src/ptz/cmdline.rs | 40 +++++++++++ src/ptz/mod.rs | 79 ++++++++++++++++++++++ 9 files changed, 320 insertions(+), 2 deletions(-) create mode 100644 src/ptz/cmdline.rs create mode 100644 src/ptz/mod.rs diff --git a/crates/core/src/bc/model.rs b/crates/core/src/bc/model.rs index 86a51e9..6961221 100644 --- a/crates/core/src/bc/model.rs +++ b/crates/core/src/bc/model.rs @@ -19,6 +19,8 @@ pub const MSG_ID_TALKABILITY: u32 = 10; pub const MSG_ID_TALKRESET: u32 = 11; /// PtzControl messages have this ID pub const MSG_ID_PTZ_CONTROL: u32 = 18; +/// PTZ goto preset position +pub const MSG_ID_PTZ_CONTROL_PRESET: u32 = 19; /// Reboot messages have this ID pub const MSG_ID_REBOOT: u32 = 23; /// Request motion detection messages @@ -35,6 +37,8 @@ pub const MSG_ID_GET_GENERAL: u32 = 104; pub const MSG_ID_ABILITY_INFO: u32 = 151; /// Setting general system info (clock mostly) messages have this ID pub const MSG_ID_SET_GENERAL: u32 = 105; +/// Get the available PTZ position presets +pub const MSG_ID_GET_PTZ_PRESET: u32 = 190; /// Will send the talk config for talk back data to follow this msg pub const MSG_ID_TALKCONFIG: u32 = 201; /// Used to send talk back binary data diff --git a/crates/core/src/bc/xml.rs b/crates/core/src/bc/xml.rs index f7aeafe..19b0cce 100644 --- a/crates/core/src/bc/xml.rs +++ b/crates/core/src/bc/xml.rs @@ -76,6 +76,9 @@ pub struct BcXml { /// Sent to move the camera #[yaserde(rename = "PtzControl")] pub ptz_control: Option, + /// Sent or received for the PTZ preset functionality + #[yaserde(rename = "PtzPreset")] + pub ptz_preset: Option, /// Recieved on login/low battery events #[yaserde(rename = "BatteryList")] pub battery_list: Option, @@ -519,10 +522,43 @@ pub struct PtzControl { pub channel_id: u8, /// The amount of movement to perform pub speed: f32, - /// The direction to transverse. Known directions: "right" + /// The direction to transverse. Known values are `"left"`, `"right"`, `"up"`, `"down"`, + /// `"leftUp"`, `"leftDown"`, `"rightUp"`, `"rightDown"` and `"stop"` pub command: String, } +/// An XML that describes a list of available PTZ presets +#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)] +pub struct PtzPreset { + /// XML Version + #[yaserde(attribute)] + pub version: String, + /// The channel ID. Usually zero unless from an NVR + #[yaserde(rename = "channelId")] + pub channel_id: u8, + /// List of presets + #[yaserde(rename = "presetList")] + pub preset_list: Option, +} + +/// A preset list +#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)] +pub struct PresetList { + /// List of Presets + pub preset: Vec, +} + +/// A preset. Either contains the ID and the name or the ID and the command +#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)] +pub struct Preset { + /// The ID of the preset + pub id: i8, + /// The preset name + pub name: Option, + /// Command: Known values: `"toPos"` and `"setPos"` + pub command: Option, +} + /// A list of battery infos. This message is sent from the camera as /// an event #[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)] diff --git a/crates/core/src/bc_protocol/ptz.rs b/crates/core/src/bc_protocol/ptz.rs index 3c925d3..0e08843 100644 --- a/crates/core/src/bc_protocol/ptz.rs +++ b/crates/core/src/bc_protocol/ptz.rs @@ -82,4 +82,109 @@ impl BcCamera { }) } } + + /// Get the [PtzPreset] XML which contains the list of the preset positions known to the camera + pub async fn get_ptz_preset(&self) -> Result { + self.has_ability_rw("control").await?; + let connection = self.get_connection(); + let msg_num = self.new_message_num(); + let mut sub_set = connection.subscribe(msg_num).await?; + + let send = Bc { + meta: BcMeta { + msg_id: MSG_ID_GET_PTZ_PRESET, + channel_id: self.channel_id, + msg_num, + response_code: 0, + stream_type: 0, + class: 0x6414, + }, + body: BcBody::ModernMsg(ModernMsg { + extension: Some(Extension { + channel_id: Some(self.channel_id), + ..Default::default() + }), + payload: None, + }), + }; + + sub_set.send(send).await?; + let msg = sub_set.recv().await?; + + if let BcBody::ModernMsg(ModernMsg { + payload: + Some(BcPayloads::BcXml(BcXml { + ptz_preset: Some(ptz_preset), + .. + })), + .. + }) = msg.body + { + Ok(ptz_preset) + } else { + Err(Error::UnintelligibleReply { + reply: std::sync::Arc::new(Box::new(msg)), + why: "The camera did not return a valid PtzPreset xml", + }) + } + } + + /// Set a PTZ preset. If a [name] is given the current position will be saved as a preset + /// with the given [preset_id] and [name], otherwise the camera will attempt to move to the + /// preset with the given ID. + pub async fn set_ptz_preset(&self, preset_id: i8, name: Option) -> Result<()> { + self.has_ability_rw("control").await?; + let connection = self.get_connection(); + let msg_num = self.new_message_num(); + let mut sub_set = connection.subscribe(msg_num).await?; + + let command = if name.is_some() { "setPos" } else { "toPos" }; + let preset = Preset { + id: preset_id, + name, + command: Some(command.to_string()), + ..Default::default() + }; + let send = Bc { + meta: BcMeta { + msg_id: MSG_ID_PTZ_CONTROL_PRESET, + channel_id: self.channel_id, + msg_num, + response_code: 0, + stream_type: 0, + class: 0x6414, + }, + + body: BcBody::ModernMsg(ModernMsg { + extension: Some(Extension { + channel_id: Some(self.channel_id), + ..Default::default() + }), + payload: Some(BcPayloads::BcXml(BcXml { + ptz_preset: Some(PtzPreset { + preset_list: Some(PresetList { + preset: vec![preset], + }), + ..Default::default() + }), + ..Default::default() + })), + }), + }; + + sub_set.send(send).await?; + let msg = sub_set.recv().await?; + + if let BcMeta { + response_code: 200, .. + } = msg.meta + { + Ok(()) + } else { + Err(Error::UnintelligibleReply { + reply: std::sync::Arc::new(Box::new(msg)), + why: "The camera did not accept the PtzPreset xml", + }) + } + } } diff --git a/dissector/baichuan.lua b/dissector/baichuan.lua index d5b2079..6111e96 100644 --- a/dissector/baichuan.lua +++ b/dissector/baichuan.lua @@ -88,6 +88,7 @@ local message_types = { [15]="", [16]="", [18]="", + [19]="", [23]="Reboot", [25]=" (write)", [26]="", -- diff --git a/dissector/messages.md b/dissector/messages.md index cc87cc4..7d5042f 100644 --- a/dissector/messages.md +++ b/dissector/messages.md @@ -354,6 +354,10 @@ Message have zero to two payloads. ``` + + - **Notes** : The known movement commands are `"left"`, `"right"`, `"up"`, `"down"`, `"leftUp"`, + `"leftDown"`, `"rightUp"`, `"rightDown"` and `"stop"` although the diagonal movement + does not seem to work. - Camera @@ -363,6 +367,45 @@ Message have zero to two payloads. |--------------|--------------|----------------|-------------------|-------------------|---------------|---------------| | 0a bc de f0 | 00 00 00 12 | 00 00 00 00 | 1e 00 00 00 | c8 00 | 00 00 | 00 00 00 00 | +- 19: `` + + - Client + + - Header + + | Magic | Message ID | Message Length | Encryption Offset | Status Code | Message Class | Payload Offset | + |--------------|-------------|----------------|-------------------|-------------------|---------------|---------------| + | 0a bc de f0 | 00 00 00 13 | 00 00 01 44 | 1e 00 00 00 | 00 00 | 64 14 | 00 00 00 00 | + + - Payload + + ```xml + + + + 0 + + + 0 + setPos + Test + + + + + ``` + + - **Notes** : The known values for command are `"setPos"` and `"toPos"` + + - Camera + + - Header + + | Magic | Message ID | Message Length | Encryption Offset | Status Code | Message Class | Payload Offset | + |--------------|-------------|----------------|-------------------|-------------------|---------------|---------------| + | 0a bc de f0 | 00 00 00 13 | 00 00 00 00 | 1e 00 00 00 | c8 00 | 00 00 | 00 00 00 00 | + + - 23: `Reboot` - Client @@ -1987,7 +2030,12 @@ Message have zero to two payloads. 0 - + + + 0 + Test + + ``` diff --git a/src/cmdline.rs b/src/cmdline.rs index ea2f319..6e47674 100644 --- a/src/cmdline.rs +++ b/src/cmdline.rs @@ -21,6 +21,7 @@ pub enum Command { StatusLight(super::statusled::Opt), Reboot(super::reboot::Opt), Pir(super::pir::Opt), + Ptz(super::ptz::Opt), Talk(super::talk::Opt), Mqtt(super::mqtt::Opt), Image(super::image::Opt), diff --git a/src/main.rs b/src/main.rs index efa9a3c..f20c6b4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,6 +34,7 @@ mod config; mod image; mod mqtt; mod pir; +mod ptz; mod reboot; mod rtsp; mod statusled; @@ -102,6 +103,9 @@ async fn main() -> Result<()> { Some(Command::Pir(opts)) => { pir::main(opts, config).await?; } + Some(Command::Ptz(opts)) => { + ptz::main(opts, config).await?; + } Some(Command::Talk(opts)) => { talk::main(opts, config).await?; } diff --git a/src/ptz/cmdline.rs b/src/ptz/cmdline.rs new file mode 100644 index 0000000..50b16dd --- /dev/null +++ b/src/ptz/cmdline.rs @@ -0,0 +1,40 @@ +use clap::Parser; + +#[derive(clap::ValueEnum, Clone, Debug)] +pub enum CmdDirection { + Left, + Right, + Up, + Down, + In, + Out, + Stop, +} + +/// The ptz command will control the positioning of the camera +#[derive(Parser, Debug)] +pub struct Opt { + /// The name of the camera to change the lights of. Must be a name in the config + pub camera: String, + + #[command(subcommand)] + pub cmd: PtzCommand, +} + +#[derive(Parser, Debug)] +pub enum PtzCommand { + /// Gets the available presets on the camera, moves the camera to a given preset ID or saves + /// the current position as a preset with name and ID. + Preset { + preset_id: Option, + name: Option, + }, + /// Performs a movement in the given direction + Control { + /// The time in milliseconds to move + duration: u32, + /// The direction command + #[clap(value_enum)] + command: CmdDirection, + }, +} diff --git a/src/ptz/mod.rs b/src/ptz/mod.rs new file mode 100644 index 0000000..8bf2846 --- /dev/null +++ b/src/ptz/mod.rs @@ -0,0 +1,79 @@ +/// +/// # Neolink PTZ Control +/// +/// This module handles the controls of the PTZ commands +/// +/// # Usage +/// +/// ```bash +/// # Rotate left for 300 milliseconds +/// neolink status-light --config=config.toml CameraName control 300 left +/// # Print the list of preset positions +/// neolink status-light --config=config.toml CameraName preset +/// # Move the camera to preset ID 0 +/// neolink status-light --config=config.toml CameraName preset 0 +/// # Save the current position as preset ID 0 with name PresetName +/// neolink status-light --config=config.toml CameraName preset 0 PresetName +/// ``` +/// +use anyhow::{Context, Result}; +use std::thread::sleep; +use std::time::Duration; + +mod cmdline; + +use super::config::Config; +use crate::ptz::cmdline::CmdDirection; +use crate::ptz::cmdline::PtzCommand; +use crate::utils::find_and_connect; +pub(crate) use cmdline::Opt; +use neolink_core::bc_protocol::Direction; + +/// Entry point for the ptz subcommand +/// +/// Opt is the command line options +pub(crate) async fn main(opt: Opt, config: Config) -> Result<()> { + let camera = find_and_connect(&config, &opt.camera).await?; + + match opt.cmd { + PtzCommand::Preset { preset_id, name } => { + if preset_id.is_some() { + camera + .set_ptz_preset(preset_id.unwrap(), name) + .await + .context("Unable to set PTZ preset") + .expect("TODO: panic message"); + } else { + let preset_list = camera + .get_ptz_preset() + .await + .context("Unable to get PTZ presets")?; + println!("Available presets:\nID Name"); + for preset in preset_list.preset_list.unwrap().preset { + println!("{:<2} {}", preset.id, preset.name.unwrap()); + } + } + } + PtzCommand::Control { duration, command } => { + let direction = match command { + CmdDirection::Left => Direction::Left, + CmdDirection::Right => Direction::Right, + CmdDirection::Up => Direction::Up, + CmdDirection::Down => Direction::Down, + CmdDirection::In => Direction::In, + CmdDirection::Out => Direction::Out, + CmdDirection::Stop => Direction::Stop, + }; + camera + .send_ptz(direction, 32_f32) + .await + .context("Unable to execute PTZ move command")?; + sleep(Duration::from_millis(duration as u64)); + camera + .send_ptz(Direction::Stop, 0_f32) + .await + .context("Unable to execute PTZ move command")?; + } + }; + Ok(()) +} From 27dc4c2bca9e1be102f68956fb4e573f920c8be5 Mon Sep 17 00:00:00 2001 From: Daniel Kaiser Date: Wed, 24 May 2023 19:11:52 +0200 Subject: [PATCH 2/4] Add control/preset command to mqtt --- README.md | 1 + src/mqtt/event_cam.rs | 9 +++++++++ src/mqtt/mod.rs | 16 ++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/README.md b/README.md index 948b186..8cde7cf 100644 --- a/README.md +++ b/README.md @@ -190,6 +190,7 @@ Control messages: - `/control/reboot` Reboot the camera - `/control/ptz [up|down|left|right|in|out]` (amount) Control the PTZ movements, amount defaults to 32.0 +- `/control/preset [id]` Move to PTZ preset `id` - `/control/pir [on|off]` Status Messages: diff --git a/src/mqtt/event_cam.rs b/src/mqtt/event_cam.rs index 91fde9f..98da733 100644 --- a/src/mqtt/event_cam.rs +++ b/src/mqtt/event_cam.rs @@ -30,6 +30,7 @@ pub(crate) enum Messages { PIROff, PIRQuery, Ptz(Direction), + Preset(i8), } #[derive(Debug, Copy, Clone)] @@ -449,6 +450,14 @@ impl<'a> MessageHandler<'a> { } } } + Messages::Preset(id) => { + if let Err(e) = self.camera.set_ptz_preset(id, None).await { + error = Some(format!("Failed to send PTZ preset: {:?}", e)); + "FAIL".to_string() + } else { + "OK".to_string() + } + } _ => "UNKNOWN COMMAND".to_string(), }; if let Some(replier) = replier { diff --git a/src/mqtt/mod.rs b/src/mqtt/mod.rs index 15e4ab0..4216674 100644 --- a/src/mqtt/mod.rs +++ b/src/mqtt/mod.rs @@ -14,6 +14,7 @@ /// - `/control/ir [on|off|auto]` Turn IR lights on/off or automatically via light detection /// - `/control/reboot` Reboot the camera /// - `/control/ptz` [up|down|left|right|in|out] (amount) Control the PTZ movements, amount defaults to 32.0 +/// - `/control/preset` [id] Move the camera to a known preset /// /// Status Messages: /// @@ -325,6 +326,21 @@ async fn handle_mqtt_message( error!("No PTZ Direction given. Please add up/down/left/right/in/out"); } } + MqttReplyRef { + topic: "control/preset", + message, + } => { + if let Ok(id) = message.parse::() { + reply = Some( + event_cam_sender + .send_message_with_reply(Messages::Preset(id)) + .await + .with_context(|| "Failed to send PTZ preset")?, + ); + } else { + error!("PTZ preset was not a valid number"); + } + } MqttReplyRef { topic: "control/pir", message: "on", From da3afe228edfc67c9b6b05243f6377e0b827a455 Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Thu, 25 May 2023 23:55:47 +0700 Subject: [PATCH 3/4] Use async sleep --- src/ptz/mod.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ptz/mod.rs b/src/ptz/mod.rs index 8bf2846..93f0923 100644 --- a/src/ptz/mod.rs +++ b/src/ptz/mod.rs @@ -17,8 +17,7 @@ /// ``` /// use anyhow::{Context, Result}; -use std::thread::sleep; -use std::time::Duration; +use tokio::time::{sleep, Duration}; mod cmdline; @@ -68,7 +67,7 @@ pub(crate) async fn main(opt: Opt, config: Config) -> Result<()> { .send_ptz(direction, 32_f32) .await .context("Unable to execute PTZ move command")?; - sleep(Duration::from_millis(duration as u64)); + sleep(Duration::from_millis(duration as u64)).await; camera .send_ptz(Direction::Stop, 0_f32) .await From 4628946514bad6809ac0b44144cb00f6a5ccef30 Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Fri, 26 May 2023 00:55:11 +0700 Subject: [PATCH 4/4] Use same amount model as in mqtt and add optional speed --- src/mqtt/event_cam.rs | 32 +++++++++++++------------------- src/mqtt/mod.rs | 15 ++++++++------- src/ptz/cmdline.rs | 6 ++++-- src/ptz/mod.rs | 25 +++++++++++++++++-------- 4 files changed, 42 insertions(+), 36 deletions(-) diff --git a/src/mqtt/event_cam.rs b/src/mqtt/event_cam.rs index 95e4839..6fc652b 100644 --- a/src/mqtt/event_cam.rs +++ b/src/mqtt/event_cam.rs @@ -511,27 +511,23 @@ impl<'a> MessageHandler<'a> { } } Messages::Ptz(direction) => { - let (bc_direction, amount, seconds) = match direction { - Direction::Up(amount, seconds) => { - (BcDirection::Up, amount, seconds) + let (bc_direction, speed, seconds) = match direction { + Direction::Up(speed, seconds) => (BcDirection::Up, speed, seconds), + Direction::Down(speed, seconds) => { + (BcDirection::Down, speed, seconds) } - Direction::Down(amount, seconds) => { - (BcDirection::Down, amount, seconds) + Direction::Left(speed, seconds) => { + (BcDirection::Left, speed, seconds) } - Direction::Left(amount, seconds) => { - (BcDirection::Left, amount, seconds) + Direction::Right(speed, seconds) => { + (BcDirection::Right, speed, seconds) } - Direction::Right(amount, seconds) => { - (BcDirection::Right, amount, seconds) - } - Direction::In(amount, seconds) => { - (BcDirection::In, amount, seconds) - } - Direction::Out(amount, seconds) => { - (BcDirection::Out, amount, seconds) + Direction::In(speed, seconds) => (BcDirection::In, speed, seconds), + Direction::Out(speed, seconds) => { + (BcDirection::Out, speed, seconds) } }; - if let Err(e) = self.camera.send_ptz(bc_direction, amount).await { + if let Err(e) = self.camera.send_ptz(bc_direction, speed).await { error = Some(format!("Failed to send PTZ: {:?}", e)); "FAIL".to_string() } else { @@ -539,9 +535,7 @@ impl<'a> MessageHandler<'a> { sleep(Duration::from_secs_f32(seconds)).await; // note that amount is not used in the stop command - if let Err(e) = - self.camera.send_ptz(BcDirection::Stop, amount).await - { + if let Err(e) = self.camera.send_ptz(BcDirection::Stop, 0.0).await { error = Some(format!("Failed to send PTZ: {:?}", e)); "FAIL".to_string() } else { diff --git a/src/mqtt/mod.rs b/src/mqtt/mod.rs index dab7b9e..d0b0056 100644 --- a/src/mqtt/mod.rs +++ b/src/mqtt/mod.rs @@ -333,9 +333,10 @@ async fn handle_mqtt_message( let mut words = lowercase_message.split_whitespace(); if let Some(direction_txt) = words.next() { // Target amount to move + let speed = 32f32; let amount = words.next().unwrap_or("32.0"); if let Ok(amount) = amount.parse::() { - let seconds = amount / 32f32; + let seconds = amount / speed; // range checking on seconds so that you can't sleep for 3.4E+38 seconds match seconds { x if (0.0..10.0).contains(&x) => seconds, @@ -346,12 +347,12 @@ async fn handle_mqtt_message( }; let direction = match direction_txt { - "up" => Direction::Up(amount, seconds), - "down" => Direction::Down(amount, seconds), - "left" => Direction::Left(amount, seconds), - "right" => Direction::Right(amount, seconds), - "in" => Direction::In(amount, seconds), - "out" => Direction::Out(amount, seconds), + "up" => Direction::Up(speed, seconds), + "down" => Direction::Down(speed, seconds), + "left" => Direction::Left(speed, seconds), + "right" => Direction::Right(speed, seconds), + "in" => Direction::In(speed, seconds), + "out" => Direction::Out(speed, seconds), _ => { error!("Unrecognized PTZ direction \"{}\"", direction_txt); return Ok(()); diff --git a/src/ptz/cmdline.rs b/src/ptz/cmdline.rs index 50b16dd..6e54a6d 100644 --- a/src/ptz/cmdline.rs +++ b/src/ptz/cmdline.rs @@ -31,10 +31,12 @@ pub enum PtzCommand { }, /// Performs a movement in the given direction Control { - /// The time in milliseconds to move - duration: u32, + /// The amount to move + amount: u32, /// The direction command #[clap(value_enum)] command: CmdDirection, + /// The speed to move at + speed: Option, }, } diff --git a/src/ptz/mod.rs b/src/ptz/mod.rs index 93f0923..58fe4ad 100644 --- a/src/ptz/mod.rs +++ b/src/ptz/mod.rs @@ -6,14 +6,16 @@ /// # Usage /// /// ```bash -/// # Rotate left for 300 milliseconds -/// neolink status-light --config=config.toml CameraName control 300 left +/// # Rotate left by 32 +/// neolink ptz --config=config.toml CameraName control 32 left +/// # Rotate left by 32 at speed 10 (speed not supported on most camera) +/// neolink ptz --config=config.toml CameraName control 32 left 10 /// # Print the list of preset positions -/// neolink status-light --config=config.toml CameraName preset +/// neolink ptz --config=config.toml CameraName preset /// # Move the camera to preset ID 0 -/// neolink status-light --config=config.toml CameraName preset 0 +/// neolink ptz --config=config.toml CameraName preset 0 /// # Save the current position as preset ID 0 with name PresetName -/// neolink status-light --config=config.toml CameraName preset 0 PresetName +/// neolink ptz --config=config.toml CameraName preset 0 PresetName /// ``` /// use anyhow::{Context, Result}; @@ -53,7 +55,11 @@ pub(crate) async fn main(opt: Opt, config: Config) -> Result<()> { } } } - PtzCommand::Control { duration, command } => { + PtzCommand::Control { + amount, + command, + speed, + } => { let direction = match command { CmdDirection::Left => Direction::Left, CmdDirection::Right => Direction::Right, @@ -63,11 +69,14 @@ pub(crate) async fn main(opt: Opt, config: Config) -> Result<()> { CmdDirection::Out => Direction::Out, CmdDirection::Stop => Direction::Stop, }; + let speed = speed.unwrap_or(32) as f32; + let seconds = amount as f32 / speed; + let duration = Duration::from_secs_f32(seconds); camera - .send_ptz(direction, 32_f32) + .send_ptz(direction, speed) .await .context("Unable to execute PTZ move command")?; - sleep(Duration::from_millis(duration as u64)).await; + sleep(duration).await; camera .send_ptz(Direction::Stop, 0_f32) .await