diff --git a/crates/core/src/bc/model.rs b/crates/core/src/bc/model.rs index 168921e..aa43820 100644 --- a/crates/core/src/bc/model.rs +++ b/crates/core/src/bc/model.rs @@ -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; diff --git a/crates/core/src/bc/xml.rs b/crates/core/src/bc/xml.rs index c4144ca..a909cbd 100644 --- a/crates/core/src/bc/xml.rs +++ b/crates/core/src/bc/xml.rs @@ -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, + /// For zooming the camera + #[yaserde(rename = "StartZoomFocus")] + pub start_zoom_focus: Option, + /// Get the support xml + #[yaserde(rename = "Support")] + pub support: Option, } impl BcXml { @@ -969,6 +975,297 @@ pub struct AlarmDelay { pub def: Option, } +/// 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, + /// IO port number (output) + #[yaserde(rename = "IOOutputPortNum")] + pub io_output_port_num: Option, + #[yaserde(rename = "diskNum")] + /// Number of disks + pub disk_num: Option, + /// Number of video channels + #[yaserde(rename = "channelNum")] + pub channel_num: Option, + /// Number of audio channels + #[yaserde(rename = "audioNum")] + pub audio_num: Option, + /// The supported PTZ Mode: pt + #[yaserde(rename = "ptzMode")] + pub ptz_mode: Option, + /// PTZ cfg: 0 + #[yaserde(rename = "ptzCfg")] + pub ptz_cfg: Option, + /// Use b485 ptz + #[yaserde(rename = "")] + pub B485: Option, + /// Support autoupdate + #[yaserde(rename = "autoUpdate")] + pub auto_update: Option, + /// Support push notificaion alarms + #[yaserde(rename = "pushAlarm")] + pub push_alarm: Option, + /// Support ftp + pub ftp: Option, + /// Support test for ftp + #[yaserde(rename = "ftpTest")] + pub ftp_test: Option, + /// Support email notification + pub email: Option, + /// Support wifi connections + pub wifi: Option, + /// Support recording + pub record: Option, + /// Support test for wifi + #[yaserde(rename = "wifiTest")] + pub wifi_test: Option, + /// Support rtsp + pub rtsp: Option, + /// Support onvif + pub onvif: Option, + /// Support audio talk + #[yaserde(rename = "audioTalk")] + pub audio_talk: Option, + /// RF version + #[yaserde(rename = "rfVersion")] + pub rf_version: Option, + /// Support rtmp + pub rtmp: Option, + /// Has external stream + #[yaserde(rename = "noExternStream")] + pub no_extern_stream: Option, + /// Time format + #[yaserde(rename = "timeFormat")] + pub time_format: Option, + /// DDNS version + #[yaserde(rename = "ddnsVersion")] + pub ddns_version: Option, + /// Email version + #[yaserde(rename = "emailVersion")] + pub email_version: Option, + /// Push notification version + #[yaserde(rename = "pushVersion")] + pub push_version: Option, + /// Push notification type: 1 + #[yaserde(rename = "pushType")] + pub push_type: Option, + /// Support audio alarm + #[yaserde(rename = "audioAlarm")] + pub audio_alarm: Option, + /// Support AP + #[yaserde(rename = "apMode")] + pub ap_mode: Option, + /// Could version + #[yaserde(rename = "cloudVersion")] + pub cloud_version: Option, + /// Replay version + #[yaserde(rename = "replayVersion")] + pub replay_version: Option, + /// mobComVersion + #[yaserde(rename = "mobComVersion")] + pub mob_com_version: Option, + /// Export images + #[yaserde(rename = "ExportImport")] + pub export_import: Option, + /// Language version + #[yaserde(rename = "languageVer")] + pub language_ver: Option, + /// Video standard + #[yaserde(rename = "videoStandard")] + pub video_standard: Option, + /// Support sync time + #[yaserde(rename = "syncTime")] + pub sync_time: Option, + /// Support net port + #[yaserde(rename = "netPort")] + pub net_port: Option, + /// NAS version + #[yaserde(rename = "nasVersion")] + pub nas_version: Option, + /// Reboot required + #[yaserde(rename = "needReboot")] + pub need_reboot: Option, + /// Support reboot + pub reboot: Option, + /// Support Audio config + #[yaserde(rename = "audioCfg")] + pub audio_cfg: Option, + /// Support network diagnosis + #[yaserde(rename = "networkDiagnosis")] + pub network_diagnosis: Option, + /// Support height adjustment + #[yaserde(rename = "heightDiffAdjust")] + pub height_diff_adjust: Option, + /// Support upgrade + pub upgrade: Option, + /// Support GPS + pub gps: Option, + /// Support power save config + #[yaserde(rename = "powerSavingCfg")] + pub power_saving_cfg: Option, + /// Login Locked + #[yaserde(rename = "loginLocked")] + pub login_locked: Option, + /// View plan + #[yaserde(rename = "viewPlan")] + pub view_plan: Option, + /// Preview replay limit + #[yaserde(rename = "previewReplayLimit")] + pub preview_replay_limit: Option, + /// IOT link + #[yaserde(rename = "IOTLink")] + pub iot_link: Option, + /// IOT link maximum actions + #[yaserde(rename = "IOTLinkActionMax")] + pub iot_link_action_max: Option, + /// Support record config + #[yaserde(rename = "recordCfg")] + pub record_cfg: Option, + /// Has large battery + #[yaserde(rename = "largeBattery")] + pub large_battery: Option, + /// Smart home config + #[yaserde(rename = "smartHome")] + pub smart_home: Option, + /// Support config for specific channels + #[yaserde(rename = "item")] + pub items: Vec, +} + +/// 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, +} + +/// 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, + /// RF config + #[yaserde(rename = "rfCfg")] + pub rf_cfg: Option, + /// Support audio + #[yaserde(rename = "noAudio")] + pub no_audio: Option, + /// Support auto focus + #[yaserde(rename = "autoFocus")] + pub auto_focus: Option, + /// Support video clip + #[yaserde(rename = "videoClip")] + pub video_clip: Option, + /// Has battery + pub battery: Option, + /// ISP config + #[yaserde(rename = "ispCfg")] + pub isp_cfg: Option, + /// OSD config + #[yaserde(rename = "osdCfg")] + pub osd_cfg: Option, + /// Support battery analysis + #[yaserde(rename = "batAnalysis")] + pub bat_analysis: Option, + /// Supports dynamic resolution + #[yaserde(rename = "dynamicReso")] + pub dynamic_reso: Option, + /// Audio version + #[yaserde(rename = "audioVersion")] + pub audio_version: Option, + /// Supports LED control + #[yaserde(rename = "ledCtrl")] + pub led_ctrl: Option, + /// Supports PTZ Control + #[yaserde(rename = "ptzControl")] + pub ptz_control: Option, + /// Supports new ISP config + #[yaserde(rename = "newIspCfg")] + pub new_isp_cfg: Option, + /// Supports PTZ presets + #[yaserde(rename = "ptzPreset")] + pub ptz_preset: Option, + /// Supports PTZ patrol + #[yaserde(rename = "ptzPatrol")] + pub ptz_patrol: Option, + /// Supports PTZ Tattern + #[yaserde(rename = "ptzTattern")] + pub ptz_tattern: Option, + /// Supports Auto PT + #[yaserde(rename = "autoPt")] + pub auto_pt: Option, + /// H264 Profile: 7 + #[yaserde(rename = "h264Profile")] + pub h264_profile: Option, + /// Supports motion alarm + pub motion: Option, + /// AI Type + #[yaserde(rename = "aitype")] + pub ai_type: Option, + /// Animal AI Type + #[yaserde(rename = "aiAnimalType")] + pub ai_animal_type: Option, + /// Supports time lapse + pub timelapse: Option, + /// Supports snap + pub snap: Option, + /// Supports encoding control + #[yaserde(rename = "encCtrl")] + pub enc_ctrl: Option, + /// Has Zoom focus backlash + #[yaserde(rename = "zfBacklash")] + pub zf_backlash: Option, + /// Supports IOT Link Ability + #[yaserde(rename = "IOTLinkAbility")] + pub iot_link_ability: Option, + /// Supports IPC audio talk + #[yaserde(rename = "ipcAudioTalk")] + pub ipc_audio_talk: Option, + /// Supports Bino Config + #[yaserde(rename = "binoCfg")] + pub bino_cfg: Option, + /// Supports thumbnail + pub thumbnail: Option, +} + /// 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 2d1646e..844cc02 100644 --- a/crates/core/src/bc_protocol.rs +++ b/crates/core/src/bc_protocol.rs @@ -33,6 +33,7 @@ mod resolution; mod snap; mod stream; mod stream_info; +mod support; mod talk; mod time; mod uid; diff --git a/crates/core/src/bc_protocol/floodlight.rs b/crates/core/src/bc_protocol/floodlight.rs new file mode 100644 index 0000000..ec2cf94 --- /dev/null +++ b/crates/core/src/bc_protocol/floodlight.rs @@ -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> { + 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 { + 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(()) + } +} diff --git a/crates/core/src/bc_protocol/ptz.rs b/crates/core/src/bc_protocol/ptz.rs index 7e98e5c..9b7c5ac 100644 --- a/crates/core/src/bc_protocol/ptz.rs +++ b/crates/core/src/bc_protocol/ptz.rs @@ -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", + }) + } + } } diff --git a/crates/core/src/bc_protocol/support.rs b/crates/core/src/bc_protocol/support.rs new file mode 100644 index 0000000..20df452 --- /dev/null +++ b/crates/core/src/bc_protocol/support.rs @@ -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 { + 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", + }) + } + } +} diff --git a/dissector/baichuan.lua b/dissector/baichuan.lua index 7409f3b..e9b403f 100644 --- a/dissector/baichuan.lua +++ b/dissector/baichuan.lua @@ -183,12 +183,13 @@ local message_types = { [252]="", [253]="", [268]="", + [281]="", [282]="", [287]="", [272]="", [273]="", [274]="", - [299]="", + [291]="", [299]="", [319]="", [342]="", diff --git a/dissector/messages.md b/dissector/messages.md index 4ca9243..60ef45e 100644 --- a/dissector/messages.md +++ b/dissector/messages.md @@ -2270,6 +2270,143 @@ Message have zero to two payloads. ``` + This example payload is from a duel camera with zoom on the secondary camera + + ```xml + + 0 + 0 + 0 + 2 + 1 + pt + 0 + 0 + 1 + 3 + 0 + 1 + 1 + 0 + 0 + 1 + 0 + 0 + 1 + 4 + 0 + 1 + 1 + 1 + 3 + 1 + 1 + 1 + 0 + 127 + 20 + 3 + 3 + 0 + 0 + 0 + 1 + 7 + 0 + 1 + 1 + 0 + 2 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 48 + 53 + 0 + + 1 + + googleHome + 1 + + + amazonAlexa + 1 + + + + 0 + 3 + 0 + 0 + 0 + 0 + 2 + 195 + 1 + 1 + 1 + 63 + 10 + 207 + 22467 + 1 + 0 + 0 + 0 + 7 + 0 + 32503 + 1 + 3 + 20 + 0 + 0 + 747 + 1 + 0 + 2 + + + 1 + 3 + 0 + 0 + 0 + 0 + 2 + 195 + 1 + 1 + 0 + 63 + 10 + 223 + 22467 + 1 + 0 + 0 + 0 + 7 + 0 + 32503 + 1 + 3 + 28 + 0 + 0 + 747 + 1 + 0 + 2 + + + ``` + - 201: `` - Client @@ -2831,6 +2968,25 @@ Message have zero to two payloads. ``` +- 295: `` + + - Client + + - Extension: Usual extension xml with channel + + - Payload + + ```xml + + + + 1 + zoomPos + 2994 + + + ``` + - 299: `` (read) - Client: Standard payload with extension xml of the channel diff --git a/src/mqtt/mod.rs b/src/mqtt/mod.rs index d00cbd4..358262b 100644 --- a/src/mqtt/mod.rs +++ b/src/mqtt/mod.rs @@ -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::() { + 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", diff --git a/src/ptz/cmdline.rs b/src/ptz/cmdline.rs index 66d474e..d75fc6d 100644 --- a/src/ptz/cmdline.rs +++ b/src/ptz/cmdline.rs @@ -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, }, + Zoom { + /// The amount to zoom to + amount: f32, + }, } diff --git a/src/ptz/mod.rs b/src/ptz/mod.rs index 539dd6e..6f9c96f 100644 --- a/src/ptz/mod.rs +++ b/src/ptz/mod.rs @@ -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(()) diff --git a/src/rtsp/stream.rs b/src/rtsp/stream.rs index 8bf3d10..2b77c96 100644 --- a/src/rtsp/stream.rs +++ b/src/rtsp/stream.rs @@ -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?;