Revert "Revert "uwb(hal): Implement UCI over serial in the defau..."
Revert submission 2528605-revert-2215484-pica_cf-BZDQSZLKEP
Reason for revert: revert^2
Reverted changes: /q/submissionid:2528605-revert-2215484-pica_cf-BZDQSZLKEP
Change-Id: I0c64b449c5da236a7cd63f88a605d48b9c471c67
diff --git a/uwb/aidl/default/src/uwb.rs b/uwb/aidl/default/src/uwb.rs
new file mode 100644
index 0000000..428f08f
--- /dev/null
+++ b/uwb/aidl/default/src/uwb.rs
@@ -0,0 +1,53 @@
+use android_hardware_uwb::aidl::android::hardware::uwb::{IUwb, IUwbChip};
+use android_hardware_uwb::binder;
+use binder::{Result, Strong};
+use binder_tokio::TokioRuntime;
+use tokio::runtime::Handle as TokioHandle;
+
+use crate::uwb_chip;
+
+pub struct Uwb {
+ chips: Vec<Strong<dyn IUwbChip::IUwbChip>>,
+}
+
+impl Uwb {
+ pub fn from_chips(
+ chips: impl IntoIterator<Item = uwb_chip::UwbChip>,
+ handle: TokioHandle,
+ ) -> Self {
+ Self {
+ chips: chips
+ .into_iter()
+ .map(|chip| {
+ IUwbChip::BnUwbChip::new_async_binder(
+ chip,
+ TokioRuntime(handle.clone()),
+ binder::BinderFeatures::default(),
+ )
+ })
+ .collect(),
+ }
+ }
+}
+
+impl binder::Interface for Uwb {}
+
+impl IUwb::IUwb for Uwb {
+ fn getChips(&self) -> Result<Vec<String>> {
+ log::debug!("getChips");
+ self.chips.iter().map(|chip| chip.getName()).collect()
+ }
+
+ fn getChip(&self, name: &str) -> Result<Strong<dyn IUwbChip::IUwbChip>> {
+ log::debug!("getChip {}", name);
+ let chip = self
+ .chips
+ .iter()
+ .find(|chip| chip.getName().as_deref() == Ok(name));
+ if let Some(chip) = chip {
+ Ok(chip.clone())
+ } else {
+ Err(binder::ExceptionCode::ILLEGAL_ARGUMENT.into())
+ }
+ }
+}