/*创建新命令并填充它*/
cmd alloc\u ble\u msg(gatble\mgr\cmd service\u add
cmd->;handle=handle;如果(!ble_cmd_execute(cmd,(void**)&rsp,ble_mgr_gatts_service_add_include_cmd_handler){
返回retble\U error\U t ble\U gatts\U add\U特征(常量att\U uuid\U t*uuid,gatt\U prop\t prop,att perm\U perm,
uint16\U max\U len,gatts\U标志,uint16\U t*h\U偏移,
uint16\U*h\U val\U偏移量)
{
ble_-mgr_-gatts_-service_-add_-characteristic_-cmd_-gt*cmd;
ble_-mgr_-gatts_-service_-add_-characteristic_-rsp_-t*rsp;
ble-error_-ret=ble_-error_-error_失败;
/*创建新命令并填充它*/
cmd
cmd->;uuid=*uuid;
cmd->;prop=prop;
cmd->;perm=perm;
cmd->;max\u len=max\u len;
cmd->;flags=flags;
如果(!ble\u cmd\u执行(cmd,(void**)rsp,ble\u管理器\u gatts服务\u添加特性\u cmd处理程序){br/>返回ret《p><
如果(h>p>>p>如果p>
>p
p>p>p>p>p>p>p>p>p>p>p>p>p>p>由于由于错误,我们的错误,我们的错误,我们的错误,我们的错误,我们是在测试,我们的错误,我们在在测试测试中,_标志_t标志,uint16_t*h_偏移量)
{
ble\u mgr\u gatts\u service\u add\u descriptor\u cmd\u t*cmd;
ble\u mgr\u gatts\u service\u add\u descriptor\u rsp\u t*rsp;
ble\u error\u ret=ble\u error\u失败;
/*创建新命令并填充它*/
cmd alloc\u sible\u msg(ble\u mgr\u gatts\u service\u descriptor,EOF cmd)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>cmd>>>>>>>>>
>>>>>
>>>>>>>cmd>>>>>cmd>cmd>cmd>cmd>>cmd>cmd>难难难难难难>难难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>难>/>}
/*免费信息*/
OS_FREE(rsp);
return ret;
}
ble_error_t ble_gatts_register_service(uint16_t *handle, ...)
{
va_list ap;
ble_mgr_gatts_service_register_cmd_t *cmd;
ble_mgr_gatts_service_register_rsp_t *rsp;
ble_error_t ret = BLE_ERROR_FAILED;
/* Create new command and fill it */
cmd = alloc_ble_msg(BLE_MGR_GATTS_SERVICE_REGISTER_CMD, sizeof(*cmd));
if (!ble_cmd_execute(cmd, (void **) &rsp, ble_mgr_gatts_service_register_cmd_handler)) {
return ret;
}
ret = rsp->status;
if (handle) {
*handle = rsp->handle;
}
va_start(ap, handle);
for (;;) {
uint16_t *h = va_arg(ap, uint16_t*);
if (!h) {
break;
}
*h = *h + rsp->handle;
}
va_end(ap);
/* free message */
OS_FREE(rsp);
return ret;
}
ble_error_t ble_gatts_enable_service(uint16_t handle)
{
ble_mgr_gatts_service_enable_cmd_t *cmd;
ble_mgr_gatts_service_enable_rsp_t *rsp;
ble_error_t ret = BLE_ERROR_FAILED;
/* Create new command and fill it */
cmd = alloc_ble_msg(BLE_MGR_GATTS_SERVICE_ENABLE_CMD, sizeof(*cmd));
cmd->handle = handle;
if (!ble_cmd_execute(cmd, (void **) &rsp, ble_mgr_gatts_service_enable_cmd_handler)) {
return ret;
}
ret = rsp->status;
/* free message */
OS_FREE(rsp);
return ret;
}
ble_error_t ble_gatts_disable_service(uint16_t handle)
{
ble_mgr_gatts_service_disable_cmd_t *cmd;
ble_mgr_gatts_service_disable_rsp_t *rsp;
ble_error_t ret = BLE_ERROR_FAILED;
/* Create new command and fill it */
cmd = alloc_ble_msg(BLE_MGR_GATTS_SERVICE_DISABLE_CMD, sizeof(*cmd));
cmd->handle = handle;
if (!ble_cmd_execute(cmd, (void **) &rsp, ble_mgr_gatts_service_disable_cmd_handler)) {
return ret;
}
ret = rsp->status;
/* free message */
OS_FREE(rsp);
return ret;
}
ble_error_t ble_gatts_get_characteristic_prop(uint16_t handle, gatt_prop_t *prop, att_perm_t *perm)
{
ble_mgr_gatts_service_characteristic_get_prop_cmd_t *cmd;
ble_mgr_gatts_service_characteristic_get_prop_rsp_t *rsp;
ble_error_t ret = BLE_ERROR_FAILED;
/* Create new command and fill it */
cmd = alloc_ble_msg(BLE_MGR_GATTS_SERVICE_CHARACTERISTIC_GET_PROP_CMD, sizeof(*cmd));
cmd->handle = handle;
if (!ble_cmd_execute(cmd, (void **) &rsp,
ble_mgr_gatts_service_characteristic_get_prop_cmd_handler)) {
return ret;
}
ret = rsp->status;
if (ret == BLE_STATUS_OK) {
if (prop) {
*prop = rsp->prop;
}
if (perm) {
*perm = rsp->perm;
}
}
/* free message */
OS_FREE(rsp);
return ret;
}
ble_error_t ble_gatts_set_characteristic_prop(uint16_t handle, gatt_prop_t prop, att_perm_t perm)
{
ble_mgr_gatts_service_characteristic_set_prop_cmd_t *cmd;
ble_mgr_gatts_service_characteristic_set_prop_rsp_t *rsp;
ble_error_t ret = BLE_ERROR_FAILED;
/* Create new command and fill it */
cmd = alloc_ble_msg(BLE_MGR_GATTS_SERVICE_CHARACTERISTIC_SET_PROP_CMD, sizeof(*cmd));
cmd->handle = handle;
cmd->prop = prop;
cmd->perm = perm;
if (!ble_cmd_execute(cmd, (void **) &rsp,
ble_mgr_gatts_service_characteristic_set_prop_cmd_handler)) {
return ret;
}
ret = rsp->status;
/* free message */
OS_FREE(rsp);
return ret;
}
ble_error_t ble_gatts_get_value(uint16_t handle, uint16_t *length, void *value)
{
ble_mgr_gatts_get_value_cmd_t *cmd;
ble_mgr_gatts_get_value_rsp_t *rsp;
ble_error_t ret = BLE_ERROR_FAILED;
uint16_t copy_length;
/* Create new command and fill it */
cmd = alloc_ble_msg(BLE_MGR_GATTS_GET_VALUE_CMD, sizeof(*cmd));
cmd->handle = handle;
cmd->max_len = *length;
copy_length = *length; // save for later
if (!ble_cmd_execute(cmd, (void **) &rsp, ble_mgr_gatts_get_value_cmd_handler)) {
return ret;
}
/*
* Update length with actual attribute value length.
* Copy as much data as will fit in buffer or what was returned (if buffer provided).
*/
*length = rsp->length;
if (value) {
if (rsp->length < copy_length) {
copy_length = rsp->length;
}
memcpy(value, rsp->value, copy_length);
}
ret = rsp->status;
/* free message */
OS_FREE(rsp);
return ret;
}
ble_error_t ble_gatts_set_value(uint16_t handle, uint16_t length, const void *value)
{
ble_mgr_gatts_set_value_cmd_t *cmd;
ble_mgr_gatts_set_value_rsp_t *rsp;
ble_error_t ret = BLE_ERROR_FAILED;
/* Create new command and fill it */
cmd = alloc_ble_msg(BLE_MGR_GATTS_SET_VALUE_CMD, sizeof(*cmd) + length);
cmd->handle = handle;
cmd->length = length;
memcpy(cmd->value, value, length);
if (!ble_cmd_execute(cmd, (void **) &rsp, ble_mgr_gatts_set_value_cmd_handler)) {
return BLE_ERROR_FAILED;
}
ret = rsp->status;
OS_FREE(rsp);
return ret;
}
ble_error_t ble_gatts_read_cfm(uint16_t conn_idx, uint16_t handle, att_error_t status,
uint16_t length, const void *value)
{
ble_mgr_gatts_read_cfm_cmd_t *cmd;
ble_mgr_gatts_read_cfm_rsp_t *rsp;
ble_error_t ret = BLE_ERROR_FAILED;
if (length && !value) {
return ret;
}
/* Create new command and fill it */
cmd = alloc_ble_msg(BLE_MGR_GATTS_READ_CFM_CMD, sizeof(*cmd) + length);
cmd->conn_idx = conn_idx;
cmd->handle = handle;
cmd->status = status;
cmd->length = length;
if (value) {
memcpy(cmd->value, value, length);
}
if (!ble_cmd_execute(cmd, (void **) &rsp, ble_mgr_gatts_read_cfm_cmd_handler)) {
return BLE_ERROR_FAILED;
}
ret = rsp->status;
OS_FREE(rsp);
return ret;
}
ble_error_t ble_gatts_write_cfm(uint16_t conn_idx, uint16_t handle, att_error_t status)
{
ble_mgr_gatts_write_cfm_cmd_t *cmd;
ble_mgr_gatts_write_cfm_rsp_t *rsp;
ble_error_t ret = BLE_ERROR_FAILED;
/* Create new command and fill it */
cmd = alloc_ble_msg(BLE_MGR_GATTS_WRITE_CFM_CMD, sizeof(*cmd));
cmd->conn_idx = conn_idx;
cmd->handle = handle;
cmd->status = status;
if (!ble_cmd_execute(cmd, (void **) &rsp, ble_mgr_gatts_write_cfm_cmd_handler)) {
return BLE_ERROR_FAILED;
}
ret = rsp->status;
OS_FREE(rsp);
return ret;
}
ble_error_t ble_gatts_prepare_write_cfm(uint16_t conn_idx, uint16_t handle, uint16_t length,
att_error_t status)
{
ble_mgr_gatts_prepare_write_cfm_cmd_t *cmd;
ble_mgr_gatts_prepare_write_cfm_rsp_t *rsp;
ble_error_t ret = BLE_ERROR_FAILED;
/* Create new command and fill it */
cmd = alloc_ble_msg(BLE_MGR_GATTS_PREPARE_WRITE_CFM_CMD, sizeof(*cmd));
cmd->conn_idx = conn_idx;
cmd->handle = handle;
cmd->length = length;
cmd->status = status;
if (!ble_cmd_execute(cmd, (void **) &rsp, ble_mgr_gatts_prepare_write_cfm_cmd_handler)) {
return BLE_ERROR_FAILED;
}
ret = rsp->status;
OS_FREE(rsp);
return ret;
}
ble_error_t ble_gatts_send_event(uint16_t conn_idx, uint16_t handle, gatt_event_t type,
uint16_t length, const void *value)
{
ble_mgr_gatts_send_event_cmd_t *cmd;
ble_mgr_gatts_send_event_rsp_t *rsp;
ble_error_t ret = BLE_ERROR_FAILED;
/* Create new command and fill it */
cmd = alloc_ble_msg(BLE_MGR_GATTS_SEND_EVENT_CMD, sizeof(*cmd) + length);
cmd->conn_idx = conn_idx;
cmd->handle = handle;
cmd->type = type;
cmd->length = length;
memcpy(cmd->value, value, length);
if (!ble_cmd_execute(cmd, (void **) &rsp, ble_mgr_gatts_send_event_cmd_handler)) {
return BLE_ERROR_FAILED;
}
ret = rsp->status;
OS_FREE(rsp);
return ret;
}
ble_error_t ble_gatts_service_changed_ind(uint16_t conn_idx, uint16_t start_handle,
uint16_t end_handle)
{
ble_mgr_gatts_service_changed_ind_cmd_t *cmd;
ble_mgr_gatts_service_changed_ind_rsp_t *rsp;
ble_error_t ret = BLE_ERROR_FAILED;
/* Create new command and fill it */
cmd = alloc_ble_msg(BLE_MGR_GATTS_SERVICE_CHANGED_IND_CMD, sizeof(*cmd));
cmd->conn_idx = conn_idx;
cmd->start_handle = start_handle;
cmd->end_handle = end_handle;
if (!ble_cmd_execute(cmd, (void **) &rsp, ble_mgr_gatts_service_changed_ind_cmd_handler)) {
return BLE_ERROR_FAILED;
}
ret = rsp->status;
OS_FREE(rsp);
return ret;
}
#endif /* (dg_configBLE_GATT_SERVER == 1) */