




已阅读5页,还剩15页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
sappleapp.c#include osal.h#include zglobals.h#include af.h#include aps_groups.h#include zdapp.h#include sampleapp.h#include sampleapphw.h#include onboard.h/* hal */#include hal_lcd.h#include hal_led.h#include hal_key.h#include string.h#include mt_uart.h/#include lcd128x64.h#include utoled.h#include sensor.h#include hal_adc.h#include exsensor.h#include lcd128_64.hconst cid_t sampleapp_clusterlistsampleapp_max_clusters = sampleapp_periodic_clusterid, sampleapp_flash_clusterid;const simpledescriptionformat_t sampleapp_simpledesc = sampleapp_endpoint, / int endpoint; sampleapp_profid, / uint16 appprofid2; sampleapp_deviceid, / uint16 appdeviceid2; sampleapp_device_version, / int appdevver:4; sampleapp_flags, / int appflags:4; sampleapp_max_clusters, / uint8 appnuminclusters; (cid_t *)sampleapp_clusterlist, / uint8 *pappinclusterlist; sampleapp_max_clusters, / uint8 appnuminclusters; (cid_t *)sampleapp_clusterlist / uint8 *pappinclusterlist;endpointdesc_t sampleapp_epdesc;uint8 sampleapp_taskid;devstates_t sampleapp_nwkstate;uint8 sampleapp_transid; uint8 changeline2=0x0a,0x0d;union h uint8 rxbuf70; union_data rxdata;uartrxbuf;/串口接收缓冲区union e uint8 txbuf70; union_data txdata;uarttxbuf;/串口发送缓冲区union f uint8 rxbuf70; union_data rxdata;rfrx;/无线接收缓冲区union g uint8 txbuf70; union_data txdata;rftx;/无线接收缓冲区void sampleapp_messagemsgcb( afincomingmsgpacket_t *pckt );void sampleapp_senddata(unsigned char buff,uint8 length);static void rxcb(uint8 port, uint8 event);void sampleapp_init( uint8 task_id ) haluartcfg_t uartconfig; sampleapp_taskid = task_id; sampleapp_nwkstate = dev_init; sampleapp_transid = 0; sampleapp_epdesc.endpoint = sampleapp_endpoint; sampleapp_epdesc.task_id = &sampleapp_taskid; sampleapp_epdesc.simpledesc = (simpledescriptionformat_t *)&sampleapp_simpledesc; sampleapp_epdesc.latencyreq = nolatencyreqs; afregister( &sampleapp_epdesc ); registerforkeys( sampleapp_taskid ); mt_uartregistertaskid(sampleapp_taskid); lcdinit(); clearscreen(); print(0,10,coordinator,1); print(2,5,zhanghang,1); print(4,5,fengguangwen,1); print(6,5,yaojiadong,1); uartconfig.configured = true; uartconfig.baudrate = hal_uart_br_115200; uartconfig.flowcontrol = false; uartconfig.callbackfunc = rxcb ; /uartconfig.callbackfunc = null ; haluartopen( 0, &uartconfig);uint16 sampleapp_processevent( uint8 task_id, uint16 events ) afincomingmsgpacket_t *msgpkt; (void)task_id;if ( events & sys_event_msg )msgpkt = (afincomingmsgpacket_t *)osal_msg_receive( sampleapp_taskid );while ( msgpkt )switch ( msgpkt-hdr.event )case zdo_state_change:sampleapp_nwkstate = (devstates_t)(msgpkt-hdr.status); halledblink(0x02,0,50,500); uint8 *buff; buff0=a; buff1=b; buff2=c; haluartwrite(0,buff,3); haluartwrite(0,changeline,2);break; case af_incoming_msg_cmd: halledblink(0x01,0,50,500);sampleapp_messagemsgcb( msgpkt ); break; /*case spi_incoming_ztool_port: halledblink(0x02,0,50,500); rxcbx();*/default:break;osal_msg_deallocate( (uint8 *)msgpkt );msgpkt = (afincomingmsgpacket_t *)osal_msg_receive( sampleapp_taskid );return (events sys_event_msg);return 0;static uint8 serialapp_txlen;void sampleapp_messagemsgcb( afincomingmsgpacket_t *pkt ) unsigned char buffer42; osal_memcpy(buffer,pkt-cmd.data ,42); haluartwrite(0,buffer,42); haluartwrite(0,changeline,2); /* unsigned char buffer100; osal_memcpy(buffer,pkt-cmd.data ,100); serialapp_txlen=haluartread(0,buffer,100); haluartwrite(0,buffer,serialapp_txlen); haluartwrite(0,changeline,2); */ void sampleapp_senddata(uint8 buff,uint8 length) afaddrtype_t senddataaddr;senddataaddr.addrmode = (afaddrmode_t)addrbroadcast;senddataaddr.endpoint = sampleapp_endpoint;senddataaddr.addr.shortaddr = 0xffff; af_datarequest( &senddataaddr, &sampleapp_epdesc, 2, length, buff, &sampleapp_transid, af_discv_route, af_default_radius ); static void rxcb(uint8 port, uint8 event) uint8 length = hal_uart_rxbuflen(0); uint8 *buff; buff = osal_mem_alloc(length); haluartread(0,buff,length); if(length!=0) sampleapp_senddata(buff,length); printn8(5,5,length,1,3); osal_mem_free(buff);router.c#include osal.h#include zglobals.h#include af.h#include aps_groups.h#include zdapp.h#include sampleapp.h#include sampleapphw.h#include onboard.h#include iocc2530.h/* hal */#include hal_lcd.h#include hal_led.h#include hal_key.h#include string.h#include mt_uart.h/#include lcd128x64.h#include utoled.h#include sensor.h#include hal_adc.h#include exsensor.h#include lcd128_64.hconst cid_t sampleapp_clusterlistsampleapp_max_clusters = sampleapp_periodic_clusterid, sampleapp_flash_clusterid;const simpledescriptionformat_t sampleapp_simpledesc = sampleapp_endpoint, / int endpoint; sampleapp_profid, / uint16 appprofid2; sampleapp_deviceid, / uint16 appdeviceid2; sampleapp_device_version, / int appdevver:4; sampleapp_flags, / int appflags:4; sampleapp_max_clusters, / uint8 appnuminclusters; (cid_t *)sampleapp_clusterlist, / uint8 *pappinclusterlist; sampleapp_max_clusters, / uint8 appnuminclusters; (cid_t *)sampleapp_clusterlist / uint8 *pappinclusterlist;endpointdesc_t sampleapp_epdesc;uint8 sampleapp_taskid;devstates_t sampleapp_nwkstate;uint8 sampleapp_transid; uint8 mymac16;/物理地址uint8 myshort4;/本节点网络地址uint8 temp; uint16 nwk;uint8 readbuf50;uint8 sendbuf50;uint8 changeline2=0x0a,0x0d;uint8 ledstate =1;uint8 ledstate5=1;uint8 ledstate6=1;uint8 people=0;uint8 people1=0;uint8 people2=0;uint8 light=115;int timexx1=0;int timexx2=0;union h uint8 rxbuf70; union_data rxdata;uartrxbuf;/串口接收缓冲区union e uint8 txbuf70; union_data txdata;uarttxbuf;/串口发送缓冲区union f uint8 rxbuf70; union_data rxdata;rfrx;/无线接收缓冲区union g uint8 txbuf70; union_data txdata;rftx;/无线接收缓冲区typedef struct rftxbuf uint8 mynwk4; uint8 mymac16; uint8 pnwk4; uint8 pmac16;rftx;void sampleapp_handlekey( uint8 shift, uint8 keys );void sampleapp_senddata(void);void datapack(void);void sampleapp_messagemsgcb( afincomingmsgpacket_t *pkt );void tostring(uint8 *dest, char *src ,uint8 length);void showscreen(void);void halinit(void);void dolight(void);void sampleapp_init( uint8 task_id ) haluartcfg_t uartconfig; sampleapp_taskid = task_id; sampleapp_nwkstate = dev_init; sampleapp_transid = 0; sampleapp_epdesc.endpoint = sampleapp_endpoint; sampleapp_epdesc.task_id = &sampleapp_taskid; sampleapp_epdesc.simpledesc = (simpledescriptionformat_t *)&sampleapp_simpledesc; sampleapp_epdesc.latencyreq = nolatencyreqs; afregister( &sampleapp_epdesc ); registerforkeys( sampleapp_taskid ); mt_uartregistertaskid(sampleapp_taskid); halinit(); uartconfig.configured = true; uartconfig.baudrate = hal_uart_br_115200; uartconfig.flowcontrol = false; uartconfig.callbackfunc = null; haluartopen( 0, &uartconfig);uint16 sampleapp_processevent( uint8 task_id, uint16 events ) afincomingmsgpacket_t *msgpkt; (void)task_id;if ( events & sys_event_msg )msgpkt = (afincomingmsgpacket_t *)osal_msg_receive( sampleapp_taskid );while ( msgpkt )switch ( msgpkt-hdr.event )case zdo_state_change:sampleapp_nwkstate = (devstates_t)(msgpkt-hdr.status); if(sampleapp_nwkstate = dev_router) halledblink(0x02,0,50,500); / datapack(); / osal_set_event(sampleapp_taskid,send_data_event); / osal_set_event(sampleapp_taskid,show_data_event); / osal_set_event(sampleapp_taskid,light_event); / clearscreen(); uint8 *buff; buff0=a; buff1=b; buff2=c; haluartwrite(0,buff,3); haluartwrite(0,changeline,2); break; case af_incoming_msg_cmd: halledblink(0x01,0,50,500); sampleapp_messagemsgcb(msgpkt); break;default:break;osal_msg_deallocate( (uint8 *)msgpkt );msgpkt = (afincomingmsgpacket_t *)osal_msg_receive( sampleapp_taskid ); return (events sys_event_msg); if(events & send_data_event) sampleapp_senddata(); osal_start_timerex(sampleapp_taskid,send_data_event,1000); return (events send_data_event); if(events & show_data_event) showscreen(); datapack(); dolight(); osal_start_timerex(sampleapp_taskid,show_data_event,100); return (events show_data_event); return 0;void datapack(void) sendbuf0=&;sendbuf1=s; /数据包头包括节点类型 sendbuf2=c;sendbuf3=u; sendbuf4=r;sendbuf5=o; sendbuf6=3; tostring(mymac,nlme_getextaddr(),8); / 物理地址 for(int i=7;i=22;i+)sendbufi=mymaci-7; nwk= nlme_getshortaddr(); /网络地址 tostring(myshort,(uint8 *)&nwk,2); for(int i=23;i=26;i+)sendbufi=myshorti-23; temp=readtemp(); /温度信息 sendbuf27=temp/10+0; sendbuf28=temp%10+0; unsigned char adc=haladcread(0x00,1); /光感传感器值 sendbuf29=adc/100+0; sendbuf30=(adc/10)%10+0; sendbuf31=adc%10+0; sendbuf32=ledstate + 0; /总灯光控制 sendbuf33=ledstate5+ 0; /两路灯光控制 sendbuf34=ledstate6+ 0; people=p0_4; /来人检测 sendbuf35= people + 0; sendbuf36=light; /光感阙值 用于判断灯的亮否 for(int i=37;icmd.data,42); /张航 unsigned char buffer42; osal_memcpy(buffer,pkt-cmd.data ,42); haluartwrite(0,buffer,42); haluartwrite(0,changeline,2); /* unsigned char buffer100; osal_memcpy(buffer,pkt-cmd.data ,100); serialapp_txlen=haluartread(0,buffer,100); haluartwrite(0,buffer,serialapp_txlen); haluartwrite(0,changeline,2); */ /任意长度字符串 /* if(buff5=o&buff6=3) /uint8 changeline2=0x0a,0x0d; /haluartwrite(0,buff,42); /haluartwrite(0,changeline,2); if(buff32=0)ledstate =0; else ledstate =1; if(buff33=0)ledstate5=0; else ledstate5=1; if(buff34=0)ledstate6=0; else ledstate6=1; if(buff35=0)people=0; else people=1; light=buff36; */void tostring(uint8 *dest, char *src ,uint8 length) uint8 *xad; uint8 i = 0; uint8 ch; xad = src +length -1; for(i=0;i4)&0x0f; desti1=ch+(ch10)?0:7); ch=*xad & 0x0f; dest(i1)+1=ch+(chlight) if(timexx120) if(people=0)p0_5=1; timexx1=0; goto ll; if(people=1)p0_5=0;timexx1=0; else if(people=0)timexx1+; else p0_5=1; ll :; if(ledstate6=0)p0_6=1; else if(ledstate6=1) if(adclight) if(timexx220) if(people=0)p0_6=1; timexx2=0; goto xx; if(people=1)p0_6=0;timexx2=0; else if(people=0)timexx2+; else p0_6=1; xx:; enddevice.c#include osal.h#include zglobals.h#include af.h#include aps_groups.h#include zdapp.h#include sampleapp.h#include sampleapphw.h#include onboard.h/* hal */#include hal_lcd.h#include hal_led.h#include hal_key.h#include string.h#include mt_uart.h/#include lcd128x64.h#include utoled.h#include sensor.h#include hal_adc.h#include exsensor.h#include lcd128_64.hconst cid_t sampleapp_clusterlistsampleapp_max_clusters = sampleapp_periodic_clusterid, sampleapp_flash_clusterid;const simpledescriptionformat_t sampleapp_simpledesc = sampleapp_endpoint, / int endpoint; sampleapp_profid, / uint16 appprofid2; sampleapp_deviceid, / uint16 appdeviceid2; sampleapp_device_version, / int appdevver:4; sampleapp_flags, / int appflags:4; sampleapp_max_clusters, / uint8 appnuminclusters; (cid_t *)sampleapp_clusterlist, / uint8 *pappinclusterlist; sampleapp_max_clusters, / uint8 appnuminclusters; (cid_t *)sampleapp_clusterlist / uint8 *pappinclusterlist;endpointdesc_t sampleapp_epdesc;uint8 sampleapp_taskid;devstates_t sampleapp_nwkstate;uint8 sampleapp_transid; uint8 mymac16;/物理地址uint8 myshort4;/本节点网络地址uint8 temp; uint16 nwk;uint8 readbuf50;uint8 sendbuf50;uint8 changeline2=0x0a,0x0d;uint8 ledstate=0;uint8 people=0;union h uint8 rxbuf70; union_data rxdata;uartrxbuf;/串口接收缓冲区union e uint8 txbuf70; union_data txdata;uarttxbuf;/串口发送缓冲区union f uint8 rxbuf70; union_data rxdata;rfrx;/无线接收缓冲区union g uint8 txbuf70; union_data txdata;rftx;/无线接收缓冲区typedef struct rftxbuf uint8 mynwk4; uint8 mymac16; uint8 pnwk4; uint8 pmac16;rftx;void sampleapp_handlekey( uint8 shift, uint8 keys );void sampleapp_senddata(void);void datapack(void);void sampleapp_messagemsgcb( afincomingmsgpacket_t *pkt );void tostring(uint8 *dest, char *src ,ui
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 转权转让合同范本
- 拆除窗户出售合同范本
- 购房定向开发合同范本
- 个人安全用工合同范本
- 社区工会消防知识培训班课件
- 限期包销房合同范本
- 甲方商铺租赁合同范本
- 施工框架搭建合同范本
- 盖房施工合同范本
- 广告物料结款合同范本
- 政府会计(第八版)课件 王宗江 第1、2章 政府会计概述、流动资产
- 健康保险相关行业公司成立方案及可行性研究报告
- 彩钢瓦检验批
- 还款计划书15篇
- 送货单完整模板
- 如何成为一名好的医生
- 雅安市雨城区2024年重点中学小升初数学入学考试卷含解析
- JBT 9229-2024 剪叉式升降工作平台(正式版)
- 土地出租合同书电子版
- 小升初测试(试题)-2023-2024学年六年级下册数学苏教版
- 《化妆品稳定性试验规范》
评论
0/150
提交评论