Compare commits

..

2 commits

Author SHA1 Message Date
Nickiel12
0a47c7a958 fixed pong messages being sent to the wrong socket 2024-07-04 09:03:31 -07:00
Nickiel12
047a180664 added debug console logging 2024-07-04 09:03:17 -07:00
4 changed files with 19 additions and 7 deletions

View file

@ -7,6 +7,7 @@ edition = "2021"
[features] [features]
tracker-state-debug = [] tracker-state-debug = []
tokio-logging = []
[dependencies] [dependencies]
async-channel = "2.2.0" async-channel = "2.2.0"

View file

@ -193,9 +193,11 @@ pub async fn start_coordinator(
y_adj = y; y_adj = y;
} }
Err(e) => { Err(e) => {
if state.tracker_state.tracking_id > 0 {
info!("Could not calculate the tracking!: {e}"); info!("Could not calculate the tracking!: {e}");
} }
} }
}
let me = MoveEvent { x: x_adj, y: y_adj }; let me = MoveEvent { x: x_adj, y: y_adj };
if let Err(e) = state if let Err(e) = state

View file

@ -6,7 +6,7 @@ use std::{
use async_recursion::async_recursion; use async_recursion::async_recursion;
use async_channel::Sender; use async_channel::Sender;
use futures_util::{stream::SplitStream, SinkExt, StreamExt, TryStreamExt}; use futures_util::{stream::{SplitSink, SplitStream}, SinkExt, StreamExt, TryStreamExt};
use gstreamer_app::AppSink; use gstreamer_app::AppSink;
use tokio::{net::TcpStream, sync::Mutex, time::sleep_until}; use tokio::{net::TcpStream, sync::Mutex, time::sleep_until};
use tokio_tungstenite::{connect_async, tungstenite::Message, MaybeTlsStream, WebSocketStream}; use tokio_tungstenite::{connect_async, tungstenite::Message, MaybeTlsStream, WebSocketStream};
@ -75,7 +75,7 @@ pub async fn remote_video_loop(
break; break;
} }
let do_not_break = handle_message(&mut recvr, &to_mec, last_iter).await; let do_not_break = handle_message(&mut recvr, &mut sender, &to_mec, last_iter).await;
if !do_not_break { break; } if !do_not_break { break; }
@ -131,6 +131,7 @@ fn get_video_frame(appsink: &AppSink) -> Result<Message, String> {
#[async_recursion] #[async_recursion]
async fn handle_message( async fn handle_message(
recvr: &mut SplitStream<WebSocketStream<MaybeTlsStream<TcpStream>>>, recvr: &mut SplitStream<WebSocketStream<MaybeTlsStream<TcpStream>>>,
sender: &mut SplitSink<WebSocketStream<MaybeTlsStream<TcpStream>>, Message>,
to_mec: &Sender<ApplicationEvent>, to_mec: &Sender<ApplicationEvent>,
last_iter: Instant, last_iter: Instant,
) -> bool { ) -> bool {
@ -144,15 +145,15 @@ async fn handle_message(
Message::Pong(_) | Message::Frame(_) | Message::Text(_) => { Message::Pong(_) | Message::Frame(_) | Message::Text(_) => {
warn!("There was an unhandled message type from the camera: {}\n{}", message, message.to_string()); warn!("There was an unhandled message type from the camera: {}\n{}", message, message.to_string());
// this was not the expected response, recursion! // this was not the expected response, recursion!
return handle_message(recvr, to_mec, last_iter).await; return handle_message(recvr, sender, to_mec, last_iter).await;
} }
Message::Ping(content) => { Message::Ping(content) => {
if let Err(e) = to_mec.send(ApplicationEvent::SocketMessage(Message::Pong(content))).await { if let Err(e) = sender.send(Message::Pong(content)).await {
error!("Video processor could not send message to MEC, exiting: {e}"); error!("Video processor could not send message to MEC, exiting: {e}");
return false; return false;
} }
// this was not the expected response, recursion! // this was not the expected response, recursion!
return handle_message(recvr, to_mec, last_iter).await; return handle_message(recvr, sender, to_mec, last_iter).await;
} }
Message::Binary(bin) => { Message::Binary(bin) => {
let message = std::str::from_utf8(&bin); let message = std::str::from_utf8(&bin);

View file

@ -31,11 +31,19 @@ fn main() -> glib::ExitCode {
.with_ansi(false) .with_ansi(false)
.init(); .init();
} }
#[cfg(debug_assertions)] #[cfg(all(not(feature = "tokio-debug"), debug_assertions))]
{
let sub = tracing_subscriber::FmtSubscriber::new();
if let Err(e) = tracing::subscriber::set_global_default(sub) {
panic!("Could not set tracing global: {e}");
}
}
#[cfg(feature = "tokio-debug")]
{ {
console_subscriber::init(); console_subscriber::init();
} }
let span = tracing::span!(Level::TRACE, "main"); let span = tracing::span!(Level::TRACE, "main");
let _enter = span.enter(); let _enter = span.enter();