Files
esp-nimble-cpp/src/NimBLEService.h
T

71 lines
2.6 KiB
C++
Raw Normal View History

2020-03-29 17:44:20 -06:00
/*
* NimBLEService.h
*
* Created: on March 2, 2020
* Author H2zero
*
2020-03-29 17:44:20 -06:00
* Originally:
*
* BLEService.h
*
* Created on: Mar 25, 2017
* Author: kolban
*/
2024-07-26 14:47:36 -06:00
#ifndef NIMBLE_CPP_SERVICE_H_
#define NIMBLE_CPP_SERVICE_H_
2020-03-29 17:44:20 -06:00
#include "nimconfig.h"
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
2024-07-26 14:47:36 -06:00
class NimBLEService;
2020-03-29 17:44:20 -06:00
2024-07-26 14:47:36 -06:00
# include "NimBLEAttribute.h"
# include "NimBLEServer.h"
# include "NimBLECharacteristic.h"
2020-03-29 17:44:20 -06:00
/**
2024-07-26 14:47:36 -06:00
* @brief The model of a BLE service.
2020-03-29 17:44:20 -06:00
*
*/
2024-07-26 14:47:36 -06:00
class NimBLEService : public NimBLELocalAttribute {
public:
NimBLEService(const char* uuid);
2024-07-26 14:47:36 -06:00
NimBLEService(const NimBLEUUID& uuid);
~NimBLEService();
2024-07-26 14:47:36 -06:00
NimBLEServer* getServer() const;
std::string toString() const;
void dump() const;
bool isStarted() const;
bool start();
NimBLECharacteristic* createCharacteristic(const char* uuid,
2024-07-26 14:47:36 -06:00
uint32_t properties = NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE,
uint16_t max_len = BLE_ATT_ATTR_MAX_LEN);
2024-07-26 14:47:36 -06:00
NimBLECharacteristic* createCharacteristic(const NimBLEUUID& uuid,
uint32_t properties = NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE,
uint16_t max_len = BLE_ATT_ATTR_MAX_LEN);
void addCharacteristic(NimBLECharacteristic* pCharacteristic);
void removeCharacteristic(NimBLECharacteristic* pCharacteristic, bool deleteChr = false);
2024-07-26 14:47:36 -06:00
NimBLECharacteristic* getCharacteristic(const char* uuid, uint16_t instanceId = 0) const;
NimBLECharacteristic* getCharacteristic(const NimBLEUUID& uuid, uint16_t instanceId = 0) const;
NimBLECharacteristic* getCharacteristicByHandle(uint16_t handle) const;
2024-07-26 14:47:36 -06:00
const std::vector<NimBLECharacteristic*>& getCharacteristics() const;
std::vector<NimBLECharacteristic*> getCharacteristics(const char* uuid) const;
std::vector<NimBLECharacteristic*> getCharacteristics(const NimBLEUUID& uuid) const;
2024-07-26 14:47:36 -06:00
private:
friend class NimBLEServer;
2020-03-29 17:44:20 -06:00
2024-07-26 14:47:36 -06:00
std::vector<NimBLECharacteristic*> m_vChars{};
// Nimble requires an array of services to be sent to the api
// Since we are adding 1 at a time we create an array of 2 and set the type
// of the second service to 0 to indicate the end of the array.
ble_gatt_svc_def m_pSvcDef[2]{};
}; // NimBLEService
2020-03-29 17:44:20 -06:00
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL */
2024-07-26 14:47:36 -06:00
#endif /* NIMBLE_CPP_SERVICE_H_ */