|
Bluenet
5.7.0
Bluenet, firmware for nRF52 smart home devices
|
Class that enables you to connect to a device, and perform write or read operations. More...
#include <cs_BleCentral.h>


Public Member Functions | |
| void | init () |
| Initializes the class: More... | |
| cs_ret_code_t | connect (const device_address_t &address, uint16_t timeoutMs=3000) |
| Connect to a device. More... | |
| cs_ret_code_t | disconnect () |
| Terminate current connection. More... | |
| cs_ret_code_t | discoverServices (const UUID *uuids, uint8_t uuidCount) |
| Discover services. More... | |
| cs_ret_code_t | read (uint16_t handle) |
| Read data from a characteristic. More... | |
| cs_ret_code_t | write (uint16_t handle, const uint8_t *data, uint16_t len) |
| Write data to a characteristic. More... | |
| cs_ret_code_t | writeNotificationConfig (uint16_t cccdHandle, bool enableNotifications) |
| Performs a write() with the value to enable or disable notifications. More... | |
| cs_data_t | requestWriteBuffer () |
| Request the write buffer. More... | |
| bool | isConnected () |
| Check whether this crownstone is connected as central. More... | |
| bool | isBusy () |
| Check whether an operation is in progress. More... | |
| void | onBleEvent (const ble_evt_t *event) |
| Internal usage: to be called on BLE events. More... | |
| void | onDiscoveryEvent (ble_db_discovery_evt_t &event) |
| Internal usage. More... | |
| void | handleEvent (event_t &event) |
| Internal usage. More... | |
Static Public Member Functions | |
| static BleCentral & | getInstance () |
Private Types | |
| enum class | Operation : uint8_t { NONE , CONNECT_CLEARANCE , CONNECT , DISCONNECT , DISCOVERY , READ , WRITE } |
Private Member Functions | |
| BleCentral () | |
| BleCentral (BleCentral const &) | |
| void | operator= (BleCentral const &) |
| TYPIFY (CONFIG_SCAN_INTERVAL_625US) _scanInterval | |
| Scan setting to be used when connecting. More... | |
| TYPIFY (CONFIG_SCAN_WINDOW_625US) _scanWindow | |
| cs_ret_code_t | connectWithClearance (const device_address_t &address, uint16_t timeoutMs=3000) |
| Same as connect(), but now we have clearance. More... | |
| cs_ret_code_t | nextWrite (uint16_t handle, uint16_t offset) |
| Writes the next chunk of a long write. More... | |
| void | finalizeOperation (Operation operation, cs_ret_code_t retCode) |
| Finalize an operation. More... | |
| void | finalizeOperation (Operation operation, uint8_t *data, uint8_t dataSize) |
| void | sendOperationResult (event_t &event) |
| void | onGapEvent (uint16_t evtId, const ble_gap_evt_t &event) |
| Event handlers. More... | |
| void | onGattCentralEvent (uint16_t evtId, const ble_gattc_evt_t &event) |
| void | onConnectClearance () |
| void | onConnect (uint16_t connectionHandle, const ble_gap_evt_connected_t &event) |
| void | onDisconnect (const ble_gap_evt_disconnected_t &event) |
| void | onGapTimeout (const ble_gap_evt_timeout_t &event) |
| void | onMtu (uint16_t gattStatus, const ble_gattc_evt_exchange_mtu_rsp_t &event) |
| void | onRead (uint16_t gattStatus, const ble_gattc_evt_read_rsp_t &event) |
| void | onWrite (uint16_t gattStatus, const ble_gattc_evt_write_rsp_t &event) |
| void | onNotification (uint16_t gattStatus, const ble_gattc_evt_hvx_t &event) |
Private Member Functions inherited from EventListener | |
| EventListener () | |
| virtual | ~EventListener () |
| unregisters the listener. More... | |
| virtual void | handleEvent (event_t &event)=0 |
| Handle events. More... | |
| void | listen () |
| Registers this with the EventDispatcher. More... | |
Private Attributes | |
| device_address_t | _address |
| uint16_t | _timeoutMs |
| cs_data_t | _buf |
| Buffer used for reading and writing. More... | |
| uint16_t | _bufDataSize = 0 |
| How much data is actually in the buffer. More... | |
| uint16_t | _connectionHandle = BLE_CONN_HANDLE_INVALID |
| uint16_t | _currentHandle = BLE_GATT_HANDLE_INVALID |
| Keep up the handle of the current write or read operation. More... | |
| ble_db_discovery_t | _discoveryModule |
| uint16_t | _mtu = BLE_GATT_ATT_MTU_DEFAULT |
| Current MTU. More... | |
| Operation | _currentOperation = Operation::NONE |
| Operation in progress. More... | |
Class that enables you to connect to a device, and perform write or read operations.
Generally, you first connect, then discover, then perform read and/or write operations, and finally disconnect. Note that the disconnect event might happen at any time.
This class uses the EncryptionBuffer as write and read buffer.
TODO: introduce a timeout, so that a connection cannot remain open.
|
strongprivate |
|
private |
|
private |
| cs_ret_code_t BleCentral::connect | ( | const device_address_t & | address, |
| uint16_t | timeoutMs = 3000 |
||
| ) |
Connect to a device.
|
private |
Same as connect(), but now we have clearance.
| cs_ret_code_t BleCentral::disconnect | ( | ) |
Terminate current connection.
Can be called at any moment: will cancel the current operation if any.
| cs_ret_code_t BleCentral::discoverServices | ( | const UUID * | uuids, |
| uint8_t | uuidCount | ||
| ) |
Discover services.
Unfortunately you cannot simply discover all services, you will need to tell in advance which services you are looking for.
For each discovered service and characteristic, EVT_BLE_CENTRAL_DISCOVERY is dispatched. Use these events to figure out which handles to use for reading and writing.
| [in] | uuids | Array of UUIDs that will be attempted to discover. |
| [in] | uuidCount | Number of UUIDs in the array. |
|
private |
Finalize an operation.
Will always lead to sending an event, and resetting current operation.
|
private |
|
inlinestatic |
|
virtual |
Internal usage.
Implements EventListener.
| void BleCentral::init | ( | ) |
Initializes the class:
| bool BleCentral::isBusy | ( | ) |
Check whether an operation is in progress.
| bool BleCentral::isConnected | ( | ) |
Check whether this crownstone is connected as central.
|
private |
Writes the next chunk of a long write.
| void BleCentral::onBleEvent | ( | const ble_evt_t * | event | ) |
Internal usage: to be called on BLE events.
|
private |
|
private |
|
private |
| void BleCentral::onDiscoveryEvent | ( | ble_db_discovery_evt_t & | event | ) |
Internal usage.
|
private |
Event handlers.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
| cs_ret_code_t BleCentral::read | ( | uint16_t | handle | ) |
Read data from a characteristic.
| [in] | handle | The characteristic handle to read from. The handle was received during discovery. |
| cs_data_t BleCentral::requestWriteBuffer | ( | ) |
Request the write buffer.
You can then put your data in this buffer and use it as data in the write() command, so no copy has to take place.
|
private |
|
private |
Scan setting to be used when connecting.
Will be retrieved from State at init.
|
private |
| cs_ret_code_t BleCentral::write | ( | uint16_t | handle, |
| const uint8_t * | data, | ||
| uint16_t | len | ||
| ) |
Write data to a characteristic.
| [in] | handle | The characteristic handle to write to. The handle was received during discovery. |
| [in] | data | Pointer to data, which will be copied. If the pointer equals the requested write buffer, no copying will take place. |
| [in] | len | Length of the data to write. |
| cs_ret_code_t BleCentral::writeNotificationConfig | ( | uint16_t | cccdHandle, |
| bool | enableNotifications | ||
| ) |
|
private |
|
private |
Buffer used for reading and writing.
|
private |
How much data is actually in the buffer.
|
private |
|
private |
Keep up the handle of the current write or read operation.
|
private |
Operation in progress.
|
private |
|
private |
Current MTU.
|
private |