我们如何通过BLE发送负值?

⚠️
嗨,...感谢您来论坛。令人兴奋的消息!我们现在正在迁至我们的新论坛平台,将提供更好的功能,并包含在主对话框网站中。所有帖子和帐户都已迁移。我们现在只接受新论坛上的流量 - 请发布任何新线程https://www.dialog-seminile.com/support.。我们将在未来几天修复错误/优化搜索和标记。
2个帖子/ 0新
最后一篇
Mahmed106.
离线
最后一次露面:1个月5天前
加入:2019-05-03 17:28
我们如何通过BLE发送负值?

嗨对话框

我正在基于DA14681和SDK工作的定制板,是1.0.14.1081。
在文件BLE_GATTS.C中,所有功能都将输入为uint16_t。
如果我想发送像Int8或Int16这样的负值的数据。我该如何发送?因为ble_gatts.c是一个我不想改变的SDK文件。

谢谢

这是所有文件

/ **
****************************************************************************************
*
* @file ble_gatts.c.
*
* @brief tbd.
*
*版权所有(c)2015-2017对话半导体。雷竞技电竞平台
*此计算机程序包括机密,专有信息
*对话框半雷竞技电竞平台导体。版权所有。
*
****************************************************************************************
* /

#include
#include
#include“freertos.h”
#include“ble_mgr.h”
#include“ble_mgr_cmd.h”
#include“ble_mgr_gatts.h”
#include“ble_mgr_helper.h”
#include“ble_common.h”
#include“ble_gatts.h”

#if(dg_configble_gatt_server == 1)
ble_error_t ble_gatts_add_service(const att_uuid_t * uuid,const gatt_service_t类型,
uint16_t num_attrs)
{
ble_mgr_gatts_service_add_cmd_t * cmd;
ble_mgr_gatts_service_add_rsp_t * rsp;
ble_error_t ret = ble_error_failed;

/ *创建新命令并填写* /
cmd = alloc_ble_msg(ble_mgr_gatts_service_add_cmd,sizeof(* cmd));
cmd-> uuid = * uuid;
cmd-> type = type;
cmd-> num_attrs = num_attrs;

if(!ble_cmd_execute(cmd,(void **)&rsp,ble_mgr_gatts_service_add_cmd_handler)){
返回ble_error_failed;
}

RET = RSP->状态;
OS_FREE(RSP);

返回Ret;
}

BLE_ERROR_T BLE_GATTS_ADD_INCLUDE(UINT16_T句柄,UINT16_T * H_OFFSET)
{
ble_mgr_gatts_service_add_include_cmd_t * cmd;
ble_mgr_gatts_service_add_include_rsp_t * rsp;
ble_error_t ret = ble_error_failed;

/ *创建新命令并填写* /
cmd = alloc_ble_msg(ble_mgr_gatts_service_include_add_cmd,sizeof(* cmd));
cmd->手柄=手柄;

if(!ble_cmd_execute(cmd,(void **)&rsp,ble_mgr_gatts_service_add_include_cmd_handler)){
返回Ret;
}

RET = RSP->状态;

if(h_offset){
* h_offset = rsp-> h_offset;
}

/ *免费信息* /
OS_FREE(RSP);

返回Ret;
}

BLE_ERROR_T BLE_GATTS_ADD_CHAROURY(CONST ATT_UUID_T * UUID,GATT_PROP_T PROP,ATT_PERM_T PERM,
uint16_t max_len,gatts_flag_t标志,uint16_t * h_offset,
UINT16_T * H_VAL_OFFSET)
{
ble_mgr_gatts_service_add_charactery_cmd_t * cmd;
ble_mgr_gatts_service_add_charactery_rsp_t * rsp;
ble_error_t ret = ble_error_failed;

/ *创建新命令并填写* /
cmd = alloc_ble_msg(ble_mgr_gatts_service_characteristic_add_cmd,sizeof(* cmd));
cmd-> uuid = * uuid;
cmd-> prop = prop;
cmd-> perm = perm;
cmd-> max_len = max_len;
CMD->标志=标志;

if(!ble_cmd_execute(cmd,(void **)&rsp,ble_mgr_gatts_service_add_charactery_cmd_handler))){
返回Ret;
}

RET = RSP->状态;

if(h_offset){
* h_offset = rsp-> h_offset;
}

if(h_val_offset){
* h_val_offset = rsp-> h_val_offset;
}

/ *免费信息* /
OS_FREE(RSP);

返回Ret;
}

ble_error_t ble_gatts_add_descriptor(const att_uuid_t * uuid,att_perm_t perm,uint16_t max_len,
gatts_flag_t标志,uint16_t * h_offset)
{
ble_mgr_gatts_service_add_descriptor_cmd_t * cmd;
ble_mgr_gatts_service_add_descriptor_rsp_t * rsp;
ble_error_t ret = ble_error_failed;

/ *创建新命令并填写* /
cmd = alloc_ble_msg(ble_mgr_gatts_service_descriptor_add_cmd,sizeof(* cmd));
cmd-> uuid = * uuid;
cmd-> perm = perm;
cmd-> max_len = max_len;
CMD->标志=标志;

if(!ble_cmd_execute(cmd,(void **)&rsp,ble_mgr_gatts_service_add_descriptor_cmd_handler))){
返回Ret;
}

RET = RSP->状态;

if(h_offset){
* h_offset = rsp-> h_offset;
}

/ *免费信息* /
OS_FREE(RSP);

返回Ret;
}

ble_error_t ble_gatts_register_service(uint16_t * hander,...)
{
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;

/ *创建新命令并填写* /
cmd = alloc_ble_msg(ble_mgr_gatts_service_register_cmd,sizeof(* cmd));

如果(!ble_cmd_execute(cmd,(void **)&rsp,ble_mgr_gatts_service_register_cmd_handler)){
返回Ret;
}

RET = RSP->状态;

if(手柄){
*处理= rsp->手柄;
}

va_start(AP,句柄);
为了 (;;) {
uint16_t * h = va_arg(ap,uint16_t *);

如果(!h){
休息;
}

* H = * H + RSP->手柄;
}
va_end(ap);

/ *免费信息* /
OS_FREE(RSP);

返回Ret;
}

ble_error_t ble_gatts_enable_service(uint16_t句柄)
{
ble_mgr_gatts_service_enable_cmd_t * cmd;
ble_mgr_gatts_service_enable_rsp_t * rsp;
ble_error_t ret = ble_error_failed;

/ *创建新命令并填写* /
cmd = alloc_ble_msg(ble_mgr_gatts_service_enable_cmd,sizeof(* cmd));
cmd->手柄=手柄;

if(!ble_cmd_execute(cmd,(void **)&rsp,ble_mgr_gatts_service_enable_cmd_handler)){
返回Ret;
}

RET = RSP->状态;

/ *免费信息* /
OS_FREE(RSP);

返回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;

/ *创建新命令并填写* /
cmd = alloc_ble_msg(ble_mgr_gatts_service_disable_cmd,sizeof(* cmd));
cmd->手柄=手柄;

if(!ble_cmd_execute(cmd,(void **)&rsp,ble_mgr_gatts_service_disable_cmd_handler)){
返回Ret;
}

RET = RSP->状态;

/ *免费信息* /
OS_FREE(RSP);

返回Ret;
}

BLE_ERROR_T BLE_GATTS_GAT_CHAROURATIV_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_charraction_get_prop_rsp_t * rsp;
ble_error_t ret = ble_error_failed;

/ *创建新命令并填写* /
cmd = alloc_ble_msg(ble_mgr_gatts_service_characteristic_get_prop_cmd,sizeof(* cmd));
cmd->手柄=手柄;

if(!ble_cmd_execute(cmd,(void **)&rsp,
ble_mgr_gatts_service_charraction_get_prop_cmd_handler)){
返回Ret;
}

RET = RSP->状态;

if(ret == ble_status_ok){
if(prop){
* prop = rsp-> prop;
}

if(perm){
* perm = rsp-> perm;
}
}

/ *免费信息* /
OS_FREE(RSP);

返回Ret;
}

BLE_ERROR_T BLE_GATTS_SET_CHARACTION_PROP(UINT16_T句柄,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;

/ *创建新命令并填写* /
cmd = alloc_ble_msg(ble_mgr_gatts_service_characteristic_set_prop_cmd,sizeof(* cmd));
cmd->手柄=手柄;
cmd-> prop = prop;
cmd-> perm = perm;

if(!ble_cmd_execute(cmd,(void **)&rsp,
ble_mgr_gatts_service_characteristic_set_prop_cmd_handler)){
返回Ret;
}

RET = RSP->状态;

/ *免费信息* /
OS_FREE(RSP);

返回Ret;
}

BLE_ERROR_T BLE_GATTS_GET_VALUE(UINT16_T句柄,UINT16_T *长度,void *值)
{
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;

/ *创建新命令并填写* /
cmd = alloc_ble_msg(ble_mgr_gatts_get_value_cmd,sizeof(* cmd));
cmd->手柄=手柄;
cmd-> max_len = *长度;
copy_length = *长度;// 留着以后用

if(!ble_cmd_execute(cmd,(void **)&rsp,ble_mgr_gatts_get_value_cmd_handler)){
返回Ret;
}

/ *
*使用实际属性值长度更新长度。
*将数据复制为适合缓冲区或返回的内容(如果提供的缓冲区)。
* /
*长度= rsp->长度;
if(价值){
if(rsp-> length copy_length = rsp->长度;
}
memcpy(值,rsp->值,copy_length);
}

RET = RSP->状态;
/ *免费信息* /
OS_FREE(RSP);

返回Ret;
}

BLE_ERROR_T BLE_GATTS_SET_VALUE(UINT16_T句柄,uint16_t长度,const void *值)
{
ble_mgr_gatts_set_value_cmd_t * cmd;
ble_mgr_gatts_set_value_rsp_t * rsp;
ble_error_t ret = ble_error_failed;

/ *创建新命令并填写* /
cmd = alloc_ble_msg(ble_mgr_gatts_set_value_cmd,sizeof(* cmd)+长度);
cmd->手柄=手柄;
cmd->长度=长度;
memcpy(cmd->值,值,长度);

if(!ble_cmd_execute(cmd,(void **)&rsp,ble_mgr_gatts_set_value_cmd_handler))){
返回ble_error_failed;
}

RET = RSP->状态;
OS_FREE(RSP);

返回Ret;
}

ble_error_t ble_gatts_read_cfm(uint16_t conn_idx,uint16_t句柄,att_error_t状态,
uint16_t长度,const void *值)
{
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 &&!值){
返回Ret;
}

/ *创建新命令并填写* /
cmd = alloc_ble_msg(ble_mgr_gatts_read_cfm_cmd,sizeof(* cmd)+长度);
cmd-> conn_idx = conn_idx;
cmd->手柄=手柄;
cmd-> status = status;
cmd->长度=长度;
if(价值){
memcpy(cmd->值,值,长度);
}

if(!ble_cmd_execute(cmd,(void **)&rsp,ble_mgr_gatts_read_cfm_cmd_handler)){
返回ble_error_failed;
}

RET = RSP->状态;
OS_FREE(RSP);

返回Ret;
}

BLE_ERROR_T BLE_GATTS_WRITE_CFM(UINT16_T CONN_IDX,UINT16_T HANDLE,ATT_ERROR_T状态)
{
ble_mgr_gatts_write_cfm_cmd_t * cmd;
ble_mgr_gatts_write_cfm_rsp_t * rsp;
ble_error_t ret = ble_error_failed;

/ *创建新命令并填写* /
cmd = alloc_ble_msg(ble_mgr_gatts_write_cfm_cmd,sizeof(* cmd));
cmd-> conn_idx = conn_idx;
cmd->手柄=手柄;
cmd-> status = status;

if(!ble_cmd_execute(cmd,(void **)&rsp,ble_mgr_gatts_write_cfm_cmd_handler)){
返回ble_error_failed;
}

RET = RSP->状态;
OS_FREE(RSP);

返回Ret;
}

ble_error_t ble_gatts_prepare_write_cfm(uint16_t conn_idx,uint16_t句柄,uint16_t长度,
ATT_ERROR_T状态)
{
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;

/ *创建新命令并填写* /
cmd = alloc_ble_msg(ble_mgr_gatts_prepare_write_cfm_cmd,sizeof(* cmd));
cmd-> conn_idx = conn_idx;
cmd->手柄=手柄;
cmd->长度=长度;
cmd-> status = status;

if(!ble_cmd_execute(cmd,(void **)&rsp,ble_mgr_gatts_prepare_write_cfm_cmd_handler)))){
返回ble_error_failed;
}

RET = RSP->状态;
OS_FREE(RSP);

返回Ret;
}

ble_error_t ble_gatts_send_event(uint16_t conn_idx,uint16_t handle,gatt_event_t类型,
uint16_t长度,const void *值)
{
ble_mgr_gatts_send_event_cmd_t * cmd;
ble_mgr_gatts_send_event_rsp_t * rsp;
ble_error_t ret = ble_error_failed;

/ *创建新命令并填写* /
cmd = alloc_ble_msg(ble_mgr_gatts_send_event_cmd,sizeof(* cmd)+长度);
cmd-> conn_idx = conn_idx;
cmd->手柄=手柄;
cmd-> type = type;
cmd->长度=长度;
memcpy(cmd->值,值,长度);

if(!ble_cmd_execute(cmd,(void **)&rsp,ble_mgr_gatts_send_event_cmd_handler)){
返回ble_error_failed;
}

RET = RSP->状态;
OS_FREE(RSP);

返回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;

/ *创建新命令并填写* /
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))){
返回ble_error_failed;
}

RET = RSP->状态;
OS_FREE(RSP);

返回Ret;
}
#endif / *(dg_configble_gatt_server == 1)* /

关键词:
设备:
mhv_dialog.
离线
最后一次露面:4个月2周前
职员
加入:2013-12-06 15:10
嗨mahmed106,

嗨mahmed106,

负值通常被发送为2的恭维。请参阅以下定义:https://en.wikipedia.org/wiki/two%27s_complement.

/ mhv.