aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Android.bp2
-rw-r--r--Cargo.lock10
-rw-r--r--Cargo.toml6
-rw-r--r--METADATA4
-rw-r--r--build.rs2
-rw-r--r--src/bin/http-server/main.rs19
-rw-r--r--src/bin/main.rs4
-rw-r--r--src/device.rs24
-rw-r--r--src/lib.rs23
-rw-r--r--src/session.rs4
10 files changed, 56 insertions, 42 deletions
diff --git a/Android.bp b/Android.bp
index 42d3c8b..19bdfb5 100644
--- a/Android.bp
+++ b/Android.bp
@@ -17,7 +17,7 @@ license {
genrule {
name: "libpica_uci_packets",
- defaults: ["pdl_rust_generator_defaults"],
+ defaults: ["pdl_rust_legacy_generator_defaults"],
srcs: ["src/uci_packets.pdl"],
out: ["uci_packets.rs"],
}
diff --git a/Cargo.lock b/Cargo.lock
index 353f8fd..2afdffa 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -491,9 +491,9 @@ checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee"
[[package]]
name = "pdl-compiler"
-version = "0.2.3"
+version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d277c9e6a1869e95522f9bd532bc225f85c03434b48cd914524235910f9ccdbe"
+checksum = "6853e3b47aa4a5be1287e9115d6fae9b3118971eba855f4d60323d19a66c07cf"
dependencies = [
"argh",
"codespan-reporting",
@@ -510,9 +510,9 @@ dependencies = [
[[package]]
name = "pdl-runtime"
-version = "0.2.3"
+version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ce05e0a116b0250bb41732e2858eada706aebdf311d7f832898c9256bb442abe"
+checksum = "a8684812e36689336c83de6033669573b33b6e59c831145ee496c38a71ed0d7c"
dependencies = [
"bytes",
"thiserror",
@@ -565,7 +565,7 @@ dependencies = [
[[package]]
name = "pica"
-version = "0.1.9"
+version = "0.1.11"
dependencies = [
"anyhow",
"bytes",
diff --git a/Cargo.toml b/Cargo.toml
index 3130ef2..24feebe 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "pica"
-version = "0.1.9"
+version = "0.1.11"
edition = "2021"
description = "Pica is a virtual UWB Controller implementing the FiRa UCI specification."
repository = "https://github.com/google/pica"
@@ -41,7 +41,7 @@ default = ["web"]
web = ["hyper", "tokio/rt-multi-thread"]
[build-dependencies]
-pdl-compiler = "0.2.3"
+pdl-compiler = "0.3.0"
[dependencies]
anyhow = "1.0.56"
@@ -55,7 +55,7 @@ log = "0.4.17"
env_logger = { version = "0.10.0", default-features = false }
num-derive = "0.3.3"
num-traits = "0.2.17"
-pdl-runtime = "0.2.2"
+pdl-runtime = "0.3.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror = "1.0.49"
diff --git a/METADATA b/METADATA
index 46cbcbf..b94f89c 100644
--- a/METADATA
+++ b/METADATA
@@ -12,7 +12,7 @@ third_party {
type: GIT
value: "https://github.com/google/pica.git"
}
- version: "v0.1.9"
+ version: "v0.1.11"
license_type: NOTICE
- last_upgrade_date { year: 2024 month: 4 day: 5 }
+ last_upgrade_date { year: 2024 month: 6 day: 3 }
}
diff --git a/build.rs b/build.rs
index 3535d03..c99bdd8 100644
--- a/build.rs
+++ b/build.rs
@@ -39,7 +39,7 @@ fn generate_module(in_file: &Path) {
)
.expect("PDL parse failed");
let analyzed_file = pdl_compiler::analyzer::analyze(&parsed_file).expect("PDL analysis failed");
- let rust_source = pdl_compiler::backends::rust::generate(&sources, &analyzed_file);
+ let rust_source = pdl_compiler::backends::rust_legacy::generate(&sources, &analyzed_file);
out_file
.write_all(rust_source.as_bytes())
.expect("Could not write to output file");
diff --git a/src/bin/http-server/main.rs b/src/bin/http-server/main.rs
index 0882661..e248040 100644
--- a/src/bin/http-server/main.rs
+++ b/src/bin/http-server/main.rs
@@ -356,21 +356,12 @@ impl pica::RangingEstimator for Context {
&self,
left: &pica::Handle,
right: &pica::Handle,
- ) -> anyhow::Result<pica::RangingMeasurement> {
- let devices = self
- .devices
- .lock()
- .map_err(|_| anyhow::anyhow!("cannot take lock"))?;
- let left_pos = devices
- .get(left)
- .ok_or(anyhow::anyhow!("unknown position"))?
- .position;
- let right_pos = devices
- .get(right)
- .ok_or(anyhow::anyhow!("unknown position"))?
- .position;
+ ) -> Option<pica::RangingMeasurement> {
+ let devices = self.devices.lock().ok()?;
+ let left_pos = devices.get(left)?.position;
+ let right_pos = devices.get(right)?.position;
let (range, azimuth, elevation) = left_pos.compute_range_azimuth_elevation(&right_pos);
- Ok(pica::RangingMeasurement {
+ Some(pica::RangingMeasurement {
range,
azimuth,
elevation,
diff --git a/src/bin/main.rs b/src/bin/main.rs
index 205550e..96ffe6c 100644
--- a/src/bin/main.rs
+++ b/src/bin/main.rs
@@ -67,8 +67,8 @@ impl pica::RangingEstimator for MockRangingEstimator {
&self,
_left: &pica::Handle,
_right: &pica::Handle,
- ) -> Result<pica::RangingMeasurement> {
- Err(anyhow::anyhow!("position not available"))
+ ) -> Option<pica::RangingMeasurement> {
+ Some(Default::default())
}
}
diff --git a/src/device.rs b/src/device.rs
index eec1c7f..62f3ffc 100644
--- a/src/device.rs
+++ b/src/device.rs
@@ -19,6 +19,7 @@ use crate::PicaCommand;
use std::collections::HashMap;
use std::time::Duration;
+use pdl_runtime::Packet;
use tokio::sync::mpsc;
use tokio::time;
@@ -142,8 +143,13 @@ impl Device {
let tx = self.tx.clone();
tokio::spawn(async move {
time::sleep(Duration::from_millis(5)).await;
- tx.send(CoreDeviceStatusNtfBuilder { device_state }.build().into())
- .unwrap()
+ tx.send(
+ CoreDeviceStatusNtfBuilder { device_state }
+ .build()
+ .encode_to_vec()
+ .unwrap(),
+ )
+ .unwrap()
});
}
@@ -194,8 +200,13 @@ impl Device {
}
// Send a response or notification to the Host.
- fn send_control(&mut self, packet: impl Into<Vec<u8>>) {
- let _ = self.tx.send(packet.into());
+ fn send_raw_control(&mut self, packet: Vec<u8>) {
+ let _ = self.tx.send(packet);
+ }
+
+ // Send a response or notification to the Host.
+ fn send_control(&mut self, packet: impl Packet) {
+ self.send_raw_control(packet.encode_to_vec().unwrap());
}
// The fira norm specify to send a response, then reset, then
@@ -753,7 +764,8 @@ impl Device {
session_token: session_handle,
}
.build()
- .into(),
+ .encode_to_vec()
+ .unwrap(),
)
.unwrap()
});
@@ -1050,7 +1062,7 @@ impl Device {
1,
status.into(),
];
- self.send_control(response)
+ self.send_raw_control(response)
}
// Parsing success, ignore non command packets.
diff --git a/src/lib.rs b/src/lib.rs
index 17ad1c2..ef9fdd6 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -13,6 +13,7 @@
// limitations under the License.
use anyhow::Result;
+use pdl_runtime::Packet;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::fmt::Display;
@@ -62,7 +63,9 @@ pub trait RangingEstimator: Send + Sync {
/// identified by their respective handle. The result is a triplet
/// containing the range, azimuth, and elevation of the right device
/// relative to the left device.
- fn estimate(&self, left: &Handle, right: &Handle) -> Result<RangingMeasurement>;
+ /// Return `None` if the measurement could not be estimated, e.g. because
+ /// the devices are out of range.
+ fn estimate(&self, left: &Handle, right: &Handle) -> Option<RangingMeasurement>;
}
/// Pica emulation environment.
@@ -413,14 +416,18 @@ impl Pica {
// Look for compatible anchors.
for mac_address in session.get_dst_mac_address() {
if let Some(other) = self.anchors.get(mac_address) {
- let local = self
+ let Some(local) = self
.ranging_estimator
.estimate(&device.handle, &other.handle)
- .unwrap_or(Default::default());
- let remote = self
+ else {
+ continue;
+ };
+ let Some(remote) = self
.ranging_estimator
.estimate(&other.handle, &device.handle)
- .unwrap_or(Default::default());
+ else {
+ continue;
+ };
measurements.push(make_measurement(mac_address, local, remote));
}
}
@@ -471,7 +478,8 @@ impl Pica {
status: uci::Status::Ok,
}
.build()
- .into(),
+ .encode_to_vec()
+ .unwrap(),
)
.unwrap();
}
@@ -489,7 +497,8 @@ impl Pica {
vendor_data: vec![],
}
.build()
- .into(),
+ .encode_to_vec()
+ .unwrap(),
)
.unwrap();
diff --git a/src/session.rs b/src/session.rs
index 2ee656a..e31a262 100644
--- a/src/session.rs
+++ b/src/session.rs
@@ -19,6 +19,7 @@
use crate::packets::uci::{self, *};
use crate::{AppConfig, MacAddress};
use bytes::BytesMut;
+use pdl_runtime::Packet;
use std::time::Duration;
use tokio::sync::mpsc;
use tokio::task::JoinHandle;
@@ -80,7 +81,8 @@ impl Session {
reason_code: reason_code.into(),
}
.build()
- .into(),
+ .encode_to_vec()
+ .unwrap(),
)
.unwrap()
});