text: /*
  * The Clear BSD License
  * Copyright 2016-2017 NXP
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted (subject to the limitations in the
  * disclaimer below) provided that the following conditions are met:
  *
  * * Redistributions of source code must retain the above copyright
  *   notice, this list of conditions and the following disclaimer.
  *
  * * Redistributions in binary form must reproduce the above copyright
  *   notice, this list of conditions and the following disclaimer in the
  *   documentation and/or other materials provided with the distribution.
  *
  * * Neither the name of the copyright holder nor the names of its
  *   contributors may be used to endorse or promote products derived from
  *   this software without specific prior written permission.
  *
  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
  
  
  #ifndef HOME_GATEWAY_H
  #define HOME_GATEWAY_H
  
  /*!
  \file       home_gateway.h
  \brief      Header for ZigBee Home Gateway functions
  */
  
  #if defined __cplusplus
  extern "C" {
  #endif
  
  /****************************************************************************/
  /***        Include Files                                                 ***/
  /****************************************************************************/
  #include <jendefs.h>
  #include "zcl.h"
  #include "zcl_options.h"
  #include "Basic.h"
  #include "Identify.h"
  #include "PowerConfiguration.h"
  #include "DeviceTemperatureConfiguration.h"
  #include "Alarms.h"
  
  #include "ApplianceControl.h"
  #include "ApplianceEventsAndAlerts.h"
  #include "ApplianceIdentification.h"
  #include "ApplianceStatistics.h"
  #include "PowerProfile.h"
  
  #ifdef CLD_OTA
  #include "OTA.h"
  #endif
  #include "ZclTime.h"
  #ifdef CLD_POLL_CONTROL
      #include "PollControl.h"
  #endif
  #ifdef CLD_ELECTRICAL_MEASUREMENT
  	#include "ElectricalMeasurement.h"
  #endif
  /****************************************************************************/
  /***        Macro Definitions                                             ***/
  /****************************************************************************/
  #define APPLIANCE_MANAGEMENT_HOME_GATEWAY_DEVICE_ID                     0x0050
  /****************************************************************************/
  /***        Type Definitions                                              ***/
  /****************************************************************************/
  
  /* Holds cluster instances */
  #if defined(__IAR_SYSTEMS_ICC__)
  #pragma pack(push, 4)
  typedef struct 
  {
      /* All HA devices have 2 mandatory clusters - Basic(server) and Identify(server) */
  #if (defined CLD_BASIC) && (defined BASIC_SERVER)
      tsZCL_ClusterInstance sBasicServer;
  #endif
  
  #if (defined CLD_IDENTIFY) && (defined IDENTIFY_SERVER)
      tsZCL_ClusterInstance sIdentifyServer;
  #endif
  
      /* Optional server clusters */
  #if (defined CLD_POWER_CONFIGURATION) && (defined POWER_CONFIGURATION_SERVER)
      tsZCL_ClusterInstance sPowerConfigurationServer;
  #endif
  
  #if (defined CLD_DEVICE_TEMPERATURE_CONFIGURATION) && (defined DEVICE_TEMPERATURE_CONFIGURATION_SERVER)
      tsZCL_ClusterInstance sDeviceTemperatureConfigurationServer;
  #endif
  
  #if (defined CLD_ALARMS) && (defined ALARMS_SERVER)
      tsZCL_ClusterInstance sAlarmsServer;
  #endif
  
  #if (defined CLD_POLL_CONTROL) && (defined POLL_CONTROL_SERVER)
      tsZCL_ClusterInstance sPollControlServer;
  #endif
  
      /* Mandatory E@H clusters */
  #if (defined CLD_APPLIANCE_STATISTICS) && (defined APPLIANCE_STATISTICS_CLIENT)
      tsZCL_ClusterInstance sASCClient;
  #endif
  
  #if (defined CLD_PP) && (defined PP_CLIENT)
      tsZCL_ClusterInstance sPPClient;
  #endif
  
  #if (defined CLD_APPLIANCE_CONTROL) && (defined APPLIANCE_CONTROL_CLIENT)
      tsZCL_ClusterInstance sACCClient;
  #endif
  
  #if (defined CLD_APPLIANCE_IDENTIFICATION) && (defined APPLIANCE_IDENTIFICATION_CLIENT)
      tsZCL_ClusterInstance sAICClient;
  #endif
  
  #if (defined CLD_APPLIANCE_EVENTS_AND_ALERTS) && (defined APPLIANCE_EVENTS_AND_ALERTS_CLIENT)
      tsZCL_ClusterInstance sAEACClient;
  #endif
  
  #ifdef CLD_OTA
      #ifdef OTA_CLIENT
      /* Add  cluster instance for the OTA cluster */
      tsZCL_ClusterInstance sOTAClient;
      #endif 
      #ifdef OTA_SERVER
      /* Add  server instance for the OTA cluster */
      tsZCL_ClusterInstance sOTAServer;    
      #endif
  #endif
  
  #ifdef CLD_TIME
      #ifdef TIME_SERVER
          tsZCL_ClusterInstance sTimeServer;
      #endif
      #ifdef TIME_CLIENT
          tsZCL_ClusterInstance sTimeClient;
      #endif
  #endif
  
      /* Optional client clusters */
  
  #if (defined CLD_POLL_CONTROL) && (defined POLL_CONTROL_CLIENT)
      tsZCL_ClusterInstance sPollControlClient;
  #endif
  
  #if (defined CLD_ELECTRICAL_MEASUREMENT && defined ELECTRICAL_MEASUREMENT_SERVER)
      tsZCL_ClusterInstance sElectricalMeasurementServer;
  #endif
  
  } tsHA_HomeGatewayDeviceClusterInstances;
  #pragma pack(pop)
  #else  
  typedef struct 
  {
      /* All HA devices have 2 mandatory clusters - Basic(server) and Identify(server) */
  #if (defined CLD_BASIC) && (defined BASIC_SERVER)
      tsZCL_ClusterInstance sBasicServer;
  #endif
  
  #if (defined CLD_IDENTIFY) && (defined IDENTIFY_SERVER)
      tsZCL_ClusterInstance sIdentifyServer;
  #endif
  
      /* Optional server clusters */
  #if (defined CLD_POWER_CONFIGURATION) && (defined POWER_CONFIGURATION_SERVER)
      tsZCL_ClusterInstance sPowerConfigurationServer;
  #endif
  
  #if (defined CLD_DEVICE_TEMPERATURE_CONFIGURATION) && (defined DEVICE_TEMPERATURE_CONFIGURATION_SERVER)
      tsZCL_ClusterInstance sDeviceTemperatureConfigurationServer;
  #endif
  
  #if (defined CLD_ALARMS) && (defined ALARMS_SERVER)
      tsZCL_ClusterInstance sAlarmsServer;
  #endif
  
  #if (defined CLD_POLL_CONTROL) && (defined POLL_CONTROL_SERVER)
      tsZCL_ClusterInstance sPollControlServer;
  #endif
  
      /* Mandatory E@H clusters */
  #if (defined CLD_APPLIANCE_STATISTICS) && (defined APPLIANCE_STATISTICS_CLIENT)
      tsZCL_ClusterInstance sASCClient;
  #endif
  
  #if (defined CLD_PP) && (defined PP_CLIENT)
      tsZCL_ClusterInstance sPPClient;
  #endif
  
  #if (defined CLD_APPLIANCE_CONTROL) && (defined APPLIANCE_CONTROL_CLIENT)
      tsZCL_ClusterInstance sACCClient;
  #endif
  
  #if (defined CLD_APPLIANCE_IDENTIFICATION) && (defined APPLIANCE_IDENTIFICATION_CLIENT)
      tsZCL_ClusterInstance sAICClient;
  #endif
  
  #if (defined CLD_APPLIANCE_EVENTS_AND_ALERTS) && (defined APPLIANCE_EVENTS_AND_ALERTS_CLIENT)
      tsZCL_ClusterInstance sAEACClient;
  #endif
  
  #ifdef CLD_OTA
      #ifdef OTA_CLIENT
      /* Add  cluster instance for the OTA cluster */
      tsZCL_ClusterInstance sOTAClient;
      #endif 
      #ifdef OTA_SERVER
      /* Add  server instance for the OTA cluster */
      tsZCL_ClusterInstance sOTAServer;    
      #endif
  #endif
  
  #ifdef CLD_TIME
      #ifdef TIME_SERVER
          tsZCL_ClusterInstance sTimeServer;
      #endif
      #ifdef TIME_CLIENT
          tsZCL_ClusterInstance sTimeClient;
      #endif
  #endif
  
      /* Optional client clusters */
  
  #if (defined CLD_POLL_CONTROL) && (defined POLL_CONTROL_CLIENT)
      tsZCL_ClusterInstance sPollControlClient;
  #endif
  
  #if (defined CLD_ELECTRICAL_MEASUREMENT && defined ELECTRICAL_MEASUREMENT_SERVER)
      tsZCL_ClusterInstance sElectricalMeasurementServer;
  #endif
  
  } tsHA_HomeGatewayDeviceClusterInstances __attribute__ ((aligned(4)));
  #endif
  
  
  /* Holds everything required to create an instance home gateway  */
  typedef struct
  {
      tsZCL_EndPointDefinition sEndPoint;
  
      /* Cluster instances */
      tsHA_HomeGatewayDeviceClusterInstances sClusterInstance;
  
      /* Mandatory server clusters */
  #if (defined CLD_BASIC) && (defined BASIC_SERVER)
      /* Basic Cluster - Server */
      tsCLD_Basic sBasicServerCluster;
  #endif
  
  #if (defined CLD_IDENTIFY) && (defined IDENTIFY_SERVER)
      /* Identify Cluster - Server */
      tsCLD_Identify sIdentifyServerCluster;
      tsCLD_IdentifyCustomDataStructure sIdentifyServerCustomDataStructure;
  #endif
  
      /* Optional server clusters */
  #if (defined CLD_POWER_CONFIGURATION) && (defined POWER_CONFIGURATION_SERVER)
      /* Power Configuration Cluster - Server */
      tsCLD_PowerConfiguration sPowerConfigServerCluster;
  #endif
  
  #if (defined CLD_DEVICE_TEMPERATURE_CONFIGURATION) && (defined DEVICE_TEMPERATURE_CONFIGURATION_SERVER)
      /* Device Temperature Configuration Cluster - Server */
      tsCLD_DeviceTemperatureConfiguration sDeviceTemperatureConfigurationServerCluster;
  #endif
  
  #if (defined CLD_ALARMS) && (defined ALARMS_SERVER)
      /* Alarms Cluster - Server */
      tsCLD_Alarms sAlarmsServerCluster;
      tsCLD_AlarmsCustomDataStructure sAlarmsServerCustomDataStructure;
  #endif
  
  #if (defined CLD_POLL_CONTROL) && (defined POLL_CONTROL_SERVER)
      tsCLD_PollControl sPollControlServerCluster;
      tsCLD_PollControlCustomDataStructure sPollControlServerCustomDataStructure;
  #endif
  
      /* Mandatory client clusters */
  #if (defined CLD_APPLIANCE_STATISTICS) && (defined APPLIANCE_STATISTICS_CLIENT)
      /* Appliance statistics - Client */
      tsCLD_ApplianceStatistics sASCClientCluster;
      tsCLD_ApplianceStatisticsCustomDataStructure sASCClientCustomDataStructure;
  #endif
  
  #if (defined CLD_PP) && (defined PP_CLIENT)
       tsCLD_PP sPPClientCluster;
       tsCLD_PPCustomDataStructure sPPClientCustomDataStructure;
  #endif
  
  #if (defined CLD_APPLIANCE_CONTROL) && (defined APPLIANCE_CONTROL_CLIENT)
      tsCLD_ApplianceControl sACCClientCluster;
      tsCLD_ApplianceControlCustomDataStructure sACCClientCustomDataStructure;
  #endif
  
  #if (defined CLD_TIME) && (defined TIME_SERVER)
      tsCLD_Time sTimeCluster;
  #endif
  
      /* Optional client clusters */
  
  #if (defined CLD_POLL_CONTROL) && (defined POLL_CONTROL_CLIENT)
      tsCLD_PollControl sPollControlClientCluster;
      tsCLD_PollControlCustomDataStructure sPollControlClientCustomDataStructure;
  #endif
  
  #if (defined CLD_APPLIANCE_IDENTIFICATION) && (defined APPLIANCE_IDENTIFICATION_CLIENT)
      tsCLD_ApplianceIdentification sAICClientCluster;
  #endif
  
  #if (defined CLD_APPLIANCE_EVENTS_AND_ALERTS) && (defined APPLIANCE_EVENTS_AND_ALERTS_CLIENT)
      tsCLD_ApplianceEventsAndAlerts sAEACClientCluster;
      tsCLD_ApplianceEventsAndAlertsCustomDataStructure sAEACClientClusterCustomDataStructure;
  #endif
  
  #ifdef CLD_OTA
      /* OTA cluster */
      #ifdef OTA_CLIENT
          tsCLD_AS_Ota sCLD_OTA;
          tsOTA_Common sCLD_OTA_CustomDataStruct;
      #endif
      
      #ifdef OTA_SERVER
          tsCLD_AS_Ota sCLD_ServerOTA;
          tsOTA_Common sCLD_OTA_ServerCustomDataStruct;
      #endif
  #endif
  
  #if (defined CLD_ELECTRICAL_MEASUREMENT && defined ELECTRICAL_MEASUREMENT_SERVER)
          tsCLD_ElectricalMeasurement sCLD_ElectricalMeasurement;
  #endif
  
  #if (defined CLD_TIME) && (defined TIME_CLIENT)
      tsCLD_Time sTimeClientCluster;
  #endif
  
  } tsHA_HomeGatewayDevice;
  
  
  /****************************************************************************/
  /***        Exported Functions                                            ***/
  /****************************************************************************/
  
  PUBLIC teZCL_Status eHA_RegisterHomeGatewayEndPoint(uint8 u8EndPointIdentifier,
                                                tfpZCL_ZCLCallBackFunction cbCallBack,
                                                tsHA_HomeGatewayDevice *psDeviceInfo);
  
  /****************************************************************************/
  /***        External Variables                                            ***/
  /****************************************************************************/
  
  #if defined __cplusplus
  }
  #endif
  
  /****************************************************************************/
  /***        END OF FILE                                                   ***/
  /****************************************************************************/
  
  #endif /* HOME_GATEWAY_H */
  