Rework PIR data and fetch status

This commit is contained in:
QuantumEntangledAndy committed 2023-04-02 18:39:36 +07:00
1 parent 4fcaf4d538
commit 77be9483b0
6 files changed
+81 -15

No files matched your search

+4 -4
View File
@@ -27,10 +27,6 @@ pub const MSG_ID_MOTION_REQUEST: u32 = 31;
pub const MSG_ID_MOTION: u32 = 33;
/// Version messages have this ID
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
pub const MSG_ID_PING: u32 = 93;
/// General system info messages have this ID
@@ -45,6 +41,10 @@ pub const MSG_ID_TALK: u32 = 202;
pub const MSG_ID_GET_LED_STATUS: u32 = 208;
/// Setting the LED status is done with this ID
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
pub const MSG_ID_UDP_KEEP_ALIVE: u32 = 234;
/// Battery message initiaed by the camera
+48 -1
View File
@@ -336,7 +336,54 @@ pub struct RfAlarmCfg {
/// reduce False alarm boolean
pub reduceFalseAlarm: u8,
/// 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
@@ -253,12 +253,15 @@ impl UdpPayloadSource {
fn handle_ack(&mut self, ack: UdpAck) {
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() {
let packet_id = (start + 1) + idx as u32;
if value > 0 {
self.sent.remove(&packet_id);
for (idx, &value) in ack.payload.iter().enumerate() {
let packet_id = (start + 1) + idx as u32;
if value > 0 {
self.sent.remove(&packet_id);
}
}
}
}
+3
View File
@@ -166,6 +166,7 @@ local message_types = {
[210]="<PTOP>",
[211]="<PTOP> (write)",
[212]="<rfAlarmCfg>",
[213]="<rfAlarmCfg> (write)",
[216]="<EmailTask> (write)",
[217]="<EmailTask>",
[218]="<PushTask> (write)",
@@ -179,6 +180,8 @@ local message_types = {
[272]="<findAlarmVideo>",
[273]="<alarmVideoInfo>",
[274]="<findAlarmVideo>",
[319]="<timelapseCfg>",
[342]="<AiDetectCfg>",
}
local message_classes = {
+1 -1
View File
@@ -19,5 +19,5 @@ pub struct Opt {
pub camera: String,
/// Whether to turn the PIR ON or OFF
#[structopt(parse(try_from_str = onoff_parse), name = "on|off")]
pub on: bool,
pub on: Option<bool>,
}
+17 -4
View File
@@ -27,9 +27,22 @@ pub(crate) use cmdline::Opt;
pub(crate) async fn main(opt: Opt, config: Config) -> Result<()> {
let camera = find_and_connect(&config, &opt.camera).await?;
camera
.pir_set(opt.on)
.await
.context("Unable to set camera PIR state")?;
if let Some(on) = opt.on {
camera
.pir_set(on)
.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(())
}