Skip to content

Commit 443602f

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 dc37c36 commit 443602f

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
@@ -123,13 +123,11 @@ const char* BLEDescriptor::uuid() const
123123

124124
const byte* BLEDescriptor::value() const
125125
{
126-
// TODO: Not support now
127126
return _value;
128127
}
129128

130129
int BLEDescriptor::valueLength() const
131130
{
132-
// TODO: Not support now
133131
return _value_size;
134132
}
135133

@@ -141,8 +139,7 @@ byte BLEDescriptor::operator[] (int offset) const
141139

142140
BLEDescriptor::operator bool() const
143141
{
144-
// TODO: Not support now
145-
return false;
142+
return (strlen(_uuid_cstr) > 3);
146143
}
147144

148145
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));
@@ -489,8 +490,22 @@ BLEDevice BLEDeviceManager::central()
489490

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

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)