Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5734321633 | ||
|
|
fb4f929109 | ||
|
|
16022c8b28 | ||
|
|
17f3695ca7 | ||
|
|
000f756420 | ||
|
|
6a1415913b | ||
|
|
3014be9008 | ||
|
|
618aafef2c | ||
|
|
ca5de6445d | ||
|
|
82a39a2fa1 | ||
|
|
77be9483b0 | ||
|
|
4fcaf4d538 | ||
|
|
70e62170a9 | ||
|
|
92447b63b8 | ||
|
|
1bcf1cfe85 | ||
|
|
aef898c471 | ||
|
|
0bbd334a78 | ||
|
|
80e705bd60 | ||
|
|
19c2031691 | ||
|
|
52c4515e62 | ||
|
|
8d3c0af7af | ||
|
|
f4d7bebbf1 | ||
|
|
e04c2a10f0 | ||
|
|
1dc25da8f2 | ||
|
|
8bd560b04e |
No files matched your search
Generated
+3
-2
@@ -1206,7 +1206,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "neolink"
|
name = "neolink"
|
||||||
version = "0.5.4"
|
version = "0.5.6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aes",
|
"aes",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
@@ -1248,7 +1248,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "neolink_core"
|
name = "neolink_core"
|
||||||
version = "0.5.4"
|
version = "0.5.6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aes",
|
"aes",
|
||||||
"assert_matches",
|
"assert_matches",
|
||||||
@@ -1272,6 +1272,7 @@ dependencies = [
|
|||||||
"nom",
|
"nom",
|
||||||
"rand",
|
"rand",
|
||||||
"regex",
|
"regex",
|
||||||
|
"serde",
|
||||||
"socket2 0.3.19",
|
"socket2 0.3.19",
|
||||||
"time",
|
"time",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
|||||||
+3
-2
@@ -1,9 +1,10 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "neolink"
|
name = "neolink"
|
||||||
description = "A standards-compliant bridge to Reolink IP cameras"
|
description = "A standards-compliant bridge to Reolink IP cameras"
|
||||||
version = "0.5.4"
|
version = "0.5.6"
|
||||||
authors = ["George Hilliard <thirtythreeforty@gmail.com>", "Andrew King <sheepchaan@gmail.com>"]
|
authors = ["George Hilliard <thirtythreeforty@gmail.com>", "Andrew King <sheepchaan@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
default-run = "neolink"
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
@@ -16,7 +17,7 @@ test = false
|
|||||||
bench = false
|
bench = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
neolink_core = { path = "crates/core", version = "0.5.4" }
|
neolink_core = { path = "crates/core", version = "0.5.6" }
|
||||||
aes = "0.6"
|
aes = "0.6"
|
||||||
cfb-mode = "0.6"
|
cfb-mode = "0.6"
|
||||||
cookie-factory = "0.3"
|
cookie-factory = "0.3"
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ with additional features not yet in upstream master.
|
|||||||
- Protocol more closely follows offical reolink format
|
- Protocol more closely follows offical reolink format
|
||||||
- Possibly can handle more simulatenous connections
|
- Possibly can handle more simulatenous connections
|
||||||
- More ways to connect to the camera. Including Relaying through reolink servers
|
- More ways to connect to the camera. Including Relaying through reolink servers
|
||||||
|
- Camera battery levels can be displayed in the log
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@@ -129,10 +130,12 @@ Control messages:
|
|||||||
Status Messages:
|
Status Messages:
|
||||||
`/status offline` Sent when the neolink goes offline this is a LastWill message
|
`/status offline` Sent when the neolink goes offline this is a LastWill message
|
||||||
`/status disconnected` Sent when the camera goes offline
|
`/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` an XML encoded version of the battery status
|
||||||
|
`/status/pir` Sent in reply to a `/query/pir` an XML encoded version of the pir status
|
||||||
|
|
||||||
Query Messages:
|
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
|
||||||
|
`/query/pir` Request that the camera reports its pir status
|
||||||
|
|
||||||
### Pause
|
### Pause
|
||||||
|
|
||||||
@@ -159,6 +162,19 @@ Then start the rtsp server as usual:
|
|||||||
./neolink rtsp --config=neolink.toml
|
./neolink rtsp --config=neolink.toml
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Battery Levels
|
||||||
|
|
||||||
|
If you have a battery camera and would like to see the battery messages in the log
|
||||||
|
add the following to your config
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[[cameras]]
|
||||||
|
# Usual camera options like uid etc
|
||||||
|
print_format = "Human"
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also print into xml format with `print_format = "Xml"` which can then be passed
|
||||||
|
by a script for processing.
|
||||||
|
|
||||||
### Docker
|
### Docker
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "neolink_core"
|
name = "neolink_core"
|
||||||
description = "Core services and structure for Reolink IP cameras"
|
description = "Core services and structure for Reolink IP cameras"
|
||||||
version = "0.5.4"
|
version = "0.5.6"
|
||||||
authors = ["George Hilliard <thirtythreeforty@gmail.com>", "Andrew King <sheepchaan@gmail.com>"]
|
authors = ["George Hilliard <thirtythreeforty@gmail.com>", "Andrew King <sheepchaan@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
@@ -25,6 +25,7 @@ md5 = "0.7"
|
|||||||
nom = { version = "6.1.2", features = ["alloc"] }
|
nom = { version = "6.1.2", features = ["alloc"] }
|
||||||
rand = "0.8.4"
|
rand = "0.8.4"
|
||||||
regex = "1.5.4"
|
regex = "1.5.4"
|
||||||
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
socket2 = "0.3"
|
socket2 = "0.3"
|
||||||
time = "0.2"
|
time = "0.2"
|
||||||
tokio = { version = "1.24.2", features = ["full"] }
|
tokio = { version = "1.24.2", features = ["full"] }
|
||||||
|
|||||||
@@ -27,14 +27,12 @@ pub const MSG_ID_MOTION_REQUEST: u32 = 31;
|
|||||||
pub const MSG_ID_MOTION: u32 = 33;
|
pub const MSG_ID_MOTION: u32 = 33;
|
||||||
/// Version messages have this ID
|
/// Version messages have this ID
|
||||||
pub const MSG_ID_VERSION: u32 = 80;
|
pub const MSG_ID_VERSION: u32 = 80;
|
||||||
/// Getting PIR status messages have this ID
|
|
||||||
pub const MSG_ID_GET_PIR_ALARM: u32 = 212;
|
|
||||||
/// Setting PIR status messages have this ID
|
|
||||||
pub const MSG_ID_START_PIR_ALARM: u32 = 213;
|
|
||||||
/// Ping messages have this ID
|
/// Ping messages have this ID
|
||||||
pub const MSG_ID_PING: u32 = 93;
|
pub const MSG_ID_PING: u32 = 93;
|
||||||
/// General system info messages have this ID
|
/// General system info messages have this ID
|
||||||
pub const MSG_ID_GET_GENERAL: u32 = 104;
|
pub const MSG_ID_GET_GENERAL: u32 = 104;
|
||||||
|
/// Used to get the abilities of a user
|
||||||
|
pub const MSG_ID_ABILITY_INFO: u32 = 151;
|
||||||
/// Setting general system info (clock mostly) messages have this ID
|
/// Setting general system info (clock mostly) messages have this ID
|
||||||
pub const MSG_ID_SET_GENERAL: u32 = 105;
|
pub const MSG_ID_SET_GENERAL: u32 = 105;
|
||||||
/// Will send the talk config for talk back data to follow this msg
|
/// Will send the talk config for talk back data to follow this msg
|
||||||
@@ -45,8 +43,16 @@ pub const MSG_ID_TALK: u32 = 202;
|
|||||||
pub const MSG_ID_GET_LED_STATUS: u32 = 208;
|
pub const MSG_ID_GET_LED_STATUS: u32 = 208;
|
||||||
/// Setting the LED status is done with this ID
|
/// Setting the LED status is done with this ID
|
||||||
pub const MSG_ID_SET_LED_STATUS: u32 = 209;
|
pub const MSG_ID_SET_LED_STATUS: u32 = 209;
|
||||||
|
/// Getting PIR status messages have this ID
|
||||||
|
pub const MSG_ID_GET_PIR_ALARM: u32 = 212;
|
||||||
|
/// Setting PIR status messages have this ID
|
||||||
|
pub const MSG_ID_START_PIR_ALARM: u32 = 213;
|
||||||
/// UDP Keep alive
|
/// UDP Keep alive
|
||||||
pub const MSG_ID_UDP_KEEP_ALIVE: u32 = 234;
|
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
|
/// An empty password in legacy format
|
||||||
pub const EMPTY_LEGACY_PASSWORD: &str =
|
pub const EMPTY_LEGACY_PASSWORD: &str =
|
||||||
|
|||||||
+152
-1
@@ -76,6 +76,15 @@ pub struct BcXml {
|
|||||||
/// Sent to move the camera
|
/// Sent to move the camera
|
||||||
#[yaserde(rename = "PtzControl")]
|
#[yaserde(rename = "PtzControl")]
|
||||||
pub ptz_control: Option<PtzControl>,
|
pub ptz_control: Option<PtzControl>,
|
||||||
|
/// Recieved on login/low battery events
|
||||||
|
#[yaserde(rename = "BatteryList")]
|
||||||
|
pub battery_list: Option<BatteryList>,
|
||||||
|
/// Recieved on request for battery info
|
||||||
|
#[yaserde(rename = "BatteryInfo")]
|
||||||
|
pub battery_info: Option<BatteryInfo>,
|
||||||
|
/// Recieved on request for a users persmissions/capabilitoes
|
||||||
|
#[yaserde(rename = "AbilityInfo")]
|
||||||
|
pub ability_info: Option<AbilityInfo>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BcXml {
|
impl BcXml {
|
||||||
@@ -232,6 +241,9 @@ pub struct Extension {
|
|||||||
/// The channel ID. This is usually `0` unless using an NVR
|
/// The channel ID. This is usually `0` unless using an NVR
|
||||||
#[yaserde(rename = "channelId")]
|
#[yaserde(rename = "channelId")]
|
||||||
pub channel_id: Option<u8>,
|
pub channel_id: Option<u8>,
|
||||||
|
/// The rfID used in the PIR
|
||||||
|
#[yaserde(rename = "rfId")]
|
||||||
|
pub rf_id: Option<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Extension {
|
impl Default for Extension {
|
||||||
@@ -242,6 +254,7 @@ impl Default for Extension {
|
|||||||
user_name: None,
|
user_name: None,
|
||||||
token: None,
|
token: None,
|
||||||
channel_id: None,
|
channel_id: None,
|
||||||
|
rf_id: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -330,7 +343,54 @@ pub struct RfAlarmCfg {
|
|||||||
/// reduce False alarm boolean
|
/// reduce False alarm boolean
|
||||||
pub reduceFalseAlarm: u8,
|
pub reduceFalseAlarm: u8,
|
||||||
/// XML time block for all week days
|
/// XML time block for all week days
|
||||||
pub timeBlockList: String,
|
#[yaserde(rename = "timeBlockList")]
|
||||||
|
pub time_block_list: TimeBlockList,
|
||||||
|
/// The alarm handle to attach to this Rf
|
||||||
|
#[yaserde(rename = "alarmHandle")]
|
||||||
|
pub alarm_handle: AlarmHandle,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// TimeBlockList XML
|
||||||
|
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)]
|
||||||
|
#[yaserde(rename = "timeBlockList")]
|
||||||
|
pub struct TimeBlockList {
|
||||||
|
/// List of time block entries which disable/enable the PIR at a time
|
||||||
|
#[yaserde(rename = "timeBlock")]
|
||||||
|
pub time_block: Vec<TimeBlock>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// TimeBlock XML Used to set the time to enable/disable PIR dectection
|
||||||
|
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)]
|
||||||
|
#[yaserde(rename = "timeBlock")]
|
||||||
|
pub struct TimeBlock {
|
||||||
|
/// Whether to enable or disable for this time block
|
||||||
|
pub enable: u8,
|
||||||
|
/// The day of the week for this block
|
||||||
|
pub weekDay: String,
|
||||||
|
/// Time to start this block
|
||||||
|
#[yaserde(rename = "beginHour")]
|
||||||
|
pub begin_hour: u8,
|
||||||
|
/// Time to end this block
|
||||||
|
#[yaserde(rename = "endHour")]
|
||||||
|
pub end_hour: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)]
|
||||||
|
/// AlarmHandle Xml
|
||||||
|
pub struct AlarmHandle {
|
||||||
|
/// Items in the alarm handle
|
||||||
|
pub item: Vec<AlarmHandleItem>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)]
|
||||||
|
/// An item in the alarm handle
|
||||||
|
#[yaserde(rename = "item")]
|
||||||
|
pub struct AlarmHandleItem {
|
||||||
|
/// The channel ID
|
||||||
|
pub channel: u8,
|
||||||
|
/// The handle type: Known values, comma seperated list of snap,rec,push
|
||||||
|
#[yaserde(rename = "handleType")]
|
||||||
|
pub handle_type: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TalkConfig xml
|
/// TalkConfig xml
|
||||||
@@ -463,6 +523,97 @@ pub struct PtzControl {
|
|||||||
pub command: String,
|
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<BatteryInfo>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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", "none",
|
||||||
|
#[yaserde(rename = "chargeStatus")]
|
||||||
|
pub charge_status: String,
|
||||||
|
/// Status of charging port known values: "solarPanel"
|
||||||
|
#[yaserde(rename = "adapterStatus")]
|
||||||
|
pub adapter_status: String,
|
||||||
|
/// Voltage
|
||||||
|
pub voltage: i32,
|
||||||
|
/// Current
|
||||||
|
pub current: i32,
|
||||||
|
/// Temperture
|
||||||
|
pub temperature: i32,
|
||||||
|
/// % 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,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The ability battery info
|
||||||
|
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)]
|
||||||
|
pub struct AbilityInfo {
|
||||||
|
/// Username with this ability
|
||||||
|
#[yaserde(rename = "userName")]
|
||||||
|
pub username: String,
|
||||||
|
/// System permissions
|
||||||
|
pub system: Option<AbilityInfoToken>,
|
||||||
|
/// Network permissions
|
||||||
|
pub network: Option<AbilityInfoToken>,
|
||||||
|
/// Alarm permissions
|
||||||
|
pub alarm: Option<AbilityInfoToken>,
|
||||||
|
/// Image permissions
|
||||||
|
pub image: Option<AbilityInfoToken>,
|
||||||
|
/// Video permissions
|
||||||
|
pub video: Option<AbilityInfoToken>,
|
||||||
|
/// Secutiry permissions
|
||||||
|
pub security: Option<AbilityInfoToken>,
|
||||||
|
/// Replay permissions
|
||||||
|
pub replay: Option<AbilityInfoToken>,
|
||||||
|
/// PTZ permissions
|
||||||
|
#[yaserde(rename = "PTZ")]
|
||||||
|
pub ptz: Option<AbilityInfoToken>,
|
||||||
|
/// IO permissions
|
||||||
|
#[yaserde(rename = "IO")]
|
||||||
|
pub io: Option<AbilityInfoToken>,
|
||||||
|
/// Streaming permissions
|
||||||
|
pub streaming: Option<AbilityInfoToken>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Ability info for system token
|
||||||
|
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)]
|
||||||
|
pub struct AbilityInfoToken {
|
||||||
|
/// Submodule for this ability info token
|
||||||
|
#[yaserde(rename = "subModule")]
|
||||||
|
pub sub_module: Vec<AbilityInfoSubModule>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Token submodule infomation
|
||||||
|
#[derive(PartialEq, Eq, Default, Debug, YaDeserialize, YaSerialize)]
|
||||||
|
#[yaserde(rename = "subModule")]
|
||||||
|
pub struct AbilityInfoSubModule {
|
||||||
|
/// The channel the for the camera usually 0
|
||||||
|
#[yaserde(rename = "channelId")]
|
||||||
|
pub channel_id: Option<u8>,
|
||||||
|
/// The comma seperated list of permissions like this: `general_rw, norm_rw, version_ro`
|
||||||
|
#[yaserde(rename = "abilityValue")]
|
||||||
|
pub ability_value: String,
|
||||||
|
}
|
||||||
|
|
||||||
/// Convience function to return the xml version used throughout the library
|
/// Convience function to return the xml version used throughout the library
|
||||||
pub fn xml_ver() -> String {
|
pub fn xml_ver() -> String {
|
||||||
"1.1".to_string()
|
"1.1".to_string()
|
||||||
|
|||||||
@@ -1,11 +1,18 @@
|
|||||||
use crate::bc;
|
use crate::bc;
|
||||||
use futures::stream::StreamExt;
|
use futures::stream::StreamExt;
|
||||||
use log::*;
|
use log::*;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
use std::net::ToSocketAddrs;
|
use std::net::ToSocketAddrs;
|
||||||
use std::sync::atomic::{AtomicBool, AtomicU16, Ordering};
|
use std::{
|
||||||
|
collections::HashMap,
|
||||||
|
sync::atomic::{AtomicBool, AtomicU16, Ordering},
|
||||||
|
};
|
||||||
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
use Md5Trunc::*;
|
use Md5Trunc::*;
|
||||||
|
|
||||||
|
mod abilityinfo;
|
||||||
|
mod battery;
|
||||||
mod connection;
|
mod connection;
|
||||||
mod credentials;
|
mod credentials;
|
||||||
mod errors;
|
mod errors;
|
||||||
@@ -38,6 +45,13 @@ pub use stream::{StreamData, StreamKind};
|
|||||||
|
|
||||||
pub(crate) type Result<T> = std::result::Result<T, Error>;
|
pub(crate) type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
|
enum ReadKind {
|
||||||
|
ReadOnly,
|
||||||
|
ReadWrite,
|
||||||
|
None,
|
||||||
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// This is the primary struct of this library when interacting with the camera
|
/// This is the primary struct of this library when interacting with the camera
|
||||||
///
|
///
|
||||||
@@ -48,6 +62,21 @@ pub struct BcCamera {
|
|||||||
message_num: AtomicU16,
|
message_num: AtomicU16,
|
||||||
// Certain commands such as logout require the username/pass in plain text.... why....???
|
// Certain commands such as logout require the username/pass in plain text.... why....???
|
||||||
credentials: Credentials,
|
credentials: Credentials,
|
||||||
|
abilities: RwLock<HashMap<String, ReadKind>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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 {
|
impl BcCamera {
|
||||||
@@ -69,6 +98,7 @@ impl BcCamera {
|
|||||||
channel_id: u8,
|
channel_id: u8,
|
||||||
username: V,
|
username: V,
|
||||||
passwd: Option<W>,
|
passwd: Option<W>,
|
||||||
|
aux_info_format: PrintFormat,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let username: String = username.into();
|
let username: String = username.into();
|
||||||
let passwd: Option<String> = passwd.map(|t| t.into());
|
let passwd: Option<String> = passwd.map(|t| t.into());
|
||||||
@@ -82,6 +112,7 @@ impl BcCamera {
|
|||||||
channel_id,
|
channel_id,
|
||||||
&username,
|
&username,
|
||||||
passwd.as_ref(),
|
passwd.as_ref(),
|
||||||
|
aux_info_format,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
@@ -111,12 +142,14 @@ impl BcCamera {
|
|||||||
username: U,
|
username: U,
|
||||||
passwd: Option<V>,
|
passwd: Option<V>,
|
||||||
discovery_method: DiscoveryMethods,
|
discovery_method: DiscoveryMethods,
|
||||||
|
aux_info_format: PrintFormat,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
Self::new(
|
Self::new(
|
||||||
SocketAddrOrUid::Uid(uid.to_string(), discovery_method),
|
SocketAddrOrUid::Uid(uid.to_string(), discovery_method),
|
||||||
channel_id,
|
channel_id,
|
||||||
username,
|
username,
|
||||||
passwd,
|
passwd,
|
||||||
|
aux_info_format,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
@@ -146,6 +179,7 @@ impl BcCamera {
|
|||||||
channel_id: u8,
|
channel_id: u8,
|
||||||
username: V,
|
username: V,
|
||||||
passwd: Option<W>,
|
passwd: Option<W>,
|
||||||
|
aux_info_format: PrintFormat,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let addr_iter = match host.to_socket_addrs_or_uid() {
|
let addr_iter = match host.to_socket_addrs_or_uid() {
|
||||||
Ok(iter) => iter,
|
Ok(iter) => iter,
|
||||||
@@ -154,7 +188,15 @@ impl BcCamera {
|
|||||||
let username: String = username.into();
|
let username: String = username.into();
|
||||||
let passwd: Option<String> = passwd.map(|t| t.into());
|
let passwd: Option<String> = passwd.map(|t| t.into());
|
||||||
for addr_or_uid in addr_iter {
|
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);
|
return Ok(cam);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -184,6 +226,7 @@ impl BcCamera {
|
|||||||
channel_id: u8,
|
channel_id: u8,
|
||||||
username: U,
|
username: U,
|
||||||
passwd: Option<V>,
|
passwd: Option<V>,
|
||||||
|
aux_info_format: PrintFormat,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let username: String = username.into();
|
let username: String = username.into();
|
||||||
let passwd: Option<String> = passwd.map(|t| t.into());
|
let passwd: Option<String> = passwd.map(|t| t.into());
|
||||||
@@ -304,8 +347,12 @@ impl BcCamera {
|
|||||||
channel_id,
|
channel_id,
|
||||||
logged_in: AtomicBool::new(false),
|
logged_in: AtomicBool::new(false),
|
||||||
credentials: Credentials::new(username, passwd),
|
credentials: Credentials::new(username, passwd),
|
||||||
|
abilities: Default::default(),
|
||||||
};
|
};
|
||||||
me.keepalive().await?;
|
me.keepalive().await?;
|
||||||
|
if let Err(e) = me.monitor_battery(aux_info_format).await {
|
||||||
|
warn!("Could not monitor battery: {:?}", e);
|
||||||
|
}
|
||||||
Ok(me)
|
Ok(me)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -324,6 +371,42 @@ impl BcCamera {
|
|||||||
fn get_credentials(&self) -> &Credentials {
|
fn get_credentials(&self) -> &Credentials {
|
||||||
&self.credentials
|
&self.credentials
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn has_ability<T: Into<String>>(&self, name: T) -> ReadKind {
|
||||||
|
let abilities = self.abilities.read().await;
|
||||||
|
if let Some(kind) = abilities.get(&name.into()).copied() {
|
||||||
|
kind
|
||||||
|
} else {
|
||||||
|
ReadKind::None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async fn has_ability_ro<T: Into<String>>(&self, name: T) -> Result<()> {
|
||||||
|
let s: String = name.into();
|
||||||
|
match self.has_ability(&s).await {
|
||||||
|
ReadKind::ReadWrite | ReadKind::ReadOnly => Ok(()),
|
||||||
|
ReadKind::None => Err(Error::MissingAbility {
|
||||||
|
name: s.clone(),
|
||||||
|
requested: "read".to_string(),
|
||||||
|
actual: "none".to_string(),
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async fn has_ability_rw<T: Into<String>>(&self, name: T) -> Result<()> {
|
||||||
|
let s: String = name.into();
|
||||||
|
match self.has_ability(&s).await {
|
||||||
|
ReadKind::ReadWrite => Ok(()),
|
||||||
|
ReadKind::ReadOnly => Err(Error::MissingAbility {
|
||||||
|
name: s.clone(),
|
||||||
|
requested: "write".to_string(),
|
||||||
|
actual: "read".to_string(),
|
||||||
|
}),
|
||||||
|
ReadKind::None => Err(Error::MissingAbility {
|
||||||
|
name: s.clone(),
|
||||||
|
requested: "write".to_string(),
|
||||||
|
actual: "none".to_string(),
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The Baichuan library has a very peculiar behavior where it always zeros the last byte. I
|
/// The Baichuan library has a very peculiar behavior where it always zeros the last byte. I
|
||||||
|
|||||||
@@ -0,0 +1,104 @@
|
|||||||
|
use super::{BcCamera, Error, Result};
|
||||||
|
use crate::bc::{model::*, xml::*};
|
||||||
|
|
||||||
|
impl BcCamera {
|
||||||
|
/// Get the ability info xml for the current user
|
||||||
|
pub async fn get_abilityinfo(&self) -> Result<AbilityInfo> {
|
||||||
|
let connection = self.get_connection();
|
||||||
|
let msg_num = self.new_message_num();
|
||||||
|
let mut sub_get = connection.subscribe(msg_num).await?;
|
||||||
|
let get = Bc {
|
||||||
|
meta: BcMeta {
|
||||||
|
msg_id: MSG_ID_ABILITY_INFO,
|
||||||
|
channel_id: self.channel_id,
|
||||||
|
msg_num,
|
||||||
|
response_code: 0,
|
||||||
|
stream_type: 0,
|
||||||
|
class: 0x6414,
|
||||||
|
},
|
||||||
|
body: BcBody::ModernMsg(ModernMsg {
|
||||||
|
extension: Some(Extension {
|
||||||
|
user_name: Some(self.get_credentials().username.clone()),
|
||||||
|
token: Some("system, streaming, PTZ, IO, security, replay, disk, network, alarm, record, video, image".to_string()),
|
||||||
|
..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);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let BcBody::ModernMsg(ModernMsg {
|
||||||
|
payload:
|
||||||
|
Some(BcPayloads::BcXml(BcXml {
|
||||||
|
ability_info: Some(ability_info),
|
||||||
|
..
|
||||||
|
})),
|
||||||
|
..
|
||||||
|
}) = msg.body
|
||||||
|
{
|
||||||
|
Ok(ability_info)
|
||||||
|
} else {
|
||||||
|
Err(Error::UnintelligibleReply {
|
||||||
|
reply: std::sync::Arc::new(Box::new(msg)),
|
||||||
|
why: "Expected AbilityInfo xml but it was not recieved",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Populate ability list of the camera
|
||||||
|
pub async fn polulate_abilities(&self) -> Result<()> {
|
||||||
|
let info = self.get_abilityinfo().await?;
|
||||||
|
let mut abilities: Vec<String> = vec![];
|
||||||
|
|
||||||
|
let mut tokens: Vec<Option<&AbilityInfoToken>> = vec![
|
||||||
|
info.system.as_ref(),
|
||||||
|
info.network.as_ref(),
|
||||||
|
info.alarm.as_ref(),
|
||||||
|
info.image.as_ref(),
|
||||||
|
info.video.as_ref(),
|
||||||
|
info.security.as_ref(),
|
||||||
|
info.replay.as_ref(),
|
||||||
|
info.ptz.as_ref(),
|
||||||
|
info.io.as_ref(),
|
||||||
|
info.streaming.as_ref(),
|
||||||
|
];
|
||||||
|
for token in tokens.drain(..).flatten() {
|
||||||
|
for sub_module in token.sub_module.iter() {
|
||||||
|
abilities.extend(
|
||||||
|
sub_module
|
||||||
|
.ability_value
|
||||||
|
.replace(' ', "")
|
||||||
|
.split(',')
|
||||||
|
.map(|s| s.to_string()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut locked_abilities = self.abilities.write().await;
|
||||||
|
for ability in abilities.iter() {
|
||||||
|
let mut abilities_ro = ability.split('_').map(|s| s.to_string());
|
||||||
|
if let (Some(ability_name), Some(ability_kind)) =
|
||||||
|
(abilities_ro.next(), abilities_ro.next())
|
||||||
|
{
|
||||||
|
match ability_kind.as_str() {
|
||||||
|
"rw" => {
|
||||||
|
locked_abilities.insert(ability_name, super::ReadKind::ReadWrite);
|
||||||
|
}
|
||||||
|
"ro" => {
|
||||||
|
locked_abilities.insert(ability_name, super::ReadKind::ReadOnly);
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,130 @@
|
|||||||
|
//! 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, PrintFormat, Result};
|
||||||
|
use crate::{
|
||||||
|
bc::{model::*, xml::BatteryInfo},
|
||||||
|
Error,
|
||||||
|
};
|
||||||
|
|
||||||
|
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, format: PrintFormat) -> Result<()> {
|
||||||
|
let connection = self.get_connection();
|
||||||
|
connection
|
||||||
|
.handle_msg(MSG_ID_BATTERY_INFO_LIST, move |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() {
|
||||||
|
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
|
||||||
|
})
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Requests the current battery status of the camera
|
||||||
|
pub async fn battery_info(&self) -> Result<BatteryInfo> {
|
||||||
|
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.",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -938,7 +938,7 @@ fn generate_cid() -> i32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn connect() -> Result<UdpSocket> {
|
async fn connect() -> Result<UdpSocket> {
|
||||||
let mut ports: Vec<u16> = (53500..54000).into_iter().collect();
|
let mut ports: Vec<u16> = (53500..54000).collect();
|
||||||
{
|
{
|
||||||
let mut rng = thread_rng();
|
let mut rng = thread_rng();
|
||||||
ports.shuffle(&mut rng);
|
ports.shuffle(&mut rng);
|
||||||
|
|||||||
@@ -253,12 +253,15 @@ impl UdpPayloadSource {
|
|||||||
|
|
||||||
fn handle_ack(&mut self, ack: UdpAck) {
|
fn handle_ack(&mut self, ack: UdpAck) {
|
||||||
let start = ack.packet_id;
|
let start = ack.packet_id;
|
||||||
self.sent.retain(|&k, _| k > start);
|
// -1 is the special case of no messages recieved
|
||||||
|
if start != 0xFFFFFFFF {
|
||||||
|
self.sent.retain(|&k, _| k > start);
|
||||||
|
|
||||||
for (idx, &value) in ack.payload.iter().enumerate() {
|
for (idx, &value) in ack.payload.iter().enumerate() {
|
||||||
let packet_id = (start + 1) + idx as u32;
|
let packet_id = (start + 1) + idx as u32;
|
||||||
if value > 0 {
|
if value > 0 {
|
||||||
self.sent.remove(&packet_id);
|
self.sent.remove(&packet_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -508,7 +511,7 @@ impl futures::AsyncWrite for UdpPayloadSource {
|
|||||||
|
|
||||||
/// Helper to create a TcpStream with a connect timeout
|
/// Helper to create a TcpStream with a connect timeout
|
||||||
async fn connect() -> Result<UdpSocket> {
|
async fn connect() -> Result<UdpSocket> {
|
||||||
let mut ports: Vec<u16> = (53500..54000).into_iter().collect();
|
let mut ports: Vec<u16> = (53500..54000).collect();
|
||||||
let mut rng = thread_rng();
|
let mut rng = thread_rng();
|
||||||
ports.shuffle(&mut rng);
|
ports.shuffle(&mut rng);
|
||||||
|
|
||||||
|
|||||||
@@ -143,6 +143,22 @@ pub enum Error {
|
|||||||
#[error(display = "Nom Parsing error: {}", _0)]
|
#[error(display = "Nom Parsing error: {}", _0)]
|
||||||
NomError(String),
|
NomError(String),
|
||||||
|
|
||||||
|
/// Raised when a camera/user lacks an ability
|
||||||
|
#[error(
|
||||||
|
display = "Missing ability: {} with {} permission has only {}",
|
||||||
|
name,
|
||||||
|
requested,
|
||||||
|
actual
|
||||||
|
)]
|
||||||
|
MissingAbility {
|
||||||
|
/// Name of the ability
|
||||||
|
name: String,
|
||||||
|
/// Requested permission (read/write)
|
||||||
|
requested: String,
|
||||||
|
/// Actual permission (read/write/none)
|
||||||
|
actual: String,
|
||||||
|
},
|
||||||
|
|
||||||
/// A generic catch all error
|
/// A generic catch all error
|
||||||
#[error(display = "Other error: {}", _0)]
|
#[error(display = "Other error: {}", _0)]
|
||||||
Other(&'static str),
|
Other(&'static str),
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use crate::bc::{model::*, xml::*};
|
|||||||
impl BcCamera {
|
impl BcCamera {
|
||||||
/// Get the [LedState] xml which contains the LED status of the camera
|
/// Get the [LedState] xml which contains the LED status of the camera
|
||||||
pub async fn get_ledstate(&self) -> Result<LedState> {
|
pub async fn get_ledstate(&self) -> Result<LedState> {
|
||||||
|
self.has_ability_ro("ledState").await?;
|
||||||
let connection = self.get_connection();
|
let connection = self.get_connection();
|
||||||
let msg_num = self.new_message_num();
|
let msg_num = self.new_message_num();
|
||||||
let mut sub_get = connection.subscribe(msg_num).await?;
|
let mut sub_get = connection.subscribe(msg_num).await?;
|
||||||
@@ -51,6 +52,7 @@ impl BcCamera {
|
|||||||
|
|
||||||
/// Set the led lights using the [LedState] xml
|
/// Set the led lights using the [LedState] xml
|
||||||
pub async fn set_ledstate(&self, mut led_state: LedState) -> Result<()> {
|
pub async fn set_ledstate(&self, mut led_state: LedState) -> Result<()> {
|
||||||
|
self.has_ability_rw("ledState").await?;
|
||||||
let connection = self.get_connection();
|
let connection = self.get_connection();
|
||||||
|
|
||||||
let msg_num = self.new_message_num();
|
let msg_num = self.new_message_num();
|
||||||
|
|||||||
@@ -164,6 +164,9 @@ impl BcCamera {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Populate the list of abilities this user has with the camera
|
||||||
|
self.polulate_abilities().await?;
|
||||||
Ok(device_info)
|
Ok(device_info)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,6 +86,7 @@ impl BcCamera {
|
|||||||
/// This message tells the camera to send the motion events to us
|
/// This message tells the camera to send the motion events to us
|
||||||
/// Which are the recieved on msgid 33
|
/// Which are the recieved on msgid 33
|
||||||
async fn start_motion_query(&self) -> Result<u16> {
|
async fn start_motion_query(&self) -> Result<u16> {
|
||||||
|
self.has_ability_rw("motion").await?;
|
||||||
let connection = self.get_connection();
|
let connection = self.get_connection();
|
||||||
|
|
||||||
let msg_num = self.new_message_num();
|
let msg_num = self.new_message_num();
|
||||||
|
|||||||
@@ -1,56 +1,73 @@
|
|||||||
use super::{BcCamera, Error, Result};
|
use super::{BcCamera, Error, Result};
|
||||||
use crate::bc::{model::*, xml::*};
|
use crate::bc::{model::*, xml::*};
|
||||||
|
use tokio::time::{interval, Duration};
|
||||||
|
|
||||||
impl BcCamera {
|
impl BcCamera {
|
||||||
/// Get the [RfAlarmCfg] xml which contains the PIR status of the camera
|
/// Get the [RfAlarmCfg] xml which contains the PIR status of the camera
|
||||||
pub async fn get_pirstate(&self) -> Result<RfAlarmCfg> {
|
pub async fn get_pirstate(&self) -> Result<RfAlarmCfg> {
|
||||||
|
self.has_ability_ro("rfAlarm").await?;
|
||||||
let connection = self.get_connection();
|
let connection = self.get_connection();
|
||||||
let msg_num = self.new_message_num();
|
let mut reties: usize = 0;
|
||||||
let mut sub_get = connection.subscribe(msg_num).await?;
|
let mut retry_interval = interval(Duration::from_millis(500));
|
||||||
let get = Bc {
|
loop {
|
||||||
meta: BcMeta {
|
retry_interval.tick().await;
|
||||||
msg_id: MSG_ID_GET_PIR_ALARM,
|
let msg_num = self.new_message_num();
|
||||||
channel_id: self.channel_id,
|
let mut sub_get = connection.subscribe(msg_num).await?;
|
||||||
msg_num,
|
let get = Bc {
|
||||||
response_code: 0,
|
meta: BcMeta {
|
||||||
stream_type: 0,
|
msg_id: MSG_ID_GET_PIR_ALARM,
|
||||||
class: 0x6414,
|
channel_id: self.channel_id,
|
||||||
},
|
msg_num,
|
||||||
body: BcBody::ModernMsg(ModernMsg {
|
response_code: 0,
|
||||||
extension: Some(Extension {
|
stream_type: 0,
|
||||||
channel_id: Some(self.channel_id),
|
class: 0x6414,
|
||||||
..Default::default()
|
},
|
||||||
|
body: BcBody::ModernMsg(ModernMsg {
|
||||||
|
extension: Some(Extension {
|
||||||
|
rf_id: Some(self.channel_id),
|
||||||
|
..Default::default()
|
||||||
|
}),
|
||||||
|
payload: None,
|
||||||
}),
|
}),
|
||||||
payload: None,
|
};
|
||||||
}),
|
|
||||||
};
|
|
||||||
|
|
||||||
sub_get.send(get).await?;
|
sub_get.send(get).await?;
|
||||||
let msg = sub_get.recv().await?;
|
let msg = sub_get.recv().await?;
|
||||||
if msg.meta.response_code != 200 {
|
if msg.meta.response_code == 400 {
|
||||||
return Err(Error::CameraServiceUnavaliable);
|
// Retryable
|
||||||
}
|
if reties < 5 {
|
||||||
|
reties += 1;
|
||||||
if let BcBody::ModernMsg(ModernMsg {
|
continue;
|
||||||
payload:
|
} else {
|
||||||
Some(BcPayloads::BcXml(BcXml {
|
return Err(Error::CameraServiceUnavaliable);
|
||||||
rf_alarm_cfg: Some(pirstate),
|
}
|
||||||
|
} else if msg.meta.response_code != 200 {
|
||||||
|
return Err(Error::CameraServiceUnavaliable);
|
||||||
|
} else {
|
||||||
|
// Valid message with response_code == 200
|
||||||
|
if let BcBody::ModernMsg(ModernMsg {
|
||||||
|
payload:
|
||||||
|
Some(BcPayloads::BcXml(BcXml {
|
||||||
|
rf_alarm_cfg: Some(pirstate),
|
||||||
|
..
|
||||||
|
})),
|
||||||
..
|
..
|
||||||
})),
|
}) = msg.body
|
||||||
..
|
{
|
||||||
}) = msg.body
|
return Ok(pirstate);
|
||||||
{
|
} else {
|
||||||
Ok(pirstate)
|
return Err(Error::UnintelligibleReply {
|
||||||
} else {
|
reply: std::sync::Arc::new(Box::new(msg)),
|
||||||
Err(Error::UnintelligibleReply {
|
why: "Expected PirSate xml but it was not recieved",
|
||||||
reply: std::sync::Arc::new(Box::new(msg)),
|
});
|
||||||
why: "Expected PirSate xml but it was not recieved",
|
}
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the PIR sensor using the [RfAlarmCfg] xml
|
/// Set the PIR sensor using the [RfAlarmCfg] xml
|
||||||
pub async fn set_pirstate(&self, rf_alarm_cfg: RfAlarmCfg) -> Result<()> {
|
pub async fn set_pirstate(&self, rf_alarm_cfg: RfAlarmCfg) -> Result<()> {
|
||||||
|
self.has_ability_rw("rfAlarm").await?;
|
||||||
let connection = self.get_connection();
|
let connection = self.get_connection();
|
||||||
let msg_num = self.new_message_num();
|
let msg_num = self.new_message_num();
|
||||||
let mut sub_set = connection.subscribe(msg_num).await?;
|
let mut sub_set = connection.subscribe(msg_num).await?;
|
||||||
@@ -66,7 +83,7 @@ impl BcCamera {
|
|||||||
},
|
},
|
||||||
body: BcBody::ModernMsg(ModernMsg {
|
body: BcBody::ModernMsg(ModernMsg {
|
||||||
extension: Some(Extension {
|
extension: Some(Extension {
|
||||||
channel_id: Some(self.channel_id),
|
rf_id: Some(self.channel_id),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
payload: Some(BcPayloads::BcXml(BcXml {
|
payload: Some(BcPayloads::BcXml(BcXml {
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ pub enum Direction {
|
|||||||
impl BcCamera {
|
impl BcCamera {
|
||||||
/// Send a PTZ message to the camera
|
/// Send a PTZ message to the camera
|
||||||
pub async fn send_ptz(&self, direction: Direction, amount: f32) -> Result<()> {
|
pub async fn send_ptz(&self, direction: Direction, amount: f32) -> Result<()> {
|
||||||
|
self.has_ability_rw("control").await?;
|
||||||
let connection = self.get_connection();
|
let connection = self.get_connection();
|
||||||
let msg_num = self.new_message_num();
|
let msg_num = self.new_message_num();
|
||||||
let mut sub_set = connection.subscribe(msg_num).await?;
|
let mut sub_set = connection.subscribe(msg_num).await?;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use crate::bc::model::*;
|
|||||||
impl BcCamera {
|
impl BcCamera {
|
||||||
/// Reboot the camera
|
/// Reboot the camera
|
||||||
pub async fn reboot(&self) -> Result<()> {
|
pub async fn reboot(&self) -> Result<()> {
|
||||||
|
self.has_ability_rw("reboot").await?;
|
||||||
let connection = self.get_connection();
|
let connection = self.get_connection();
|
||||||
let msg_num = self.new_message_num();
|
let msg_num = self.new_message_num();
|
||||||
let mut sub = connection.subscribe(msg_num).await?;
|
let mut sub = connection.subscribe(msg_num).await?;
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ impl BcCamera {
|
|||||||
mut buffer_size: usize,
|
mut buffer_size: usize,
|
||||||
strict: bool,
|
strict: bool,
|
||||||
) -> Result<StreamData> {
|
) -> Result<StreamData> {
|
||||||
|
self.has_ability_rw("preview").await?;
|
||||||
let connection = self.get_connection();
|
let connection = self.get_connection();
|
||||||
let msg_num = self.new_message_num();
|
let msg_num = self.new_message_num();
|
||||||
|
|
||||||
@@ -208,6 +209,7 @@ impl BcCamera {
|
|||||||
|
|
||||||
/// Stop a camera from sending more stream data.
|
/// Stop a camera from sending more stream data.
|
||||||
pub async fn stop_video(&self, stream: StreamKind) -> Result<()> {
|
pub async fn stop_video(&self, stream: StreamKind) -> Result<()> {
|
||||||
|
self.has_ability_rw("preview").await?;
|
||||||
let connection = self.get_connection();
|
let connection = self.get_connection();
|
||||||
let msg_num = self.new_message_num();
|
let msg_num = self.new_message_num();
|
||||||
let mut sub_video = connection.subscribe(msg_num).await?;
|
let mut sub_video = connection.subscribe(msg_num).await?;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ impl BcCamera {
|
|||||||
/// returns either an error or an option with the offsetted date time
|
/// returns either an error or an option with the offsetted date time
|
||||||
///
|
///
|
||||||
pub async fn get_time(&self) -> Result<Option<OffsetDateTime>> {
|
pub async fn get_time(&self) -> Result<Option<OffsetDateTime>> {
|
||||||
|
self.has_ability_ro("general").await?;
|
||||||
let connection = self.get_connection();
|
let connection = self.get_connection();
|
||||||
let msg_num = self.new_message_num();
|
let msg_num = self.new_message_num();
|
||||||
let mut sub_get_general = connection.subscribe(msg_num).await?;
|
let mut sub_get_general = connection.subscribe(msg_num).await?;
|
||||||
@@ -95,6 +96,7 @@ impl BcCamera {
|
|||||||
/// returns Ok(()) or error
|
/// returns Ok(()) or error
|
||||||
///
|
///
|
||||||
pub async fn set_time(&self, timestamp: OffsetDateTime) -> Result<()> {
|
pub async fn set_time(&self, timestamp: OffsetDateTime) -> Result<()> {
|
||||||
|
self.has_ability_rw("general").await?;
|
||||||
let connection = self.get_connection();
|
let connection = self.get_connection();
|
||||||
let msg_num = self.new_message_num();
|
let msg_num = self.new_message_num();
|
||||||
let mut sub_set_general = connection.subscribe(msg_num).await?;
|
let mut sub_set_general = connection.subscribe(msg_num).await?;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use crate::bc::{model::*, xml::*};
|
|||||||
impl BcCamera {
|
impl BcCamera {
|
||||||
/// Request the [VersionInfo] xml
|
/// Request the [VersionInfo] xml
|
||||||
pub async fn version(&self) -> Result<VersionInfo> {
|
pub async fn version(&self) -> Result<VersionInfo> {
|
||||||
|
self.has_ability_ro("version").await?;
|
||||||
let connection = self.get_connection();
|
let connection = self.get_connection();
|
||||||
let msg_num = self.new_message_num();
|
let msg_num = self.new_message_num();
|
||||||
let mut sub_version = connection.subscribe(msg_num).await?;
|
let mut sub_version = connection.subscribe(msg_num).await?;
|
||||||
|
|||||||
@@ -2,6 +2,20 @@
|
|||||||
-- Copy/symlink it into ~/.local/lib/wireshark/plugins/ and restart Wireshark; it should
|
-- Copy/symlink it into ~/.local/lib/wireshark/plugins/ and restart Wireshark; it should
|
||||||
-- automatically attempt to decode TCP connections on port 9000.
|
-- automatically attempt to decode TCP connections on port 9000.
|
||||||
|
|
||||||
|
-- Copyright (c) the Neolink contributors
|
||||||
|
--
|
||||||
|
-- This program is free software: you can redistribute it and/or modify it
|
||||||
|
-- under the terms of the GNU Affero General Public License, version 3, as
|
||||||
|
-- published by the Free Software Foundation.
|
||||||
|
--
|
||||||
|
-- This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
-- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
-- more details.
|
||||||
|
--
|
||||||
|
-- You should have received a copy of the GNU General Public License along with
|
||||||
|
-- this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
local bc_protocol = Proto("Baichuan", "Baichuan/Reolink IP Camera Protocol")
|
local bc_protocol = Proto("Baichuan", "Baichuan/Reolink IP Camera Protocol")
|
||||||
|
|
||||||
local magic_bytes = ProtoField.int32("baichuan.magic", "magic", base.DEC)
|
local magic_bytes = ProtoField.int32("baichuan.magic", "magic", base.DEC)
|
||||||
@@ -152,6 +166,7 @@ local message_types = {
|
|||||||
[210]="<PTOP>",
|
[210]="<PTOP>",
|
||||||
[211]="<PTOP> (write)",
|
[211]="<PTOP> (write)",
|
||||||
[212]="<rfAlarmCfg>",
|
[212]="<rfAlarmCfg>",
|
||||||
|
[213]="<rfAlarmCfg> (write)",
|
||||||
[216]="<EmailTask> (write)",
|
[216]="<EmailTask> (write)",
|
||||||
[217]="<EmailTask>",
|
[217]="<EmailTask>",
|
||||||
[218]="<PushTask> (write)",
|
[218]="<PushTask> (write)",
|
||||||
@@ -165,6 +180,8 @@ local message_types = {
|
|||||||
[272]="<findAlarmVideo>",
|
[272]="<findAlarmVideo>",
|
||||||
[273]="<alarmVideoInfo>",
|
[273]="<alarmVideoInfo>",
|
||||||
[274]="<findAlarmVideo>",
|
[274]="<findAlarmVideo>",
|
||||||
|
[319]="<timelapseCfg>",
|
||||||
|
[342]="<AiDetectCfg>",
|
||||||
}
|
}
|
||||||
|
|
||||||
local message_classes = {
|
local message_classes = {
|
||||||
|
|||||||
@@ -63,6 +63,18 @@ address = "192.168.1.187:9000"
|
|||||||
#
|
#
|
||||||
# discovery = "relay"
|
# 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]]
|
[[cameras]]
|
||||||
name = "storage shed"
|
name = "storage shed"
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ use std::path::PathBuf;
|
|||||||
use structopt::{clap::AppSettings, StructOpt};
|
use structopt::{clap::AppSettings, StructOpt};
|
||||||
|
|
||||||
/// A standards-compliant bridge to Reolink IP cameras
|
/// A standards-compliant bridge to Reolink IP cameras
|
||||||
|
///
|
||||||
|
/// Neolink is free software released under the GNU AGPL v3.
|
||||||
|
/// You can find its source code at https://github.com/thirtythreeforty/neolink
|
||||||
#[derive(StructOpt, Debug)]
|
#[derive(StructOpt, Debug)]
|
||||||
#[structopt(
|
#[structopt(
|
||||||
name = "neolink",
|
name = "neolink",
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
use neolink_core::bc_protocol::PrintFormat;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::clone::Clone;
|
use std::clone::Clone;
|
||||||
@@ -99,6 +100,9 @@ pub(crate) struct CameraConfig {
|
|||||||
#[serde(default = "default_strict")]
|
#[serde(default = "default_strict")]
|
||||||
/// If strict then the media stream will error in the event that the media packets are not as expected
|
/// If strict then the media stream will error in the event that the media packets are not as expected
|
||||||
pub(crate) strict: bool,
|
pub(crate) strict: bool,
|
||||||
|
|
||||||
|
#[serde(default = "default_print", alias = "print")]
|
||||||
|
pub(crate) print_format: PrintFormat,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Validate, Clone)]
|
#[derive(Debug, Deserialize, Validate, Clone)]
|
||||||
@@ -143,6 +147,10 @@ fn default_mqtt() -> Option<MqttConfig> {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn default_print() -> PrintFormat {
|
||||||
|
PrintFormat::None
|
||||||
|
}
|
||||||
|
|
||||||
fn default_discovery() -> String {
|
fn default_discovery() -> String {
|
||||||
"Relay".to_string()
|
"Relay".to_string()
|
||||||
}
|
}
|
||||||
|
|||||||
+13
@@ -7,6 +7,19 @@
|
|||||||
//! It contains sub commands for running an rtsp proxy which can be used on Reolink cameras
|
//! It contains sub commands for running an rtsp proxy which can be used on Reolink cameras
|
||||||
//! that do not nativly support RTSP.
|
//! that do not nativly support RTSP.
|
||||||
//!
|
//!
|
||||||
|
//! This program is free software: you can redistribute it and/or modify it under the terms of the
|
||||||
|
//! GNU General Public License as published by the Free Software Foundation, either version 3 of
|
||||||
|
//! the License, or (at your option) any later version.
|
||||||
|
//!
|
||||||
|
//! This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
//! without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
|
||||||
|
//! the GNU General Public License for more details.
|
||||||
|
//!
|
||||||
|
//! You should have received a copy of the GNU General Public License along with this program. If
|
||||||
|
//! not, see <https://www.gnu.org/licenses/>.
|
||||||
|
//!
|
||||||
|
//! Neolink source code is available online at <https://github.com/thirtythreeforty/neolink>
|
||||||
|
//!
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use env_logger::Env;
|
use env_logger::Env;
|
||||||
use log::*;
|
use log::*;
|
||||||
|
|||||||
+73
-2
@@ -25,6 +25,9 @@ pub(crate) enum Messages {
|
|||||||
IRLedOff,
|
IRLedOff,
|
||||||
IRLedAuto,
|
IRLedAuto,
|
||||||
Battery,
|
Battery,
|
||||||
|
PIROn,
|
||||||
|
PIROff,
|
||||||
|
PIRQuery,
|
||||||
Ptz(Direction),
|
Ptz(Direction),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,6 +162,7 @@ impl EventCam {
|
|||||||
camera_config.channel_id,
|
camera_config.channel_id,
|
||||||
&camera_config.username,
|
&camera_config.username,
|
||||||
camera_config.password.as_ref(),
|
camera_config.password.as_ref(),
|
||||||
|
camera_config.print_format,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.with_context(|| {
|
.with_context(|| {
|
||||||
@@ -322,8 +326,75 @@ impl MessageHandler {
|
|||||||
"OK".to_string()
|
"OK".to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Messages::Battery => {
|
Messages::Battery => match self.camera.battery_info().await {
|
||||||
todo!()
|
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::PIRQuery => match self.camera.get_pirstate().await {
|
||||||
|
Err(_) => {
|
||||||
|
error!("Failed to get pir status");
|
||||||
|
"FAIL".to_string()
|
||||||
|
}
|
||||||
|
Ok(pir_info) => {
|
||||||
|
let bytes_res = yaserde::ser::serialize_with_writer(
|
||||||
|
&pir_info,
|
||||||
|
vec![],
|
||||||
|
&Default::default(),
|
||||||
|
);
|
||||||
|
match bytes_res {
|
||||||
|
Ok(bytes) => match String::from_utf8(bytes) {
|
||||||
|
Ok(str) => str,
|
||||||
|
Err(_) => {
|
||||||
|
error!("Failed to encode pir status");
|
||||||
|
"FAIL".to_string()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(_) => {
|
||||||
|
error!("Failed to serialise pir status");
|
||||||
|
"FAIL".to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Messages::PIROn => {
|
||||||
|
if self.camera.pir_set(true).await.is_err() {
|
||||||
|
error!("Failed to turn on the pir");
|
||||||
|
self.abort();
|
||||||
|
"FAIL".to_string()
|
||||||
|
} else {
|
||||||
|
"OK".to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Messages::PIROff => {
|
||||||
|
if self.camera.pir_set(false).await.is_err() {
|
||||||
|
error!("Failed to turn on the pir");
|
||||||
|
self.abort();
|
||||||
|
"FAIL".to_string()
|
||||||
|
} else {
|
||||||
|
"OK".to_string()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Messages::Ptz(direction) => {
|
Messages::Ptz(direction) => {
|
||||||
let (bc_direction, amount) = match direction {
|
let (bc_direction, amount) = match direction {
|
||||||
|
|||||||
+32
-3
@@ -11,6 +11,7 @@ use log::*;
|
|||||||
/// Control messages:
|
/// Control messages:
|
||||||
///
|
///
|
||||||
/// - `/control/led [on|off]` Turns status LED on/off
|
/// - `/control/led [on|off]` Turns status LED on/off
|
||||||
|
/// - `/control/pir [on|off]` Turns PIR on/off
|
||||||
/// - `/control/ir [on|off|auto]` Turn IR lights on/off or automatically via light detection
|
/// - `/control/ir [on|off|auto]` Turn IR lights on/off or automatically via light detection
|
||||||
/// - `/control/reboot` Reboot the camera
|
/// - `/control/reboot` Reboot the camera
|
||||||
/// - `/control/ptz` [up|down|left|right|in|out] (amount) Control the PTZ movements, amount defaults to 32.0
|
/// - `/control/ptz` [up|down|left|right|in|out] (amount) Control the PTZ movements, amount defaults to 32.0
|
||||||
@@ -20,10 +21,12 @@ use log::*;
|
|||||||
/// `/status offline` Sent when the neolink goes offline this is a LastWill message
|
/// `/status offline` Sent when the neolink goes offline this is a LastWill message
|
||||||
/// `/status disconnected` Sent when the camera goes offline
|
/// `/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`
|
||||||
|
/// `/status/pir` Sent in reply to a `/query/pir`
|
||||||
///
|
///
|
||||||
/// Query Messages:
|
/// 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
|
||||||
|
/// `/query/pir` Request that the camera reports its pir status
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// # Usage
|
/// # Usage
|
||||||
@@ -193,7 +196,7 @@ async fn listen_on_camera(
|
|||||||
message: "on",
|
message: "on",
|
||||||
} => {
|
} => {
|
||||||
if event_cam.send_message(Messages::IRLedOn).await.is_err() {
|
if event_cam.send_message(Messages::IRLedOn).await.is_err() {
|
||||||
error!("Failed to set camera status light off");
|
error!("Failed to set camera status light on");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MqttReplyRef {
|
MqttReplyRef {
|
||||||
@@ -255,6 +258,22 @@ async fn listen_on_camera(
|
|||||||
error!("No PTZ Direction given. Please add up/down/left/right/in/out");
|
error!("No PTZ Direction given. Please add up/down/left/right/in/out");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
MqttReplyRef {
|
||||||
|
topic: "control/pir",
|
||||||
|
message: "on",
|
||||||
|
} => {
|
||||||
|
if event_cam.send_message(Messages::PIROn).await.is_err() {
|
||||||
|
error!("Failed to set pir on");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MqttReplyRef {
|
||||||
|
topic: "control/pir",
|
||||||
|
message: "off",
|
||||||
|
} => {
|
||||||
|
if event_cam.send_message(Messages::PIROff).await.is_err() {
|
||||||
|
error!("Failed to set pir off");
|
||||||
|
}
|
||||||
|
}
|
||||||
MqttReplyRef {
|
MqttReplyRef {
|
||||||
topic: "query/battery",
|
topic: "query/battery",
|
||||||
..
|
..
|
||||||
@@ -264,7 +283,17 @@ async fn listen_on_camera(
|
|||||||
error!("Failed to send battery status reply");
|
error!("Failed to send battery status reply");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_) => error!("Failed to set camera status light off"),
|
Err(_) => error!("Failed to get battery status"),
|
||||||
|
},
|
||||||
|
MqttReplyRef {
|
||||||
|
topic: "query/pir", ..
|
||||||
|
} => match event_cam.send_message_with_reply(Messages::PIRQuery).await {
|
||||||
|
Ok(reply) => {
|
||||||
|
if mqtt.send_message("status/pir", &reply, false).is_err() {
|
||||||
|
error!("Failed to send pir status reply");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(_) => error!("Failed to get pir status"),
|
||||||
},
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -19,5 +19,5 @@ pub struct Opt {
|
|||||||
pub camera: String,
|
pub camera: String,
|
||||||
/// Whether to turn the PIR ON or OFF
|
/// Whether to turn the PIR ON or OFF
|
||||||
#[structopt(parse(try_from_str = onoff_parse), name = "on|off")]
|
#[structopt(parse(try_from_str = onoff_parse), name = "on|off")]
|
||||||
pub on: bool,
|
pub on: Option<bool>,
|
||||||
}
|
}
|
||||||
+17
-4
@@ -27,9 +27,22 @@ pub(crate) use cmdline::Opt;
|
|||||||
pub(crate) async fn main(opt: Opt, config: Config) -> Result<()> {
|
pub(crate) async fn main(opt: Opt, config: Config) -> Result<()> {
|
||||||
let camera = find_and_connect(&config, &opt.camera).await?;
|
let camera = find_and_connect(&config, &opt.camera).await?;
|
||||||
|
|
||||||
camera
|
if let Some(on) = opt.on {
|
||||||
.pir_set(opt.on)
|
camera
|
||||||
.await
|
.pir_set(on)
|
||||||
.context("Unable to set camera PIR state")?;
|
.await
|
||||||
|
.context("Unable to set camera PIR state")?;
|
||||||
|
} else {
|
||||||
|
let pir_state = camera
|
||||||
|
.get_pirstate()
|
||||||
|
.await
|
||||||
|
.context("Unable to get camera PIR state")?;
|
||||||
|
let pir_ser = String::from_utf8(
|
||||||
|
yaserde::ser::serialize_with_writer(&pir_state, vec![], &Default::default())
|
||||||
|
.expect("Should Ser the struct"),
|
||||||
|
)
|
||||||
|
.expect("Should be UTF8");
|
||||||
|
println!("{}", pir_ser);
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -67,6 +67,7 @@ impl RtspCamera {
|
|||||||
config.channel_id,
|
config.channel_id,
|
||||||
&config.username,
|
&config.username,
|
||||||
config.password.as_ref(),
|
config.password.as_ref(),
|
||||||
|
config.print_format,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.with_context(|| {
|
.with_context(|| {
|
||||||
|
|||||||
+16
-5
@@ -4,7 +4,7 @@ use log::*;
|
|||||||
|
|
||||||
use super::config::{CameraConfig, Config};
|
use super::config::{CameraConfig, Config};
|
||||||
use anyhow::{anyhow, Context, Error, Result};
|
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};
|
use std::fmt::{Display, Error as FmtError, Formatter};
|
||||||
|
|
||||||
pub(crate) enum AddressOrUid {
|
pub(crate) enum AddressOrUid {
|
||||||
@@ -56,14 +56,24 @@ impl AddressOrUid {
|
|||||||
channel_id: u8,
|
channel_id: u8,
|
||||||
username: T,
|
username: T,
|
||||||
passwd: Option<U>,
|
passwd: Option<U>,
|
||||||
|
aux_print_format: PrintFormat,
|
||||||
) -> Result<BcCamera, Error> {
|
) -> Result<BcCamera, Error> {
|
||||||
match self {
|
match self {
|
||||||
AddressOrUid::Address(host) => {
|
AddressOrUid::Address(host) => {
|
||||||
Ok(BcCamera::new_with_addr(host, channel_id, username, passwd).await?)
|
Ok(
|
||||||
}
|
BcCamera::new_with_addr(host, channel_id, username, passwd, aux_print_format)
|
||||||
AddressOrUid::Uid(host, method) => {
|
.await?,
|
||||||
Ok(BcCamera::new_with_uid(host, channel_id, username, passwd, *method).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<Bc
|
|||||||
camera_config.channel_id,
|
camera_config.channel_id,
|
||||||
&camera_config.username,
|
&camera_config.username,
|
||||||
camera_config.password.as_ref(),
|
camera_config.password.as_ref(),
|
||||||
|
camera_config.print_format,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.with_context(|| {
|
.with_context(|| {
|
||||||
|
|||||||
Reference in new issue
Block a user