mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-20 09:03:28 +00:00
Merge branch 'i18n-jp' into i18n-jp
This commit is contained in:
commit
d1c443f62e
7 changed files with 314 additions and 189 deletions
|
|
@ -579,12 +579,16 @@ impl Com {
|
||||||
Message::new_blocking_scalar(Opcode::IntAck.to_usize().unwrap(), ack_val as usize, 0, 0, 0)
|
Message::new_blocking_scalar(Opcode::IntAck.to_usize().unwrap(), ack_val as usize, 0, 0, 0)
|
||||||
).expect("couldn't send IntSetMask message");
|
).expect("couldn't send IntSetMask message");
|
||||||
}
|
}
|
||||||
pub fn ints_get_active(&self, int_list: &mut Vec::<ComIntSources>) -> (Option<u16>, usize, usize) {
|
pub fn ints_get_active(&self, int_list: &mut Vec::<ComIntSources>) -> Result<(Option<u16>, usize, usize), xous::Error> {
|
||||||
let response = send_message(self.conn,
|
let response = send_message(self.conn,
|
||||||
Message::new_blocking_scalar(Opcode::IntFetchVector.to_usize().unwrap(), 0, 0, 0, 0))
|
Message::new_blocking_scalar(Opcode::IntFetchVector.to_usize().unwrap(), 0, 0, 0, 0))
|
||||||
.expect("couldn't get IntFetchVector");
|
.expect("couldn't get IntFetchVector");
|
||||||
let mut rxlen: Option<u16> = None;
|
let mut rxlen: Option<u16> = None;
|
||||||
if let xous::Result::Scalar2(ints, maybe_rxlen) = response {
|
if let xous::Result::Scalar2(ints, maybe_rxlen) = response {
|
||||||
|
if ints == 0xDDDD {
|
||||||
|
log::warn!("IntFetchVector: 0xDDDD sentinel returned");
|
||||||
|
return Err(xous::Error::Timeout);
|
||||||
|
}
|
||||||
let mut mask_bit: u16 = 1;
|
let mut mask_bit: u16 = 1;
|
||||||
for _ in 0..16 {
|
for _ in 0..16 {
|
||||||
let int_src = ComIntSources::from(mask_bit & ints as u16);
|
let int_src = ComIntSources::from(mask_bit & ints as u16);
|
||||||
|
|
@ -603,7 +607,7 @@ impl Com {
|
||||||
}
|
}
|
||||||
mask_bit <<= 1;
|
mask_bit <<= 1;
|
||||||
}
|
}
|
||||||
(rxlen, ints, maybe_rxlen)
|
Ok((rxlen, ints, maybe_rxlen))
|
||||||
} else {
|
} else {
|
||||||
panic!("failed to send IntGetmask message");
|
panic!("failed to send IntGetmask message");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -208,6 +208,7 @@ mod implementation {
|
||||||
/// indicate if the chord has been captured. Once captured, further presses are ignored, until all keys are let up.
|
/// indicate if the chord has been captured. Once captured, further presses are ignored, until all keys are let up.
|
||||||
chord_captured: bool,
|
chord_captured: bool,
|
||||||
susres: RegManager::<{utra::keyboard::KEYBOARD_NUMREGS}>,
|
susres: RegManager::<{utra::keyboard::KEYBOARD_NUMREGS}>,
|
||||||
|
pub debug: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_kbd(_irq_no: usize, arg: *mut usize) {
|
fn handle_kbd(_irq_no: usize, arg: *mut usize) {
|
||||||
|
|
@ -233,11 +234,16 @@ mod implementation {
|
||||||
xous::Message::new_scalar(Opcode::HandlerTrigger.to_usize().unwrap(), 0, 0, 0, 0)).ok();
|
xous::Message::new_scalar(Opcode::HandlerTrigger.to_usize().unwrap(), 0, 0, 0, 0)).ok();
|
||||||
}
|
}
|
||||||
if kbd.csr.rf(utra::keyboard::EV_PENDING_INJECT) != 0 {
|
if kbd.csr.rf(utra::keyboard::EV_PENDING_INJECT) != 0 {
|
||||||
while kbd.csr.rf(utra::keyboard::UART_CHAR_STB) != 0 {
|
loop {
|
||||||
let c = kbd.csr.rf(utra::keyboard::UART_CHAR_CHAR);
|
let char_reg = kbd.csr.r(utra::keyboard::UART_CHAR);
|
||||||
xous::try_send_message(kbd.conn,
|
if char_reg & kbd.csr.ms(utra::keyboard::UART_CHAR_STB, 1) != 0 {
|
||||||
xous::Message::new_scalar(Opcode::InjectKey.to_usize().unwrap(), c as _, 0, 0, 0)
|
xous::try_send_message(kbd.conn,
|
||||||
).ok();
|
xous::Message::new_scalar(Opcode::InjectKey.to_usize().unwrap(), (char_reg & 0xff) as _, 0, 0, 0)
|
||||||
|
).ok();
|
||||||
|
kbd.debug += 1;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
kbd.csr.wo(utra::keyboard::EV_PENDING, pending);
|
kbd.csr.wo(utra::keyboard::EV_PENDING, pending);
|
||||||
|
|
@ -300,6 +306,7 @@ mod implementation {
|
||||||
chord_active: 0,
|
chord_active: 0,
|
||||||
chord_captured: false,
|
chord_captured: false,
|
||||||
susres: RegManager::new(csr.as_mut_ptr() as *mut u32),
|
susres: RegManager::new(csr.as_mut_ptr() as *mut u32),
|
||||||
|
debug: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
xous::claim_interrupt(
|
xous::claim_interrupt(
|
||||||
|
|
@ -757,6 +764,7 @@ mod implementation {
|
||||||
rate: u32,
|
rate: u32,
|
||||||
delay: u32,
|
delay: u32,
|
||||||
chord_interval: u32,
|
chord_interval: u32,
|
||||||
|
pub debug: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Keyboard {
|
impl Keyboard {
|
||||||
|
|
@ -767,6 +775,7 @@ mod implementation {
|
||||||
rate: 20,
|
rate: 20,
|
||||||
delay: 200,
|
delay: 200,
|
||||||
chord_interval: 50,
|
chord_interval: 50,
|
||||||
|
debug: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn suspend(&self) {
|
pub fn suspend(&self) {
|
||||||
|
|
@ -849,7 +858,8 @@ fn xmain() -> ! {
|
||||||
log::warn!("kbd server is overriding WFI for debugging, remember to disable for production");
|
log::warn!("kbd server is overriding WFI for debugging, remember to disable for production");
|
||||||
llio.wfi_override(true).unwrap();
|
llio.wfi_override(true).unwrap();
|
||||||
}*/
|
}*/
|
||||||
let mut inject_esc = false;
|
let mut esc_index: Option<usize> = None;
|
||||||
|
let mut esc_chars = [0u8; 16];
|
||||||
|
|
||||||
log::trace!("starting main loop");
|
log::trace!("starting main loop");
|
||||||
loop {
|
loop {
|
||||||
|
|
@ -906,41 +916,61 @@ fn xmain() -> ! {
|
||||||
}),
|
}),
|
||||||
Some(Opcode::InjectKey) => msg_scalar_unpack!(msg, k, _, _, _, {
|
Some(Opcode::InjectKey) => msg_scalar_unpack!(msg, k, _, _, _, {
|
||||||
// key substitutions to help things work better
|
// key substitutions to help things work better
|
||||||
// 5b31 = home (5b7e now that we have things working better?? maybe this is a three-byte sequence and I'm missing a third?)
|
// 1b5b317e = home
|
||||||
// 5b44 = left
|
// 1b5b44 = left
|
||||||
// 5b43 = right
|
// 1b5b43 = right
|
||||||
// 5b41 = up
|
// 1b5b41 = up
|
||||||
// 5b42 = down
|
// 1b5b42 = down
|
||||||
let k_prime = if !inject_esc {
|
log::trace!("{:x} {}", k, kbd.debug);
|
||||||
match k {
|
kbd.debug = 0;
|
||||||
0x7f => 0x08,
|
|
||||||
0x5b => {
|
let key = match esc_index {
|
||||||
inject_esc = true;
|
Some(i) => {
|
||||||
0x00
|
esc_chars[i] = (k & 0xff) as u8;
|
||||||
|
match esc_match(&esc_chars[..i + 1]) {
|
||||||
|
Ok(m) => {
|
||||||
|
if let Some(code) = m {
|
||||||
|
// Ok(Some(code)) is a character found
|
||||||
|
esc_chars = [0u8; 16];
|
||||||
|
esc_index = None;
|
||||||
|
code
|
||||||
|
} else {
|
||||||
|
// Ok(None) means we're still accumulating characters
|
||||||
|
if i + 1 < esc_chars.len() {
|
||||||
|
esc_index = Some(i + 1);
|
||||||
|
} else {
|
||||||
|
esc_index = None;
|
||||||
|
esc_chars = [0u8; 16];
|
||||||
|
}
|
||||||
|
'\u{0000}'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// invalid sequence encountered, abort
|
||||||
|
Err(_) => {
|
||||||
|
log::warn!("Unhandled escape sequence: {:x?}", &esc_chars[..i+1]);
|
||||||
|
esc_chars = [0u8; 16];
|
||||||
|
esc_index = None;
|
||||||
|
'\u{0000}'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => k as u32
|
|
||||||
}
|
}
|
||||||
} else {
|
_ => {
|
||||||
inject_esc = false;
|
if k == 0x1b {
|
||||||
match k {
|
esc_index = Some(1);
|
||||||
0x7e => '∴' as u32,
|
esc_chars = [0u8; 16]; // clear the full search array with every escape sequence init
|
||||||
0x44 => '←' as u32,
|
esc_chars[0] = 0x1b;
|
||||||
0x43 => '→' as u32,
|
'\u{0000}'
|
||||||
0x41 => '↑' as u32,
|
} else {
|
||||||
0x42 => '↓' as u32,
|
let bs_del_fix = if k == 0x7f {
|
||||||
_ => {
|
0x08
|
||||||
log::warn!("unknown escape sequence, ignoring: 0x5b{:x}", k);
|
} else {
|
||||||
0
|
k
|
||||||
|
};
|
||||||
|
core::char::from_u32(bs_del_fix as u32).unwrap_or('\u{0000}')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let key = if let Some(a) = core::char::from_u32(k_prime) {
|
|
||||||
a
|
|
||||||
} else {
|
|
||||||
log::warn!("Uninterpreable key sequence, ignoring: 0x{:x}", k);
|
|
||||||
'\u{0000}'
|
|
||||||
};
|
|
||||||
if let Some(conn) = listener_conn {
|
if let Some(conn) = listener_conn {
|
||||||
if key != '\u{0000}' {
|
if key != '\u{0000}' {
|
||||||
log::info!("injecting key '{}'({:x})", key, key as u32); // always be noisy about this, it's an exploit path
|
log::info!("injecting key '{}'({:x})", key, key as u32); // always be noisy about this, it's an exploit path
|
||||||
|
|
@ -1029,3 +1059,33 @@ fn xmain() -> ! {
|
||||||
log::trace!("quitting");
|
log::trace!("quitting");
|
||||||
xous::terminate_process(0)
|
xous::terminate_process(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn esc_match(esc_chars: &[u8]) -> Result<Option<char>, ()> {
|
||||||
|
let mut extended = Vec::<u8>::new();
|
||||||
|
for (i, &c) in esc_chars.iter().enumerate() {
|
||||||
|
match i {
|
||||||
|
0 => if c != 0x1b { return Err(()) },
|
||||||
|
1 => if c != 0x5b { return Err(()) },
|
||||||
|
2 => match c {
|
||||||
|
0x41 => return Ok(Some('↑')),
|
||||||
|
0x42 => return Ok(Some('↓')),
|
||||||
|
0x43 => return Ok(Some('→')),
|
||||||
|
0x44 => return Ok(Some('←')),
|
||||||
|
0x7e => return Err(()), // premature end
|
||||||
|
_ => extended.push(c)
|
||||||
|
}
|
||||||
|
_ => if c == 0x7e {
|
||||||
|
if extended.len() == 1 {
|
||||||
|
if extended[0] == 0x31 {
|
||||||
|
return Ok(Some('∴'))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return Err(()) // code unrecognized
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
extended.push(c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
|
@ -171,6 +171,12 @@ pub(crate) fn connection_manager(sid: xous::SID, activity_interval: Arc<AtomicU3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LinkState::WFXError => {
|
LinkState::WFXError => {
|
||||||
|
// reset the stats cache, and update subscribers that we're disconnected
|
||||||
|
wifi_stats_cache = WlanStatus::from_ipc(WlanStatusIpc::default());
|
||||||
|
for &sub in status_subscribers.keys() {
|
||||||
|
let buf = Buffer::into_buf(com::WlanStatusIpc::from_status(wifi_stats_cache)).or(Err(xous::Error::InternalError)).unwrap();
|
||||||
|
buf.send(sub, WifiStateCallback::Update.to_u32().unwrap()).or(Err(xous::Error::InternalError)).unwrap();
|
||||||
|
}
|
||||||
wifi_state = WifiState::Error;
|
wifi_state = WifiState::Error;
|
||||||
}
|
}
|
||||||
_ => { // should approximately be a "disconnected" state.
|
_ => { // should approximately be a "disconnected" state.
|
||||||
|
|
@ -484,7 +490,11 @@ fn get_next_ssid(ssid_list: &mut HashSet<String>, ssid_attempted: &mut HashSet<S
|
||||||
log::debug!("SSID connect attempt: {:?}", candidate);
|
log::debug!("SSID connect attempt: {:?}", candidate);
|
||||||
Some(candidate.to_string())
|
Some(candidate.to_string())
|
||||||
} else {
|
} else {
|
||||||
log::info!("No SSID candidates visible");
|
log::info!("No SSID candidates visible. Debug dump:");
|
||||||
|
log::info!("ap_list: {:?}", ap_list);
|
||||||
|
log::info!("ssid_list: {:?}", ssid_list);
|
||||||
|
log::info!("candidate list: {:?}", all_candidate_list);
|
||||||
|
log::info!("untried candidate list: {:?}", untried_candidate_list);
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,18 @@ pub struct PingConnection {
|
||||||
retop: usize,
|
retop: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_com_ints(com_int_list: &mut Vec::<ComIntSources>) {
|
||||||
|
com_int_list.clear();
|
||||||
|
com_int_list.push(ComIntSources::WlanIpConfigUpdate);
|
||||||
|
com_int_list.push(ComIntSources::WlanRxReady);
|
||||||
|
com_int_list.push(ComIntSources::BatteryCritical);
|
||||||
|
com_int_list.push(ComIntSources::Connect);
|
||||||
|
com_int_list.push(ComIntSources::Disconnect);
|
||||||
|
com_int_list.push(ComIntSources::WlanSsidScanUpdate);
|
||||||
|
com_int_list.push(ComIntSources::WlanSsidScanFinished);
|
||||||
|
com_int_list.push(ComIntSources::WfxErr);
|
||||||
|
}
|
||||||
|
|
||||||
#[xous::xous_main]
|
#[xous::xous_main]
|
||||||
fn xmain() -> ! {
|
fn xmain() -> ! {
|
||||||
log_server::init_wait().unwrap();
|
log_server::init_wait().unwrap();
|
||||||
|
|
@ -101,20 +113,12 @@ fn xmain() -> ! {
|
||||||
llio.com_event_enable(true).unwrap();
|
llio.com_event_enable(true).unwrap();
|
||||||
// setup the interrupt masks
|
// setup the interrupt masks
|
||||||
let mut com_int_list: Vec::<ComIntSources> = vec![];
|
let mut com_int_list: Vec::<ComIntSources> = vec![];
|
||||||
com.ints_get_active(&mut com_int_list);
|
com.ints_get_active(&mut com_int_list).ok();
|
||||||
log::debug!("COM initial pending interrupts: {:?}", com_int_list);
|
log::debug!("COM initial pending interrupts: {:?}", com_int_list);
|
||||||
com_int_list.clear();
|
set_com_ints(&mut com_int_list);
|
||||||
com_int_list.push(ComIntSources::WlanIpConfigUpdate);
|
|
||||||
com_int_list.push(ComIntSources::WlanRxReady);
|
|
||||||
com_int_list.push(ComIntSources::BatteryCritical);
|
|
||||||
com_int_list.push(ComIntSources::Connect);
|
|
||||||
com_int_list.push(ComIntSources::Disconnect);
|
|
||||||
com_int_list.push(ComIntSources::WlanSsidScanUpdate);
|
|
||||||
com_int_list.push(ComIntSources::WlanSsidScanFinished);
|
|
||||||
com_int_list.push(ComIntSources::WfxErr);
|
|
||||||
com.ints_enable(&com_int_list);
|
com.ints_enable(&com_int_list);
|
||||||
com_int_list.clear();
|
com_int_list.clear();
|
||||||
com.ints_get_active(&mut com_int_list);
|
com.ints_get_active(&mut com_int_list).ok();
|
||||||
log::debug!("COM pending interrupts after enabling: {:?}", com_int_list);
|
log::debug!("COM pending interrupts after enabling: {:?}", com_int_list);
|
||||||
const MAX_DELAY_THREADS: u32 = 10; // limit the number of concurrent delay threads. Typically we have 1-2 running at any time, but DoS conditions could lead to many more.
|
const MAX_DELAY_THREADS: u32 = 10; // limit the number of concurrent delay threads. Typically we have 1-2 running at any time, but DoS conditions could lead to many more.
|
||||||
let delay_threads = Arc::new(AtomicU32::new(0));
|
let delay_threads = Arc::new(AtomicU32::new(0));
|
||||||
|
|
@ -554,128 +558,149 @@ fn xmain() -> ! {
|
||||||
|
|
||||||
Some(Opcode::ComInterrupt) => {
|
Some(Opcode::ComInterrupt) => {
|
||||||
com_int_list.clear();
|
com_int_list.clear();
|
||||||
let (maybe_rxlen, ints, raw_rxlen) = com.ints_get_active(&mut com_int_list);
|
match com.ints_get_active(&mut com_int_list) {
|
||||||
log::debug!("COM got interrupts: {:?}, {:?}", com_int_list, maybe_rxlen);
|
Ok((maybe_rxlen, ints, raw_rxlen)) => {
|
||||||
// forward the interrupt to the connection manager as well
|
log::debug!("COM got interrupts: {:?}, {:?}", com_int_list, maybe_rxlen);
|
||||||
match xous::try_send_message(cm_cid, Message::new_scalar(
|
// forward the interrupt to the connection manager as well
|
||||||
connection_manager::ConnectionManagerOpcode::ComInt.to_usize().unwrap(),
|
match xous::try_send_message(cm_cid, Message::new_scalar(
|
||||||
ints,
|
connection_manager::ConnectionManagerOpcode::ComInt.to_usize().unwrap(),
|
||||||
raw_rxlen,
|
ints,
|
||||||
0, 0
|
raw_rxlen,
|
||||||
)) {
|
0, 0
|
||||||
Ok(_) => {},
|
)) {
|
||||||
Err(xous::Error::ServerQueueFull) => {
|
Ok(_) => {},
|
||||||
log::warn!("Our net queue runneth over, interrupts were dropped.");
|
Err(xous::Error::ServerQueueFull) => {
|
||||||
},
|
log::warn!("Our net queue runneth over, interrupts were dropped.");
|
||||||
Err(e) => {
|
},
|
||||||
log::error!("Unhandled error forwarding ComInt to the connection manager: {:?}", e);
|
Err(e) => {
|
||||||
}
|
log::error!("Unhandled error forwarding ComInt to the connection manager: {:?}", e);
|
||||||
};
|
|
||||||
for &pending in com_int_list.iter() {
|
|
||||||
if pending == ComIntSources::Invalid {
|
|
||||||
log::error!("COM interrupt vector had an error, ignoring event.");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for &pending in com_int_list.iter() {
|
|
||||||
match pending {
|
|
||||||
ComIntSources::BatteryCritical => {
|
|
||||||
log::warn!("Battery is critical! TODO: go into SHIP mode");
|
|
||||||
},
|
|
||||||
ComIntSources::WlanIpConfigUpdate => {
|
|
||||||
// right now the WLAN implementation only does IPV4. So IPV6 compatibility ends here.
|
|
||||||
// if IPV6 gets added to the EC/COM bus, ideally this is one of a couple spots in Xous that needs a tweak.
|
|
||||||
let config = com.wlan_get_config().expect("couldn't retrieve updated ipv4 config");
|
|
||||||
log::info!("Network config acquired: {:?}", config);
|
|
||||||
net_config = Some(config);
|
|
||||||
let mac = EthernetAddress::from_bytes(&config.mac);
|
|
||||||
|
|
||||||
// we need to clear the ARP cache in case we've migrated base stations (e.g. in a wireless network
|
|
||||||
// that is coverd by multiple AP), as the host AP's MAC address would have changed, and we wouldn't
|
|
||||||
// be able to route responses back. I can't seem to find a function in smoltcp 0.7.5 that allows us
|
|
||||||
// to neatly clear the ARP cache as the BTreeMap that underlies it is moved into the container and
|
|
||||||
// no "clear" API is exposed, so let's just rebuild the whole interface if we get a DHCP renewal.
|
|
||||||
let neighbor_cache = NeighborCache::new(BTreeMap::new());
|
|
||||||
let ip_addrs = [IpCidr::new(Ipv4Address::UNSPECIFIED.into(), 0)];
|
|
||||||
let routes = Routes::new(BTreeMap::new());
|
|
||||||
let device = device::NetPhy::new(&xns);
|
|
||||||
let medium = device.capabilities().medium;
|
|
||||||
let mut builder = InterfaceBuilder::new(device)
|
|
||||||
.ip_addrs(ip_addrs)
|
|
||||||
.routes(routes);
|
|
||||||
if medium == Medium::Ethernet {
|
|
||||||
builder = builder
|
|
||||||
.ethernet_addr(mac)
|
|
||||||
.neighbor_cache(neighbor_cache);
|
|
||||||
}
|
}
|
||||||
iface = builder.finalize();
|
};
|
||||||
|
for &pending in com_int_list.iter() {
|
||||||
let ip_addr =
|
if pending == ComIntSources::Invalid {
|
||||||
Ipv4Cidr::new(Ipv4Address::new(
|
log::error!("COM interrupt vector had an error, ignoring event.");
|
||||||
config.addr[0],
|
continue;
|
||||||
config.addr[1],
|
|
||||||
config.addr[2],
|
|
||||||
config.addr[3],
|
|
||||||
), 24);
|
|
||||||
set_ipv4_addr(&mut iface, ip_addr);
|
|
||||||
let default_v4_gw = Ipv4Address::new(
|
|
||||||
config.gtwy[0],
|
|
||||||
config.gtwy[1],
|
|
||||||
config.gtwy[2],
|
|
||||||
config.gtwy[3],
|
|
||||||
);
|
|
||||||
|
|
||||||
// reset the default route, in case it has changed
|
|
||||||
iface.routes_mut().remove_default_ipv4_route();
|
|
||||||
match iface.routes_mut().add_default_ipv4_route(default_v4_gw) {
|
|
||||||
Ok(route) => log::info!("routing table updated successfully [{:?}]", route),
|
|
||||||
Err(e) => log::error!("routing table update error: {}", e),
|
|
||||||
}
|
}
|
||||||
dns_allclear_hook.notify();
|
}
|
||||||
dns_ipv4_hook.notify_custom_args([
|
for &pending in com_int_list.iter() {
|
||||||
Some(u32::from_be_bytes(config.dns1)),
|
match pending {
|
||||||
None, None, None,
|
ComIntSources::BatteryCritical => {
|
||||||
]);
|
log::warn!("Battery is critical! TODO: go into SHIP mode");
|
||||||
// the current implementation always returns 0.0.0.0 as the second dns,
|
},
|
||||||
// ignore this if that's what we've got; otherwise, pass it on.
|
ComIntSources::WlanIpConfigUpdate => {
|
||||||
if config.dns2 != [0, 0, 0, 0] {
|
// right now the WLAN implementation only does IPV4. So IPV6 compatibility ends here.
|
||||||
dns_ipv4_hook.notify_custom_args([
|
// if IPV6 gets added to the EC/COM bus, ideally this is one of a couple spots in Xous that needs a tweak.
|
||||||
Some(u32::from_be_bytes(config.dns2)),
|
let config = com.wlan_get_config().expect("couldn't retrieve updated ipv4 config");
|
||||||
None, None, None,
|
log::info!("Network config acquired: {:?}", config);
|
||||||
]);
|
net_config = Some(config);
|
||||||
}
|
let mac = EthernetAddress::from_bytes(&config.mac);
|
||||||
},
|
|
||||||
ComIntSources::WlanRxReady => {
|
// we need to clear the ARP cache in case we've migrated base stations (e.g. in a wireless network
|
||||||
activity_interval.store(0, Ordering::Relaxed); // reset the activity interval to 0
|
// that is coverd by multiple AP), as the host AP's MAC address would have changed, and we wouldn't
|
||||||
if let Some(_config) = net_config {
|
// be able to route responses back. I can't seem to find a function in smoltcp 0.7.5 that allows us
|
||||||
if let Some(rxlen) = maybe_rxlen {
|
// to neatly clear the ARP cache as the BTreeMap that underlies it is moved into the container and
|
||||||
match iface.device_mut().push_rx_avail(rxlen) {
|
// no "clear" API is exposed, so let's just rebuild the whole interface if we get a DHCP renewal.
|
||||||
None => {} //log::info!("pushed {} bytes avail to iface", rxlen),
|
let neighbor_cache = NeighborCache::new(BTreeMap::new());
|
||||||
Some(_) => log::warn!("Got more packets, but smoltcp didn't drain them in time"),
|
let ip_addrs = [IpCidr::new(Ipv4Address::UNSPECIFIED.into(), 0)];
|
||||||
|
let routes = Routes::new(BTreeMap::new());
|
||||||
|
let device = device::NetPhy::new(&xns);
|
||||||
|
let medium = device.capabilities().medium;
|
||||||
|
let mut builder = InterfaceBuilder::new(device)
|
||||||
|
.ip_addrs(ip_addrs)
|
||||||
|
.routes(routes);
|
||||||
|
if medium == Medium::Ethernet {
|
||||||
|
builder = builder
|
||||||
|
.ethernet_addr(mac)
|
||||||
|
.neighbor_cache(neighbor_cache);
|
||||||
}
|
}
|
||||||
match xous::try_send_message(
|
iface = builder.finalize();
|
||||||
net_conn,
|
|
||||||
Message::new_scalar(Opcode::NetPump.to_usize().unwrap(), 0, 0, 0, 0)
|
let ip_addr =
|
||||||
) {
|
Ipv4Cidr::new(Ipv4Address::new(
|
||||||
Ok(_) => {},
|
config.addr[0],
|
||||||
Err(xous::Error::ServerQueueFull) => {
|
config.addr[1],
|
||||||
log::warn!("Our net queue runneth over, packets will be dropped.");
|
config.addr[2],
|
||||||
},
|
config.addr[3],
|
||||||
Err(e) => {
|
), 24);
|
||||||
log::error!("Unhandled error sending NetPump to self: {:?}", e);
|
set_ipv4_addr(&mut iface, ip_addr);
|
||||||
|
let default_v4_gw = Ipv4Address::new(
|
||||||
|
config.gtwy[0],
|
||||||
|
config.gtwy[1],
|
||||||
|
config.gtwy[2],
|
||||||
|
config.gtwy[3],
|
||||||
|
);
|
||||||
|
|
||||||
|
// reset the default route, in case it has changed
|
||||||
|
iface.routes_mut().remove_default_ipv4_route();
|
||||||
|
match iface.routes_mut().add_default_ipv4_route(default_v4_gw) {
|
||||||
|
Ok(route) => log::info!("routing table updated successfully [{:?}]", route),
|
||||||
|
Err(e) => log::error!("routing table update error: {}", e),
|
||||||
|
}
|
||||||
|
dns_allclear_hook.notify();
|
||||||
|
dns_ipv4_hook.notify_custom_args([
|
||||||
|
Some(u32::from_be_bytes(config.dns1)),
|
||||||
|
None, None, None,
|
||||||
|
]);
|
||||||
|
// the current implementation always returns 0.0.0.0 as the second dns,
|
||||||
|
// ignore this if that's what we've got; otherwise, pass it on.
|
||||||
|
if config.dns2 != [0, 0, 0, 0] {
|
||||||
|
dns_ipv4_hook.notify_custom_args([
|
||||||
|
Some(u32::from_be_bytes(config.dns2)),
|
||||||
|
None, None, None,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
ComIntSources::WlanRxReady => {
|
||||||
|
activity_interval.store(0, Ordering::Relaxed); // reset the activity interval to 0
|
||||||
|
if let Some(_config) = net_config {
|
||||||
|
if let Some(rxlen) = maybe_rxlen {
|
||||||
|
match iface.device_mut().push_rx_avail(rxlen) {
|
||||||
|
None => {} //log::info!("pushed {} bytes avail to iface", rxlen),
|
||||||
|
Some(_) => log::warn!("Got more packets, but smoltcp didn't drain them in time"),
|
||||||
|
}
|
||||||
|
match xous::try_send_message(
|
||||||
|
net_conn,
|
||||||
|
Message::new_scalar(Opcode::NetPump.to_usize().unwrap(), 0, 0, 0, 0)
|
||||||
|
) {
|
||||||
|
Ok(_) => {},
|
||||||
|
Err(xous::Error::ServerQueueFull) => {
|
||||||
|
log::warn!("Our net queue runneth over, packets will be dropped.");
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("Unhandled error sending NetPump to self: {:?}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log::error!("Got RxReady interrupt but no packet length specified!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
},
|
||||||
log::error!("Got RxReady interrupt but no packet length specified!");
|
_ => {
|
||||||
|
log::debug!("Unhandled: {:?}", pending);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
_ => {
|
|
||||||
log::debug!("Unhandled: {:?}", pending);
|
|
||||||
}
|
}
|
||||||
|
com.ints_ack(&com_int_list);
|
||||||
|
},
|
||||||
|
Err(xous::Error::Timeout) => {
|
||||||
|
log::warn!("Interrupt fetch from COM timed out.");
|
||||||
|
// bread crumb: this is a "normal" error to throw when the EC is being reset,
|
||||||
|
// or when it is handling the reset of the wifi subsystem, so it's not fatal.
|
||||||
|
// However, if we see this repeatedly, it might be a good idea to add some sort
|
||||||
|
// of event counter to log the number of times we've seen this consecutively and
|
||||||
|
// if it's too much, issue a reset to the EC.
|
||||||
|
|
||||||
|
// refresh the interrupt list to the EC, just in case it lost the prior list
|
||||||
|
timer.sleep_ms(1000).unwrap(); // a brief delay because if the EC wasn't responding before, it probably needs /some/ time before being able to handle this next message
|
||||||
|
set_com_ints(&mut com_int_list);
|
||||||
|
com.ints_enable(&com_int_list);
|
||||||
|
com_int_list.clear();
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
// not fatal, just report it.
|
||||||
|
log::error!("Unhanlded error in COM interrupt fetch");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
com.ints_ack(&com_int_list);
|
|
||||||
}
|
}
|
||||||
Some(Opcode::NetPump) => {
|
Some(Opcode::NetPump) => {
|
||||||
let timestamp = Instant::from_millis(timer.elapsed_ms() as i64);
|
let timestamp = Instant::from_millis(timer.elapsed_ms() as i64);
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,12 @@ impl<'a> ShellCmdApi<'a> for Ssid {
|
||||||
|
|
||||||
if let Some(sub_cmd) = tokens.next() {
|
if let Some(sub_cmd) = tokens.next() {
|
||||||
match sub_cmd {
|
match sub_cmd {
|
||||||
|
"force" => {
|
||||||
|
env.com.set_ssid_scanning(true).unwrap();
|
||||||
|
write!(ret, "Forcing SSID scan. Warning: could put the connection manager in an inconsistent state.").unwrap();
|
||||||
|
}
|
||||||
"scan" => {
|
"scan" => {
|
||||||
// SSID scanning is automatically initiated by the connection manager
|
// SSID scanning is automatically initiated by the connection manager, so we don't initiate it explicitly, just report results
|
||||||
let ssid_list = env.com.ssid_fetch_as_list().unwrap();
|
let ssid_list = env.com.ssid_fetch_as_list().unwrap();
|
||||||
write!(ret, "RSSI in dBm:\n").unwrap();
|
write!(ret, "RSSI in dBm:\n").unwrap();
|
||||||
for (rssi, name) in ssid_list {
|
for (rssi, name) in ssid_list {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,20 @@
|
||||||
{
|
{
|
||||||
|
"stats.measuring": {
|
||||||
|
"en": "Measuring...",
|
||||||
|
"zh": "进行测量...",
|
||||||
|
"en-audio": "Measuring..."
|
||||||
|
},
|
||||||
|
"stats.disconnected": {
|
||||||
|
"en": "Not connected",
|
||||||
|
"zh": "没有连接",
|
||||||
|
"en-audio": "Not connected"
|
||||||
|
},
|
||||||
|
"stats.uptime": {
|
||||||
|
"translator-note": "This needs to be a very short string, 2 chars max. Trailing space is necessary for English due to proportional font.",
|
||||||
|
"en": "Up ",
|
||||||
|
"zh": "运行",
|
||||||
|
"en-audio": "Uptime"
|
||||||
|
},
|
||||||
"secnote.usb_unlock": {
|
"secnote.usb_unlock": {
|
||||||
"en": " USB unlocked",
|
"en": " USB unlocked",
|
||||||
"ja": "USBロック解除",
|
"ja": "USBロック解除",
|
||||||
|
|
|
||||||
|
|
@ -357,34 +357,39 @@ fn xmain() -> ! {
|
||||||
battstats_tv.clear_str();
|
battstats_tv.clear_str();
|
||||||
// have to clear the entire rectangle area, because the SSID has a variable width and can be much wider or shorter than battstats
|
// have to clear the entire rectangle area, because the SSID has a variable width and can be much wider or shorter than battstats
|
||||||
gam.draw_rectangle(status_gid, stats_rect).ok();
|
gam.draw_rectangle(status_gid, stats_rect).ok();
|
||||||
// toggle between two views of the data every time we have a status update
|
|
||||||
let mut wattage = stats.current as f32 / 1000.0 * stats.voltage as f32 / 1000.0;
|
if stats.current == 0xdddd || stats.current == 0xffff
|
||||||
let sign = if wattage > 0.005 {
|
|| stats.voltage == 0xdddd || stats.voltage == 0xffff
|
||||||
'\u{2b06}' // up arrow
|
|| stats.soc == 0xdddd || stats.soc == 0xffff {
|
||||||
} else if wattage < -0.005 {
|
write!(&mut battstats_tv, "{}", t!("stats.measuring", xous::LANG)).unwrap();
|
||||||
'\u{2b07}' // down arrow
|
|
||||||
} else {
|
} else {
|
||||||
'\u{1f50c}' // plugged in icon (e.g., fully charged, running on wall power now)
|
// toggle between two views of the data every time we have a status update
|
||||||
};
|
let mut wattage = stats.current as f32 / 1000.0 * stats.voltage as f32 / 1000.0;
|
||||||
wattage = wattage.abs();
|
let sign = if wattage > 0.005 {
|
||||||
if battstats_phase {
|
'\u{2b06}' // up arrow
|
||||||
write!(&mut battstats_tv, "{:.3}W{}{:.2}V {}%", wattage, sign, stats.voltage as f32 / 1000.0, stats.soc)
|
} else if wattage < -0.005 {
|
||||||
.expect("|status: can't write string");
|
'\u{2b07}' // down arrow
|
||||||
} else {
|
|
||||||
if let Some(ssid) = wifi_status.ssid {
|
|
||||||
write!(
|
|
||||||
&mut battstats_tv,
|
|
||||||
"{} -{}dBm",
|
|
||||||
ssid.name.as_str().unwrap_or("UTF-8 Erorr"),
|
|
||||||
ssid.rssi,
|
|
||||||
)
|
|
||||||
.expect("|status: can't write string");
|
|
||||||
} else {
|
} else {
|
||||||
write!(
|
'\u{1f50c}' // plugged in icon (e.g., fully charged, running on wall power now)
|
||||||
&mut battstats_tv,
|
};
|
||||||
"Not connected"
|
wattage = wattage.abs();
|
||||||
)
|
if battstats_phase {
|
||||||
.expect("|status: can't write string");
|
write!(&mut battstats_tv, "{:.3}W{}{:.2}V {}%", wattage, sign, stats.voltage as f32 / 1000.0, stats.soc).unwrap();
|
||||||
|
} else {
|
||||||
|
if let Some(ssid) = wifi_status.ssid {
|
||||||
|
write!(
|
||||||
|
&mut battstats_tv,
|
||||||
|
"{} -{}dBm",
|
||||||
|
ssid.name.as_str().unwrap_or("UTF-8 Erorr"),
|
||||||
|
ssid.rssi,
|
||||||
|
).unwrap();
|
||||||
|
} else {
|
||||||
|
write!(
|
||||||
|
&mut battstats_tv,
|
||||||
|
"{}",
|
||||||
|
t!("stats.disconnected", xous::LANG)
|
||||||
|
).unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gam.post_textview(&mut battstats_tv)
|
gam.post_textview(&mut battstats_tv)
|
||||||
|
|
@ -539,7 +544,8 @@ fn xmain() -> ! {
|
||||||
// use ticktimer, not stats_phase, because stats_phase encodes some phase drift due to task-switching overhead
|
// use ticktimer, not stats_phase, because stats_phase encodes some phase drift due to task-switching overhead
|
||||||
write!(
|
write!(
|
||||||
&mut uptime_tv,
|
&mut uptime_tv,
|
||||||
" Up {}:{:02}:{:02}",
|
" {}{}:{:02}:{:02}",
|
||||||
|
t!("stats.uptime", xous::LANG),
|
||||||
(elapsed_time / 3_600_000),
|
(elapsed_time / 3_600_000),
|
||||||
(elapsed_time / 60_000) % 60,
|
(elapsed_time / 60_000) % 60,
|
||||||
(elapsed_time / 1000) % 60,
|
(elapsed_time / 1000) % 60,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue