-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom-viewer.rs
More file actions
117 lines (95 loc) · 4.02 KB
/
custom-viewer.rs
File metadata and controls
117 lines (95 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// A custom rerun viewer capable of showing and editing settings
use probe_plotter_tools::{gui::MyApp, parse, probe_background_thread, setting::Setting};
use rerun::external::{eframe, re_crash_handler, re_grpc_server, re_viewer, tokio};
use std::{env, io::Read, sync::mpsc, thread, time::Duration};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let help =
"Usage: \nprobe-plotter /path/to/elf [chip] [update_rate_ms=10] [channel_mode=no change]";
let elf_path = env::args().nth(1).expect(help);
let target = env::args()
.nth(2)
.unwrap_or_else(|| "stm32g474retx".to_owned());
let update_rate = env::args()
.nth(3)
.map(|s| {
Duration::from_millis(
s.parse()
.unwrap_or_else(|_| panic!("Invalid update_rate\n\n{help}")),
)
})
.unwrap_or_else(|| Duration::from_millis(10));
let channel_mode = env::args()
.nth(4)
.map(|s| match s.as_str() {
"NoBlockSkip" => probe_rs::rtt::ChannelMode::NoBlockSkip,
"NoBlockTrim" => probe_rs::rtt::ChannelMode::NoBlockTrim,
"BlockIfFull" => probe_rs::rtt::ChannelMode::BlockIfFull,
_ => panic!("Invalid channel_mode. Select one of\n* NoBlockSkip\n* NoBlockTrim\n* BlockIfFull\n\n{help}"),
});
let mut elf_bytes = Vec::new();
std::fs::File::open(elf_path)
.unwrap()
.read_to_end(&mut elf_bytes)
.unwrap();
let (metrics, settings, scan_region) = parse(&elf_bytes);
let main_thread_token = rerun::MainThreadToken::i_promise_i_am_on_the_main_thread();
// Direct calls using the `log` crate to stderr. Control with `RUST_LOG=debug` etc.
// Install handlers for panics and crashes that prints to stderr and send
// them to Rerun analytics (if the `analytics` feature is on in `Cargo.toml`).
re_crash_handler::install_crash_handlers(rerun::build_info());
// Listen for gRPC connections from Rerun's logging SDKs.
// There are other ways of "feeding" the viewer though - all you need is a `re_smart_channel::Receiver`.
let (rx, _) = re_grpc_server::spawn_with_recv(
"0.0.0.0:9876".parse().unwrap(),
"75%".parse().unwrap(),
re_grpc_server::shutdown::never(),
);
let (settings_update_sender, settings_update_receiver) = mpsc::channel::<Setting>();
let mut native_options = re_viewer::native::eframe_options(None);
native_options.viewport = native_options.viewport.with_app_id("probe-plotter");
let startup_options = re_viewer::StartupOptions::default();
// This is used for analytics, if the `analytics` feature is on in `Cargo.toml`
let app_env = re_viewer::AppEnvironment::Custom("probe-plotter-tools".to_owned());
let (initial_settings_sender, initial_settings_receiver) = mpsc::channel();
// probe-thread
thread::spawn(move || {
probe_background_thread(
update_rate,
channel_mode,
&target,
&elf_bytes,
settings,
metrics,
scan_region,
settings_update_receiver,
initial_settings_sender,
)
});
// Receive initial settings from to probe-thread thread
let settings = initial_settings_receiver.recv().unwrap();
let window_title = "probe-plotter";
eframe::run_native(
window_title,
native_options,
Box::new(move |cc| {
re_viewer::customize_eframe_and_setup_renderer(cc)?;
let mut rerun_app = re_viewer::App::new(
main_thread_token,
re_viewer::build_info(),
&app_env,
startup_options,
cc,
None,
re_viewer::AsyncRuntimeHandle::from_current_tokio_runtime_or_wasmbindgen()?,
);
rerun_app.add_log_receiver(rx);
Ok(Box::new(MyApp::new(
rerun_app,
settings,
settings_update_sender,
)))
}),
)?;
Ok(())
}