From f4d7bebbf1904a8c987be45ab17e243560e79898 Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Wed, 1 Mar 2023 10:09:19 +0700 Subject: [PATCH 1/9] Added battery info commands --- crates/core/src/bc/model.rs | 4 + crates/core/src/bc/xml.rs | 47 ++++++++++ crates/core/src/bc_protocol.rs | 2 + crates/core/src/bc_protocol/battery.rs | 114 +++++++++++++++++++++++++ 4 files changed, 167 insertions(+) create mode 100644 crates/core/src/bc_protocol/battery.rs diff --git a/crates/core/src/bc/model.rs b/crates/core/src/bc/model.rs index 46ee38a..141c84f 100644 --- a/crates/core/src/bc/model.rs +++ b/crates/core/src/bc/model.rs @@ -47,6 +47,10 @@ pub const MSG_ID_GET_LED_STATUS: u32 = 208; pub const MSG_ID_SET_LED_STATUS: u32 = 209; /// UDP Keep alive pub const MSG_ID_UDP_KEEP_ALIVE: u32 = 234; +/// Battery message initiaed by the camera +pub const MSG_ID_BATTERY_INFO_LIST: u32 = 252; +/// Battery message initiaed by the client +pub const MSG_ID_BATTERY_INFO: u32 = 253; /// An empty password in legacy format pub const EMPTY_LEGACY_PASSWORD: &str = diff --git a/crates/core/src/bc/xml.rs b/crates/core/src/bc/xml.rs index cd12fa2..1ed7ea0 100644 --- a/crates/core/src/bc/xml.rs +++ b/crates/core/src/bc/xml.rs @@ -76,6 +76,12 @@ pub struct BcXml { /// Sent to move the camera #[yaserde(rename = "PtzControl")] pub ptz_control: Option, + /// Recieved on login/low battery events + #[yaserde(rename = "BatteryList")] + pub battery_list: Option, + /// Recieved on request for battery info + #[yaserde(rename = "BatteryInfo")] + pub battery_info: Option, } impl BcXml { @@ -463,6 +469,47 @@ pub struct PtzControl { pub command: String, } +/// A list of battery infos. This message is sent from the camera as +/// an event +#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)] +pub struct BatteryList { + /// XML Version + #[yaserde(attribute)] + pub version: String, + /// Battery info items + #[yaserde(rename = "BatteryInfo")] + pub battery_info: Vec, +} + +/// The individual battery info +#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)] +pub struct BatteryInfo { + /// The channel the for the camera usually 0 + #[yaserde(rename = "channelId")] + pub channel_id: u8, + /// Charge status known values, "chargeComplete", "charging", + #[yaserde(rename = "chargeStatus")] + pub charge_status: String, + /// Status of charging port known values: "solarPanel" + #[yaserde(rename = "adapterStatus")] + pub adapter_status: String, + /// Voltage + pub voltage: u32, + /// Current + pub current: u32, + /// Temperture + pub temperature: u32, + /// % charge from 0-100 + #[yaserde(rename = "batteryPercent")] + pub battery_percent: u32, + /// Low power flag. Known values 0, 1 (0=false) + #[yaserde(rename = "lowPower")] + pub low_power: u32, + /// Battery version info: Known values 2 + #[yaserde(rename = "batteryVersion")] + pub battery_version: u32, +} + /// 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 5cdc3a6..669c0e0 100644 --- a/crates/core/src/bc_protocol.rs +++ b/crates/core/src/bc_protocol.rs @@ -6,6 +6,7 @@ use std::sync::atomic::{AtomicBool, AtomicU16, Ordering}; use Md5Trunc::*; +mod battery; mod connection; mod credentials; mod errors; @@ -306,6 +307,7 @@ impl BcCamera { credentials: Credentials::new(username, passwd), }; me.keepalive().await?; + me.monitor_battery().await?; Ok(me) } diff --git a/crates/core/src/bc_protocol/battery.rs b/crates/core/src/bc_protocol/battery.rs new file mode 100644 index 0000000..ae2dec0 --- /dev/null +++ b/crates/core/src/bc_protocol/battery.rs @@ -0,0 +1,114 @@ +//! Handles battery related messages +//! +//! There are primarily two messages: +//! - BatteryInfoList which the camera sends as part of its login info +//! - BatteryInfo which the client can request on demand +//! + +use super::{BcCamera, Result}; +use crate::{ + bc::{model::*, xml::BatteryInfo}, + Error, +}; +use log::*; + +impl BcCamera { + /// Create a handller to respond to battery messages + /// These messages are sent by the camera on login and maybe + /// also on low battery events + pub async fn monitor_battery(&self) -> Result<()> { + let connection = self.get_connection(); + connection + .handle_msg(MSG_ID_BATTERY_INFO_LIST, |bc| { + if let Bc { + body: + BcBody::ModernMsg(ModernMsg { + payload: + Some(BcPayloads::BcXml(BcXml { + battery_list: Some(battery_list), + .. + })), + .. + }), + .. + } = bc + { + for battery in battery_list.battery_info.iter() { + info!( + "==Battery==\n\ + Charge: {}%,\n\ + Temperature: {}°C,\n\ + LowPower: {},\n\ + Adapter: {},\n\ + ChargeStatus: {},\n\ + ", + battery.battery_percent, + battery.temperature, + if battery.low_power == 1 { + "true" + } else { + "false" + }, + battery.adapter_status, + battery.charge_status, + ); + } + } + None + }) + .await?; + Ok(()) + } + + /// Requests the current battery status of the camera + pub async fn battery_info(&self) -> Result { + let connection = self.get_connection(); + + let msg_num = self.new_message_num(); + let mut sub = connection.subscribe(msg_num).await?; + + let msg = Bc { + meta: BcMeta { + msg_id: MSG_ID_BATTERY_INFO, + channel_id: self.channel_id, + msg_num, + stream_type: 0, + response_code: 0, + class: 0x6414, + }, + body: BcBody::ModernMsg(ModernMsg { + extension: Some(Extension { + channel_id: Some(self.channel_id), + ..Default::default() + }), + payload: None, + }), + }; + + sub.send(msg).await?; + let msg = sub.recv().await?; + + if let Bc { + meta: BcMeta { + response_code: 200, .. + }, + body: + BcBody::ModernMsg(ModernMsg { + payload: + Some(BcPayloads::BcXml(BcXml { + battery_info: Some(battery_info), + .. + })), + .. + }), + } = msg + { + Ok(battery_info) + } else { + Err(Error::UnintelligibleReply { + reply: std::sync::Arc::new(Box::new(msg)), + why: "The camera did not accept the battery info (maybe no battery) command.", + }) + } + } +} From 8d3c0af7af685606c855289f09d4dcde8a152cb9 Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Wed, 1 Mar 2023 10:16:07 +0700 Subject: [PATCH 2/9] Added default-run --- Cargo.toml | 1 + crates/core/src/bc/xml.rs | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e16da8c..ce53421 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ description = "A standards-compliant bridge to Reolink IP cameras" version = "0.5.4" authors = ["George Hilliard ", "Andrew King "] edition = "2018" +default-run = "neolink" [workspace] members = [ diff --git a/crates/core/src/bc/xml.rs b/crates/core/src/bc/xml.rs index 1ed7ea0..b7bb174 100644 --- a/crates/core/src/bc/xml.rs +++ b/crates/core/src/bc/xml.rs @@ -487,7 +487,7 @@ pub struct BatteryInfo { /// The channel the for the camera usually 0 #[yaserde(rename = "channelId")] pub channel_id: u8, - /// Charge status known values, "chargeComplete", "charging", + /// Charge status known values, "chargeComplete", "charging", "none", #[yaserde(rename = "chargeStatus")] pub charge_status: String, /// Status of charging port known values: "solarPanel" @@ -510,6 +510,9 @@ pub struct BatteryInfo { pub battery_version: u32, } +/// , +} + /// Convience function to return the xml version used throughout the library pub fn xml_ver() -> String { "1.1".to_string() @@ -677,6 +680,4 @@ fn test_binary_deser() { binary_data: Some(1), .. } => {} - _ => panic!(), - } -} + _ => panic!(), \ No newline at end of file From 52c4515e622fa3043f05ce9883b7b066b5f0eab3 Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Wed, 1 Mar 2023 10:16:07 +0700 Subject: [PATCH 3/9] Revert "Added default-run" This reverts commit c54f62d79c56f30c0b18d290171c7b8864774af1. --- Cargo.toml | 1 - crates/core/src/bc/xml.rs | 9 ++++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ce53421..e16da8c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,6 @@ description = "A standards-compliant bridge to Reolink IP cameras" version = "0.5.4" authors = ["George Hilliard ", "Andrew King "] edition = "2018" -default-run = "neolink" [workspace] members = [ diff --git a/crates/core/src/bc/xml.rs b/crates/core/src/bc/xml.rs index b7bb174..1ed7ea0 100644 --- a/crates/core/src/bc/xml.rs +++ b/crates/core/src/bc/xml.rs @@ -487,7 +487,7 @@ pub struct BatteryInfo { /// The channel the for the camera usually 0 #[yaserde(rename = "channelId")] pub channel_id: u8, - /// Charge status known values, "chargeComplete", "charging", "none", + /// Charge status known values, "chargeComplete", "charging", #[yaserde(rename = "chargeStatus")] pub charge_status: String, /// Status of charging port known values: "solarPanel" @@ -510,9 +510,6 @@ pub struct BatteryInfo { pub battery_version: u32, } -/// , -} - /// Convience function to return the xml version used throughout the library pub fn xml_ver() -> String { "1.1".to_string() @@ -680,4 +677,6 @@ fn test_binary_deser() { binary_data: Some(1), .. } => {} - _ => panic!(), \ No newline at end of file + _ => panic!(), + } +} From 19c2031691f3c2f21832d23f89395c619d3ed816 Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Wed, 1 Mar 2023 12:55:07 +0700 Subject: [PATCH 4/9] Added default-run --- Cargo.toml | 1 + crates/core/src/bc/xml.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index e16da8c..ce53421 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ description = "A standards-compliant bridge to Reolink IP cameras" version = "0.5.4" authors = ["George Hilliard ", "Andrew King "] edition = "2018" +default-run = "neolink" [workspace] members = [ diff --git a/crates/core/src/bc/xml.rs b/crates/core/src/bc/xml.rs index 1ed7ea0..1c114cb 100644 --- a/crates/core/src/bc/xml.rs +++ b/crates/core/src/bc/xml.rs @@ -487,7 +487,7 @@ pub struct BatteryInfo { /// The channel the for the camera usually 0 #[yaserde(rename = "channelId")] pub channel_id: u8, - /// Charge status known values, "chargeComplete", "charging", + /// Charge status known values, "chargeComplete", "charging", "none", #[yaserde(rename = "chargeStatus")] pub charge_status: String, /// Status of charging port known values: "solarPanel" From 80e705bd60bbfe72f039f5729a9b9b2f218e02f8 Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Wed, 1 Mar 2023 13:42:59 +0700 Subject: [PATCH 5/9] Add battery status to the MQTT --- src/mqtt/event_cam.rs | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/mqtt/event_cam.rs b/src/mqtt/event_cam.rs index 0f06a7d..0ef2025 100644 --- a/src/mqtt/event_cam.rs +++ b/src/mqtt/event_cam.rs @@ -322,9 +322,32 @@ impl MessageHandler { "OK".to_string() } } - Messages::Battery => { - todo!() - } + Messages::Battery => match self.camera.battery_info().await { + Err(_) => { + error!("Failed to get battery status"); + "FAIL".to_string() + } + Ok(battery_info) => { + let bytes_res = yaserde::ser::serialize_with_writer( + &battery_info, + vec![], + &Default::default(), + ); + match bytes_res { + Ok(bytes) => match String::from_utf8(bytes) { + Ok(str) => str, + Err(_) => { + error!("Failed to encode battery status"); + "FAIL".to_string() + } + }, + Err(_) => { + error!("Failed to serialise battery status"); + "FAIL".to_string() + } + } + } + }, Messages::Ptz(direction) => { let (bc_direction, amount) = match direction { Direction::Up(amount) => (BcDirection::Up, amount), From 0bbd334a78604fb5a418d8ea41a36ae160215df1 Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Wed, 1 Mar 2023 13:44:32 +0700 Subject: [PATCH 6/9] Updated readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 29d6115..ff27f16 100644 --- a/README.md +++ b/README.md @@ -129,10 +129,10 @@ Control messages: Status Messages: `/status offline` Sent when the neolink goes offline this is a LastWill message `/status disconnected` Sent when the camera goes offline -`/status/battery` Sent in reply to a `/query/battery` +`/status/battery` Sent in reply to a `/query/battery` send an XML encoded version of the battery status Query Messages: -`/query/battery` Request that the camera reports its battery level (Not Yet Implemented) +`/query/battery` Request that the camera reports its battery level ### Pause From aef898c471c541780f32475f11cad12e05b53380 Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Thu, 2 Mar 2023 14:44:23 +0700 Subject: [PATCH 7/9] Negative temperatures and such --- crates/core/src/bc/xml.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/core/src/bc/xml.rs b/crates/core/src/bc/xml.rs index 1c114cb..add10c2 100644 --- a/crates/core/src/bc/xml.rs +++ b/crates/core/src/bc/xml.rs @@ -494,11 +494,11 @@ pub struct BatteryInfo { #[yaserde(rename = "adapterStatus")] pub adapter_status: String, /// Voltage - pub voltage: u32, + pub voltage: i32, /// Current - pub current: u32, + pub current: i32, /// Temperture - pub temperature: u32, + pub temperature: i32, /// % charge from 0-100 #[yaserde(rename = "batteryPercent")] pub battery_percent: u32, From 1bcf1cfe852c812e944f84aea2190ede4012194a Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Thu, 2 Mar 2023 14:45:29 +0700 Subject: [PATCH 8/9] Print battery status to stdout --- crates/core/src/bc_protocol/battery.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/core/src/bc_protocol/battery.rs b/crates/core/src/bc_protocol/battery.rs index ae2dec0..9e24168 100644 --- a/crates/core/src/bc_protocol/battery.rs +++ b/crates/core/src/bc_protocol/battery.rs @@ -34,7 +34,7 @@ impl BcCamera { } = bc { for battery in battery_list.battery_info.iter() { - info!( + println!( "==Battery==\n\ Charge: {}%,\n\ Temperature: {}°C,\n\ From 92447b63b8655a233cc35a8ca2705adc11022650 Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Thu, 2 Mar 2023 15:55:15 +0700 Subject: [PATCH 9/9] Add configurable battery printing --- Cargo.lock | 1 + crates/core/Cargo.toml | 1 + crates/core/src/bc_protocol.rs | 33 +++++++++++++- crates/core/src/bc_protocol/battery.rs | 60 ++++++++++++++++---------- sample_config.toml | 12 ++++++ src/config.rs | 8 ++++ src/mqtt/event_cam.rs | 1 + src/rtsp/states/mod.rs | 1 + src/utils.rs | 21 ++++++--- 9 files changed, 109 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7e32873..caffb9c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1272,6 +1272,7 @@ dependencies = [ "nom", "rand", "regex", + "serde", "socket2 0.3.19", "time", "tokio", diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index da7e376..7a38458 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -25,6 +25,7 @@ md5 = "0.7" nom = { version = "6.1.2", features = ["alloc"] } rand = "0.8.4" regex = "1.5.4" +serde = { version = "1.0", features = ["derive"] } socket2 = "0.3" time = "0.2" tokio = { version = "1.24.2", features = ["full"] } diff --git a/crates/core/src/bc_protocol.rs b/crates/core/src/bc_protocol.rs index 669c0e0..6d2d1d6 100644 --- a/crates/core/src/bc_protocol.rs +++ b/crates/core/src/bc_protocol.rs @@ -1,6 +1,7 @@ use crate::bc; use futures::stream::StreamExt; use log::*; +use serde::{Deserialize, Serialize}; use std::net::ToSocketAddrs; use std::sync::atomic::{AtomicBool, AtomicU16, Ordering}; @@ -51,6 +52,20 @@ pub struct BcCamera { credentials: Credentials, } +/// Used to choode the print format of various status messages like battery levels +/// +/// Currently this is just the format of battery levels but if we ever got more status +/// messages then they will also use this information +#[derive(Debug, Clone, Copy, Serialize, Deserialize)] +pub enum PrintFormat { + /// None, don't print + None, + /// A human readable output + Human, + /// Xml formatted + Xml, +} + impl BcCamera { /// /// Create a new camera interface with this address and channel ID @@ -70,6 +85,7 @@ impl BcCamera { channel_id: u8, username: V, passwd: Option, + aux_info_format: PrintFormat, ) -> Result { let username: String = username.into(); let passwd: Option = passwd.map(|t| t.into()); @@ -83,6 +99,7 @@ impl BcCamera { channel_id, &username, passwd.as_ref(), + aux_info_format, ) .await { @@ -112,12 +129,14 @@ impl BcCamera { username: U, passwd: Option, discovery_method: DiscoveryMethods, + aux_info_format: PrintFormat, ) -> Result { Self::new( SocketAddrOrUid::Uid(uid.to_string(), discovery_method), channel_id, username, passwd, + aux_info_format, ) .await } @@ -147,6 +166,7 @@ impl BcCamera { channel_id: u8, username: V, passwd: Option, + aux_info_format: PrintFormat, ) -> Result { let addr_iter = match host.to_socket_addrs_or_uid() { Ok(iter) => iter, @@ -155,7 +175,15 @@ impl BcCamera { let username: String = username.into(); let passwd: Option = passwd.map(|t| t.into()); for addr_or_uid in addr_iter { - if let Ok(cam) = Self::new(addr_or_uid, channel_id, &username, passwd.as_ref()).await { + if let Ok(cam) = Self::new( + addr_or_uid, + channel_id, + &username, + passwd.as_ref(), + aux_info_format, + ) + .await + { return Ok(cam); } } @@ -185,6 +213,7 @@ impl BcCamera { channel_id: u8, username: U, passwd: Option, + aux_info_format: PrintFormat, ) -> Result { let username: String = username.into(); let passwd: Option = passwd.map(|t| t.into()); @@ -307,7 +336,7 @@ impl BcCamera { credentials: Credentials::new(username, passwd), }; me.keepalive().await?; - me.monitor_battery().await?; + me.monitor_battery(aux_info_format).await?; Ok(me) } diff --git a/crates/core/src/bc_protocol/battery.rs b/crates/core/src/bc_protocol/battery.rs index 9e24168..83697e8 100644 --- a/crates/core/src/bc_protocol/battery.rs +++ b/crates/core/src/bc_protocol/battery.rs @@ -5,21 +5,20 @@ //! - BatteryInfo which the client can request on demand //! -use super::{BcCamera, Result}; +use super::{BcCamera, PrintFormat, Result}; use crate::{ bc::{model::*, xml::BatteryInfo}, Error, }; -use log::*; impl BcCamera { /// Create a handller to respond to battery messages /// These messages are sent by the camera on login and maybe /// also on low battery events - pub async fn monitor_battery(&self) -> Result<()> { + pub async fn monitor_battery(&self, format: PrintFormat) -> Result<()> { let connection = self.get_connection(); connection - .handle_msg(MSG_ID_BATTERY_INFO_LIST, |bc| { + .handle_msg(MSG_ID_BATTERY_INFO_LIST, move |bc| { if let Bc { body: BcBody::ModernMsg(ModernMsg { @@ -34,24 +33,41 @@ impl BcCamera { } = bc { for battery in battery_list.battery_info.iter() { - println!( - "==Battery==\n\ - Charge: {}%,\n\ - Temperature: {}°C,\n\ - LowPower: {},\n\ - Adapter: {},\n\ - ChargeStatus: {},\n\ - ", - battery.battery_percent, - battery.temperature, - if battery.low_power == 1 { - "true" - } else { - "false" - }, - battery.adapter_status, - battery.charge_status, - ); + match format { + PrintFormat::None => {} + PrintFormat::Human => { + println!( + "==Battery==\n\ + Charge: {}%,\n\ + Temperature: {}°C,\n\ + LowPower: {},\n\ + Adapter: {},\n\ + ChargeStatus: {},\n\ + ", + battery.battery_percent, + battery.temperature, + if battery.low_power == 1 { + "true" + } else { + "false" + }, + battery.adapter_status, + battery.charge_status, + ); + } + PrintFormat::Xml => { + let bat_ser = String::from_utf8( + yaserde::ser::serialize_with_writer( + battery, + vec![], + &Default::default(), + ) + .expect("Should Ser the struct"), + ) + .expect("Should be UTF8"); + println!("{}", bat_ser); + } + } } } None diff --git a/sample_config.toml b/sample_config.toml index 7b17e02..a36b920 100644 --- a/sample_config.toml +++ b/sample_config.toml @@ -63,6 +63,18 @@ address = "192.168.1.187:9000" # # discovery = "relay" +# Certain types of camera emit status messages (such as battery levels) +# +# By default we hide these status messages from the user but you can instead requst that +# they be printed to stdout using print_format +# +# Valid values are: +# - None +# - Human +# - Xml +# +# print_format = "None" + [[cameras]] name = "storage shed" diff --git a/src/config.rs b/src/config.rs index 2d69bbe..a6a8243 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,4 +1,5 @@ use lazy_static::lazy_static; +use neolink_core::bc_protocol::PrintFormat; use regex::Regex; use serde::Deserialize; use std::clone::Clone; @@ -99,6 +100,9 @@ pub(crate) struct CameraConfig { #[serde(default = "default_strict")] /// If strict then the media stream will error in the event that the media packets are not as expected pub(crate) strict: bool, + + #[serde(default = "default_print", alias = "print")] + pub(crate) print_format: PrintFormat, } #[derive(Debug, Deserialize, Validate, Clone)] @@ -143,6 +147,10 @@ fn default_mqtt() -> Option { None } +fn default_print() -> PrintFormat { + PrintFormat::None +} + fn default_discovery() -> String { "Relay".to_string() } diff --git a/src/mqtt/event_cam.rs b/src/mqtt/event_cam.rs index 0ef2025..22d07e6 100644 --- a/src/mqtt/event_cam.rs +++ b/src/mqtt/event_cam.rs @@ -159,6 +159,7 @@ impl EventCam { camera_config.channel_id, &camera_config.username, camera_config.password.as_ref(), + camera_config.print_format, ) .await .with_context(|| { diff --git a/src/rtsp/states/mod.rs b/src/rtsp/states/mod.rs index e8d4272..3cfe7c0 100644 --- a/src/rtsp/states/mod.rs +++ b/src/rtsp/states/mod.rs @@ -67,6 +67,7 @@ impl RtspCamera { config.channel_id, &config.username, config.password.as_ref(), + config.print_format, ) .await .with_context(|| { diff --git a/src/utils.rs b/src/utils.rs index 20ca367..58f2a56 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -4,7 +4,7 @@ use log::*; use super::config::{CameraConfig, Config}; use anyhow::{anyhow, Context, Error, Result}; -use neolink_core::bc_protocol::{BcCamera, DiscoveryMethods, MaxEncryption}; +use neolink_core::bc_protocol::{BcCamera, DiscoveryMethods, MaxEncryption, PrintFormat}; use std::fmt::{Display, Error as FmtError, Formatter}; pub(crate) enum AddressOrUid { @@ -56,14 +56,24 @@ impl AddressOrUid { channel_id: u8, username: T, passwd: Option, + aux_print_format: PrintFormat, ) -> Result { match self { AddressOrUid::Address(host) => { - Ok(BcCamera::new_with_addr(host, channel_id, username, passwd).await?) - } - AddressOrUid::Uid(host, method) => { - Ok(BcCamera::new_with_uid(host, channel_id, username, passwd, *method).await?) + Ok( + BcCamera::new_with_addr(host, channel_id, username, passwd, aux_print_format) + .await?, + ) } + AddressOrUid::Uid(host, method) => Ok(BcCamera::new_with_uid( + host, + channel_id, + username, + passwd, + *method, + aux_print_format, + ) + .await?), } } } @@ -90,6 +100,7 @@ pub(crate) async fn connect_and_login(camera_config: &CameraConfig) -> Result