Skip to content

Commit

Permalink
Expose RSSI property
Browse files Browse the repository at this point in the history
This adds rssi to PeripheralProperties to complement tx_power_level
that's already reported.

This exposes the rssi as i16 which is consistent with bluez and Windows.

This also updates tx_power_level to be an i16 for consistency - though
it is a small public API change.

Note: the corebluetooth backend currently always reports None for the TX
and RSSI power levels.

Addresses: deviceplug#76
  • Loading branch information
rib committed Aug 25, 2021
1 parent b40ddab commit 6b0378b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# Unreleased

## Features

- Added Received Signal Strength Indicator (RSSI) peripheral property

## Breaking changes

- Removed `CentralEvent::DeviceLost`. It wasn't emitted anywhere.
- Changed tx_power_level type from i8 to i16

# 0.8.1 (2021-08-14)

Expand Down
4 changes: 3 additions & 1 deletion src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ pub struct PeripheralProperties {
/// The local name. This is generally a human-readable string that identifies the type of device.
pub local_name: Option<String>,
/// The transmission power level for the device
pub tx_power_level: Option<i8>,
pub tx_power_level: Option<i16>,
/// The most recent Received Signal Strength Indicator for the device
pub rssi: Option<i16>,
/// Advertisement data specific to the device manufacturer. The keys of this map are
/// 'manufacturer IDs', while the values are arbitrary data.
pub manufacturer_data: HashMap<u16, Vec<u8>>,
Expand Down
3 changes: 2 additions & 1 deletion src/bluez/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ impl api::Peripheral for Peripheral {
address: (&device_info.mac_address).into(),
address_type: Some(device_info.address_type.into()),
local_name: device_info.name,
tx_power_level: device_info.tx_power.map(|tx_power| tx_power as i8),
tx_power_level: device_info.tx_power,
rssi: device_info.rssi,
manufacturer_data: device_info.manufacturer_data,
service_data: device_info.service_data,
services: device_info.services,
Expand Down
1 change: 1 addition & 0 deletions src/corebluetooth/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ impl Peripheral {
address_type: None,
local_name,
tx_power_level: None,
rssi: None,
manufacturer_data: HashMap::new(),
service_data: HashMap::new(),
services: Vec::new(),
Expand Down
5 changes: 4 additions & 1 deletion src/winrtble/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,12 @@ impl Peripheral {
// all panic here without returning a Result as documented.
// Value() is apparently the _right_ way to extract something from an IReference<T>...
if let Ok(tx) = tx_reference.Value() {
properties.tx_power_level = Some(tx as i8);
properties.tx_power_level = Some(tx);
}
}
if let Ok(rssi) = args.RawSignalStrengthInDBm() {
properties.rssi = Some(rssi);
}
}
}

Expand Down

0 comments on commit 6b0378b

Please sign in to comment.