ZigBee学习之40—Home Automation Profile3.doc_第1页
ZigBee学习之40—Home Automation Profile3.doc_第2页
ZigBee学习之40—Home Automation Profile3.doc_第3页
ZigBee学习之40—Home Automation Profile3.doc_第4页
ZigBee学习之40—Home Automation Profile3.doc_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

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

文档简介

#1楼主:【原创】ZigBee学习之40Home Automation Profile3文章发表于:2010-02-26 10:20static void zclProcessMessageMSG( afIncomingMSGPacket_t *pkt )/首先检查命令域的数据长度,如果没有数据则直接退出 if ( pkt-cmd.DataLength = 0 )return; / Error, ignore the message/然后检查消息的目的终端是否存在于节点上,若不是发送给此节点的则退出 epDesc = afFindEndPointDesc( pkt-endPoint ); if ( epDesc = NULL )return; / Error, ignore the message/将簇ID转换到逻辑簇ID,如果为0xFFFF则退出 logicalClusterID = zclConvertClusterID( pkt-clusterId, epDesc-simpleDesc-AppProfId, TRUE ); if ( logicalClusterID = ZCL_INVALID_CLUSTER_ID )return; / Error, ignore the message/检查设备是否可操作,即检查DEVICE_ENABLED属性 if ( zcl_DeviceOperational( pkt-endPoint, pkt-clusterId, inMsg.hdr.fc.type, inMmandID ) = FALSE ) return; / Error, ignore the message/一下是处理和解析收到的命令 if ( zcl_ProfileCmd( inMsg.hdr.fc.type ) ) /收到的是针对剖面的命令比如读写属性,报告属性,身份认证等 if ( inMsg.hdr.fc.manuSpecific ) / We dont support any manufacturer specific command /不支持生产商的特定命令 status = ZCL_STATUS_UNSUP_MANU_GENERAL_COMMAND; else if ( ( inMmandID endPoint; parseCmd.dataLen = inMsg.pDataLen; parseCmd.pData = inMsg.pData; / Parse the command, remember that the return value is a pointer to allocated memory inMsg.attrCmd = zclParseCmd( inMmandID, &parseCmd ); if ( (inMsg.attrCmd != NULL) & (zclCmdTableinMmandID.pfnProcessInProfile != NULL) ) / Process the command if ( zclProcessCmd( inMmandID, &inMsg ) = FALSE ) /处理此命令不成功 / Couldnt find attribute in the table. else /处理此簇ID的特殊命令 / Nope, must be specific to the cluster ID /为实际的簇ID查找合适的插头 / Find the appropriate pluginpInPlugin = zclFindPlugin( pkt-clusterId, epDesc-simpleDesc-AppProfId );/在这个查找插头的函数中关联了一个静态变量plugins,这个变量中指明了插头的范围以及处理输入消息的函数,其数据结构定义为:【zcl.c】typedef struct zclLibPlugin struct zclLibPlugin *next; uint16 startLogCluster; / starting logical cluster ID uint16 endLogCluster; / ending logical cluster ID zclInHdlr_t pfnIncomingHdlr; / function to handle incoming message zclLibPlugin_t;/在zclSampleLight_Init()中我们通过调用zclGeneral_RegisterCmdCallbacks()来注册了插头:/ zcl_registerPlugin( ZCL_GEN_LOGICAL_CLUSTER_ID_BASIC,/ ZCL_GEN_LOGICAL_CLUSTER_ID_LOCATION,/ zclGeneral_HdlIncoming );/ZStatus_t zcl_registerPlugin( uint16 startLogCluster, uint16 endLogCluster, zclInHdlr_t pfnIncomingHdlr )/ Find spot in list/在这个函数中我们对静态变量plugins进行了填充 if ( plugins = NULL ) plugins = pNewItem; else / Look for end of list pLoop = plugins; while ( pLoop-next != NULL ) pLoop = pLoop-next; / Put new item at end of list pLoop-next = pNewItem; return ( ZSuccess );/对应的回调函数zclGeneral_HdlIncoming()首先检查接收的消息是否是簇的特定命令,然后调用zclGeneral_HdlInSpecificCommands()来处理不同的命令:static ZStatus_t zclGeneral_HdlInSpecificCommands( zclIncoming_t *pInMsg, uint16 logicalClusterID ) ZStatus_t stat; switch ( logicalClusterID ) /逻辑簇ID存在是进行判断的基础#ifdef ZCL_ON_OFF/调用处理开关簇的处理函数 case ZCL_GEN_LOGICAL_CLUSTER_ID_ON_OFF: stat = zclGeneral_ProcessInOnOff( pInMsg );static ZStatus_t zclGeneral_ProcessInOnOff( zclIncoming_t *pInMsg ) zclGeneral_AppCallbacks_t *pCBs; if ( zcl_ServerCmd( pInMsg-hdr.fc.direction ) ) /只处理服务器方向,因为对于开关簇来说,灯是作为服务端,被其他设备控制的 if ( pInMmandID COMMAND_TOGGLE ) return ( ZFailure ); / Error ignore the commandpCBs = zclGeneral_FindCallbacks( pInMsg-msg-endPoint );/通过终端号来查找相应的命令回调函数,在这个查找命令回调函数的函数中又调用了一个静态变量zclGenCBs,这个变量保存着终端与命令回调函数的对应,其数据结构如下:typedef struct zclGenCBRec struct zclGenCBRec *next; uint8 endpoint; / Used to link it into the endpoint descriptor zclGeneral_AppCallbacks_t *CBs; / Pointer to Callback function zclGenCBRec_t;/这个变量在zcl应用任务初始化注册回调函数时也同时注册了:ZStatus_t zclGeneral_RegisterCmdCallbacks( uint8 endpoint, zclGeneral_AppCallbacks_t *callbacks ) / Fill in the new profile list pNewItem = osal_mem_alloc( sizeof( zclGenCBRec_t ) ); if ( pNewItem = NULL ) return (ZMemError); pNewItem-next = (zclGenCBRec_t *)NULL; pNewItem-endpoint = endpoint; pNewItem-CBs = callbacks; / Find spot in list if ( zclGenCBs = NULL ) zclGenCBs = pNewItem; else / Look for end of list pLoop = zclGenCBs; while ( pLoop-next != NULL ) pLoop = pLoop-next; / Put new item at end of list pLoop-next = pNewItem; return ( ZSuccess );/这些注册的命令回调函数都是属于一个终端的,一个终端中有多个命令回调函数,那么如何区分到底应该调用哪个回调函数呢?接着往下看: if ( pCBs & pCBs-pfnOnOff ) pCBs-pfnOnOff( pInMmandID );/上面两句进行判断和调用,如果开关簇的命令回调函数存在则进行调用。所以在对回调函数数据结构zclGeneral_AppCallbacks_t进行填充时需要把用到的簇的回调函数填充,没有用到的填为NULL,而且要安全按照定义中簇的顺序来填充。 / no Client command return ( ZSuccess ); break;#endif / ZCL_ON_OFF default: stat = ZFailure; break; return ( stat ); if ( pInPlugin & pInPlugin-pfnIncomingHdlr ) zclInHdlrMsg_t inHdlrMsg; inHdlrMsg.msg = &inMsg; inHdlrMsg.logicalClusterID = logicalClusterID; status = pInPlugin-pfnIncomingHdlr( &inHdlrMsg ); if ( status = ZCL_STATUS_CMD_HAS_RSP ) return; / Were done if ( status != ZSuccess ) / Unsupported message if ( inMsg.hdr.fc.manuSpecific ) status = ZCL_STATUS_UNSUP_MANU_CLUSTER_COMMAND; else status = ZCL_STATUS_UNSUP_CLUSTER_COMMAND; /总结一下:应用层收到数据ZCL事件处理循环zcl_event

温馨提示

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

评论

0/150

提交评论