本文整理汇总了C++中sd_ble_gatts_characteristic_add函数的典型用法代码示例。如果您正苦于以下问题:C++ sd_ble_gatts_characteristic_add函数的具体用法?C++ sd_ble_gatts_characteristic_add怎么用?C++ sd_ble_gatts_characteristic_add使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sd_ble_gatts_characteristic_add函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init_characteristic_set_led_color
/**
* @brief Initialize the set_led_color characteristic
*/
void init_characteristic_set_led_color()
{
ble_gatts_char_md_t characteristic_metadata;
ble_gatts_attr_md_t attribute_metadata;
ble_gatts_attr_t gatt_attribute;
memset(&characteristic_metadata, 0, sizeof(characteristic_metadata));
characteristic_metadata.char_props.write = 1;
characteristic_metadata.char_props.write_wo_resp = 1;
characteristic_metadata.p_char_user_desc = NULL;
characteristic_metadata.p_char_pf = NULL;
characteristic_metadata.p_user_desc_md = NULL;
characteristic_metadata.p_cccd_md = NULL;
characteristic_metadata.p_sccd_md = NULL;
memset(&attribute_metadata, 0, sizeof(attribute_metadata));
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attribute_metadata.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attribute_metadata.write_perm);
attribute_metadata.vloc = BLE_GATTS_VLOC_STACK;
attribute_metadata.rd_auth = 0;
attribute_metadata.wr_auth = 0;
attribute_metadata.vlen = 1;
memset(&gatt_attribute, 0, sizeof(gatt_attribute));
tree_service.characteristic_set_led_color_uuid.uuid = BLE_UUID_SET_LED_COLOR_CHARACTERISTIC;
tree_service.characteristic_set_led_color_uuid.type = tree_service.uuid.type;
gatt_attribute.p_uuid = &tree_service.characteristic_set_led_color_uuid;
gatt_attribute.p_attr_md = &attribute_metadata;
gatt_attribute.init_len = 1;
gatt_attribute.init_offs = 0;
gatt_attribute.max_len = 20;
uint32_t retval =
sd_ble_gatts_characteristic_add(
tree_service.service_handle,
&characteristic_metadata,
&gatt_attribute,
&tree_service.characteristic_set_led_color_handles
);
APP_ERROR_CHECK(retval);
}
示例2: protocol_mode_char_add
/**@brief Function for adding Protocol Mode characteristics.
*
* @param[in] p_hids HID Service structure.
* @param[in] p_sec_mode Characteristic security settings.
*
* @return NRF_SUCCESS on success, otherwise an error code.
*/
static uint32_t protocol_mode_char_add(ble_hids_t * p_hids,
const ble_srv_security_mode_t * p_sec_mode)
{
ble_gatts_char_md_t char_md;
ble_gatts_attr_t attr_char_value;
ble_uuid_t ble_uuid;
ble_gatts_attr_md_t attr_md;
uint8_t initial_protocol_mode;
memset(&char_md, 0, sizeof(char_md));
char_md.char_props.read = 1;
char_md.char_props.write_wo_resp = 1;
char_md.p_char_user_desc = NULL;
char_md.p_char_pf = NULL;
char_md.p_user_desc_md = NULL;
char_md.p_cccd_md = NULL;
char_md.p_sccd_md = NULL;
BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_PROTOCOL_MODE_CHAR);
memset(&attr_md, 0, sizeof(attr_md));
attr_md.read_perm = p_sec_mode->read_perm;
attr_md.write_perm = p_sec_mode->write_perm;
attr_md.vloc = BLE_GATTS_VLOC_STACK;
attr_md.rd_auth = 0;
attr_md.wr_auth = 0;
attr_md.vlen = 0;
memset(&attr_char_value, 0, sizeof(attr_char_value));
initial_protocol_mode = DEFAULT_PROTOCOL_MODE;
attr_char_value.p_uuid = &ble_uuid;
attr_char_value.p_attr_md = &attr_md;
attr_char_value.init_len = sizeof(uint8_t);
attr_char_value.init_offs = 0;
attr_char_value.max_len = sizeof(uint8_t);
attr_char_value.p_value = &initial_protocol_mode;
return sd_ble_gatts_characteristic_add(p_hids->service_handle,
&char_md,
&attr_char_value,
&p_hids->protocol_mode_handles);
}
示例3: read_char_add
//eric-han:for wehcat fec9
static uint32_t read_char_add(uint16_t uuid,uint8_t len,uint8_t * p_value,
const ble_srv_security_mode_t * step_attr_md,
ble_gatts_char_handles_t * p_handles,ble_step_t * p_step)
{
ble_uuid_t ble_uuid;
ble_gatts_char_md_t char_md;
ble_gatts_attr_t attr_char_value;
ble_gatts_attr_md_t attr_md;
uint8_t temp=100;
//APP_ERROR_CHECK_BOOL(p_char_value != NULL);
//APP_ERROR_CHECK_BOOL(char_len > 0);
// The ble_gatts_char_md_t structure uses bit fields. So we reset the memory to zero.
memset(&char_md, 0, sizeof(char_md));
char_md.char_props.read = 1;
char_md.p_char_user_desc = NULL;
char_md.p_char_pf = NULL;
char_md.p_user_desc_md = NULL;
char_md.p_cccd_md = NULL;
char_md.p_sccd_md = NULL;
BLE_UUID_BLE_ASSIGN(ble_uuid, uuid);
memset(&attr_md, 0, sizeof(attr_md));
attr_md.read_perm = step_attr_md->read_perm;
attr_md.write_perm = step_attr_md->write_perm;
attr_md.vloc = BLE_GATTS_VLOC_STACK;
attr_md.rd_auth = 0;
attr_md.wr_auth = 0;
attr_md.vlen = 0;
memset(&attr_char_value, 0, sizeof(attr_char_value));
attr_char_value.p_uuid = &ble_uuid;
attr_char_value.p_attr_md = &attr_md;
attr_char_value.init_len = len;
attr_char_value.init_offs = 0;
attr_char_value.max_len = len;
attr_char_value.p_value = p_value;
return sd_ble_gatts_characteristic_add(p_step->service_handle, &char_md, &attr_char_value, p_handles);
}
示例4: bps_feature_char_add
/**@brief Function for adding Blood Pressure Feature characteristics.
*
* @param[in] p_bps Blood Pressure Service structure.
* @param[in] p_bps_init Information needed to initialize the service.
*
* @return NRF_SUCCESS on success, otherwise an error code.
*/
static uint32_t bps_feature_char_add(ble_bps_t * p_bps, const ble_bps_init_t * p_bps_init)
{
ble_gatts_char_md_t char_md;
ble_gatts_attr_t attr_char_value;
ble_uuid_t ble_uuid;
ble_gatts_attr_md_t attr_md;
uint8_t init_value_encoded[2];
uint8_t init_value_len;
memset(&char_md, 0, sizeof(char_md));
char_md.char_props.read = 1;
char_md.p_char_user_desc = NULL;
char_md.p_char_pf = NULL;
char_md.p_user_desc_md = NULL;
char_md.p_cccd_md = NULL;
char_md.p_sccd_md = NULL;
BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_BLOOD_PRESSURE_FEATURE_CHAR);
memset(&attr_md, 0, sizeof(attr_md));
attr_md.vloc = BLE_GATTS_VLOC_STACK;
attr_md.read_perm = p_bps_init->bps_feature_attr_md.read_perm;
attr_md.write_perm = p_bps_init->bps_feature_attr_md.write_perm;
attr_md.rd_auth = 0;
attr_md.wr_auth = 0;
attr_md.vlen = 0;
memset(&attr_char_value, 0, sizeof(attr_char_value));
init_value_len = uint16_encode(p_bps_init->feature, init_value_encoded);
attr_char_value.p_uuid = &ble_uuid;
attr_char_value.p_attr_md = &attr_md;
attr_char_value.init_len = init_value_len;
attr_char_value.init_offs = 0;
attr_char_value.max_len = init_value_len;
attr_char_value.p_value = init_value_encoded;
return sd_ble_gatts_characteristic_add(p_bps->service_handle,
&char_md,
&attr_char_value,
&p_bps->feature_handles);
}
示例5: lock_char_add
/**@brief Function for adding the LED characteristic.
*
*/
static uint32_t lock_char_add(ble_doorlock_t * p_doorlock, const ble_doorlock_init_t * p_lbs_init)
{
ble_gatts_char_md_t char_md;
ble_gatts_attr_t attr_char_value;
ble_uuid_t ble_uuid;
ble_gatts_attr_md_t attr_md;
memset(&char_md, 0, sizeof(char_md));
char_md.char_props.read = 1;
char_md.char_props.write = 1;
char_md.p_char_user_desc = NULL;
char_md.p_char_pf = NULL;
char_md.p_user_desc_md = NULL;
char_md.p_cccd_md = NULL;
char_md.p_sccd_md = NULL;
ble_uuid.type = p_doorlock->uuid_type;
ble_uuid.uuid = DOORLOCK_UUID_LOCK_CHAR;
memset(&attr_md, 0, sizeof(attr_md));
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
attr_md.vloc = BLE_GATTS_VLOC_STACK;
attr_md.rd_auth = 0;
attr_md.wr_auth = 0;
attr_md.vlen = 0;
memset(&attr_char_value, 0, sizeof(attr_char_value));
attr_char_value.p_uuid = &ble_uuid;
attr_char_value.p_attr_md = &attr_md;
attr_char_value.init_len = sizeof(uint8_t);
attr_char_value.init_offs = 0;
attr_char_value.max_len = sizeof(uint8_t);
attr_char_value.p_value = NULL;
return sd_ble_gatts_characteristic_add(p_doorlock->service_handle, &char_md,
&attr_char_value,
&p_doorlock->lock_char_handles);
}
示例6: light_status_char_add
// Function for adding the Light Status characteristic
static uint32_t light_status_char_add(ble_lc_t * p_lc, const ble_lc_init_t * p_lc_init, ble_uuid_t * ble_uuid)
{
ble_gatts_char_md_t char_md;
ble_gatts_attr_md_t cccd_md;
ble_gatts_attr_t attr_char_value;
ble_gatts_attr_md_t attr_md;
memset(&cccd_md, 0, sizeof(cccd_md));
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);
cccd_md.vloc = BLE_GATTS_VLOC_STACK;
memset(&char_md, 0, sizeof(char_md));
char_md.char_props.notify = NULL;
char_md.char_props.read = 1;
char_md.p_char_user_desc = NULL;
char_md.p_char_pf = NULL;
char_md.p_user_desc_md = NULL;
char_md.p_cccd_md = &cccd_md;
char_md.p_sccd_md = NULL;
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&attr_md.write_perm);
attr_md.vloc = BLE_GATTS_VLOC_STACK;
attr_md.rd_auth = 1;
attr_md.wr_auth = 0;
attr_md.vlen = 1;
memset(&attr_char_value, 0, sizeof(attr_char_value));
attr_char_value.p_uuid = ble_uuid;
attr_char_value.p_attr_md = &attr_md;
attr_char_value.init_len = sizeof(uint8_t);
attr_char_value.init_offs = 0;
attr_char_value.max_len = BLE_LC_MAX_DATA_LEN;
return sd_ble_gatts_characteristic_add(p_lc->service_handle,
&char_md,
&attr_char_value,
&p_lc->light_status_handles);
}
示例7: dfu_ctrl_pt_add
/**@brief Function for adding DFU Control Point characteristic to the BLE Stack.
*
* @param[in] p_dfu DFU Service structure.
*
* @return NRF_SUCCESS on success. Otherwise an error code.
*/
static uint32_t dfu_ctrl_pt_add(ble_dfu_t * const p_dfu)
{
ble_gatts_char_md_t char_md;
ble_gatts_attr_t attr_char_value;
ble_uuid_t char_uuid;
ble_gatts_attr_md_t attr_md;
memset(&char_md, 0, sizeof(char_md));
char_md.char_props.write = 1;
char_md.char_props.notify = 1;
char_md.p_char_user_desc = NULL;
char_md.p_char_pf = NULL;
char_md.p_user_desc_md = NULL;
char_md.p_cccd_md = NULL;
char_md.p_sccd_md = NULL;
char_uuid.type = p_dfu->uuid_type;
char_uuid.uuid = BLE_DFU_CTRL_PT_UUID;
memset(&attr_md, 0, sizeof(attr_md));
BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&attr_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
attr_md.vloc = BLE_GATTS_VLOC_STACK;
attr_md.rd_auth = 0;
attr_md.wr_auth = 1;
attr_md.vlen = 1;
memset(&attr_char_value, 0, sizeof(attr_char_value));
attr_char_value.p_uuid = &char_uuid;
attr_char_value.p_attr_md = &attr_md;
attr_char_value.init_len = 0;
attr_char_value.init_offs = 0;
attr_char_value.max_len = BLE_L2CAP_MTU_DEF;
attr_char_value.p_value = NULL;
return sd_ble_gatts_characteristic_add(p_dfu->service_handle,
&char_md,
&attr_char_value,
&p_dfu->dfu_ctrl_pt_handles);
}
示例8: tx_power_level_char_add
/**@brief Function for adding TX Power Level characteristics.
*
* @param[in] p_tps TX Power Service structure.
* @param[in] p_tps_init Information needed to initialize the service.
*
* @return NRF_SUCCESS on success, otherwise an error code.
*/
static uint32_t tx_power_level_char_add(ble_tps_t * p_tps,
const ble_tps_init_t * p_tps_init)
{
ble_gatts_char_md_t char_md;
ble_gatts_attr_t attr_char_value;
ble_uuid_t ble_uuid;
ble_gatts_attr_md_t attr_md;
memset(&char_md, 0, sizeof(char_md));
char_md.char_props.read = 1;
char_md.p_char_user_desc = NULL;
char_md.p_char_pf = NULL;
char_md.p_user_desc_md = NULL;
char_md.p_cccd_md = NULL;
char_md.p_sccd_md = NULL;
BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_TX_POWER_LEVEL_CHAR);
memset(&attr_md, 0, sizeof(attr_md));
attr_md.read_perm = p_tps_init->tps_attr_md.read_perm;
attr_md.write_perm = p_tps_init->tps_attr_md.write_perm;
attr_md.vloc = BLE_GATTS_VLOC_STACK;
attr_md.rd_auth = 0;
attr_md.wr_auth = 0;
attr_md.vlen = 0;
memset(&attr_char_value, 0, sizeof(attr_char_value));
memset(&attr_char_value, 0, sizeof (attr_char_value));
attr_char_value.p_uuid = &ble_uuid;
attr_char_value.p_attr_md = &attr_md;
attr_char_value.init_len = sizeof (int8_t);
attr_char_value.init_offs = 0;
attr_char_value.max_len = sizeof (uint8_t);
attr_char_value.p_value = (uint8_t*)&p_tps_init->initial_tx_power_level;
return sd_ble_gatts_characteristic_add(p_tps->service_handle,
&char_md,
&attr_char_value,
&p_tps->tx_power_level_handles);
}
示例9: hid_control_point_char_add
/**@brief Function for adding HID Control Point characteristics.
*
* @param[in] p_hids HID Service structure.
* @param[in] p_sec_mode Characteristic security settings.
*
* @return NRF_SUCCESS on success, otherwise an error code.
*/
static uint32_t hid_control_point_char_add(ble_hids_t * p_hids,
const ble_srv_security_mode_t * p_sec_mode)
{
ble_gatts_char_md_t char_md;
ble_gatts_attr_t attr_char_value;
ble_uuid_t ble_uuid;
ble_gatts_attr_md_t attr_md;
uint8_t initial_hid_control_point;
memset(&char_md, 0, sizeof(char_md));
char_md.char_props.write_wo_resp = 1;
char_md.p_char_user_desc = NULL;
char_md.p_char_pf = NULL;
char_md.p_user_desc_md = NULL;
char_md.p_cccd_md = NULL;
char_md.p_sccd_md = NULL;
BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_HID_CONTROL_POINT_CHAR);
memset(&attr_md, 0, sizeof(attr_md));
attr_md.read_perm = p_sec_mode->read_perm;
attr_md.write_perm = p_sec_mode->write_perm;
attr_md.vloc = BLE_GATTS_VLOC_STACK;
attr_md.rd_auth = 0;
attr_md.wr_auth = 0;
attr_md.vlen = 0;
initial_hid_control_point = INITIAL_VALUE_HID_CONTROL_POINT;
memset(&attr_char_value, 0, sizeof(attr_char_value));
attr_char_value.p_uuid = &ble_uuid;
attr_char_value.p_attr_md = &attr_md;
attr_char_value.init_len = sizeof(uint8_t);
attr_char_value.init_offs = 0;
attr_char_value.max_len = sizeof(uint8_t);
attr_char_value.p_value = &initial_hid_control_point;
return sd_ble_gatts_characteristic_add(p_hids->service_handle, &char_md,
&attr_char_value,
&p_hids->hid_control_point_handles);
}
示例10: hid_information_char_add
/**@brief Function for adding HID Information characteristics.
*
* @param[in] p_hids HID Service structure.
* @param[in] p_hids_init Service initialization structure.
*
* @return NRF_SUCCESS on success, otherwise an error code.
*/
static uint32_t hid_information_char_add(ble_hids_t * p_hids, const ble_hids_init_t * p_hids_init)
{
ble_gatts_char_md_t char_md;
ble_gatts_attr_t attr_char_value;
ble_uuid_t ble_uuid;
ble_gatts_attr_md_t attr_md;
uint8_t encoded_hid_information[ENCODED_HID_INFORMATION_LEN];
uint8_t hid_info_len;
memset(&char_md, 0, sizeof(char_md));
char_md.char_props.read = 1;
char_md.p_char_user_desc = NULL;
char_md.p_char_pf = NULL;
char_md.p_user_desc_md = NULL;
char_md.p_cccd_md = NULL;
char_md.p_sccd_md = NULL;
BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_HID_INFORMATION_CHAR);
memset(&attr_md, 0, sizeof(attr_md));
attr_md.read_perm = p_hids_init->hid_information.security_mode.read_perm;
attr_md.write_perm = p_hids_init->hid_information.security_mode.write_perm;
attr_md.vloc = BLE_GATTS_VLOC_STACK;
attr_md.rd_auth = 0;
attr_md.wr_auth = 0;
attr_md.vlen = 0;
hid_info_len = encode_hid_information(encoded_hid_information, &p_hids_init->hid_information);
memset(&attr_char_value, 0, sizeof(attr_char_value));
attr_char_value.p_uuid = &ble_uuid;
attr_char_value.p_attr_md = &attr_md;
attr_char_value.init_len = hid_info_len;
attr_char_value.init_offs = 0;
attr_char_value.max_len = attr_char_value.init_len;
attr_char_value.p_value = encoded_hid_information;
return sd_ble_gatts_characteristic_add(p_hids->service_handle, &char_md,
&attr_char_value,
&p_hids->hid_information_handles);
}
示例11: alert_level_char_add
/**@brief Function for adding Alert Level characteristics.
*
* @param[in] p_ias Immediate Alert Service structure.
* @param[in] p_ias_init Information needed to initialize the service.
*
* @return NRF_SUCCESS on success, otherwise an error code.
*/
static uint32_t alert_level_char_add(ble_ias_t * p_ias)
{
ble_gatts_char_md_t char_md;
ble_gatts_attr_t attr_char_value;
ble_uuid_t ble_uuid;
ble_gatts_attr_md_t attr_md;
uint8_t initial_alert_level;
memset(&char_md, 0, sizeof(char_md));
char_md.char_props.write_wo_resp = 1;
char_md.p_char_user_desc = NULL;
char_md.p_char_pf = NULL;
char_md.p_user_desc_md = NULL;
char_md.p_cccd_md = NULL;
char_md.p_sccd_md = NULL;
BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_ALERT_LEVEL_CHAR);
memset(&attr_md, 0, sizeof(attr_md));
BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&attr_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&attr_md.write_perm);
attr_md.vloc = BLE_GATTS_VLOC_STACK;
attr_md.rd_auth = 0;
attr_md.wr_auth = 0;
attr_md.vlen = 0;
memset(&attr_char_value, 0, sizeof(attr_char_value));
initial_alert_level = INITIAL_ALERT_LEVEL;
attr_char_value.p_uuid = &ble_uuid;
attr_char_value.p_attr_md = &attr_md;
attr_char_value.init_len = sizeof (uint8_t);
attr_char_value.init_offs = 0;
attr_char_value.max_len = sizeof (uint8_t);
attr_char_value.p_value = &initial_alert_level;
return sd_ble_gatts_characteristic_add(p_ias->service_handle,
&char_md,
&attr_char_value,
&p_ias->alert_level_handles);
}
示例12: tx_char_add
/**@brief Function for adding TX characteristic.
*
* @param[in] p_nus Nordic UART Service structure.
* @param[in] p_nus_init Information needed to initialize the service.
*
* @return NRF_SUCCESS on success, otherwise an error code.
*/
static uint32_t tx_char_add(ble_nus_t * p_nus, const ble_nus_init_t * p_nus_init)
{
ble_gatts_char_md_t char_md;
ble_gatts_attr_t attr_char_value;
ble_uuid_t ble_uuid;
ble_gatts_attr_md_t attr_md;
memset(&char_md, 0, sizeof(char_md));
char_md.char_props.write = 1;
char_md.char_props.write_wo_resp = 1;
char_md.p_char_user_desc = NULL;
char_md.p_char_pf = NULL;
char_md.p_user_desc_md = NULL;
char_md.p_cccd_md = NULL;
char_md.p_sccd_md = NULL;
ble_uuid.type = p_nus->uuid_type;
ble_uuid.uuid = BLE_UUID_NUS_TX_CHARACTERISTIC;
memset(&attr_md, 0, sizeof(attr_md));
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
attr_md.vloc = BLE_GATTS_VLOC_STACK;
attr_md.rd_auth = 0;
attr_md.wr_auth = 0;
attr_md.vlen = 1;
memset(&attr_char_value, 0, sizeof(attr_char_value));
attr_char_value.p_uuid = &ble_uuid;
attr_char_value.p_attr_md = &attr_md;
attr_char_value.init_len = 1;
attr_char_value.init_offs = 0;
attr_char_value.max_len = BLE_NUS_MAX_TX_CHAR_LEN;
return sd_ble_gatts_characteristic_add(p_nus->service_handle,
&char_md,
&attr_char_value,
&p_nus->tx_handles);
}
示例13: ble_led_sta_char_add
// This function allows to add a Characteristic in our Service
static uint32_t ble_led_sta_char_add(ble_led_t * const p_led)
{
ble_gatts_char_md_t char_md;
ble_gatts_attr_t attr_char_value;
ble_uuid_t char_uuid;
ble_gatts_attr_md_t attr_md;
uint8_t initial_led_status = 0;
memset(&char_md, 0, sizeof(char_md));
// set the Characteristic type to Write Without Response
// it means Central won't except any acknowledgment from the Peripheral
char_md.char_props.write_wo_resp = 1;
// Here we set the Characteristic UUID
char_uuid.type = p_led->uuid_type;
char_uuid.uuid = BLE_LED_STA_CHAR_UUID;
memset(&attr_md, 0, sizeof(attr_md));
// add write permission
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
// Attribute configuration, the data is stored in stack memory space
attr_md.vloc = BLE_GATTS_VLOC_STACK;
attr_md.rd_auth = 0;
attr_md.wr_auth = 0;
attr_md.vlen = 0;
memset(&attr_char_value, 0, sizeof(attr_char_value));
// setup Attribute default value
attr_char_value.p_uuid = &char_uuid;
attr_char_value.p_attr_md = &attr_md;
attr_char_value.init_len = sizeof(uint8_t);
attr_char_value.init_offs = 0;
attr_char_value.max_len = sizeof(uint8_t);
attr_char_value.p_value = &initial_led_status;
return sd_ble_gatts_characteristic_add(p_led->service_handle,
&char_md,
&attr_char_value,
&p_led->led_status_handles);
}
示例14: rgb_char_add
/**@brief Function for adding the LED characteristic.
*
*/
static uint32_t rgb_char_add(ble_rgb_btn_t * p_rgb_btn, const ble_rgb_btn_init_t * p_rgb_btn_init)
{
ble_gatts_char_md_t char_md;
ble_gatts_attr_t attr_char_value;
ble_uuid_t ble_uuid;
ble_gatts_attr_md_t attr_md;
uint8_t default_rgb[3] = {0, 0, 0};
memset(&char_md, 0, sizeof(char_md));
char_md.char_props.read = 1;
char_md.char_props.write = 1;
char_md.p_char_user_desc = NULL;
char_md.p_char_pf = NULL;
char_md.p_user_desc_md = NULL;
char_md.p_cccd_md = NULL;
char_md.p_sccd_md = NULL;
ble_uuid.type = p_rgb_btn->uuid_type;
ble_uuid.uuid = RGB_BTN_UUID_LED_CHAR;
memset(&attr_md, 0, sizeof(attr_md));
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
attr_md.vloc = BLE_GATTS_VLOC_STACK;
attr_md.rd_auth = 0;
attr_md.wr_auth = 0;
attr_md.vlen = 0;
memset(&attr_char_value, 0, sizeof(attr_char_value));
attr_char_value.p_uuid = &ble_uuid;
attr_char_value.p_attr_md = &attr_md;
attr_char_value.init_len = sizeof(uint8_t)*3;
attr_char_value.init_offs = 0;
attr_char_value.max_len = sizeof(uint8_t)*3;
attr_char_value.p_value = default_rgb;
return sd_ble_gatts_characteristic_add(p_rgb_btn->service_handle, &char_md,
&attr_char_value,
&p_rgb_btn->rgb_char_handles);
}
示例15: statistics_init
void statistics_init(void)
{
uint32_t err_code;
static const ble_gatts_attr_md_t metadata =
{
.read_perm = { 1, 2 },
.vlen = 1,
.vloc = BLE_GATTS_VLOC_USER
};
static const ble_uuid_t uuid =
{
.type = UUIDS_BASE_TYPE,
.uuid = MESH_STATISTICS_UUID
};
static const ble_gatts_attr_t attr =
{
.p_uuid = (ble_uuid_t*)&uuid,
.p_attr_md = (ble_gatts_attr_md_t*)&metadata,
.init_len = sizeof(stats),
.max_len = sizeof(stats),
.p_value = (uint8_t*)&stats
};
static const ble_gatts_char_md_t characteristic =
{
.char_props.read = 1,
.p_char_user_desc = "Stats",
.char_user_desc_max_size = 5,
.char_user_desc_size = 5
};
ble_gatts_char_handles_t newhandle;
err_code = sd_ble_gatts_characteristic_add(primary_service_handle, &characteristic, &attr, &newhandle);
APP_ERROR_CHECK(err_code);
}
uint32_t statistics_get_time(void)
{
uint32_t err_code;
uint32_t ticks;
err_code = app_timer_cnt_get(&ticks);
APP_ERROR_CHECK(err_code);
return ticks;
}