Skip to content

Commit

Permalink
(feature): Add simple activate if module already have config (#71)
Browse files Browse the repository at this point in the history
* add simple activate if module already have config

* Disconnect no matter what wifistate is
  • Loading branch information
KennethKnudsen97 authored Dec 4, 2023
1 parent bd2c71b commit 9d50af1
Showing 1 changed file with 59 additions and 17 deletions.
76 changes: 59 additions & 17 deletions ublox-short-range/src/wifi/sta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,17 @@ where
Ok(())
}

pub fn activate(&mut self) -> Result<(), WifiConnectionError> {
self.send_internal(
&EdmAtCmdWrapper(ExecWifiStationAction {
config_id: CONFIG_ID,
action: WifiStationAction::Activate,
}),
true,
)?;
return Ok(());

Check warning on line 149 in ublox-short-range/src/wifi/sta.rs

View workflow job for this annotation

GitHub Actions / clippy

unneeded `return` statement

warning: unneeded `return` statement --> ublox-short-range/src/wifi/sta.rs:149:9 | 149 | return Ok(()); | ^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return = note: `#[warn(clippy::needless_return)]` on by default help: remove `return` | 149 - return Ok(()); 149 + Ok(()) |
}

pub fn scan(&mut self) -> Result<Vec<WifiNetwork, 32>, WifiError> {
match self.send_internal(&EdmAtCmdWrapper(WifiScan { ssid: None }), true) {
Ok(resp) => resp
Expand All @@ -160,25 +171,56 @@ where
.unwrap_or_default()
}

pub fn disconnect(&mut self) -> Result<(), WifiConnectionError> {
if let Some(con) = self.wifi_connection.take() {
match con.wifi_state {
WiFiState::Connected | WiFiState::NotConnected => {
defmt::debug!("Disconnecting from {:?}", con.network.ssid);
// con.wifi_state = WiFiState::Inactive;
self.send_internal(
&EdmAtCmdWrapper(ExecWifiStationAction {
config_id: CONFIG_ID,
action: WifiStationAction::Deactivate,
}),
true,
)?;
}
WiFiState::Inactive => {}
pub fn is_active_on_startup(&mut self) -> Result<bool, WifiConnectionError> {
if let Ok(resp) = self.send_internal(
&EdmAtCmdWrapper(GetWifiStationConfig {
config_id: CONFIG_ID,
parameter: Some(WifiStationConfigParameter::ActiveOnStartup),
}),
false,
) {
if let WifiStationConfigR::ActiveOnStartup(active) = resp.parameter {
return Ok(active == OnOff::On);
}
} else {
return Err(WifiConnectionError::FailedToDisconnect);
}
Err(WifiConnectionError::Illegal)
}

pub fn get_ssid(&mut self) -> Result<heapless::String<64>, WifiConnectionError> {
if let Ok(resp) = self.send_internal(
&EdmAtCmdWrapper(GetWifiStationConfig {
config_id: CONFIG_ID,
parameter: Some(WifiStationConfigParameter::SSID),
}),
false,
) {
if let WifiStationConfigR::SSID(ssid) = resp.parameter {
return Ok(ssid);
}
};
return Err(WifiConnectionError::Illegal);

Check warning on line 201 in ublox-short-range/src/wifi/sta.rs

View workflow job for this annotation

GitHub Actions / clippy

unneeded `return` statement

warning: unneeded `return` statement --> ublox-short-range/src/wifi/sta.rs:201:9 | 201 | return Err(WifiConnectionError::Illegal); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return help: remove `return` | 201 - return Err(WifiConnectionError::Illegal); 201 + Err(WifiConnectionError::Illegal) |
}

pub fn reset_config_profile(&mut self) -> Result<(), WifiConnectionError> {
self.send_internal(
&EdmAtCmdWrapper(ExecWifiStationAction {
config_id: CONFIG_ID,
action: WifiStationAction::Reset,
}),
false,
)?;
Ok(())
}

pub fn disconnect(&mut self) -> Result<(), WifiConnectionError> {
defmt::debug!("Disconnecting");
self.send_internal(
&EdmAtCmdWrapper(ExecWifiStationAction {
config_id: CONFIG_ID,
action: WifiStationAction::Deactivate,
}),
true,
)?;
Ok(())
}
}

0 comments on commit 9d50af1

Please sign in to comment.