Add basic zoom functalilty
This commit is contained in:
12 files changed
+812
-21
No files matched your search
@@ -51,6 +51,8 @@ pub const MSG_ID_STREAM_INFO_LIST: u32 = 146;
|
||||
pub const MSG_ID_ABILITY_INFO: u32 = 151;
|
||||
/// Get the available PTZ position presets
|
||||
pub const MSG_ID_GET_PTZ_PRESET: u32 = 190;
|
||||
/// Get the support details (ptz, talk et)
|
||||
pub const MSG_ID_GET_SUPPORT: u32 = 199;
|
||||
/// Will send the talk config for talk back data to follow this msg
|
||||
pub const MSG_ID_TALKCONFIG: u32 = 201;
|
||||
/// Used to send talk back binary data
|
||||
@@ -75,6 +77,8 @@ pub const MSG_ID_FLOODLIGHT_MANUAL: u32 = 288;
|
||||
pub const MSG_ID_FLOODLIGHT_TASKS_WRITE: u32 = 290;
|
||||
/// Floodlight status report from the camera
|
||||
pub const MSG_ID_FLOODLIGHT_STATUS_LIST: u32 = 291;
|
||||
/// Used for camera Zoom
|
||||
pub const MSG_ID_ZOOM_FOCUS: u32 = 295;
|
||||
/// Get the floodlight task xml
|
||||
pub const MSG_ID_FLOODLIGHT_TASKS_READ: u32 = 438;
|
||||
|
||||
|
||||
@@ -112,6 +112,12 @@ pub struct BcXml {
|
||||
/// The floodlight settings for automatically turning on/off on schedule/motion
|
||||
#[yaserde(rename = "FloodlightTask")]
|
||||
pub floodlight_task: Option<FloodlightTask>,
|
||||
/// For zooming the camera
|
||||
#[yaserde(rename = "StartZoomFocus")]
|
||||
pub start_zoom_focus: Option<StartZoomFocus>,
|
||||
/// Get the support xml
|
||||
#[yaserde(rename = "Support")]
|
||||
pub support: Option<Support>,
|
||||
}
|
||||
|
||||
impl BcXml {
|
||||
@@ -969,6 +975,297 @@ pub struct AlarmDelay {
|
||||
pub def: Option<u32>,
|
||||
}
|
||||
|
||||
/// StartZoomFocus xml
|
||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)]
|
||||
pub struct StartZoomFocus {
|
||||
/// XML Version
|
||||
#[yaserde(attribute)]
|
||||
pub version: String,
|
||||
/// Channel ID
|
||||
#[yaserde(rename = "channelId")]
|
||||
pub channel_id: u8,
|
||||
/// Command: Observed values: zoomPos
|
||||
pub command: String,
|
||||
/// Target Position: Observed Values: 2994, 2508, 2888, 3089, 3194, 3163
|
||||
#[yaserde(rename = "movePos")]
|
||||
pub move_pos: u32,
|
||||
}
|
||||
|
||||
/// Support xml
|
||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)]
|
||||
pub struct Support {
|
||||
/// XML Version
|
||||
#[yaserde(attribute)]
|
||||
pub version: String,
|
||||
/// IO port number (input)
|
||||
#[yaserde(rename = "IOInputPortNum")]
|
||||
pub io_input_port_num: Option<u32>,
|
||||
/// IO port number (output)
|
||||
#[yaserde(rename = "IOOutputPortNum")]
|
||||
pub io_output_port_num: Option<u32>,
|
||||
#[yaserde(rename = "diskNum")]
|
||||
/// Number of disks
|
||||
pub disk_num: Option<u32>,
|
||||
/// Number of video channels
|
||||
#[yaserde(rename = "channelNum")]
|
||||
pub channel_num: Option<u32>,
|
||||
/// Number of audio channels
|
||||
#[yaserde(rename = "audioNum")]
|
||||
pub audio_num: Option<u32>,
|
||||
/// The supported PTZ Mode: pt
|
||||
#[yaserde(rename = "ptzMode")]
|
||||
pub ptz_mode: Option<String>,
|
||||
/// PTZ cfg: 0
|
||||
#[yaserde(rename = "ptzCfg")]
|
||||
pub ptz_cfg: Option<u32>,
|
||||
/// Use b485 ptz
|
||||
#[yaserde(rename = "")]
|
||||
pub B485: Option<u32>,
|
||||
/// Support autoupdate
|
||||
#[yaserde(rename = "autoUpdate")]
|
||||
pub auto_update: Option<u32>,
|
||||
/// Support push notificaion alarms
|
||||
#[yaserde(rename = "pushAlarm")]
|
||||
pub push_alarm: Option<u32>,
|
||||
/// Support ftp
|
||||
pub ftp: Option<u32>,
|
||||
/// Support test for ftp
|
||||
#[yaserde(rename = "ftpTest")]
|
||||
pub ftp_test: Option<u32>,
|
||||
/// Support email notification
|
||||
pub email: Option<u32>,
|
||||
/// Support wifi connections
|
||||
pub wifi: Option<u32>,
|
||||
/// Support recording
|
||||
pub record: Option<u32>,
|
||||
/// Support test for wifi
|
||||
#[yaserde(rename = "wifiTest")]
|
||||
pub wifi_test: Option<u32>,
|
||||
/// Support rtsp
|
||||
pub rtsp: Option<u32>,
|
||||
/// Support onvif
|
||||
pub onvif: Option<u32>,
|
||||
/// Support audio talk
|
||||
#[yaserde(rename = "audioTalk")]
|
||||
pub audio_talk: Option<u32>,
|
||||
/// RF version
|
||||
#[yaserde(rename = "rfVersion")]
|
||||
pub rf_version: Option<u32>,
|
||||
/// Support rtmp
|
||||
pub rtmp: Option<u32>,
|
||||
/// Has external stream
|
||||
#[yaserde(rename = "noExternStream")]
|
||||
pub no_extern_stream: Option<u32>,
|
||||
/// Time format
|
||||
#[yaserde(rename = "timeFormat")]
|
||||
pub time_format: Option<u32>,
|
||||
/// DDNS version
|
||||
#[yaserde(rename = "ddnsVersion")]
|
||||
pub ddns_version: Option<u32>,
|
||||
/// Email version
|
||||
#[yaserde(rename = "emailVersion")]
|
||||
pub email_version: Option<u32>,
|
||||
/// Push notification version
|
||||
#[yaserde(rename = "pushVersion")]
|
||||
pub push_version: Option<u32>,
|
||||
/// Push notification type: 1
|
||||
#[yaserde(rename = "pushType")]
|
||||
pub push_type: Option<u32>,
|
||||
/// Support audio alarm
|
||||
#[yaserde(rename = "audioAlarm")]
|
||||
pub audio_alarm: Option<u32>,
|
||||
/// Support AP
|
||||
#[yaserde(rename = "apMode")]
|
||||
pub ap_mode: Option<u32>,
|
||||
/// Could version
|
||||
#[yaserde(rename = "cloudVersion")]
|
||||
pub cloud_version: Option<u32>,
|
||||
/// Replay version
|
||||
#[yaserde(rename = "replayVersion")]
|
||||
pub replay_version: Option<u32>,
|
||||
/// mobComVersion
|
||||
#[yaserde(rename = "mobComVersion")]
|
||||
pub mob_com_version: Option<u32>,
|
||||
/// Export images
|
||||
#[yaserde(rename = "ExportImport")]
|
||||
pub export_import: Option<u32>,
|
||||
/// Language version
|
||||
#[yaserde(rename = "languageVer")]
|
||||
pub language_ver: Option<u32>,
|
||||
/// Video standard
|
||||
#[yaserde(rename = "videoStandard")]
|
||||
pub video_standard: Option<u32>,
|
||||
/// Support sync time
|
||||
#[yaserde(rename = "syncTime")]
|
||||
pub sync_time: Option<u32>,
|
||||
/// Support net port
|
||||
#[yaserde(rename = "netPort")]
|
||||
pub net_port: Option<u32>,
|
||||
/// NAS version
|
||||
#[yaserde(rename = "nasVersion")]
|
||||
pub nas_version: Option<u32>,
|
||||
/// Reboot required
|
||||
#[yaserde(rename = "needReboot")]
|
||||
pub need_reboot: Option<u32>,
|
||||
/// Support reboot
|
||||
pub reboot: Option<u32>,
|
||||
/// Support Audio config
|
||||
#[yaserde(rename = "audioCfg")]
|
||||
pub audio_cfg: Option<u32>,
|
||||
/// Support network diagnosis
|
||||
#[yaserde(rename = "networkDiagnosis")]
|
||||
pub network_diagnosis: Option<u32>,
|
||||
/// Support height adjustment
|
||||
#[yaserde(rename = "heightDiffAdjust")]
|
||||
pub height_diff_adjust: Option<u32>,
|
||||
/// Support upgrade
|
||||
pub upgrade: Option<u32>,
|
||||
/// Support GPS
|
||||
pub gps: Option<u32>,
|
||||
/// Support power save config
|
||||
#[yaserde(rename = "powerSavingCfg")]
|
||||
pub power_saving_cfg: Option<u32>,
|
||||
/// Login Locked
|
||||
#[yaserde(rename = "loginLocked")]
|
||||
pub login_locked: Option<u32>,
|
||||
/// View plan
|
||||
#[yaserde(rename = "viewPlan")]
|
||||
pub view_plan: Option<u32>,
|
||||
/// Preview replay limit
|
||||
#[yaserde(rename = "previewReplayLimit")]
|
||||
pub preview_replay_limit: Option<u32>,
|
||||
/// IOT link
|
||||
#[yaserde(rename = "IOTLink")]
|
||||
pub iot_link: Option<u32>,
|
||||
/// IOT link maximum actions
|
||||
#[yaserde(rename = "IOTLinkActionMax")]
|
||||
pub iot_link_action_max: Option<u32>,
|
||||
/// Support record config
|
||||
#[yaserde(rename = "recordCfg")]
|
||||
pub record_cfg: Option<u32>,
|
||||
/// Has large battery
|
||||
#[yaserde(rename = "largeBattery")]
|
||||
pub large_battery: Option<u32>,
|
||||
/// Smart home config
|
||||
#[yaserde(rename = "smartHome")]
|
||||
pub smart_home: Option<SmartHome>,
|
||||
/// Support config for specific channels
|
||||
#[yaserde(rename = "item")]
|
||||
pub items: Vec<SupportItem>,
|
||||
}
|
||||
|
||||
/// List of smart home items
|
||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)]
|
||||
pub struct SmartHome {
|
||||
/// Versionm
|
||||
pub version: u32,
|
||||
/// The smarthome items
|
||||
#[yaserde(rename = "item")]
|
||||
pub items: Vec<SmartHomeItem>,
|
||||
}
|
||||
|
||||
/// Smart home items, are name:version pairs
|
||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)]
|
||||
pub struct SmartHomeItem {
|
||||
/// Name of item: Option<"googleHome">, "amazonAlexa"
|
||||
pub name: String,
|
||||
/// Version of item: 1
|
||||
pub ver: u32,
|
||||
}
|
||||
|
||||
/// Support Items for an individual channel
|
||||
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)]
|
||||
pub struct SupportItem {
|
||||
/// Channel ID of the item
|
||||
#[yaserde(rename = "chnID")]
|
||||
pub chn_id: u32,
|
||||
/// PTZ type of the channel
|
||||
#[yaserde(rename = "ptzType")]
|
||||
pub ptz_type: Option<u32>,
|
||||
/// RF config
|
||||
#[yaserde(rename = "rfCfg")]
|
||||
pub rf_cfg: Option<u32>,
|
||||
/// Support audio
|
||||
#[yaserde(rename = "noAudio")]
|
||||
pub no_audio: Option<u32>,
|
||||
/// Support auto focus
|
||||
#[yaserde(rename = "autoFocus")]
|
||||
pub auto_focus: Option<u32>,
|
||||
/// Support video clip
|
||||
#[yaserde(rename = "videoClip")]
|
||||
pub video_clip: Option<u32>,
|
||||
/// Has battery
|
||||
pub battery: Option<u32>,
|
||||
/// ISP config
|
||||
#[yaserde(rename = "ispCfg")]
|
||||
pub isp_cfg: Option<u32>,
|
||||
/// OSD config
|
||||
#[yaserde(rename = "osdCfg")]
|
||||
pub osd_cfg: Option<u32>,
|
||||
/// Support battery analysis
|
||||
#[yaserde(rename = "batAnalysis")]
|
||||
pub bat_analysis: Option<u32>,
|
||||
/// Supports dynamic resolution
|
||||
#[yaserde(rename = "dynamicReso")]
|
||||
pub dynamic_reso: Option<u32>,
|
||||
/// Audio version
|
||||
#[yaserde(rename = "audioVersion")]
|
||||
pub audio_version: Option<u32>,
|
||||
/// Supports LED control
|
||||
#[yaserde(rename = "ledCtrl")]
|
||||
pub led_ctrl: Option<u32>,
|
||||
/// Supports PTZ Control
|
||||
#[yaserde(rename = "ptzControl")]
|
||||
pub ptz_control: Option<u32>,
|
||||
/// Supports new ISP config
|
||||
#[yaserde(rename = "newIspCfg")]
|
||||
pub new_isp_cfg: Option<u32>,
|
||||
/// Supports PTZ presets
|
||||
#[yaserde(rename = "ptzPreset")]
|
||||
pub ptz_preset: Option<u32>,
|
||||
/// Supports PTZ patrol
|
||||
#[yaserde(rename = "ptzPatrol")]
|
||||
pub ptz_patrol: Option<u32>,
|
||||
/// Supports PTZ Tattern
|
||||
#[yaserde(rename = "ptzTattern")]
|
||||
pub ptz_tattern: Option<u32>,
|
||||
/// Supports Auto PT
|
||||
#[yaserde(rename = "autoPt")]
|
||||
pub auto_pt: Option<u32>,
|
||||
/// H264 Profile: 7
|
||||
#[yaserde(rename = "h264Profile")]
|
||||
pub h264_profile: Option<u32>,
|
||||
/// Supports motion alarm
|
||||
pub motion: Option<u32>,
|
||||
/// AI Type
|
||||
#[yaserde(rename = "aitype")]
|
||||
pub ai_type: Option<u32>,
|
||||
/// Animal AI Type
|
||||
#[yaserde(rename = "aiAnimalType")]
|
||||
pub ai_animal_type: Option<u32>,
|
||||
/// Supports time lapse
|
||||
pub timelapse: Option<u32>,
|
||||
/// Supports snap
|
||||
pub snap: Option<u32>,
|
||||
/// Supports encoding control
|
||||
#[yaserde(rename = "encCtrl")]
|
||||
pub enc_ctrl: Option<u32>,
|
||||
/// Has Zoom focus backlash
|
||||
#[yaserde(rename = "zfBacklash")]
|
||||
pub zf_backlash: Option<u32>,
|
||||
/// Supports IOT Link Ability
|
||||
#[yaserde(rename = "IOTLinkAbility")]
|
||||
pub iot_link_ability: Option<u32>,
|
||||
/// Supports IPC audio talk
|
||||
#[yaserde(rename = "ipcAudioTalk")]
|
||||
pub ipc_audio_talk: Option<u32>,
|
||||
/// Supports Bino Config
|
||||
#[yaserde(rename = "binoCfg")]
|
||||
pub bino_cfg: Option<u32>,
|
||||
/// Supports thumbnail
|
||||
pub thumbnail: Option<u32>,
|
||||
}
|
||||
|
||||
/// Convience function to return the xml version used throughout the library
|
||||
pub fn xml_ver() -> String {
|
||||
"1.1".to_string()
|
||||
|
||||
@@ -33,6 +33,7 @@ mod resolution;
|
||||
mod snap;
|
||||
mod stream;
|
||||
mod stream_info;
|
||||
mod support;
|
||||
mod talk;
|
||||
mod time;
|
||||
mod uid;
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
use tokio::sync::mpsc::{channel, Receiver};
|
||||
|
||||
use super::{BcCamera, Error, Result};
|
||||
use crate::bc::{model::*, xml::*};
|
||||
|
||||
impl BcCamera {
|
||||
/// Listen on the flood light update messages and return their XMLs
|
||||
pub async fn listen_on_flightlight(&self) -> Result<Receiver<FloodlightStatusList>> {
|
||||
let (tx, rx) = channel(3);
|
||||
let connection = self.get_connection();
|
||||
connection
|
||||
.handle_msg(MSG_ID_FLOODLIGHT_STATUS_LIST, move |bc| {
|
||||
let tx = tx.clone();
|
||||
Box::pin(async move {
|
||||
if let Bc {
|
||||
meta:
|
||||
BcMeta {
|
||||
msg_id: MSG_ID_FLOODLIGHT_STATUS_LIST,
|
||||
..
|
||||
},
|
||||
body:
|
||||
BcBody::ModernMsg(ModernMsg {
|
||||
payload:
|
||||
Some(BcPayloads::BcXml(BcXml {
|
||||
floodlight_status_list: Some(list),
|
||||
..
|
||||
})),
|
||||
..
|
||||
}),
|
||||
} = bc
|
||||
{
|
||||
let send_this: FloodlightStatusList = list.clone();
|
||||
let _ = tx.send(send_this).await;
|
||||
}
|
||||
None
|
||||
})
|
||||
})
|
||||
.await?;
|
||||
|
||||
Ok(rx)
|
||||
}
|
||||
|
||||
/// Set the floodlight status using the [FloodlightManual] xml
|
||||
pub async fn set_floodlight_manual(&self, state: bool, duration: u16) -> Result<()> {
|
||||
let connection = self.get_connection();
|
||||
|
||||
let msg_num = self.new_message_num();
|
||||
let mut sub_set = connection
|
||||
.subscribe(MSG_ID_FLOODLIGHT_MANUAL, msg_num)
|
||||
.await?;
|
||||
|
||||
let get = Bc {
|
||||
meta: BcMeta {
|
||||
msg_id: MSG_ID_FLOODLIGHT_MANUAL,
|
||||
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 {
|
||||
floodlight_manual: Some(FloodlightManual {
|
||||
version: "1".to_string(),
|
||||
channel_id: self.channel_id,
|
||||
status: match state {
|
||||
true => 1,
|
||||
false => 0,
|
||||
},
|
||||
duration,
|
||||
}),
|
||||
..Default::default()
|
||||
})),
|
||||
}),
|
||||
};
|
||||
|
||||
sub_set.send(get).await?;
|
||||
|
||||
if let Ok(reply) =
|
||||
tokio::time::timeout(tokio::time::Duration::from_micros(500), sub_set.recv()).await
|
||||
{
|
||||
let msg = reply?;
|
||||
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 Floodlight manual state",
|
||||
})
|
||||
}
|
||||
} else {
|
||||
// Some cameras seem to just not send a reply on success, so after 500ms we return Ok
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the Flood Light tasks XML
|
||||
pub async fn get_flightlight_tasks(&self) -> Result<FloodlightTask> {
|
||||
let connection = self.get_connection();
|
||||
let msg_num = self.new_message_num();
|
||||
let mut sub_get = connection
|
||||
.subscribe(MSG_ID_FLOODLIGHT_TASKS_READ, msg_num)
|
||||
.await?;
|
||||
let get = Bc {
|
||||
meta: BcMeta {
|
||||
msg_id: MSG_ID_FLOODLIGHT_TASKS_READ,
|
||||
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: None,
|
||||
}),
|
||||
};
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
if let BcBody::ModernMsg(ModernMsg {
|
||||
payload:
|
||||
Some(BcPayloads::BcXml(BcXml {
|
||||
floodlight_task: Some(xml),
|
||||
..
|
||||
})),
|
||||
..
|
||||
}) = msg.body
|
||||
{
|
||||
Ok(xml)
|
||||
} else {
|
||||
Err(Error::UnintelligibleReply {
|
||||
reply: std::sync::Arc::new(Box::new(msg)),
|
||||
why: "Expected FloodlightTask xml but it was not recieved",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the Flood Light tasks XML
|
||||
pub async fn set_flightlight_tasks(&self, new_xml: FloodlightTask) -> Result<()> {
|
||||
let connection = self.get_connection();
|
||||
let msg_num = self.new_message_num();
|
||||
let mut sub_get = connection
|
||||
.subscribe(MSG_ID_FLOODLIGHT_TASKS_WRITE, msg_num)
|
||||
.await?;
|
||||
let get = Bc {
|
||||
meta: BcMeta {
|
||||
msg_id: MSG_ID_FLOODLIGHT_TASKS_WRITE,
|
||||
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 {
|
||||
floodlight_task: Some(new_xml),
|
||||
..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(())
|
||||
}
|
||||
|
||||
/// Activate the Flood Light night mode
|
||||
pub async fn flightlight_tasks_enable(&self, state: bool) -> Result<()> {
|
||||
let mut curr_state = self.get_flightlight_tasks().await?;
|
||||
// println!("{:?}", pir_state);
|
||||
curr_state.enable = match state {
|
||||
true => 1,
|
||||
false => 0,
|
||||
};
|
||||
self.set_flightlight_tasks(curr_state).await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -12,10 +12,6 @@ pub enum Direction {
|
||||
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,
|
||||
/// To stop currently active PTZ command
|
||||
Stop,
|
||||
}
|
||||
@@ -33,12 +29,6 @@ impl BcCamera {
|
||||
Direction::Down => "down",
|
||||
Direction::Left => "left",
|
||||
Direction::Right => "right",
|
||||
Direction::In => {
|
||||
todo!()
|
||||
}
|
||||
Direction::Out => {
|
||||
todo!()
|
||||
}
|
||||
Direction::Stop => "stop",
|
||||
}
|
||||
.to_string();
|
||||
@@ -245,4 +235,55 @@ impl BcCamera {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// The camera will zoom to a given zoom amount.
|
||||
/// Not sure what the units for this are. Or how to get the min/max values
|
||||
pub async fn zoom_to(&self, zoom_pos: u32) -> 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_ID_ZOOM_FOCUS, msg_num).await?;
|
||||
let send = Bc {
|
||||
meta: BcMeta {
|
||||
msg_id: MSG_ID_ZOOM_FOCUS,
|
||||
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 {
|
||||
start_zoom_focus: Some(StartZoomFocus {
|
||||
version: xml_ver(),
|
||||
channel_id: self.channel_id,
|
||||
command: "zoomPos".to_string(),
|
||||
move_pos: zoom_pos,
|
||||
}),
|
||||
..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 StartZoomFocus xml",
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
use super::{BcCamera, Error, Result};
|
||||
use crate::bc::{model::*, xml::*};
|
||||
|
||||
impl BcCamera {
|
||||
/// Get the [Support] xml which contains the ptz/talk support
|
||||
///
|
||||
pub async fn get_support(&self) -> Result<Support> {
|
||||
let connection = self.get_connection();
|
||||
let msg_num = self.new_message_num();
|
||||
let mut sub_get = connection.subscribe(MSG_ID_GET_SUPPORT, msg_num).await?;
|
||||
let get = Bc {
|
||||
meta: BcMeta {
|
||||
msg_id: MSG_ID_GET_SUPPORT,
|
||||
channel_id: self.channel_id,
|
||||
msg_num,
|
||||
response_code: 0,
|
||||
stream_type: 0,
|
||||
class: 0x6414,
|
||||
},
|
||||
body: BcBody::ModernMsg(ModernMsg {
|
||||
extension: None,
|
||||
payload: None,
|
||||
}),
|
||||
};
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
if let BcBody::ModernMsg(ModernMsg {
|
||||
payload:
|
||||
Some(BcPayloads::BcXml(BcXml {
|
||||
support: Some(xml), ..
|
||||
})),
|
||||
..
|
||||
}) = msg.body
|
||||
{
|
||||
Ok(xml)
|
||||
} else {
|
||||
Err(Error::UnintelligibleReply {
|
||||
reply: std::sync::Arc::new(Box::new(msg)),
|
||||
why: "Expected Support xml but it was not recieved",
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -183,12 +183,13 @@ local message_types = {
|
||||
[252]="<BatteryInfoList>",
|
||||
[253]="<BatteryInfo>",
|
||||
[268]="<CloudBindInfo>",
|
||||
[281]="<BindNasInfoList>",
|
||||
[282]="<CloudLoginKey>",
|
||||
[287]="<TimeCfg>",
|
||||
[272]="<findAlarmVideo>",
|
||||
[273]="<alarmVideoInfo>",
|
||||
[274]="<findAlarmVideo>",
|
||||
[299]="<FloodlightStatusList>",
|
||||
[291]="<FloodlightStatusList>",
|
||||
[299]="<AiCfg>",
|
||||
[319]="<timelapseCfg>",
|
||||
[342]="<AiDetectCfg>",
|
||||
|
||||
@@ -2270,6 +2270,143 @@ Message have zero to two payloads.
|
||||
</body>
|
||||
```
|
||||
|
||||
This example payload is from a duel camera with zoom on the secondary camera
|
||||
|
||||
```xml
|
||||
<Support version=\"1.1\">
|
||||
<IOInputPortNum>0</IOInputPortNum>
|
||||
<IOOutputPortNum>0</IOOutputPortNum>
|
||||
<diskNum>0</diskNum>
|
||||
<channelNum>2</channelNum>
|
||||
<audioNum>1</audioNum>
|
||||
<ptzMode>pt</ptzMode>
|
||||
<ptzCfg>0</ptzCfg>
|
||||
<B485>0</B485>
|
||||
<autoUpdate>1</autoUpdate>
|
||||
<pushAlarm>3</pushAlarm>
|
||||
<ftp>0</ftp>
|
||||
<ftpTest>1</ftpTest>
|
||||
<email>1</email>
|
||||
<wifi>0</wifi>
|
||||
<record>0</record>
|
||||
<wifiTest>1</wifiTest>
|
||||
<rtsp>0</rtsp>
|
||||
<onvif>0</onvif>
|
||||
<audioTalk>1</audioTalk>
|
||||
<rfVersion>4</rfVersion>
|
||||
<rtmp>0</rtmp>
|
||||
<noExternStream>1</noExternStream>
|
||||
<timeFormat>1</timeFormat>
|
||||
<ddnsVersion>1</ddnsVersion>
|
||||
<emailVersion>3</emailVersion>
|
||||
<pushVersion>1</pushVersion>
|
||||
<pushType>1</pushType>
|
||||
<audioAlarm>1</audioAlarm>
|
||||
<apMode>0</apMode>
|
||||
<cloudVersion>127</cloudVersion>
|
||||
<replayVersion>20</replayVersion>
|
||||
<mobComVersion>3</mobComVersion>
|
||||
<ExportImport>3</ExportImport>
|
||||
<languageVer>0</languageVer>
|
||||
<videoStandard>0</videoStandard>
|
||||
<syncTime>0</syncTime>
|
||||
<netPort>1</netPort>
|
||||
<nasVersion>7</nasVersion>
|
||||
<needReboot>0</needReboot>
|
||||
<reboot>1</reboot>
|
||||
<audioCfg>1</audioCfg>
|
||||
<networkDiagnosis>0</networkDiagnosis>
|
||||
<heightDiffAdjust>2</heightDiffAdjust>
|
||||
<upgrade>1</upgrade>
|
||||
<gps>0</gps>
|
||||
<powerSavingCfg>0</powerSavingCfg>
|
||||
<loginLocked>0</loginLocked>
|
||||
<viewPlan>0</viewPlan>
|
||||
<previewReplayLimit>0</previewReplayLimit>
|
||||
<IOTLink>0</IOTLink>
|
||||
<IOTLinkActionMax>48</IOTLinkActionMax>
|
||||
<recordCfg>53</recordCfg>
|
||||
<largeBattery>0</largeBattery>
|
||||
<smartHome>
|
||||
<version>1</version>
|
||||
<item>
|
||||
<name>googleHome</name>
|
||||
<ver>1</ver>
|
||||
</item>
|
||||
<item>
|
||||
<name>amazonAlexa</name>
|
||||
<ver>1</ver>
|
||||
</item>
|
||||
</smartHome>
|
||||
<item>
|
||||
<chnID>0</chnID>
|
||||
<ptzType>3</ptzType>
|
||||
<rfCfg>0</rfCfg>
|
||||
<noAudio>0</noAudio>
|
||||
<autoFocus>0</autoFocus>
|
||||
<videoClip>0</videoClip>
|
||||
<battery>2</battery>
|
||||
<ispCfg>195</ispCfg>
|
||||
<osdCfg>1</osdCfg>
|
||||
<batAnalysis>1</batAnalysis>
|
||||
<dynamicReso>1</dynamicReso>
|
||||
<audioVersion>63</audioVersion>
|
||||
<ledCtrl>10</ledCtrl>
|
||||
<ptzControl>207</ptzControl>
|
||||
<newIspCfg>22467</newIspCfg>
|
||||
<ptzPreset>1</ptzPreset>
|
||||
<ptzPatrol>0</ptzPatrol>
|
||||
<ptzTattern>0</ptzTattern>
|
||||
<autoPt>0</autoPt>
|
||||
<h264Profile>7</h264Profile>
|
||||
<motion>0</motion>
|
||||
<aitype>32503</aitype>
|
||||
<aiAnimalType>1</aiAnimalType>
|
||||
<timelapse>3</timelapse>
|
||||
<snap>20</snap>
|
||||
<encCtrl>0</encCtrl>
|
||||
<zfBacklash>0</zfBacklash>
|
||||
<IOTLinkAbility>747</IOTLinkAbility>
|
||||
<ipcAudioTalk>1</ipcAudioTalk>
|
||||
<binoCfg>0</binoCfg>
|
||||
<thumbnail>2</thumbnail>
|
||||
</item>
|
||||
<item>
|
||||
<chnID>1</chnID>
|
||||
<ptzType>3</ptzType>
|
||||
<rfCfg>0</rfCfg>
|
||||
<noAudio>0</noAudio>
|
||||
<autoFocus>0</autoFocus>
|
||||
<videoClip>0</videoClip>
|
||||
<battery>2</battery>
|
||||
<ispCfg>195</ispCfg>
|
||||
<osdCfg>1</osdCfg>
|
||||
<batAnalysis>1</batAnalysis>
|
||||
<dynamicReso>0</dynamicReso>
|
||||
<audioVersion>63</audioVersion>
|
||||
<ledCtrl>10</ledCtrl>
|
||||
<ptzControl>223</ptzControl>
|
||||
<newIspCfg>22467</newIspCfg>
|
||||
<ptzPreset>1</ptzPreset>
|
||||
<ptzPatrol>0</ptzPatrol>
|
||||
<ptzTattern>0</ptzTattern>
|
||||
<autoPt>0</autoPt>
|
||||
<h264Profile>7</h264Profile>
|
||||
<motion>0</motion>
|
||||
<aitype>32503</aitype>
|
||||
<aiAnimalType>1</aiAnimalType>
|
||||
<timelapse>3</timelapse>
|
||||
<snap>28</snap>
|
||||
<encCtrl>0</encCtrl>
|
||||
<zfBacklash>0</zfBacklash>
|
||||
<IOTLinkAbility>747</IOTLinkAbility>
|
||||
<ipcAudioTalk>1</ipcAudioTalk>
|
||||
<binoCfg>0</binoCfg>
|
||||
<thumbnail>2</thumbnail>
|
||||
</item>
|
||||
</Support>
|
||||
```
|
||||
|
||||
- 201: `<TalkConfig>`
|
||||
|
||||
- Client
|
||||
@@ -2831,6 +2968,25 @@ Message have zero to two payloads.
|
||||
</body>
|
||||
```
|
||||
|
||||
- 295: `<StartZoomFocus>`
|
||||
|
||||
- Client
|
||||
|
||||
- Extension: Usual extension xml with channel
|
||||
|
||||
- Payload
|
||||
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<body>
|
||||
<StartZoomFocus version="1.1">
|
||||
<channelId>1</channelId>
|
||||
<command>zoomPos</command>
|
||||
<movePos>2994</movePos>
|
||||
</StartZoomFocus>
|
||||
</body>
|
||||
```
|
||||
|
||||
- 299: `<AiCfg>` (read)
|
||||
|
||||
- Client: Standard payload with extension xml of the channel
|
||||
|
||||
+32
-3
@@ -770,9 +770,40 @@ async fn handle_mqtt_message(
|
||||
.await
|
||||
.with_context(|| "Failed to publish reboot on the camera")?;
|
||||
}
|
||||
MqttReplyRef {
|
||||
topic: "control/",
|
||||
message,
|
||||
} => {
|
||||
let reply = if let Ok(amount) = message.parse::<f32>() {
|
||||
if let Err(e) = camera
|
||||
.run_task(|cam| {
|
||||
Box::pin(async move {
|
||||
cam.zoom_to((amount * 1000.0) as u32).await?;
|
||||
AnyResult::Ok(())
|
||||
})
|
||||
})
|
||||
.await
|
||||
{
|
||||
error!("Failed to send PTZ: {:?}", e);
|
||||
format!("FAIL: {e:?}")
|
||||
} else {
|
||||
"OK".to_string()
|
||||
}
|
||||
} else {
|
||||
"FAIL: Could not convert message to number".to_string()
|
||||
};
|
||||
|
||||
mqtt.send_message("control/zoom", &reply, false)
|
||||
.await
|
||||
.with_context(|| "Failed to publish zoom on the camera")?;
|
||||
}
|
||||
MqttReplyRef {
|
||||
topic: "control/ptz",
|
||||
message,
|
||||
}
|
||||
| MqttReplyRef {
|
||||
topic: "control/pt",
|
||||
message,
|
||||
} => {
|
||||
let lowercase_message = message.to_lowercase();
|
||||
let mut words = lowercase_message.split_whitespace();
|
||||
@@ -797,8 +828,6 @@ async fn handle_mqtt_message(
|
||||
"down" => Some(BcDirection::Down),
|
||||
"left" => Some(BcDirection::Left),
|
||||
"right" => Some(BcDirection::Right),
|
||||
"in" => Some(BcDirection::In),
|
||||
"out" => Some(BcDirection::Out),
|
||||
n => {
|
||||
error!("Unrecognized PTZ direction \"{}\"", n);
|
||||
None
|
||||
@@ -847,7 +876,7 @@ async fn handle_mqtt_message(
|
||||
|
||||
mqtt.send_message("control/ptz", &reply, false)
|
||||
.await
|
||||
.with_context(|| "Failed to publish reboot on the camera")?;
|
||||
.with_context(|| "Failed to publish ptz on the camera")?;
|
||||
}
|
||||
MqttReplyRef {
|
||||
topic: "control/ptz/preset",
|
||||
|
||||
+4
-2
@@ -6,8 +6,6 @@ pub enum CmdDirection {
|
||||
Right,
|
||||
Up,
|
||||
Down,
|
||||
In,
|
||||
Out,
|
||||
Stop,
|
||||
}
|
||||
|
||||
@@ -37,4 +35,8 @@ pub enum PtzCommand {
|
||||
/// The speed to move at
|
||||
speed: Option<u32>,
|
||||
},
|
||||
Zoom {
|
||||
/// The amount to zoom to
|
||||
amount: f32,
|
||||
},
|
||||
}
|
||||
+13
-2
@@ -90,8 +90,6 @@ pub(crate) async fn main(opt: Opt, reactor: NeoReactor) -> Result<()> {
|
||||
CmdDirection::Right => Direction::Right,
|
||||
CmdDirection::Up => Direction::Up,
|
||||
CmdDirection::Down => Direction::Down,
|
||||
CmdDirection::In => Direction::In,
|
||||
CmdDirection::Out => Direction::Out,
|
||||
CmdDirection::Stop => Direction::Stop,
|
||||
};
|
||||
let speed = speed.unwrap_or(32) as f32;
|
||||
@@ -120,6 +118,19 @@ pub(crate) async fn main(opt: Opt, reactor: NeoReactor) -> Result<()> {
|
||||
})
|
||||
.await?;
|
||||
}
|
||||
PtzCommand::Zoom { amount } => {
|
||||
camera
|
||||
.run_task(|cam| {
|
||||
Box::pin(async move {
|
||||
cam.zoom_to((amount * 1000.0) as u32)
|
||||
.await
|
||||
.context("Unable to execute PTZ move command")?;
|
||||
Ok(())
|
||||
})
|
||||
})
|
||||
.await?;
|
||||
sleep(Duration::from_secs(1)).await;
|
||||
}
|
||||
};
|
||||
|
||||
Ok(())
|
||||
|
||||
+3
-3
@@ -427,9 +427,9 @@ async fn stream_run(
|
||||
let thread_vid = vid.clone();
|
||||
let mut thread_client_count = client_count.subscribe();
|
||||
log::debug!("stream_config.fps: {}", stream_config.fps);
|
||||
let fallback_time = Duration::from_secs(3);
|
||||
let fallback_framerate =
|
||||
Duration::from_millis(1000u64 / std::cmp::max(stream_config.fps as u64, 5u64));
|
||||
// let fallback_time = Duration::from_secs(3);
|
||||
// let fallback_framerate =
|
||||
// Duration::from_millis(1000u64 / std::cmp::max(stream_config.fps as u64, 5u64));
|
||||
if let Some(thread_vid) = thread_vid {
|
||||
set.spawn(async move {
|
||||
thread_client_count.activate().await?;
|
||||
|
||||
Reference in new issue
Block a user