美文网首页物联网应用开发
zigbee Zstack 开发主要步骤

zigbee Zstack 开发主要步骤

作者: Cedric_h | 来源:发表于2019-07-23 06:57 被阅读0次

    原文:https://blog.csdn.net/uyy203/article/details/51175759

    信道选择

    打开f8wconfig.cfg

    选择信道

    -DDEFAULT_CHANLIST=0x02000000;

    网络号设定:

    打开f8wconfig.cfg

    -DZDAPP_CONFIG_PAN_ID=0x32

    设备描述设定:

    打开GenericApp.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            1
    

    协调器:

    1.复制TI环境下GenericApp 工程文件,更名为xyzApp

    2.以GenericApp.c、以GenericApp.h 为蓝本,复制出 Coordinator.c、Coordinator.h、Enddevice.c、Enddevice.h 的协调器、终端文件主和头文件

    3.对Coordinator.c进行修改GenericApp.h 为Coordinator.h

    4.修改设备描述符

    const SimpleDescriptionFormat_tGenericApp_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;
    
      0,          // byte  AppNumInClusters;
    
      (cId_t*)NULL   //  byte *pAppInClusterList;
    
    };
    
    

    5.voidGenericApp_MessageMSGCB( afIncomingMSGPacket_t *pkt )

    case GENERICAPP_CLUSTERID:

    下加入

       osal_memcpy(buffer,pkt->cmd.Data,pkt->cmd.DataLength);
    
         if(osal_memcmp(buffer,"LED32",5))
    
          {
    
           HalLedBlink(HAL_LED_2,0,50,500);
    
          }
    
          else
    
          {
    
           HalLedSet(HAL_LED_2,HAL_LED_MODE_ON);
    
          }
    

    判断接收到的字符是不是LED32,是则让LED2闪烁,不是则让LED2常亮

    终端:

    1.将Enddevice.c中的

    include”GenericApp.h”改成 “Enddevice.h“

    1. 在 中UINT16GenericApp_ProcessEvent( byte task_id, UINT16 events )的

    case ZDO_STATE_CHANGE:下加入

            GenericApp_NwkState = (devStates_t)(MSGpkt->hdr.status);
    
              if(GenericApp_NwkState == DEV_END_DEVICE)
    
              {
    
                 GenericApp_SendTheMessage(  );
    
              }
    
             break;
    

    3.在void GenericApp_SendTheMessage( void )中加入

    char theMessageData[] = "LED32";
    
      afAddrType_tmy_DstAddr;
    
     my_DstAddr.addrMode=(afAddrMode_t)Addr16Bit; //单播
    
     my_DstAddr.endPoint=GENERICAPP_ENDPOINT;//初始化端口号
    
     my_DstAddr.addr.shortAddr=0x0;//接收方短地址
    
      if (AF_DataRequest( &my_DstAddr, &GenericApp_epDesc,
    
                           GENERICAPP_CLUSTERID,
    
                           (byte)osal_strlen(theMessageData ) + 1,
    
                           (byte*)&theMessageData,
    
                           &GenericApp_TransID,
    
                           AF_DISCV_ROUTE,AF_DEFAULT_RADIUS ) == afStatus_SUCCESS )
    
      {
    
        //Successfully requested to be sent.
    
        HalLedBlink(HAL_LED_2,0,50,500);
    
    }
    

    4.烧写

    相关文章

      网友评论

        本文标题:zigbee Zstack 开发主要步骤

        本文链接:https://www.haomeiwen.com/subject/cmjnlctx.html