Rename command from motion to pir

This commit is contained in:
Joris Bremond committed 2022-05-14 14:23:01 +02:00
1 parent 9f1bcd6f55
commit 2b56705172
7 files changed
+33 -33

No files matched your search

+2 -2
View File
@@ -19,9 +19,9 @@ pub const MSG_ID_REBOOT: u32 = 23;
/// Version messages have this ID
pub const MSG_ID_VERSION: u32 = 80;
/// Getting PIR status messages have this ID
pub const MSG_ID_GET_MOTION_ALARM: u32 = 212;
pub const MSG_ID_GET_PIR_ALARM: u32 = 212;
/// Setting PIR status messages have this ID
pub const MSG_ID_START_MOTION_ALARM: u32 = 213;
pub const MSG_ID_START_PIR_ALARM: u32 = 213;
/// Ping messages have this ID
pub const MSG_ID_PING: u32 = 93;
/// General system info messages have this ID
+2 -2
View File
@@ -13,7 +13,7 @@ mod login;
mod logout;
mod ping;
mod reboot;
mod motionstate;
mod pirstate;
mod resolution;
mod stream;
mod talk;
@@ -25,7 +25,7 @@ use bc::model::*;
pub(crate) use connection::*;
pub use errors::Error;
pub use ledstate::LightState;
pub use motionstate::MotionState;
pub use pirstate::PirState;
pub use resolution::*;
pub use stream::{Stream, StreamOutput, StreamOutputError};
@@ -2,16 +2,16 @@ use super::{BcCamera, Error, Result, RX_TIMEOUT};
use crate::bc::{model::*, xml::*};
impl BcCamera {
/// Get the [RfAlarmCfg] xml which contains the motion status of the camera
pub fn get_motionstate(&mut self) -> Result<RfAlarmCfg> {
/// Get the [RfAlarmCfg] xml which contains the PIR status of the camera
pub fn get_pirstate(&mut self) -> Result<RfAlarmCfg> {
let connection = self
.connection
.as_ref()
.expect("Must be connected to get time");
let sub_get = connection.subscribe(MSG_ID_GET_MOTION_ALARM)?;
let sub_get = connection.subscribe(MSG_ID_GET_PIR_ALARM)?;
let get = Bc {
meta: BcMeta {
msg_id: MSG_ID_GET_MOTION_ALARM,
msg_id: MSG_ID_GET_PIR_ALARM,
channel_id: self.channel_id,
msg_num: self.new_message_num(),
response_code: 0,
@@ -33,32 +33,32 @@ impl BcCamera {
if let BcBody::ModernMsg(ModernMsg {
payload:
Some(BcPayloads::BcXml(BcXml {
rf_alarm_cfg: Some(motionstate),
rf_alarm_cfg: Some(pirstate),
..
})),
..
}) = msg.body
{
Ok(motionstate)
Ok(pirstate)
} else {
Err(Error::UnintelligibleReply {
reply: msg,
why: "Expected MotionSate xml but it was not recieved",
why: "Expected PirSate xml but it was not recieved",
})
}
}
/// Set the PIR sensor using the [RfAlarmCfg] xml
pub fn set_motionstate(&mut self, rf_alarm_cfg: RfAlarmCfg) -> Result<()> {
pub fn set_pirstate(&mut self, rf_alarm_cfg: RfAlarmCfg) -> Result<()> {
let connection = self
.connection
.as_ref()
.expect("Must be connected to get time");
let sub_set = connection.subscribe(MSG_ID_START_MOTION_ALARM)?;
let sub_set = connection.subscribe(MSG_ID_START_PIR_ALARM)?;
let get = Bc {
meta: BcMeta {
msg_id: MSG_ID_START_MOTION_ALARM,
msg_id: MSG_ID_START_PIR_ALARM,
channel_id: self.channel_id,
msg_num: self.new_message_num(),
response_code: 0,
@@ -97,20 +97,20 @@ impl BcCamera {
/// This is a convience function to control the PIR status
/// True is on and false is off
pub fn motion_set(&mut self, state: bool) -> Result<()> {
let mut motion_state = self.get_motionstate()?;
// println!("{:?}", motion_state);
motion_state.enable = match state {
pub fn pir_set(&mut self, state: bool) -> Result<()> {
let mut pir_state = self.get_pirstate()?;
// println!("{:?}", pir_state);
pir_state.enable = match state {
true => 1,
false => 0,
};
self.set_motionstate(motion_state)?;
self.set_pirstate(pir_state)?;
Ok(())
}
}
/// Turn PIR ON or OFF
pub enum MotionState {
pub enum PirState {
/// Turn the PIR on
On,
/// Turn the PIR off
+1 -1
View File
@@ -20,6 +20,6 @@ pub enum Command {
Rtsp(super::rtsp::Opt),
StatusLight(super::statusled::Opt),
Reboot(super::reboot::Opt),
Motion(super::motion::Opt),
Pir(super::pir::Opt),
Talk(super::talk::Opt),
}
+3 -3
View File
@@ -17,7 +17,7 @@ use validator::Validate;
mod cmdline;
mod config;
mod reboot;
mod motion;
mod pir;
mod rtsp;
mod statusled;
mod talk;
@@ -65,8 +65,8 @@ fn main() -> Result<()> {
Some(Command::Reboot(opts)) => {
reboot::main(opts, config)?;
}
Some(Command::Motion(opts)) => {
motion::main(opts, config)?;
Some(Command::Pir(opts)) => {
pir::main(opts, config)?;
}
Some(Command::Talk(opts)) => {
talk::main(opts, config)?;
+1 -1
View File
@@ -12,7 +12,7 @@ fn onoff_parse(src: &str) -> Result<bool> {
}
}
/// The motion command will control the motion status off the camera
/// The pir command will control the PIR status of the camera
#[derive(StructOpt, Debug)]
pub struct Opt {
/// The name of the camera. Must be a name in the config
+8 -8
View File
@@ -1,16 +1,16 @@
///
/// # Neolink Motion
/// # Neolink PIR
///
/// This module handles the controls of the motion alarm
/// This module handles the controls of the pir sensor alarm
///
///
/// # Usage
///
/// ```bash
/// # To turn the motion on
/// neolink motion --config=config.toml CameraName on
/// # To turn the pir sensor on
/// neolink pir --config=config.toml CameraName on
/// # Or off
/// neolink motion --config=config.toml CameraName off
/// neolink pir --config=config.toml CameraName off
/// ```
///
use anyhow::{Context, Result};
@@ -21,14 +21,14 @@ use super::config::Config;
use crate::utils::find_and_connect;
pub(crate) use cmdline::Opt;
/// Entry point for the motion subcommand
/// Entry point for the pir subcommand
///
/// Opt is the command line options
pub(crate) fn main(opt: Opt, config: Config) -> Result<()> {
let mut camera = find_and_connect(&config, &opt.camera)?;
camera
.motion_set(opt.on)
.context("Unable to set camera motion state")?;
.pir_set(opt.on)
.context("Unable to set camera PIR state")?;
Ok(())
}