Put keyboard and screen into a PTY and start a PTY tester program

This commit is contained in:
pjht 2024-09-16 12:30:22 -05:00
parent 8ca0f25f7f
commit 598318ecf5
Signed by: pjht
GPG Key ID: 7B5F6AFBEC7EE78E
3 changed files with 23 additions and 40 deletions

17
Cargo.lock generated
View File

@ -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"

View File

@ -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"

View File

@ -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();
}
}