Use com_rs::serdes::StringSer for wlan ssid & pass

Switch to using the new com_rs::serdes::StringSer struct for
serializing the COM protocol arguments to WLAN_SET_SSID and
WLAN_SET_PASS. The point is to reduce the amount of ad hoc,
untested packing and unpacking.

Signed-off-by: samblenny
This commit is contained in:
Sam Blenny 2021-08-03 14:04:20 +00:00
parent a614ccffb7
commit ba4ca72703

View file

@ -10,6 +10,7 @@ use log::{error, info, trace};
use com_rs_ref as com_rs; use com_rs_ref as com_rs;
use com_rs::*; use com_rs::*;
use com_rs::serdes::{STR_32_WORDS, STR_64_WORDS, StringSer};
use xous::{CID, msg_scalar_unpack, msg_blocking_scalar_unpack}; use xous::{CID, msg_scalar_unpack, msg_blocking_scalar_unpack};
use xous_ipc::{Buffer, String}; use xous_ipc::{Buffer, String};
@ -596,19 +597,15 @@ fn xmain() -> ! {
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; 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::<WF200_SSID_LEN>, _>().unwrap();
info!("WlanSetSSID: {}", ssid); info!("WlanSetSSID: {}", ssid);
let ssid_bytes = ssid.as_bytes(); let mut str_ser = StringSer::<STR_32_WORDS>::new();
let length = ssid.len(); match str_ser.encode(&ssid.to_str()) {
com.txrx(ComState::WLAN_SET_SSID.verb); Ok(tx_words) => {
// Always send fixed size message of 1 length word + WF200_SSID_LEN/2 ssid words com.txrx(ComState::WLAN_SET_SSID.verb);
com.txrx(length as u16); for w in tx_words.iter() {
for i in 0..WF200_SSID_LEN/2 { com.txrx(*w);
let n = i * 2; }
let word: u16 = match 0 { }
_ if n + 1 < length => (ssid_bytes[n] as u16) | ((ssid_bytes[n + 1] as u16) << 8), _ => info!("WlanSetSSID FAIL"),
_ if n < length => ssid_bytes[n] as u16,
_ => 0 as u16,
};
com.txrx(word);
} }
} }
Some(Opcode::WlanSetPass) => { Some(Opcode::WlanSetPass) => {
@ -616,19 +613,15 @@ fn xmain() -> ! {
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; 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::<WF200_PASS_LEN>, _>().unwrap();
info!("WlanSetPass: {}", pass); info!("WlanSetPass: {}", pass);
let pass_bytes = pass.as_bytes(); let mut str_ser = StringSer::<STR_64_WORDS>::new();
let length = pass.len(); match str_ser.encode(&pass.to_str()) {
com.txrx(ComState::WLAN_SET_PASS.verb); Ok(tx_words) => {
// Always send fixed size message of 1 length word + WF200_PASS_LEN/2 ssid words com.txrx(ComState::WLAN_SET_PASS.verb);
com.txrx(length as u16); for w in tx_words.iter() {
for i in 0..WF200_PASS_LEN/2 { com.txrx(*w);
let n = i * 2; }
let word: u16 = match 0 { }
_ if n + 1 < length => (pass_bytes[n] as u16) | ((pass_bytes[n + 1] as u16) << 8), _ => info!("WlanSetPASS FAIL"),
_ if n < length => pass_bytes[n] as u16,
_ => 0 as u16,
};
com.txrx(word);
} }
} }
Some(Opcode::WlanJoin) => { Some(Opcode::WlanJoin) => {