博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
文件选择用zstack实现自己的sample--点灯
阅读量:6794 次
发布时间:2019-06-26

本文共 7668 字,大约阅读时间需要 25 分钟。

本文纯属个人见解,是对前面学习的总结,如有描述不正确的地方还请高手指正~

    1,复制samples上面的GenericApp,并粘贴到以后文件夹下,重命名为LED;

    2,删除GenericApp.c和GenericApp.h

    3,  新建 文件Coordinator.h,Coordinator.c  Enddevice.c并且将文件添加到工程 。

    三个文件里面的代码如下:

    Coordinator.h:

#ifndef COORDINATOR_H#define COORDINATOR_H#include "ZComDef.h"#define GENERICAPP_ENDPOINT                10#define GENERICAPP_PROFID                  0x0F04 #define GENERICAPP_DEVICEID                0x0001#define GENERICAPP_DEVICE_VERSION          0   #define GENERICAPP_FLAGS                   0#define GENERICAPP_MAX_CLUSTERS            1  #define GENERICAPP_CLUSTERID               1extern void GenericApp_Init(byte task_id);extern UINT16 GenericApp_ProcessEvent(byte task_id, UINT16 events);#endif

    Coordinator.c:

#include "OSAL.h"#include "AF.h"#include "ZDApp.h"#include "ZDObject.h"#include "ZDProfile.h"#include "Coordinator.h"#include "DebugTrace.h"#if !defined( WIN32 )  #include "OnBoard.h"#endif/* HAL */#include "hal_lcd.h"#include "hal_led.h"#include "hal_key.h"#include "hal_uart.h"#include 
// This list should be filled with Application specific Cluster IDs.const cId_t GenericApp_ClusterList[GENERICAPP_MAX_CLUSTERS] ={ GENERICAPP_CLUSTERID};const SimpleDescriptionFormat_t GenericApp_SimpleDesc ={ GENERICAPP_ENDPOINT, // int Endpoint; GENERICAPP_PROFID, // uint16 AppProfId[2]; GENERICAPP_DEVICEID, // uint16 AppDeviceId[2]; GENERICAPP_DEVICE_VERSION, // int AppDevVer:4; GENERICAPP_FLAGS, // int AppFlags:4; GENERICAPP_MAX_CLUSTERS, // byte AppNumInClusters; (cId_t *)GenericApp_ClusterList, // byte *pAppInClusterList; GENERICAPP_MAX_CLUSTERS, // byte AppNumInClusters; (cId_t *)GenericApp_ClusterList // byte *pAppInClusterList;};endPointDesc_t GenericApp_epDesc;byte GenericApp_TaskID; // Task ID for internal task/event processing // This variable will be received when // GenericApp_Init() is called.byte GenericApp_TransID; // This is the unique message ID (counter)void GenericApp_MessageMSGCB ( afIncomingMSGPacket_t *pckt);void GenericApp_SendTheMessage( void);void GenericApp_Init(byte task_id){ GenericApp_TaskID = task_id; GenericApp_TransID = 0; GenericApp_epDesc.endPoint = GENERICAPP_ENDPOINT; GenericApp_epDesc.task_id = &GenericApp_TaskID; GenericApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&GenericApp_SimpleDesc; GenericApp_epDesc.latencyReq = noLatencyReqs; afRegister(&GenericApp_epDesc);}UINT16 GenericApp_ProcessEvent( byte task_id, UINT16 events ){ afIncomingMSGPacket_t *MSGpkt; if ( events & SYS_EVENT_MSG ) { MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive(GenericApp_TaskID); while( MSGpkt ) { switch ( MSGpkt->hdr.event ) { case AF_INCOMING_MSG_CMD: { GenericApp_MessageMSGCB( MSGpkt ); break; } default: break; } osal_msg_deallocate( (uint8 *)MSGpkt ); MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive (GenericApp_TaskID); } return (events ^ SYS_EVENT_MSG); } return 0;}void GenericApp_MessageMSGCB(afIncomingMSGPacket_t *pkt){ unsigned char buffer[4] = " "; switch ( pkt->clusterId) { case GENERICAPP_CLUSTERID: { osal_memcpy(buffer,pkt->cmd.Data,3); if ( (buffer[0] == 'L') || (buffer[1] == 'E') || (buffer[2] == 'D')) { HalLedBlink(HAL_LED_2,0,50,500); } else { HalLedSet(HAL_LED_2,HAL_LED_MODE_ON); } break; } }}
    每日一道理
生命,是一场漫长的棋局。这盘棋没有猎猎西风,没有四起狼烟,只有在取舍和进退中抉择。只有像棋中的小卒那样,勇往直前,毫不退缩沿着沟沟坎坎的人生之路,艰难而执着的求索,前进,才会谱写人生最壮丽的强者之歌。

    Enddevice.c:

#include "OSAL.h"#include "AF.h"#include "ZDApp.h"#include "ZDObject.h"#include "ZDProfile.h"#include "Coordinator.h"#include "DebugTrace.h"#if !defined( WIN32 )  #include "OnBoard.h"#endif/* HAL */#include "hal_lcd.h"#include "hal_led.h"#include "hal_key.h"#include "hal_uart.h"#include 
// This list should be filled with Application specific Cluster IDs.const cId_t GenericApp_ClusterList[GENERICAPP_MAX_CLUSTERS] ={ GENERICAPP_CLUSTERID};const SimpleDescriptionFormat_t GenericApp_SimpleDesc ={ GENERICAPP_ENDPOINT, // int Endpoint; GENERICAPP_PROFID, // uint16 AppProfId[2]; GENERICAPP_DEVICEID, // uint16 AppDeviceId[2]; GENERICAPP_DEVICE_VERSION, // int AppDevVer:4; GENERICAPP_FLAGS, // int AppFlags:4; GENERICAPP_MAX_CLUSTERS, // byte AppNumInClusters; (cId_t *)GenericApp_ClusterList, // byte *pAppInClusterList; GENERICAPP_MAX_CLUSTERS, // byte AppNumInClusters; (cId_t *)GenericApp_ClusterList // byte *pAppInClusterList;};endPointDesc_t GenericApp_epDesc;byte GenericApp_TaskID; // Task ID for internal task/event processing // This variable will be received when // GenericApp_Init() is called.byte GenericApp_TransID; // This is the unique message ID (counter)devStates_t GenericApp_NwkState;void GenericApp_MessageMSGCB ( afIncomingMSGPacket_t *pckt);void GenericApp_SendTheMessage( void);void GenericApp_Init(byte task_id){ GenericApp_TaskID = task_id; GenericApp_NwkState = DEV_INIT; GenericApp_TransID = 0; GenericApp_epDesc.endPoint = GENERICAPP_ENDPOINT; GenericApp_epDesc.task_id = &GenericApp_TaskID; GenericApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&GenericApp_SimpleDesc; GenericApp_epDesc.latencyReq = noLatencyReqs; afRegister(&GenericApp_epDesc);}UINT16 GenericApp_ProcessEvent( byte task_id, UINT16 events ){ afIncomingMSGPacket_t *MSGpkt; if ( events & SYS_EVENT_MSG ) { MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive(GenericApp_TaskID); while( MSGpkt ) { switch ( MSGpkt->hdr.event ) { case ZDO_STATE_CHANGE: { GenericApp_NwkState = (devStates_t)(MSGpkt->hdr.status); if(GenericApp_NwkState == DEV_END_DEVICE) { GenericApp_SendTheMessage(); } break; } default: break; } osal_msg_deallocate( (uint8 *)MSGpkt ); MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive (GenericApp_TaskID); } return (events ^ SYS_EVENT_MSG); } return 0;}void GenericApp_SendTheMessage( void ){ unsigned char theMessageDate[4] = "LED"; afAddrType_t my_DstAddr; my_DstAddr.addrMode = (afAddrMode_t)Addr16Bit; my_DstAddr.endPoint = GENERICAPP_ENDPOINT; my_DstAddr.addr.shortAddr = 0x0000; AF_DataRequest( &my_DstAddr, &GenericApp_epDesc, GENERICAPP_CLUSTERID, 3, theMessageDate, &GenericApp_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS); HalLedBlink(HAL_LED_2,0,50,500);}

    选择CoodinatorEB,在Endevice.c上右键选择options,把Exclude from build  这个选项勾选 上;

    同样选择Endevice,让Coordinator.c不编译 。

    分别将两个程序下载到 两个不同的板子 上。先开启协调器的电源,这时候LED2的灯是 没有 闪烁的,再开启终端设备的电源 ,过几秒后后协调器 和终端设备的LED2会一同闪烁。

文章结束给大家分享下程序员的一些笑话语录: 问答

Q:你是怎么区分一个内向的程序员和一个外向的程序员的? A:外向的程序员会看着你的鞋和你说话时。
Q:为什么程序员不能区分万圣节和圣诞节? A:这是因为 Oct 31 == Dec 25!(八进制的 31==十进制的 25)

转载地址:http://lbrgo.baihongyu.com/

你可能感兴趣的文章
mysql注入绕过tips
查看>>
移动应用在线开发平台Appcan将支持开发者在线编译证书并将应用提交到苹果应用商店...
查看>>
hsrp实验
查看>>
IBM 开发资源库
查看>>
linux系统的负载与CPU、内存、硬盘、用户数监控shell脚本
查看>>
岁月催人老
查看>>
获取用户Ip地址通用方法常见安全隐患(HTTP_X_FORWARDED_FOR)
查看>>
出场率比较高的一道多线程安全面试题
查看>>
swt browser控件与java交互
查看>>
深度剖析Service Mesh服务网格新生代Istio
查看>>
Memcached笔记
查看>>
SCVMM 2012系列之一——安装部署
查看>>
zabbix通过skype发送报警消息之弯路
查看>>
我的友情链接
查看>>
Android开发
查看>>
jQuery stop()浅析
查看>>
我的友情链接
查看>>
linux下修改path
查看>>
几行代码,让你的app动感起来--Android Design Support Library使用
查看>>
Jquery实现回车键Enter切换焦点
查看>>