diff --git a/examples/L2CAP/L2CAP_Client/main/main.cpp b/examples/L2CAP/L2CAP_Client/main/main.cpp index 9512916a..b1f00f02 100644 --- a/examples/L2CAP/L2CAP_Client/main/main.cpp +++ b/examples/L2CAP/L2CAP_Client/main/main.cpp @@ -27,31 +27,27 @@ const size_t HEAP_LEAK_THRESHOLD = 10; // Warn after 10 consecutive decreases class L2CAPChannelCallbacks: public BLEL2CAPChannelCallbacks { public: - void onConnect(NimBLEL2CAPChannel* channel) { - printf("L2CAP connection established\n"); + void onConnect(NimBLEL2CAPChannel* channel, uint16_t negotiatedMTU) override { + printf("L2CAP connection established (MTU %u)\n", negotiatedMTU); } - void onMTUChange(NimBLEL2CAPChannel* channel, uint16_t mtu) { - printf("L2CAP MTU changed to %d\n", mtu); + void onRead(NimBLEL2CAPChannel* channel, std::vector& data) override { + printf("L2CAP read %zu bytes\n", data.size()); } - - void onRead(NimBLEL2CAPChannel* channel, std::vector& data) { - printf("L2CAP read %d bytes\n", data.size()); - } - void onDisconnect(NimBLEL2CAPChannel* channel) { + void onDisconnect(NimBLEL2CAPChannel* channel) override { printf("L2CAP disconnected\n"); } }; class MyClientCallbacks: public BLEClientCallbacks { - void onConnect(BLEClient* pClient) { + void onConnect(BLEClient* pClient) override { printf("GAP connected\n"); pClient->setDataLen(251); theChannel = BLEL2CAPChannel::connect(pClient, L2CAP_PSM, L2CAP_MTU, new L2CAPChannelCallbacks()); } - void onDisconnect(BLEClient* pClient, int reason) { + void onDisconnect(BLEClient* pClient, int reason) override { printf("GAP disconnected (reason: %d)\n", reason); theDevice = NULL; theChannel = NULL; @@ -62,7 +58,7 @@ class MyClientCallbacks: public BLEClientCallbacks { class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks { - void onResult(const BLEAdvertisedDevice* advertisedDevice) { + void onResult(const BLEAdvertisedDevice* advertisedDevice) override { if (theDevice) { return; } printf("BLE Advertised Device found: %s\n", advertisedDevice->toString().c_str()); diff --git a/examples/L2CAP/L2CAP_Server/main/main.cpp b/examples/L2CAP/L2CAP_Server/main/main.cpp index 9d161536..5ef97a65 100644 --- a/examples/L2CAP/L2CAP_Server/main/main.cpp +++ b/examples/L2CAP/L2CAP_Server/main/main.cpp @@ -14,13 +14,13 @@ const size_t HEAP_LEAK_THRESHOLD = 10; // Warn after 10 consecutive decreases class GATTCallbacks: public BLEServerCallbacks { public: - void onConnect(BLEServer* pServer, BLEConnInfo& info) { + void onConnect(BLEServer* pServer, BLEConnInfo& info) override { /// Booster #1 pServer->setDataLen(info.getConnHandle(), 251); /// Booster #2 (especially for Apple devices) BLEDevice::getServer()->updateConnParams(info.getConnHandle(), 12, 12, 0, 200); } -}; +} gattCallbacks; class L2CAPChannelCallbacks: public BLEL2CAPChannelCallbacks { @@ -36,8 +36,8 @@ class L2CAPChannelCallbacks: public BLEL2CAPChannelCallbacks { std::vector buffer; // Buffer for incomplete frames public: - void onConnect(NimBLEL2CAPChannel* channel) { - printf("L2CAP connection established on PSM %d\n", L2CAP_PSM); + void onConnect(NimBLEL2CAPChannel* channel, uint16_t negotiatedMTU) override { + printf("L2CAP connection established on PSM %d (MTU %u)\n", L2CAP_PSM, negotiatedMTU); connected = true; totalBytesReceived = 0; totalFramesReceived = 0; @@ -49,7 +49,7 @@ class L2CAPChannelCallbacks: public BLEL2CAPChannelCallbacks { buffer.clear(); } - void onRead(NimBLEL2CAPChannel* channel, std::vector& data) { + void onRead(NimBLEL2CAPChannel* channel, std::vector& data) override { // Append new data to buffer buffer.insert(buffer.end(), data.begin(), data.end()); totalBytesReceived += data.size(); @@ -98,7 +98,7 @@ class L2CAPChannelCallbacks: public BLEL2CAPChannelCallbacks { } } - void onDisconnect(NimBLEL2CAPChannel* channel) { + void onDisconnect(NimBLEL2CAPChannel* channel) override { printf("\nL2CAP disconnected\n"); double elapsedSeconds = startTime > 0 ? (esp_timer_get_time() - startTime) / 1000000.0 : 0.0; double bytesPerSecond = elapsedSeconds > 0 ? totalBytesReceived / elapsedSeconds : 0.0; @@ -143,7 +143,7 @@ void app_main(void) { (void)channel; // prevent unused warning auto server = BLEDevice::createServer(); - server->setCallbacks(new GATTCallbacks()); + server->setCallbacks(gattCallbacks); auto advertising = BLEDevice::getAdvertising(); NimBLEAdvertisementData scanData;