sl4f_lib/wlan_phy/
facade.rsuse anyhow::{format_err, Context, Error};
use fidl_fuchsia_wlan_device_service::{DeviceMonitorMarker, DeviceMonitorProxy};
use fuchsia_component::client::connect_to_protocol;
#[derive(Debug)]
pub struct WlanPhyFacade {
device_monitor: DeviceMonitorProxy,
}
impl WlanPhyFacade {
pub fn new() -> Result<WlanPhyFacade, Error> {
Ok(WlanPhyFacade { device_monitor: connect_to_protocol::<DeviceMonitorMarker>()? })
}
pub async fn get_country(&self, phy_id: u16) -> Result<[u8; 2], Error> {
let country_code = self
.device_monitor
.get_country(phy_id)
.await
.context("get_country(): encountered FIDL error")?;
match country_code {
Ok(country) => Ok(country.alpha2),
Err(status) => Err(format_err!(
"get_country(): encountered service failure {}",
zx::Status::from_raw(status)
)),
}
}
pub async fn get_dev_path(&self, phy_id: u16) -> Result<Option<String>, Error> {
self.device_monitor
.get_dev_path(phy_id)
.await
.map_err(|e| format_err!("get_path(): encountered FIDL error: {:?}", e))
}
}