HF Interface Wrapper 0.1.0-dev
Embedded C++ hardware abstraction layer
Loading...
Searching...
No Matches
BaseBluetooth.h File Reference

Unified Bluetooth base class for all Bluetooth implementations. More...

#include "HardwareTypes.h"
#include <cctype>
#include <cstdint>
#include <functional>
#include <string>
#include <string_view>
#include <vector>
Include dependency graph for BaseBluetooth.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  hf_bluetooth_address_t
 Bluetooth address structure (6 bytes) More...
 
struct  hf_bluetooth_device_info_t
 Bluetooth device information structure. More...
 
struct  hf_bluetooth_classic_config_t
 Bluetooth Classic configuration structure. More...
 
struct  hf_bluetooth_ble_config_t
 Bluetooth Low Energy configuration structure. More...
 
struct  hf_bluetooth_gatt_service_t
 GATT service structure. More...
 
struct  hf_bluetooth_gatt_characteristic_t
 GATT characteristic structure. More...
 
class  BaseBluetooth
 Abstract base class for Bluetooth functionality. More...
 

Macros

#define HF_BLUETOOTH_ERR_LIST(X)
 HardFOC Bluetooth error codes macro list.
 
#define X(name, value, desc)   name = value,
 Generate Bluetooth error enumeration using X-macro pattern.
 
#define X(NAME, VALUE, DESC)
 Generate Bluetooth error enumeration using X-macro pattern.
 
#define X(name, value, desc)
 Generate Bluetooth error enumeration using X-macro pattern.
 

Typedefs

using hf_bluetooth_event_callback_t
 Bluetooth event callback function type.
 
using hf_bluetooth_data_callback_t
 Data received callback function type.
 

Enumerations

enum class  hf_bluetooth_err_t : hf_u8_t {
  BLUETOOTH_SUCCESS = 0 , BLUETOOTH_ERR_FAILURE = 1 , BLUETOOTH_ERR_INVALID_PARAM = 2 , BLUETOOTH_ERR_NOT_INITIALIZED = 3 ,
  BLUETOOTH_ERR_ALREADY_INITIALIZED = 4 , BLUETOOTH_ERR_NOT_ENABLED = 5 , BLUETOOTH_ERR_ALREADY_ENABLED = 6 , BLUETOOTH_ERR_NOT_CONNECTED = 7 ,
  BLUETOOTH_ERR_ALREADY_CONNECTED = 8 , BLUETOOTH_ERR_CONNECTION_FAILED = 9 , BLUETOOTH_ERR_DISCONNECTION_FAILED = 10 , BLUETOOTH_ERR_SCAN_FAILED = 11 ,
  BLUETOOTH_ERR_PAIR_FAILED = 12 , BLUETOOTH_ERR_UNPAIR_FAILED = 13 , BLUETOOTH_ERR_TIMEOUT = 14 , BLUETOOTH_ERR_NO_MEMORY = 15 ,
  BLUETOOTH_ERR_INVALID_ADDRESS = 16 , BLUETOOTH_ERR_DEVICE_NOT_FOUND = 17 , BLUETOOTH_ERR_SERVICE_NOT_FOUND = 18 , BLUETOOTH_ERR_CHARACTERISTIC_NOT_FOUND = 19 ,
  BLUETOOTH_ERR_AUTHENTICATION_FAILED = 20 , BLUETOOTH_ERR_AUTHORIZATION_FAILED = 21 , BLUETOOTH_ERR_ENCRYPTION_FAILED = 22 , BLUETOOTH_ERR_OPERATION_NOT_SUPPORTED = 23 ,
  BLUETOOTH_ERR_GATT_ERROR = 24 , BLUETOOTH_ERR_INVALID_STATE = 25 , BLUETOOTH_ERR_PERMISSION_DENIED = 26 , BLUETOOTH_ERR_BUSY = 27 ,
  BLUETOOTH_ERR_SECURITY_ERROR = 28 , BLUETOOTH_ERR_INIT_FAILED = 29 , BLUETOOTH_ERR_NOT_SUPPORTED = 30 , BLUETOOTH_ERR_ALREADY_STARTED = 31 ,
  BLUETOOTH_ERR_CONFIG_FAILED = 32 , BLUETOOTH_ERR_START_FAILED = 33 , BLUETOOTH_ERR_STOP_FAILED = 34 , BLUETOOTH_ERR_CONNECTION_NOT_FOUND = 35 ,
  BLUETOOTH_ERR_MAX_CONNECTIONS_REACHED = 36 , BLUETOOTH_ERR_SEND_FAILED = 37 , BLUETOOTH_ERR_GATT_SERVICE_ADD_FAILED = 38 , BLUETOOTH_ERR_GATT_CHAR_ADD_FAILED = 39 ,
  BLUETOOTH_ERR_GATT_SERVICE_NOT_FOUND = 40 , BLUETOOTH_ERR_GATT_SERVICE_START_FAILED = 41 , BLUETOOTH_ERR_UNKNOWN = 42
}
 
