diff --git a/crates/core/src/bc/model.rs b/crates/core/src/bc/model.rs index 3353fe3..f416677 100644 --- a/crates/core/src/bc/model.rs +++ b/crates/core/src/bc/model.rs @@ -71,6 +71,8 @@ pub const MSG_ID_UDP_KEEP_ALIVE: u32 = 234; pub const MSG_ID_BATTERY_INFO_LIST: u32 = 252; /// Battery message initiaed by the client pub const MSG_ID_BATTERY_INFO: u32 = 253; +/// Used for to play sounds like the siren +pub const MSG_ID_PLAY_AUDIO: u32 = 263; /// Manual Floodlight Control pub const MSG_ID_FLOODLIGHT_MANUAL: u32 = 288; /// Set Floodlight tasks xml diff --git a/crates/core/src/bc/xml.rs b/crates/core/src/bc/xml.rs index 8b26a07..dccacba 100644 --- a/crates/core/src/bc/xml.rs +++ b/crates/core/src/bc/xml.rs @@ -121,6 +121,9 @@ pub struct BcXml { /// Get the support xml #[yaserde(rename = "Support")] pub support: Option, + /// Play a sound + #[yaserde(rename = "audioPlayInfo")] + pub audio_play_info: Option, } impl BcXml { @@ -1298,6 +1301,26 @@ pub struct SupportItem { pub thumbnail: Option, } +/// Instruct camera to play an audio alarm, usually this is the siren +#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)] +pub struct AudioPlayInfo { + /// Channel ID + #[yaserde(rename = "channelId")] + pub channel_id: u8, + /// Playmode: 0 + #[yaserde(rename = "playMode")] + pub play_mode: u32, + /// Duration: 0 + #[yaserde(rename = "playDuration")] + pub play_duration: u32, + /// Times to play: 1 + #[yaserde(rename = "playTimes")] + pub play_times: u32, + /// On or Off: 0 + #[yaserde(rename = "onOff")] + pub on_off: u32, +} + /// 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 844cc02..fd5447f 100644 --- a/crates/core/src/bc_protocol.rs +++ b/crates/core/src/bc_protocol.rs @@ -30,6 +30,7 @@ mod ptz; mod pushinfo; mod reboot; mod resolution; +mod siren; mod snap; mod stream; mod stream_info; diff --git a/crates/core/src/bc_protocol/siren.rs b/crates/core/src/bc_protocol/siren.rs new file mode 100644 index 0000000..5e664a4 --- /dev/null +++ b/crates/core/src/bc_protocol/siren.rs @@ -0,0 +1,47 @@ +//! Trigger for the siren + +use super::{BcCamera, Error, Result}; +use crate::bc::{model::*, xml::*}; + +impl BcCamera { + /// Trigger the siren + pub async fn siren(&self) -> Result<()> { + let connection = self.get_connection(); + let msg_num = self.new_message_num(); + let mut sub_get = connection.subscribe(MSG_ID_PLAY_AUDIO, msg_num).await?; + let get = Bc { + meta: BcMeta { + msg_id: MSG_ID_PLAY_AUDIO, + 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 { + audio_play_info: Some(AudioPlayInfo { + channel_id: self.channel_id, + play_mode: 0, + play_duration: 0, + play_times: 1, + on_off: 0, + }), + ..Default::default() + })), + }), + }; + + sub_get.send(get).await?; + let msg = sub_get.recv().await?; + if msg.meta.response_code != 200 { + return Err(Error::CameraServiceUnavaliable(msg.meta.response_code)); + } + + Ok(()) + } +} diff --git a/dissector/baichuan.lua b/dissector/baichuan.lua index d167a8d..eabddef 100644 --- a/dissector/baichuan.lua +++ b/dissector/baichuan.lua @@ -184,6 +184,7 @@ local message_types = { [234]="UDP Keep Alive", [252]="", [253]="", + [263]="", [268]="", [281]="", [282]="", diff --git a/dissector/messages.md b/dissector/messages.md index f5d78da..a2d28c7 100644 --- a/dissector/messages.md +++ b/dissector/messages.md @@ -2790,6 +2790,31 @@ Message have zero to two payloads. ``` +- 264: `` + + - Client: Usual header and extension xml with channel + + - Payload + + ```xml + + + + 0 + 0 + 0 + 1 + 0 + + + ``` + + **Notes:** This is used to play the siren + + - Camera: + + Replies with standard OK message + - 264: `` (write) - Client diff --git a/src/mqtt/mod.rs b/src/mqtt/mod.rs index 071c578..94d2e61 100644 --- a/src/mqtt/mod.rs +++ b/src/mqtt/mod.rs @@ -1115,6 +1115,29 @@ async fn handle_mqtt_message( .await .with_context(|| "Failed to publish floodlight_tasks")?; } + MqttReplyRef { + topic: "control/siren", + message: "on", + } => { + let res = camera + .run_task(|cam| { + Box::pin(async move { + cam.siren().await?; + AnyResult::Ok(()) + }) + }) + .await; + let reply = if let Err(e) = res { + error!("Failed to trigger siren: {:?}", e); + format!("FAIL: {e:?}") + } else { + "OK".to_string() + }; + + mqtt.send_message("control/siren", &reply, false) + .await + .with_context(|| "Failed to publish siren")?; + } MqttReplyRef { topic: "query/battery", ..