Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return status 33 when ranging is not available between devices. #93

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/app_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,14 +499,18 @@ impl AppConfig {
pub fn is_compatible_for_ranging(&self, peer_config: &Self) -> bool {
self.device_role != peer_config.device_role
&& self.device_type != peer_config.device_type
&& peer_config
.dst_mac_address
.contains(&self.device_mac_address.unwrap())
&& self
.dst_mac_address
.contains(&peer_config.device_mac_address.unwrap())
}

pub fn can_start_ranging(&self, peer_config: &Self) -> bool {
self.is_compatible_for_ranging(peer_config)
&& peer_config
.dst_mac_address
.contains(&self.device_mac_address.unwrap())
}

pub fn can_start_data_transfer(&self) -> bool {
self.device_role == Some(uci::DeviceRole::Initiator)
}
Expand Down
12 changes: 11 additions & 1 deletion src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,23 @@ impl Device {
self.sessions.get_mut(&session_id)
}

pub fn is_compatible_for_ranging(&self, peer_session: &Session, session_id: u32) -> bool {
if let Some(session) = self.session(session_id) {
session
.app_config
.is_compatible_for_ranging(&peer_session.app_config)
} else {
false
}
}

pub fn can_start_ranging(&self, peer_session: &Session, session_id: u32) -> bool {
match self.session(session_id) {
Some(session) => {
session.session_state() == SessionState::SessionStateActive
&& session
.app_config
.is_compatible_for_ranging(&peer_session.app_config)
.can_start_ranging(&peer_session.app_config)
}
None => false,
}
Expand Down
88 changes: 58 additions & 30 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,25 +158,49 @@ struct Anchor {

fn make_measurement(
mac_address: &MacAddress,
local: RangingMeasurement,
remote: RangingMeasurement,
local: Option<RangingMeasurement>,
remote: Option<RangingMeasurement>,
) -> ShortAddressTwoWayRangingMeasurement {
if let MacAddress::Short(address) = mac_address {
ShortAddressTwoWayRangingMeasurement {
mac_address: u16::from_le_bytes(*address),
status: uci::Status::Ok,
nlos: 0, // in Line Of Sight
distance: local.range,
aoa_azimuth: local.azimuth as u16,
aoa_azimuth_fom: 100, // Yup, pretty sure about this
aoa_elevation: local.elevation as u16,
aoa_elevation_fom: 100, // Yup, pretty sure about this
aoa_destination_azimuth: remote.azimuth as u16,
aoa_destination_azimuth_fom: 100,
aoa_destination_elevation: remote.elevation as u16,
aoa_destination_elevation_fom: 100,
slot_index: 0,
rssi: u8::MAX,
match (local, remote) {
(Some(l), Some(r)) => {
ShortAddressTwoWayRangingMeasurement {
mac_address: u16::from_le_bytes(*address),
status: uci::Status::Ok,
nlos: 0, // in Line Of Sight
distance: l.range,
aoa_azimuth: l.azimuth as u16,
aoa_azimuth_fom: 100, // Yup, pretty sure about this
aoa_elevation: l.elevation as u16,
aoa_elevation_fom: 100, // Yup, pretty sure about this
aoa_destination_azimuth: r.azimuth as u16,
aoa_destination_azimuth_fom: 100,
aoa_destination_elevation: r.elevation as u16,
aoa_destination_elevation_fom: 100,
slot_index: 0,
rssi: u8::MAX,
}
}
// If a controlee drops out due to out of range or power off etc, send
// ranging measurement with status 33.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with code STATUS_RANGING_RX_TIMEOUT

(None, _) | (_, None) => {
ShortAddressTwoWayRangingMeasurement {
mac_address: u16::from_le_bytes(*address),
status: uci::Status::RangingRxTimeout,
nlos: 0, // in Line Of Sight
distance: 0,
aoa_azimuth: 0,
aoa_azimuth_fom: 100, // Yup, pretty sure about this
aoa_elevation: 0,
aoa_elevation_fom: 100, // Yup, pretty sure about this
aoa_destination_azimuth: 0,
aoa_destination_azimuth_fom: 100,
aoa_destination_elevation: 0,
aoa_destination_elevation_fom: 100,
slot_index: 0,
rssi: u8::MAX,
}
}
}
} else {
panic!("Extended address is not supported.")
Expand Down Expand Up @@ -416,19 +440,15 @@ 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 Some(local) = self
let local = self
.ranging_estimator
.estimate(&device.handle, &other.handle)
else {
continue;
};
let Some(remote) = self
.estimate(&device.handle, &other.handle);
let remote = self
.ranging_estimator
.estimate(&other.handle, &device.handle)
else {
continue;
};
.estimate(&other.handle, &device.handle);
measurements.push(make_measurement(mac_address, local, remote));
} else {
measurements.push(make_measurement(mac_address, None, None));
}
}

Expand All @@ -438,7 +458,7 @@ impl Pica {
continue;
}

if peer_device.can_start_ranging(session, session_id) {
if peer_device.is_compatible_for_ranging(session, session_id) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you check the wrong condition here: you should be checking if the session app_config contains the peer_device, but you check if the peer_device has a session that contains the session

let peer_mac_address = peer_device
.session(session_id)
.unwrap()
Expand All @@ -453,7 +473,15 @@ impl Pica {
.ranging_estimator
.estimate(&peer_device.handle, &device.handle)
.unwrap_or(Default::default());
measurements.push(make_measurement(&peer_mac_address, local, remote));
if peer_device.can_start_ranging(session, session_id) {
measurements.push(make_measurement(
&peer_mac_address,
Some(local),
Some(remote),
));
} else {
measurements.push(make_measurement(&peer_mac_address, None, None));
}
}

if device.can_start_data_transfer(session_id)
Expand Down Expand Up @@ -483,7 +511,7 @@ impl Pica {
)
.unwrap();
}
if session.is_session_info_ntf_enabled() {
if session.is_session_info_ntf_enabled() && !measurements.is_empty() {
device
.tx
.send(
Expand Down
Loading