enum class  hf_bluetooth_mode_t : hf_u8_t { hf_bluetooth_mode_t::HF_BLUETOOTH_MODE_DISABLED = 0 , hf_bluetooth_mode_t::HF_BLUETOOTH_MODE_CLASSIC = 1 , hf_bluetooth_mode_t::HF_BLUETOOTH_MODE_BLE = 2 , hf_bluetooth_mode_t::HF_BLUETOOTH_MODE_DUAL = 3 }
 Bluetooth operating modes. More...
 
enum class  hf_bluetooth_device_type_t : hf_u8_t { hf_bluetooth_device_type_t::HF_BLUETOOTH_DEVICE_TYPE_UNKNOWN = 0 , hf_bluetooth_device_type_t::HF_BLUETOOTH_DEVICE_TYPE_CLASSIC = 1 , hf_bluetooth_device_type_t::HF_BLUETOOTH_DEVICE_TYPE_BLE = 2 , hf_bluetooth_device_type_t::HF_BLUETOOTH_DEVICE_TYPE_DUAL = 3 }
 Bluetooth device types. More...
 
enum class  hf_bluetooth_state_t : hf_u8_t {
  hf_bluetooth_state_t::HF_BLUETOOTH_STATE_DISABLED = 0 , hf_bluetooth_state_t::HF_BLUETOOTH_STATE_ENABLED = 1 , hf_bluetooth_state_t::HF_BLUETOOTH_STATE_SCANNING = 2 , hf_bluetooth_state_t::HF_BLUETOOTH_STATE_CONNECTING = 3 ,
  hf_bluetooth_state_t::HF_BLUETOOTH_STATE_CONNECTED = 4 , hf_bluetooth_state_t::HF_BLUETOOTH_STATE_DISCONNECTING = 5 , hf_bluetooth_state_t::HF_BLUETOOTH_STATE_PAIRING = 6 , hf_bluetooth_state_t::HF_BLUETOOTH_STATE_PAIRED = 7
}
 Bluetooth connection states. More...
 
enum class  hf_bluetooth_security_t : hf_u8_t {
  hf_bluetooth_security_t::HF_BLUETOOTH_SECURITY_NONE = 0 , hf_bluetooth_security_t::HF_BLUETOOTH_SECURITY_UNAUTHENTICATED = 1 , hf_bluetooth_security_t::HF_BLUETOOTH_SECURITY_AUTHENTICATED = 2 , hf_bluetooth_security_t::HF_BLUETOOTH_SECURITY_AUTHORIZED = 3 ,
  hf_bluetooth_security_t::HF_BLUETOOTH_SECURITY_ENCRYPTED = 4 , hf_bluetooth_security_t::HF_BLUETOOTH_SECURITY_AUTHENTICATED_SC = 5
}
 Bluetooth security levels. More...
 
