move get/set of deviceName and appearance to Gap
This commit is contained in:
parent
10ad7e4f1a
commit
4e77274ffc
4 changed files with 44 additions and 44 deletions
39
nRF51Gap.cpp
39
nRF51Gap.cpp
|
@ -312,3 +312,42 @@ ble_error_t nRF51Gap::setAddress(addr_type_t type, const uint8_t address[6])
|
|||
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
ble_error_t nRF51Gap::setDeviceName(const uint8_t *deviceName)
|
||||
{
|
||||
ble_gap_conn_sec_mode_t sec_mode;
|
||||
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); // no security is needed
|
||||
|
||||
if (sd_ble_gap_device_name_set(&sec_mode, deviceName, strlen((const char *)deviceName)) == NRF_SUCCESS) {
|
||||
return BLE_ERROR_NONE;
|
||||
} else {
|
||||
return BLE_ERROR_PARAM_OUT_OF_RANGE;
|
||||
}
|
||||
}
|
||||
|
||||
ble_error_t nRF51Gap::getDeviceName(uint8_t *deviceName, unsigned *lengthP)
|
||||
{
|
||||
if (sd_ble_gap_device_name_get(deviceName, (uint16_t *)lengthP) == NRF_SUCCESS) {
|
||||
return BLE_ERROR_NONE;
|
||||
} else {
|
||||
return BLE_ERROR_PARAM_OUT_OF_RANGE;
|
||||
}
|
||||
}
|
||||
|
||||
ble_error_t nRF51Gap::setAppearance(uint16_t appearance)
|
||||
{
|
||||
if (sd_ble_gap_appearance_set(appearance) == NRF_SUCCESS) {
|
||||
return BLE_ERROR_NONE;
|
||||
} else {
|
||||
return BLE_ERROR_PARAM_OUT_OF_RANGE;
|
||||
}
|
||||
}
|
||||
|
||||
ble_error_t nRF51Gap::getAppearance(uint16_t *appearanceP)
|
||||
{
|
||||
if (sd_ble_gap_appearance_get(appearanceP)) {
|
||||
return BLE_ERROR_NONE;
|
||||
} else {
|
||||
return BLE_ERROR_PARAM_OUT_OF_RANGE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,6 +47,11 @@ public:
|
|||
virtual ble_error_t stopAdvertising(void);
|
||||
virtual ble_error_t disconnect(void);
|
||||
|
||||
virtual ble_error_t setDeviceName(const uint8_t *deviceName);
|
||||
virtual ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP);
|
||||
virtual ble_error_t setAppearance(uint16_t appearance);
|
||||
virtual ble_error_t getAppearance(uint16_t *appearanceP);
|
||||
|
||||
void setConnectionHandle(uint16_t con_handle);
|
||||
uint16_t getConnectionHandle(void);
|
||||
|
||||
|
|
|
@ -213,45 +213,6 @@ ble_error_t nRF51GattServer::updateValue(uint16_t charHandle, uint8_t buffer[],
|
|||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
ble_error_t nRF51GattServer::setDeviceName(const uint8_t *deviceName)
|
||||
{
|
||||
ble_gap_conn_sec_mode_t sec_mode;
|
||||
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); // no security is needed
|
||||
|
||||
if (sd_ble_gap_device_name_set(&sec_mode, deviceName, strlen((const char *)deviceName)) == NRF_SUCCESS) {
|
||||
return BLE_ERROR_NONE;
|
||||
} else {
|
||||
return BLE_ERROR_PARAM_OUT_OF_RANGE;
|
||||
}
|
||||
}
|
||||
|
||||
ble_error_t nRF51GattServer::getDeviceName(uint8_t *deviceName, unsigned *lengthP)
|
||||
{
|
||||
if (sd_ble_gap_device_name_get(deviceName, (uint16_t *)lengthP) == NRF_SUCCESS) {
|
||||
return BLE_ERROR_NONE;
|
||||
} else {
|
||||
return BLE_ERROR_PARAM_OUT_OF_RANGE;
|
||||
}
|
||||
}
|
||||
|
||||
ble_error_t nRF51GattServer::setAppearance(uint16_t appearance)
|
||||
{
|
||||
if (sd_ble_gap_appearance_set(appearance) == NRF_SUCCESS) {
|
||||
return BLE_ERROR_NONE;
|
||||
} else {
|
||||
return BLE_ERROR_PARAM_OUT_OF_RANGE;
|
||||
}
|
||||
}
|
||||
|
||||
ble_error_t nRF51GattServer::getAppearance(uint16_t *appearanceP)
|
||||
{
|
||||
if (sd_ble_gap_appearance_get(appearanceP)) {
|
||||
return BLE_ERROR_NONE;
|
||||
} else {
|
||||
return BLE_ERROR_PARAM_OUT_OF_RANGE;
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Callback handler for events getting pushed up from the SD
|
||||
|
|
|
@ -39,11 +39,6 @@ public:
|
|||
virtual ble_error_t readValue(uint16_t handle, uint8_t buffer[], uint16_t *const lengthP);
|
||||
virtual ble_error_t updateValue(uint16_t, uint8_t[], uint16_t, bool localOnly = false);
|
||||
|
||||
virtual ble_error_t setDeviceName(const uint8_t *deviceName);
|
||||
virtual ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP);
|
||||
virtual ble_error_t setAppearance(uint16_t appearance);
|
||||
virtual ble_error_t getAppearance(uint16_t *appearanceP);
|
||||
|
||||
/* nRF51 Functions */
|
||||
void eventCallback(void);
|
||||
void hwCallback(ble_evt_t *p_ble_evt);
|
||||
|
|
Loading…
Reference in a new issue