Seperate set and assign presets. Also add queury messages to mqtt

This commit is contained in:
QuantumEntangledAndy committed 2023-05-26 15:09:54 +07:00
1 parent 4628946514
commit 9524a1a9f7
7 files changed
+166 -32

No files matched your search

+3 -3
View File
@@ -583,7 +583,7 @@ pub struct PtzPreset {
pub channel_id: u8,
/// List of presets
#[yaserde(rename = "presetList")]
pub preset_list: Option<PresetList>,
pub preset_list: PresetList,
}
/// A preset list
@@ -597,11 +597,11 @@ pub struct PresetList {
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)]
pub struct Preset {
/// The ID of the preset
pub id: i8,
pub id: u8,
/// The preset name
pub name: Option<String>,
/// Command: Known values: `"toPos"` and `"setPos"`
pub command: Option<String>,
pub command: String,
}
/// A list of battery infos. This message is sent from the camera as
+63 -10
View File
@@ -129,21 +129,19 @@ impl BcCamera {
}
}
/// Set a PTZ preset. If a [name] is given the current position will be saved as a preset
/// with the given [preset_id] and [name], otherwise the camera will attempt to move to the
/// preset with the given ID.
pub async fn set_ptz_preset(&self, preset_id: i8, name: Option<String>) -> Result<()> {
/// Set a PTZ preset.
///
/// The current position will be saved as a preset with the given [preset_id] and [name]
pub async fn set_ptz_preset(&self, preset_id: u8, name: String) -> Result<()> {
self.has_ability_rw("control").await?;
let connection = self.get_connection();
let msg_num = self.new_message_num();
let mut sub_set = connection.subscribe(msg_num).await?;
let command = if name.is_some() { "setPos" } else { "toPos" };
let preset = Preset {
id: preset_id,
name,
command: Some(command.to_string()),
..Default::default()
name: Some(name),
command: "setPos".to_owned(),
};
let send = Bc {
meta: BcMeta {
@@ -162,9 +160,64 @@ impl BcCamera {
}),
payload: Some(BcPayloads::BcXml(BcXml {
ptz_preset: Some(PtzPreset {
preset_list: Some(PresetList {
preset_list: PresetList {
preset: vec![preset],
}),
},
..Default::default()
}),
..Default::default()
})),
}),
};
sub_set.send(send).await?;
let msg = sub_set.recv().await?;
if let BcMeta {
response_code: 200, ..
} = msg.meta
{
Ok(())
} else {
Err(Error::UnintelligibleReply {
reply: std::sync::Arc::new(Box::new(msg)),
why: "The camera did not accept the PtzPreset xml",
})
}
}
/// The camera will attempt to move to the preset with the given ID.
pub async fn moveto_ptz_preset(&self, preset_id: u8) -> Result<()> {
self.has_ability_rw("control").await?;
let connection = self.get_connection();
let msg_num = self.new_message_num();
let mut sub_set = connection.subscribe(msg_num).await?;
let preset = Preset {
id: preset_id,
name: None,
command: "toPos".to_owned(),
};
let send = Bc {
meta: BcMeta {
msg_id: MSG_ID_PTZ_CONTROL_PRESET,
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_preset: Some(PtzPreset {
preset_list: PresetList {
preset: vec![preset],
},
..Default::default()
}),
..Default::default()