forked from sandeepmistry/arduino-BLEPeripheral
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBLECentral.cpp
58 lines (42 loc) · 1.19 KB
/
BLECentral.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
#include "Arduino.h"
#include "BLEPeripheral.h"
#include "BLECentral.h"
#include "BLEUtil.h"
BLECentral::BLECentral(BLEPeripheral* peripheral) :
_peripheral(peripheral)
{
this->clearAddress();
}
BLECentral::operator bool() const {
unsigned char zero[6] = {0, 0, 0, 0, 0, 0};
return (memcmp(this->_address, zero, sizeof(this->_address)) != 0);
}
bool BLECentral::operator==(const BLECentral& rhs) const {
return (memcmp(this->_address, rhs._address, sizeof(this->_address)) == 0);
}
bool BLECentral::operator!=(const BLECentral& rhs) const {
return !(*this == rhs);
}
bool BLECentral::connected() {
this->poll();
return (*this && *this == this->_peripheral->central());
}
const char* BLECentral::address() const {
static char address[18];
BLEUtil::addressToString(this->_address, address);
return address;
}
void BLECentral::poll() {
this->_peripheral->poll();
}
void BLECentral::disconnect() {
if (this->connected()) {
this->_peripheral->disconnect();
}
}
void BLECentral::setAddress(const unsigned char* address) {
memcpy(this->_address, address, sizeof(this->_address));
}
void BLECentral::clearAddress() {
memset(this->_address, 0x00, sizeof(this->_address));
}