예제 #1
0
파일: ZDiags.c 프로젝트: Daan1992/WSN-Lab
/****************************************************************************
 * @fn          ZDiagsSaveStatsToNV
 *
 * @brief       Saves the statistics table from RAM to NV.
 *
 * @param       none.
 *
 * @return      System Time.
 */
uint32 ZDiagsSaveStatsToNV( void )
{
  uint32 sysClock = 0;

#if defined ( FEATURE_SYSTEM_STATS )
  // call this function to update the DiagsStatsTable with MAC values,
  // the return value does not need to be saved because the function
  // is updating the value in DiagsStatsTable
  (void)ZDiagsGetStatsAttr( ZDIAGS_MAC_RX_CRC_PASS );
  (void)ZDiagsGetStatsAttr( ZDIAGS_MAC_RX_CRC_FAIL );
  (void)ZDiagsGetStatsAttr( ZDIAGS_MAC_RX_BCAST );
  (void)ZDiagsGetStatsAttr( ZDIAGS_MAC_TX_BCAST );
  (void)ZDiagsGetStatsAttr( ZDIAGS_MAC_RX_UCAST );
  (void)ZDiagsGetStatsAttr( ZDIAGS_MAC_TX_UCAST );
  (void)ZDiagsGetStatsAttr( ZDIAGS_MAC_TX_UCAST_RETRY );
  (void)ZDiagsGetStatsAttr( ZDIAGS_MAC_TX_UCAST_FAIL );

  // System Clock when statistics were saved
  sysClock = DiagsStatsTable.SysClock = osal_GetSystemClock();

  // save the statistics table from RAM to NV
  osal_nv_write( ZCD_NV_DIAGNOSTIC_STATS, 0,
                 sizeof( DiagStatistics_t ), &DiagsStatsTable );
#endif

  // returns the System Time
  return ( sysClock );
}
예제 #2
0
/****************************************************************************
 * @fn          zclDiagnostic_GetStatsAttr
 *
 * @brief       Reads Diagnostic values based on specific ZCL Diagnostics
 *              attribute ID
 *
 * @param       attributeId  input  - ZCL identifier for the required attribute
 * @param       value       output - value of the specific item
 *
 * NOTE:  the user of this function will have to cast the value
 *        based on the type of the attributeId, the returned value
 *        will allways be uint32
 *
 * @return      ZStatus_t
 */
ZStatus_t zclDiagnostic_GetStatsAttr( uint16 attributeId, uint32 *attrValue, uint16 *dataLen )
{
  uint8 status = ZSuccess;
  uint16 ZDiagsAttrId;

  // this atribute is a calculated value
  if ( attributeId == ATTRID_DIAGNOSTIC_AVERAGE_MAC_RETRY_PER_APS_MESSAGE_SENT )
  {
    uint32 macRetriesPerApsTx;
    uint32 apsTxUcastSuccess;
    uint32 apsTxUcastFailure;

    // retrieve each attribute to calculate the requested value
    macRetriesPerApsTx = ZDiagsGetStatsAttr( ZDIAGS_MAC_RETRIES_PER_APS_TX_SUCCESS );

    apsTxUcastSuccess = ZDiagsGetStatsAttr( ZDIAGS_APS_TX_UCAST_SUCCESS );

    apsTxUcastFailure = ZDiagsGetStatsAttr( ZDIAGS_APS_TX_UCAST_FAIL );

    *dataLen = 2;  // this is the lenght of ATTRID_DIAGNOSTIC_AVERAGE_MAC_RETRY_PER_APS_MESSAGE_SENT

    if ( ( apsTxUcastSuccess != 0 ) || ( apsTxUcastFailure != 0 ) )
    {
      // This formula considers the total MAC Failures per APS transmitted packet.
      // If MAC PIB element maxFrameRetries is changed from the default value 3, this formula
      // shall be updated and replace 4 with (MAC PIB maxFrameRetries+1) value
      *attrValue = ( macRetriesPerApsTx + ( apsTxUcastFailure * 4 ) ) / ( apsTxUcastSuccess + apsTxUcastFailure );
    }
    else
    {
      *attrValue = 0;
    }
  }
  // look-up for ZDiags attribute ID, based on the ZCL Diagnostics cluster attribute ID
  else if ( zclDiagnostic_GetAttribData( attributeId, &ZDiagsAttrId, dataLen ) == ZSuccess )
  {
    *attrValue = ZDiagsGetStatsAttr( ZDiagsAttrId );
  }
  else
  {
    status = ZFailure;
  }

  return ( status );
}
예제 #3
0
파일: ZDiags.c 프로젝트: Daan1992/WSN-Lab
/****************************************************************************
 * @fn          ZDiagsGetStatsTable
 *
 * @brief       Reads the statistics and metrics table
 *
 * @return      pointer to ZDiagStatistics_t structure.
 */
DiagStatistics_t *ZDiagsGetStatsTable( void )
{
#if defined ( FEATURE_SYSTEM_STATS )
  // call this function to update the DiagsStatsTable with MAC values,
  // the return value does not need to be saved because the function
  // is updating the value in DiagsStatsTable
  (void)ZDiagsGetStatsAttr( ZDIAGS_MAC_RX_CRC_PASS );
  (void)ZDiagsGetStatsAttr( ZDIAGS_MAC_RX_CRC_FAIL );
  (void)ZDiagsGetStatsAttr( ZDIAGS_MAC_RX_BCAST );
  (void)ZDiagsGetStatsAttr( ZDIAGS_MAC_TX_BCAST );
  (void)ZDiagsGetStatsAttr( ZDIAGS_MAC_RX_UCAST );
  (void)ZDiagsGetStatsAttr( ZDIAGS_MAC_TX_UCAST );
  (void)ZDiagsGetStatsAttr( ZDIAGS_MAC_TX_UCAST_RETRY );
  (void)ZDiagsGetStatsAttr( ZDIAGS_MAC_TX_UCAST_FAIL );

  return ( &DiagsStatsTable );
#else
  return ( NULL );
#endif  // FEATURE_SYSTEM_STATS
}