diff --git a/crates/core/src/bc/model.rs b/crates/core/src/bc/model.rs
index e19ef6b..d7de246 100644
--- a/crates/core/src/bc/model.rs
+++ b/crates/core/src/bc/model.rs
@@ -16,6 +16,8 @@ pub const MSG_ID_VIDEO_STOP: u32 = 4;
pub const MSG_ID_TALKABILITY: u32 = 10;
/// TalkReset messages have this ID
pub const MSG_ID_TALKRESET: u32 = 11;
+/// PtzControl messages have this ID
+pub const MSG_ID_PTZ_CONTROL: u32 = 18;
/// Reboot messages have this ID
pub const MSG_ID_REBOOT: u32 = 23;
/// Request motion detection messages
@@ -50,7 +52,7 @@ pub const EMPTY_LEGACY_PASSWORD: &str =
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
/// Top level bc message
-#[derive(Debug, PartialEq, Eq)]
+#[derive(Debug, PartialEq)]
pub struct Bc {
/// header part of the message
pub meta: BcMeta,
@@ -61,7 +63,7 @@ pub struct Bc {
///
/// The body of a bc message is either legacy or modern
///
-#[derive(Debug, PartialEq, Eq)]
+#[derive(Debug, PartialEq)]
#[allow(clippy::large_enum_variant)]
pub enum BcBody {
/// Legacy is unsupported except for login where it is used
@@ -86,7 +88,7 @@ pub enum BcBody {
/// `extension` or `payload` these are header only messages. This usually occurs to acknoledge receipt
/// of a command. In such cases the header `response_code` should be checked.
///
-#[derive(Debug, Default, PartialEq, Eq)]
+#[derive(Debug, Default, PartialEq)]
pub struct ModernMsg {
/// Extension describes the following payload such as which channel id it is for
pub extension: Option,
diff --git a/crates/core/src/bc/xml.rs b/crates/core/src/bc/xml.rs
index e5cc699..cd12fa2 100644
--- a/crates/core/src/bc/xml.rs
+++ b/crates/core/src/bc/xml.rs
@@ -10,7 +10,7 @@ use yaserde_derive::{YaDeserialize, YaSerialize};
use indoc::indoc;
/// There are two types of payloads xml and binary
-#[derive(PartialEq, Eq, Debug, YaDeserialize)]
+#[derive(PartialEq, Debug, YaDeserialize)]
#[yaserde(flatten)]
#[allow(clippy::large_enum_variant)]
pub enum BcPayloads {
@@ -31,7 +31,7 @@ impl Default for BcPayloads {
}
/// The top level BC Xml
-#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)]
+#[derive(PartialEq, Default, Debug, YaDeserialize, YaSerialize)]
#[yaserde(rename = "body")]
pub struct BcXml {
/// Encryption xml is received during login and contain the NONCE
@@ -73,6 +73,9 @@ pub struct BcXml {
/// Received when motion is detected
#[yaserde(rename = "AlarmEventList")]
pub alarm_event_list: Option,
+ /// Sent to move the camera
+ #[yaserde(rename = "PtzControl")]
+ pub ptz_control: Option,
}
impl BcXml {
@@ -445,6 +448,21 @@ pub struct AlarmEvent {
pub timeStamp: i32,
}
+/// The Ptz messages used to move the camera
+#[derive(PartialEq, Default, Debug, YaDeserialize, YaSerialize)]
+pub struct PtzControl {
+ /// XML Version
+ #[yaserde(attribute)]
+ pub version: String,
+ /// The channel the event occured on. Usually zero unless from an NVR
+ #[yaserde(rename = "channelId")]
+ pub channel_id: u8,
+ /// The amount of movement to perform
+ pub speed: f32,
+ /// The direction to transverse. Known directions: "right"
+ pub command: String,
+}
+
/// Convience function to return the xml version used throughout the library
pub fn xml_ver() -> String {
"1.1".to_string()
diff --git a/crates/core/src/bc_protocol.rs b/crates/core/src/bc_protocol.rs
index 8b3e3c6..d3e86ba 100644
--- a/crates/core/src/bc_protocol.rs
+++ b/crates/core/src/bc_protocol.rs
@@ -17,6 +17,7 @@ mod logout;
mod motion;
mod ping;
mod pirstate;
+mod ptz;
mod reboot;
mod resolution;
mod stream;
@@ -31,6 +32,7 @@ pub use errors::Error;
pub use ledstate::LightState;
pub use motion::{MotionData, MotionStatus};
pub use pirstate::PirState;
+pub use ptz::Direction;
pub use resolution::*;
use std::sync::Arc;
pub use stream::{Stream, StreamData};
diff --git a/crates/core/src/bc_protocol/motion.rs b/crates/core/src/bc_protocol/motion.rs
index 58cd7d9..bc3bf2f 100644
--- a/crates/core/src/bc_protocol/motion.rs
+++ b/crates/core/src/bc_protocol/motion.rs
@@ -68,9 +68,6 @@ impl MotionData {
Err(e) => return Err(Error::from(e)),
}
}
- for res in results.iter() {
- log::info!("Mption: {:?}", res);
- }
if let Some(last) = results.last() {
self.last_update = *last;
}
diff --git a/crates/core/src/bc_protocol/pirstate.rs b/crates/core/src/bc_protocol/pirstate.rs
index b02f798..aae4c91 100644
--- a/crates/core/src/bc_protocol/pirstate.rs
+++ b/crates/core/src/bc_protocol/pirstate.rs
@@ -3,7 +3,7 @@ use crate::bc::{model::*, xml::*};
impl BcCamera {
/// Get the [RfAlarmCfg] xml which contains the PIR status of the camera
- pub fn get_pirstate(&mut self) -> Result {
+ pub fn get_pirstate(&self) -> Result {
let connection = self.get_connection();
let msg_num = self.new_message_num();
let sub_get = connection.subscribe(msg_num)?;
@@ -50,7 +50,7 @@ impl BcCamera {
}
/// Set the PIR sensor using the [RfAlarmCfg] xml
- pub fn set_pirstate(&mut self, rf_alarm_cfg: RfAlarmCfg) -> Result<()> {
+ pub fn set_pirstate(&self, rf_alarm_cfg: RfAlarmCfg) -> Result<()> {
let connection = self.get_connection();
let msg_num = self.new_message_num();
let sub_set = connection.subscribe(msg_num)?;
@@ -97,7 +97,7 @@ impl BcCamera {
/// This is a convience function to control the PIR status
/// True is on and false is off
- pub fn pir_set(&mut self, state: bool) -> Result<()> {
+ pub fn pir_set(&self, state: bool) -> Result<()> {
let mut pir_state = self.get_pirstate()?;
// println!("{:?}", pir_state);
pir_state.enable = match state {
diff --git a/crates/core/src/bc_protocol/ptz.rs b/crates/core/src/bc_protocol/ptz.rs
new file mode 100644
index 0000000..252cbb2
--- /dev/null
+++ b/crates/core/src/bc_protocol/ptz.rs
@@ -0,0 +1,81 @@
+use super::{BcCamera, Error, Result, RX_TIMEOUT};
+use crate::bc::{model::*, xml::*};
+
+/// Directions used for Ptz
+pub enum Direction {
+ /// To move the camera Up
+ Up,
+ /// To move the camera Down
+ Down,
+ /// To move the camera Left
+ Left,
+ /// To move the camera Right
+ Right,
+ /// To zoom the camera In (may be done with cropping depending on camera model)
+ In,
+ /// To zoom the camera Out (may be done with cropping depending on camera model)
+ Out,
+}
+
+impl BcCamera {
+ /// Send a PTZ message to the camera
+ pub fn send_ptz(&self, direction: Direction, amount: f32) -> Result<()> {
+ let connection = self.get_connection();
+ let msg_num = self.new_message_num();
+ let sub_set = connection.subscribe(msg_num)?;
+
+ let direction_str = match direction {
+ Direction::Up => "up",
+ Direction::Down => "down",
+ Direction::Left => "left",
+ Direction::Right => "right",
+ Direction::In => {
+ unimplemented!()
+ }
+ Direction::Out => {
+ unimplemented!()
+ }
+ }
+ .to_string();
+ let send = Bc {
+ meta: BcMeta {
+ msg_id: MSG_ID_PTZ_CONTROL,
+ 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_control: Some(PtzControl {
+ version: xml_ver(),
+ channel_id: self.channel_id,
+ speed: amount,
+ command: direction_str,
+ }),
+ ..Default::default()
+ })),
+ }),
+ };
+
+ sub_set.send(send)?;
+ let msg = sub_set.rx.recv_timeout(RX_TIMEOUT)?;
+
+ if let BcMeta {
+ response_code: 200, ..
+ } = msg.meta
+ {
+ Ok(())
+ } else {
+ Err(Error::UnintelligibleReply {
+ reply: Box::new(msg),
+ why: "The camera did not accept the PtzControl xml",
+ })
+ }
+ }
+}
diff --git a/dissector/messages.md b/dissector/messages.md
index bc0ff2e..cc87cc4 100644
--- a/dissector/messages.md
+++ b/dissector/messages.md
@@ -2182,7 +2182,7 @@ Message have zero to two payloads.
- Client
- Extension
-
+
```xml
@@ -2190,7 +2190,7 @@ Message have zero to two payloads.
```
- - Payload
+ - Payload
```xml
@@ -2480,7 +2480,7 @@ Message have zero to two payloads.
0
1
- 1
+ 1
2
0
300
@@ -2522,4 +2522,41 @@ Message have zero to two payloads.
none
+
+
+ 0
+ chargeComplete
+ solarPanel
+ 3999
+ 0
+ 21
+ 100
+ 0
+ 2
+
+
+