rudimentary shellchat -- commit for help on debug Move message

This commit is contained in:
bunnie 2021-03-09 03:52:39 +08:00
parent d54b815653
commit b5411851fd
8 changed files with 140 additions and 3 deletions

16
Cargo.lock generated
View file

@ -1074,6 +1074,22 @@ dependencies = [
"xous-names",
]
[[package]]
name = "shellchat"
version = "0.1.0"
dependencies = [
"gam",
"heapless",
"ime-plugin-api",
"log",
"log-server",
"rkyv",
"ticktimer-server",
"utralib",
"xous",
"xous-names",
]
[[package]]
name = "shlex"
version = "0.1.1"

View file

@ -19,6 +19,7 @@ members = [
"services/benchmark-target",
"services/ime-frontend",
"services/ime-plugin-shell",
"services/shellchat",
"svd2utra",
"xtask",
"imports/blitstr-ref",
@ -45,6 +46,7 @@ default-members = [
"services/benchmark-target",
"services/ime-frontend",
"services/ime-plugin-shell",
"services/shellchat",
"services/llio",
"services/trng-tester",
]

View file

@ -615,8 +615,10 @@ fn xmain() -> ! {
}
},
rkyv::Archived::<ImefOpcode>::RegisterListener(registration) => {
let s: xous::String<256> = registration.unarchive();
// note second copy down below, this is put in early-init because we're likely to get these requests early on
let cid = xous_names::request_connection_blocking(registration.as_str()).expect("IMEF: can't connect to requested listener for reporting events");
let cid = xous_names::request_connection_blocking(s.as_str().expect("IMEF: can't decode RegisterListener string"))
.expect("IMEF: can't connect to requested listener for reporting events");
listeners.push(cid).expect("IMEF: probably ran out of slots for input event reporting");
},
_ => panic!("IME_SH: invalid response from server -- corruption occurred in MemoryMessage")
@ -667,7 +669,10 @@ fn xmain() -> ! {
}
},
rkyv::Archived::<ImefOpcode>::RegisterListener(registration) => {
let cid = xous_names::request_connection_blocking(registration.as_str()).expect("IMEF: can't connect to requested listener for reporting events");
let s: xous::String<256> = registration.unarchive();
// note first copy above, put in early-init because we're likely to get these requests early on
let cid = xous_names::request_connection_blocking(s.as_str().expect("IMEF: can't decode RegisterListener string"))
.expect("IMEF: can't connect to requested listener for reporting events");
listeners.push(cid).expect("IMEF: probably ran out of slots for input event reporting");
},
_ => panic!("IME_SH: invalid response from server -- corruption occurred in MemoryMessage")

View file

@ -232,7 +232,7 @@ pub enum ImefOpcode {
SetPredictionServer(xous::String<256>),
/// register a listener for finalized inputs
RegisterListener(xous_names::api::XousServerName),
RegisterListener(xous::String<256>),
/// this is the event opcode used by listeners
GotInputLine(xous::String<4000>),
@ -270,6 +270,7 @@ pub trait ImeFrontEndApi {
fn set_input_canvas(&self, g: graphics_server::Gid) -> Result<(), xous::Error>;
fn set_prediction_canvas(&self, g: graphics_server::Gid) -> Result<(), xous::Error>;
fn set_predictor(&self, servername: &str) -> Result<(), xous::Error>;
fn register_listener(&self, servername: &str) -> Result<(), xous::Error>;
}
pub struct ImeFrontEnd {
@ -314,4 +315,22 @@ impl ImeFrontEndApi for ImeFrontEnd {
_ => Err(xous::Error::UseBeforeInit)
}
}
fn register_listener(&self, servername: &str) -> Result<(), xous::Error> {
match self.connection {
Some(cid) => {
let mut server = xous::String::<256>::new();
use core::fmt::Write;
write!(server, "{}", servername).expect("IMEF: couldn't write set_predictor server name");
let ime_op = ImefOpcode::RegisterListener(server);
use rkyv::Write as ArchiveWrite;
let mut writer = rkyv::ArchiveBuffer::new(xous::XousBuffer::new(4096));
let pos = writer.archive(&ime_op).expect("IMEF: couldn't archive SetPredictionServer");
writer.into_inner().lend(cid, pos as u32).expect("IMEF: SetPredicitonServer request failure");
Ok(())
},
_ => Err(xous::Error::UseBeforeInit)
}
}
}

View file

