Put keyboard and screen into a PTY and start a PTY tester program
This commit is contained in:
parent
8ca0f25f7f
commit
598318ecf5
17
Cargo.lock
generated
17
Cargo.lock
generated
@ -88,7 +88,6 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"syslog_msg_ipc",
|
||||
"syslog_rpc",
|
||||
"unicode_reader",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -274,22 +273,6 @@ version = "1.0.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-segmentation"
|
||||
version = "1.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202"
|
||||
|
||||
[[package]]
|
||||
name = "unicode_reader"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d68d43b506d20b459657e0f0fe3bf0fdbac65b61cbcc2bff842fc6614a8dc179"
|
||||
dependencies = [
|
||||
"smallvec",
|
||||
"unicode-segmentation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.52.6"
|
||||
|
@ -6,4 +6,3 @@ edition = "2021"
|
||||
[dependencies]
|
||||
syslog_msg_ipc = { version = "0.1.0", path = "../syslog/syslog_msg_ipc" }
|
||||
syslog_rpc = { version = "0.1.0", path = "../syslog/syslog_rpc" }
|
||||
unicode_reader = "1.0.2"
|
||||
|
45
src/main.rs
45
src/main.rs
@ -1,7 +1,11 @@
|
||||
use std::{fs::File, io::{BufReader, Write}, os::mikros::{ipc, syscalls}, process::Command};
|
||||
use std::{
|
||||
fs::File,
|
||||
io::{Read, Write},
|
||||
os::mikros::{ipc, syscalls},
|
||||
process::Command,
|
||||
};
|
||||
|
||||
use syslog_rpc::Message;
|
||||
use unicode_reader::CodePoints;
|
||||
|
||||
struct SyslogMessageHandler {
|
||||
registered_devices: Vec<String>,
|
||||
@ -48,32 +52,29 @@ fn main() {
|
||||
.unwrap();
|
||||
Command::new("/bin/ps2").spawn().unwrap();
|
||||
|
||||
syslog_client
|
||||
.send_text_message("init_phase2", "Starting PTY server")
|
||||
.unwrap();
|
||||
Command::new("/bin/pty_server").spawn().unwrap();
|
||||
|
||||
let mut msg_handler = SyslogMessageHandler::new();
|
||||
while !msg_handler
|
||||
.registered_devices
|
||||
.iter()
|
||||
.any(|x| x == "kbd")
|
||||
{
|
||||
while !msg_handler.registered_devices.iter().any(|x| x == "kbd") {
|
||||
msg_handler.process_messages();
|
||||
}
|
||||
|
||||
let kbd = BufReader::new(File::open("/dev/kbd").unwrap());
|
||||
let mut kbd = File::open("/dev/kbd").unwrap();
|
||||
let mut display = File::open("/dev/bga0").unwrap();
|
||||
|
||||
let mut line_buf = String::new();
|
||||
let mut pty = File::open("/dev/ptmx").unwrap();
|
||||
|
||||
for ch in CodePoints::from(kbd) {
|
||||
let Ok(ch) = ch else {
|
||||
continue;
|
||||
};
|
||||
write!(display, "{}", ch).unwrap();
|
||||
if ch == '\n' {
|
||||
println!("Got line: {:?}", &line_buf);
|
||||
line_buf.clear();
|
||||
} else if ch == '\u{8}' {
|
||||
line_buf.pop();
|
||||
} else {
|
||||
line_buf.push(ch);
|
||||
}
|
||||
Command::new("/bin/pts_tester").spawn().unwrap();
|
||||
|
||||
let mut kbd_buf = [0u8; 512];
|
||||
let mut pty_buf = [0u8; 512];
|
||||
loop {
|
||||
let kbd_len = kbd.read(&mut kbd_buf).unwrap();
|
||||
let pty_len = pty.read(&mut pty_buf).unwrap();
|
||||
pty.write_all(&kbd_buf[..kbd_len]).unwrap();
|
||||
display.write_all(&pty_buf[..pty_len]).unwrap();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user