TI的Zstack协议栈SensorDemo例程温度收发说明_第1页
TI的Zstack协议栈SensorDemo例程温度收发说明_第2页
TI的Zstack协议栈SensorDemo例程温度收发说明_第3页
TI的Zstack协议栈SensorDemo例程温度收发说明_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、t 的 zstack 协议栈 sensordemo 例程温度收发学习zigbee也有快ti的sensordemo例程中,打开workspace卜有四种选择, collectoreb,sensoreb collectoreb-pro,sensoreb-pro,其中 pro 代表专业版。 在这里我们主要写一下ti提供的这个例程关于温度数据传送与接收的问题。首 先在workspace卜选择sensoreb(其实这里collectoreb与sensoreb是样的打 开目录app就会发现)打开app后有两个重要的.c文件democollector.c和 demosensor.c,我们发现democoll

2、ector.c是白色的表明该文件在sensoreb模式 下不会被编译。点开 demosensor.c 找到 static void sendreport(void)函数t1定义的温度数据通过无线传输给每个设备的数据格式是这样的1 byte1 byte2 bytestemperaturevoltagepare nt short address温度值和电流值各占一个字节,设备段地址占两个字节,接下来看函数是不是很 容易理解了,呵呵。static void sendreport(void)uint8 pdatasensor_report_length;/存放数据的数组static uints rep

3、ortnr=0;uint8 txoptions;/读温度值pdatasensor_temp_offset = readtempo;/读电压值pdatasensor_voltage_offset = readvoltage();写入设备段地址pdatasensor_parent_offset = hi_uint 16(parentshort addr);pdatasensor_parent_offset + 1 = lo_uint 16(parentshort addr);/ set ack request on each ack_interval report/ if a report fai

4、led, set ack request on next reportif ( +reportnr<ack_req_interval && reportfailurenr=0 )txoptions = af_tx_options_none;elsetxoptions = af_msg_ack_request;reportnr = 0;/ destination address oxfffe: destination address is sent to previously/ established binding for the commandld.发送数据请求,把温度

5、信息发送给地址为0xfffe的设备zb_senddatarequest( oxfffe, sensor_report_cmd_id, sensor_report_length, pdata, 0, txoptions, 0 );这样节点测得的温度信息就可以通过这种方式发送给i办调器了。那么协调器是怎 么接收这些数据的呢?选中collectoreb,打开app目录下的sapi.c文件找到uint16 sapi_processevent( byte task_id, uint16 events )函数,这个函数厉害了,它是來 处理后务的所有事件,这些事件包括定时器,消息以及其他的一些用户定义的事

6、件,在这个函数里我们看到case af_incoming_msg_cmd:pmsgpkt=(afincomingmsgpacket_t *)pmsg;sapi_receivedataindication(pmsgpkt->srcaddr.addr.shortaddr,pmsgpkt->cluster id,pmsgpkt->cmd.datalength, pmsgpkt->cmd.data);break;也就是当消息到來时,会调用sapi_receivedataindication ()函数进一步追踪该 函数 void sapi_receivedataindicatio

7、n( uintl6 source, uintl6 command, uintl6 len, uint8 *pdata )#if defined ( mt_sapi_cb_func )/* first check if mt has subscribed for this callback. if so , pass it asa event to monitortest and return control to calling function after that */if ( s apicb_check( spi_cb_sapi_rcv_data_ind )zb_mtcallbackre

8、ceivedataindication( source, command, len, pdata );else#endif /mt_sapi_cb_func#if (sapi_cb_func)zb_receivedataindication( source, command, len, pdata );#endif这个函数的功能是协议栈提示应用层有其他设备上的数据已经接收到了提示相 关应用来处理,那么处理函数很显然就是zb_receivedataindication( source, command, len, pdata )啦,追踪这个函数可以看到它在democollector.c中定义,接

9、收数据的格式是这样的areq:1112220-84length = 0x06-5a cmdo = 0x46 cmdl = 0x87 source command len dataattributes:attributelength (byte)descriptionsource2specifies the short address of the peer device that sent the data.command2the command id associated with the data.len2specifies the number of bytes in the data parameter.data0-84the data sent by the peer device.这一层的数据格式定义应该不要解释了吧?值得注意的是data最大84个字节, 温度与电压值就是存放在这里的哦,如果想定义自c的数据传输格式就可以在 data里面定义了。好了,既然协调器已经收到数据了那么它是怎么传输给pc机的呢? ti例程里用 的是串口。在void zb_receivedataindication ()函

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论