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(())
|
||||
}
|
||||
}
|
||||
@@ -184,6 +184,7 @@ local message_types = {
|
||||
[234]="UDP Keep Alive",
|
||||
[252]="<BatteryInfoList>",
|
||||
[253]="<BatteryInfo>",
|
||||
[263]="<audioPlayInfo>",
|
||||
[268]="<CloudBindInfo>",
|
||||
[281]="<BindNasInfoList>",
|
||||
[282]="<CloudLoginKey>",
|
||||
|
||||
@@ -2790,6 +2790,31 @@ Message have zero to two payloads.
|
||||
</body>
|
||||
```
|
||||
|
||||
- 264: `<audioPlayInfo>`
|
||||
|
||||
- Client: Usual header and extension xml with channel
|
||||
|
||||
- Payload
|
||||
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<body>
|
||||
<audioPlayInfo version="1.1">
|
||||
<channelId>0</channelId>
|
||||
<playMode>0</playMode>
|
||||
<playDuration>0</playDuration>
|
||||
<playTimes>1</playTimes>
|
||||
<onOff>0</onOff>
|
||||
</audioPlayInfo>
|
||||
</body>
|
||||
```
|
||||
|
||||
**Notes:** This is used to play the siren
|
||||
|
||||
- Camera:
|
||||
|
||||
Replies with standard OK message
|
||||
|
||||
- 264: `<audioCfg>` (write)
|
||||
|
||||
- Client
|
||||
|
||||
@@ -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",
|
||||
..
|
||||
|
||||
Reference in new issue
Block a user