diff --git a/crates/core/src/bc/xml.rs b/crates/core/src/bc/xml.rs index 1aafe0a..8b26a07 100644 --- a/crates/core/src/bc/xml.rs +++ b/crates/core/src/bc/xml.rs @@ -112,6 +112,9 @@ pub struct BcXml { /// The floodlight settings for automatically turning on/off on schedule/motion #[yaserde(rename = "FloodlightTask")] pub floodlight_task: Option, + /// For geting the zoom anf focus of the camera + #[yaserde(rename = "PtzZoomFocus")] + pub ptz_zoom_focus: Option, /// For zooming the camera #[yaserde(rename = "StartZoomFocus")] pub start_zoom_focus: Option, @@ -975,6 +978,21 @@ pub struct AlarmDelay { pub def: Option, } +/// PtzZoomFocus xml +#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)] +pub struct PtzZoomFocus { + /// XML Version + #[yaserde(attribute)] + pub version: String, + /// Channel ID + #[yaserde(rename = "channelId")] + pub channel_id: u8, + /// Max, min and current zoom. (Read Only) + pub zoom: HelperPosition, + /// Max, min and current focus. (Read Only) + pub focus: HelperPosition, +} + /// StartZoomFocus xml #[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)] pub struct StartZoomFocus { @@ -985,14 +1003,10 @@ pub struct StartZoomFocus { #[yaserde(rename = "channelId")] pub channel_id: u8, /// Command: Observed values: zoomPos. (Write Only) - pub command: Option, + pub command: String, /// Target Position: Observed Values: 2994, 2508, 2888, 3089, 3194, 3163. (Write Only) #[yaserde(rename = "movePos")] - pub move_pos: Option, - /// Max, min and current zoom. (Read Only) - pub zoom: Option, - /// Max, min and current focus. (Read Only) - pub focus: Option, + pub move_pos: u32, } /// Helper for Max, Min, Curr pos of zoom/focus @@ -1000,13 +1014,13 @@ pub struct StartZoomFocus { pub struct HelperPosition { /// Max value #[yaserde(rename = "maxPos")] - pub maxPos: u32, + pub max_pos: u32, /// Min value #[yaserde(rename = "minPos")] - pub minPos: u32, + pub min_pos: u32, /// Curr value #[yaserde(rename = "curPos")] - pub curPos: u32, + pub cur_pos: u32, } /// Support xml diff --git a/crates/core/src/bc_protocol/ptz.rs b/crates/core/src/bc_protocol/ptz.rs index 8c8d746..985df32 100644 --- a/crates/core/src/bc_protocol/ptz.rs +++ b/crates/core/src/bc_protocol/ptz.rs @@ -238,14 +238,17 @@ impl BcCamera { /// The camera will zoom to a given zoom amount. /// Not sure what the units for this are, seems to be 1000 is 1x and 2000 is 2x - pub async fn zoom_to(&self, in_zoom_pos: u32) -> Result<()> { + pub async fn zoom_to(&self, zoom_pos: u32) -> Result<()> { + log::debug!("Setting to {}", zoom_pos); let current = self.get_zoom().await?; - let zoom_pos; - if let Some(zoom) = current.zoom { - zoom_pos = in_zoom_pos.clamp(zoom.minPos, zoom.maxPos); - } else { - zoom_pos = in_zoom_pos; - } + log::debug!( + " curr: {}, min: {}, max: {}", + current.zoom.cur_pos, + current.zoom.min_pos, + current.zoom.max_pos + ); + let zoom_pos = zoom_pos.clamp(current.zoom.min_pos, current.zoom.max_pos); + log::debug!("Clamped to {}", zoom_pos); self.has_ability_rw("control").await?; let connection = self.get_connection(); @@ -270,9 +273,8 @@ impl BcCamera { start_zoom_focus: Some(StartZoomFocus { version: xml_ver(), channel_id: self.channel_id, - command: Some("zoomPos".to_string()), - move_pos: Some(zoom_pos), - ..Default::default() + command: "zoomPos".to_string(), + move_pos: zoom_pos, }), ..Default::default() })), @@ -297,7 +299,7 @@ impl BcCamera { } /// Get the zoom xml, that has current min and max zoom values - pub async fn get_zoom(&self) -> Result { + pub async fn get_zoom(&self) -> Result { self.has_ability_ro("control").await?; let connection = self.get_connection(); let msg_num = self.new_message_num(); @@ -329,7 +331,7 @@ impl BcCamera { if let BcBody::ModernMsg(ModernMsg { payload: Some(BcPayloads::BcXml(BcXml { - start_zoom_focus: Some(xml), + ptz_zoom_focus: Some(xml), .. })), .. @@ -339,7 +341,7 @@ impl BcCamera { } else { Err(Error::UnintelligibleReply { reply: std::sync::Arc::new(Box::new(msg)), - why: "Expected StartZoomFocus xml but it was not recieved", + why: "Expected PtzZoomFocus xml but it was not recieved", }) } } diff --git a/dissector/messages.md b/dissector/messages.md index 0583e9a..f5d78da 100644 --- a/dissector/messages.md +++ b/dissector/messages.md @@ -2968,7 +2968,7 @@ Message have zero to two payloads. ``` -- 294: `` (Read) +- 294: `` (Read) - Client: Standard header and channel extension @@ -3173,12 +3173,18 @@ Message have zero to two payloads. ```xml + + +- 295: `` (Write) + + - Client + + - Extension: Usual extension xml with channel + + - Payload + + ```xml + - - 5 - 21 - 7 - 72403 - - - ``` \ No newline at end of file + + 1