ruuvi.drivers.c  ${PROJECT_VERSION}
Drivers for external sensors and peripherals on embedded systems.
ruuvi_interface_communication_ble_advertising.h
Go to the documentation of this file.
1 #ifndef RUUVI_INTERFACE_COMMUNICATION_BLE_ADVERTISING_H
2 #define RUUVI_INTERFACE_COMMUNICATION_BLE_ADVERTISING_H
3 
14 #include "ruuvi_driver_error.h"
17 #include <stdint.h>
18 
19 #if RI_ADV_ENABLED
20 # define RUUVI_NRF5_SDK15_ADV_ENABLED RUUVI_NRF5_SDK15_ENABLED
21 # define RUUVI_NRF5_SDK15_ADV_EXTENDED_ENABLED RI_ADV_EXTENDED_ENABLED
22 #endif
23 
24 #define RUUVI_COMM_BLE_ADV_MAX_LENGTH (RI_COMM_BLE_PAYLOAD_MAX_LENGTH)
25 #define RUUVI_COMM_BLE_ADV_SCAN_LENGTH (RUUVI_COMM_BLE_ADV_MAX_LENGTH)
26 #define RUUVI_COMM_BLE_ADV_SCAN_BUFFER (RUUVI_COMM_BLE_ADV_MAX_LENGTH)
27 
28 /* @brief number of bytes in a MAC address */
29 #define BLE_MAC_ADDRESS_LENGTH 6
30 
32 typedef enum
33 {
39 
40 typedef struct
41 {
42  uint8_t addr[BLE_MAC_ADDRESS_LENGTH]; //<! MAC address, MSB first
43  int8_t rssi;
45  size_t data_len;
46  bool is_coded_phy;
47  uint8_t primary_phy;
49  uint8_t secondary_phy;
54  uint8_t ch_index;
56  int8_t tx_power;
63 } ri_adv_scan_t;
64 
82 
90 void ri_adv_rx_ble_phy_enabled_set (const bool is_le_1m_phy_enabled,
91  const bool is_le_2m_phy_enabled,
92  const bool is_le_coded_phy_enabled);
93 
102 void ri_adv_rx_set_max_advertisement_data_length (const uint8_t max_adv_length);
103 
104 /*
105  * @brief Uninitializes advertising module and scanning module.
106  *
107  * @param[out] channel comm api to send and receive data via advertisements.
108  * @retval RD_SUCCESS on success or if radio was not initialized.
109  * @retval RD_ERROR_INVALID_STATE if radio hardware was initialized by another radio module.
110  */
112 
113 /*
114  * @brief Setter for broadcast advertisement interval.
115  *
116  * Will take effect on next send. Has no effect on messages already queued.
117  *
118  * @param[in] ms Milliseconds, random delay of 0 - 10 ms will be added to the interval on
119  * every TX to avoid collisions. min 100 ms, max 10 000 ms.
120  * @retval RD_SUCCESS on success,
121  * @retval RD_ERROR_INVALID_PARAM if the parameter is outside allowed range.
122  */
124 
134 
144 
155 
156 
173 
183 
199 rd_status_t ri_adv_scan_response_setup (const char * const name,
200  const bool advertise_nus);
201 
215 
226 
254 rd_status_t ri_adv_scan_start (const uint32_t window_interval_ms,
255  const uint32_t window_size_ms);
256 
267 
277 
286 uint16_t ri_adv_parse_manuid (uint8_t * const data,
287  const size_t data_length);
288 
302 void ri_adv_enable_uuid (const bool enable_uuid);
303 
314 void ri_adv_set_service_uuid (const uint16_t uuid);
315 
316 #endif
uint32_t rd_status_t
bitfield for representing errors
Header to enable and disable module compilation.
Ruuvi error codes and error check function.
uint16_t ri_adv_parse_manuid(uint8_t *const data, const size_t data_length)
Parse Manufacturer ID from given Bluetooth scan data.
rd_status_t ri_adv_channels_set(const ri_radio_channels_t channels)
Set channels to use on radio. This has effect only on BLE advertising.
rd_status_t ri_adv_scan_start(const uint32_t window_interval_ms, const uint32_t window_size_ms)
setup scan window interval and window size.
ri_adv_type_t
Allowed advertisement types.
@ NONCONNECTABLE_SCANNABLE
Nonconnectable, scannable.
@ CONNECTABLE_NONSCANNABLE
Connectable, nonscannable.
@ NONCONNECTABLE_NONSCANNABLE
Nonconnectable, nonscannable.
@ CONNECTABLE_SCANNABLE
Connectable, scannable.
void ri_adv_rx_set_max_advertisement_data_length(const uint8_t max_adv_length)
Set maximum advertisement data length. This is used to limit the size of extended advertisement data.
rd_status_t ri_adv_tx_power_get(int8_t *dbm)
Get radio TX power.
rd_status_t ri_adv_manufacturer_id_set(const uint16_t id)
Set manufacturer ID of manufacturer specific advertisement.
rd_status_t ri_adv_init(ri_comm_channel_t *const channel)
Initialize Advertising module and scanning module.
rd_status_t ri_adv_scan_response_setup(const char *const name, const bool advertise_nus)
Configure advertising data with a scan response.
rd_status_t ri_adv_channels_enable(const ri_radio_channels_t channel)
Select active channels.
void ri_adv_set_service_uuid(const uint16_t uuid)
Configure Bluetooth GATT Service UUID to advertise in primary advertisement packet.
rd_status_t ri_adv_tx_interval_get(uint32_t *ms)
Getter for broadcast advertisement interval.
rd_status_t ri_adv_stop(void)
Stop ongoing advertisements.
rd_status_t ri_adv_uninit(ri_comm_channel_t *const channel)
rd_status_t ri_adv_type_set(ri_adv_type_t type)
Configure the type of advertisement.
rd_status_t ri_adv_tx_interval_set(const uint32_t ms)
rd_status_t ri_adv_tx_power_set(int8_t *dbm)
Set radio TX power.
void ri_adv_enable_uuid(const bool enable_uuid)
Set to true to enable advertising 16-bit service UUID in primary advertisement packet.
rd_status_t ri_adv_scan_stop(void)
Stop ongoing scanning.
void ri_adv_rx_ble_phy_enabled_set(const bool is_le_1m_phy_enabled, const bool is_le_2m_phy_enabled, const bool is_le_coded_phy_enabled)
Set BLE PHYs enabled or disabled for scanning.
bool is_coded_phy
True if Coded PHY was used.
size_t data_len
Length of received data.
control API for communication via outside world
Bitfield to describe related sensor data.