/*
 * app_thermostat_msp_commands.c
 *
 *  Created on: 15.05.2017
 *      Author: j.huebner
 */

/****************************************************************************/
/***        Include files                                                 ***/
/****************************************************************************/
#include "app_thermostat_msp_commands.h"
#include "dbg_uart.h"
#include "zcl_options.h"
#include "Thermostat.h"
/****************************************************************************/
/***        Macro Definitions                                             ***/
/****************************************************************************/
#define THERMOSTAT_HOLIDAY_BUFFER_SIZE 9
/****************************************************************************/
/***        Type Definitions                                              ***/
/****************************************************************************/
/****************************************************************************/
/***        Local Function Prototypes                                     ***/
/****************************************************************************/
/****************************************************************************/
/***        Exported Variables                                            ***/
/****************************************************************************/
PUBLIC uint8 u8decodedSwitchpointsArray[113];
/****************************************************************************/
/***        Local Variables                                               ***/
/****************************************************************************/
/****************************************************************************/
/***        Exported Functions                                            ***/
/****************************************************************************/
#ifdef THERMOSTAT_CLIENT
 /****************************************************************************
  **
  ** NAME:       eCLD_ThermostatCommandHostSchedulePayloadSend
  **
  ** DESCRIPTION:
  ** Builds and sends an thermostat cluster command
  **
  ** PARAMETERS:                                     Name                           Usage
  ** uint8                                           u8SourceEndPointId             Source EP Id
  ** uint8                                           u8DestinationEndPointId        Destination EP Id
  ** tsZCL_Address                                   *psDestinationAddress           Destination Address
  ** uint8                                           *pu8TransactionSequenceNumber   Sequence number Pointer
  ** tsCLD_Thermostat_HostSchedulePayload    			*psPayload                      Payload
  **
  ** RETURN:
  ** teZCL_Status
  **
  ****************************************************************************/
 PUBLIC teZCL_Status eCLD_Thermostat_SetHostHolidayPayloadSend(
                     uint8                                           u8SourceEndPointId,
                     uint8                                           u8DestinationEndPointId,
                     tsZCL_Address                                   *psDestinationAddress,
                     uint8                                           *pu8TransactionSequenceNumber,
					 tsCLD_Thermostat_SetHostHolidayPayload   			*psPayload)
 {
	    tsZCL_TxPayloadItem asPayloadDefinition[] = {
	            {THERMOSTAT_HOLIDAY_BUFFER_SIZE,  E_ZCL_ENUM8,   &psPayload->u8_SetHolidayBuffer},
	                                              };

	    return (eZCL_CustomCommandSend(u8SourceEndPointId,
	                                  u8DestinationEndPointId,
	                                  psDestinationAddress,
	                                  HVAC_CLUSTER_ID_THERMOSTAT,
	                                  FALSE,
									  E_CLD_THERMOSTAT_CMD_SET_HOST_HOLIDAY,
	                                  pu8TransactionSequenceNumber,
	                                  asPayloadDefinition,
	                                  TRUE,
									  ZCL_MANUFACTURER_CODE,
	                                  sizeof(asPayloadDefinition) / sizeof(tsZCL_TxPayloadItem)));
 }
 /****************************************************************************
  **
  ** NAME:       eCLD_ThermostatCommandHostSchedulePayloadSend
  **
  ** DESCRIPTION:
  ** Builds and sends an thermostat cluster command
  **
  ** PARAMETERS:                                     Name                           Usage
  ** uint8                                           u8SourceEndPointId             Source EP Id
  ** uint8                                           u8DestinationEndPointId        Destination EP Id
  ** tsZCL_Address                                   *psDestinationAddress           Destination Address
  ** uint8                                           *pu8TransactionSequenceNumber   Sequence number Pointer
  ** tsCLD_Thermostat_HostSchedulePayload    			*psPayload                      Payload
  **
  ** RETURN:
  ** teZCL_Status
  **
  ****************************************************************************/
 PUBLIC teZCL_Status eCLD_ThermostatCommandHostSchedulePayloadSend(
                     uint8                                           u8SourceEndPointId,
                     uint8                                           u8DestinationEndPointId,
                     tsZCL_Address                                   *psDestinationAddress,
                     uint8                                           *pu8TransactionSequenceNumber,
 					tsCLD_Thermostat_HostSchedulePayload   			*psPayload)
 {
	    tsZCL_TxPayloadItem asPayloadDefinition[] = {
	            {56,                         E_ZCL_ENUM8,   &psPayload->u8_ScheduleBuffer},
	                                              };

	    return (eZCL_CustomCommandSend(u8SourceEndPointId,
	                                  u8DestinationEndPointId,
	                                  psDestinationAddress,
	                                  HVAC_CLUSTER_ID_THERMOSTAT,
	                                  FALSE,
									  E_CLD_THERMOSTAT_CMD_SET_HOST_SCHEDULE,
	                                  pu8TransactionSequenceNumber,
	                                  asPayloadDefinition,
	                                  TRUE,
									  ZCL_MANUFACTURER_CODE,
	                                  sizeof(asPayloadDefinition) / sizeof(tsZCL_TxPayloadItem)));


 }
