Cordio: bring back device name & appearance function

Functions in Cordio for device name & appearance are currently
unused as they are both part of and dependent on deprecated
Mbed OS BLE APIs.

Nonetheless we want to keep them (and disable using macros)
so we can reintroduce them and make improvements in the future
as needed.
pull/12730/head
Lingkai Dong 2020-04-07 14:49:40 +01:00
parent 53550bb63b
commit d6eeab1744
3 changed files with 135 additions and 0 deletions

View File

@ -149,6 +149,29 @@ public:
*/ */
void setPreferredConnectionParams(const ::Gap::ConnectionParams_t& params); void setPreferredConnectionParams(const ::Gap::ConnectionParams_t& params);
#if 0 // Disabled until reworked and reintroduced to GattServer API
/**
* @see ::GattServer::setDeviceName
*/
ble_error_t setDeviceName(const uint8_t *deviceName);
/**
* @see ::GattServer::getDeviceName
*/
void getDeviceName(const uint8_t*& name, uint16_t& length);
/**
* @see ::GattServer::setAppearance
*/
void setAppearance(GapAdvertisingData::Appearance appearance);
/**
* @see ::GattServer::getAppearance
*/
GapAdvertisingData::Appearance getAppearance();
#endif // Disabled until reworked and reintroduced to GattServer API
/** /**
* @see ::GattServer::reset * @see ::GattServer::reset
*/ */

View File

@ -19,6 +19,73 @@ public:
virtual ~GenericAccessService() { } virtual ~GenericAccessService() { }
#if 0 // Disabled until reworked and reintroduced to GattServer API
virtual ble_error_t get_device_name_length(uint8_t& length) {
#if BLE_FEATURE_GATT_SERVER
const uint8_t* name = NULL;
uint16_t actual_length = 0;
gatt_server().getDeviceName(name, actual_length);
length = actual_length;
return BLE_ERROR_NONE;
#else
return BLE_ERROR_NOT_IMPLEMENTED;
#endif
}
virtual ble_error_t get_device_name(Span<uint8_t>& array) {
#if BLE_FEATURE_GATT_SERVER
const uint8_t* name = NULL;
uint16_t length = 0;
gatt_server().getDeviceName(name, length);
if (length > array.size()) {
return BLE_ERROR_PARAM_OUT_OF_RANGE;
}
memcpy(array.data(), name, length);
return BLE_ERROR_NONE;
#else
return BLE_ERROR_NOT_IMPLEMENTED;
#endif // BLE_FEATURE_GATT_SERVER
}
virtual ble_error_t set_device_name(const uint8_t* device_name) {
#if BLE_FEATURE_GATT_SERVER
return gatt_server().setDeviceName(device_name);
#else
return BLE_ERROR_NOT_IMPLEMENTED;
#endif // BLE_FEATURE_GATT_SERVER
}
virtual ble_error_t get_appearance(
GapAdvertisingData::Appearance& appearance
) {
#if BLE_FEATURE_GATT_SERVER
appearance = gatt_server().getAppearance();
return BLE_ERROR_NONE;
#else
return BLE_ERROR_NOT_IMPLEMENTED;
#endif // BLE_FEATURE_GATT_SERVER
}
virtual ble_error_t set_appearance(
GapAdvertisingData::Appearance appearance
) {
#if BLE_FEATURE_GATT_SERVER
gatt_server().setAppearance(appearance);
return BLE_ERROR_NONE;
#else
return BLE_ERROR_NOT_IMPLEMENTED;
#endif // BLE_FEATURE_GATT_SERVER
}
#endif // Disabled until reworked and reintroduced to GattServer API
virtual ble_error_t get_peripheral_prefered_connection_parameters( virtual ble_error_t get_peripheral_prefered_connection_parameters(
::Gap::ConnectionParams_t& parameters ::Gap::ConnectionParams_t& parameters
) { ) {

View File

@ -818,6 +818,51 @@ void GattServer::setPreferredConnectionParams(const ::Gap::ConnectionParams_t& p
memcpy(generic_access_service.ppcp + 6, &params.connectionSupervisionTimeout, 2); memcpy(generic_access_service.ppcp + 6, &params.connectionSupervisionTimeout, 2);
} }
#if 0 // Disabled until reworked and reintroduced to GattServer API
ble_error_t GattServer::setDeviceName(const uint8_t *deviceName)
{
size_t length = 0;
if (deviceName != NULL) {
length = strlen((const char*)deviceName);
}
if (length == 0) {
free(generic_access_service.device_name_value());
} else {
uint8_t* res = (uint8_t*) realloc(generic_access_service.device_name_value(), length);
if (res == NULL) {
return BLE_ERROR_NO_MEM;
}
generic_access_service.device_name_value() = res;
memcpy(res, deviceName, length);
}
generic_access_service.device_name_length = length;
return BLE_ERROR_NONE;
}
void GattServer::getDeviceName(const uint8_t*& name, uint16_t& length)
{
length = generic_access_service.device_name_length;
name = generic_access_service.device_name_value();
}
void GattServer::setAppearance(GapAdvertisingData::Appearance appearance)
{
generic_access_service.appearance = appearance;
}
GapAdvertisingData::Appearance GattServer::getAppearance()
{
return (GapAdvertisingData::Appearance) generic_access_service.appearance;
}
#endif // Disabled until reworked and reintroduced to GattServer API
ble_error_t GattServer::reset_(void) ble_error_t GattServer::reset_(void)
{ {
Base::reset_(); Base::reset_();