8000 Fix Jira 768 BLE Appearance Value is 0 · sgbihu/corelibs-arduino101@e915fdc · GitHub
[go: up one dir, main page]

Skip to content

Commit e915fdc

Browse files
committed
Fix Jira 768 BLE Appearance Value is 0
Solution: Add service and appearance characteristic in the BLE lib. Changed files BLEDevice.cpp - check the local device BLEDeviceManager.cpp - Change the calls BLEDeviceManager.h - remove appearance member BLEProfileManager.cpp - Add GAP service and appearance characteristic BLEProfileManager.h - Add set/get API
1 parent 7d049ee commit e915fdc

File tree

5 files changed

+38
-12
lines changed

5 files changed

+38
-12
lines changed

libraries/CurieBLE/src/BLEDevice.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,11 @@ void BLEDevice::setDeviceName(const char* deviceName)
229229

230230
void BLEDevice::setAppearance(unsigned short appearance)
231231
{
232-
BLEDeviceManager::instance()->setAppearance(appearance);
232+
if (BLEUtils::isLocalBLE(*this))
233+
{
234+
// Only local device can set the appearance
235+
BLEDeviceManager::instance()->setAppearance(appearance);
236+
}
233237
}
234238

235239
int BLEDevice::addService(BLEService& attribute)

libraries/CurieBLE/src/internal/BLEDeviceManager.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ BLEDeviceManager::BLEDeviceManager():
4545
_connecting(false),
4646
_has_service_uuid(false),
4747
_has_service_solicit_uuid(false),
48-
_appearance(0),
4948
_manufacturer_data_length(0),
5049
_service_data_length(0),
5150
_adv_type(0),
@@ -355,7 +354,7 @@ BLEDeviceManager::setDeviceName()
355354

356355
void BLEDeviceManager::setAppearance(unsigned short appearance)
357356
{
358-
_appearance = appearance;
357+
BLEProfileManager::instance()->setAppearance(appearance);
359358
}
360359

361360
BLE_STATUS_T
@@ -1046,7 +1045,7 @@ String BLEDeviceManager::advertisedServiceUuid(const BLEDevice* device, int inde
10461045
if (index < service_cnt)
10471046
{
10481047
if (type == BT_DATA_UUID16_ALL ||
1049-
type == BT_DATA_UUID16_SOME)
1048+
type == BT_DATA_UUID16_SOME)
10501049
{
10511050
service_uuid.uuid.type = BT_UUID_TYPE_16;
10521051
memcpy(&BT_UUID_16(&service_uuid.uuid)->val, &adv_data[2], 2);
@@ -1218,7 +1217,7 @@ String BLEDeviceManager::deviceName(const BLEDevice* device)
12181217

12191218
int BLEDeviceManager::appearance()
12201219
{
1221-
return _appearance;
1220+
return BLEProfileManager::instance()->getAppearance();
12221221
}
12231222

12241223
BLEDeviceManager* BLEDeviceManager::instance()
@@ -1319,19 +1318,14 @@ bool BLEDeviceManager::advertiseDataProc(uint8_t type,
13191318
const uint8_t *dataPtr,
13201319
uint8_t data_len)
13211320
{
1322-
//Serial1.print("[AD]:");
1323-
//Serial1.print(type);
1324-
//Serial1.print(" data_len ");
1325-
//Serial1.println(data_len);
1326-
1327-
//const bt_data_t zero = {0, 0,0};
13281321
if (_adv_accept_critical.type == 0 &&
13291322
_adv_accept_critical.data_len == 0 &&
13301323
_adv_accept_critical.data == NULL)
13311324
{
13321325
// Not set the critical. Accept all.
13331326
return true;
13341327
}
1328+
13351329
if (type == _adv_accept_critical.type &&
13361330
data_len == _adv_accept_critical.data_len &&
13371331
0 == memcmp(dataPtr, _adv_accept_critical.data, data_len))

libraries/CurieBLE/src/internal/BLEDeviceManager.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,6 @@ class BLEDeviceManager
431431
bt_uuid_128_t _service_uuid;
432432
bool _has_service_solicit_uuid;
433433
bt_uuid_128_t _service_solicit_uuid;
434-
uint16_t _appearance;
435434
uint8_t _manufacturer_data[BLE_MAX_ADV_SIZE];
436435
uint8_t _manufacturer_data_length;
437436
bt_uuid_128_t _service_data_uuid;

libraries/CurieBLE/src/internal/BLEProfileManager.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include "BLEUtils.h"
2727

2828
BLEDevice BLE(BLEUtils::bleGetLoalAddress());
29+
static BLEService gapService("1800");
30+
static BLEUnsignedShortCharacteristic appearenceChrc("2a01", BLERead);
2931

3032
BLEProfileManager* BLEProfileManager::_instance = NULL;
3133

@@ -67,6 +69,8 @@ BLEProfileManager::BLEProfileManager ():
6769
_service_header_array[i].value = NULL;
6870
}
6971

72+
addService(BLE, gapService);
73+
gapService.addCharacteristic(appearenceChrc);
7074
pr_debug(LOG_MODULE_BLE, "%s-%d: Construct", __FUNCTION__, __LINE__);
7175
}
7276

@@ -1130,5 +1134,16 @@ uint8_t BLEProfileManager::serviceReadRspProc(bt_conn_t *conn,
11301134
return BT_GATT_ITER_STOP;
11311135
}
11321136

1137+
void BLEProfileManager::setAppearance(unsigned short appearance)
1138+
{
1139+
if (false == hasRegisterProfile())
1140+
{
1141+
appearenceChrc.setValue(appearance);
1142+
}
1143+
}
11331144

1145+
unsigned short BLEProfileManager::getA A935 ppearance()
1146+
{
1147+
return appearenceChrc.value();
1148+
}
11341149

libraries/CurieBLE/src/internal/BLEProfileManager.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,20 @@ class BLEProfileManager{
117117
bt_gatt_read_params_t *params,
118118
const void *data,
119119
uint16_t length);
120+
/**
121+
* @brief Set the appearance type for the BLE Peripheral Device
122+
*
123+
* See https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gap.appearance.xml
124+
* for available options.
125+
*
126+
* @param[in] appearance Appearance category identifier as defined by BLE Standard
127+
*
128+
* @return BleStatus indicating success or error
129+
*
130+
* @note This method must be called before the begin method
131+
*/
132+
void setAppearance(unsigned short appearance);
133+
unsigned short getAppearance();
120134
protected:
121135
friend ssize_t profile_write_process(bt_conn_t *conn,
122136
const bt_gatt_attr_t *attr,

0 commit comments

Comments
 (0)
0