Skip to content

Commit

Permalink
Add command for camera service port controls (not on old camera)
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumEntangledAndy committed Apr 5, 2024
1 parent 9187694 commit 54f7665
Show file tree
Hide file tree
Showing 10 changed files with 858 additions and 5 deletions.
4 changes: 4 additions & 0 deletions crates/core/src/bc/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ pub const MSG_ID_REBOOT: u32 = 23;
pub const MSG_ID_MOTION_REQUEST: u32 = 31;
/// Motion detection messages
pub const MSG_ID_MOTION: u32 = 33;
/// Set service ports
pub const MSG_ID_SET_SERVICE_PORTS: u32 = 36;
/// Get service ports
pub const MSG_ID_GET_SERVICE_PORTS: u32 = 37;
/// Version messages have this ID
pub const MSG_ID_VERSION: u32 = 80;
/// Ping messages have this ID
Expand Down
102 changes: 102 additions & 0 deletions crates/core/src/bc/xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,24 @@ pub struct BcXml {
/// Play a sound
#[serde(rename = "audioPlayInfo", skip_serializing_if = "Option::is_none")]
pub audio_play_info: Option<AudioPlayInfo>,
/// For changing baichaun server port
#[serde(rename = "ServerPort", skip_serializing_if = "Option::is_none")]
pub server_port: Option<ServerPort>,
/// For changing http server port
#[serde(rename = "HttpPort", skip_serializing_if = "Option::is_none")]
pub http_port: Option<HttpPort>,
/// For changing https server port
#[serde(rename = "HttpsPort", skip_serializing_if = "Option::is_none")]
pub https_port: Option<HttpsPort>,
/// For changing rtsp server port
#[serde(rename = "RtspPort", skip_serializing_if = "Option::is_none")]
pub rtsp_port: Option<RtspPort>,
/// For changing rtmp server port
#[serde(rename = "RtmpPort", skip_serializing_if = "Option::is_none")]
pub rtmp_port: Option<RtmpPort>,
/// For changing rtmp server port
#[serde(rename = "OnvifPort", skip_serializing_if = "Option::is_none")]
pub onvif_port: Option<OnvifPort>,
}

impl BcXml {
Expand Down Expand Up @@ -1373,6 +1391,90 @@ pub struct AudioPlayInfo {
pub on_off: u32,
}

/// Server port for baichaun defaults 9000
#[derive(PartialEq, Eq, Default, Debug, Deserialize, Serialize)]
pub struct ServerPort {
/// XML Version
#[serde(rename = "@version")]
pub version: String,
/// The port number
#[serde(rename = "serverPort")]
pub port: u32,
/// The enable status known values are `1`, `0`
#[serde(skip_serializing_if = "Option::is_none")]
pub enable: Option<u32>,
}

/// Server port for http defaults to 80
#[derive(PartialEq, Eq, Default, Debug, Deserialize, Serialize)]
pub struct HttpPort {
/// XML Version
#[serde(rename = "@version")]
pub version: String,
/// The port number
#[serde(rename = "httpPort")]
pub port: u32,
/// The enable status known values are `1`, `0`
#[serde(skip_serializing_if = "Option::is_none")]
pub enable: Option<u32>,
}

/// Server port for https defaults to 443
#[derive(PartialEq, Eq, Default, Debug, Deserialize, Serialize)]
pub struct HttpsPort {
/// XML Version
#[serde(rename = "@version")]
pub version: String,
/// The port number
#[serde(rename = "httpsPort")]
pub port: u32,
/// The enable status known values are `1`, `0`
#[serde(skip_serializing_if = "Option::is_none")]
pub enable: Option<u32>,
}

/// Server port for Rtsp defaults to 554
#[derive(PartialEq, Eq, Default, Debug, Deserialize, Serialize)]
pub struct RtspPort {
/// XML Version
#[serde(rename = "@version")]
pub version: String,
/// The port number
#[serde(rename = "rtspPort")]
pub port: u32,
/// The enable status known values are `1`, `0`
#[serde(skip_serializing_if = "Option::is_none")]
pub enable: Option<u32>,
}

/// Server port for Rtmp defaults to 1935
#[derive(PartialEq, Eq, Default, Debug, Deserialize, Serialize)]
pub struct RtmpPort {
/// XML Version
#[serde(rename = "@version")]
pub version: String,
/// The port number
#[serde(rename = "rtmpPort")]
pub port: u32,
/// The enable status known values are `1`, `0`, can be `None` on cameras that can't change it
#[serde(skip_serializing_if = "Option::is_none")]
pub enable: Option<u32>,
}

/// Server port for Onvif defaults to 8000
#[derive(PartialEq, Eq, Default, Debug, Deserialize, Serialize)]
pub struct OnvifPort {
/// XML Version
#[serde(rename = "@version")]
pub version: String,
/// The port number
#[serde(rename = "onvifPort")]
pub port: u32,
/// The enable status known values are `1`, `0`
#[serde(skip_serializing_if = "Option::is_none")]
pub enable: Option<u32>,
}

/// Convience function to return the xml version used throughout the library
pub fn xml_ver() -> String {
"1.1".to_string()
Expand Down
1 change: 1 addition & 0 deletions crates/core/src/bc_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ mod ptz;
mod pushinfo;
mod reboot;
mod resolution;
mod services;
mod siren;
mod snap;
mod stream;
Expand Down
11 changes: 10 additions & 1 deletion crates/core/src/bc_protocol/errors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::bc::model::Bc;
use super::bc::model::{Bc, BcXml};
use crate::NomErrorType;
use thiserror::Error;

Expand Down Expand Up @@ -35,6 +35,15 @@ pub enum Error {
why: &'static str,
},

/// Raised when a BcXml reply was not understood
#[error("Communication error")]
UnintelligibleXml {
/// The Bc packet that was not understood
reply: std::sync::Arc<Box<BcXml>>,
/// The message attached to the error
why: &'static str,
},

/// Raised when the camera responds with a status code over than OK
#[error("Camera responded with Service Unavaliable: {0}")]
CameraServiceUnavailable(u16),
Expand Down
Loading

0 comments on commit 54f7665

Please sign in to comment.