Skip to content

Commit 3192eef

Browse files
Rerun custom (space) view (#437)
1 parent aa18bb5 commit 3192eef

21 files changed

Lines changed: 781 additions & 495 deletions

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/re_control/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "re_control"
3-
version = "0.3.0"
3+
version = "0.4.0"
44

55
authors.workspace = true
66
categories.workspace = true
@@ -9,6 +9,7 @@ rust-version.workspace = true
99

1010
[dependencies]
1111
heimdall = { workspace = true }
12+
sindri = { workspace = true }
1213

1314
clap = { workspace = true, features = ["derive"] }
1415
miette = { workspace = true }

tools/re_control/re_control_comms/src/viewer.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use super::protocol::{HandlerFn, RobotMessage, ViewerMessage};
2020

2121
const LINGER_DURATION: Duration = Duration::from_secs(2);
2222
const CONNECTION_ATTEMPT_DELAY: Duration = Duration::from_secs(5);
23+
const CONNECTION_ATTEMPTS: usize = 3;
2324

2425
pub struct ControlViewer {
2526
address: SocketAddrV4,
@@ -61,7 +62,7 @@ impl ControlViewer {
6162
let handle = app.clone();
6263

6364
tokio::spawn(async move {
64-
loop {
65+
for attempt in 1..=CONNECTION_ATTEMPTS {
6566
let socket = Socket::new(
6667
Domain::for_address(app.address.into()),
6768
Type::STREAM,
@@ -80,7 +81,13 @@ impl ControlViewer {
8081
app.handle_connection(stream).await;
8182
}
8283
Err(error) => {
83-
tracing::error!(?error, "failed to connect to {}", app.address);
84+
tracing::debug!(
85+
?error,
86+
"failed to connect to {}, attempt [{}/{}]",
87+
app.address,
88+
attempt,
89+
CONNECTION_ATTEMPTS
90+
);
8491
}
8592
}
8693

@@ -93,7 +100,6 @@ impl ControlViewer {
93100
}
94101

95102
async fn handle_connection(&self, socket: TcpStream) {
96-
tracing::info!("connected with app: {}", self.address);
97103
let (read_half, write_half) = socket.split();
98104

99105
// Spawn tasks to handle read and write
@@ -116,7 +122,7 @@ impl ControlViewer {
116122
// is completed.
117123
writer_task.abort();
118124

119-
tracing::warn!("connection termintaed with app: {}", self.address);
125+
tracing::warn!("connection terminated with app: {}", self.address);
120126
}
121127

122128
async fn global_message_handler(
@@ -133,7 +139,7 @@ impl ControlViewer {
133139
}
134140
notify.notify_one();
135141
}
136-
tracing::info!("Global message channel closed");
142+
tracing::debug!("Global message channel closed");
137143
}
138144

139145
async fn handle_read(
@@ -223,6 +229,11 @@ pub struct ControlViewerHandle {
223229
}
224230

225231
impl ControlViewerHandle {
232+
#[must_use]
233+
pub fn addr(&self) -> SocketAddrV4 {
234+
self.app.address
235+
}
236+
226237
pub fn send(&self, msg: ViewerMessage) -> Result<()> {
227238
self.app.tx.unbounded_send(msg).into_diagnostic()
228239
}

tools/re_control/src/app.rs

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
11
use std::net::Ipv4Addr;
22

33
use miette::{IntoDiagnostic, Result};
4-
use re_control_comms::viewer::ControlViewer;
5-
use re_viewer::{external::eframe, StartupOptions};
4+
use re_viewer::StartupOptions;
65

7-
use crate::control::Control;
6+
use crate::re_control_view::ControlView;
87

98
// Rerun can collect analytics if the `analytics` feature is enabled in
109
// `Cargo.toml`. This variable is used for the rerun analytics
1110
const APP_ENV: &str = "Control Wrapper";
1211

1312
pub struct App {
1413
startup_options: StartupOptions,
15-
viewer: ControlViewer,
1614
}
1715

1816
impl App {
19-
pub fn new(startup_options: StartupOptions, viewer: ControlViewer) -> Self {
20-
App {
21-
startup_options,
22-
viewer,
23-
}
17+
pub fn new(startup_options: StartupOptions) -> Self {
18+
App { startup_options }
2419
}
2520

2621
pub async fn run(self, main_thread_token: re_viewer::MainThreadToken) -> Result<()> {
@@ -35,20 +30,9 @@ impl App {
3530
)
3631
.into_diagnostic()?;
3732

38-
let rerun_native_options = re_viewer::native::eframe_options(None);
39-
let native_options = eframe::NativeOptions {
40-
viewport: rerun_native_options
41-
.viewport
42-
.with_app_id("yggdrasil_control"),
43-
..rerun_native_options
44-
};
45-
46-
eframe::run_native(
47-
"Rerun",
48-
native_options,
33+
re_viewer::run_native_app(
34+
main_thread_token,
4935
Box::new(move |cc| {
50-
re_viewer::customize_eframe_and_setup_renderer(cc)?;
51-
5236
let mut app = re_viewer::App::new(
5337
main_thread_token,
5438
re_viewer::build_info(),
@@ -58,8 +42,13 @@ impl App {
5842
cc.storage,
5943
);
6044
app.add_receiver(rx);
61-
Ok(Box::new(Control::new(app, self.viewer)))
45+
46+
// Register the custom view class
47+
app.add_view_class::<ControlView>().unwrap();
48+
49+
Box::new(app)
6250
}),
51+
None,
6352
)
6453
.into_diagnostic()?;
6554

tools/re_control/src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clap::Parser;
55
#[derive(Parser, Debug)]
66
pub struct Cli {
77
/// Robot ip address
8-
pub robot_ip: Ipv4Addr,
8+
pub robot_ip: Option<Ipv4Addr>,
99

1010
/// Max allowed memory usage for rerun, absolute (e.g. "16GB") or relative
1111
/// (e.g. "50%")

tools/re_control/src/connection.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use re_control_comms::viewer::ControlViewerHandle;
2+
use sindri::config::{ConfigRobot, Robot};
3+
4+
pub struct ConnectionState {
5+
pub handle: ControlViewerHandle,
6+
pub selected_robot_config: ConfigRobot,
7+
pub team_number: u8,
8+
pub wired_connection: bool,
9+
pub possible_robot_connections: Vec<ConfigRobot>,
10+
}
11+
12+
impl ConnectionState {
13+
pub fn from_handle(handle: ControlViewerHandle) -> Self {
14+
let sindri_config = sindri::config::load_config().unwrap();
15+
16+
let robots = sindri_config.robots;
17+
18+
ConnectionState {
19+
handle,
20+
selected_robot_config: robots[0].clone(),
21+
team_number: sindri_config.team_number,
22+
wired_connection: false,
23+
possible_robot_connections: robots,
24+
}
25+
}
26+
27+
pub fn robot_from_state(&self) -> Robot {
28+
self.selected_robot_config
29+
.clone()
30+
.to_robot(self.team_number, self.wired_connection)
31+
}
32+
}

0 commit comments

Comments
 (0)