small improvements, but tracker state do_send swapped?
This commit is contained in:
parent
36e5afeb57
commit
4b56e1bc5d
6 changed files with 44 additions and 13 deletions
|
@ -1,2 +1,5 @@
|
|||
ip = "localhost"
|
||||
port = 8765
|
||||
camera_ip = "10.0.0.33"
|
||||
camera_port = 8765
|
||||
tracker_ip = "localhost"
|
||||
tracker_port = 6543
|
||||
tracker_refresh_rate_millis = 100
|
||||
|
|
|
@ -22,7 +22,7 @@ impl Default for AppConfig {
|
|||
camera_port: 8765,
|
||||
|
||||
tracker_ip: "10.0.0.210".to_string(),
|
||||
tracker_port: 8765,
|
||||
tracker_port: 6543,
|
||||
tracker_refresh_rate_millis: 100,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,7 +73,8 @@ struct CoordState<'a> {
|
|||
pub rt: Handle,
|
||||
|
||||
pub pipeline: gstreamer_pipeline::WebcamPipeline,
|
||||
pub keep_windows_pipe_alive: Arc<AtomicBool>,
|
||||
pub tracker_keep_alive: Arc<AtomicBool>,
|
||||
pub tracker_is_alive: Arc<AtomicBool>,
|
||||
|
||||
pub tracker_state: Arc<Mutex<TrackerState>>,
|
||||
}
|
||||
|
@ -104,7 +105,8 @@ impl<'a> CoordState<'a> {
|
|||
rt,
|
||||
|
||||
pipeline: gstreamer_pipeline::WebcamPipeline::new(),
|
||||
keep_windows_pipe_alive: Arc::new(AtomicBool::new(true)),
|
||||
tracker_keep_alive: Arc::new(AtomicBool::new(false)),
|
||||
tracker_is_alive: Arc::new(AtomicBool::new(false)),
|
||||
|
||||
tracker_state,
|
||||
};
|
||||
|
@ -180,7 +182,8 @@ impl<'a> CoordState<'a> {
|
|||
conn_string,
|
||||
self.pipeline.sink_frame.clone(),
|
||||
self.to_mec.clone(),
|
||||
self.keep_windows_pipe_alive.clone(),
|
||||
self.tracker_keep_alive.clone(),
|
||||
self.tracker_is_alive.clone(),
|
||||
self.tracker_state.clone(),
|
||||
self.rt.clone(),
|
||||
));
|
||||
|
@ -195,7 +198,11 @@ impl<'a> CoordState<'a> {
|
|||
));
|
||||
}
|
||||
|
||||
if !self.keep_windows_pipe_alive.load(Ordering::SeqCst) {}
|
||||
if !self.tracker_is_alive.load(Ordering::SeqCst) {
|
||||
if self.tracker_keep_alive.load(Ordering::SeqCst) {
|
||||
self.start_video_loop().await;
|
||||
}
|
||||
}
|
||||
|
||||
if !self.sck_alive_server.load(Ordering::SeqCst) {
|
||||
info!("Restarting socket server");
|
||||
|
@ -222,7 +229,7 @@ impl<'a> CoordState<'a> {
|
|||
|
||||
pub async fn close(&mut self) {
|
||||
info!("closing coord state");
|
||||
self.keep_windows_pipe_alive.store(false, Ordering::SeqCst);
|
||||
self.tracker_keep_alive.store(false, Ordering::SeqCst);
|
||||
self.socket_close().await;
|
||||
|
||||
self.joystick_loop_alive.store(false, Ordering::SeqCst);
|
||||
|
@ -289,7 +296,9 @@ pub async fn start_coordinator(
|
|||
debug!("Trying to get lock on tracker_state for enable automatic");
|
||||
if let Ok(mut ts) = state.tracker_state.lock() {
|
||||
ts.enabled = do_enable;
|
||||
state.tracker_keep_alive.store(do_enable, Ordering::SeqCst);
|
||||
}
|
||||
state.check_states().await;
|
||||
}
|
||||
ApplicationEvent::MoveEvent(coord, priority) => {
|
||||
// If Automatic control, but local event happens, override the automatice events for 2 seconds
|
||||
|
|
|
@ -28,19 +28,22 @@ pub async fn remote_video_loop(
|
|||
appsink: Arc<Mutex<AppSink>>,
|
||||
to_mec: Sender<ApplicationEvent>,
|
||||
keep_alive: Arc<AtomicBool>,
|
||||
is_alive: Arc<AtomicBool>,
|
||||
tracker_state: Arc<Mutex<TrackerState>>,
|
||||
runtime: Handle,
|
||||
) {
|
||||
info!("Starting remote tracker processing connection to: {}", conn_string);
|
||||
let video_info =
|
||||
gstreamer_video::VideoInfo::builder(gstreamer_video::VideoFormat::Rgb, 640, 480)
|
||||
.build()
|
||||
.expect("Could not build video info!");
|
||||
|
||||
loop {
|
||||
is_alive.store(true, Ordering::SeqCst);
|
||||
match connect_async(&conn_string).await {
|
||||
Err(e) => {
|
||||
error!("Could not connect to remote video loop! Trying again in 5 seconds: {e}");
|
||||
sleep_until(Instant::now() + Duration::from_secs(5)).await;
|
||||
error!("Could not connect to remote video loop! Trying again in 1 seconds: {e}");
|
||||
sleep_until(Instant::now() + Duration::from_secs(1)).await;
|
||||
}
|
||||
Ok((connection, _)) => {
|
||||
let (mut sender, recvr) = connection.split();
|
||||
|
@ -92,6 +95,11 @@ pub async fn remote_video_loop(
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
if !keep_alive.load(Ordering::SeqCst) {
|
||||
info!("Shutting down remote video loop");
|
||||
break;
|
||||
}
|
||||
// rate limit updates
|
||||
sleep_until(Instant::now() + Duration::from_millis(50)).await;
|
||||
}
|
||||
|
@ -102,6 +110,7 @@ pub async fn remote_video_loop(
|
|||
break;
|
||||
}
|
||||
}
|
||||
is_alive.store(false, Ordering::SeqCst);
|
||||
}
|
||||
|
||||
async fn listen_to_messages(
|
||||
|
@ -110,14 +119,19 @@ async fn listen_to_messages(
|
|||
tracker_state: Arc<Mutex<TrackerState>>,
|
||||
keep_alive: Arc<AtomicBool>,
|
||||
) {
|
||||
info!("Starting tracker connection listen");
|
||||
while keep_alive.load(Ordering::SeqCst) {
|
||||
match recvr.try_next().await {
|
||||
Ok(Some(message)) => {
|
||||
let (x_off, y_off, do_send) =
|
||||
let (x_off, y_off, _do_send) =
|
||||
process_incoming_string(message.to_string(), &tracker_state)
|
||||
.and_then(|_| calculate_tracking(&tracker_state))
|
||||
.unwrap_or((0, 0, false));
|
||||
|
||||
let do_send = true;
|
||||
|
||||
// For some reason, this do_send is inverted from what it should be
|
||||
// info!("Do Send is: {}", do_send.to_string());
|
||||
if do_send {
|
||||
if let Err(e) = to_mec
|
||||
.send(ApplicationEvent::MoveEvent(
|
||||
|
@ -138,6 +152,7 @@ async fn listen_to_messages(
|
|||
}
|
||||
}
|
||||
}
|
||||
info!("Stopping tracker connection listen with keep alive: {}", keep_alive.load(Ordering::SeqCst));
|
||||
}
|
||||
|
||||
fn get_video_frame(
|
||||
|
|
|
@ -120,7 +120,7 @@ impl ConnectionsModal {
|
|||
main_box.append(&quit_button);
|
||||
|
||||
let new_ref = app_config.clone();
|
||||
quit_button.connect_activate(clone!(
|
||||
quit_button.connect_clicked(clone!(
|
||||
@strong rt,
|
||||
@weak camera_ip_entry, @weak camera_port_entry,
|
||||
@weak tracker_ip_entry, @weak tracker_port_entry,
|
||||
|
@ -132,6 +132,7 @@ impl ConnectionsModal {
|
|||
let new_tracker_ip = tracker_ip_entry.text().to_string();
|
||||
let new_tracker_port = tracker_port_entry.text().parse::<u32>().unwrap();
|
||||
let new_tracker_millis = tracker_refresh_millis.text().parse::<u32>().unwrap();
|
||||
info!("Starting config save");
|
||||
|
||||
{
|
||||
// maybe just send the police.
|
||||
|
|
|
@ -85,7 +85,10 @@ impl TrackerPanel {
|
|||
.margin_bottom(12)
|
||||
.build();
|
||||
|
||||
let enable_disable = ToggleButton::with_label("Enable Automatic Tracking");
|
||||
let enable_disable = ToggleButton::builder()
|
||||
.label("Enable Automatic Tracking")
|
||||
.active(false)
|
||||
.build();
|
||||
|
||||
let current_id = Label::builder()
|
||||
.label("Not Tracking")
|
||||
|
|
Loading…
Reference in a new issue