forked from h2zero/esp-nimble-cpp
L2CAP is the underlying technology powering GATT. BLE 5 exposes L2CAP COC (Connection Oriented Channels) allowing a streaming API that leads to much higher throughputs than you can achieve with updating GATT characteristics. The patch follows the established infrastructure very closely. The main components are: - `NimBLEL2CAPChannel`, encapsulating an L2CAP COC. - `NimBLEL2CAPServer`, encapsulating the L2CAP service. - `Examples/L2CAP`, containing a client and a server application. Apart from these, only minor adjustments to the existing code was necessary.
37 lines
931 B
C++
37 lines
931 B
C++
//
|
|
// (C) Dr. Michael 'Mickey' Lauer <mickey@vanille-media.de>
|
|
//
|
|
#include "NimBLEL2CAPServer.h"
|
|
#include "NimBLEL2CAPChannel.h"
|
|
#include "NimBLEDevice.h"
|
|
#include "NimBLELog.h"
|
|
|
|
static const char* LOG_TAG = "NimBLEL2CAPServer";
|
|
|
|
NimBLEL2CAPServer::NimBLEL2CAPServer() {
|
|
|
|
// Nothing to do here...
|
|
}
|
|
|
|
NimBLEL2CAPServer::~NimBLEL2CAPServer() {
|
|
|
|
// Delete all services
|
|
for (auto service: this->services) {
|
|
delete service;
|
|
}
|
|
}
|
|
|
|
NimBLEL2CAPChannel* NimBLEL2CAPServer::createService(const uint16_t psm, const uint16_t mtu, NimBLEL2CAPChannelCallbacks* callbacks) {
|
|
|
|
auto service = new NimBLEL2CAPChannel(psm, mtu, callbacks);
|
|
auto rc = ble_l2cap_create_server(psm, mtu, NimBLEL2CAPChannel::handleL2capEvent, service);
|
|
|
|
if (rc != 0) {
|
|
NIMBLE_LOGE(LOG_TAG, "Could not ble_l2cap_create_server: %d", rc);
|
|
return nullptr;
|
|
}
|
|
|
|
this->services.push_back(service);
|
|
return service;
|
|
}
|