mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
initial cut at SSID scanning
This commit is contained in:
parent
bda82246cf
commit
b2c0608b0b
5 changed files with 143 additions and 4 deletions
|
|
@ -79,11 +79,11 @@ pub(crate) enum Opcode {
|
|||
/// Program a page of FLASH
|
||||
//FlashProgram(&'a [u8]),
|
||||
|
||||
/// Update the SSID list
|
||||
//SsidScan,
|
||||
/// Checks if an updated SSID list is available
|
||||
SsidCheckUpdate,
|
||||
|
||||
/// Return the latest SSID list
|
||||
//SsidFetch,
|
||||
SsidFetchAsString,
|
||||
|
||||
/// Fetch the git ID of the EC
|
||||
EcGitRev,
|
||||
|
|
|
|||
|
|
@ -137,6 +137,25 @@ impl Com {
|
|||
send_message(self.conn, Message::new_scalar(Opcode::ScanOff.to_usize().unwrap(), 0, 0, 0, 0,)).map(|_| ())
|
||||
}
|
||||
}
|
||||
pub fn ssid_scan_updated(&self) -> Result<bool, xous::Error> {
|
||||
if let xous::Result::Scalar1(avail) =
|
||||
send_message(self.conn, Message::new_blocking_scalar(Opcode::SsidCheckUpdate.to_usize().unwrap(), 0, 0, 0, 0)).unwrap() {
|
||||
if avail != 0 {
|
||||
Ok(true)
|
||||
} else {
|
||||
Ok(false)
|
||||
}
|
||||
} else {
|
||||
Err(xous::Error::InternalError)
|
||||
}
|
||||
}
|
||||
pub fn ssid_fetch_as_string(&self) -> Result<xous_ipc::String::<256>, xous::Error> {
|
||||
let ssid_list = xous_ipc::String::<256>::new();
|
||||
let mut buf = Buffer::into_buf(ssid_list).or(Err(xous::Error::InternalError))?;
|
||||
buf.lend_mut(self.conn, Opcode::SsidFetchAsString.to_u32().unwrap()).or(Err(xous::Error::InternalError))?;
|
||||
let response = buf.to_original::<xous_ipc::String::<256>, _>().unwrap();
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
pub fn get_standby_current(&self) -> Result<Option<i16>, xous::Error> {
|
||||
if let xous::Result::Scalar2(valid, current) =
|
||||
|
|
|
|||
|
|
@ -273,7 +273,7 @@ fn xmain() -> ! {
|
|||
|
||||
trace!("starting main loop");
|
||||
loop {
|
||||
let msg = xous::receive_message(com_sid).unwrap();
|
||||
let mut msg = xous::receive_message(com_sid).unwrap();
|
||||
trace!("Message: {:?}", msg);
|
||||
match FromPrimitive::from_usize(msg.body.id()) {
|
||||
Some(Opcode::RegisterBattStatsListener) => msg_scalar_unpack!(msg, sid0, sid1, sid2, sid3, {
|
||||
|
|
@ -385,6 +385,44 @@ fn xmain() -> ! {
|
|||
Some(Opcode::ScanOff) => {
|
||||
com.txrx(ComState::SSID_SCAN_OFF.verb);
|
||||
}
|
||||
Some(Opcode::SsidCheckUpdate) => {
|
||||
com.txrx(ComState::SSID_CHECK.verb);
|
||||
let available = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)) as u16;
|
||||
xous::return_scalar(
|
||||
msg.sender, available as usize
|
||||
).expect("couldn't return SsidCheckUpdate");
|
||||
},
|
||||
Some(Opcode::SsidFetchAsString) => {
|
||||
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||
|
||||
com.txrx(ComState::SSID_FETCH.verb);
|
||||
let mut ssid_list: [[u8; 32]; 6] = [[0; 32]; 6]; // index as ssid_list[6][32]
|
||||
for i in 0..16 * 6 {
|
||||
let data = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)) as u16;
|
||||
let mut lsb : u8 = (data & 0xff) as u8;
|
||||
let mut msb : u8 = ((data >> 8) & 0xff) as u8;
|
||||
if lsb == 0 { lsb = 0x20; }
|
||||
if msb == 0 { msb = 0x20; }
|
||||
ssid_list[i / 16][(i % 16) * 2] = lsb;
|
||||
ssid_list[i / 16][(i % 16) * 2 + 1] = msb;
|
||||
}
|
||||
// this is a questionably useful return format -- maybe it's actually more useful to return the raw characters??
|
||||
// for now, this is good enough for human eyes, but a scrollable list of SSIDs might be more useful with the raw u8 representation
|
||||
let mut ssid_str = xous_ipc::String::<256>::new();
|
||||
for i in 0..6 {
|
||||
let ssid = core::str::from_utf8(&ssid_list[i]);
|
||||
match ssid {
|
||||
Ok(textid) => {
|
||||
ssid_str.append(textid).unwrap();
|
||||
ssid_str.append("\n").unwrap();
|
||||
},
|
||||
_ => {
|
||||
ssid_str.append("-Parse Error-\n").unwrap();
|
||||
},
|
||||
}
|
||||
}
|
||||
buffer.replace(ssid_str).unwrap();
|
||||
}
|
||||
None => {error!("unknown opcode"); break},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,6 +65,8 @@ mod sensors; use sensors::*;
|
|||
mod callback; use callback::*;
|
||||
mod rtc_cmd; use rtc_cmd::*;
|
||||
mod vibe; use vibe::*;
|
||||
mod ssid; use ssid::*;
|
||||
|
||||
mod fcc; use fcc::*;
|
||||
mod pds; // dependency of the FCC file
|
||||
|
||||
|
|
@ -79,6 +81,8 @@ pub struct CmdEnv {
|
|||
callback_cmd: CallBack,
|
||||
rtc_cmd: RtcCmd,
|
||||
vibe_cmd: Vibe,
|
||||
ssid_cmd: Ssid,
|
||||
|
||||
fcc_cmd: Fcc,
|
||||
}
|
||||
impl CmdEnv {
|
||||
|
|
@ -99,6 +103,8 @@ impl CmdEnv {
|
|||
callback_cmd: CallBack::new(),
|
||||
rtc_cmd: RtcCmd::new(&xns),
|
||||
vibe_cmd: Vibe::new(&xns),
|
||||
ssid_cmd: Ssid::new(),
|
||||
|
||||
fcc_cmd: Fcc::new(),
|
||||
}
|
||||
}
|
||||
|
|
@ -116,6 +122,8 @@ impl CmdEnv {
|
|||
&mut self.callback_cmd,
|
||||
&mut self.rtc_cmd,
|
||||
&mut self.vibe_cmd,
|
||||
&mut self.ssid_cmd,
|
||||
|
||||
&mut self.fcc_cmd,
|
||||
];
|
||||
|
||||
|
|
|
|||
74
services/shellchat/src/cmds/ssid.rs
Normal file
74
services/shellchat/src/cmds/ssid.rs
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
use crate::{ShellCmdApi, CommonEnv};
|
||||
use xous_ipc::String;
|
||||
use com::Com;
|
||||
use ticktimer_server::Ticktimer;
|
||||
|
||||
use core::fmt::Write;
|
||||
|
||||
use xous::{Message, ScalarMessage, MessageEnvelope};
|
||||
use core::sync::atomic::{AtomicBool, Ordering};
|
||||
static CB_RUN: AtomicBool = AtomicBool::new(false);
|
||||
pub fn callback_thread() {
|
||||
let ticktimer = Ticktimer::new().expect("Couldn't connect to Ticktimer");
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
let callback_conn = xns.request_connection_blocking(crate::SERVER_NAME_SHELLCHAT).unwrap();
|
||||
let com = Com::new(&xns).unwrap();
|
||||
|
||||
loop {
|
||||
if CB_RUN.load(Ordering::Relaxed) {
|
||||
if com.ssid_scan_updated().unwrap() {
|
||||
// just send a bogus message
|
||||
xous::send_message(callback_conn, Message::Scalar(ScalarMessage{
|
||||
id: 0xdeadbeef, arg1: 0, arg2: 0, arg3: 0, arg4: 0,
|
||||
})).unwrap();
|
||||
CB_RUN.store(false, Ordering::Relaxed);
|
||||
}
|
||||
ticktimer.sleep_ms(2_000).unwrap();
|
||||
} else {
|
||||
ticktimer.sleep_ms(1_000).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Ssid {
|
||||
}
|
||||
impl Ssid {
|
||||
pub fn new() -> Ssid {
|
||||
xous::create_thread_0(callback_thread).expect("couldn't create callback generator thread");
|
||||
Ssid {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'a> ShellCmdApi<'a> for Ssid {
|
||||
cmd_api!(ssid);
|
||||
|
||||
fn process(&mut self, args: String::<1024>, env: &mut CommonEnv) -> Result<Option<String::<1024>>, xous::Error> {
|
||||
let mut ret = String::<1024>::new();
|
||||
let helpstring = "ssid [scan]";
|
||||
|
||||
let mut tokens = args.as_str().unwrap().split(' ');
|
||||
|
||||
if let Some(sub_cmd) = tokens.next() {
|
||||
match sub_cmd {
|
||||
"scan" => {
|
||||
env.com.set_ssid_scanning(true).expect("couldn't turn on SSID scanning");
|
||||
CB_RUN.store(true, Ordering::Relaxed);
|
||||
write!(ret, "SSID scan initiated, please wait...").unwrap();
|
||||
}
|
||||
_ => {
|
||||
write!(ret, "{}", helpstring).unwrap();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
write!(ret, "{}", helpstring).unwrap();
|
||||
}
|
||||
Ok(Some(ret))
|
||||
}
|
||||
|
||||
fn callback(&mut self, _msg: &MessageEnvelope, env: &mut CommonEnv) -> Result<Option<String::<1024>>, xous::Error> {
|
||||
let mut ret = String::<1024>::new();
|
||||
write!(ret, "{}", env.com.ssid_fetch_as_string().unwrap()).unwrap();
|
||||
Ok(Some(ret))
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue