全志XR806蓝牙透传(单向)测试

评测三 蓝牙透传(单向)
有时无线透传在无法布线时有很方便的效用,不妨试试蓝牙透传,效果如下:

具体是无线数据->串口数据,串口数据->无线数据,目前前者实现了,后者还有些问题未解决,

在这里插入图片描述

实现过程如下,基于工程demo/Bluetooth/peripheral_demo改成peripheral_uart_demo,同时目录下peripheral_uart_demo/gcc/defconfig文件里工程名也改成peripheral_uart_demo,然后引入串口读写独立接口即把demo/at_demo下的serial.c、serial.h、serial_debug.h复制到刚才peripheral_uart_demo工程下,由于要无线写以及串口写转无线,所以profile涉及到write_without_rsp和notify,具体配置为:
服务 特征
UUID 12345678-1234-5678-56789abcdef0 12345678-1234-5678-56789abcdef1
Properties Write no response/Notify

static struct bt_gatt_attr vnd_attrs[] = {
	/* Vendor Primary Service Declaration */
	BT_GATT_PRIMARY_SERVICE(&vnd_uuid),
	BT_GATT_CHARACTERISTIC(&vnd_enc_uuid.uuid,
	                BT_GATT_CHRC_WRITE_WITHOUT_RESP | BT_GATT_CHRC_NOTIFY,
	                BT_GATT_PERM_WRITE,
	                NULL, write_without_rsp_vnd, &vnd_value),
	BT_GATT_CCC(vnd_ccc_notify_changed, BT_GATT_PERM_READ|BT_GATT_PERM_WRITE),
};

写回调接口为:

/**********************vnd_write_cmd_uuid*****************************/
static ssize_t write_without_rsp_vnd(struct bt_conn *conn,
                const struct bt_gatt_attr *attr,
                const void *buf, uint16_t len, uint16_t offset,
                uint8_t flags)
{
	uint8_t *value = attr->user_data;

	/* Write request received. Reject it since this char only accepts
	 * Write Commands.
	 */
	if (!(flags & BT_GATT_WRITE_FLAG_CMD)) {
		return BT_GATT_ERR(BT_ATT_ERR_WRITE_REQ_REJECTED);
	}

	if (offset + len > sizeof(vnd_value)) {
		return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
	}

	memset(value, 0, sizeof(vnd_value));
	memcpy(value + offset, buf, len);
	serial_write(value + offset, len);
	*(value + offset + len) = '\0';
	printf("\r\nwrite_without_rsp_vnd");
	return len;
}

串口转无线回调(有问题):

static void vnd_notify(void)
{
	static uint8_t vnd[MAX_LONG_DATA];
	uint16_t len=0;
	if (!vnd_notif_enabled)
		return;
	printf("\r\nnotify\r\n");
	serial_read(vnd_notify_value,len);
	if(len>MAX_LONG_DATA || len==0)
		return;
	memcpy(vnd, vnd_notify_value, len);
    printf("\r\nvnd_notify\r\n");
	bt_gatt_notify(NULL, &vnd_svc.attrs[1], vnd, sizeof(vnd));
}

然后在bt_app_init函数里加入透传口UART1的初始化代码即可:

	serial_init(SERIAL_UART_ID, 115200, UART_DATA_BITS_8, UART_PARITY_NONE,
		UART_STOP_BITS_1, 0);
	serial_start();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值