This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Zstack 3.0.2中,怎么读取空中发来的数据数据内容?ZCL_INCOMING_MSG

 case ZCL_INCOMING_MSG:
          // Incoming ZCL Foundation command/response messages
          zclMyApp_ProcessIncomingMsg( (zclIncomingMsg_t *)MSGpkt );
          break;

static void zclMyApp_ProcessIncomingMsg( zclIncomingMsg_t *pInMsg )
{
  uint8 databuf[50]={0};  //用来接收AF数据的数组
  uint8 Info_temp[80]={0};
 
  osal_memset(databuf,0,50);
  osal_memset(Info_temp,0,80);
 
  osal_memcpy(databuf,pInMsg->cmd.Data,pInMsg->cmd.DataLength);
 
  switch ( pInMsg->zclHdr.commandID )
  {

……

}

}

这个函数中参数为zclIncomingMsg_t *pInMsg,没有数据内容,是要用某个解析语句么?刚从旧协议栈转过来,有点不适应

  • 可以參考SampleLight程內zclSampleLight_ProcessIncomingMsg的作法

  • 协调器已经可以建立网络了,但是终端下载程序后,却没有现象。
    初始化程序如下:是终端没有加入网络,还是协调器禁止入网了?zstack 3.0 如何让协调器一直可以入网。
    void zclMyApp_Init( byte task_id )
    {
    static uint8 addr_temp[2]={0xFF,0xFE};

    zclMyApp_TaskID = task_id;

    // This app is part of the Home Automation Profile //注册使能家居描述符
    bdb_RegisterSimpleDescriptor( &zclMyApp_SimpleDesc ); //注册简单描述符

    // Register the ZCL General Cluster Library callback functions
    zclGeneral_RegisterCmdCallbacks( MYAPP_ENDPOINT, &zclMyApp_CmdCallbacks );

    // MYAPP_TODO: Register other cluster command callbacks here

    // Register the application's attribute list
    zcl_registerAttrList( MYAPP_ENDPOINT, zclMyApp_NumAttributes, zclMyApp_Attrs );

    // Register the Application to receive the unprocessed Foundation command/response messages
    zcl_registerForMsg( zclMyApp_TaskID );

    #ifdef ZCL_DISCOVER
    // Register the application's command list
    zcl_registerCmdList( MYAPP_ENDPOINT, zclCmdsArraySize, zclMyApp_Cmds );
    #endif

    // Register low voltage NV memory protection application callback
    RegisterVoltageWarningCB( zclSampleApp_BatteryWarningCB );

    // Register for all key events - This app will handle all key events
    RegisterForKeys( zclMyApp_TaskID );

    bdb_RegisterCommissioningStatusCB( zclMyApp_ProcessCommissioningStatus );
    bdb_RegisterIdentifyTimeChangeCB( zclMyApp_ProcessIdentifyTimeChange );
    bdb_RegisterBindNotificationCB( zclMyApp_BindNotification );

    //=============================add by user=================================
    //串口初始化,并打印信息
    MyApp_UartInit();
    HalUARTWrite(0,"---USRT_DTU_TEST---\r\n",strlen("---USRT_DTU_TEST---\r\n"));
    //建立、加入网络
    bdb_StartCommissioning(BDB_COMMISSIONING_MODE_NWK_FORMATION | BDB_COMMISSIONING_MODE_NWK_STEERING | BDB_COMMISSIONING_MODE_FINDING_BINDING | BDB_COMMISSIONING_MODE_INITIATOR_TL);

    ChangePA(20);
    }
  • 串口打印都不显示HalUARTWrite(0,"---USRT_DTU_TEST---\r\n",strlen("---USRT_DTU_TEST---\r\n"));
  • zstack 3.0 無法让协调器一直允許入网、最多只能開放254秒、有沒有抓包看看設備為什麼無法入网
  • 怎么跟更改协议栈,可以实现?
  • 解决了,现在又有一个问题:终端发送给协调器的无线数据。提示终端发送成功,但是协调却没有按预期的显示。
    经查看有一个CONST zclAttrRec_t zclSampleTemperatureSensor_Attrs[] =;
    我没有做任何更改,是需要把自定的MYAPP_SENDADDR_CLUSTERID放在这个里面进行初始化么?
  • 不大懂你的問題、你可以貼出你终端发送给协调器数据的代碼?
  • 终端中定义:
    const cId_t zclMyApp_InClusterList[] =
    {
    ZCL_CLUSTER_ID_GEN_BASIC,
    ZCL_CLUSTER_ID_GEN_IDENTIFY,


    // MYAPP_TODO: Add MyApp specific Input Clusters Here.
    // See zcl.h for Cluster ID definitions

    };
    协调器中定义:
    const cId_t zclMyApp_OutClusterList[] =
    {
    ZCL_CLUSTER_ID_GEN_BASIC,
    MYAPP_CLUSTERID_SENDADDR,
    // MYAPP_TODO: Add MyApp specific Output Clusters Here.
    // See zcl.h for Cluster ID definitions
    };
    --------------------------------------------------------------------------------------------------------------------------------------------------

    终端发送的代码:
    void MyApp_SendShortaddrToCoor(uint8 DeviceType)
    {
    //设置发送目的地址
    MyApp_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;
    MyApp_DstAddr.addr.shortAddr = 0x0000;
    MyApp_DstAddr.endPoint = MYAPP_ENDPOINT;
    //HalUARTWrite(0,buf,7);
    //发送出去
    if(AF_DataRequest(&MyApp_DstAddr, //目的地址
    &MyApp_epDesc, //设备描述符
    MYAPP_CLUSTERID_SENDADDR, //簇ID
    14, //长度
    buf, //要发送的数组
    &MyApp_TransID, //传输序列号
    AF_ACK_REQUEST, //发送选项
    AF_DEFAULT_RADIUS)==afStatus_SUCCESS)
    {
    //成功;
    HalUARTWrite(0,"MyApp_SendShortaddrToCoor Success\r\n",strlen("MyApp_SendShortaddrToCoor Success\r\n"));
    }
    else
    {
    //如果不成功,就再发送一次
    HalUARTWrite(0,"MyApp_SendShortaddrToCoor Error\r\n",strlen("MyApp_SendShortaddrToCoor Error\r\n"));
    }
    }
    协调器接收代码:
    static void zclMyApp_ProcessIncomingMsg( zclIncomingMsg_t *pInMsg )
    {
    uint8 databuf[50]={0}; //用来接收AF数据的数组

    osal_memset(databuf,0,50);

    osal_memcpy(databuf,((afIncomingMSGPacket_t *)pInMsg)->cmd.Data,((afIncomingMSGPacket_t *)pInMsg)->cmd.DataLength);
    switch ( pInMsg->zclHdr.commandID )
    {
    ……

    case MYAPP_CLUSTERID_SENDADDR:
    HalUARTWrite(0,"MYAPP_CLUSTERID_SENDADDR\r\n",strlen("MYAPP_CLUSTERID_SENDADDR\r\n")); //接收到打印
    break;

    default:
    break;
    }

    if ( pInMsg->attrCmd )
    osal_mem_free( pInMsg->attrCmd );
    }

    协调器接收数据应该会打印,结果根本没有打印
  • 协议栈中这个是做什么用的?我对这个没有做任何更改:
    /*********************************************************************
    * ATTRIBUTE DEFINITIONS - Uses REAL cluster IDs
    */
    CONST zclAttrRec_t zclMyApp_Attrs[] =
    {
    // *** General Basic Cluster Attributes ***
    {
    ZCL_CLUSTER_ID_GEN_BASIC, // Cluster IDs - defined in the foundation (ie. zcl.h)
    { // Attribute record
    ATTRID_BASIC_HW_VERSION, // Attribute ID - Found in Cluster Library header (ie. zcl_general.h)
    ZCL_DATATYPE_UINT8, // Data Type - found in zcl.h
    ACCESS_CONTROL_READ, // Variable access control - found in zcl.h
    (void *)&zclMyApp_HWRevision // Pointer to attribute variable
    }
    },
    {
    ZCL_CLUSTER_ID_GEN_BASIC,
    { // Attribute record
    ATTRID_BASIC_ZCL_VERSION,
    ZCL_DATATYPE_UINT8,
    ACCESS_CONTROL_READ,
    (void *)&zclMyApp_ZCLVersion
    }
    },
    ……
    };
  • 你发送的不是ZCL命令,你转化后肯定是无法识别的,

    你需要在:

    case AF_INCOMING_MSG_CMD:
    GenericApp_MessageMSGCB( MSGpkt );

    static void GenericApp_MessageMSGCB( afIncomingMSGPacket_t *pkt )
    {
    switch ( pkt->clusterId )
    {

    }
    }

  • 我想问一下,
    1、这两个有什么区别,我看例程里面温度传感器采集,用的就是 case ZCL_INCOMING_MSG:(即ZCL命令)。
    2、我自己定义的光照传感器数据采集传输,可以使用zcl命令么?
  • 光照传感器数据可以使用標準的zcl命令,cluster ID是ZCL_CLUSTER_ID_MS_ILLUMINANCE_MEASUREMENT,attribute是ATTRID_MS_ILLUMINANCE_MEASURED_VALUE,細節請參考ZCL spec
  • 还用一个是自定义的数据,想让终端设备上电自动传输一次自身地址到协调器。
    按照推荐更改后,还是不行,这是我的端口描述符和简单描述符
    volatile static endPointDesc_t MyApp_epDesc = //端口描述符
    {
    MYAPP_ENDPOINT, // endpoint 8
    0,
    &zclMyApp_TaskID,
    (SimpleDescriptionFormat_t *)&zclMyApp_SimpleDesc, // No Simple description for this test endpoint
    (afNetworkLatencyReq_t)0 // No Network Latency req
    };
    SimpleDescriptionFormat_t zclMyApp_SimpleDesc =
    {
    MYAPP_ENDPOINT, // int Endpoint; 8
    ZCL_HA_PROFILE_ID, // uint16 AppProfId;
    // MYAPP_TODO: Replace ZCL_HA_DEVICEID_ON_OFF_LIGHT with MyApp specific device ID
    ZCL_HA_DEVICEID_ON_OFF_LIGHT, // uint16 AppDeviceId;
    MYAPP_DEVICE_VERSION, // int AppDevVer:4;
    MYAPP_FLAGS, // int AppFlags:4;
    ZCLMYAPP_MAX_INCLUSTERS, // byte AppNumInClusters;
    (cId_t *)zclMyApp_InClusterList, // byte *pAppInClusterList;
    ZCLMYAPP_MAX_OUTCLUSTERS, // byte AppNumInClusters;
    (cId_t *)zclMyApp_OutClusterList // byte *pAppInClusterList;
    };
    协调器输入zclMyApp_InClusterList
    const cId_t zclMyApp_InClusterList[] =
    {
    ZCL_CLUSTER_ID_GEN_BASIC,
    ZCL_CLUSTER_ID_GEN_IDENTIFY,


    // MYAPP_TODO: Add MyApp specific Input Clusters Here.
    // See zcl.h for Cluster ID definitions
    MYAPP_CLUSTERID_SENDADDR,

    };
    终端输出zclMyApp_OutClusterList
    const cId_t zclMyApp_OutClusterList[] =
    {
    ZCL_CLUSTER_ID_GEN_BASIC,
    MYAPP_CLUSTERID_SENDADDR,
    // MYAPP_TODO: Add MyApp specific Output Clusters Here.
    // See zcl.h for Cluster ID definitions
    };
  • 建議你參考一下SampleThermoStat/SampleTemperatureSensor例程是怎樣透過ZCL_CLUSTER_ID_MS_TEMPERATURE_MEASUREMENT接收發送溫度的,你要作的只是修改成cluster ID是ZCL_CLUSTER_ID_MS_ILLUMINANCE_MEASUREMENT,attribute是ATTRID_MS_ILLUMINANCE_MEASURED_VALUE
  • 我想添加自定义一个端口,用来传输数据。
    定义如下:
    const cId_t MyApp_ClusterList[MYAPP_MAX_CLUSTERS] =
    {
    MYAPP_SENDADDR_CLUSTERID,
    };
    const SimpleDescriptionFormat_t MyApp_SimpleDesc =
    {
    MYAPP_ENDPOINT_ADDR, // int Endpoint;
    ZCL_HA_PROFILE_ID, // uint16 AppProfId[2]; ZCL_HA_PROFILE_ID
    MYAPP_DEVICEID, // uint16 AppDeviceId[2];
    MYAPP_DEVICE_VERSION, // int AppDevVer:4;
    MYAPP_FLAGS, // int AppFlags:4;
    MYAPP_MAX_CLUSTERS, // byte AppNumInClusters;
    (cId_t *)MyApp_ClusterList, // byte *pAppInClusterList;
    MYAPP_MAX_CLUSTERS, // byte AppNumInClusters;
    (cId_t *)MyApp_ClusterList // byte *pAppInClusterList;
    };
    static endPointDesc_t MyApp_epDesc = //端口描述符
    {
    MYAPP_ENDPOINT_ADDR, // endpoint
    0,
    &zclMyApp_TaskID,
    (SimpleDescriptionFormat_t *)&MyApp_SimpleDesc, // No Simple description for this test endpoint
    (afNetworkLatencyReq_t)0 // No Network Latency req
    };
    在初始化函数中注册:
    afRegister( &MyApp_epDesc );//注册自定义的端口号描述符

    结果发现不注册时,设备上电会产生一次ZDO_STATE_CHANGE状态改变事件。
    注册后,设备上电会产生两次连续的ZDO_STATE_CHANGE状态改变事件。

    请问这是怎么回事?端口号MYAPP_ENDPOINT_ADDR为0x30
  • 端口号的 MyApp_epDesc.epType =应该怎么赋值?
  • afIncomingMSGPacket_t结构中只有clusterId,没有attributeId,如何区分attribute?

  • 可以根據ZCL spec去解構区分attribute
  • 谢谢回复,能否做详细说明?
    typedef struct
    {
    OsalPort_EventHdr hdr; /* OSAL Message header */
    uint16_t groupId; /* Message's group ID - 0 if not set */
    uint16_t clusterId; /* Message's cluster ID */
    afAddrType_t srcAddr; /* Source Address, if endpoint is STUBAPS_INTER_PAN_EP,
    it's an InterPAN message */
    uint16_t macDestAddr; /* MAC header destination short address */
    uint8_t endPoint; /* destination endpoint */
    uint8_t wasBroadcast; /* TRUE if network destination was a broadcast address */
    uint8_t LinkQuality; /* The link quality of the received data frame */
    uint8_t correlation; /* The raw correlation value of the received data frame */
    int8_t rssi; /* The received RF power in units dBm */
    uint8_t SecurityUse; /* deprecated */
    uint32_t timestamp; /* receipt timestamp from MAC */
    uint8_t nwkSeqNum; /* network header frame sequence number */
    afMSGCommandFormat_t cmd; /* Application Data */
    uint16_t macSrcAddr; /* MAC header source short address */
    uint8_t radius;
    } afIncomingMSGPacket_t;
  • 就是照ZCL spec去解構afMSGCommandFormat_t cmd; /* Application Data */