diff --git a/services/shellchat/src/cmds.rs b/services/shellchat/src/cmds.rs index dfbeaac3a..337c82fcc 100644 --- a/services/shellchat/src/cmds.rs +++ b/services/shellchat/src/cmds.rs @@ -381,7 +381,7 @@ impl CmdEnv { let mut cmd_ret: Result, xous::Error> = Ok(None); if let Some(verb_string) = maybe_verb { - let verb = verb_string.to_str(); + let verb = &verb_string; // search through the list of commands linearly until one matches, // then run it. @@ -389,7 +389,7 @@ impl CmdEnv { for cmd in commands.iter_mut() { if cmd.matches(verb) { match_found = true; - cmd_ret = cmd.process(*cmdline, &mut self.common_env); + cmd_ret = cmd.process(cmdline.to_string(), &mut self.common_env); self.lastverb.clear(); write!(self.lastverb, "{}", verb).expect("SHCH: couldn't record last verb"); }; @@ -403,7 +403,7 @@ impl CmdEnv { if !first { ret.push_str(", "); } - ret.append(cmd.verb())?; + ret.push_str(cmd.verb()); first = false; } Ok(Some(ret)) @@ -416,9 +416,9 @@ impl CmdEnv { } else if let Some(callback) = maybe_callback { let mut cmd_ret: Result, xous::Error> = Ok(None); // first check and see if we have a callback registration; if not, just map to the last verb - let verb = match self.common_env.cb_registrations.get(&(callback.body.id() as u32)) { - Some(verb) => verb.to_str(), - None => self.lastverb.to_str(), + let verb: &str = match self.common_env.cb_registrations.get(&(callback.body.id() as u32)) { + Some(verb) => verb.as_str(), + None => self.lastverb.as_str(), }; // now dispatch let mut verbfound = false; @@ -449,13 +449,13 @@ pub fn tokenize(line: &mut String) -> Option { let mut foundrest = false; for ch in lineiter { if ch != ' ' && !foundspace { - token.push(ch).unwrap(); + token.push(ch); } else if foundspace && foundrest { - retline.push(ch).unwrap(); + retline.push(ch); } else if foundspace && ch != ' ' { // handle case of multiple spaces in a row foundrest = true; - retline.push(ch).unwrap(); + retline.push(ch); } else { foundspace = true; // consume the space diff --git a/services/shellchat/src/cmds/net_cmd.rs b/services/shellchat/src/cmds/net_cmd.rs index 5e5106091..b0ff9b7ec 100644 --- a/services/shellchat/src/cmds/net_cmd.rs +++ b/services/shellchat/src/cmds/net_cmd.rs @@ -13,6 +13,7 @@ use num_traits::*; #[cfg(feature = "shellperf")] use perflib::*; use xous::MessageEnvelope; +use xous_ipc::Buffer; use String; #[cfg(feature = "ditherpunk")] use {gam::DecodePng, std::str::FromStr}; @@ -22,7 +23,7 @@ use { tungstenite::{stream::MaybeTlsStream, WebSocket}, }; -use crate::{CommonEnv, ShellCmdApi}; +use crate::{CommonEnv, ShellCmdApi, ShellOpcode}; pub struct NetCmd { callback_id: Option, @@ -303,7 +304,8 @@ impl<'a> ShellCmdApi<'a> for NetCmd { let mut iters = 0; let mut s = String::new(); write!(s, "UDP server {} started", index).unwrap(); - s.send(self_cid).unwrap(); + let buf = Buffer::into_buf(s.to_string()).unwrap(); + buf.send(self_cid, ShellOpcode::Line.to_u32().unwrap()).unwrap(); loop { s.clear(); let mut buf = [0u8; NET_MTU]; @@ -318,7 +320,8 @@ impl<'a> ShellCmdApi<'a> for NetCmd { std::str::from_utf8(&buf[..bytes]).unwrap() ) .unwrap(); - s.send(self_cid).unwrap(); + let buf = Buffer::into_buf(s.to_string()).unwrap(); + buf.send(self_cid, ShellOpcode::Line.to_u32().unwrap()).unwrap(); if do_response { match udp.send_to( format!("Server {} received {} bytes\r\n", index, bytes) @@ -347,7 +350,8 @@ impl<'a> ShellCmdApi<'a> for NetCmd { } s.clear(); write!(s, "UDP server {} rx closed after {} iters", index, iters).unwrap(); - s.send(self_cid).unwrap(); + let buf = Buffer::into_buf(s.to_string()).unwrap(); + buf.send(self_cid, ShellOpcode::Line.to_u32().unwrap()).unwrap(); } }); } @@ -841,7 +845,8 @@ impl<'a> ShellCmdApi<'a> for NetCmd { } } xous::Message::Move(m) => { - let s = String::from_message(m).unwrap(); + let buffer = unsafe { Buffer::from_memory_message(m) }; + let s = buffer.as_flat::().unwrap(); write!(ret, "{}", s.as_str()).unwrap(); } _ => { diff --git a/services/shellchat/src/cmds/ssid.rs b/services/shellchat/src/cmds/ssid.rs index d25337f31..b4cd70fd9 100644 --- a/services/shellchat/src/cmds/ssid.rs +++ b/services/shellchat/src/cmds/ssid.rs @@ -37,8 +37,7 @@ impl<'a> ShellCmdApi<'a> for Ssid { write!(ret, "RSSI reported in dBm:\n").unwrap(); for ssid in ssid_list { if ssid.name.len() > 0 { - write!(ret, "-{} {}\n", ssid.rssi, &ssid.name.as_str().unwrap_or("UTF-8 error")) - .unwrap(); + write!(ret, "-{} {}\n", ssid.rssi, &ssid.name.as_str()).unwrap(); } } write!(ret, "Scan state: {:?}\n", state).unwrap(); diff --git a/services/shellchat/src/cmds/test.rs b/services/shellchat/src/cmds/test.rs index cb9ff1293..19d623043 100644 --- a/services/shellchat/src/cmds/test.rs +++ b/services/shellchat/src/cmds/test.rs @@ -695,13 +695,7 @@ impl<'a> ShellCmdApi<'a> for Test { write!(ret, "RSSI reported in dBm:\n").unwrap(); for ssid in ssid_list { if ssid.name.len() > 0 { - write!( - ret, - "-{} {}\n", - ssid.rssi, - &ssid.name.as_str().unwrap_or("UTF-8 error") - ) - .unwrap(); + write!(ret, "-{} {}\n", ssid.rssi, &ssid.name.as_str()).unwrap(); } } write!( @@ -736,8 +730,8 @@ impl<'a> ShellCmdApi<'a> for Test { net_up = status.link_state == com_rs::LinkState::Connected; dhcp_ok = status.ipv4.dhcp == com_rs::DhcpState::Bound; ssid_ok = if let Some(ssid) = status.ssid { - log::info!("got ssid: {}", ssid.name.as_str().unwrap_or("invalid")); - ssid.name.as_str().unwrap_or("invalid") == "precursortest" + log::info!("got ssid: {}", ssid.name.as_str()); + ssid.name.as_str() == "precursortest" } else { false }; diff --git a/services/shellchat/src/main.rs b/services/shellchat/src/main.rs index ab4514556..d3b6cef69 100644 --- a/services/shellchat/src/main.rs +++ b/services/shellchat/src/main.rs @@ -231,19 +231,16 @@ impl Repl { let mut dirty = true; // take the input and pass it on to the various command parsers, and attach result - if let Some(local) = &self.input { + if let Some(local) = &mut self.input { log::trace!("processing line: {}", local); - if let Some(res) = - self.env.dispatch(Some(&mut String::from(&local)), None).expect("command dispatch failed") - { + if let Some(res) = self.env.dispatch(Some(local), None).expect("command dispatch failed") { #[cfg(feature = "tts")] { let mut output = t!("shellchat.output-tts", locales::LANG).to_string(); - output.push_str(res.as_str().unwrap_or("UTF-8 error")); + output.push_str(res.as_str()); self.tts.tts_simple(&output).unwrap(); } - let output_history = - History { text: String::from(res.as_str().unwrap_or("UTF-8 Error")), is_input: false }; + let output_history = History { text: String::from(res.as_str()), is_input: false }; self.circular_push(output_history); } else { dirty = false; @@ -254,11 +251,10 @@ impl Repl { #[cfg(feature = "tts")] { let mut output = t!("shellchat.output-tts", locales::LANG).to_string(); - output.push_str(res.as_str().unwrap_or("UTF-8 error")); + output.push_str(res.as_str()); self.tts.tts_simple(&output).unwrap(); } - let output_history = - History { text: String::from(res.as_str().unwrap_or("UTF-8 Error")), is_input: false }; + let output_history = History { text: String::from(res.as_str()), is_input: false }; self.circular_push(output_history); } else { dirty = false;