Skip to content

Commit 8707049

Browse files
committed
Update the API
1. Implement the peripheral API in BLEDevice 2. Move the unimplemented API to private as feature release
1 parent 8cc006f commit 8707049

File tree

5 files changed

+38
-21
lines changed

5 files changed

+38
-21
lines changed

libraries/BLE/src/BLEDescriptor.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,11 @@ const char* BLEDescriptor::uuid() const
124124

125125
const byte* BLEDescriptor::value() const
126126
{
127-
// TODO: Not support now
128127
return _value;
129128
}
130129

131130
int BLEDescriptor::valueLength() const
132131
{
133-
// TODO: Not support now
134132
return _value_size;
135133
}
136134

@@ -142,8 +140,7 @@ byte BLEDescriptor::operator[] (int offset) const
142140

143141
BLEDescriptor::operator bool() const
144142
{
145-
// TODO: Not support now
146-
return false;
143+
return (strlen(_uuid_cstr) > 3);
147144
}
148145

149146
bool BLEDescriptor::writeValue(const byte value[], int length)

libraries/BLE/src/BLEDescriptor.h

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,24 @@ class BLEDescriptor
4141

4242
virtual const byte* value() const; // returns the value buffer
4343
virtual int valueLength() const; // returns the current length of the value
44-
virtual byte operator[] (int offset) const; // returns a byte of the value at the specified offset
45-
44+
4645
virtual operator bool() const; // is the descriptor valid (discovered from peripheral)
4746

47+
unsigned char properties() const;
48+
int valueSize() const;
49+
private:
50+
char _uuid_cstr[37]; // The characteristic UUID
51+
BLEDevice _bledev;
52+
53+
unsigned char _properties; // The characteristic property
54+
55+
unsigned short _value_size; // The value size
56+
unsigned char* _value; // The value. Will delete after create the _internal
57+
58+
59+
// The API reserved for feature release
60+
// move here for temp
61+
4862
/**
4963
* @brief Write the value of the descriptor
5064
*
@@ -83,22 +97,13 @@ class BLEDescriptor
8397
* @note none
8498
*/
8599
bool writeValue(const char* value);
100+
virtual byte operator[] (int offset) const; // returns a byte of the value at the specified offset
86101

87102
// GATT client Write the value of the descriptor
88103
virtual bool write(const byte value[], int length);
89104
bool write(const byte value[], int length, int offset);
90105
bool write(const char* value);
91106
bool read();
92-
unsigned char properties() const;
93-
int valueSize() const;
94-
private:
95-
char _uuid_cstr[37]; // The characteristic UUID
96-
BLEDevice _bledev;
97-
98-
unsigned char _properties; // The characteristic property
99-
100-
unsigned short _value_size; // The value size
101-
unsigned char* _value; // The value. Will delete after create the _internal
102107
};
103108

104109
#endif

libraries/BLE/src/BLEDevice.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,7 @@ BLEDevice BLEDevice::central()
182182

183183
BLEDevice BLEDevice::peripheral()
184184
{
185-
// TODO: How to get the target devices
186-
BLEDevice temp;
187-
return temp;
185+
return BLEDeviceManager::instance()->peripheral();
188186
}
189187

190188
BLEDevice::operator bool() const
@@ -197,6 +195,7 @@ BLEDevice::operator bool() const
197195
// if (*this != device)
198196
// {
199197
// memcpy(&(this->_bt_addr), &(device._bt_addr), sizeof (bt_addr_le_t));
198+
// memcpy(*this->_conn_param, &device._conn_param, sizeof (bt_le_conn_param));
200199
// }
201200
// return *this;
202201
//}

libraries/BLE/src/internal/BLEDeviceManager.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ BLEDeviceManager::BLEDeviceManager():
4545
_adv_data_idx(0),
4646
_local_name(""),
4747
_state(BLE_PERIPH_STATE_NOT_READY),
48-
_local_ble(NULL)
48+
_local_ble(NULL),
49+
_peer_peripheral_index(0)
4950
{
5051
memset(&_local_bda, 0, sizeof(_local_bda));
5152
memset(&_wait_for_connect_peripheral, 0, sizeof(_wait_for_connect_peripheral));
@@ -490,8 +491,22 @@ BLEDevice BLEDeviceManager::central()
490491

491492
BLEDevice BLEDeviceManager::peripheral()
492493
{
493-
// TODO
494494
BLEDevice temp;
495+
for (int i = 0; i < BLE_MAX_CONN_CFG; i++)
496+
{
497+
if (_peer_peripheral_index >= BLE_MAX_CONN_CFG)
498+
{
499+
_peer_peripheral_index = 0;
500+
}
501+
const bt_addr_le_t & addr = _peer_peripheral[_peer_peripheral_index];
502+
_peer_peripheral_index++;
503+
504+
if (true == BLEUtils::macAddressValid(addr))
505+
{
506+
temp.setAddress(addr);
507+
break;
508+
}
509+
}
495510
return temp;
496511
}
497512

libraries/BLE/src/internal/BLEDeviceManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ class BLEDeviceManager
424424
// Connected device object
425425
bt_addr_le_t _peer_central;
426426
bt_addr_le_t _peer_peripheral[BLE_MAX_CONN_CFG];
427+
uint8_t _peer_peripheral_index;
427428
uint8_t _peer_peripheral_adv_data[BLE_MAX_CONN_CFG][BLE_MAX_ADV_SIZE];
428429
uint8_t _peer_peripheral_adv_data_len[BLE_MAX_CONN_CFG];
429430
uint8_t _peer_peripheral_adv_rssi[BLE_MAX_CONN_CFG];

0 commit comments

Comments
 (0)