mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
add wlan shell command
This is for turning the WF200 wifi radio on and off, setting the SSID and password, joining an AP, leaving an AP, and checking the AP connection status. Signed-off-by: samblenny
This commit is contained in:
parent
0d3c936d43
commit
e8bdf91cc3
2 changed files with 98 additions and 0 deletions
|
|
@ -97,6 +97,7 @@ mod engine; use engine::*;
|
|||
mod console; use console::*;
|
||||
mod memtest; use memtest::*;
|
||||
mod keys; use keys::*;
|
||||
mod wlan; use wlan::*;
|
||||
|
||||
//mod fcc; use fcc::*;
|
||||
//mod pds; // dependency of the FCC file
|
||||
|
|
@ -181,6 +182,7 @@ impl CmdEnv {
|
|||
let mut ret = String::<1024>::new();
|
||||
|
||||
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 ver_cmd = Ver{};
|
||||
let mut backlight_cmd = Backlight{};
|
||||
let mut accel_cmd = Accel{};
|
||||
|
|
@ -207,6 +209,7 @@ impl CmdEnv {
|
|||
&mut console_cmd,
|
||||
&mut self.memtest_cmd,
|
||||
&mut self.keys_cmd,
|
||||
&mut wlan_cmd,
|
||||
|
||||
//&mut self.fcc_cmd,
|
||||
];
|
||||
|
|
|
|||
95
services/shellchat/src/cmds/wlan.rs
Normal file
95
services/shellchat/src/cmds/wlan.rs
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
use crate::{CommonEnv, ShellCmdApi};
|
||||
use core::fmt::Write;
|
||||
use xous_ipc::String;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Wlan {}
|
||||
|
||||
/**
|
||||
wlan shell command:
|
||||
- on: if in off mode, reset WF200 and load firmware, otherwise NOP
|
||||
- off: disconnect from AP (if joined) and put WF200 in low power standby
|
||||
- setssid ...: set AP SSID to ... (... can include spaces)
|
||||
- setpass ...: set AP password to ... (... can include spaces)
|
||||
- join: if disconnected, connect by WPA2 personal with previously set SSID
|
||||
and password, otherwise NOP
|
||||
- leave: if joined, disconnect from AP
|
||||
- show: show AP connection info (SSID, signal strength)
|
||||
*/
|
||||
impl<'a> ShellCmdApi<'a> for Wlan {
|
||||
cmd_api!(wlan); // 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 = "wlan [on] [off] [setssid ...] [setpass ...] [join] [leave] [show]";
|
||||
let mut show_help = false;
|
||||
|
||||
let mut tokens = args.as_str().unwrap().split(' ');
|
||||
if let Some(sub_cmd) = tokens.next() {
|
||||
match sub_cmd {
|
||||
"on" => {
|
||||
//env.com.set_wlan_on().unwrap();
|
||||
write!(ret, "wlan on").unwrap();
|
||||
}
|
||||
"off" => {
|
||||
//env.com.set_wlan_off().unwrap();
|
||||
write!(ret, "wlan off").unwrap();
|
||||
}
|
||||
"setssid" => {
|
||||
let mut val = String::<1024>::new();
|
||||
join_tokens(&mut val, &mut tokens);
|
||||
//env.com.set_wlan_ssid(&val).unwrap();
|
||||
write!(ret, "wlan setssid {}", val).unwrap();
|
||||
}
|
||||
"setpass" => {
|
||||
let mut val = String::<1024>::new();
|
||||
join_tokens(&mut val, &mut tokens);
|
||||
//env.com.set_wlan_pass(&val).unwrap();
|
||||
write!(ret, "wlan setpass {}", val).unwrap();
|
||||
}
|
||||
"join" => {
|
||||
//env.com.wlan_join().unwrap();
|
||||
write!(ret, "wlan join").unwrap();
|
||||
}
|
||||
"leave" => {
|
||||
//env.com.wlan_leave().unwrap();
|
||||
write!(ret, "wlan leave").unwrap();
|
||||
}
|
||||
"show" => {
|
||||
//env.com.wlan_show().unwrap();
|
||||
write!(ret, "wlan show").unwrap();
|
||||
}
|
||||
_ => {
|
||||
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