Skip to content

Commit

Permalink
Fix defmt feature gating
Browse files Browse the repository at this point in the history
  • Loading branch information
MathiasKoch committed Jul 18, 2024
1 parent e9e0dff commit 0b88cc0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 43 deletions.
52 changes: 27 additions & 25 deletions src/asynch/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ impl<'a, const INGRESS_BUF_SIZE: usize, const URC_CAPACITY: usize>
Ok(())
}

async fn start_ap(&self, ssid: &str) -> Result<(), Error> {
async fn start_ap(&self, ssid: &str, _channel: u8) -> Result<(), Error> {
self.state_ch.wait_for_initialized().await;

// Deactivate network id 0
Expand Down Expand Up @@ -432,13 +432,18 @@ impl<'a, const INGRESS_BUF_SIZE: usize, const URC_CAPACITY: usize>
}

/// Start open access point.
pub async fn start_ap_open(&mut self, ssid: &str, channel: u8) {
todo!()
pub async fn start_ap_open(&mut self, ssid: &str, channel: u8) -> Result<(), Error> {
self.start_ap(ssid, channel).await
}

/// Start WPA2 protected access point.
pub async fn start_ap_wpa2(&mut self, ssid: &str, passphrase: &str, channel: u8) {
todo!()
pub async fn start_ap_wpa2(
&mut self,
ssid: &str,
_passphrase: &str,
channel: u8,
) -> Result<(), Error> {
self.start_ap(ssid, channel).await
}

/// Closes access point.
Expand Down Expand Up @@ -477,9 +482,7 @@ impl<'a, const INGRESS_BUF_SIZE: usize, const URC_CAPACITY: usize>
(&self.at_client)
.send_retry(&SetWifiStationConfig {
config_id: CONFIG_ID,
config_param: WifiStationConfig::SSID(
heapless::String::try_from(ssid).map_err(|_| Error::Overflow)?,
),
config_param: WifiStationConfig::SSID(ssid),
})
.await?;

Expand All @@ -503,26 +506,25 @@ impl<'a, const INGRESS_BUF_SIZE: usize, const URC_CAPACITY: usize>
(&self.at_client)
.send_retry(&SetWifiStationConfig {
config_id: CONFIG_ID,
config_param: WifiStationConfig::WpaPskOrPassphrase(
heapless::String::try_from(passphrase).map_err(|_| Error::Overflow)?,
),
config_param: WifiStationConfig::WpaPskOrPassphrase(passphrase),
})
.await?;
}
WifiAuthentication::Wpa2Psk(psk) => {
(&self.at_client)
.send_retry(&SetWifiStationConfig {
config_id: CONFIG_ID,
config_param: WifiStationConfig::Authentication(Authentication::WpaWpa2Psk),
})
.await?;

(&self.at_client)
.send_retry(&SetWifiStationConfig {
config_id: CONFIG_ID,
config_param: WifiStationConfig::WpaPskOrPassphrase(todo!("hex values?!")),
})
.await?;
WifiAuthentication::Wpa2Psk(_psk) => {
unimplemented!()
// (&self.at_client)
// .send_retry(&SetWifiStationConfig {
// config_id: CONFIG_ID,
// config_param: WifiStationConfig::Authentication(Authentication::WpaWpa2Psk),
// })
// .await?;

// (&self.at_client)
// .send_retry(&SetWifiStationConfig {
// config_id: CONFIG_ID,
// config_param: WifiStationConfig::WpaPskOrPassphrase(todo!("hex values?!")),
// })
// .await?;
}
}

Expand Down
33 changes: 18 additions & 15 deletions src/command/wifi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,29 @@ impl<'a> atat::AtatLen for SetWifiStationConfig<'a> {
const ATAT_SETWIFISTATIONCONFIG_LEN: usize =
<WifiStationConfig<'_> as atat::AtatLen>::LEN + <u8 as atat::AtatLen>::LEN + 1usize;
#[automatically_derived]
impl<'a> atat::AtatCmd<{ ATAT_SETWIFISTATIONCONFIG_LEN + 12usize }> for SetWifiStationConfig<'a> {
impl<'a> atat::AtatCmd for SetWifiStationConfig<'a> {
type Response = NoResponse;
const MAX_TIMEOUT_MS: u32 = 1000u32;
#[inline]
fn as_bytes(&self) -> atat::heapless::Vec<u8, { ATAT_SETWIFISTATIONCONFIG_LEN + 12usize }> {
match atat::serde_at::to_vec(
fn parse(
&self,
res: Result<&[u8], atat::InternalError>,
) -> core::result::Result<Self::Response, atat::Error> {
match res {
Ok(resp) => {
atat::serde_at::from_slice::<NoResponse>(resp).map_err(|_e| atat::Error::Parse)
}
Err(e) => Err(e.into()),
}
}

const MAX_LEN: usize = ATAT_SETWIFISTATIONCONFIG_LEN + 12usize;

fn write(&self, buf: &mut [u8]) -> usize {
match atat::serde_at::to_slice(
self,
"+UWSC",
buf,
atat::serde_at::SerializeOptions {
value_sep: true,
cmd_prefix: "AT",
Expand All @@ -53,18 +68,6 @@ impl<'a> atat::AtatCmd<{ ATAT_SETWIFISTATIONCONFIG_LEN + 12usize }> for SetWifiS
Err(_) => panic!("Failed to serialize command"),
}
}
#[inline]
fn parse(
&self,
res: Result<&[u8], atat::InternalError>,
) -> core::result::Result<Self::Response, atat::Error> {
match res {
Ok(resp) => {
atat::serde_at::from_slice::<NoResponse>(resp).map_err(|e| atat::Error::Parse)
}
Err(e) => Err(e.into()),
}
}
}
#[automatically_derived]
impl<'a> atat::serde_at::serde::Serialize for SetWifiStationConfig<'a> {
Expand Down
4 changes: 3 additions & 1 deletion src/command/wifi/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,14 +426,16 @@ pub enum WifiStationAction {
Deactivate = 4,
}

#[derive(Debug, Clone, PartialEq, AtatEnum, defmt::Format)]
#[derive(Debug, Clone, PartialEq, AtatEnum)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[repr(u8)]
pub enum OperationMode {
Infrastructure = 1,
AdHoc = 2,
}

#[derive(Clone, PartialEq, AtatEnum)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[repr(u8)]
pub enum StatusId {
SSID = 0,
Expand Down
5 changes: 3 additions & 2 deletions src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ pub enum WifiMode {
AccessPoint,
}

#[derive(Debug, defmt::Format)]
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct WifiNetwork {
#[defmt(Debug2Format)]
#[cfg_attr(feature = "defmt", defmt(Debug2Format))]
pub bssid: Bytes<20>,
pub op_mode: OperationMode,
pub ssid: String<64>,
Expand Down

0 comments on commit 0b88cc0

Please sign in to comment.