<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                >[success] 導師視頻講解:[**去聽課**](https://www.bilibili.com/video/BV1k34y1D7Vz?p=36) >[success] **技術支持說明:** >**1**.一般以自主學習為主 > **2**.可到官方問答社區中提問:[**去提問**](https://bbs.csdn.net/forums/zigbee) > **3**.工程師**會盡快**解答社區問題,但他們是一線開發,【**難以保證**】解答時效,解答辛苦,感謝理解! <br/> 前述章節講解了如何使用AF層通信API,但是現在用得更多的是基于ZCL的數據通信方式。ZCL的全稱是ZigBee Cluster Library,中文意思是ZigBee集群庫。ZCL與AF的關系如圖所示: ![](https://img.kancloud.cn/b5/2c/b52ca643c0af792c291c855b9dafaabf_434x526.png =200x) ## 圖中共有3個層次,分別是AF、ZCL和應用層,分別詳細講解一下。 <br/> ## **AF層** 在前述章節已經詳細講解了AF層,可以調用AF層的數據通信API實現ZigBee設備之間的數據發送與接收。然而,直接使用AF層通信API的最大問題是不同公司開發的設備難以做到互聯互通。 <br/> ## **應用層** 開發者此層次中專注于開發設備的各個功能。在講解AF通信的章節中,我們就是在應用層中直接調用AF層的通信API來發送和接收數據的。 <br/> ## **ZCL層簡介** ZigBee聯盟在AF層與應用層之間構建了ZCL層,其最大的作用就是實現了各個ZigBee設備的互聯互通。ZCL定義了ZigBee設備的各種應用領域(Profile)、設備類型(Device)、集群(Cluster)、設備屬性和命令,這些定義均由ZigBee聯盟統一定制。各個廠商在開發ZigBee設備時都遵循這些定義,便實現了互聯互通了。 <br/> ## **ZCL層的架構** ZCL的大部分內容在Z-Stack 3.0 中的以下目錄中: ``` ...\\Z-Stack 3.0.1\\Components\\stack\\zcl ``` 它的部分內容如圖所示。 ![](https://img.kancloud.cn/3e/3a/3e3a892e04f37a3d02933d150faf45e0_897x804.png =500x) ### 一個設備一般只會使用ZCL中的部分內容,例如本書一直講解的這個SampleSwitch工程使用了這些內容,如圖所示。 ![](https://img.kancloud.cn/9b/6c/9b6c17f576895e15efc8c73df30068fd_312x626.png =250x) <br/> **代碼分析** 我們對ZCL中的代碼簡單分析一下,打開zcl.h文件,可以找到ZCL層數據發送函數zcl\_SendCommand(),代碼如下: ``` /********************************************************************* * @fn zcl_SendCommand * * @brief Used to send Profile and Cluster Specific Command messages. * * NOTE: The calling application is responsible for incrementing * the Sequence Number. * * @param srcEp - source endpoint * @param destAddr - destination address * @param clusterID - cluster ID * @param cmd - command ID * @param specific - whether the command is Cluster Specific * @param direction - client/server direction of the command * @param disableDefaultRsp - disable Default Response command * @param manuCode - manufacturer code for proprietary extensions to a profile * @param seqNumber - identification number for the transaction * @param cmdFormatLen - length of the command to be sent * @param cmdFormat - command to be sent * * @return ZSuccess if OK */ ZStatus_t zcl_SendCommand( uint8 srcEP, afAddrType_t *destAddr, uint16 clusterID, uint8 cmd, uint8 specific, uint8 direction, uint8 disableDefaultRsp, uint16 manuCode, uint8 seqNum, uint16 cmdFormatLen, uint8 *cmdFormat ) { endPointDesc_t *epDesc; zclFrameHdr_t hdr; uint8 *msgBuf; uint16 msgLen; uint8 *pBuf; uint8 options; ZStatus_t status; epDesc = afFindEndPointDesc( srcEP ); if ( epDesc == NULL ) { return ( ZInvalidParameter ); // EMBEDDED RETURN } #if defined ( INTER_PAN ) if ( StubAPS_InterPan( destAddr->panId, destAddr->endPoint ) ) { options = AF_TX_OPTIONS_NONE; } else #endif { options = zclGetClusterOption( srcEP, clusterID ); // The cluster might not have been defined to use security but if this message // is in response to another message that was using APS security this message // will be sent with APS security if ( !( options & AF_EN_SECURITY ) ) { afIncomingMSGPacket_t *origPkt = zcl_getRawAFMsg(); if ( ( origPkt != NULL ) && ( origPkt->SecurityUse == TRUE ) ) { options |= AF_EN_SECURITY; } } } zcl_memset( &hdr, 0, sizeof( zclFrameHdr_t ) ); // Not Profile wide command (like READ, WRITE) if ( specific ) { hdr.fc.type = ZCL_FRAME_TYPE_SPECIFIC_CMD; } else { hdr.fc.type = ZCL_FRAME_TYPE_PROFILE_CMD; } if ( ( epDesc->simpleDesc == NULL ) || ( zcl_DeviceOperational( srcEP, clusterID, hdr.fc.type, cmd, epDesc->simpleDesc->AppProfId ) == FALSE ) ) { return ( ZFailure ); // EMBEDDED RETURN } // Fill in the Maufacturer Code if ( manuCode != 0 ) { hdr.fc.manuSpecific = 1; hdr.manuCode = manuCode; } // Set the Command Direction if ( direction ) { hdr.fc.direction = ZCL_FRAME_SERVER_CLIENT_DIR; } else { hdr.fc.direction = ZCL_FRAME_CLIENT_SERVER_DIR; } // Set the Disable Default Response field if ( disableDefaultRsp ) { hdr.fc.disableDefaultRsp = 1; } else { hdr.fc.disableDefaultRsp = 0; } // Fill in the Transaction Sequence Number hdr.transSeqNum = seqNum; // Fill in the command hdr.commandID = cmd; // calculate the needed buffer size msgLen = zclCalcHdrSize( &hdr ); msgLen += cmdFormatLen; // Allocate the buffer needed msgBuf = zcl_mem_alloc( msgLen ); if ( msgBuf != NULL ) { // Fill in the ZCL Header pBuf = zclBuildHdr( &hdr, msgBuf ); // Fill in the command frame zcl_memcpy( pBuf, cmdFormat, cmdFormatLen ); status = AF_DataRequest( destAddr, epDesc, clusterID, msgLen, msgBuf, &zcl_TransID, options, AF_DEFAULT_RADIUS ); zcl_mem_free ( msgBuf ); } else { status = ZMemError; } return ( status ); } ``` 可以看到zcl\_SendCommand()函數中,其實是調用AF層的數據發送函數AF_DataRequest()來發送數據的。 ### 在zcl.c文件中還有一個名為zcl\_event\_loop()的函數。在這個函數中,我們可以看到AF層數據的接收和處理,代碼如圖所示。 ![](https://img.kancloud.cn/5b/f8/5bf8562956a76e53b2a77d016afdbb2e_1680x1007.png =500x) ### 以上的分析也印正了ZCL層的底層就是AF層。 <br/> <br/> ## **項目定制** * 如需項目定制開發,可掃碼添加項目經理好友(注明“**項目定制**”) * 定制范圍:**NB-IoT**、**CATn(4G)**、**WiFi**、**ZigBee**、**BLE Mesh**以及**STM32**、**嵌入式Linux**等IoT技術方案 * 善學坊官網:[www.sxf-iot.com](https://www.sxf-iot.com/) ![](https://img.kancloud.cn/ca/73/ca739f92cab220a3059378642e3bd502_430x430.png =200x) * 非項目定制**勿擾**,此處**非**技術支持
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看