fixed some handshake socket issues
This commit is contained in:
parent
1bebdd1fd8
commit
ef96409082
3 changed files with 25 additions and 25 deletions
|
@ -81,25 +81,23 @@ impl<'a> CoordState<'a> {
|
||||||
self.sck_outbound.is_some()
|
self.sck_outbound.is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn socket_start(&mut self, conn: String) {
|
async fn socket_start(&mut self, conn: String) {
|
||||||
if !(self.sck_alive_recvr.load(Ordering::SeqCst)) {
|
info!("Starting socket");
|
||||||
info!("Starting socket");
|
|
||||||
|
|
||||||
match connect_async(conn).await {
|
match connect_async(conn).await {
|
||||||
Ok((val, _)) => {
|
Ok((val, _)) => {
|
||||||
info!("Socket connection to camera made successfully");
|
info!("Socket connection to camera made successfully");
|
||||||
|
|
||||||
let (outbound, inbound) = val.split();
|
let (outbound, inbound) = val.split();
|
||||||
self.rt.spawn(socket_listen(
|
self.rt.spawn(socket_listen(
|
||||||
self.to_mec.clone(),
|
self.to_mec.clone(),
|
||||||
self.sck_alive_recvr.clone(),
|
self.sck_alive_recvr.clone(),
|
||||||
inbound,
|
inbound,
|
||||||
));
|
));
|
||||||
self.sck_outbound = Some(outbound);
|
self.sck_outbound = Some(outbound);
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
error!("Couldn't connect to URL!");
|
error!("Couldn't connect to URL!");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,7 +120,7 @@ impl<'a> CoordState<'a> {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.sck_alive_server.load(Ordering::SeqCst) || self.sck_outbound.is_none() {
|
if !self.sck_alive_server.load(Ordering::SeqCst) {
|
||||||
info!("Restarting socket server");
|
info!("Restarting socket server");
|
||||||
self.sck_alive_server.store(true, Ordering::SeqCst);
|
self.sck_alive_server.store(true, Ordering::SeqCst);
|
||||||
self.rt.spawn(remote_sources::start_socketserver(
|
self.rt.spawn(remote_sources::start_socketserver(
|
||||||
|
|
|
@ -101,15 +101,12 @@ fn process_incoming_string(
|
||||||
ts.tracking_id = boxes[0].id;
|
ts.tracking_id = boxes[0].id;
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("boxes len: {}", boxes.len());
|
|
||||||
|
|
||||||
if let Some(target_box) = boxes.into_iter().find(|e| e.id == ts.tracking_id) {
|
if let Some(target_box) = boxes.into_iter().find(|e| e.id == ts.tracking_id) {
|
||||||
let x_adjust = calc_x_adjust(target_box.x1, target_box.x2);
|
let x_adjust = calc_x_adjust(target_box.x1, target_box.x2);
|
||||||
let y_adjust = calc_y_adjust(target_box.y1);
|
let y_adjust = calc_y_adjust(target_box.y1);
|
||||||
ts.last_detect = Instant::now();
|
ts.last_detect = Instant::now();
|
||||||
Ok((x_adjust, y_adjust))
|
Ok((x_adjust, y_adjust))
|
||||||
} else {
|
} else {
|
||||||
info!("Tracking ID: {}", ts.tracking_id);
|
|
||||||
Err("Couldn't find target in results".to_string())
|
Err("Couldn't find target in results".to_string())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -10,7 +10,7 @@ use std::{
|
||||||
use async_channel::Sender;
|
use async_channel::Sender;
|
||||||
use futures_core::FusedStream;
|
use futures_core::FusedStream;
|
||||||
use futures_util::{SinkExt, StreamExt};
|
use futures_util::{SinkExt, StreamExt};
|
||||||
use log::{error, info};
|
use log::{debug, error, info, warn};
|
||||||
use tokio::{
|
use tokio::{
|
||||||
net::{TcpListener, TcpStream},
|
net::{TcpListener, TcpStream},
|
||||||
runtime::Handle,
|
runtime::Handle,
|
||||||
|
@ -50,7 +50,7 @@ pub async fn start_socketserver(
|
||||||
let peer = stream
|
let peer = stream
|
||||||
.peer_addr()
|
.peer_addr()
|
||||||
.expect("connected streams should have a peer address");
|
.expect("connected streams should have a peer address");
|
||||||
info!("Peer address: {}", peer);
|
debug!("Peer address: {}", peer);
|
||||||
|
|
||||||
rt.spawn(accept_connection(
|
rt.spawn(accept_connection(
|
||||||
peer,
|
peer,
|
||||||
|
@ -109,14 +109,19 @@ async fn handle_connection(
|
||||||
};
|
};
|
||||||
|
|
||||||
if msg.is_text() && msg.to_string().starts_with("Type: ") {
|
if msg.is_text() && msg.to_string().starts_with("Type: ") {
|
||||||
match msg.to_string().split(' ').collect::<Vec<&str>>()[0] {
|
match msg.to_string().split(' ').collect::<Vec<&str>>()[1] {
|
||||||
"Automated" => {
|
"Automated" => {
|
||||||
|
debug!("Connection type is: Automated");
|
||||||
connection_type = Some(ConnectionType::Automated);
|
connection_type = Some(ConnectionType::Automated);
|
||||||
}
|
}
|
||||||
"Remote" => {
|
"Remote" => {
|
||||||
|
debug!("Connection type is: Remote");
|
||||||
connection_type = Some(ConnectionType::Remote);
|
connection_type = Some(ConnectionType::Remote);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {
|
||||||
|
warn!("Unknown connection type, dropping connection");
|
||||||
|
ws_stream.close(None).await?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue