コード例 #1
0
ファイル: ZGlobals.c プロジェクト: Lieubk/SmartLife
/*********************************************************************
 * @fn          zgInit
 *
 * @brief
 *
 *   Initialize the Z-Stack Globals. If an item doesn't exist in
 *   NV memory, write the system default into NV memory. But if
 *   it exists, set the item to the value stored in NV memory.
 *
 * NOTE: The Startup Options (ZCD_NV_STARTUP_OPTION) indicate
 *       that the Config state items (zgItemTable) need to be
 *       set to defaults (ZCD_STARTOPT_DEFAULT_CONFIG_STATE). The
 *
 * @param       none
 *
 * @return      ZSUCCESS if successful, NV_ITEM_UNINIT if item did not
 *              exist in NV, NV_OPER_FAILED if failure.
 */
uint8 zgInit( void )
{
  uint8  setDefault = FALSE;

  // Do we want to default the Config state values
  if ( zgReadStartupOptions() & ZCD_STARTOPT_DEFAULT_CONFIG_STATE )
  {
    setDefault = TRUE;
  }

#if defined ( FEATURE_SYSTEM_STATS )
  // This sections tracks the number of resets
  uint16 bootCnt = 0;

  // Update the Boot Counter
  if ( osal_nv_item_init( ZCD_NV_BOOTCOUNTER, sizeof(bootCnt), &bootCnt ) == ZSUCCESS )
  {
    // Get the old value from NV memory
    osal_nv_read( ZCD_NV_BOOTCOUNTER, 0, sizeof(bootCnt), &bootCnt );
  }

  // Increment the Boot Counter and store it into NV memory
  if ( setDefault )
  {
    bootCnt = 0;
  }
  else
  {
    bootCnt++;
  }

  osal_nv_write( ZCD_NV_BOOTCOUNTER, 0, sizeof(bootCnt), &bootCnt );
#endif  // FEATURE_SYSTEM_STATS

  // Initialize the Extended PAN ID as my own extended address
  ZMacGetReq( ZMacExtAddr, zgExtendedPANID );

  // Initialize the items table
  zgInitItems( setDefault );

#ifndef NONWK
  if ( ZG_SECURE_ENABLED )
  {
    // Initialize the Pre-Configured Key to the default key
    zgPreconfigKeyInit( setDefault );

    // Initialize NV items for all Keys: NWK, APS, TCLK and Master
    ZDSecMgrInitNVKeyTables( setDefault );
  }
#endif // NONWK

  // Clear the Config State default
  if ( setDefault )
  {
    zgWriteStartupOptions( ZG_STARTUP_CLEAR, ZCD_STARTOPT_DEFAULT_CONFIG_STATE );
  }

  return ( ZSUCCESS );
}
コード例 #2
0
ファイル: modbus.c プロジェクト: TemcoLijun/Zigbee_Modules
/******************************************************************************
 * @fn      modbus_multi_write
 */
void modbus_multi_write( uint8 *data_buffer, uint8 len)
{
  uint8 address;
  
  address = BUILD_UINT16( data_buffer[3], data_buffer[2]);
  
  if( address == MODBUS_SECURITY_KEY_START)
  {
    if(data_buffer[6]>=32)
    {
      for(uint8 i=0; i<16; i++)
      {
      //  osal_memcpy(defaultKey, data_buffer[7+i*2], 1);
        defaultKey[i] = data_buffer[7+i*2];
        zgPreconfigKeyInit( TRUE );

        // Initialize NV items for all Keys: NWK, APS, TCLK and Master
        ZDSecMgrInitNVKeyTables( TRUE );
      }
    }
  }
}