mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
add SSID scanning
This commit is contained in:
parent
b2c0608b0b
commit
53f3ca20f0
2 changed files with 22 additions and 8 deletions
|
|
@ -393,28 +393,39 @@ fn xmain() -> ! {
|
||||||
).expect("couldn't return SsidCheckUpdate");
|
).expect("couldn't return SsidCheckUpdate");
|
||||||
},
|
},
|
||||||
Some(Opcode::SsidFetchAsString) => {
|
Some(Opcode::SsidFetchAsString) => {
|
||||||
|
use core::fmt::Write;
|
||||||
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||||
|
|
||||||
com.txrx(ComState::SSID_FETCH.verb);
|
com.txrx(ComState::SSID_FETCH.verb);
|
||||||
let mut ssid_list: [[u8; 32]; 6] = [[0; 32]; 6]; // index as ssid_list[6][32]
|
let mut ssid_list: [[u8; 32]; 6] = [[0; 32]; 6]; // index as ssid_list[6][32]
|
||||||
for i in 0..16 * 6 {
|
for i in 0..16 * 6 {
|
||||||
let data = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)) as u16;
|
let data = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)) as u16;
|
||||||
let mut lsb : u8 = (data & 0xff) as u8;
|
let lsb : u8 = (data & 0xff) as u8;
|
||||||
let mut msb : u8 = ((data >> 8) & 0xff) as u8;
|
let msb : u8 = ((data >> 8) & 0xff) as u8;
|
||||||
if lsb == 0 { lsb = 0x20; }
|
//if lsb == 0 { lsb = 0x20; }
|
||||||
if msb == 0 { msb = 0x20; }
|
//if msb == 0 { msb = 0x20; }
|
||||||
ssid_list[i / 16][(i % 16) * 2] = lsb;
|
ssid_list[i / 16][(i % 16) * 2] = lsb;
|
||||||
ssid_list[i / 16][(i % 16) * 2 + 1] = msb;
|
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??
|
// 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
|
// 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();
|
let mut ssid_str = xous_ipc::String::<256>::from_str("Top 6 SSIDs:\n");
|
||||||
|
let mut itemized = xous_ipc::String::<256>::new();
|
||||||
for i in 0..6 {
|
for i in 0..6 {
|
||||||
let ssid = core::str::from_utf8(&ssid_list[i]);
|
let mut stop = 0;
|
||||||
|
// truncate the nulls
|
||||||
|
for l in 0..ssid_list[i].len() {
|
||||||
|
stop = l;
|
||||||
|
if ssid_list[i][l] == 0 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let ssid = core::str::from_utf8(&ssid_list[i][0..stop]);
|
||||||
match ssid {
|
match ssid {
|
||||||
Ok(textid) => {
|
Ok(textid) => {
|
||||||
ssid_str.append(textid).unwrap();
|
itemized.clear();
|
||||||
ssid_str.append("\n").unwrap();
|
write!(itemized, "{}. {}\n", i+1, textid).unwrap();
|
||||||
|
ssid_str.append(itemized.as_str().unwrap()).unwrap();
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
ssid_str.append("-Parse Error-\n").unwrap();
|
ssid_str.append("-Parse Error-\n").unwrap();
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,9 @@ pub fn callback_thread() {
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if CB_RUN.load(Ordering::Relaxed) {
|
if CB_RUN.load(Ordering::Relaxed) {
|
||||||
|
log::trace!("checking ssid status");
|
||||||
if com.ssid_scan_updated().unwrap() {
|
if com.ssid_scan_updated().unwrap() {
|
||||||
|
log::trace!("initiating callback check");
|
||||||
// just send a bogus message
|
// just send a bogus message
|
||||||
xous::send_message(callback_conn, Message::Scalar(ScalarMessage{
|
xous::send_message(callback_conn, Message::Scalar(ScalarMessage{
|
||||||
id: 0xdeadbeef, arg1: 0, arg2: 0, arg3: 0, arg4: 0,
|
id: 0xdeadbeef, arg1: 0, arg2: 0, arg3: 0, arg4: 0,
|
||||||
|
|
@ -68,6 +70,7 @@ impl<'a> ShellCmdApi<'a> for Ssid {
|
||||||
|
|
||||||
fn callback(&mut self, _msg: &MessageEnvelope, env: &mut CommonEnv) -> Result<Option<String::<1024>>, xous::Error> {
|
fn callback(&mut self, _msg: &MessageEnvelope, env: &mut CommonEnv) -> Result<Option<String::<1024>>, xous::Error> {
|
||||||
let mut ret = String::<1024>::new();
|
let mut ret = String::<1024>::new();
|
||||||
|
log::trace!("fetching SSID");
|
||||||
write!(ret, "{}", env.com.ssid_fetch_as_string().unwrap()).unwrap();
|
write!(ret, "{}", env.com.ssid_fetch_as_string().unwrap()).unwrap();
|
||||||
Ok(Some(ret))
|
Ok(Some(ret))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue