merge from upstream/master into main at 2023-07-05T10:11:32.265094Z
Change-Id: I4e819d0e016ff727e246cc7c26b06f88a4c2c01f
diff --git a/src/Android.bp b/src/Android.bp
index 4c59eab..193ac98 100755
--- a/src/Android.bp
+++ b/src/Android.bp
@@ -198,7 +198,7 @@
":include_uwb_core_proto",
],
rustlibs: [
- "libprotobuf_deprecated",
+ "libprotobuf",
],
features: ["proto"],
host_supported: true,
@@ -206,11 +206,11 @@
genrule {
name: "gen_uwb_core_proto",
- tools: ["aprotoc", "protoc-gen-rust-deprecated"],
+ tools: ["aprotoc", "protoc-gen-rust"],
cmd: "$(location aprotoc)" +
" --proto_path=`dirname $(in)`" +
" --dependency_out=$(depfile)" +
- " --plugin=protoc-gen-rust=$(location protoc-gen-rust-deprecated)" +
+ " --plugin=protoc-gen-rust=$(location protoc-gen-rust)" +
" --rust_out=$(genDir) $(in)",
srcs: [
"rust/uwb_core/protos/uwb_service.proto",
diff --git a/src/rust/uwb_core/protos/uwb_service.proto b/src/rust/uwb_core/protos/uwb_service.proto
index 72cd879..e13765e 100644
--- a/src/rust/uwb_core/protos/uwb_service.proto
+++ b/src/rust/uwb_core/protos/uwb_service.proto
@@ -375,7 +375,7 @@
bytes device_mac_address = 6;
repeated bytes dst_mac_address = 7;
uint32 slot_duration_rstu = 8;
- uint32 ranging_interval_ms = 9;
+ uint32 ranging_duration_ms = 9;
MacFcsType mac_fcs_type = 10;
RangingRoundControl ranging_round_control = 11;
AoaResultRequest aoa_result_request = 12;
diff --git a/src/rust/uwb_core/src/params/ccc_app_config_params.rs b/src/rust/uwb_core/src/params/ccc_app_config_params.rs
index ab90d3a..2e8e0ca 100644
--- a/src/rust/uwb_core/src/params/ccc_app_config_params.rs
+++ b/src/rust/uwb_core/src/params/ccc_app_config_params.rs
@@ -73,7 +73,7 @@
match session_state {
SessionState::SessionStateIdle => {
// Only ran_multiplier can be updated at idle state.
- config_map.keys().all(|key| key == &AppConfigTlvType::RangingInterval)
+ config_map.keys().all(|key| key == &AppConfigTlvType::RangingDuration)
}
_ => false,
}
@@ -93,7 +93,7 @@
u16_to_bytes((self.chaps_per_slot as u16) * CHAP_IN_RSTU),
),
(
- AppConfigTlvType::RangingInterval,
+ AppConfigTlvType::RangingDuration,
u32_to_bytes(self.ran_multiplier * MINIMUM_BLOCK_DURATION_MS),
),
(AppConfigTlvType::RngDataNtf, u8_to_bytes(CCC_RANGE_DATA_NTF_CONFIG as u8)),
@@ -329,7 +329,7 @@
(AppConfigTlvType::NoOfControlee, u8_to_bytes(num_responder_nodes)),
(AppConfigTlvType::SlotDuration, u16_to_bytes((chaps_per_slot as u16) * CHAP_IN_RSTU)),
(
- AppConfigTlvType::RangingInterval,
+ AppConfigTlvType::RangingDuration,
u32_to_bytes(ran_multiplier * MINIMUM_BLOCK_DURATION_MS),
),
(AppConfigTlvType::RngDataNtf, u8_to_bytes(CCC_RANGE_DATA_NTF_CONFIG as u8)),
@@ -349,7 +349,7 @@
let updated_ran_multiplier = 5;
assert_ne!(ran_multiplier, updated_ran_multiplier);
let expected_updated_config_map = HashMap::from([(
- AppConfigTlvType::RangingInterval,
+ AppConfigTlvType::RangingDuration,
u32_to_bytes(updated_ran_multiplier * MINIMUM_BLOCK_DURATION_MS),
)]);
diff --git a/src/rust/uwb_core/src/params/ccc_started_app_config_params.rs b/src/rust/uwb_core/src/params/ccc_started_app_config_params.rs
index 18d6002..97039a1 100644
--- a/src/rust/uwb_core/src/params/ccc_started_app_config_params.rs
+++ b/src/rust/uwb_core/src/params/ccc_started_app_config_params.rs
@@ -34,7 +34,7 @@
sts_index: bytes_to_u32(config_map.remove(&AppConfigTlvType::StsIndex)?)?,
hop_mode_key: bytes_to_u32(config_map.remove(&AppConfigTlvType::CccHopModeKey)?)?,
uwb_time0: bytes_to_u64(config_map.remove(&AppConfigTlvType::CccUwbTime0)?)?,
- ran_multiplier: bytes_to_u32(config_map.remove(&AppConfigTlvType::RangingInterval)?)?
+ ran_multiplier: bytes_to_u32(config_map.remove(&AppConfigTlvType::RangingDuration)?)?
/ MINIMUM_BLOCK_DURATION_MS,
sync_code_index: bytes_to_u8(config_map.remove(&AppConfigTlvType::PreambleCodeIndex)?)?,
})
@@ -62,7 +62,7 @@
(AppConfigTlvType::CccHopModeKey, u32_to_bytes(hop_mode_key)),
(AppConfigTlvType::CccUwbTime0, u64_to_bytes(uwb_time0)),
(
- AppConfigTlvType::RangingInterval,
+ AppConfigTlvType::RangingDuration,
u32_to_bytes(ran_multiplier * MINIMUM_BLOCK_DURATION_MS),
),
(AppConfigTlvType::PreambleCodeIndex, u8_to_bytes(sync_code_index)),
diff --git a/src/rust/uwb_core/src/params/fira_app_config_params.rs b/src/rust/uwb_core/src/params/fira_app_config_params.rs
index 880d197..de0321a 100644
--- a/src/rust/uwb_core/src/params/fira_app_config_params.rs
+++ b/src/rust/uwb_core/src/params/fira_app_config_params.rs
@@ -31,7 +31,7 @@
const DEFAULT_STS_CONFIG: StsConfig = StsConfig::Static;
const DEFAULT_CHANNEL_NUMBER: UwbChannel = UwbChannel::Channel9;
const DEFAULT_SLOT_DURATION_RSTU: u16 = 2400;
-const DEFAULT_RANGING_INTERVAL_MS: u32 = 200;
+const DEFAULT_RANGING_DURATION_MS: u32 = 200;
const DEFAULT_MAC_FCS_TYPE: MacFcsType = MacFcsType::Crc16;
const DEFAULT_RANGING_ROUND_CONTROL: RangingRoundControl = RangingRoundControl {
ranging_result_report_message: true,
@@ -86,7 +86,7 @@
device_mac_address: UwbAddress,
dst_mac_address: Vec<UwbAddress>,
slot_duration_rstu: u16,
- ranging_interval_ms: u32,
+ ranging_duration_ms: u32,
mac_fcs_type: MacFcsType,
ranging_round_control: RangingRoundControl,
aoa_result_request: AoaResultRequest,
@@ -143,7 +143,7 @@
.field("device_mac_address", &self.device_mac_address)
.field("dst_mac_address", &self.dst_mac_address)
.field("slot_duration_rstu", &self.slot_duration_rstu)
- .field("ranging_interval_ms", &self.ranging_interval_ms)
+ .field("ranging_duration_ms", &self.ranging_duration_ms)
.field("mac_fcs_type", &self.mac_fcs_type)
.field("ranging_round_control", &self.ranging_round_control)
.field("aoa_result_request", &self.aoa_result_request)
@@ -208,7 +208,7 @@
getter_field!(device_mac_address, UwbAddress);
getter_field!(dst_mac_address, Vec<UwbAddress>);
getter_field!(slot_duration_rstu, u16);
- getter_field!(ranging_interval_ms, u32);
+ getter_field!(ranging_duration_ms, u32);
getter_field!(mac_fcs_type, MacFcsType);
getter_field!(ranging_round_control, RangingRoundControl);
getter_field!(aoa_result_request, AoaResultRequest);
@@ -396,7 +396,7 @@
match session_state {
SessionState::SessionStateActive => {
let avalible_list = HashSet::from([
- AppConfigTlvType::RangingInterval,
+ AppConfigTlvType::RangingDuration,
AppConfigTlvType::RngDataNtf,
AppConfigTlvType::RngDataNtfProximityNear,
AppConfigTlvType::RngDataNtfProximityFar,
@@ -423,7 +423,7 @@
(AppConfigTlvType::DeviceMacAddress, self.device_mac_address.clone().into()),
(AppConfigTlvType::DstMacAddress, addresses_to_bytes(self.dst_mac_address.clone())),
(AppConfigTlvType::SlotDuration, u16_to_bytes(self.slot_duration_rstu)),
- (AppConfigTlvType::RangingInterval, u32_to_bytes(self.ranging_interval_ms)),
+ (AppConfigTlvType::RangingDuration, u32_to_bytes(self.ranging_duration_ms)),
(AppConfigTlvType::MacFcsType, u8_to_bytes(self.mac_fcs_type as u8)),
(
AppConfigTlvType::RangingRoundControl,
@@ -503,7 +503,7 @@
device_mac_address: Option<UwbAddress>,
dst_mac_address: Vec<UwbAddress>,
slot_duration_rstu: u16,
- ranging_interval_ms: u32,
+ ranging_duration_ms: u32,
mac_fcs_type: MacFcsType,
ranging_round_control: RangingRoundControl,
aoa_result_request: AoaResultRequest,
@@ -558,7 +558,7 @@
device_mac_address: None,
dst_mac_address: vec![],
slot_duration_rstu: DEFAULT_SLOT_DURATION_RSTU,
- ranging_interval_ms: DEFAULT_RANGING_INTERVAL_MS,
+ ranging_duration_ms: DEFAULT_RANGING_DURATION_MS,
mac_fcs_type: DEFAULT_MAC_FCS_TYPE,
ranging_round_control: DEFAULT_RANGING_ROUND_CONTROL,
aoa_result_request: DEFAULT_AOA_RESULT_REQUEST,
@@ -611,7 +611,7 @@
device_mac_address: Some(params.device_mac_address.clone()),
dst_mac_address: params.dst_mac_address.clone(),
slot_duration_rstu: params.slot_duration_rstu,
- ranging_interval_ms: params.ranging_interval_ms,
+ ranging_duration_ms: params.ranging_duration_ms,
mac_fcs_type: params.mac_fcs_type,
ranging_round_control: params.ranging_round_control.clone(),
aoa_result_request: params.aoa_result_request,
@@ -665,7 +665,7 @@
device_mac_address: self.device_mac_address.clone()?,
dst_mac_address: self.dst_mac_address.clone(),
slot_duration_rstu: self.slot_duration_rstu,
- ranging_interval_ms: self.ranging_interval_ms,
+ ranging_duration_ms: self.ranging_duration_ms,
mac_fcs_type: self.mac_fcs_type,
ranging_round_control: self.ranging_round_control.clone(),
aoa_result_request: self.aoa_result_request,
@@ -719,7 +719,7 @@
builder_field!(device_mac_address, UwbAddress, Some);
builder_field!(dst_mac_address, Vec<UwbAddress>);
builder_field!(slot_duration_rstu, u16);
- builder_field!(ranging_interval_ms, u32);
+ builder_field!(ranging_duration_ms, u32);
builder_field!(mac_fcs_type, MacFcsType);
builder_field!(ranging_round_control, RangingRoundControl);
builder_field!(aoa_result_request, AoaResultRequest);
@@ -1150,7 +1150,7 @@
let dst_mac_address1 = [2, 2, 3, 4, 5, 6, 7, 8];
let dst_mac_address2 = [3, 2, 3, 4, 5, 6, 7, 8];
let slot_duration_rstu = 0x0A28;
- let ranging_interval_ms = 100;
+ let ranging_duration_ms = 100;
let mac_fcs_type = MacFcsType::Crc32;
let ranging_round_control = RangingRoundControl {
ranging_result_report_message: false,
@@ -1201,7 +1201,7 @@
UwbAddress::Extended(dst_mac_address2),
])
.slot_duration_rstu(slot_duration_rstu)
- .ranging_interval_ms(ranging_interval_ms)
+ .ranging_duration_ms(ranging_duration_ms)
.mac_fcs_type(mac_fcs_type)
.ranging_round_control(ranging_round_control.clone())
.aoa_result_request(aoa_result_request)
@@ -1250,7 +1250,7 @@
[dst_mac_address1, dst_mac_address2].concat().to_vec(),
),
(AppConfigTlvType::SlotDuration, slot_duration_rstu.to_le_bytes().to_vec()),
- (AppConfigTlvType::RangingInterval, ranging_interval_ms.to_le_bytes().to_vec()),
+ (AppConfigTlvType::RangingDuration, ranging_duration_ms.to_le_bytes().to_vec()),
(AppConfigTlvType::MacFcsType, vec![mac_fcs_type as u8]),
(AppConfigTlvType::RangingRoundControl, vec![ranging_round_control.as_u8()]),
(AppConfigTlvType::AoaResultReq, vec![aoa_result_request as u8]),
diff --git a/src/rust/uwb_core/src/proto/mappings.rs b/src/rust/uwb_core/src/proto/mappings.rs
index 1535197..a08046d 100644
--- a/src/rust/uwb_core/src/proto/mappings.rs
+++ b/src/rust/uwb_core/src/proto/mappings.rs
@@ -16,7 +16,6 @@
use std::convert::{TryFrom, TryInto};
-use protobuf::RepeatedField;
use zeroize::Zeroize;
use crate::error::{Error, Result};
@@ -58,6 +57,7 @@
};
use crate::uci::notification::{RangingMeasurements, SessionRangeData};
use crate::uci::uci_logger::UciLoggerMode;
+use protobuf::{EnumOrUnknown, MessageField};
/// Generate the conversion functions between 2 enum types, which field is 1-to-1 mapping.
///
@@ -711,20 +711,20 @@
impl From<ShortAddressTwoWayRangingMeasurement> for ProtoTwoWayRangingMeasurement {
fn from(item: ShortAddressTwoWayRangingMeasurement) -> Self {
let mut result = Self::new();
- result.set_mac_address(item.mac_address.into());
- result.set_status(item.status.into());
- result.set_nlos(item.nlos.into());
- result.set_distance(item.distance.into());
- result.set_aoa_azimuth(item.aoa_azimuth.into());
- result.set_aoa_azimuth_fom(item.aoa_azimuth_fom.into());
- result.set_aoa_elevation(item.aoa_elevation.into());
- result.set_aoa_elevation_fom(item.aoa_elevation_fom.into());
- result.set_aoa_destination_azimuth(item.aoa_destination_azimuth.into());
- result.set_aoa_destination_azimuth_fom(item.aoa_destination_azimuth_fom.into());
- result.set_aoa_destination_elevation(item.aoa_destination_elevation.into());
- result.set_aoa_destination_elevation_fom(item.aoa_destination_elevation_fom.into());
- result.set_slot_index(item.slot_index.into());
- result.set_rssi(item.rssi.into());
+ result.mac_address = item.mac_address.into();
+ result.status = EnumOrUnknown::new(item.status.into());
+ result.nlos = item.nlos.into();
+ result.distance = item.distance.into();
+ result.aoa_azimuth = item.aoa_azimuth.into();
+ result.aoa_azimuth_fom = item.aoa_azimuth_fom.into();
+ result.aoa_elevation = item.aoa_elevation.into();
+ result.aoa_elevation_fom = item.aoa_elevation_fom.into();
+ result.aoa_destination_azimuth = item.aoa_destination_azimuth.into();
+ result.aoa_destination_azimuth_fom = item.aoa_destination_azimuth_fom.into();
+ result.aoa_destination_elevation = item.aoa_destination_elevation.into();
+ result.aoa_destination_elevation_fom = item.aoa_destination_elevation_fom.into();
+ result.slot_index = item.slot_index.into();
+ result.rssi = item.rssi.into();
result
}
}
@@ -732,20 +732,20 @@
impl From<ExtendedAddressTwoWayRangingMeasurement> for ProtoTwoWayRangingMeasurement {
fn from(item: ExtendedAddressTwoWayRangingMeasurement) -> Self {
let mut result = Self::new();
- result.set_mac_address(item.mac_address);
- result.set_status(item.status.into());
- result.set_nlos(item.nlos.into());
- result.set_distance(item.distance.into());
- result.set_aoa_azimuth(item.aoa_azimuth.into());
- result.set_aoa_azimuth_fom(item.aoa_azimuth_fom.into());
- result.set_aoa_elevation(item.aoa_elevation.into());
- result.set_aoa_elevation_fom(item.aoa_elevation_fom.into());
- result.set_aoa_destination_azimuth(item.aoa_destination_azimuth.into());
- result.set_aoa_destination_azimuth_fom(item.aoa_destination_azimuth_fom.into());
- result.set_aoa_destination_elevation(item.aoa_destination_elevation.into());
- result.set_aoa_destination_elevation_fom(item.aoa_destination_elevation_fom.into());
- result.set_slot_index(item.slot_index.into());
- result.set_rssi(item.rssi.into());
+ result.mac_address = item.mac_address;
+ result.status = EnumOrUnknown::new(item.status.into());
+ result.nlos = item.nlos.into();
+ result.distance = item.distance.into();
+ result.aoa_azimuth = item.aoa_azimuth.into();
+ result.aoa_azimuth_fom = item.aoa_azimuth_fom.into();
+ result.aoa_elevation = item.aoa_elevation.into();
+ result.aoa_elevation_fom = item.aoa_elevation_fom.into();
+ result.aoa_destination_azimuth = item.aoa_destination_azimuth.into();
+ result.aoa_destination_azimuth_fom = item.aoa_destination_azimuth_fom.into();
+ result.aoa_destination_elevation = item.aoa_destination_elevation.into();
+ result.aoa_destination_elevation_fom = item.aoa_destination_elevation_fom.into();
+ result.slot_index = item.slot_index.into();
+ result.rssi = item.rssi.into();
result
}
}
@@ -753,15 +753,15 @@
impl From<ShortAddressOwrAoaRangingMeasurement> for ProtoOwrAoaRangingMeasurement {
fn from(item: ShortAddressOwrAoaRangingMeasurement) -> Self {
let mut result = Self::new();
- result.set_mac_address(item.mac_address.into());
- result.set_status(item.status.into());
- result.set_nlos(item.nlos.into());
- result.set_block_index(item.block_index.into());
- result.set_frame_sequence_number(item.frame_sequence_number.into());
- result.set_aoa_azimuth(item.aoa_azimuth.into());
- result.set_aoa_azimuth_fom(item.aoa_azimuth_fom.into());
- result.set_aoa_elevation(item.aoa_elevation.into());
- result.set_aoa_elevation_fom(item.aoa_elevation_fom.into());
+ result.mac_address = item.mac_address.into();
+ result.status = EnumOrUnknown::new(item.status.into());
+ result.nlos = item.nlos.into();
+ result.block_index = item.block_index.into();
+ result.frame_sequence_number = item.frame_sequence_number.into();
+ result.aoa_azimuth = item.aoa_azimuth.into();
+ result.aoa_azimuth_fom = item.aoa_azimuth_fom.into();
+ result.aoa_elevation = item.aoa_elevation.into();
+ result.aoa_elevation_fom = item.aoa_elevation_fom.into();
result
}
}
@@ -769,15 +769,15 @@
impl From<ExtendedAddressOwrAoaRangingMeasurement> for ProtoOwrAoaRangingMeasurement {
fn from(item: ExtendedAddressOwrAoaRangingMeasurement) -> Self {
let mut result = Self::new();
- result.set_mac_address(item.mac_address);
- result.set_status(item.status.into());
- result.set_nlos(item.nlos.into());
- result.set_block_index(item.block_index.into());
- result.set_frame_sequence_number(item.frame_sequence_number.into());
- result.set_aoa_azimuth(item.aoa_azimuth.into());
- result.set_aoa_azimuth_fom(item.aoa_azimuth_fom.into());
- result.set_aoa_elevation(item.aoa_elevation.into());
- result.set_aoa_elevation_fom(item.aoa_elevation_fom.into());
+ result.mac_address = item.mac_address;
+ result.status = EnumOrUnknown::new(item.status.into());
+ result.nlos = item.nlos.into();
+ result.block_index = item.block_index.into();
+ result.frame_sequence_number = item.frame_sequence_number.into();
+ result.aoa_azimuth = item.aoa_azimuth.into();
+ result.aoa_azimuth_fom = item.aoa_azimuth_fom.into();
+ result.aoa_elevation = item.aoa_elevation.into();
+ result.aoa_elevation_fom = item.aoa_elevation_fom.into();
result
}
}
@@ -785,38 +785,36 @@
impl From<ShortAddressDlTdoaRangingMeasurement> for ProtoDlTDoARangingMeasurement {
fn from(item: ShortAddressDlTdoaRangingMeasurement) -> Self {
let mut result = Self::new();
- result.set_mac_address(item.mac_address.into());
- result.set_status(
+ result.mac_address = item.mac_address.into();
+ result.status = EnumOrUnknown::new(
StatusCode::try_from(item.measurement.status)
.unwrap_or(StatusCode::UciStatusFailed)
.into(),
);
- result.set_message_control(item.measurement.message_control.into());
- result.set_block_index(item.measurement.block_index.into());
- result.set_round_index(item.measurement.round_index.into());
- result.set_nlos(item.measurement.nlos.into());
- result.set_aoa_azimuth(item.measurement.aoa_azimuth.into());
- result.set_aoa_azimuth_fom(item.measurement.aoa_azimuth_fom.into());
- result.set_aoa_elevation(item.measurement.aoa_elevation.into());
- result.set_aoa_elevation_fom(item.measurement.aoa_elevation_fom.into());
- result.set_rssi(item.measurement.rssi.into());
- result.set_tx_timestamp(item.measurement.tx_timestamp);
- result.set_rx_timestamp(item.measurement.rx_timestamp);
- result.set_anchor_cfo(item.measurement.anchor_cfo.into());
- result.set_cfo(item.measurement.cfo.into());
- result.set_initiator_reply_time(item.measurement.initiator_reply_time);
- result.set_responder_reply_time(item.measurement.responder_reply_time);
- result.set_initiator_responder_tof(item.measurement.initiator_responder_tof.into());
- result.set_dt_anchor_location(
- item.measurement
- .dt_anchor_location
- .into_iter()
- .map(|val| val as u32)
- .collect::<Vec<u32>>(),
- );
- result.set_ranging_rounds(
- item.measurement.ranging_rounds.into_iter().map(|val| val as u32).collect::<Vec<u32>>(),
- );
+ result.message_control = item.measurement.message_control.into();
+ result.block_index = item.measurement.block_index.into();
+ result.round_index = item.measurement.round_index.into();
+ result.nlos = item.measurement.nlos.into();
+ result.aoa_azimuth = item.measurement.aoa_azimuth.into();
+ result.aoa_azimuth_fom = item.measurement.aoa_azimuth_fom.into();
+ result.aoa_elevation = item.measurement.aoa_elevation.into();
+ result.aoa_elevation_fom = item.measurement.aoa_elevation_fom.into();
+ result.rssi = item.measurement.rssi.into();
+ result.tx_timestamp = item.measurement.tx_timestamp;
+ result.rx_timestamp = item.measurement.rx_timestamp;
+ result.anchor_cfo = item.measurement.anchor_cfo.into();
+ result.cfo = item.measurement.cfo.into();
+ result.initiator_reply_time = item.measurement.initiator_reply_time;
+ result.responder_reply_time = item.measurement.responder_reply_time;
+ result.initiator_responder_tof = item.measurement.initiator_responder_tof.into();
+ result.dt_anchor_location = item
+ .measurement
+ .dt_anchor_location
+ .into_iter()
+ .map(|val| val as u32)
+ .collect::<Vec<u32>>();
+ result.ranging_rounds =
+ item.measurement.ranging_rounds.into_iter().map(|val| val as u32).collect::<Vec<u32>>();
result
}
}
@@ -824,38 +822,36 @@
impl From<ExtendedAddressDlTdoaRangingMeasurement> for ProtoDlTDoARangingMeasurement {
fn from(item: ExtendedAddressDlTdoaRangingMeasurement) -> Self {
let mut result = Self::new();
- result.set_mac_address(item.mac_address);
- result.set_status(
+ result.mac_address = item.mac_address;
+ result.status = EnumOrUnknown::new(
StatusCode::try_from(item.measurement.status)
.unwrap_or(StatusCode::UciStatusFailed)
.into(),
);
- result.set_message_control(item.measurement.message_control.into());
- result.set_block_index(item.measurement.block_index.into());
- result.set_round_index(item.measurement.round_index.into());
- result.set_nlos(item.measurement.nlos.into());
- result.set_aoa_azimuth(item.measurement.aoa_azimuth.into());
- result.set_aoa_azimuth_fom(item.measurement.aoa_azimuth_fom.into());
- result.set_aoa_elevation(item.measurement.aoa_elevation.into());
- result.set_aoa_elevation_fom(item.measurement.aoa_elevation_fom.into());
- result.set_rssi(item.measurement.rssi.into());
- result.set_tx_timestamp(item.measurement.tx_timestamp);
- result.set_rx_timestamp(item.measurement.rx_timestamp);
- result.set_anchor_cfo(item.measurement.anchor_cfo.into());
- result.set_cfo(item.measurement.cfo.into());
- result.set_initiator_reply_time(item.measurement.initiator_reply_time);
- result.set_responder_reply_time(item.measurement.responder_reply_time);
- result.set_initiator_responder_tof(item.measurement.initiator_responder_tof.into());
- result.set_dt_anchor_location(
- item.measurement
- .dt_anchor_location
- .into_iter()
- .map(|val| val as u32)
- .collect::<Vec<u32>>(),
- );
- result.set_ranging_rounds(
- item.measurement.ranging_rounds.into_iter().map(|val| val as u32).collect::<Vec<u32>>(),
- );
+ result.message_control = item.measurement.message_control.into();
+ result.block_index = item.measurement.block_index.into();
+ result.round_index = item.measurement.round_index.into();
+ result.nlos = item.measurement.nlos.into();
+ result.aoa_azimuth = item.measurement.aoa_azimuth.into();
+ result.aoa_azimuth_fom = item.measurement.aoa_azimuth_fom.into();
+ result.aoa_elevation = item.measurement.aoa_elevation.into();
+ result.aoa_elevation_fom = item.measurement.aoa_elevation_fom.into();
+ result.rssi = item.measurement.rssi.into();
+ result.tx_timestamp = item.measurement.tx_timestamp;
+ result.rx_timestamp = item.measurement.rx_timestamp;
+ result.anchor_cfo = item.measurement.anchor_cfo.into();
+ result.cfo = item.measurement.cfo.into();
+ result.initiator_reply_time = item.measurement.initiator_reply_time;
+ result.responder_reply_time = item.measurement.responder_reply_time;
+ result.initiator_responder_tof = item.measurement.initiator_responder_tof.into();
+ result.dt_anchor_location = item
+ .measurement
+ .dt_anchor_location
+ .into_iter()
+ .map(|val| val as u32)
+ .collect::<Vec<u32>>();
+ result.ranging_rounds =
+ item.measurement.ranging_rounds.into_iter().map(|val| val as u32).collect::<Vec<u32>>();
result
}
}
@@ -863,19 +859,19 @@
impl From<SessionRangeData> for ProtoSessionRangeData {
fn from(item: SessionRangeData) -> Self {
let mut result = Self::new();
- result.set_sequence_number(item.sequence_number);
- result.set_session_id(item.session_token);
- result.set_current_ranging_interval_ms(item.current_ranging_interval_ms);
- result.set_ranging_measurement_type(item.ranging_measurement_type.into());
+ result.sequence_number = item.sequence_number;
+ result.session_id = item.session_token;
+ result.current_ranging_interval_ms = item.current_ranging_interval_ms;
+ result.ranging_measurement_type = EnumOrUnknown::new(item.ranging_measurement_type.into());
match to_proto_ranging_measurements(item.ranging_measurements) {
ProtoRangingMeasurements::TwoWay(twoway_measurements) => {
- result.set_twoway_ranging_measurements(RepeatedField::from_vec(twoway_measurements))
+ result.twoway_ranging_measurements = twoway_measurements;
}
ProtoRangingMeasurements::OwrAoa(owraoa_measurement) => {
- result.set_owraoa_ranging_measurement(owraoa_measurement)
+ result.owraoa_ranging_measurement = MessageField::from(Some(owraoa_measurement));
}
ProtoRangingMeasurements::DlTDoa(dltdoa_measurements) => {
- result.set_dltdoa_ranging_measurements(RepeatedField::from_vec(dltdoa_measurements))
+ result.dltdoa_ranging_measurements = dltdoa_measurements;
}
}
result
@@ -914,9 +910,9 @@
impl From<RangingRoundControl> for ProtoRangingRoundControl {
fn from(item: RangingRoundControl) -> Self {
let mut res = Self::new();
- res.set_ranging_result_report_message(item.ranging_result_report_message);
- res.set_control_message(item.control_message);
- res.set_measurement_report_message(item.measurement_report_message);
+ res.ranging_result_report_message = item.ranging_result_report_message;
+ res.control_message = item.control_message;
+ res.measurement_report_message = item.measurement_report_message;
res
}
}
@@ -935,10 +931,10 @@
impl From<ResultReportConfig> for ProtoResultReportConfig {
fn from(item: ResultReportConfig) -> Self {
let mut res = Self::new();
- res.set_tof(item.tof);
- res.set_aoa_azimuth(item.aoa_azimuth);
- res.set_aoa_elevation(item.aoa_elevation);
- res.set_aoa_fom(item.aoa_fom);
+ res.tof = item.tof;
+ res.aoa_azimuth = item.aoa_azimuth;
+ res.aoa_elevation = item.aoa_elevation;
+ res.aoa_fom = item.aoa_fom;
res
}
}
@@ -970,11 +966,11 @@
impl From<PowerStats> for ProtoPowerStats {
fn from(item: PowerStats) -> Self {
let mut res = Self::new();
- res.set_status(item.status.into());
- res.set_idle_time_ms(item.idle_time_ms);
- res.set_tx_time_ms(item.tx_time_ms);
- res.set_rx_time_ms(item.rx_time_ms);
- res.set_total_wake_count(item.total_wake_count);
+ res.status = ProtoStatusCode::from(item.status).into();
+ res.idle_time_ms = item.idle_time_ms;
+ res.tx_time_ms = item.tx_time_ms;
+ res.rx_time_ms = item.rx_time_ms;
+ res.total_wake_count = item.total_wake_count;
res
}
}
@@ -982,66 +978,62 @@
impl From<FiraAppConfigParams> for ProtoFiraAppConfigParams {
fn from(item: FiraAppConfigParams) -> Self {
let mut res = Self::new();
- res.set_device_type((*item.device_type()).into());
- res.set_ranging_round_usage((*item.ranging_round_usage()).into());
- res.set_sts_config((*item.sts_config()).into());
- res.set_multi_node_mode((*item.multi_node_mode()).into());
- res.set_channel_number((*item.channel_number()).into());
- res.set_device_mac_address(item.device_mac_address().clone().into());
- res.set_dst_mac_address(
- item.dst_mac_address()
- .clone()
- .into_iter()
- .map(|addr| addr.into())
- .collect::<Vec<_>>()
- .into(),
- );
- res.set_slot_duration_rstu((*item.slot_duration_rstu()).into());
- res.set_ranging_interval_ms(*item.ranging_interval_ms());
- res.set_mac_fcs_type((*item.mac_fcs_type()).into());
- res.set_ranging_round_control(item.ranging_round_control().clone().into());
- res.set_aoa_result_request((*item.aoa_result_request()).into());
- res.set_range_data_ntf_config((*item.range_data_ntf_config()).into());
- res.set_range_data_ntf_proximity_near_cm((*item.range_data_ntf_proximity_near_cm()).into());
- res.set_range_data_ntf_proximity_far_cm((*item.range_data_ntf_proximity_far_cm()).into());
- res.set_device_role((*item.device_role()).into());
- res.set_rframe_config((*item.rframe_config()).into());
- res.set_preamble_code_index((*item.preamble_code_index()).into());
- res.set_sfd_id((*item.sfd_id()).into());
- res.set_psdu_data_rate((*item.psdu_data_rate()).into());
- res.set_preamble_duration((*item.preamble_duration()).into());
- res.set_ranging_time_struct((*item.ranging_time_struct()).into());
- res.set_slots_per_rr((*item.slots_per_rr()).into());
- res.set_tx_adaptive_payload_power((*item.tx_adaptive_payload_power()).into());
- res.set_responder_slot_index((*item.responder_slot_index()).into());
- res.set_prf_mode((*item.prf_mode()).into());
- res.set_scheduled_mode((*item.scheduled_mode()).into());
- res.set_key_rotation((*item.key_rotation()).into());
- res.set_key_rotation_rate((*item.key_rotation_rate()).into());
- res.set_session_priority((*item.session_priority()).into());
- res.set_mac_address_mode((*item.mac_address_mode()).into());
- res.set_vendor_id((*item.vendor_id()).into());
- res.set_static_sts_iv((*item.static_sts_iv()).into());
- res.set_number_of_sts_segments((*item.number_of_sts_segments()).into());
- res.set_max_rr_retry((*item.max_rr_retry()).into());
- res.set_uwb_initiation_time_ms(*item.uwb_initiation_time_ms());
- res.set_hopping_mode((*item.hopping_mode()).into());
- res.set_block_stride_length((*item.block_stride_length()).into());
- res.set_result_report_config(item.result_report_config().clone().into());
- res.set_in_band_termination_attempt_count(
- (*item.in_band_termination_attempt_count()).into(),
- );
- res.set_sub_session_id(*item.sub_session_id());
- res.set_bprf_phr_data_rate((*item.bprf_phr_data_rate()).into());
- res.set_max_number_of_measurements((*item.max_number_of_measurements()).into());
- res.set_sts_length((*item.sts_length()).into());
- res.set_number_of_range_measurements((*item.number_of_range_measurements()).into());
- res.set_number_of_aoa_azimuth_measurements(
- (*item.number_of_aoa_azimuth_measurements()).into(),
- );
- res.set_number_of_aoa_elevation_measurements(
- (*item.number_of_aoa_elevation_measurements()).into(),
- );
+ res.device_type = EnumOrUnknown::new((*item.device_type()).into());
+ res.ranging_round_usage = ProtoRangingRoundUsage::from(*item.ranging_round_usage()).into();
+ res.sts_config = ProtoStsConfig::from(*item.sts_config()).into();
+ res.multi_node_mode = ProtoMultiNodeMode::from(*item.multi_node_mode()).into();
+ res.channel_number = ProtoUwbChannel::from(*item.channel_number()).into();
+ res.device_mac_address = item.device_mac_address().clone().into();
+ res.dst_mac_address =
+ item.dst_mac_address().clone().into_iter().map(|addr| addr.into()).collect::<Vec<_>>();
+ res.slot_duration_rstu = (*item.slot_duration_rstu()).into();
+ res.ranging_duration_ms = *item.ranging_duration_ms();
+ res.mac_fcs_type = ProtoMacFcsType::from(*item.mac_fcs_type()).into();
+ res.ranging_round_control = MessageField::from(Some(ProtoRangingRoundControl::from(
+ item.ranging_round_control().clone(),
+ )));
+ res.aoa_result_request = ProtoAoaResultRequest::from(*item.aoa_result_request()).into();
+ res.range_data_ntf_config =
+ ProtoRangeDataNtfConfig::from(*item.range_data_ntf_config()).into();
+ res.range_data_ntf_proximity_near_cm = (*item.range_data_ntf_proximity_near_cm()).into();
+ res.range_data_ntf_proximity_far_cm = (*item.range_data_ntf_proximity_far_cm()).into();
+ res.device_role = ProtoDeviceRole::from(*item.device_role()).into();
+ res.rframe_config = ProtoRframeConfig::from(*item.rframe_config()).into();
+ res.preamble_code_index = (*item.preamble_code_index()).into();
+ res.sfd_id = (*item.sfd_id()).into();
+ res.psdu_data_rate = ProtoPsduDataRate::from(*item.psdu_data_rate()).into();
+ res.preamble_duration = ProtoPreambleDuration::from(*item.preamble_duration()).into();
+ res.ranging_time_struct = ProtoRangingTimeStruct::from(*item.ranging_time_struct()).into();
+ res.slots_per_rr = (*item.slots_per_rr()).into();
+ res.tx_adaptive_payload_power =
+ ProtoTxAdaptivePayloadPower::from(*item.tx_adaptive_payload_power()).into();
+ res.responder_slot_index = (*item.responder_slot_index()).into();
+ res.prf_mode = ProtoPrfMode::from(*item.prf_mode()).into();
+ res.scheduled_mode = ProtoScheduledMode::from(*item.scheduled_mode()).into();
+ res.key_rotation = ProtoKeyRotation::from(*item.key_rotation()).into();
+ res.key_rotation_rate = (*item.key_rotation_rate()).into();
+ res.session_priority = (*item.session_priority()).into();
+ res.mac_address_mode = ProtoMacAddressMode::from(*item.mac_address_mode()).into();
+ res.vendor_id = (*item.vendor_id()).into();
+ res.static_sts_iv = (*item.static_sts_iv()).into();
+ res.number_of_sts_segments = (*item.number_of_sts_segments()).into();
+ res.max_rr_retry = (*item.max_rr_retry()).into();
+ res.uwb_initiation_time_ms = *item.uwb_initiation_time_ms();
+ res.hopping_mode = ProtoHoppingMode::from(*item.hopping_mode()).into();
+ res.block_stride_length = (*item.block_stride_length()).into();
+ res.result_report_config = MessageField::from(Some(ProtoResultReportConfig::from(
+ item.result_report_config().clone(),
+ )));
+ res.in_band_termination_attempt_count = (*item.in_band_termination_attempt_count()).into();
+ res.sub_session_id = *item.sub_session_id();
+ res.bprf_phr_data_rate = ProtoBprfPhrDataRate::from(*item.bprf_phr_data_rate()).into();
+ res.max_number_of_measurements = (*item.max_number_of_measurements()).into();
+ res.sts_length = ProtoStsLength::from(*item.sts_length()).into();
+ res.number_of_range_measurements = (*item.number_of_range_measurements()).into();
+ res.number_of_aoa_azimuth_measurements =
+ (*item.number_of_aoa_azimuth_measurements()).into();
+ res.number_of_aoa_elevation_measurements =
+ (*item.number_of_aoa_elevation_measurements()).into();
res
}
@@ -1050,23 +1042,49 @@
impl TryFrom<ProtoFiraAppConfigParams> for AppConfigParams {
type Error = String;
fn try_from(mut item: ProtoFiraAppConfigParams) -> std::result::Result<Self, Self::Error> {
- let device_mac_address =
- to_uwb_address(item.device_mac_address.clone(), item.mac_address_mode)
- .ok_or("Failed to convert device_mac_address")?;
+ let device_mac_address = to_uwb_address(
+ item.device_mac_address.clone(),
+ item.mac_address_mode.enum_value().map_err(|_| "Failed to read mac_address_mode")?,
+ )
+ .ok_or("Failed to convert device_mac_address")?;
let mut dst_mac_address = vec![];
for addr in item.dst_mac_address.clone().into_iter() {
- let addr = to_uwb_address(addr, item.mac_address_mode)
- .ok_or("Failed to convert dst_mac_address")?;
+ let addr = to_uwb_address(
+ addr,
+ item.mac_address_mode
+ .enum_value()
+ .map_err(|_| "Failed to convert mac_address_mode")?,
+ )
+ .ok_or("Failed to convert dst_mac_address")?;
dst_mac_address.push(addr);
}
let mut builder = FiraAppConfigParamsBuilder::new();
builder
- .device_type(item.device_type.into())
- .ranging_round_usage(item.ranging_round_usage.into())
- .sts_config(item.sts_config.into())
- .multi_node_mode(item.multi_node_mode.into())
- .channel_number(item.channel_number.into())
+ .device_type(
+ item.device_type.enum_value().map_err(|_| "Failed to convert device_type")?.into(),
+ )
+ .ranging_round_usage(
+ item.ranging_round_usage
+ .enum_value()
+ .map_err(|_| "Failed to convert ranging_round_usage")?
+ .into(),
+ )
+ .sts_config(
+ item.sts_config.enum_value().map_err(|_| "Failed to convert sts_config")?.into(),
+ )
+ .multi_node_mode(
+ item.multi_node_mode
+ .enum_value()
+ .map_err(|_| "Failed to convert multi_node_mode")?
+ .into(),
+ )
+ .channel_number(
+ item.channel_number
+ .enum_value()
+ .map_err(|_| "Failed to convert channel_number")?
+ .into(),
+ )
.device_mac_address(device_mac_address)
.dst_mac_address(dst_mac_address)
.slot_duration_rstu(
@@ -1074,13 +1092,28 @@
.try_into()
.map_err(|_| "Failed to convert slot_duration_rstu")?,
)
- .ranging_interval_ms(item.ranging_interval_ms)
- .mac_fcs_type(item.mac_fcs_type.into())
+ .ranging_duration_ms(item.ranging_duration_ms)
+ .mac_fcs_type(
+ item.mac_fcs_type
+ .enum_value()
+ .map_err(|_| "Failed to convert mac_fcs_type")?
+ .into(),
+ )
.ranging_round_control(
item.ranging_round_control.take().ok_or("ranging_round_control is empty")?.into(),
)
- .aoa_result_request(item.aoa_result_request.into())
- .range_data_ntf_config(item.range_data_ntf_config.into())
+ .aoa_result_request(
+ item.aoa_result_request
+ .enum_value()
+ .map_err(|_| "Failed to convert aoa_result_request")?
+ .into(),
+ )
+ .range_data_ntf_config(
+ item.range_data_ntf_config
+ .enum_value()
+ .map_err(|_| "Failed to convert range_data_ntf_config")?
+ .into(),
+ )
.range_data_ntf_proximity_near_cm(
item.range_data_ntf_proximity_near_cm
.try_into()
@@ -1091,29 +1124,66 @@
.try_into()
.map_err(|_| "Failed to convert range_data_ntf_proximity_far_cm")?,
)
- .device_role(item.device_role.into())
- .rframe_config(item.rframe_config.into())
+ .device_role(
+ item.device_role.enum_value().map_err(|_| "Failed to convert device_role")?.into(),
+ )
+ .rframe_config(
+ item.rframe_config
+ .enum_value()
+ .map_err(|_| "Failed to convert rframe_config")?
+ .into(),
+ )
.preamble_code_index(
item.preamble_code_index
.try_into()
.map_err(|_| "Failed to convert preamble_code_index")?,
)
.sfd_id(item.sfd_id.try_into().map_err(|_| "Failed to convert sfd_id")?)
- .psdu_data_rate(item.psdu_data_rate.into())
- .preamble_duration(item.preamble_duration.into())
- .ranging_time_struct(item.ranging_time_struct.into())
+ .psdu_data_rate(
+ item.psdu_data_rate
+ .enum_value()
+ .map_err(|_| "Failed to convert psdu_data_rate")?
+ .into(),
+ )
+ .preamble_duration(
+ item.preamble_duration
+ .enum_value()
+ .map_err(|_| "Failed to convert preamble_duration")?
+ .into(),
+ )
+ .ranging_time_struct(
+ item.ranging_time_struct
+ .enum_value()
+ .map_err(|_| "Failed to convert ranging_time_struct")?
+ .into(),
+ )
.slots_per_rr(
item.slots_per_rr.try_into().map_err(|_| "Failed to convert slots_per_rr")?,
)
- .tx_adaptive_payload_power(item.tx_adaptive_payload_power.into())
+ .tx_adaptive_payload_power(
+ item.tx_adaptive_payload_power
+ .enum_value()
+ .map_err(|_| "Failed to convert tx_adaptive_payload_power")?
+ .into(),
+ )
.responder_slot_index(
item.responder_slot_index
.try_into()
.map_err(|_| "Failed to convert responder_slot_index")?,
)
- .prf_mode(item.prf_mode.into())
- .scheduled_mode(item.scheduled_mode.into())
- .key_rotation(item.key_rotation.into())
+ .prf_mode(item.prf_mode.enum_value().map_err(|_| "Failed to convert prf_mode")?.into())
+ .scheduled_mode(
+ item.scheduled_mode
+ .enum_value()
+ .map_err(|_| "Failed to convert scheduled_mode")?
+ .into(),
+ )
+ .key_rotation(
+ item.key_rotation
+ .enum_value()
+ .map_err(|_| "Failed to convert key_rotation")?
+ .into(),
+ )
.key_rotation_rate(
item.key_rotation_rate
.try_into()
@@ -1124,7 +1194,12 @@
.try_into()
.map_err(|_| "Failed to convert session_priority")?,
)
- .mac_address_mode(item.mac_address_mode.into())
+ .mac_address_mode(
+ item.mac_address_mode
+ .enum_value()
+ .map_err(|_| "Failed to convert mac_address_mode")?
+ .into(),
+ )
.vendor_id(
item.vendor_id.clone().try_into().map_err(|_| "Failed to convert vendor_id")?,
)
@@ -1143,7 +1218,7 @@
item.max_rr_retry.try_into().map_err(|_| "Failed to convert max_rr_retry")?,
)
.uwb_initiation_time_ms(item.uwb_initiation_time_ms)
- .hopping_mode(item.hopping_mode.into())
+ .hopping_mode(item.hopping_mode.unwrap().into())
.block_stride_length(
item.block_stride_length
.try_into()
@@ -1158,13 +1233,20 @@
.map_err(|_| "Failed to convert in_band_termination_attempt_count")?,
)
.sub_session_id(item.sub_session_id)
- .bprf_phr_data_rate(item.bprf_phr_data_rate.into())
+ .bprf_phr_data_rate(
+ item.bprf_phr_data_rate
+ .enum_value()
+ .map_err(|_| "Failed to convert bprf_phr_data_rate")?
+ .into(),
+ )
.max_number_of_measurements(
item.max_number_of_measurements
.try_into()
.map_err(|_| "Failed to convert max_number_of_measurements")?,
)
- .sts_length(item.sts_length.into())
+ .sts_length(
+ item.sts_length.enum_value().map_err(|_| "Failed to convert sts_length")?.into(),
+ )
.number_of_range_measurements(
item.number_of_range_measurements
.try_into()
diff --git a/src/rust/uwb_core/src/proto/utils.rs b/src/rust/uwb_core/src/proto/utils.rs
index 8f73e20..e1ffc9e 100644
--- a/src/rust/uwb_core/src/proto/utils.rs
+++ b/src/rust/uwb_core/src/proto/utils.rs
@@ -22,7 +22,7 @@
/// Convert the protobuf message to a byte buffers. Return dbus::MethodErr when conversion fails.
pub fn write_to_bytes<M: Message>(msg: &M) -> Result<Vec<u8>> {
msg.write_to_bytes().map_err(|e| {
- error!("Failed to write protobuf {} to bytes: {:?}", msg.descriptor().name(), e);
+ error!("Failed to write protobuf {} to bytes: {:?}", M::NAME, e);
Error::Unknown
})
}
@@ -30,7 +30,7 @@
/// Parse the byte buffer to the protobuf message. Return dbus::MethodErr when failed to parse.
pub fn parse_from_bytes<M: Message>(bytes: &[u8]) -> Result<M> {
M::parse_from_bytes(bytes).map_err(|e| {
- error!("Failed to parse {:?}: {:?}", M::descriptor_static().name(), e);
+ error!("Failed to parse {:?}: {:?}", M::NAME, e);
Error::BadParameters
})
}
diff --git a/src/rust/uwb_core/src/service/proto_uwb_service.rs b/src/rust/uwb_core/src/service/proto_uwb_service.rs
index 747865a..7c1362b 100644
--- a/src/rust/uwb_core/src/service/proto_uwb_service.rs
+++ b/src/rust/uwb_core/src/service/proto_uwb_service.rs
@@ -16,6 +16,7 @@
//! arguments to protobuf.
use log::{debug, error};
+use protobuf::EnumOrUnknown;
use crate::error::{Error, Result};
use crate::params::{AppConfigParams, DeviceState, ReasonCode, SessionId, SessionState};
@@ -53,21 +54,31 @@
pub fn set_logger_mode(&self, request: &[u8]) -> Result<Vec<u8>> {
let request = parse_from_bytes::<SetLoggerModeRequest>(request)?;
let mut resp = SetLoggerModeResponse::new();
- resp.set_status(self.service.set_logger_mode(request.logger_mode.into()).into());
+ let res = self.service.set_logger_mode(
+ request
+ .logger_mode
+ .enum_value()
+ .map_err(|e| {
+ error!("Failed to convert logger_mode: {e}");
+ Error::BadParameters
+ })?
+ .into(),
+ );
+ resp.status = Into::<crate::proto::bindings::Status>::into(res).into();
write_to_bytes(&resp)
}
/// Enable the UWB service.
pub fn enable(&self) -> Result<Vec<u8>> {
let mut resp = EnableResponse::new();
- resp.set_status(self.service.enable().into());
+ resp.status = EnumOrUnknown::new(self.service.enable().into());
write_to_bytes(&resp)
}
/// Disable the UWB service.
pub fn disable(&self) -> Result<Vec<u8>> {
let mut resp = DisableResponse::new();
- resp.set_status(self.service.disable().into());
+ resp.status = EnumOrUnknown::new(self.service.disable().into());
write_to_bytes(&resp)
}
@@ -90,9 +101,20 @@
})?;
let mut resp = InitSessionResponse::new();
- resp.set_status(
+ resp.status = EnumOrUnknown::new(
self.service
- .init_session(request.session_id, request.session_type.into(), params)
+ .init_session(
+ request.session_id,
+ request
+ .session_type
+ .enum_value()
+ .map_err(|e| {
+ error!("Failed to convert session_type: {:?}", e);
+ Error::BadParameters
+ })?
+ .into(),
+ params,
+ )
.into(),
);
write_to_bytes(&resp)
@@ -102,7 +124,7 @@
pub fn deinit_session(&self, request: &[u8]) -> Result<Vec<u8>> {
let request = parse_from_bytes::<DeinitSessionRequest>(request)?;
let mut resp = DeinitSessionResponse::new();
- resp.set_status(self.service.deinit_session(request.session_id).into());
+ resp.status = EnumOrUnknown::new(self.service.deinit_session(request.session_id).into());
write_to_bytes(&resp)
}
@@ -113,7 +135,7 @@
// AppConfigParams is the same as the configured one before start_ranging(). Therefore, we
// don't reply the AppConfigParams received from uwb_core.
let mut resp = StartRangingResponse::new();
- resp.set_status(self.service.start_ranging(request.session_id).into());
+ resp.status = EnumOrUnknown::new(self.service.start_ranging(request.session_id).into());
write_to_bytes(&resp)
}
@@ -121,7 +143,7 @@
pub fn stop_ranging(&self, request: &[u8]) -> Result<Vec<u8>> {
let request = parse_from_bytes::<StopRangingRequest>(request)?;
let mut resp = StopRangingResponse::new();
- resp.set_status(self.service.stop_ranging(request.session_id).into());
+ resp.status = EnumOrUnknown::new(self.service.stop_ranging(request.session_id).into());
write_to_bytes(&resp)
}
@@ -142,7 +164,8 @@
})?;
let mut resp = ReconfigureResponse::new();
- resp.set_status(self.service.reconfigure(request.session_id, params).into());
+ resp.status =
+ EnumOrUnknown::new(self.service.reconfigure(request.session_id, params).into());
write_to_bytes(&resp)
}
@@ -159,11 +182,18 @@
}
let mut resp = UpdateControllerMulticastListResponse::new();
- resp.set_status(
+ resp.status = EnumOrUnknown::new(
self.service
.update_controller_multicast_list(
request.session_id,
- request.action.into(),
+ request
+ .action
+ .enum_value()
+ .map_err(|e| {
+ error!("Failed to convert action: {:?}", e);
+ Error::BadParameters
+ })?
+ .into(),
controlees,
)
.into(),
@@ -177,7 +207,8 @@
let country_code = request.country_code.try_into()?;
let mut resp = AndroidSetCountryCodeResponse::new();
- resp.set_status(self.service.android_set_country_code(country_code).into());
+ resp.status =
+ EnumOrUnknown::new(self.service.android_set_country_code(country_code).into());
write_to_bytes(&resp)
}
@@ -186,11 +217,12 @@
let mut resp = AndroidGetPowerStatsResponse::new();
match self.service.android_get_power_stats() {
Ok(power_stats) => {
- resp.set_status(Ok(()).into());
- resp.set_power_stats(power_stats.into());
+ resp.status = EnumOrUnknown::new(Ok(()).into());
+ resp.power_stats = Some(power_stats.into()).into();
}
Err(e) => {
- resp.set_status(From::<Result<()>>::from(Err(e)));
+ let err: Result<()> = Err(e);
+ resp.status = crate::proto::bindings::Status::from(err).into();
}
}
write_to_bytes(&resp)
@@ -202,13 +234,14 @@
let mut resp = SendVendorCmdResponse::new();
match self.service.raw_uci_cmd(request.mt, request.gid, request.oid, request.payload) {
Ok(msg) => {
- resp.set_status(Ok(()).into());
- resp.set_gid(msg.gid);
- resp.set_oid(msg.oid);
- resp.set_payload(msg.payload);
+ resp.status = EnumOrUnknown::new(Ok(()).into());
+ resp.gid = msg.gid;
+ resp.oid = msg.oid;
+ resp.payload = msg.payload;
}
Err(e) => {
- resp.set_status(From::<Result<()>>::from(Err(e)));
+ let err: Result<()> = Err(e);
+ resp.status = (Into::<crate::proto::bindings::Status>::into(err)).into();
}
}
write_to_bytes(&resp)
@@ -220,15 +253,17 @@
let mut resp = SessionParamsResponse::new();
match self.service.session_params(request.session_id) {
Ok(AppConfigParams::Fira(params)) => {
- resp.set_status(Ok(()).into());
- resp.set_params(params.into());
+ resp.status =
+ EnumOrUnknown::from(Into::<crate::proto::bindings::Status>::into(Ok(())));
+ resp.params = Some(params.into()).into();
}
Ok(params) => {
error!("Received non-Fira session parameters: {:?}", params);
- resp.set_status(ProtoStatus::UNKNOWN);
+ resp.status = ProtoStatus::UNKNOWN.into();
}
Err(e) => {
- resp.set_status(From::<Result<()>>::from(Err(e)));
+ let err: Result<()> = Err(e);
+ resp.status = Into::<crate::proto::bindings::Status>::into(err).into();
}
}
write_to_bytes(&resp)
@@ -258,7 +293,7 @@
fn on_service_reset(&mut self, success: bool) {
debug!("UwbService is reset, success: {}", success);
let mut msg = ServiceResetSignal::new();
- msg.set_success(success);
+ msg.success = success;
if let Ok(payload) = write_to_bytes(&msg) {
ProtoUwbServiceCallback::on_service_reset(self, payload);
} else {
@@ -269,7 +304,7 @@
fn on_uci_device_status_changed(&mut self, state: DeviceState) {
debug!("UCI device status is changed: {:?}", state);
let mut msg = UciDeviceStatusChangedSignal::new();
- msg.set_state(state.into());
+ msg.state = EnumOrUnknown::new(state.into());
if let Ok(payload) = write_to_bytes(&msg) {
ProtoUwbServiceCallback::on_uci_device_status_changed(self, payload);
} else {
@@ -288,9 +323,9 @@
session_id, session_state, reason_code
);
let mut msg = SessionStateChangedSignal::new();
- msg.set_session_id(session_id);
- msg.set_session_state(session_state.into());
- msg.set_reason_code(reason_code.into());
+ msg.session_id = session_id;
+ msg.session_state = EnumOrUnknown::new(session_state.into());
+ msg.reason_code = EnumOrUnknown::new(reason_code.into());
if let Ok(payload) = write_to_bytes(&msg) {
ProtoUwbServiceCallback::on_session_state_changed(self, payload);
} else {
@@ -301,8 +336,8 @@
fn on_range_data_received(&mut self, session_id: SessionId, range_data: SessionRangeData) {
debug!("Received range data {:?} from Session {:?}", range_data, session_id);
let mut msg = RangeDataReceivedSignal::new();
- msg.set_session_id(session_id);
- msg.set_range_data(range_data.into());
+ msg.session_id = session_id;
+ msg.range_data = Some(range_data.into()).into();
if let Ok(payload) = write_to_bytes(&msg) {
ProtoUwbServiceCallback::on_range_data_received(self, payload);
} else {
@@ -313,9 +348,9 @@
fn on_vendor_notification_received(&mut self, gid: u32, oid: u32, payload: Vec<u8>) {
debug!("Received vendor notification: gid={}, oid={}, payload={:?}", gid, oid, payload);
let mut msg = VendorNotificationReceivedSignal::new();
- msg.set_gid(gid);
- msg.set_oid(oid);
- msg.set_payload(payload);
+ msg.gid = gid;
+ msg.oid = oid;
+ msg.payload = payload;
if let Ok(payload) = write_to_bytes(&msg) {
ProtoUwbServiceCallback::on_vendor_notification_received(self, payload);
} else {
diff --git a/src/rust/uwb_core/src/session/session_manager.rs b/src/rust/uwb_core/src/session/session_manager.rs
index 2c9a711..e49dd9c 100644
--- a/src/rust/uwb_core/src/session/session_manager.rs
+++ b/src/rust/uwb_core/src/session/session_manager.rs
@@ -376,6 +376,7 @@
session_token,
uci_sequence_number: _,
status: _,
+ tx_count: _,
} => {
match self.active_sessions.get(&session_token) {
Some(_) => {
@@ -722,7 +723,7 @@
(AppConfigTlvType::StsIndex, u32_to_bytes(3)),
(AppConfigTlvType::CccHopModeKey, u32_to_bytes(5)),
(AppConfigTlvType::CccUwbTime0, u64_to_bytes(7)),
- (AppConfigTlvType::RangingInterval, u32_to_bytes(96)),
+ (AppConfigTlvType::RangingDuration, u32_to_bytes(96)),
(AppConfigTlvType::PreambleCodeIndex, u8_to_bytes(9)),
]);
let received_tlvs = received_config_map
diff --git a/src/rust/uwb_core/src/uci/notification.rs b/src/rust/uwb_core/src/uci/notification.rs
index 2e955f6..eab8233 100644
--- a/src/rust/uwb_core/src/uci/notification.rs
+++ b/src/rust/uwb_core/src/uci/notification.rs
@@ -85,6 +85,8 @@
uci_sequence_number: u8,
/// Data Transfer Status Code
status: DataTransferNtfStatusCode,
+ /// Transmission count
+ tx_count: u8,
},
}
@@ -271,6 +273,7 @@
session_token: evt.get_session_token(),
uci_sequence_number: evt.get_uci_sequence_number(),
status: evt.get_status(),
+ tx_count: evt.get_tx_count(),
})
}
_ => {
diff --git a/src/rust/uwb_core/src/uci/pcapng_uci_logger_factory.rs b/src/rust/uwb_core/src/uci/pcapng_uci_logger_factory.rs
index e99bb8b..9bcadf3 100644
--- a/src/rust/uwb_core/src/uci/pcapng_uci_logger_factory.rs
+++ b/src/rust/uwb_core/src/uci/pcapng_uci_logger_factory.rs
@@ -129,6 +129,7 @@
pub(crate) enum PcapngLoggerMessage {
ByteStream(Vec<u8>),
NewChip((String, u32)),
+ Flush(mpsc::UnboundedSender<bool>),
}
/// LogWriterActor performs the log writing and file operations asynchronously.
@@ -215,6 +216,22 @@
break;
}
}
+ Some(PcapngLoggerMessage::Flush(flush_sender)) => {
+ if self.current_file.is_some() {
+ match self.current_file.as_mut().unwrap().flush_file() {
+ Some(_) => {
+ let _ = flush_sender.send(true);
+ }
+ None => {
+ error!("UCI log: failed flushing the file");
+ let _ = flush_sender.send(false);
+ }
+ }
+ } else {
+ error!("UCI log: current_file not present");
+ let _ = flush_sender.send(false);
+ }
+ }
None => {
debug!("UCI log: LogWriterActor dropping.");
break;
@@ -264,6 +281,19 @@
}
}
+ pub fn flush(&mut self) -> Option<mpsc::UnboundedReceiver<bool>> {
+ let log_sender = self.log_sender.as_ref()?;
+ let (flush_sender, flush_receiver) = mpsc::unbounded_channel();
+ match log_sender.send(PcapngLoggerMessage::Flush(flush_sender)) {
+ Ok(_) => Some(flush_receiver),
+ Err(e) => {
+ error!("UCI log: LogWriterActor dead unexpectedly, sender error: {:?}", e);
+ self.log_sender = None;
+ None
+ }
+ }
+ }
+
fn send_chip(&mut self, chip_id: String, interface_id: u32) -> Option<()> {
let log_sender = self.log_sender.as_ref()?;
match log_sender.send(PcapngLoggerMessage::NewChip((chip_id, interface_id))) {
@@ -391,6 +421,7 @@
);
}
}
+
let file = match fs::OpenOptions::new().write(true).create_new(true).open(file_path) {
Ok(f) => f,
Err(e) => {
@@ -427,6 +458,13 @@
self.file.flush().ok()
}
+
+ pub fn flush_file(&mut self) -> Option<()> {
+ // Flush the buffer and then the file to storage.
+ self.flush_buffer();
+ self.file.sync_all().ok();
+ Some(())
+ }
}
/// Manual Drop implementation.
@@ -441,7 +479,7 @@
mod tests {
use super::*;
- use std::{fs, thread, time};
+ use std::fs;
use tempfile::tempdir;
use tokio::runtime::Builder;
@@ -476,23 +514,31 @@
Some(block_info)
}
+ async fn flush_loggers(loggers: Vec<UciLoggerPcapng>) {
+ for mut logger in loggers {
+ let flush_receiver = logger.flush();
+ flush_receiver.unwrap().recv().await;
+ }
+ }
+
#[test]
fn test_no_file_write() {
let dir = tempdir().unwrap();
- {
- let runtime = Builder::new_multi_thread().enable_all().build().unwrap();
- let mut file_manager = PcapngUciLoggerFactoryBuilder::new()
- .buffer_size(1024)
- .filename_prefix("log".to_owned())
- .log_path(dir.as_ref().to_owned())
- .runtime_handle(runtime.handle().to_owned())
- .build()
- .unwrap();
- let _logger_0 = file_manager.build_logger("logger 0").unwrap();
- let _logger_1 = file_manager.build_logger("logger 1").unwrap();
- // Sleep needed to guarantee handling pending logs before runtime goes out of scope.
- thread::sleep(time::Duration::from_millis(10));
- }
+
+ let runtime = Builder::new_multi_thread().enable_all().build().unwrap();
+ let mut file_manager = PcapngUciLoggerFactoryBuilder::new()
+ .buffer_size(1024)
+ .filename_prefix("log".to_owned())
+ .log_path(dir.as_ref().to_owned())
+ .runtime_handle(runtime.handle().to_owned())
+ .build()
+ .unwrap();
+ let logger_0 = file_manager.build_logger("logger 0").unwrap();
+ let logger_1 = file_manager.build_logger("logger 1").unwrap();
+
+ // Flush the loggers so that the files are created.
+ runtime.block_on(flush_loggers(vec![logger_0, logger_1]));
+
// Expect no log file created as no packet is received.
let log_path = dir.as_ref().to_owned().join("log.pcapng");
assert!(fs::read(log_path).is_err());
@@ -503,29 +549,22 @@
let dir_root = Path::new("./uwb_test_dir_123");
let dir = dir_root.join("this/path/doesnt/exist");
let log_path = dir.join("log.pcapng");
- {
- let runtime = Builder::new_multi_thread().enable_all().build().unwrap();
- let mut file_manager = PcapngUciLoggerFactoryBuilder::new()
- .buffer_size(1024)
- .filename_prefix("log".to_owned())
- .log_path(dir.clone())
- .runtime_handle(runtime.handle().to_owned())
- .build()
- .unwrap();
- let mut logger_0 = file_manager.build_logger("logger 0").unwrap();
- let packet_0 = UciVendor_A_NotificationBuilder { opcode: 0, payload: None }.build();
- logger_0.log_uci_control_packet(packet_0.into());
- // Sleep needed to guarantee handling pending logs before runtime goes out of scope.
- let mut timeout = 100;
- let timeout_slice = 10;
- loop {
- if log_path.exists() || timeout == 0 {
- break;
- }
- thread::sleep(time::Duration::from_millis(timeout_slice));
- timeout -= timeout_slice;
- }
- }
+
+ let runtime = Builder::new_multi_thread().enable_all().build().unwrap();
+ let mut file_manager = PcapngUciLoggerFactoryBuilder::new()
+ .buffer_size(1024)
+ .filename_prefix("log".to_owned())
+ .log_path(dir.clone())
+ .runtime_handle(runtime.handle().to_owned())
+ .build()
+ .unwrap();
+ let mut logger_0 = file_manager.build_logger("logger 0").unwrap();
+ let packet_0 = UciVendor_A_NotificationBuilder { opcode: 0, payload: None }.build();
+ logger_0.log_uci_control_packet(packet_0.into());
+
+ // Flush all the loggers so that the files are created and all packets written.
+ runtime.block_on(flush_loggers(vec![logger_0]));
+
// Expect the dir was created.
assert!(dir.is_dir());
// Expect the log file exists.
@@ -537,38 +576,30 @@
#[test]
fn test_single_file_write() {
let dir = tempdir().unwrap();
- let last_file_expected = dir.as_ref().to_owned().join("log.pcapng");
- {
- let runtime = Builder::new_multi_thread().enable_all().build().unwrap();
- let mut file_manager = PcapngUciLoggerFactoryBuilder::new()
- .buffer_size(1024)
- .filename_prefix("log".to_owned())
- .log_path(dir.as_ref().to_owned())
- .runtime_handle(runtime.handle().to_owned())
- .build()
- .unwrap();
- let mut logger_0 = file_manager.build_logger("logger 0").unwrap();
- let packet_0 = UciVendor_A_NotificationBuilder { opcode: 0, payload: None }.build();
- logger_0.log_uci_control_packet(packet_0.into());
- let mut logger_1 = file_manager.build_logger("logger 1").unwrap();
- let packet_1 = UciVendor_A_NotificationBuilder { opcode: 1, payload: None }.build();
- logger_1.log_uci_control_packet(packet_1.into());
- let packet_2 = UciVendor_A_NotificationBuilder { opcode: 2, payload: None }.build();
- logger_0.log_uci_control_packet(packet_2.into());
- // Sleep needed to guarantee handling pending logs before runtime goes out of scope.
- let mut timeout = 100;
- let timeout_slice = 10;
- loop {
- if last_file_expected.exists() || timeout == 0 {
- break;
- }
- thread::sleep(time::Duration::from_millis(timeout_slice));
- timeout -= timeout_slice;
- }
- }
+ let runtime = Builder::new_multi_thread().enable_all().build().unwrap();
+ let mut file_manager = PcapngUciLoggerFactoryBuilder::new()
+ .buffer_size(1024)
+ .filename_prefix("log".to_owned())
+ .log_path(dir.as_ref().to_owned())
+ .runtime_handle(runtime.handle().to_owned())
+ .build()
+ .unwrap();
+ let mut logger_0 = file_manager.build_logger("logger 0").unwrap();
+ let packet_0 = UciVendor_A_NotificationBuilder { opcode: 0, payload: None }.build();
+ logger_0.log_uci_control_packet(packet_0.into());
+ let mut logger_1 = file_manager.build_logger("logger 1").unwrap();
+ let packet_1 = UciVendor_A_NotificationBuilder { opcode: 1, payload: None }.build();
+ logger_1.log_uci_control_packet(packet_1.into());
+ let packet_2 = UciVendor_A_NotificationBuilder { opcode: 2, payload: None }.build();
+ logger_0.log_uci_control_packet(packet_2.into());
+
+ // Flush all the loggers so that the files are created and all packets written.
+ runtime.block_on(flush_loggers(vec![logger_0, logger_1]));
+
// Expect file log.pcapng consist of SHB->IDB(logger 0)->EPB(packet 0)->IDB(logger 1)
// ->EPB(packet 1)->EPB(packet 2)
let log_path = dir.as_ref().to_owned().join("log.pcapng");
+ assert!(log_path.is_file());
let log_content = fs::read(log_path).unwrap();
let block_info = get_block_info(log_content).unwrap();
assert_eq!(block_info.len(), 6);
@@ -583,41 +614,33 @@
#[test]
fn test_file_switch_epb_unfit_case() {
let dir = tempdir().unwrap();
- let last_file_expected = dir.as_ref().to_owned().join("log_2.pcapng");
- {
- let runtime = Builder::new_multi_thread().enable_all().build().unwrap();
- let mut file_manager_140 = PcapngUciLoggerFactoryBuilder::new()
- .buffer_size(1024)
- .filename_prefix("log".to_owned())
- .log_path(dir.as_ref().to_owned())
- .file_size(140)
- .runtime_handle(runtime.handle().to_owned())
- .build()
- .unwrap();
- let mut logger_0 = file_manager_140.build_logger("logger 0").unwrap();
- let packet_0 = UciVendor_A_NotificationBuilder { opcode: 0, payload: None }.build();
- logger_0.log_uci_control_packet(packet_0.into());
- let mut logger_1 = file_manager_140.build_logger("logger 1").unwrap();
- let packet_1 = UciVendor_A_NotificationBuilder { opcode: 1, payload: None }.build();
- logger_1.log_uci_control_packet(packet_1.into());
- let packet_2 = UciVendor_A_NotificationBuilder { opcode: 2, payload: None }.build();
- logger_0.log_uci_control_packet(packet_2.into());
- // Sleep needed to guarantee handling pending logs before runtime goes out of scope.
- let mut timeout = 100;
- let timeout_slice = 10;
- loop {
- if last_file_expected.exists() || timeout == 0 {
- break;
- }
- thread::sleep(time::Duration::from_millis(timeout_slice));
- timeout -= timeout_slice;
- }
- }
+ let runtime = Builder::new_multi_thread().enable_all().build().unwrap();
+ let mut file_manager_140 = PcapngUciLoggerFactoryBuilder::new()
+ .buffer_size(1024)
+ .filename_prefix("log".to_owned())
+ .log_path(dir.as_ref().to_owned())
+ .file_size(140)
+ .runtime_handle(runtime.handle().to_owned())
+ .build()
+ .unwrap();
+ let mut logger_0 = file_manager_140.build_logger("logger 0").unwrap();
+ let packet_0 = UciVendor_A_NotificationBuilder { opcode: 0, payload: None }.build();
+ logger_0.log_uci_control_packet(packet_0.into());
+ let mut logger_1 = file_manager_140.build_logger("logger 1").unwrap();
+ let packet_1 = UciVendor_A_NotificationBuilder { opcode: 1, payload: None }.build();
+ logger_1.log_uci_control_packet(packet_1.into());
+ let packet_2 = UciVendor_A_NotificationBuilder { opcode: 2, payload: None }.build();
+ logger_0.log_uci_control_packet(packet_2.into());
+
+ // Flush all the loggers so that the files are created and all packets written.
+ runtime.block_on(flush_loggers(vec![logger_0, logger_1]));
+
// Expect (Old to new):
// File 2: SHB->IDB->EPB->IDB (cannot fit next)
// File 1: SHB->IDB->IDB->EPB (cannot fit next)
// File 0: SHB->IDB->IDB->EPB
let log_path = dir.as_ref().to_owned().join("log_2.pcapng");
+ assert!(log_path.is_file());
let log_content = fs::read(log_path).unwrap();
let block_info = get_block_info(log_content).unwrap();
assert_eq!(block_info.len(), 4);
@@ -626,6 +649,7 @@
assert_eq!(block_info[2].0, 0x6); // EPB
assert_eq!(block_info[3].0, 0x1); // IDB
let log_path = dir.as_ref().to_owned().join("log_1.pcapng");
+ assert!(log_path.is_file());
let log_content = fs::read(log_path).unwrap();
let block_info = get_block_info(log_content).unwrap();
assert_eq!(block_info.len(), 4);
@@ -634,6 +658,7 @@
assert_eq!(block_info[2].0, 0x1); // IDB
assert_eq!(block_info[3].0, 0x6); // EPB
let log_path = dir.as_ref().to_owned().join("log.pcapng");
+ assert!(log_path.is_file());
let log_content = fs::read(log_path).unwrap();
let block_info = get_block_info(log_content).unwrap();
assert_eq!(block_info.len(), 4);
@@ -646,40 +671,32 @@
#[test]
fn test_file_switch_idb_unfit_case() {
let dir = tempdir().unwrap();
- let last_file_expected = dir.as_ref().to_owned().join("log_1.pcapng");
- {
- let runtime = Builder::new_multi_thread().enable_all().build().unwrap();
- let mut file_manager_144 = PcapngUciLoggerFactoryBuilder::new()
- .buffer_size(1024)
- .filename_prefix("log".to_owned())
- .log_path(dir.as_ref().to_owned())
- .file_size(144)
- .runtime_handle(runtime.handle().to_owned())
- .build()
- .unwrap();
- let mut logger_0 = file_manager_144.build_logger("logger 0").unwrap();
- let packet_0 = UciVendor_A_NotificationBuilder { opcode: 0, payload: None }.build();
- logger_0.log_uci_control_packet(packet_0.into());
- let packet_2 = UciVendor_A_NotificationBuilder { opcode: 2, payload: None }.build();
- logger_0.log_uci_control_packet(packet_2.into());
- let mut logger_1 = file_manager_144.build_logger("logger 1").unwrap();
- let packet_1 = UciVendor_A_NotificationBuilder { opcode: 1, payload: None }.build();
- logger_1.log_uci_control_packet(packet_1.into());
- // Sleep needed to guarantee handling pending logs before runtime goes out of scope.
- let mut timeout = 100;
- let timeout_slice = 10;
- loop {
- if last_file_expected.exists() || timeout == 0 {
- break;
- }
- thread::sleep(time::Duration::from_millis(timeout_slice));
- timeout -= timeout_slice;
- }
- }
+ let runtime = Builder::new_multi_thread().enable_all().build().unwrap();
+ let mut file_manager_144 = PcapngUciLoggerFactoryBuilder::new()
+ .buffer_size(1024)
+ .filename_prefix("log".to_owned())
+ .log_path(dir.as_ref().to_owned())
+ .file_size(144)
+ .runtime_handle(runtime.handle().to_owned())
+ .build()
+ .unwrap();
+ let mut logger_0 = file_manager_144.build_logger("logger 0").unwrap();
+ let packet_0 = UciVendor_A_NotificationBuilder { opcode: 0, payload: None }.build();
+ logger_0.log_uci_control_packet(packet_0.into());
+ let packet_2 = UciVendor_A_NotificationBuilder { opcode: 2, payload: None }.build();
+ logger_0.log_uci_control_packet(packet_2.into());
+ let mut logger_1 = file_manager_144.build_logger("logger 1").unwrap();
+ let packet_1 = UciVendor_A_NotificationBuilder { opcode: 1, payload: None }.build();
+ logger_1.log_uci_control_packet(packet_1.into());
+
+ // Flush all the loggers so that the files are created and all packets written.
+ runtime.block_on(flush_loggers(vec![logger_0, logger_1]));
+
// Expect (Old to new):
// File 1: SHB->IDB->EPB->EPB (cannot fit next)
// File 0: SHB->IDB->IDB->EPB
let log_path = dir.as_ref().to_owned().join("log_1.pcapng");
+ assert!(log_path.is_file());
let log_content = fs::read(log_path).unwrap();
let block_info = get_block_info(log_content).unwrap();
assert_eq!(block_info.len(), 4);
@@ -688,6 +705,7 @@
assert_eq!(block_info[2].0, 0x6); // EPB
assert_eq!(block_info[3].0, 0x6); // EPB
let log_path = dir.as_ref().to_owned().join("log.pcapng");
+ assert!(log_path.is_file());
let log_content = fs::read(log_path).unwrap();
let block_info = get_block_info(log_content).unwrap();
assert_eq!(block_info.len(), 4);
@@ -701,24 +719,31 @@
#[test]
fn test_log_fail_safe() {
let dir = tempdir().unwrap();
- {
- let runtime = Builder::new_multi_thread().enable_all().build().unwrap();
- let mut file_manager_96 = PcapngUciLoggerFactoryBuilder::new()
- .buffer_size(1024)
- .filename_prefix("log".to_owned())
- .log_path(dir.as_ref().to_owned())
- .file_size(96) // Fails logging, as metadata takes 100
- .runtime_handle(runtime.handle().to_owned())
- .build()
- .unwrap();
- let mut logger_0 = file_manager_96.build_logger("logger 0").unwrap();
- let packet_0 = UciVendor_A_NotificationBuilder { opcode: 0, payload: None }.build();
- logger_0.log_uci_control_packet(packet_0.into());
- let packet_2 = UciVendor_A_NotificationBuilder { opcode: 2, payload: None }.build();
- logger_0.log_uci_control_packet(packet_2.into());
- let mut logger_1 = file_manager_96.build_logger("logger 1").unwrap();
- let packet_1 = UciVendor_A_NotificationBuilder { opcode: 1, payload: None }.build();
- logger_1.log_uci_control_packet(packet_1.into());
- }
+ let runtime = Builder::new_multi_thread().enable_all().build().unwrap();
+ let mut file_manager_96 = PcapngUciLoggerFactoryBuilder::new()
+ .buffer_size(1024)
+ .filename_prefix("log".to_owned())
+ .log_path(dir.as_ref().to_owned())
+ .file_size(96) // Fails logging, as metadata takes 100
+ .runtime_handle(runtime.handle().to_owned())
+ .build()
+ .unwrap();
+ let mut logger_0 = file_manager_96.build_logger("logger 0").unwrap();
+ let packet_0 = UciVendor_A_NotificationBuilder { opcode: 0, payload: None }.build();
+ logger_0.log_uci_control_packet(packet_0.into());
+ let packet_2 = UciVendor_A_NotificationBuilder { opcode: 2, payload: None }.build();
+ logger_0.log_uci_control_packet(packet_2.into());
+ let mut logger_1 = file_manager_96.build_logger("logger 1").unwrap();
+ let packet_1 = UciVendor_A_NotificationBuilder { opcode: 1, payload: None }.build();
+ logger_1.log_uci_control_packet(packet_1.into());
+
+ // Flush all the loggers so that the files are created and all packets written.
+ runtime.block_on(flush_loggers(vec![logger_0, logger_1]));
+
+ // Verify existence of the log files.
+ let log_path = dir.as_ref().to_owned().join("log_1.pcapng");
+ assert!(log_path.is_file());
+ let log_path = dir.as_ref().to_owned().join("log.pcapng");
+ assert!(log_path.is_file());
}
}
diff --git a/src/rust/uwb_core/src/uci/uci_logger_pcapng.rs b/src/rust/uwb_core/src/uci/uci_logger_pcapng.rs
index 279713b..5743913 100644
--- a/src/rust/uwb_core/src/uci/uci_logger_pcapng.rs
+++ b/src/rust/uwb_core/src/uci/uci_logger_pcapng.rs
@@ -15,6 +15,7 @@
//! Implements UciLoggerPcapng, a UciLogger with PCAPNG format log.
use log::warn;
+use tokio::sync::mpsc;
use uwb_uci_packets::{UciControlPacket, UciDataPacket};
use crate::uci::pcapng_block::{BlockBuilder, BlockOption, EnhancedPacketBlockBuilder};
@@ -39,6 +40,11 @@
warn!("UCI log: Logging to LogWritter failed.")
}
}
+
+ /// Flush the logs.
+ pub fn flush(&mut self) -> Option<mpsc::UnboundedReceiver<bool>> {
+ self.log_writer.flush()
+ }
}
impl UciLogger for UciLoggerPcapng {
diff --git a/src/rust/uwb_core/src/uci/uci_manager.rs b/src/rust/uwb_core/src/uci/uci_manager.rs
index f2563eb..24c0737 100644
--- a/src/rust/uwb_core/src/uci/uci_manager.rs
+++ b/src/rust/uwb_core/src/uci/uci_manager.rs
@@ -1179,6 +1179,7 @@
session_token: _,
uci_sequence_number: _,
status: _,
+ tx_count: _,
} => {
// Reset the UciDataSnd Retryer since we received a DataTransferStatusNtf.
let _ = self.uci_data_snd_retryer.take();
@@ -1233,10 +1234,12 @@
session_token,
uci_sequence_number,
status,
+ tx_count,
} => Ok(SessionNotification::DataTransferStatus {
session_token: self.get_session_id(&session_token).await?,
uci_sequence_number,
status,
+ tx_count,
}),
SessionNotification::DataCredit { session_token, credit_availability } => {
Ok(SessionNotification::DataCredit {
@@ -2760,6 +2763,7 @@
0x01, 0x02, 0x03, // AppData
];
let status = DataTransferNtfStatusCode::UciDataTransferStatusRepetitionOk;
+ let tx_count = 0x00;
let (uci_manager, mut mock_hal) = setup_uci_manager_with_session_active(
|mut hal| async move {
@@ -2776,6 +2780,7 @@
// TODO(b/282230468): Remove the u16-to-u8 conversion once spec is updated.
uci_sequence_number: uci_sequence_number.try_into().unwrap(),
status,
+ tx_count,
},
));
hal.expected_send_packet(data_packet_snd, ntfs, Ok(()));
@@ -2819,6 +2824,7 @@
];
let mut expected_data_snd_payload_fragment_2 = Vec::new();
let status = DataTransferNtfStatusCode::UciDataTransferStatusRepetitionOk;
+ let tx_count = 0x00;
// Setup the app data for both the Tx data packet and expected packet fragments.
let app_data_len_fragment_1 = 255 - expected_data_snd_payload_fragment_1.len();
@@ -2865,6 +2871,7 @@
// TODO(b/282230468): Remove the u16-to-u8 conversion once spec is updated.
uci_sequence_number: uci_sequence_number.try_into().unwrap(),
status,
+ tx_count,
},
));
hal.expected_send_packet(data_packet_snd_fragment_2, ntfs, Ok(()));
@@ -2892,6 +2899,7 @@
let oid = 0x0;
let session_id = 0x5;
let session_token = 0x5;
+ let tx_count = 0x01;
let dest_mac_address = vec![0xa0, 0xb0, 0xc0, 0xd0, 0xa1, 0xb1, 0xc1, 0xd1];
let uci_sequence_number: u16 = 0xa;
let app_data = vec![0x01, 0x02, 0x03];
@@ -2927,6 +2935,7 @@
// TODO(b/282230468): Remove the u16-to-u8 conversion once spec is updated.
uci_sequence_number: uci_sequence_number.try_into().unwrap(),
status,
+ tx_count,
},
));
hal.expected_send_packet(data_packet_snd, ntfs, Ok(()));
diff --git a/src/rust/uwb_uci_packets/uci_packets.pdl b/src/rust/uwb_uci_packets/uci_packets.pdl
index 7deb831..12bdb6c 100644
--- a/src/rust/uwb_uci_packets/uci_packets.pdl
+++ b/src/rust/uwb_uci_packets/uci_packets.pdl
@@ -193,7 +193,7 @@
DEVICE_MAC_ADDRESS = 0x06,
DST_MAC_ADDRESS = 0x07,
SLOT_DURATION = 0x08,
- RANGING_INTERVAL = 0x09,
+ RANGING_DURATION = 0x09,
STS_INDEX = 0x0A,
MAC_FCS_TYPE = 0x0B,
RANGING_ROUND_CONTROL = 0x0C,
@@ -209,6 +209,7 @@
PSDU_DATA_RATE = 0x16,
PREAMBLE_DURATION = 0x17,
LINK_LAYER_MODE = 0x18,
+ DATA_REPETITION_COUNT = 0x19,
RANGING_TIME_STRUCT = 0x1A,
SLOTS_PER_RR = 0x1B,
TX_ADAPTIVE_PAYLOAD_POWER = 0x1C,
@@ -247,7 +248,8 @@
RFU_APP_CFG_TLV_TYPE_RANGE_1 = 0x3D..0x44,
SESSION_KEY = 0x45,
SUBSESSION_KEY = 0x46,
- RFU_APP_CFG_TLV_TYPE_RANGE_2 = 0x47..0x9F,
+ SESSION_DATA_TRANSFER_STATUS_NTF_CONFIG = 0x47,
+ RFU_APP_CFG_TLV_TYPE_RANGE_2 = 0x48..0x9F,
VENDOR_SPECIFIC_APP_CFG_TLV_TYPE_RANGE_1 = 0xA0..0xDF {
// CCC specific
@@ -973,11 +975,11 @@
session_token: 32, // Session ID or Session Handle (based on UWBS version)
uci_sequence_number: 8,
status: DataTransferNtfStatusCode,
- // TODO(b/269779288): Add the tx_count field for implementing the DATA_REPETITION added in CR490.
+ tx_count: 8,
}
test DataTransferStatusNtf {
- "\x62\x05\x00\x06\x00\x00\x00\x00\x00\x00\x01\x01\x00",
+ "\x62\x05\x00\x06\x00\x00\x00\x00\x00\x00\x01\x01\x00\x00",
}
packet SessionQueryMaxDataSizeCmd : SessionConfigCommand (opcode = 0xB) { //QUERY_MAX_DATA_SIZE