-
Notifications
You must be signed in to change notification settings - Fork 258
Expand file tree
/
Copy pathBleConnectionStatus.cpp
More file actions
54 lines (46 loc) · 2.26 KB
/
Copy pathBleConnectionStatus.cpp
File metadata and controls
54 lines (46 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "BleConnectionStatus.h"
#include "NimBLELog.h"
#include "NimBLEAdvertising.h"
static const char* LOG_TAG = "BleConnectionStatus";
BleConnectionStatus::BleConnectionStatus(void)
{
}
void BleConnectionStatus::onConnect(NimBLEServer *pServer, NimBLEConnInfo& connInfo)
{
NIMBLE_LOGD(LOG_TAG, "onConnect - Connected Address: %s", std::string(connInfo.getAddress()).c_str());
pServer->updateConnParams(connInfo.getConnHandle(), 6, 7, 0, 600);
// A bonded central that reconnects may never fire onAuthenticationComplete
// (no new pairing ceremony: the link just re-encrypts with stored keys).
// Without this latch, `connected` stays false forever after any reboot and
// sendReport() silently drops every HID report while the serial side keeps
// replying `ok` - exactly the failure that looks like "joy.cpl is dead".
if (connInfo.isEncrypted() || connInfo.isBonded())
{
NIMBLE_LOGD(LOG_TAG, "onConnect - bonded/encrypted link, marking connected");
this->authenticatedConnHandles.insert(connInfo.getConnHandle());
this->connected = true;
}
// Keep advertising so additional centrals can connect alongside whichever
// peer is already connected.
if (pServer->getConnectedCount() < CONFIG_BT_NIMBLE_MAX_CONNECTIONS)
{
NIMBLE_LOGD(LOG_TAG, "onConnect - Restarting advertising to allow additional connections");
pServer->getAdvertising()->start();
}
}
void BleConnectionStatus::onDisconnect(NimBLEServer* pServer, NimBLEConnInfo& connInfo, int reason)
{
NIMBLE_LOGD(LOG_TAG, "onDisconnectConnect - Disconnected Address: %s", std::string(connInfo.getAddress()).c_str());
this->authenticatedConnHandles.erase(connInfo.getConnHandle());
this->connected = !this->authenticatedConnHandles.empty();
}
void BleConnectionStatus::onAuthenticationComplete(NimBLEConnInfo& connInfo)
{
NIMBLE_LOGD(LOG_TAG, "onAuthenticationComplete - Authenticated Address: %s", std::string(connInfo.getAddress()).c_str());
this->authenticatedConnHandles.insert(connInfo.getConnHandle());
this->connected = true;
}
void BleConnectionStatus::onSubscribe(NimBLECharacteristic *pCharacteristic, NimBLEConnInfo &connInfo, uint16_t subValue)
{
NIMBLE_LOGD(LOG_TAG, "onSubscribe: subValue=%d", subValue);
}