mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
add ip shellchat command
This is for testing out the IP stack: list dhcp info, send pings, send UDP message, and receive UDP message. Signed-off-by: samblenny
This commit is contained in:
parent
e8bdf91cc3
commit
2bbb8d05b9
2 changed files with 93 additions and 0 deletions
|
|
@ -98,6 +98,7 @@ mod console; use console::*;
|
|||
mod memtest; use memtest::*;
|
||||
mod keys; use keys::*;
|
||||
mod wlan; use wlan::*;
|
||||
mod ip; use ip::*;
|
||||
|
||||
//mod fcc; use fcc::*;
|
||||
//mod pds; // dependency of the FCC file
|
||||
|
|
@ -183,6 +184,7 @@ impl CmdEnv {
|
|||
|
||||
let mut echo_cmd = Echo {}; // this command has no persistent storage, so we can "create" it every time we call dispatch (but it's a zero-cost absraction so this doesn't actually create any instructions)
|
||||
let mut wlan_cmd = Wlan {};
|
||||
let mut ip_cmd = Ip {};
|
||||
let mut ver_cmd = Ver{};
|
||||
let mut backlight_cmd = Backlight{};
|
||||
let mut accel_cmd = Accel{};
|
||||
|
|
@ -210,6 +212,7 @@ impl CmdEnv {
|
|||
&mut self.memtest_cmd,
|
||||
&mut self.keys_cmd,
|
||||
&mut wlan_cmd,
|
||||
&mut ip_cmd,
|
||||
|
||||
//&mut self.fcc_cmd,
|
||||
];
|
||||
|
|
|
|||
90
services/shellchat/src/cmds/ip.rs
Normal file
90
services/shellchat/src/cmds/ip.rs
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
use crate::{CommonEnv, ShellCmdApi};
|
||||
use core::fmt::Write;
|
||||
use xous_ipc::String;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Ip {}
|
||||
|
||||
/**
|
||||
ip shell command:
|
||||
- list: show ip address, netmask, gateway, dns server, etc.
|
||||
- ping host: send 3 ICMP pings to host (ip/hostname)
|
||||
- udptx host port ...: send a UDP packet with string ... to host:port
|
||||
- udprx: listen on udp localhost:port and echo payload of first incoming
|
||||
packet (5s timeout)
|
||||
*/
|
||||
impl<'a> ShellCmdApi<'a> for Ip {
|
||||
cmd_api!(ip); // inserts boilerplate for command API
|
||||
|
||||
fn process(
|
||||
&mut self,
|
||||
args: String<1024>,
|
||||
_env: &mut CommonEnv,
|
||||
) -> Result<Option<String<1024>>, xous::Error> {
|
||||
let mut ret = String::<1024>::new();
|
||||
let helpstring = "ip [list] [ping host] [udptx host port ...] [udprx port]";
|
||||
let mut show_help = false;
|
||||
|
||||
let mut tokens = args.as_str().unwrap().split(' ');
|
||||
if let Some(sub_cmd) = tokens.next() {
|
||||
match sub_cmd {
|
||||
"list" => {
|
||||
//env.com.ip_list().unwrap();
|
||||
write!(ret, "ip list").unwrap();
|
||||
}
|
||||
"ping" => {
|
||||
if let Some(host) = tokens.next() {
|
||||
//env.com.ip_ping(&host).unwrap();
|
||||
write!(ret, "ip ping {}", host).unwrap();
|
||||
} else {
|
||||
show_help = true;
|
||||
}
|
||||
}
|
||||
"udptx" => {
|
||||
if let (Some(host), Some(port)) = (tokens.next(), tokens.next()) {
|
||||
let mut val = String::<1024>::new();
|
||||
join_tokens(&mut val, &mut tokens);
|
||||
//env.com.ip_udptx(&host, &port, &val).unwrap();
|
||||
write!(ret, "ip udptx {} {} {}", host, port, val).unwrap();
|
||||
} else {
|
||||
show_help = true;
|
||||
}
|
||||
}
|
||||
"udprx" => {
|
||||
if let Some(port) = tokens.next() {
|
||||
//env.com.ip_updprx(&port).unwrap();
|
||||
write!(ret, "ip udprx {}", port).unwrap();
|
||||
} else {
|
||||
show_help = true;
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
show_help = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
show_help = true;
|
||||
}
|
||||
if show_help {
|
||||
write!(ret, "{}", helpstring).unwrap();
|
||||
}
|
||||
Ok(Some(ret))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Join an iterator of string tokens with spaces.
|
||||
|
||||
This is intended to reverse the effect of .split(' ') in the context of a very simple
|
||||
command parser. This is a lazy way to avoid building a parser for quoted strings, since
|
||||
SSIDs or passwords might include spaces.
|
||||
*/
|
||||
fn join_tokens<'a>(buf: &mut String<1024>, tokens: impl Iterator<Item = &'a str>) {
|
||||
for (i, tok) in tokens.enumerate() {
|
||||
if i == 0 {
|
||||
write!(buf, "{}", tok).unwrap();
|
||||
} else {
|
||||
write!(buf, " {}", tok).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue