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.

how does a ZED knows someone write the attribute of his cluster

Hi !

I have a question about the ZCL_SendWrite()process。

when a device(A) was finish binding with other one device(B),  sometimes B need to send a write CMD  to change some attribute of A,(the attribute was define as Read/Write)。

when the B process the ZCL_SendWrite()  function by action a keypress,  how could we (or  A) catch the moment of  being writed by B ?

I have try to set a debug point in the case of  ZCL_CMD_WRITE  on ( MSGpkt->hdr.event ==ZCL_INCOMING_MSG)  at  A side .

I always set a Uart debug printf out the value of attribute  by key press。

when press the key in B side, there is nothing happen in A side (i mean the code was running without stop at the debug point ),i wait a long time,then i press the key in A side, printf out the value of attribute ,it was already changed!!!

so I curious about why does A could not catch the moment that his attribute was changed by other device?

is that possible to catch this moment ??? 

  • Hi,

    In order for the application to be notified about attribute read/write access, please use zcl_registerReadWriteCB() to register the respective callbacks, and also make sure when defining the attribute to have dataPtr set to NULL instead of pointing to the actual attribute's memory location. Your registered callback will be called whenever the attribute needs to be written. Note that the attribute will not be modified automatically in this case. It is up to your callback to do modify the attribute's value in memory.

    Best regards,
    OD
  • Hi OD
    should i just register the function in the APP.c ,and then i will catch the moment (in ZCL_INCOMING_MSG)when someone other write my attribute of located devices ?

    but do you find that the function note as below :


    * Note: The pfnReadWriteCB callback function is only required
    * when the attribute data format is unknown to ZCL. The
    * callback function gets called when the pointer 'dataPtr'
    * to the attribute value is NULL in the attribute database
    * registered with the ZCL.

    but when the attribute was konwn to ZCL, just like the ATTRID_SS_IAS_CIE_ADDRESS, is it work ?
  • hi OD:

             i registered the  zcl_registerReadWriteCB() in app initial function as below:

      // Register the ZCL General Cluster Library callback functions
      zcl_registerReadWriteCB( WarningDevice_ENDPOINT, &zclGetWriteCB,NULL);

    then  i process the zclgetwriteCB as below, but i always have not catch the write moment:

    static ZStatus_t zclGetWriteCB(uint16 clusterId, uint16 attrId, uint8 oper,uint8 *pValue, uint16 *pLen)
    {
      if(zclWarningDevice_ZoneState != SS_IAS_ZONE_STATE_ENROLLED )
      {
    #ifdef UartShow
             HalUARTWrite(0,"OOOOOO\n", sizeof("OOOOOO\n"));
    #endif
      return (ZCL_STATUS_SUCCESS);
      } 
      else
      { 
    #ifdef UartShow
             HalUARTWrite(0,"***\n", sizeof("***\n"));
    #endif
        return (ZCL_STATUS_FAILURE);
      }
    }

  • hi OD:

            i have register the zcl_registerReadWriteCB() as below :

              zcl_registerReadWriteCB( WarningDevice_ENDPOINT, &zclGetWriteCB,NULL);

           but  when i debug  , the code  running to status = ZCL_STATUS_SOFTWARE_FAILURE ,it seem that pfnReadWriteCB  have  not value。

    static ZStatus_t zclWriteAttrDataUsingCB( uint8 endpoint, afAddrType_t *srcAddr,
                                              zclAttrRec_t *pAttr, uint8 *pAttrData )
    {
      uint8 status;

      if ( zcl_AccessCtrlWrite( pAttr->attr.accessControl ) )
      {
        status = zclAuthorizeWrite( endpoint, srcAddr, pAttr );
        if ( status == ZCL_STATUS_SUCCESS )
        {
          zclReadWriteCB_t pfnReadWriteCB = zclGetReadWriteCB( endpoint );
          if ( pfnReadWriteCB != NULL )
          {
            // Write the attribute value
            status = (*pfnReadWriteCB)( pAttr->clusterID, pAttr->attr.attrId,
                                        ZCL_OPER_WRITE, pAttrData, NULL );
          }
          else
          {
            status = ZCL_STATUS_SOFTWARE_FAILURE;
          }
        }
      }
      else
      {
        status = ZCL_STATUS_READ_ONLY;
      }

      return ( status );
    }

  • hi OD
    what is the authorizeCB_t function?

    // Callback function prototype to authorize a Read or Write operation
    // on a given attribute.
    //
    // srcAddr - source Address
    // pAttr - pointer to attribute
    // oper - ZCL_OPER_READ, or ZCL_OPER_WRITE
    //
    // return ZCL_STATUS_SUCCESS: Operation authorized
    // ZCL_STATUS_NOT_AUTHORIZED: Operation not authorized
    typedef ZStatus_t (*zclAuthorizeCB_t)( afAddrType_t *srcAddr, zclAttrRec_t *pAttr, uint8 oper );
  • Hi OD:

               how could i process the ZCL_SendRead moment? is that right coding as below:

      static ZStatus_t zcl_GetReadWriteCB(uint16 clusterId, uint16 attrId, uint8 oper,uint8 *pValue, uint16 *pLen)
    {
      uint8 status; 

       case ZCL_OPER_READ:
              *pLen = Z_EXTADDR_LEN;
                osal_memcpy(pValue,zclWarningDevice_IAS_CIE_Address,Z_EXTADDR_LEN);
                status = ZCL_STATUS_SUCCESS;
        break;

        case ZCL_OPER_LEN:
              *pLen = Z_EXTADDR_LEN;
              status = ZCL_STATUS_SUCCESS;
          break;

                }

    but i found that no matter how to process, it will return  ( ZCL_STATUS_SOFTWARE_FAILURE ); in zcl.c , what is the purpose of  setting ZCL_STATUS_SOFTWARE_FAILURE

    static ZStatus_t zclReadAttrDataUsingCB( uint8 endpoint, uint16 clusterId, uint16 attrId,
                                             uint8 *pAttrData, uint16 *pDataLen )
    {
      zclReadWriteCB_t pfnReadWriteCB = zclGetReadWriteCB( endpoint );

      if ( pDataLen != NULL )
      {
        *pDataLen = 0; // Always initialize it to 0
      }

      if ( pfnReadWriteCB != NULL )
      {
        // Read the attribute value and its length
        return ( (*pfnReadWriteCB)( clusterId, attrId, ZCL_OPER_READ, pAttrData, pDataLen ) );
      }
     
      return ( ZCL_STATUS_SOFTWARE_FAILURE );
    }