Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumEntangledAndy committed May 14, 2023
2 parents eed2aeb + 634bff0 commit 61f65ed
Show file tree
Hide file tree
Showing 5 changed files with 269 additions and 181 deletions.
6 changes: 3 additions & 3 deletions crates/core/src/bc_protocol/connection/udpsource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ impl Stream for UdpPayloadSource {

fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
let camera_addr = self.inner.addr;
let mut this = self.get_mut();
let this = self.get_mut();
match this.state {
State::Normal => {
// this.state = State::YieldNow;
Expand Down Expand Up @@ -417,7 +417,7 @@ impl Sink<Vec<u8>> for UdpPayloadSource {
}
}
fn start_send(self: Pin<&mut Self>, item: Vec<u8>) -> std::result::Result<(), Self::Error> {
let mut this = self.get_mut();
let this = self.get_mut();
for chunk in item.chunks(MTU - UDPDATA_HEADER_SIZE) {
let udp_data = UdpData {
connection_id: this.camera_id,
Expand Down Expand Up @@ -487,7 +487,7 @@ impl Sink<Vec<u8>> for UdpPayloadSource {
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<std::result::Result<(), Self::Error>> {
let mut this = self.get_mut();
let this = self.get_mut();
if let State::Closed = this.state {
return Poll::Ready(Ok(()));
}
Expand Down
3 changes: 3 additions & 0 deletions crates/core/src/bc_protocol/ptz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pub enum Direction {
In,
/// To zoom the camera Out (may be done with cropping depending on camera model)
Out,
/// To stop currently active PTZ command
Stop,
}

impl BcCamera {
Expand All @@ -36,6 +38,7 @@ impl BcCamera {
Direction::Out => {
todo!()
}
Direction::Stop => "stop",
}
.to_string();
let send = Bc {
Expand Down
54 changes: 40 additions & 14 deletions src/mqtt/event_cam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ use std::sync::Arc;
use tokio::{
sync::mpsc::{channel, Receiver, Sender},
task::JoinSet,
time::sleep,
};

use core::time::Duration;

#[derive(Debug, Copy, Clone)]
pub(crate) enum Messages {
Login,
Expand All @@ -31,12 +34,12 @@ pub(crate) enum Messages {

#[derive(Debug, Copy, Clone)]
pub(crate) enum Direction {
Up(f32),
Down(f32),
Left(f32),
Right(f32),
In(f32),
Out(f32),
Up(f32, f32),
Down(f32, f32),
Left(f32, f32),
Right(f32, f32),
In(f32, f32),
Out(f32, f32),
}

#[derive(Debug)]
Expand Down Expand Up @@ -408,19 +411,42 @@ impl<'a> MessageHandler<'a> {
}
}
Messages::Ptz(direction) => {
let (bc_direction, amount) = match direction {
Direction::Up(amount) => (BcDirection::Up, amount),
Direction::Down(amount) => (BcDirection::Down, amount),
Direction::Left(amount) => (BcDirection::Left, amount),
Direction::Right(amount) => (BcDirection::Right, amount),
Direction::In(amount) => (BcDirection::In, amount),
Direction::Out(amount) => (BcDirection::Out, amount),
let (bc_direction, amount, seconds) = match direction {
Direction::Up(amount, seconds) => {
(BcDirection::Up, amount, seconds)
}
Direction::Down(amount, seconds) => {
(BcDirection::Down, amount, seconds)
}
Direction::Left(amount, seconds) => {
(BcDirection::Left, amount, seconds)
}
Direction::Right(amount, seconds) => {
(BcDirection::Right, amount, seconds)
}
Direction::In(amount, seconds) => {
(BcDirection::In, amount, seconds)
}
Direction::Out(amount, seconds) => {
(BcDirection::Out, amount, seconds)
}
};
if let Err(e) = self.camera.send_ptz(bc_direction, amount).await {
error = Some(format!("Failed to send PTZ: {:?}", e));
"FAIL".to_string()
} else {
"OK".to_string()
// sleep for the designated seconds
sleep(Duration::from_secs_f32(seconds)).await;

// note that amount is not used in the stop command
if let Err(e) =
self.camera.send_ptz(BcDirection::Stop, amount).await
{
error = Some(format!("Failed to send PTZ: {:?}", e));
"FAIL".to_string()
} else {
"OK".to_string()
}
}
}
_ => "UNKNOWN COMMAND".to_string(),
Expand Down
Loading

0 comments on commit 61f65ed

Please sign in to comment.