-
Notifications
You must be signed in to change notification settings - Fork 0
/
BleStar.cpp
66 lines (43 loc) · 1.95 KB
/
BleStar.cpp
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
55
56
57
58
59
60
61
62
63
64
65
66
#include "BleStar.h"
BleStar::BleStar() { Log.initialize(&Serial, "BleStar:"); }
BleStar::BleStar(int messageBufferCapacity, int messageTableCapacity, int routingTableCapacity) {
mTable.initialize(messageBufferCapacity, messageTableCapacity);
rTable.initialize(routingTableCapacity);
//initializeBleStar(messageBufferCapacity, messageTableCapacity, routingTableCapacity);
}
void BleStar::initializeBleStar(int messageBufferCapacity, int messageTableCapacity, int routingTableCapacity) {
mTable.initialize(messageBufferCapacity, messageTableCapacity);
rTable.initialize(routingTableCapacity);
}
void BleStar::begin(int maxConnectionsAsPeripheral, int maxConnectionsAsCentral, int power, char * thisDeviceName, boolean isGateway) {
Log.initialize(&Serial, "BleStar:", Log.VERBOSE);
_pointerToBleStarClass = this;
_maxConnectionsAsPeripheral = maxConnectionsAsPeripheral;
_maxConnectionsAsCentral = min(MAX_CENTRAL_CONNECTIONS, maxConnectionsAsCentral);
_transmitPowerDbm = power;
_thisDeviceName = rTable.getNamePointerFromName(thisDeviceName, BLE_THIS_DEVICE_INDEX);
bleDeviceTable[0].peerName = _thisDeviceName;
_isGateway = isGateway;
CRC::initializeTables();
Message::initialize();
setUuidForSignalStrengthMonitoring(DEFAULT_UUID_FOR_SIGNAL_STRENGTH_MONITORING);
setUuidForConnection(isGateway ? DEFAULT_UUID_FOR_CONNECTION : DEFAULT_UUID_FOR_GATEWAY);
resetBleDeviceTable();
Log.v("starting BleStar with max %d peripheral, %d central connections\n", maxConnectionsAsPeripheral, maxConnectionsAsCentral);
#ifdef ARCHITECTURE_NRF52
Bluefruit.begin(maxConnectionsAsPeripheral, maxConnectionsAsCentral);
Bluefruit.setTxPower(power);
Bluefruit.setName(thisDeviceName);
bleDfu.begin();
centralBegin();
startScanning();
#else
#endif
peripheralBegin();
startAdvertisingForConnection();
}
void BleStar::loop() {
pollReceivingMessages();
pollRoutingMessages();
pollSendingMessages();
}