Skip to content

Commit 9cdd8fe

Browse files
author
Florian Guggi
committed
fix: Update config file for COBC sim tool
1 parent 3236b9b commit 9cdd8fe

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

scheduler/examples/cli.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
use std::{
22
error::Error,
33
io::{Read, Write},
4-
path::Path,
4+
path::{Path, PathBuf},
55
process::{Child, ChildStdin, ChildStdout, Stdio},
66
time::Duration,
77
};
88

99
use STS1_EDU_Scheduler::communication::{CEPPacket, CommunicationHandle};
1010

1111
fn main() {
12-
let scheduler_path =
13-
std::env::args().nth(1).expect("Pass in the directory containing the scheduler binary");
12+
let scheduler_path = PathBuf::from(
13+
std::env::args().nth(1).expect("Pass in the directory containing the scheduler binary"),
14+
);
1415

15-
let mut serial = SocatSerialPort::new(&format!("{scheduler_path}/virtualserial"));
16+
let mut serial = SocatSerialPort::new(&scheduler_path.join("virtualserial"));
1617
write_scheduler_config(&scheduler_path);
1718
let _scheduler = PoisonedChild(
18-
std::process::Command::new(format!("{scheduler_path}/STS1_EDU_Scheduler"))
19+
std::process::Command::new("./STS1_EDU_Scheduler")
1920
.current_dir(&scheduler_path)
2021
.spawn()
2122
.unwrap(),
@@ -35,10 +36,10 @@ pub struct SocatSerialPort<T: Read, U: Write> {
3536
}
3637

3738
impl SocatSerialPort<ChildStdout, ChildStdin> {
38-
fn new(path: &str) -> Self {
39+
fn new(path: &Path) -> Self {
3940
let mut child = std::process::Command::new("socat")
4041
.arg("stdio")
41-
.arg(format!("pty,raw,echo=0,link={path},b921600,wait-slave"))
42+
.arg(format!("pty,raw,echo=0,link={},b921600,wait-slave", path.display()))
4243
.stdin(Stdio::piped())
4344
.stdout(Stdio::piped())
4445
.spawn()
@@ -57,16 +58,17 @@ impl SocatSerialPort<ChildStdout, ChildStdin> {
5758
}
5859
}
5960

60-
fn write_scheduler_config(path: &str) {
61+
fn write_scheduler_config(path: &Path) {
6162
std::fs::write(
62-
format!("{path}/config.toml"),
63+
path.join("config.toml"),
6364
"
6465
uart = \"virtualserial\"
6566
baudrate = 921600
6667
heartbeat_pin = 34
6768
update_pin = 35
6869
heartbeat_freq = 10
6970
log_path = \"log\"
71+
socket = \"/tmp/scheduler_socket\"
7072
",
7173
)
7274
.unwrap();
@@ -77,10 +79,10 @@ const COMMANDS: &[&str] =
7779

7880
fn inquire_and_send_command(
7981
edu: &mut impl CommunicationHandle,
80-
path: &str,
82+
path: &Path,
8183
) -> Result<(), Box<dyn Error>> {
8284
let mut select = inquire::Select::new("Select command", COMMANDS.to_vec());
83-
if Path::new(&format!("{path}/updatepin")).exists() {
85+
if path.join("updatepin").exists() {
8486
select.help_message = Some("Update Pin is high");
8587
}
8688
let command = select.prompt()?;

0 commit comments

Comments
 (0)