|
CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
|
#include <BleUartService.h>
Public Types | |
| using | ConnectCallback = std::function<void()> |
| using | DisconnectCallback = std::function<void()> |
Public Member Functions | |
| bool | init () |
| Initializes Nordic UART Service over BLE GATT. | |
| void | deinit () |
| Deinitializes BLE UART service runtime state. | |
| bool | isInitialized () const |
| size_t | send (const uint8_t *data, size_t len) |
| Sends binary payload to connected BLE peer via notifications. | |
| size_t | send (const char *str) |
| Sends null-terminated string via BLE UART notifications. | |
| bool | txReady () const |
| Returns whether TX path is currently ready. | |
| size_t | available () const |
| Returns number of buffered RX bytes. | |
| int | getchar () |
| Reads one byte from RX ring buffer. | |
| size_t | read (uint8_t *buf, size_t maxLen) |
| Reads up to maxLen bytes from RX ring buffer. | |
| bool | isConnected () const |
| Returns whether BLE link is currently connected. | |
| void | onRxData (const uint8_t *data, size_t len) |
| Appends received BLE UART data into RX ring buffer. | |
| void | onConnectionChange (bool connected) |
| Handles BLE connection state changes. | |
| void | setOnConnect (ConnectCallback cb) |
| void | setOnDisconnect (DisconnectCallback cb) |
Static Public Member Functions | |
| static BleUartService & | instance () |
| Returns singleton BLE UART service instance. | |
BLE UART Service (Nordic UART Service compatible)
Provides serial communication over BLE using IBluetoothController API only.
Definition at line 19 of file BleUartService.h.
| using cdc::mod_ble_serial::BleUartService::ConnectCallback = std::function<void()> |
Definition at line 102 of file BleUartService.h.
| using cdc::mod_ble_serial::BleUartService::DisconnectCallback = std::function<void()> |
Definition at line 103 of file BleUartService.h.
| size_t cdc::mod_ble_serial::BleUartService::available | ( | ) | const |
Returns number of buffered RX bytes.
Check if data is available to read
Definition at line 202 of file BleUartService.cpp.
| void cdc::mod_ble_serial::BleUartService::deinit | ( | ) |
Deinitializes BLE UART service runtime state.
Deinitialize the GATT service
Definition at line 114 of file BleUartService.cpp.
References cdc::hal::BleUuid::from128(), cdc::hal::getBluetoothControllerInstance(), cdc::hal::IBluetoothController::INVALID_LISTENER, LOG_I, cdc::mod_ble_serial::NUS_SVC_UUID, and TAG.
Referenced by cdc::mod_ble_serial::BleSerialModule::stop(), and cdc::mod_ble_serial::BleSerialModule::toggle().
| int cdc::mod_ble_serial::BleUartService::getchar | ( | ) |
Reads one byte from RX ring buffer.
Read single character
Definition at line 219 of file BleUartService.cpp.
References available().
Referenced by read().
| bool cdc::mod_ble_serial::BleUartService::init | ( | ) |
Initializes Nordic UART Service over BLE GATT.
Initialize the GATT service via IBluetoothController API
Definition at line 44 of file BleUartService.cpp.
References GattServiceDef::characteristics, BleUuid::from128(), cdc::hal::getBluetoothControllerInstance(), instance(), LOG_E, LOG_I, cdc::hal::GattProp::NOTIFY, GattServiceDef::numCharacteristics, cdc::mod_ble_serial::NUS_RX_UUID, cdc::mod_ble_serial::NUS_SVC_UUID, cdc::mod_ble_serial::NUS_TX_UUID, onConnectionChange(), GattCharacteristic::onRead, onRxData(), GattCharacteristic::onWrite, GattCharacteristic::permissions, GattCharacteristic::properties, cdc::hal::GattPerm::READ, TAG, GattCharacteristic::uuid, GattServiceDef::uuid, GattCharacteristic::valueHandle, cdc::hal::GattPerm::WRITE, cdc::hal::GattProp::WRITE, and cdc::hal::GattProp::WRITE_NO_RSP.
|
static |
Returns singleton BLE UART service instance.
Definition at line 35 of file BleUartService.cpp.
Referenced by cdc::mod_ble_serial::bleInputAvailableHook(), cdc::mod_ble_serial::bleInputGetcharHook(), cdc::mod_ble_serial::bleOutputHook(), init(), cdc::mod_ble_serial::BleSerialModule::start(), cdc::mod_ble_serial::BleSerialModule::stop(), and cdc::mod_ble_serial::BleSerialModule::toggle().
| bool cdc::mod_ble_serial::BleUartService::isConnected | ( | ) | const |
Returns whether BLE link is currently connected.
Check if a device is connected
Definition at line 252 of file BleUartService.cpp.
References cdc::hal::getBluetoothControllerInstance().
|
inline |
Check if service is initialized
Definition at line 35 of file BleUartService.h.
| void cdc::mod_ble_serial::BleUartService::onConnectionChange | ( | bool | connected | ) |
Handles BLE connection state changes.
Handle connection state change (called from BLE connection callbacks)
| connected | New connection state. |
Definition at line 283 of file BleUartService.cpp.
Referenced by init().
| void cdc::mod_ble_serial::BleUartService::onRxData | ( | const uint8_t * | data, |
| size_t | len ) |
Appends received BLE UART data into RX ring buffer.
Handle incoming RX data (called from GATT write callback)
| data | Received payload. |
| len | Payload length. |
Definition at line 262 of file BleUartService.cpp.
Referenced by init().
| size_t cdc::mod_ble_serial::BleUartService::read | ( | uint8_t * | buf, |
| size_t | maxLen ) |
Reads up to maxLen bytes from RX ring buffer.
Read data into buffer
| buf | Output buffer |
| maxLen | Maximum bytes to read |
| buf | Output buffer. |
| maxLen | Maximum bytes to read. |
Definition at line 236 of file BleUartService.cpp.
References available(), and getchar().
| size_t cdc::mod_ble_serial::BleUartService::send | ( | const char * | str | ) |
Sends null-terminated string via BLE UART notifications.
Send string to connected device
| str | Null-terminated string |
| str | String to send. |
Definition at line 185 of file BleUartService.cpp.
References send().
| size_t cdc::mod_ble_serial::BleUartService::send | ( | const uint8_t * | data, |
| size_t | len ) |
Sends binary payload to connected BLE peer via notifications.
Send data to connected device
| data | Data to send |
| len | Data length |
| data | Data buffer. |
| len | Data length. |
Definition at line 138 of file BleUartService.cpp.
References cdc::hal::getBluetoothControllerInstance(), and isConnected().
Referenced by send().
|
inline |
Definition at line 105 of file BleUartService.h.
|
inline |
Definition at line 106 of file BleUartService.h.
| bool cdc::mod_ble_serial::BleUartService::txReady | ( | ) | const |
Returns whether TX path is currently ready.
Check if TX is ready (not congested)
Definition at line 194 of file BleUartService.cpp.
References isConnected().