enum class  hf_bluetooth_scan_type_t : hf_u8_t { hf_bluetooth_scan_type_t::HF_BLUETOOTH_SCAN_TYPE_PASSIVE = 0 , hf_bluetooth_scan_type_t::HF_BLUETOOTH_SCAN_TYPE_ACTIVE = 1 }
 Bluetooth scan types. More...
 
enum class  hf_bluetooth_scan_mode_t : hf_u8_t { hf_bluetooth_scan_mode_t::HF_BLUETOOTH_SCAN_MODE_GENERAL_INQUIRY = 0 , hf_bluetooth_scan_mode_t::HF_BLUETOOTH_SCAN_MODE_LE_GENERAL = 1 , hf_bluetooth_scan_mode_t::HF_BLUETOOTH_SCAN_MODE_LE_LIMITED = 2 }
 Bluetooth scan modes. More...
 
enum class  hf_bluetooth_connection_type_t : hf_u8_t { hf_bluetooth_connection_type_t::HF_BLUETOOTH_CONNECTION_TYPE_AUTO = 0 , hf_bluetooth_connection_type_t::HF_BLUETOOTH_CONNECTION_TYPE_CLASSIC = 1 , hf_bluetooth_connection_type_t::HF_BLUETOOTH_CONNECTION_TYPE_BLE = 2 }
 Bluetooth connection types. More...
 
enum class  hf_bluetooth_connection_state_t : hf_u8_t {
  hf_bluetooth_connection_state_t::HF_BLUETOOTH_CONNECTION_STATE_DISCONNECTED = 0 , hf_bluetooth_connection_state_t::HF_BLUETOOTH_CONNECTION_STATE_CONNECTING = 1 , hf_bluetooth_connection_state_t::HF_BLUETOOTH_CONNECTION_STATE_CONNECTED = 2 , hf_bluetooth_connection_state_t::HF_BLUETOOTH_CONNECTION_STATE_ADVERTISING = 3 ,
  hf_bluetooth_connection_state_t::HF_BLUETOOTH_CONNECTION_STATE_SCANNING = 4
}
 Bluetooth connection states. More...
 
enum class  hf_bluetooth_event_t : hf_u8_t {
  hf_bluetooth_event_t::HF_BLUETOOTH_EVENT_ENABLED = 0 , hf_bluetooth_event_t::HF_BLUETOOTH_EVENT_DISABLED = 1 , hf_bluetooth_event_t::HF_BLUETOOTH_EVENT_SCAN_START = 2 , hf_bluetooth_event_t::HF_BLUETOOTH_EVENT_SCAN_STOP = 3 ,
  hf_bluetooth_event_t::HF_BLUETOOTH_EVENT_DEVICE_FOUND = 4 , hf_bluetooth_event_t::HF_BLUETOOTH_EVENT_PAIR_REQUEST = 5 , hf_bluetooth_event_t::HF_BLUETOOTH_EVENT_PAIR_SUCCESS = 6 , hf_bluetooth_event_t::HF_BLUETOOTH_EVENT_PAIR_FAILED = 7 ,
  hf_bluetooth_event_t::HF_BLUETOOTH_EVENT_UNPAIR_SUCCESS = 8 , hf_bluetooth_event_t::HF_BLUETOOTH_EVENT_CONNECT_SUCCESS = 9 , hf_bluetooth_event_t::HF_BLUETOOTH_EVENT_CONNECT_FAILED = 10 , hf_bluetooth_event_t::HF_BLUETOOTH_EVENT_DISCONNECT = 11 ,
  hf_bluetooth_event_t::HF_BLUETOOTH_EVENT_DATA_RECEIVED = 12 , hf_bluetooth_event_t::HF_BLUETOOTH_EVENT_DATA_SENT = 13 , hf_bluetooth_event_t::HF_BLUETOOTH_EVENT_GATT_SERVICE_DISCOVERED = 14 , hf_bluetooth_event_t::HF_BLUETOOTH_EVENT_GATT_CHARACTERISTIC_READ = 15 ,
  hf_bluetooth_event_t::HF_BLUETOOTH_EVENT_GATT_CHARACTERISTIC_WRITE = 16 , hf_bluetooth_event_t::HF_BLUETOOTH_EVENT_GATT_NOTIFICATION = 17
}
 Bluetooth event types for callback functions. More...
 

