mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
regex search/replace instances of xous_ipc::String to String
includes some light touch-up to the API to clean up a consequence of String not being copy-able anymore
This commit is contained in:
parent
849ae5f874
commit
3eb61d3002
4 changed files with 47 additions and 41 deletions
|
|
@ -21,8 +21,9 @@ llio = { path = "../llio" }
|
|||
|
||||
num-derive = { version = "0.3.3", default-features = false }
|
||||
num-traits = { version = "0.2.14", default-features = false }
|
||||
rkyv = { version = "0.4.3", default-features = false, features = [
|
||||
"const_generics",
|
||||
rkyv = { version = "0.8.8", default-features = false, features = [
|
||||
"std",
|
||||
"alloc",
|
||||
] }
|
||||
|
||||
xous-semver = "0.1.2"
|
||||
|
|
|
|||
|
|
@ -52,24 +52,37 @@ pub(crate) struct FlashRecord {
|
|||
/// operation
|
||||
pub op: FlashOp,
|
||||
}
|
||||
#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
||||
#[derive(Debug, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
||||
pub struct SsidRecord {
|
||||
pub name: xous_ipc::String<32>,
|
||||
pub name: String,
|
||||
/// rssi is reported as the negative of actual rssi in dBm. Example: an rssi of -42dBm is reported as
|
||||
/// `42u8`.
|
||||
pub rssi: u8,
|
||||
}
|
||||
impl Default for SsidRecord {
|
||||
fn default() -> Self { SsidRecord { name: xous_ipc::String::<32>::new(), rssi: 0 } }
|
||||
fn default() -> Self { SsidRecord { name: String::new(), rssi: 0 } }
|
||||
}
|
||||
#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
||||
#[derive(Debug, 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] } }
|
||||
fn default() -> Self {
|
||||
SsidReturn {
|
||||
list: [
|
||||
SsidRecord::default(),
|
||||
SsidRecord::default(),
|
||||
SsidRecord::default(),
|
||||
SsidRecord::default(),
|
||||
SsidRecord::default(),
|
||||
SsidRecord::default(),
|
||||
SsidRecord::default(),
|
||||
SsidRecord::default(),
|
||||
],
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
||||
#[derive(Debug, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
||||
pub struct WlanStatusIpc {
|
||||
pub ssid: Option<SsidRecord>,
|
||||
pub link_state: u16, // this is slung around as a u16 to avoid pulling rkyv into the EC dependency tree
|
||||
|
|
@ -94,7 +107,7 @@ impl Default for WlanStatusIpc {
|
|||
}
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct WlanStatus {
|
||||
pub ssid: Option<SsidRecord>,
|
||||
pub link_state: com_rs::LinkState, // converted back into LinkState once it's across the IPC boundary
|
||||
|
|
@ -203,10 +216,10 @@ pub(crate) enum Opcode {
|
|||
Wf200Rev = 25,
|
||||
|
||||
/// Send a line of PDS data
|
||||
Wf200PdsLine = 26, //String<512>
|
||||
Wf200PdsLine = 26, //String
|
||||
|
||||
/// request for a listener to BattStats events
|
||||
RegisterBattStatsListener = 27, //String<64>
|
||||
RegisterBattStatsListener = 27, //String
|
||||
|
||||
/// Reset the wifi chip
|
||||
Wf200Reset = 28,
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ pub use com_rs::serdes::Ipv4Conf;
|
|||
use com_rs::{DhcpState, LinkState};
|
||||
use num_traits::{FromPrimitive, ToPrimitive};
|
||||
use xous::{msg_scalar_unpack, send_message, Error, Message, CID};
|
||||
use xous_ipc::{Buffer, String};
|
||||
use xous_ipc::Buffer;
|
||||
use xous_semver::SemVer;
|
||||
|
||||
/// mapping of the callback function to the library user
|
||||
|
|
@ -184,10 +184,10 @@ impl Com {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn send_pds_line(&self, s: &String<512>) -> Result<(), Error> {
|
||||
pub fn send_pds_line(&self, s: &String) -> Result<(), Error> {
|
||||
use core::fmt::Write;
|
||||
let mut clone_s: String<512> = String::new();
|
||||
write!(clone_s, "{}", s.as_str().unwrap()).map_err(|_| xous::Error::AccessDenied)?;
|
||||
let mut clone_s: String = String::new();
|
||||
write!(clone_s, "{}", s.as_str()).map_err(|_| xous::Error::AccessDenied)?;
|
||||
|
||||
let buf = Buffer::into_buf(clone_s).or(Err(xous::Error::InternalError))?;
|
||||
buf.lend(self.conn, Opcode::Wf200PdsLine.to_u32().unwrap()).map(|_| ())
|
||||
|
|
@ -317,12 +317,12 @@ impl Com {
|
|||
|
||||
// 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();
|
||||
pub fn ssid_fetch_as_string(&self) -> Result<String, xous::Error> {
|
||||
let ssid_list = String::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();
|
||||
let response = buf.to_original::<String, _>().unwrap();
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
|
|
@ -338,10 +338,7 @@ impl Com {
|
|||
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")),
|
||||
));
|
||||
ret.push((ssid.rssi, ssid.name));
|
||||
}
|
||||
Ok(ret)
|
||||
}
|
||||
|
|
@ -513,7 +510,7 @@ impl Com {
|
|||
if s.len() > api::WF200_SSID_MAX_LEN {
|
||||
return Err(xous::Error::InvalidString);
|
||||
}
|
||||
let mut copy: String<{ api::WF200_SSID_MAX_LEN }> = String::new();
|
||||
let mut copy = String::new();
|
||||
let _ = write!(copy, "{}", s);
|
||||
let buf = Buffer::into_buf(copy).or(Err(xous::Error::InternalError))?;
|
||||
buf.lend(self.conn, Opcode::WlanSetSSID.to_u32().unwrap())
|
||||
|
|
@ -525,7 +522,7 @@ impl Com {
|
|||
if s.len() > api::WF200_PASS_MAX_LEN {
|
||||
return Err(xous::Error::InvalidString);
|
||||
}
|
||||
let mut copy: String<{ api::WF200_PASS_MAX_LEN }> = String::new();
|
||||
let mut copy = String::new();
|
||||
let _ = write!(copy, "{}", s);
|
||||
let buf = Buffer::into_buf(copy).or(Err(xous::Error::InternalError))?;
|
||||
buf.lend(self.conn, Opcode::WlanSetPass.to_u32().unwrap())
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use com_rs::*;
|
|||
use log::{error, info, trace};
|
||||
use num_traits::{FromPrimitive, ToPrimitive};
|
||||
use xous::{msg_blocking_scalar_unpack, msg_scalar_unpack, CID};
|
||||
use xous_ipc::{Buffer, String};
|
||||
use xous_ipc::Buffer;
|
||||
|
||||
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
|
||||
|
|
@ -640,7 +640,7 @@ fn main() -> ! {
|
|||
}),
|
||||
Some(Opcode::Wf200PdsLine) => {
|
||||
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||
let l = buffer.to_original::<String<512>, _>().unwrap();
|
||||
let l = buffer.to_original::<String, _>().unwrap();
|
||||
info!("Wf200PdsLine got line {}", l);
|
||||
let line = l.as_bytes();
|
||||
let length = (l.len() + 0) as u16;
|
||||
|
|
@ -856,8 +856,8 @@ fn main() -> ! {
|
|||
// 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();
|
||||
let mut ssid_str = String::from("Top 6 SSIDs:\n");
|
||||
let mut itemized = String::new();
|
||||
for i in 0..6 {
|
||||
let mut stop = 0;
|
||||
// truncate the nulls
|
||||
|
|
@ -872,10 +872,10 @@ fn main() -> ! {
|
|||
Ok(textid) => {
|
||||
itemized.clear();
|
||||
write!(itemized, "{}. {}\n", i + 1, textid).unwrap();
|
||||
ssid_str.append(itemized.as_str().unwrap()).unwrap();
|
||||
ssid_str.push_str(&itemized);
|
||||
}
|
||||
_ => {
|
||||
ssid_str.append("-Parse Error-\n").unwrap();
|
||||
ssid_str.push_str("-Parse Error-\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -910,7 +910,7 @@ fn main() -> ! {
|
|||
let ssid_str =
|
||||
core::str::from_utf8(&raw[2..2 + len 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
|
||||
ssid_rec.name.push_str(ssid_str);
|
||||
}
|
||||
buffer.replace(ssid_ret).unwrap();
|
||||
}
|
||||
|
|
@ -969,12 +969,11 @@ fn main() -> ! {
|
|||
xous::return_scalar2(msg.sender, link as usize, dhcp as usize).unwrap();
|
||||
}),
|
||||
Some(Opcode::WlanSetSSID) => {
|
||||
const WF200_SSID_LEN: usize = 32;
|
||||
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||
let ssid = buffer.to_original::<String<WF200_SSID_LEN>, _>().unwrap();
|
||||
let ssid = buffer.to_original::<String, _>().unwrap();
|
||||
info!("WlanSetSSID: {}", ssid);
|
||||
let mut str_ser = StringSer::<STR_32_WORDS>::new();
|
||||
match str_ser.encode(&ssid.to_str()) {
|
||||
match str_ser.encode(&ssid) {
|
||||
Ok(tx_words) => {
|
||||
com.txrx(ComState::WLAN_SET_SSID.verb);
|
||||
for w in tx_words.iter() {
|
||||
|
|
@ -985,12 +984,11 @@ fn main() -> ! {
|
|||
}
|
||||
}
|
||||
Some(Opcode::WlanSetPass) => {
|
||||
const WF200_PASS_LEN: usize = 64;
|
||||
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||
let pass = buffer.to_original::<String<WF200_PASS_LEN>, _>().unwrap();
|
||||
let pass = buffer.to_original::<String, _>().unwrap();
|
||||
info!("WlanSetPass *ssssh!*");
|
||||
let mut str_ser = StringSer::<STR_64_WORDS>::new();
|
||||
match str_ser.encode(&pass.to_str()) {
|
||||
match str_ser.encode(&pass) {
|
||||
Ok(tx_words) => {
|
||||
com.txrx(ComState::WLAN_SET_PASS.verb);
|
||||
for w in tx_words.iter() {
|
||||
|
|
@ -1046,10 +1044,7 @@ fn main() -> ! {
|
|||
let status = WlanStatusIpc {
|
||||
ssid: if let Some(rssi) = rssi {
|
||||
log::debug!("RSSI: -{}dBm", rssi);
|
||||
Some(SsidRecord {
|
||||
rssi: rssi as u8,
|
||||
name: xous_ipc::String::<32>::from_str(ssid_str),
|
||||
})
|
||||
Some(SsidRecord { rssi: rssi as u8, name: String::from(ssid_str) })
|
||||
} else {
|
||||
None
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue