有无中软国际的Hi3861和其他开发板发送16进制命令通信的demo代码
单片机发送16进制命令的机制是什么,发的是十六进制还是int类型?
串口调试助手中以十六进制发送的机制是什么?发的是什么类型?
该回答引用ChatGPT
Hi3861开发板是华为公司的一个低功耗蓝牙芯片,目前该芯片的SDK和文档已经开放,可以在华为官网上获取。在官网下载安装好SDK和相关工具后,可以使用SDK中提供的接口函数和示例代码来进行蓝牙通信开发。
以下是一个简单的Hi3861开发板蓝牙通信的示例代码,用于向其他设备发送16进制命令:
#include <stdio.h>
#include "hi_types.h"
#include "hi_bt_hci.h"
#include "hi_bt_cmd.h"
#include "hi_bt_errno.h"
#define BT_NAME "Hi3861_Bluetooth"
/* 连接句柄 */
hi_u32 g_conn_handle = 0;
/* 连接事件回调函数 */
static hi_void conn_event_cb(hi_u32 conn_handle, hi_bt_hci_event_type event_type, hi_u8 *param, hi_u16 param_len)
{
switch (event_type) {
case HI_BT_HCI_EVT_CONN_COMPLETE: {
hi_bt_hci_evt_conn_complete *conn_info = (hi_bt_hci_evt_conn_complete*)param;
if (conn_info->status == HI_ERR_SUCCESS) {
printf("Connect to remote device successfully!\n");
g_conn_handle = conn_handle;
} else {
printf("Connect to remote device failed!\n");
}
break;
}
case HI_BT_HCI_EVT_DISCONN_COMPLETE: {
printf("Disconnect to remote device!\n");
g_conn_handle = 0;
break;
}
default:
break;
}
}
/* 发送命令函数 */
hi_u32 send_cmd(hi_u8 *cmd, hi_u16 len)
{
hi_bt_cmd_param param;
hi_bt_hci_cmd_pkt pkt;
if (g_conn_handle == 0) {
printf("Not connected to remote device!\n");
return HI_ERR_BT_NO_CONNECTION;
}
/* 填充命令数据 */
param.data = cmd;
param.len = len;
pkt.opcode = HI_BT_HCI_OPCODE_VS_HUAWEI_SEND_DATA;
pkt.param = ¶m;
/* 发送命令 */
hi_u32 ret = hi_bt_hci_send_cmd(g_conn_handle, &pkt);
if (ret != HI_ERR_SUCCESS) {
printf("Send command failed! error code: 0x%08X\n", ret);
}
return ret;
}
int main(int argc, char *argv[])
{
hi_u8 addr[6] = {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB}; /* 要连接的设备地址 */
hi_u8 cmd[] = {0xAA, 0xBB, 0xCC, 0xDD}; /* 要发送的命令 */
/* 初始化蓝牙 */
hi_u32 ret = hi_bt_hci_init();
if (ret != HI_ERR_SUCCESS) {
printf("Bluetooth init failed! error code: 0x%08X\n", ret);
return ret;
}
/* 注册连接事件回调函数 */
hi_bt_hci_set_event_cb(HI_BT_HCI_EVT_CONN_COMPLETE, conn_event_cb);
hi_bt_hci_set_event_cb(HI_BT_HCI_EVT_DISCONN_COMPLETE, conn_event