mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
refactor SSID reporting
later on we'll have to add some UX around this but for now the command line stuff is a bit nicer.
This commit is contained in:
parent
c2bd695167
commit
0ba8650731
9 changed files with 280 additions and 88 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -459,7 +459,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "com_rs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/betrusted-io/com_rs.git?rev=b3bf4aebe1d3c91e77dae5d3832d17e717c5669b#b3bf4aebe1d3c91e77dae5d3832d17e717c5669b"
|
||||
source = "git+https://github.com/betrusted-io/com_rs.git?rev=2ec9ddf141faf42395ec26b34f45c3874a0b4530#2ec9ddf141faf42395ec26b34f45c3874a0b4530"
|
||||
|
||||
[[package]]
|
||||
name = "com_rs-ref"
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ description = "com_rs import package"
|
|||
|
||||
# Dependency policy: fully specify dependencies to the minor version number
|
||||
[dependencies]
|
||||
com_rs = { git = "https://github.com/betrusted-io/com_rs.git", rev = "b3bf4aebe1d3c91e77dae5d3832d17e717c5669b" }
|
||||
com_rs = { git = "https://github.com/betrusted-io/com_rs.git", rev = "2ec9ddf141faf42395ec26b34f45c3874a0b4530" }
|
||||
#com_rs = { path = "../../../betrusted-ec/sw/com_rs" }
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ impl Into<[usize; 2]> for BattStats {
|
|||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
||||
pub enum FlashOp {
|
||||
pub(crate) enum FlashOp {
|
||||
/// erase a region defined by (address, len)
|
||||
Erase(u32, u32),
|
||||
/// Send up to 1kiB of data at a time. This reduces messaging overhead and makes
|
||||
|
|
@ -54,17 +54,38 @@ pub enum FlashOp {
|
|||
Program(u32, [Option<[u8; 256]>; 4])
|
||||
}
|
||||
#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
||||
pub enum FlashResult {
|
||||
pub(crate) enum FlashResult {
|
||||
Pass,
|
||||
Fail,
|
||||
}
|
||||
#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
||||
pub struct FlashRecord {
|
||||
pub(crate) struct FlashRecord {
|
||||
/// identifier to validate that we're authorized to do this
|
||||
pub id: [u32; 4],
|
||||
/// operation
|
||||
pub op: FlashOp,
|
||||
}
|
||||
#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
||||
pub(crate) struct SsidRecord {
|
||||
pub name: xous_ipc::String::<32>,
|
||||
pub rssi: u8,
|
||||
}
|
||||
impl Default for SsidRecord {
|
||||
fn default() -> Self {
|
||||
SsidRecord { name: xous_ipc::String::<32>::new(), rssi: 0 }
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
||||
pub(crate) struct SsidReturn {
|
||||
pub list: [SsidRecord; 8],
|
||||
}
|
||||
impl Default for SsidReturn {
|
||||
fn default() -> Self {
|
||||
SsidReturn {
|
||||
list: [SsidRecord::default(); 8],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
||||
pub(crate) enum Opcode {
|
||||
|
|
@ -131,9 +152,12 @@ pub(crate) enum Opcode {
|
|||
|
||||
/// Return the latest SSID list
|
||||
SsidFetchAsString,
|
||||
SsidFetchAsStringV2,
|
||||
|
||||
/// Fetch the git ID of the EC
|
||||
EcGitRev,
|
||||
/// Fetch the SW tag of the EC as a {00|maj|min|rev} u32
|
||||
EcSwTag,
|
||||
|
||||
/// Fetch the firmware rev of the WF200
|
||||
Wf200Rev,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
/// are calling these functions inside a different process.
|
||||
pub mod api;
|
||||
|
||||
pub use api::BattStats;
|
||||
pub use api::*;
|
||||
use api::{Callback, ComIntSources, NET_MTU, Opcode};
|
||||
use xous::{send_message, Error, CID, Message, msg_scalar_unpack};
|
||||
use xous_ipc::{String, Buffer};
|
||||
|
|
@ -111,6 +111,7 @@ impl Com {
|
|||
}
|
||||
}
|
||||
|
||||
/// this is the Git rev of the *soc*, not the firmware.
|
||||
pub fn get_ec_git_rev(&self) -> Result<(u32, bool), Error> {
|
||||
let response = send_message(self.conn,
|
||||
Message::new_blocking_scalar(Opcode::EcGitRev.to_usize().unwrap(), 0, 0, 0, 0))?;
|
||||
|
|
@ -127,6 +128,22 @@ impl Com {
|
|||
}
|
||||
}
|
||||
|
||||
/// this is the rev of the firmware, as (maj, min, rev, +commit)
|
||||
pub fn get_ec_sw_tag(&self) -> Result<(u8, u8, u8, u8), Error> {
|
||||
let response = send_message(self.conn,
|
||||
Message::new_blocking_scalar(Opcode::EcSwTag.to_usize().unwrap(), 0, 0, 0, 0))?;
|
||||
if let xous::Result::Scalar1(rev) = response {
|
||||
Ok((
|
||||
((rev >> 24) & 0xff) as u8,
|
||||
((rev >> 16) & 0xff) as u8,
|
||||
((rev >> 8) & 0xff) as u8,
|
||||
((rev >> 0) & 0xff) as u8,
|
||||
))
|
||||
} else {
|
||||
panic!("unexpected return value: {:#?}", response);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn send_pds_line(&self, s: &String<512>) -> Result<(), Error> {
|
||||
use core::fmt::Write;
|
||||
let mut clone_s: String<512> = String::new();
|
||||
|
|
@ -232,6 +249,8 @@ impl Com {
|
|||
Err(xous::Error::InternalError)
|
||||
}
|
||||
}
|
||||
// superceded by ssid_fetch_as_list in versions later 0.9.5 (non-inclusive)
|
||||
#[deprecated]
|
||||
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))?;
|
||||
|
|
@ -239,6 +258,18 @@ impl Com {
|
|||
let response = buf.to_original::<xous_ipc::String::<256>, _>().unwrap();
|
||||
Ok(response)
|
||||
}
|
||||
/// returns a vector of `(u8, String)` tuples that represent rssi + AP name
|
||||
pub fn ssid_fetch_as_list(&self) -> Result<Vec<(u8, std::string::String)>, xous::Error> {
|
||||
let ssid_alloc = SsidReturn::default();
|
||||
let mut buf = Buffer::into_buf(ssid_alloc).or(Err(xous::Error::InternalError))?;
|
||||
buf.lend_mut(self.conn, Opcode::SsidFetchAsStringV2.to_u32().unwrap()).or(Err(xous::Error::InternalError))?;
|
||||
let response = buf.to_original::<SsidReturn, _>().unwrap();
|
||||
let mut ret = Vec::<(u8, std::string::String)>::new();
|
||||
for ssid in response.list {
|
||||
ret.push((ssid.rssi, std::string::String::from(ssid.name.as_str().unwrap_or("UTF-8 Parse Error"))));
|
||||
}
|
||||
Ok(ret)
|
||||
}
|
||||
|
||||
pub fn get_standby_current(&self) -> Result<Option<i16>, xous::Error> {
|
||||
if let xous::Result::Scalar2(valid, current) =
|
||||
|
|
|
|||
|
|
@ -15,7 +15,10 @@ use com_rs::serdes::{STR_32_WORDS, STR_64_WORDS, STR_64_U8_SIZE, StringSer, Stri
|
|||
use xous::{CID, msg_scalar_unpack, msg_blocking_scalar_unpack};
|
||||
use xous_ipc::{Buffer, String};
|
||||
|
||||
const LEGACY_REV: u32 = 0x8b5b_8e50; // this is the git rev shipped before we went to version tagging
|
||||
const LEGACY_TAG: u32 = 0x00_09_05_00; // this is corresponding tag
|
||||
const STD_TIMEOUT: u32 = 100;
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct WorkRequest {
|
||||
work: ComSpec,
|
||||
|
|
@ -367,6 +370,22 @@ fn xmain() -> ! {
|
|||
}
|
||||
}
|
||||
|
||||
// determine the version of the COM that we're talking to
|
||||
let mut ec_git_rev = {
|
||||
com.txrx(ComState::EC_GIT_REV.verb);
|
||||
let rev_msb = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)) as u16;
|
||||
let rev_lsb = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)) as u16;
|
||||
let _dirty = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)) as u8;
|
||||
((rev_msb as u32) << 16) | (rev_lsb as u32)
|
||||
};
|
||||
let mut ec_tag = {
|
||||
if ec_git_rev == LEGACY_REV {
|
||||
LEGACY_TAG
|
||||
} else {
|
||||
parse_version(&mut com)
|
||||
}
|
||||
};
|
||||
|
||||
trace!("starting main loop");
|
||||
loop {
|
||||
let mut msg = xous::receive_message(com_sid).unwrap();
|
||||
|
|
@ -610,13 +629,28 @@ fn xmain() -> ! {
|
|||
let rev_msb = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)) as u16;
|
||||
let rev_lsb = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)) as u16;
|
||||
let dirty = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)) as u8;
|
||||
ec_git_rev = ((rev_msb as u32) << 16) | (rev_lsb as u32);
|
||||
xous::return_scalar2(
|
||||
msg.sender,
|
||||
((rev_msb as usize) << 16) | (rev_lsb as usize),
|
||||
ec_git_rev as usize,
|
||||
dirty as usize
|
||||
)
|
||||
.expect("couldn't return WF200 firmware rev");
|
||||
}
|
||||
Some(Opcode::EcSwTag) => {
|
||||
if ec_git_rev == LEGACY_REV { // this corresponds to a 0.9.5 tag -- the last tag shipped that lacked detailed versioning
|
||||
xous::return_scalar(
|
||||
msg.sender,
|
||||
0x00_09_05_00
|
||||
).expect("couldn't return WF200 revision tag");
|
||||
} else {
|
||||
ec_tag = parse_version(&mut com);
|
||||
xous::return_scalar(
|
||||
msg.sender,
|
||||
ec_tag as usize,
|
||||
).expect("couldn't return WF200 revision tag");
|
||||
}
|
||||
}
|
||||
Some(Opcode::Wf200Reset) => {
|
||||
com.txrx(ComState::WF200_RESET.verb);
|
||||
com.txrx(0);
|
||||
|
|
@ -639,46 +673,80 @@ fn xmain() -> ! {
|
|||
).expect("couldn't return SsidCheckUpdate");
|
||||
},
|
||||
Some(Opcode::SsidFetchAsString) => {
|
||||
use core::fmt::Write;
|
||||
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||
if ec_tag == LEGACY_TAG {
|
||||
// this is kept around because the original firmware shipped with units don't support software tagging
|
||||
// and the SSID API was modified. This allows the SOC to interop with older versions of the EC for SSID scanning.
|
||||
// If it's 2023 and you're looking at this comment and thinking about removing this code, it might actually be
|
||||
// ok to do that. Just check that the factory test infrastructure is fully updated to match a modern EC rev.
|
||||
use core::fmt::Write;
|
||||
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 lsb : u8 = (data & 0xff) as u8;
|
||||
let 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>::from_str("Top 6 SSIDs:\n");
|
||||
let mut itemized = xous_ipc::String::<256>::new();
|
||||
for i in 0..6 {
|
||||
let mut stop = 0;
|
||||
// truncate the nulls
|
||||
for l in 0..ssid_list[i].len() {
|
||||
stop = l;
|
||||
if ssid_list[i][l] == 0 {
|
||||
break;
|
||||
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 lsb : u8 = (data & 0xff) as u8;
|
||||
let 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>::from_str("Top 6 SSIDs:\n");
|
||||
let mut itemized = xous_ipc::String::<256>::new();
|
||||
for i in 0..6 {
|
||||
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 {
|
||||
Ok(textid) => {
|
||||
itemized.clear();
|
||||
write!(itemized, "{}. {}\n", i+1, textid).unwrap();
|
||||
ssid_str.append(itemized.as_str().unwrap()).unwrap();
|
||||
},
|
||||
_ => {
|
||||
ssid_str.append("-Parse Error-\n").unwrap();
|
||||
},
|
||||
}
|
||||
}
|
||||
let ssid = core::str::from_utf8(&ssid_list[i][0..stop]);
|
||||
match ssid {
|
||||
Ok(textid) => {
|
||||
itemized.clear();
|
||||
write!(itemized, "{}. {}\n", i+1, textid).unwrap();
|
||||
ssid_str.append(itemized.as_str().unwrap()).unwrap();
|
||||
},
|
||||
_ => {
|
||||
ssid_str.append("-Parse Error-\n").unwrap();
|
||||
},
|
||||
buffer.replace(ssid_str).unwrap();
|
||||
} else {
|
||||
log::error!("This API is not implemented for this EC firmware revision");
|
||||
}
|
||||
}
|
||||
Some(Opcode::SsidFetchAsStringV2) => {
|
||||
if ec_tag == LEGACY_TAG {
|
||||
log::error!("This API is not implemented for legacy EC revs");
|
||||
continue;
|
||||
}
|
||||
com.txrx(ComState::SSID_FETCH_STR.verb);
|
||||
// these sizes are hard-coded constants from the EC firmware. We don't have a good cross-code base method for
|
||||
// sharing these yet, so they are just magic numbers.
|
||||
let mut ssid_list: [[u8; 34]; 8] = [[0; 34]; 8];
|
||||
for record in ssid_list.iter_mut() {
|
||||
for word in record.chunks_mut(2) {
|
||||
let data = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)) as u16;
|
||||
word[0] = (data & 0xff) as u8;
|
||||
word[1] = ((data >> 8) & 0xff) as u8;
|
||||
}
|
||||
}
|
||||
buffer.replace(ssid_str).unwrap();
|
||||
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||
let mut ssid_ret = buffer.to_original::<SsidReturn, _>().expect("couldn't convert incoming storage");
|
||||
for (raw, ssid_rec) in ssid_list.iter().zip(ssid_ret.list.iter_mut()) {
|
||||
ssid_rec.rssi = raw[0];
|
||||
let ssid_str = core::str::from_utf8(&raw[2..2 + raw[1] as usize]).unwrap_or("UTF-8 parse error");
|
||||
ssid_rec.name.clear(); // should be pre-cleared, but let's just be safe about it
|
||||
ssid_rec.name.append(ssid_str).ok(); // don't panic if we truncate
|
||||
}
|
||||
buffer.replace(ssid_ret).unwrap();
|
||||
}
|
||||
Some(Opcode::WlanOn) => {
|
||||
info!("TODO: implement WlanOn");
|
||||
|
|
@ -862,3 +930,37 @@ fn xmain() -> ! {
|
|||
log::trace!("quitting");
|
||||
xous::terminate_process(0)
|
||||
}
|
||||
|
||||
fn parse_version(com: &mut crate::implementation::XousCom) -> u32 {
|
||||
com.txrx(ComState::EC_SW_TAG.verb);
|
||||
let mut rev_ret = [0u16; ComState::EC_SW_TAG.r_words as usize];
|
||||
for w in rev_ret.iter_mut() {
|
||||
*w = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)) as u16;
|
||||
}
|
||||
// unpack u16 words into u8 array
|
||||
let mut rev_bytes = [0u8; (ComState::EC_SW_TAG.r_words as usize - 1) * 2];
|
||||
for (src, dst) in rev_ret[1..].iter().zip(rev_bytes.chunks_mut(2)) {
|
||||
dst[0] = src.to_le_bytes()[0];
|
||||
dst[1] = src.to_le_bytes()[1];
|
||||
}
|
||||
// translate u8 array into &str
|
||||
let revstr = core::str::from_utf8(&rev_bytes[..rev_ret[0] as usize]).expect("gitrev is not valid utf-8");
|
||||
// parse &str -- we do it here not in the EC, because the EC is memory-constrained
|
||||
// v0.9.5-2-gb3e2868 exemplar template
|
||||
let hyphenstr: Vec<&str> = revstr[1..].split('-').collect(); // drop the leading 'v' by doing [1..]
|
||||
let revcodes: Vec<&str> = hyphenstr[0].split('.').collect();
|
||||
let major = revcodes[0].parse::<u8>().unwrap_or(0);
|
||||
let minor = revcodes[1].parse::<u8>().unwrap_or(0);
|
||||
let rev = revcodes[2].parse::<u8>().unwrap_or(0);
|
||||
let commit = if hyphenstr.len() > 2 { // extra commits beyond the tag
|
||||
// version-extra-commit
|
||||
hyphenstr[1].parse::<u8>().unwrap_or(0)
|
||||
} else {
|
||||
// I think the "extra" might disappear in the case that there is no extra beyond the tag. In this case, we would have just
|
||||
// v0.9.6-gxxxxxx only, not v0.9.6-0-gxxxxxx. I'm actually not 100% sure, but also, I can't seem to find a definitive
|
||||
// answer right now and I don't want to fuck up the tag state of my repo just to find out. Either way, this
|
||||
// logic will cause the right thing to happen (a 0 for the extra commits)
|
||||
0
|
||||
};
|
||||
(commit & 0xff) as u32 | ((rev & 0xff) as u32) << 8 | (((minor & 0xff) as u32) << 16) | (((major & 0xff) as u32) << 24)
|
||||
}
|
||||
|
|
@ -176,10 +176,13 @@ impl CmdEnv {
|
|||
log::info!("SoC DNA: 0x{:x}", common.llio.soc_dna().unwrap());
|
||||
let (rev, dirty) = common.com.get_ec_git_rev().unwrap();
|
||||
let dirtystr = if dirty { "dirty" } else { "clean" };
|
||||
log::info!("EC git commit: {:x}, {}", rev, dirtystr);
|
||||
log::info!("EC gateware git commit: {:x}, {}", rev, dirtystr);
|
||||
let (maj, min, rev, commit) = common.com.get_ec_sw_tag().unwrap();
|
||||
log::info!("EC sw tag: {}.{}.{}+{}", maj, min, rev, commit);
|
||||
let (maj, min, rev) = common.com.get_wf200_fw_rev().unwrap();
|
||||
log::info!("WF200 fw rev {}.{}.{}", maj, min, rev);
|
||||
|
||||
|
||||
CmdEnv {
|
||||
common_env: common,
|
||||
lastverb: String::<256>::new(),
|
||||
|
|
|
|||
|
|
@ -4,49 +4,23 @@ 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();
|
||||
use num_traits::*;
|
||||
|
||||
let mut iters = 0; // count how long we've been waiting
|
||||
loop {
|
||||
if CB_RUN.load(Ordering::Relaxed) {
|
||||
log::trace!("checking ssid status");
|
||||
if com.ssid_scan_updated().unwrap() {
|
||||
log::trace!("initiating callback check");
|
||||
// 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);
|
||||
} else {
|
||||
iters += 1;
|
||||
if iters > 11 { // should have gotten a result within 20 seconds...
|
||||
// there may have been stale data in the scan cache, clear it
|
||||
let _ = com.ssid_fetch_as_string().unwrap();
|
||||
}
|
||||
}
|
||||
ticktimer.sleep_ms(2_000).unwrap();
|
||||
} else {
|
||||
ticktimer.sleep_ms(1_000).unwrap();
|
||||
iters = 0;
|
||||
}
|
||||
}
|
||||
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
||||
enum ScanResult {
|
||||
Ok,
|
||||
Timeout,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Ssid {
|
||||
cb_id: Option<xous::CID>,
|
||||
}
|
||||
impl Ssid {
|
||||
pub fn new() -> Ssid {
|
||||
xous::create_thread_0(callback_thread).expect("couldn't create callback generator thread");
|
||||
Ssid {
|
||||
cb_id: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -58,12 +32,42 @@ impl<'a> ShellCmdApi<'a> for Ssid {
|
|||
let helpstring = "ssid [scan]";
|
||||
|
||||
let mut tokens = args.as_str().unwrap().split(' ');
|
||||
if self.cb_id.is_none() {
|
||||
self.cb_id = Some(
|
||||
env.register_handler(String::<256>::from_str(self.verb()))
|
||||
);
|
||||
}
|
||||
|
||||
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);
|
||||
let _ = std::thread::spawn({
|
||||
let cb_id = self.cb_id.expect("should have been initialized by this point");
|
||||
move || {
|
||||
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();
|
||||
let mut responded = false;
|
||||
for _ in 0..15 {
|
||||
if com.ssid_scan_updated().unwrap() {
|
||||
// just send a bogus message
|
||||
xous::send_message(callback_conn, Message::Scalar(ScalarMessage{
|
||||
id: cb_id as usize, arg1: ScanResult::Ok.to_usize().unwrap(), arg2: 0, arg3: 0, arg4: 0,
|
||||
})).unwrap();
|
||||
responded = true;
|
||||
break;
|
||||
}
|
||||
ticktimer.sleep_ms(2_000).unwrap();
|
||||
}
|
||||
if !responded {
|
||||
xous::send_message(callback_conn, Message::Scalar(ScalarMessage{
|
||||
id: cb_id as usize, arg1: ScanResult::Timeout.to_usize().unwrap(), arg2: 0, arg3: 0, arg4: 0,
|
||||
})).unwrap();
|
||||
}
|
||||
}
|
||||
});
|
||||
write!(ret, "SSID scan initiated, please wait...").unwrap();
|
||||
}
|
||||
_ => {
|
||||
|
|
@ -76,10 +80,27 @@ impl<'a> ShellCmdApi<'a> for Ssid {
|
|||
Ok(Some(ret))
|
||||
}
|
||||
|
||||
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();
|
||||
log::trace!("fetching SSID");
|
||||
write!(ret, "{}", env.com.ssid_fetch_as_string().unwrap()).unwrap();
|
||||
xous::msg_scalar_unpack!(msg, arg1, _arg2, _arg3, _arg4, {
|
||||
match FromPrimitive::from_usize(arg1) {
|
||||
Some(ScanResult::Ok) => {
|
||||
let ssid_list = env.com.ssid_fetch_as_list().unwrap();
|
||||
write!(ret, "RSSI in dBm:\n").unwrap();
|
||||
for (rssi, name) in ssid_list {
|
||||
if name.len() > 0 {
|
||||
write!(ret, "-{} {}\n", rssi, &name).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(ScanResult::Timeout) => {
|
||||
write!(ret, "SSID scan timed out").unwrap();
|
||||
}
|
||||
_ => log::error!("Unknown callback received by ssid scan")
|
||||
}
|
||||
|
||||
});
|
||||
Ok(Some(ret))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -467,17 +467,26 @@ impl<'a> ShellCmdApi<'a> for Test {
|
|||
loop {
|
||||
match oqc_status(oqc_cid) {
|
||||
Some(true) => {
|
||||
let ssid_str = env.com.ssid_fetch_as_string().unwrap();
|
||||
use std::str::FromStr;
|
||||
let ssid = std::string::String::from_str(ssid_str.as_str().unwrap()).unwrap();
|
||||
let ssid_short = ssid.replace(".", "");
|
||||
let mut lines = ssid_short.lines();
|
||||
let _ = lines.next(); // skip the banner
|
||||
write!(ret, "SSID {}\nCHECK: was backlight on?\ndid keyboard vibrate?\nwas there sound?\n",
|
||||
lines.next().unwrap() // just the first SSID result
|
||||
log::info!("wrapping up: fetching SSID list");
|
||||
let ssid_str = env.com.ssid_fetch_as_list().unwrap();
|
||||
let mut min = 255u8;
|
||||
let mut min_index = 0;
|
||||
for (index, (rssi, name)) in ssid_str.iter().enumerate() {
|
||||
if name.len() > 0 {
|
||||
if *rssi < min {
|
||||
min = *rssi;
|
||||
min_index = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
let (rssi, name) = &ssid_str[min_index];
|
||||
log::info!("strongest AP: -{}dBm, {}", *rssi, name);
|
||||
write!(ret, "SSID (-{}):{}\nCHECK: was backlight on?\ndid keyboard vibrate?\nwas there sound?\n",
|
||||
*rssi, name // just the first SSID result
|
||||
).unwrap();
|
||||
let (maj, min, rev, extra, gitrev) = env.llio.soc_gitrev().unwrap();
|
||||
write!(ret, "Version {}.{}.{}+{}, commit {:x}\n", maj, min, rev, extra, gitrev).unwrap();
|
||||
log::info!("finished status update");
|
||||
break;
|
||||
}
|
||||
Some(false) => {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,9 @@ impl<'a> ShellCmdApi<'a> for Ver {
|
|||
"ec" => {
|
||||
let (rev, dirty) = env.com.get_ec_git_rev().unwrap();
|
||||
let dirtystr = if dirty { "dirty" } else { "clean" };
|
||||
write!(ret, "EC git commit: {:x}, {}", rev, dirtystr).unwrap();
|
||||
write!(ret, "EC gateware commit: {:x}, {}\n", rev, dirtystr).unwrap();
|
||||
let (maj, min, rev, commit) = env.com.get_ec_sw_tag().unwrap();
|
||||
log::info!("EC sw tag: {}.{}.{}+{}", maj, min, rev, commit);
|
||||
}
|
||||
"wf200" => {
|
||||
let (maj, min, rev) = env.com.get_wf200_fw_rev().unwrap();
|
||||
|
|
|
|||
Loading…
Reference in a new issue