找回密码
 立即注册

使用微信账号登录

只需一步,快速开始

csr867x入门之spp使用(gaia方式)

2020-5-17 10:24| 发布者: csdn| 查看: 1844| 评论: 0|来自: CSDN

摘要: 简述 Adk4.1默认是没有spp应用实现的的,所以需要自己加入相关逻辑 Adk底层提供了两种方法:shim和gaia,本篇文章里面主要是讲解如何使用gaia来实现spp的数据收发,shim方式请参考下面的博文:https://blog.cs

简述

Adk4.1默认是没有spp应用实现的的,所以需要自己加入相关逻辑  
Adk底层提供了两种方法:shim和gaia,本篇文章里面主要是讲解如何使用gaia来实现spp的数据收发,shim方式请参考下面的博文:https://blog.csdn.net/zhanghuaishu0/article/details/79863430

使能gaia

首先在配置选项中使用gaia功能,如下图所示:

Spp数据发送

由于只提供了底层的数据发送接口,所以我在GaiaSendPacket()接口的基础上,在上层封装了一个如下函数:
void gaia_send_sppdata(uint8 *payload, uint16 payload_length)
{
	gaia_transport_type type;
	uint8 *packet;
	uint8 flags;
	uint16 len;

	type = GaiaTransportGetType(gaia_data.gaia_transport);
	flags = GaiaTransportGetFlags(gaia_data.gaia_transport);
	GaiaTransportSetType(gaia_data.gaia_transport, gaia_transport_spp);

	if (flags & GAIA_PROTOCOL_FLAG_CHECK) {
		len = payload_length +1;
	} else {
		len = payload_length;
	}

	packet = mallocPanic(len);

	if (packet) {
		memmove(packet, payload, payload_length);
	}

	if (flags & GAIA_PROTOCOL_FLAG_CHECK) {
		uint8 check = 0;
		while (--payload_length)
			check ^= *packet++;
		*(packet+payload_length) = check;
	}

	GaiaSendPacket(gaia_data.gaia_transport, len, packet);
	GaiaTransportSetType(gaia_data.gaia_transport, type);
}
有两个需要注意的地方:一个是transtype,这个值决定了使用的是那个传输通道,比如spp,gatt,rfcomm等,所以这个地方我将他置为gaia_transport_spp;第二是通过GaiaSendPacket接口发送数据时,还需要封装gaia的协议,组包格式可以参考build_packet()接口。 
然后再利用AT指令将数据发送出去:
void handleSppSendData(Task t, const struct SppSendData *send_data)
{
	if(stateManagerGetState() > deviceConnDiscoverable){
		gaia_send_sppdata((uint8 *)send_data->data.data, send_data->data.length);
		UartSendStr("OK\r\n");
	}else{
		UartSendStr("ERROR\r\n");
	}
}

Spp数据接收

当接收到远端发来的spp数据,首先进入gaia.c中的message_handler进行数据分发, 然后进入在spp的处理函数gaiaTransportSppHandleMessage中判断消息类型,当为spp数据时,其msg id为MESSAGE_MORE_DATA,然后到gaiaTransportProcessSource数据进行处理。 

 
来源:https://blog.csdn.net/ylangeia/article/details/103315432
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

路过

雷人

握手

鲜花

鸡蛋

相关阅读

最新评论

小黑屋|手机版|我爱蓝牙网 - 52Bluetooth

GMT+8, 2024-5-5 06:46 , Processed in 0.208878 second(s), 32 queries , Gzip On, MemCached On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

返回顶部