diff --git a/crates/core/src/bc/model.rs b/crates/core/src/bc/model.rs index 92c43cd..6f1b8be 100644 --- a/crates/core/src/bc/model.rs +++ b/crates/core/src/bc/model.rs @@ -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 diff --git a/crates/core/src/bc_protocol.rs b/crates/core/src/bc_protocol.rs index 78627aa..3421d5a 100644 --- a/crates/core/src/bc_protocol.rs +++ b/crates/core/src/bc_protocol.rs @@ -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}; diff --git a/crates/core/src/bc_protocol/motionstate.rs b/crates/core/src/bc_protocol/pirstate.rs similarity index 75% rename from crates/core/src/bc_protocol/motionstate.rs rename to crates/core/src/bc_protocol/pirstate.rs index 01dca49..6f61dfd 100644 --- a/crates/core/src/bc_protocol/motionstate.rs +++ b/crates/core/src/bc_protocol/pirstate.rs @@ -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 { + /// Get the [RfAlarmCfg] xml which contains the PIR status of the camera + pub fn get_pirstate(&mut self) -> Result { 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 diff --git a/src/cmdline.rs b/src/cmdline.rs index 089ded0..a550b9d 100644 --- a/src/cmdline.rs +++ b/src/cmdline.rs @@ -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), } diff --git a/src/main.rs b/src/main.rs index fb3e01b..0501727 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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)?; diff --git a/src/motion/cmdline.rs b/src/pir/cmdline.rs similarity index 90% rename from src/motion/cmdline.rs rename to src/pir/cmdline.rs index 17406d7..36d2ed4 100644 --- a/src/motion/cmdline.rs +++ b/src/pir/cmdline.rs @@ -12,7 +12,7 @@ fn onoff_parse(src: &str) -> Result { } } -/// 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 diff --git a/src/motion/mod.rs b/src/pir/mod.rs similarity index 53% rename from src/motion/mod.rs rename to src/pir/mod.rs index 2117b19..ac56a40 100644 --- a/src/motion/mod.rs +++ b/src/pir/mod.rs @@ -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(()) }