@ -0,0 +1,25 @@
[package]
name = "shellchat"
version = "0.1.0"
authors = ["bunnie <bunnie@kosagi.com>"]
edition = "2018"
description = "A shell with a chat-like interface"
[dependencies]
xous = { path = "../../xous-rs" }
heapless = "0.5.6"
log-server = { path = "../log-server" }
ticktimer-server = { path = "../ticktimer-server" }
xous-names = { path = "../xous-names" }
gam = {path="../gam"}
ime-plugin-api = {path="../ime-plugin-api"}
log = "0.4"
rkyv = { version = "0.3.1", default_features = false }
[target.'cfg(not(any(windows,unix)))'.dependencies]
utralib = { path = "../../utralib"}
[features]
debugprint = []
default = [] # "debugprint"

View file

@ -0,0 +1,67 @@
#![cfg_attr(target_os = "none", no_std)]
#![cfg_attr(target_os = "none", no_main)]
use log::{error, info};
use core::fmt::Write;
use rkyv::Unarchive;
use rkyv::archived_value;
use core::pin::Pin;
use ime_plugin_api::{ImeFrontEndApi, ImeFrontEnd};
use heapless::spsc::Queue;
use heapless::consts::U4;
fn repl(history: &mut Queue<xous::String<1024>, U4>) -> Result<(), xous::Error> {
for &s in history.iter() {
info!("SHCH: command history {}", s);
}
Ok(())
}
#[xous::xous_main]
fn xmain() -> ! {
log_server::init_wait().unwrap();
info!("SHCH: my PID is {}", xous::process::id());
let shch_sid = xous_names::register_name(xous::names::SERVER_NAME_SHELLCHAT).expect("SHCH: can't register server");
info!("SHCH: registered with NS -- {:?}", shch_sid);
let imef_conn = xous_names::request_connection_blocking(xous::names::SERVER_NAME_IME_FRONT).expect("SHCH: can't connect to IMEF");
let imef = ImeFrontEnd { connection: Some(imef_conn) };
imef.register_listener(xous::names::SERVER_NAME_IME_FRONT).expect("SHCH: couldn't request events from IMEF");
let mut history: Queue<xous::String<1024>, U4> = Queue::new(); // this has 2^4 elements = 16???
info!("SHCH: starting main loop");
loop {
let envelope = xous::receive_message(shch_sid).unwrap();
if let xous::Message::Move(m) = &envelope.body {
let buf = unsafe { xous::XousBuffer::from_memory_message(m) };
let bytes = Pin::new(buf.as_ref());
let value = unsafe {
archived_value::<ime_plugin_api::ImefOpcode>(&bytes, m.id as usize)
};
match &*value {
rkyv::Archived::<ime_plugin_api::ImefOpcode>::GotInputLine(rkyv_s) => {
let s: xous::String<4000> = rkyv_s.unarchive();
let mut local: xous::String<1024> = xous::String::new();
write!(local, "{}", s.as_str().expect("SHCH: couldn't convert incoming string")).expect("SHCH: probably exceeded input length");
if history.len() == history.capacity() {
history.dequeue().expect("SHCH: couldn't dequeue historye");
}
history.enqueue(local).expect("SHCH: couldn't store input line");
repl(&mut history).expect("SHCH: repl experienced an error");
},
_ => panic!("SHCH: invalid response from server -- corruption occurred in MemoryMessage")
};
} else {
error!("SHCH: couldn't convert message");
}
}
}

View file

@ -15,6 +15,7 @@ pub const SERVER_NAME_GAM: &str = "_Graphical Abstraction Manager_";
pub const SERVER_NAME_STATUS: &str = "_Status bar manager_";
pub const SERVER_NAME_IME_FRONT: &str = "_IME front end_";
pub const SERVER_NAME_IME_PLUGIN_SHELL: &str = "_IME shell plugin_";
pub const SERVER_NAME_SHELLCHAT: &str = "_Shell chat application_";
pub const SERVER_NAME_FCCAGENT: &str = "_Agent for EMC Testing_";
pub const SERVER_NAME_BENCHMARK: &str= "_Benchmark target_";

View file

@ -39,6 +39,7 @@ fn try_main() -> Result<(), DynError> {
let hw_pkgs = [
"gam",
//"shell",
"shellchat",
"ime-frontend",
"ime-plugin-shell",
"graphics-server",
@ -194,6 +195,7 @@ fn run(debug: bool) -> Result<(), DynError> {
"gam",
"ime-frontend",
"ime-plugin-shell",
"shellchat",
//"benchmark",
//"benchmark-target",
"log-server",