diff options
author | Hyun Jae Moon <hyunjaemoon@google.com> | 2023-04-19 23:51:24 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-04-19 23:51:24 +0000 |
commit | f0c4fb9f12deaf2150dfb08a4e833b36e21e5074 (patch) | |
tree | 2b16f3c490e174b54f484c418936a397acd840ca | |
parent | 1abbea137d357614b636cd2379a2936f6e98d7af (diff) | |
parent | c94195a9127314edbea582e4b94434fa96ce3e5a (diff) | |
download | netsim-f0c4fb9f12deaf2150dfb08a4e833b36e21e5074.tar.gz |
Merge "Surface devices module in netsim-cxx for testing in presubmit" am: c94195a912
Original change: https://android-review.googlesource.com/c/platform/tools/netsim/+/2549490
Change-Id: I3101d30515eab7ace1697c2eac9cffb65b22bc47
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | rust/netsim-cxx/src/devices/chip.rs | 20 | ||||
-rw-r--r-- | rust/netsim-cxx/src/devices/device.rs | 22 | ||||
-rw-r--r-- | rust/netsim-cxx/src/devices/devices_handler.rs | 51 | ||||
-rw-r--r-- | rust/netsim-cxx/src/devices/facades.rs | 18 | ||||
-rw-r--r-- | rust/netsim-cxx/src/devices/id_factory.rs | 14 | ||||
-rw-r--r-- | rust/netsim-cxx/src/devices/mod.rs | 14 | ||||
-rw-r--r-- | rust/netsim-cxx/src/lib.rs | 1 |
7 files changed, 108 insertions, 32 deletions
diff --git a/rust/netsim-cxx/src/devices/chip.rs b/rust/netsim-cxx/src/devices/chip.rs index 7c0b251a..29827392 100644 --- a/rust/netsim-cxx/src/devices/chip.rs +++ b/rust/netsim-cxx/src/devices/chip.rs @@ -1,3 +1,17 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + /// A Chip is a generic emulated radio that connects to Chip Facade /// library. /// @@ -6,9 +20,9 @@ use crate::devices::facades::FacadeIdentifier; use crate::devices::facades::*; use crate::devices::id_factory::IdFactory; -use crate::proto::common::ChipKind as ProtoChipKind; -use crate::proto::model::Chip as ProtoChip; -use crate::proto::model::State as ProtoState; +use frontend_proto::common::ChipKind as ProtoChipKind; +use frontend_proto::model::Chip as ProtoChip; +use frontend_proto::model::State as ProtoState; use lazy_static::lazy_static; use protobuf::EnumOrUnknown; diff --git a/rust/netsim-cxx/src/devices/device.rs b/rust/netsim-cxx/src/devices/device.rs index 0d20b89f..57b07099 100644 --- a/rust/netsim-cxx/src/devices/device.rs +++ b/rust/netsim-cxx/src/devices/device.rs @@ -1,3 +1,17 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + // Device.rs use protobuf::Message; @@ -6,10 +20,10 @@ use crate::devices::chip; use crate::devices::chip::Chip; use crate::devices::chip::ChipIdentifier; use crate::devices::facades::FacadeIdentifier; -use crate::proto::common::ChipKind as ProtoChipKind; -use crate::proto::model::Device as ProtoDevice; -use crate::proto::model::Orientation as ProtoOrientation; -use crate::proto::model::Position as ProtoPosition; +use frontend_proto::common::ChipKind as ProtoChipKind; +use frontend_proto::model::Device as ProtoDevice; +use frontend_proto::model::Orientation as ProtoOrientation; +use frontend_proto::model::Position as ProtoPosition; use std::collections::HashMap; pub type DeviceIdentifier = i32; diff --git a/rust/netsim-cxx/src/devices/devices_handler.rs b/rust/netsim-cxx/src/devices/devices_handler.rs index 12b47252..f103db2d 100644 --- a/rust/netsim-cxx/src/devices/devices_handler.rs +++ b/rust/netsim-cxx/src/devices/devices_handler.rs @@ -1,3 +1,17 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + // devices_handler.rs // // Provides the API for the frontend and backend to interact with devices. @@ -13,10 +27,10 @@ use super::device::DeviceIdentifier; use super::id_factory::IdFactory; use crate::devices::device::AddChipResult; use crate::devices::device::Device; -use crate::proto::common::ChipKind as ProtoChipKind; -use crate::proto::model::Device as ProtoDevice; -use crate::proto::model::Position as ProtoPosition; -use crate::proto::model::Scene as ProtoScene; +use frontend_proto::common::ChipKind as ProtoChipKind; +use frontend_proto::model::Device as ProtoDevice; +use frontend_proto::model::Position as ProtoPosition; +use frontend_proto::model::Scene as ProtoScene; use lazy_static::lazy_static; use protobuf_json_mapping::merge_from_str; use protobuf_json_mapping::print_to_string; @@ -147,11 +161,8 @@ fn patch_device(id: DeviceIdentifier, patch_json: &str) { } } -impl ProtoPosition { - fn distance(&self, other: &Self) -> f32 { - ((other.x - self.x).powf(2.0) + (other.y - self.y).powf(2.0) + (other.z - self.z).powf(2.0)) - .sqrt() - } +fn distance(a: &ProtoPosition, b: &ProtoPosition) -> f32 { + ((b.x - a.x).powf(2.0) + (b.y - a.y).powf(2.0) + (b.z - a.z).powf(2.0)).sqrt() } #[allow(dead_code)] @@ -167,7 +178,7 @@ pub fn get_distance(id: DeviceIdentifier, other_id: DeviceIdentifier) -> f32 { None }); match (a, b) { - (Some(a), Some(b)) => a.distance(&b), + (Some(a), Some(b)) => distance(&a, &b), _ => 0.0, } } @@ -212,23 +223,17 @@ fn get_secs_until_idle_shutdown() -> Option<u32> { mod tests { use super::*; - impl ProtoPosition { - fn new_with_xyz(x: f32, y: f32, z: f32) -> Self { - let mut p = ProtoPosition::new(); - p.x = x; - p.y = y; - p.z = z; - p - } + fn new_with_xyz(x: f32, y: f32, z: f32) -> ProtoPosition { + ProtoPosition { x, y, z, ..Default::default() } } #[test] fn test_distance() { // Pythagorean quadruples - let a = ProtoPosition::new_with_xyz(0.0, 0.0, 0.0); - let mut b = ProtoPosition::new_with_xyz(1.0, 2.0, 2.0); - assert_eq!(a.distance(&b), 3.0); - b = ProtoPosition::new_with_xyz(2.0, 3.0, 6.0); - assert_eq!(a.distance(&b), 7.0); + let a = new_with_xyz(0.0, 0.0, 0.0); + let mut b = new_with_xyz(1.0, 2.0, 2.0); + assert_eq!(distance(&a, &b), 3.0); + b = new_with_xyz(2.0, 3.0, 6.0); + assert_eq!(distance(&a, &b), 7.0); } } diff --git a/rust/netsim-cxx/src/devices/facades.rs b/rust/netsim-cxx/src/devices/facades.rs index 802ac6ee..27c62928 100644 --- a/rust/netsim-cxx/src/devices/facades.rs +++ b/rust/netsim-cxx/src/devices/facades.rs @@ -1,5 +1,19 @@ -use crate::proto::model::chip::Bluetooth as ProtoBluetoothChip; -use crate::proto::model::chip::Radio as ProtoRadioChip; +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use frontend_proto::model::chip::Bluetooth as ProtoBluetoothChip; +use frontend_proto::model::chip::Radio as ProtoRadioChip; use super::device::DeviceIdentifier; diff --git a/rust/netsim-cxx/src/devices/id_factory.rs b/rust/netsim-cxx/src/devices/id_factory.rs index 1ba41239..554cf2f5 100644 --- a/rust/netsim-cxx/src/devices/id_factory.rs +++ b/rust/netsim-cxx/src/devices/id_factory.rs @@ -1,3 +1,17 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + /// A factory for generating typed identifiers. /// use std::ops::Add; diff --git a/rust/netsim-cxx/src/devices/mod.rs b/rust/netsim-cxx/src/devices/mod.rs index 5da3da78..94f7b6ac 100644 --- a/rust/netsim-cxx/src/devices/mod.rs +++ b/rust/netsim-cxx/src/devices/mod.rs @@ -1,3 +1,17 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + pub mod chip; pub mod device; pub mod devices_handler; diff --git a/rust/netsim-cxx/src/lib.rs b/rust/netsim-cxx/src/lib.rs index 06e363c4..22cb7c92 100644 --- a/rust/netsim-cxx/src/lib.rs +++ b/rust/netsim-cxx/src/lib.rs @@ -17,6 +17,7 @@ #![allow(dead_code)] mod captures; +mod devices; mod http_server; mod ranging; mod transport; |