FakeBle

Struct FakeBle 

Source
pub struct FakeBle {
    pub show_pa_level: bool,
    pub mac_address: [u8; 6],
    /* private fields */
}
Expand description

A struct that implements BLE functionality.

This implementation is subject to Limitations.

Use ble_config() to properly configure the radio for BLE compatibility.

use rf24::radio::{prelude::*, RF24};
use rf24ble::{ble_config, radio::FakeBle};

let mut radio = RF24::new(ce_pin, spi_device, delay_impl);
radio.init()?;
radio.withConfig(&ble_config())?;
let mut ble = FakeBle::new();

radio.print_details()?;

Fields§

§show_pa_level: bool

Enable or disable the inclusion of the radio’s PA level in advertisements.

Enabling this feature occupies 3 bytes of the 18 available bytes in advertised payloads.

§mac_address: [u8; 6]

Set or get the BLE device’s MAC address.

A MAC address is required by BLE specifications. Use this attribute to uniquely identify the BLE device.

Implementations§

Source§

impl FakeBle

Source

pub fn new() -> Self

Instantiate a BLE device using a given instance of RF24.

The radio object is consumed because altering the radio’s setting will instigate unexpected behavior.

Source

pub fn set_name(&mut self, name: &str)

Set the BLE device’s name for inclusion in advertisements.

Setting a BLE device name will occupy more bytes from the 18 available bytes in advertisements. The exact number of bytes occupied is the length of the given name buffer plus 2.

The maximum supported name length is 10 bytes. So, up to 12 bytes (10 + 2) will be used in the advertising payload.

Source

pub fn get_name(&self, name: &mut [u8]) -> u8

Get the current BLE device name included in advertisements.

If no name is set (with FakeBle::set_name()), then this function does nothing. If a BLE device name has been set, then this function stores the bytes of the name in the given name buffer.

This function returns the number of bytes changed in the given name buffer.

Source

pub fn len_available(&self, hypothetical: &[u8]) -> i8

How many bytes are available in an advertisement payload?

The hypothetical parameter shall be the same buf value passed to FakeBle::send().

In addition to the given hypothetical payload length, this function also accounts for the current state of FakeBle::get_name() and FakeBle::show_pa_level.

If the returned value is less than 0, then the hypothetical payload will not be broadcasted.

Source

pub fn hop_channel<SPI, DO, DELAY>( &self, radio: &mut RF24<SPI, DO, DELAY>, ) -> Result<(), Nrf24Error<SpiError, OutputPinError>>
where SPI: SpiDevice, DO: OutputPin, DELAY: DelayNs,

Hop the radio’s current channel to the next BLE compliant frequency.

Use this function after FakeBle::send() to comply with BLE specifications. This is not required, but it is recommended to avoid bandwidth pollution.

Source

pub fn make_payload( &self, buf: &[u8], pa_level: Option<PaLevel>, channel: u8, ) -> Option<[u8; 32]>

Create a buffer to be used as a BLE advertisement payload.

This is a helper method to FakeBle::send(), but it is publicly exposed for advanced usage only (eg. FFI binding).

If the resulting payload length is larger than 32 bytes, then None is returned.

Source

pub fn send<SPI, DO, DELAY>( &self, radio: &mut RF24<SPI, DO, DELAY>, buf: &[u8], ) -> Result<bool, Nrf24Error<SpiError, OutputPinError>>
where SPI: SpiDevice, DO: OutputPin, DELAY: DelayNs,

Send a BLE advertisement

The buf parameter takes a buffer that has been already formatted for BLE specifications.

See our convenient API to

For a custom/proprietary BLE service, the given buf must adopt compliance with BLE specifications. For example, a buffer of n bytes shall be formed as follows:

indexvalue
0n - 1
10xFF
2 ... n - 1custom data
Source

pub fn read<SPI, DO, DELAY>( &self, radio: &mut RF24<SPI, DO, DELAY>, ) -> Result<Option<BlePayload>, Nrf24Error<SpiError, OutputPinError>>
where SPI: SpiDevice, DO: OutputPin, DELAY: DelayNs,

Read the first available payload from the radio’s RX FIFO and decode it into a BlePayload.

The payload must be decoded while the radio is on the same channel that it received the data. Otherwise, the decoding process will fail.

Use RF24::available to check if there is data in the radio’s RX FIFO.

If the payload was somehow malformed or incomplete, then this function returns a None value.

Trait Implementations§

Source§

impl Default for FakeBle

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.