Skip to content

Commit 855737b

Browse files
committed
Change internals to use less private friends, add comments in header files, make var types more consistent
1 parent 6c946ed commit 855737b

16 files changed

+452
-759
lines changed

libraries/CurieBle/src/BleAttribute.cpp

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,42 @@
2424
unsigned char BleAttribute::_numAttributes = 0;
2525

2626
BleAttribute::BleAttribute(const char* uuid, enum BleAttributeType type) :
27-
_uuidStr(uuid),
28-
_type(type)
27+
_uuid(uuid),
28+
_type(type),
29+
_handle(0)
2930
{
30-
BleUuid bleUuid(uuid);
31-
32-
_uuid = bleUuid.uuid();
3331
_numAttributes++;
3432
}
3533

36-
const char* BleAttribute::uuid() const {
37-
return _uuidStr;
34+
const char*
35+
BleAttribute::uuid() const {
36+
return _uuid;
3837
}
3938

40-
enum BleAttributeType BleAttribute::type() const {
39+
enum BleAttributeType
40+
BleAttribute::type() const {
4141
return this->_type;
4242
}
4343

44-
unsigned char BleAttribute::numAttributes() {
44+
uint16_t
45+
BleAttribute::handle() {
46+
return _handle;
47+
}
48+
49+
void
50+
BleAttribute::setHandle(uint16_t handle) {
51+
_handle = handle;
52+
}
53+
54+
55+
bt_uuid
56+
BleAttribute::btUuid() const {
57+
BleUuid bleUuid = BleUuid(uuid());
58+
59+
return bleUuid.uuid();
60+
}
61+
62+
unsigned char
63+
BleAttribute::numAttributes() {
4564
return _numAttributes;
4665
}

libraries/CurieBle/src/BleAttribute.h

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,37 @@ enum BleAttributeType {
2828
BleTypeDescriptor = 0x2900
2929
};
3030

31+
class BlePeripheral;
32+
3133
class BleAttribute {
3234
public:
35+
36+
/**
37+
* Get the string representation of the Attribute
38+
*
39+
* @return const char* string representation of the Attribute
40+
*/
41+
const char* uuid(void) const;
42+
43+
protected:
44+
friend BlePeripheral;
45+
3346
BleAttribute(const char* uuid, enum BleAttributeType type);
3447

35-
const char* uuid() const;
36-
enum BleAttributeType type() const;
48+
BleAttributeType type(void) const;
49+
bt_uuid btUuid(void) const;
50+
uint16_t handle(void);
51+
void setHandle(uint16_t handle);
3752

38-
protected:
39-
static unsigned char numAttributes();
4053

41-
struct bt_uuid _uuid;
54+
static unsigned char numAttributes(void);
4255

4356
private:
4457
static unsigned char _numAttributes;
4558

46-
const char* _uuidStr;
59+
const char* _uuid;
4760
enum BleAttributeType _type;
61+
uint16_t _handle;
4862
};
4963

5064
#endif // _BLE_ATTRIBUTE_H_INCLUDED

libraries/CurieBle/src/BleCentral.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ BleCentral::operator bool() const {
3636
return (memcmp(&_address, &zero, sizeof(_address)) != 0);
3737
}
3838

39-
bool
39+
boolean_t
4040
BleCentral::operator==(const BleCentral& rhs) const {
4141
return (memcmp(&_address, &rhs._address, sizeof(_address)) == 0);
4242
}
4343

44-
bool
44+
boolean_t
4545
BleCentral::operator!=(const BleCentral& rhs) const {
4646
return !(*this == rhs);
4747
}
4848

49-
bool
49+
boolean_t
5050
BleCentral::connected() {
5151
poll();
5252

@@ -55,23 +55,27 @@ BleCentral::connected() {
5555

5656
const char*
5757
BleCentral::address() const {
58-
static String address = "";
58+
static char address[18];
59+
60+
String addressStr = "";
5961

6062
for (int i = 5; i >= 0; i--) {
6163
unsigned char a = _address.addr[i];
6264

6365
if (a < 0x10) {
64-
address += "0";
66+
addressStr += "0";
6567
}
6668

67-
address += String(a, 16);
69+
addressStr += String(a, 16);
6870

6971
if (i > 0) {
70-
address += ":";
72+
addressStr += ":";
7173
}
7274
}
7375

74-
return address.c_str();
76+
strcpy(address, addressStr.c_str());
77+
78+
return address;
7579
}
7680

7781
void

libraries/CurieBle/src/BleCentral.h

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,35 @@ class BleCentral {
2828
friend class BlePeripheral;
2929

3030
public:
31-
operator bool() const;
32-
bool operator==(const BleCentral& rhs) const;
33-
bool operator!=(const BleCentral& rhs) const;
31+
/**
32+
* Is the Central connected
33+
*
34+
* @return boolean_t true if the central is connected, otherwise false
35+
*/
36+
boolean_t connected(void);
3437

35-
bool connected();
36-
const char* address() const;
37-
void poll();
38+
/**
39+
* Get the address of the Central in string form
40+
*
41+
* @return const char* address of the Central in string form
42+
*/
43+
const char* address(void) const;
44+
45+
/**
46+
* Disconnect the central if it is connected
47+
*
48+
* @return BleStatus result of operation
49+
*/
50+
BleStatus disconnect(void);
3851

39-
BleStatus disconnect();
52+
/**
53+
* Poll the central for events
54+
*/
55+
void poll(void);
56+
57+
operator bool(void) const;
58+
boolean_t operator==(const BleCentral& rhs) const;
59+
boolean_t operator!=(const BleCentral& rhs) const;
4060

4161
protected:
4262
BleCentral(BlePeripheral* peripheral);

0 commit comments

Comments
 (0)