Add the siren.rs
This commit is contained in:
7 files changed
+122
No files matched your search
@@ -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
|
||||
|
||||
@@ -121,6 +121,9 @@ pub struct BcXml {
|
||||
/// Get the support xml
|
||||
#[yaserde(rename = "Support")]
|
||||
pub support: Option<Support>,
|
||||
/// Play a sound
|
||||
#[yaserde(rename = "audioPlayInfo")]
|
||||
pub audio_play_info: Option<AudioPlayInfo>,
|
||||
}
|
||||
|
||||
impl BcXml {
|
||||
@@ -1298,6 +1301,26 @@ pub struct SupportItem {
|
||||
pub thumbnail: Option<u32>,
|
||||
}
|
||||
|
||||
/// 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()
|
||||
|
||||
@@ -30,6 +30,7 @@ mod ptz;
|
||||
mod pushinfo;
|
||||
mod reboot;
|
||||
mod resolution;
|
||||
mod siren;
|
||||
mod snap;
|
||||
mod stream;
|
||||
mod stream_info;
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user