add a wifi retry to the oqc test

This commit is contained in:
bunnie 2021-10-29 05:25:40 +08:00
parent 651a05195f
commit 2962d4ffc3

View file

@ -461,32 +461,58 @@ impl<'a> ShellCmdApi<'a> for Test {
} }
} }
} }
if let Ok(msg) = env.com.wlan_status() { // re-connect to the network, if things didn't work in the first place
let mut elements = msg.as_str().unwrap().split(' '); let mut net_up = false;
let rssi_pass = if let Some(_rssi_str) = elements.next() { let mut dhcp_ok = false;
//rssi_str.parse::<i32>().unwrap() < -10 let mut ssid_ok = false;
// for now always pass, don't use RSSI as it's not reliable let mut rssi_pass = false;
true let mut wifi_tries = 0;
loop {
// parse and see if we connected from the first attempt (called before this loop)
if let Ok(msg) = env.com.wlan_status() {
let mut elements = msg.as_str().unwrap().split(' ');
rssi_pass = if let Some(_rssi_str) = elements.next() {
//rssi_str.parse::<i32>().unwrap() < -10
// for now always pass, don't use RSSI as it's not reliable
true
} else {
false
};
net_up = if let Some(up_str) = elements.next() {
up_str == "up"
} else {
false
};
dhcp_ok = if let Some(dhcp_str) = elements.next() {
dhcp_str == "dhcpBound"
} else {
false
};
ssid_ok = if let Some(ssid_str) = elements.next() {
ssid_str == "\nprecursortest"
} else {
false
};
// if connected, break
if rssi_pass && net_up && dhcp_ok && ssid_ok {
write!(ret, "WLAN OK: {}\n", msg.as_str().unwrap()).unwrap();
break;
} else {
write!(ret, "WLAN TRY: {}", msg.as_str().unwrap()).unwrap();
}
} else { } else {
false write!(ret, "WLAN TRY: Couldn't get status!\n").unwrap();
}; }
let net_up = if let Some(up_str) = elements.next() { if wifi_tries < 3 {
up_str == "up" // else retry the connection sequence -- leave, ssid, pass, join. takes some time.
} else { env.com.wlan_leave().unwrap();
false env.ticktimer.sleep_ms(2000).unwrap();
}; env.com.wlan_set_ssid(&String::<1024>::from_str("precursortest")).unwrap();
let dhcp_ok = if let Some(dhcp_str) = elements.next() { env.ticktimer.sleep_ms(800).unwrap();
dhcp_str == "dhcpBound" env.com.wlan_set_pass(&String::<1024>::from_str("notasecret")).unwrap();
} else { env.ticktimer.sleep_ms(800).unwrap();
false env.com.wlan_join().unwrap();
}; env.ticktimer.sleep_ms(8000).unwrap();
let ssid_ok = if let Some(ssid_str) = elements.next() {
ssid_str == "\nprecursortest"
} else {
false
};
if rssi_pass && net_up && dhcp_ok && ssid_ok {
write!(ret, "WLAN OK: {}\n", msg.as_str().unwrap()).unwrap();
} else { } else {
if !rssi_pass { if !rssi_pass {
write!(ret, "WLAN FAIL: rssi weak\n").unwrap(); write!(ret, "WLAN FAIL: rssi weak\n").unwrap();
@ -500,12 +526,9 @@ impl<'a> ShellCmdApi<'a> for Test {
if !ssid_ok { if !ssid_ok {
write!(ret, "WLAN FAIL: ssid mismatch\n").unwrap(); write!(ret, "WLAN FAIL: ssid mismatch\n").unwrap();
} }
write!(ret, "{}", msg.as_str().unwrap()).unwrap();
return Ok(Some(ret)); return Ok(Some(ret));
} }
} else { wifi_tries += 1;
write!(ret, "FAIL: Couldn't connect to test wifi network!\n").unwrap();
return Ok(Some(ret));
} }
AUDIO_OQC.store(true, Ordering::Relaxed); AUDIO_OQC.store(true, Ordering::Relaxed);