2020-03-30 01:44:20 +02:00
|
|
|
/*
|
|
|
|
* NimBLEService.h
|
|
|
|
*
|
|
|
|
* Created: on March 2, 2020
|
|
|
|
* Author H2zero
|
2020-05-14 06:03:56 +02:00
|
|
|
*
|
2020-03-30 01:44:20 +02:00
|
|
|
* Originally:
|
|
|
|
*
|
|
|
|
* BLEService.h
|
|
|
|
*
|
|
|
|
* Created on: Mar 25, 2017
|
|
|
|
* Author: kolban
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MAIN_NIMBLESERVICE_H_
|
|
|
|
#define MAIN_NIMBLESERVICE_H_
|
|
|
|
|
2020-05-14 06:03:56 +02:00
|
|
|
#include "nimconfig.h"
|
2021-09-07 05:14:43 +02:00
|
|
|
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
2020-05-14 06:03:56 +02:00
|
|
|
|
2020-03-30 01:44:20 +02:00
|
|
|
#include "NimBLEServer.h"
|
2020-06-11 16:06:16 +02:00
|
|
|
#include "NimBLECharacteristic.h"
|
2020-03-30 01:44:20 +02:00
|
|
|
#include "NimBLEUUID.h"
|
|
|
|
|
|
|
|
|
|
|
|
class NimBLEServer;
|
|
|
|
class NimBLECharacteristic;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The model of a %BLE service.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class NimBLEService {
|
|
|
|
public:
|
2021-02-08 16:28:32 +01:00
|
|
|
|
2021-12-29 16:12:07 +01:00
|
|
|
NimBLEService(const char* uuid);
|
|
|
|
NimBLEService(const NimBLEUUID &uuid);
|
2021-05-23 21:07:00 +02:00
|
|
|
~NimBLEService();
|
|
|
|
|
2021-02-08 16:28:32 +01:00
|
|
|
NimBLEServer* getServer();
|
|
|
|
|
|
|
|
NimBLEUUID getUUID();
|
|
|
|
uint16_t getHandle();
|
|
|
|
std::string toString();
|
|
|
|
void dump();
|
|
|
|
|
|
|
|
bool start();
|
|
|
|
|
2020-05-14 06:03:56 +02:00
|
|
|
NimBLECharacteristic* createCharacteristic(const char* uuid,
|
2020-06-08 02:42:28 +02:00
|
|
|
uint32_t properties =
|
|
|
|
NIMBLE_PROPERTY::READ |
|
2022-01-17 04:11:18 +01:00
|
|
|
NIMBLE_PROPERTY::WRITE,
|
|
|
|
uint16_t max_len = BLE_ATT_ATTR_MAX_LEN);
|
2020-05-14 06:03:56 +02:00
|
|
|
|
|
|
|
NimBLECharacteristic* createCharacteristic(const NimBLEUUID &uuid,
|
2020-06-08 02:42:28 +02:00
|
|
|
uint32_t properties =
|
|
|
|
NIMBLE_PROPERTY::READ |
|
2022-01-17 04:11:18 +01:00
|
|
|
NIMBLE_PROPERTY::WRITE,
|
|
|
|
uint16_t max_len = BLE_ATT_ATTR_MAX_LEN);
|
2020-05-14 06:03:56 +02:00
|
|
|
|
2021-05-23 21:07:00 +02:00
|
|
|
void addCharacteristic(NimBLECharacteristic* pCharacteristic);
|
2021-07-31 04:56:52 +02:00
|
|
|
void removeCharacteristic(NimBLECharacteristic* pCharacteristic, bool deleteChr = false);
|
2021-02-08 16:28:32 +01:00
|
|
|
NimBLECharacteristic* getCharacteristic(const char* uuid, uint16_t instanceId = 0);
|
|
|
|
NimBLECharacteristic* getCharacteristic(const NimBLEUUID &uuid, uint16_t instanceId = 0);
|
|
|
|
NimBLECharacteristic* getCharacteristicByHandle(uint16_t handle);
|
|
|
|
|
|
|
|
std::vector<NimBLECharacteristic*> getCharacteristics();
|
|
|
|
std::vector<NimBLECharacteristic*> getCharacteristics(const char* uuid);
|
|
|
|
std::vector<NimBLECharacteristic*> getCharacteristics(const NimBLEUUID &uuid);
|
|
|
|
|
2020-03-30 01:44:20 +02:00
|
|
|
|
|
|
|
private:
|
2020-05-14 06:03:56 +02:00
|
|
|
|
2020-06-08 02:42:28 +02:00
|
|
|
friend class NimBLEServer;
|
|
|
|
friend class NimBLEDevice;
|
|
|
|
|
|
|
|
uint16_t m_handle;
|
|
|
|
NimBLEUUID m_uuid;
|
2020-07-14 05:24:07 +02:00
|
|
|
ble_gatt_svc_def* m_pSvcDef;
|
|
|
|
uint8_t m_removed;
|
2020-06-08 02:42:28 +02:00
|
|
|
std::vector<NimBLECharacteristic*> m_chrVec;
|
2020-05-14 06:03:56 +02:00
|
|
|
|
2020-06-08 02:42:28 +02:00
|
|
|
}; // NimBLEService
|
2020-03-30 01:44:20 +02:00
|
|
|
|
2021-09-07 05:14:43 +02:00
|
|
|
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL */
|
2020-05-10 15:21:46 +02:00
|
|
|
#endif /* MAIN_NIMBLESERVICE_H_ */
|