#endif

#ifdef THERMOSTAT_SERVER
/****************************************************************************
 **
 ** NAME:       eCLD_ThermostatCommandHostScheduleReceive
 **
 ** DESCRIPTION:
 ** handles rx of identify query response
 **
 ** PARAMETERS:                                     Name                          Usage
 ** ZPS_tsAfEvent                                   *pZPSevent                     Zigbee stack event structure
 ** uint8                                           *pu8TransactionSequenceNumber  Sequence number Pointer
 ** tsCLD_Thermostat_HostSchedulePayload   			 *psPayload                     Payload
 **
 ** RETURN:
 ** teZCL_Status
 **
 ****************************************************************************/
PUBLIC teZCL_Status eCLD_ThermostatCommandSetHostHolidayReceive(
                    ZPS_tsAfEvent                                   *pZPSevent,
                    uint8                                           *pu8TransactionSequenceNumber,
					tsCLD_Thermostat_SetHostHolidayPayload    		*psPayload)
{
	uint16 u16ActualQuantity;

	    tsZCL_RxPayloadItem asPayloadDefinition[] = {
	            {THERMOSTAT_HOLIDAY_BUFFER_SIZE,                             &u16ActualQuantity,             E_ZCL_ENUM8,           &psPayload->u8_SetHolidayBuffer},

	                                                };

	    return (eZCL_CustomCommandReceive(pZPSevent,
	                                        pu8TransactionSequenceNumber,
	                                        asPayloadDefinition,
	                                        sizeof(asPayloadDefinition) / sizeof(tsZCL_RxPayloadItem),
	                                        E_ZCL_ACCEPT_EXACT));

}
/****************************************************************************
 **
 ** NAME:       eCLD_ThermostatCommandHostScheduleReceive
 **
 ** DESCRIPTION:
 ** handles rx of identify query response
 **
 ** PARAMETERS:                                     Name                          Usage
 ** ZPS_tsAfEvent                                   *pZPSevent                     Zigbee stack event structure
 ** uint8                                           *pu8TransactionSequenceNumber  Sequence number Pointer
 ** tsCLD_Thermostat_HostSchedulePayload   			 *psPayload                     Payload
 **
 ** RETURN:
 ** teZCL_Status
 **
 ****************************************************************************/
PUBLIC teZCL_Status eCLD_ThermostatCommandHostScheduleReceive(
		ZPS_tsAfEvent *pZPSevent, uint8 *pu8TransactionSequenceNumber,
		tsCLD_Thermostat_HostSchedulePayload *psPayload) {
	uint16 u16ActualQuantity;

	tsZCL_RxPayloadItem asPayloadDefinition[] = { {
			THERMOSTAT_SETPOINTS_BUFFER_SIZE, &u16ActualQuantity, E_ZCL_ENUM8,&psPayload->u8_ScheduleBuffer },

	};

	return (eZCL_CustomCommandReceive(pZPSevent, pu8TransactionSequenceNumber,
			asPayloadDefinition,
			sizeof(asPayloadDefinition) / sizeof(tsZCL_RxPayloadItem),
			E_ZCL_ACCEPT_EXACT));

}
#endif
/****************************************************************************/
/***        END OF FILE                                                   ***/
/****************************************************************************/
