2020-03-30 01:44:20 +02:00
|
|
|
/*
|
2024-12-13 03:21:03 +01:00
|
|
|
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
|
|
|
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
2020-03-30 01:44:20 +02:00
|
|
|
*
|
2024-12-13 03:21:03 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2020-05-14 06:03:56 +02:00
|
|
|
*
|
2024-12-13 03:21:03 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2020-03-30 01:44:20 +02:00
|
|
|
*
|
2024-12-13 03:21:03 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2020-03-30 01:44:20 +02:00
|
|
|
*/
|
|
|
|
|
2024-07-26 22:47:36 +02:00
|
|
|
#ifndef NIMBLE_CPP_SERVICE_H_
|
|
|
|
#define NIMBLE_CPP_SERVICE_H_
|
2020-03-30 01:44:20 +02:00
|
|
|
|
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
|
|
|
|
2024-07-26 22:47:36 +02:00
|
|
|
class NimBLEService;
|
2020-03-30 01:44:20 +02:00
|
|
|
|
2024-07-26 22:47:36 +02:00
|
|
|
# include "NimBLEAttribute.h"
|
|
|
|
# include "NimBLEServer.h"
|
|
|
|
# include "NimBLECharacteristic.h"
|
2020-03-30 01:44:20 +02:00
|
|
|
|
|
|
|
/**
|
2024-07-26 22:47:36 +02:00
|
|
|
* @brief The model of a BLE service.
|
2020-03-30 01:44:20 +02:00
|
|
|
*
|
|
|
|
*/
|
2024-07-26 22:47:36 +02:00
|
|
|
class NimBLEService : public NimBLELocalAttribute {
|
|
|
|
public:
|
2021-12-29 16:12:07 +01:00
|
|
|
NimBLEService(const char* uuid);
|
2024-07-26 22:47:36 +02:00
|
|
|
NimBLEService(const NimBLEUUID& uuid);
|
2021-05-23 21:07:00 +02:00
|
|
|
~NimBLEService();
|
|
|
|
|
2024-07-26 22:47:36 +02:00
|
|
|
NimBLEServer* getServer() const;
|
|
|
|
std::string toString() const;
|
|
|
|
void dump() const;
|
|
|
|
bool isStarted() const;
|
2021-02-08 16:28:32 +01:00
|
|
|
bool start();
|
2020-05-14 06:03:56 +02:00
|
|
|
NimBLECharacteristic* createCharacteristic(const char* uuid,
|
2024-07-26 22:47:36 +02:00
|
|
|
uint32_t properties = NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE,
|
|
|
|
uint16_t max_len = BLE_ATT_ATTR_MAX_LEN);
|
2020-05-14 06:03:56 +02:00
|
|
|
|
2024-07-26 22:47:36 +02:00
|
|
|
NimBLECharacteristic* createCharacteristic(const NimBLEUUID& uuid,
|
|
|
|
uint32_t properties = NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE,
|
|
|
|
uint16_t max_len = BLE_ATT_ATTR_MAX_LEN);
|
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);
|
2024-07-26 22:47:36 +02: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;
|
|
|
|
|
|
|
|
const std::vector<NimBLECharacteristic*>& getCharacteristics() const;
|
|
|
|
std::vector<NimBLECharacteristic*> getCharacteristics(const char* uuid) const;
|
|
|
|
std::vector<NimBLECharacteristic*> getCharacteristics(const NimBLEUUID& uuid) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class NimBLEServer;
|
|
|
|
|
|
|
|
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]{};
|
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 */
|
2024-07-26 22:47:36 +02:00
|
|
|
#endif /* NIMBLE_CPP_SERVICE_H_ */
|