Functions

constexpr std::string_view HfBluetoothErrToString (hf_bluetooth_err_t err) noexcept
 Convert hf_bluetooth_err_t to human-readable string.
 

Detailed Description

Unified Bluetooth base class for all Bluetooth implementations.

This file contains the declaration of the BaseBluetooth abstract class, which provides a comprehensive Bluetooth abstraction that serves as the base for all Bluetooth implementations in the HardFOC system. It supports both Bluetooth Classic and Bluetooth Low Energy (BLE), device discovery, pairing, connection management, and works across different hardware platforms including ESP32, and other Bluetooth-capable MCUs.

Author
Nebiyu Tadesse
Date
2025
Note
This class is not thread-safe. Use appropriate synchronization if accessed from multiple contexts.

Enumeration Type Documentation

◆ hf_bluetooth_err_t

enum class hf_bluetooth_err_t : hf_u8_t
strong
Enumerator
BLUETOOTH_SUCCESS 
BLUETOOTH_ERR_FAILURE 
BLUETOOTH_ERR_INVALID_PARAM 
BLUETOOTH_ERR_NOT_INITIALIZED 
BLUETOOTH_ERR_ALREADY_INITIALIZED 
BLUETOOTH_ERR_NOT_ENABLED 
BLUETOOTH_ERR_ALREADY_ENABLED 
BLUETOOTH_ERR_NOT_CONNECTED 
BLUETOOTH_ERR_ALREADY_CONNECTED 
BLUETOOTH_ERR_CONNECTION_FAILED 
BLUETOOTH_ERR_DISCONNECTION_FAILED 
BLUETOOTH_ERR_SCAN_FAILED 
BLUETOOTH_ERR_PAIR_FAILED 
BLUETOOTH_ERR_UNPAIR_FAILED 
BLUETOOTH_ERR_TIMEOUT 
BLUETOOTH_ERR_NO_MEMORY 
BLUETOOTH_ERR_INVALID_ADDRESS 
BLUETOOTH_ERR_DEVICE_NOT_FOUND 
BLUETOOTH_ERR_SERVICE_NOT_FOUND 
BLUETOOTH_ERR_CHARACTERISTIC_NOT_FOUND 
BLUETOOTH_ERR_AUTHENTICATION_FAILED 
BLUETOOTH_ERR_AUTHORIZATION_FAILED 
BLUETOOTH_ERR_ENCRYPTION_FAILED 
BLUETOOTH_ERR_OPERATION_NOT_SUPPORTED 
BLUETOOTH_ERR_GATT_ERROR 
BLUETOOTH_ERR_INVALID_STATE 
BLUETOOTH_ERR_PERMISSION_DENIED 
BLUETOOTH_ERR_BUSY 
BLUETOOTH_ERR_SECURITY_ERROR 
BLUETOOTH_ERR_INIT_FAILED 
BLUETOOTH_ERR_NOT_SUPPORTED 
BLUETOOTH_ERR_ALREADY_STARTED 
BLUETOOTH_ERR_CONFIG_FAILED 
BLUETOOTH_ERR_START_FAILED 
BLUETOOTH_ERR_STOP_FAILED 
BLUETOOTH_ERR_CONNECTION_NOT_FOUND 
BLUETOOTH_ERR_MAX_CONNECTIONS_REACHED 
BLUETOOTH_ERR_SEND_FAILED 
BLUETOOTH_ERR_GATT_SERVICE_ADD_FAILED 
BLUETOOTH_ERR_GATT_CHAR_ADD_FAILED 
BLUETOOTH_ERR_GATT_SERVICE_NOT_FOUND 
BLUETOOTH_ERR_GATT_SERVICE_START_FAILED 
BLUETOOTH_ERR_UNKNOWN