This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Not able to see power config cluster and its attributes, analog input cluster

Hello All,

I tried implementing basic cluster, Analog Input cluster and Power Config Cluster. My end application is report "measured tank level" using zigbee. For which nordic engineer suggested me to use Analog Input cluster.

From them I am able to see basic cluster, Analog Input cluster (few attributes from analog cluster are non editable even though access is "RW").

But I am not able to see the power config cluster and its attributes. I feel, I have followed the steps mentioned in nordic info center correctly and I am not able to locate the problem. 

I request you to please help me with this. Please find the attached firmware files and the image with the clusters for your reference.

Also it will be helpful with the following problems:

1) Regarding few attributes in analog cluster: I am not able to edit them when using deConz application even though they have read write access. Please find the attached image for your reference. In the image I have marked the problem with "1". Please guide me how can I have "read/write access". I have created the analog input cluster taking the reference of pressure sensor.c and .h file, Binary Input.h and multisensor project. In the attached analog input.h file please ignore the comments as they relate to binary input.

2) How can I change the name from temperature sensor to other custom name? I have marked the problem with " 2 " in the attached image.

3) How can I get the custom name in the place of the NWK ID (for example you can see the name " thermostat" for the thermostat device). I have marked the problem with " 3 " in the attached image.

I request you to help me with the above problems.

For more information, please feel free to ask.

Thanks and regards

Ankeet Gugale

/**
 * Copyright (c) 2018 - 2020, Nordic Semiconductor ASA
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form, except as embedded into a Nordic
 *    Semiconductor ASA integrated circuit in a product or a software update for
 *    such product, 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.
 *
 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * 4. This software, with or without modification, must only be used with a
 *    Nordic Semiconductor ASA integrated circuit.
 *
 * 5. Any software provided in binary form under this license must not be reverse
 *    engineered, decompiled, modified and/or disassembled.
 *
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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.
 *
 */
#include "zboss_api.h"
//#include "zb_zcl_pressure_measurement.h"
#include "app_error.h"
#include "nrf_log.h"
#include "zb_zcl_analog_input.h"
/**@brief Function which pre-validates the value of attributes before they are written.
 * 
 * @param [in] attr_id  Attribute ID
 * @param [in] endpoint Endpoint
 * @param [in] p_value  Pointer to the value of the attribute which is to be validated
 * 
 * @return ZB_TRUE if the value is valid, ZB_FALSE otherwise.
 */
static zb_ret_t check_value_pres_measurement(zb_uint16_t attr_id, zb_uint8_t endpoint, zb_uint8_t * p_value)
{
    zb_ret_t ret = ZB_FALSE;
    zb_int16_t val = ZB_ZCL_ATTR_GETS16(p_value);

    NRF_LOG_DEBUG("Pre-validating value %hi of Pressure attribute %d", val, attr_id);

    switch(attr_id)
    {
        
        default:
           break;
    }

    return ret;
}

/**@brief Hook which is being called whenever a new value of attribute is being written.
 * 
 * @param [in] endpoint Endpoint
 * @param [in] attr_id Attribute ID
 * @param [in] new_value Pointer to the new value of the attribute
 */
static zb_void_t zb_zcl_pres_measurement_write_attr_hook(zb_uint8_t endpoint, zb_uint16_t attr_id, zb_uint8_t * new_value)
{
    UNUSED_PARAMETER(new_value);

    NRF_LOG_DEBUG("Writing attribute %d of Pressure Measurement Cluster on endpoint %d", attr_id, endpoint);

//    if (attr_id == ZB_ZCL_ATTR_PRES_MEASUREMENT_VALUE_ID)
//    {
	      /* Implement your own write attributes hook if needed. */
//    }
}

/**@brief Function which initialises the server side of Pressure Measurement Cluster. */
zb_void_t zb_zcl_analog_input_init_server()
{
    zb_ret_t ret = zb_zcl_add_cluster_handlers(ZB_ZCL_CLUSTER_ID_ANALOG_INPUT,
                                               ZB_ZCL_CLUSTER_SERVER_ROLE,
                                               check_value_pres_measurement,
                                               zb_zcl_pres_measurement_write_attr_hook,
                                               (zb_zcl_cluster_handler_t)NULL);
    ASSERT(ret == RET_OK);
}

/**@brief Function which initialises the client side of Pressure Measurement Cluster. */
zb_void_t zb_zcl_analog_input_init_client()
{
    zb_ret_t ret = zb_zcl_add_cluster_handlers(ZB_ZCL_CLUSTER_ID_ANALOG_INPUT,
                                               ZB_ZCL_CLUSTER_CLIENT_ROLE,
                                               check_value_pres_measurement,
                                               zb_zcl_pres_measurement_write_attr_hook,
                                               (zb_zcl_cluster_handler_t)NULL);
    ASSERT(ret == RET_OK);
}

/**
 * Copyright (c) 2018 - 2020, Nordic Semiconductor ASA
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form, except as embedded into a Nordic
 *    Semiconductor ASA integrated circuit in a product or a software update for
 *    such product, 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.
 *
 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * 4. This software, with or without modification, must only be used with a
 *    Nordic Semiconductor ASA integrated circuit.
 *
 * 5. Any software provided in binary form under this license must not be reverse
 *    engineered, decompiled, modified and/or disassembled.
 *
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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.
 *
 */
/** @file
 *
 * @defgroup zigbee_examples_multi_sensor main.c
 * @{
 * @ingroup zigbee_examples
 * @brief Zigbee Pressure and Temperature sensor
 */

#include "zboss_api.h"
#include "zb_mem_config_med.h"
#include "zb_error_handler.h"
#include "zigbee_helpers.h"
#include "app_timer.h"
#include "bsp.h"
#include "boards.h"
#include "sensorsim.h"

#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"

#include "zb_multi_sensor.h"
#include "zb_zcl_analog_input.h"


#define IEEE_CHANNEL_MASK                  (ZB_TRANSCEIVER_ALL_CHANNELS_MASK)               /**< Scan only one, predefined channel to find the coordinator. */
#define ERASE_PERSISTENT_CONFIG            ZB_FALSE                             /**< Do not erase NVRAM to save the network parameters after device reboot or power-off. */

#define ZIGBEE_NETWORK_STATE_LED           BSP_BOARD_LED_2                      /**< LED indicating that light switch successfully joind Zigbee network. */

//#define MIN_TEMPERATURE_VALUE              0                                    /**< Minimum temperature value as returned by the simulated measurement function. */
//#define MAX_TEMPERATURE_VALUE              4000                                 /**< Maximum temperature value as returned by the simulated measurement function. */
//#define TEMPERATURE_VALUE_INCREMENT        50                                   /**< Value by which the temperature value is incremented/decremented for each call to the simulated measurement function. */
//#define MIN_PRESSURE_VALUE                 700                                  /**< Minimum pressure value as returned by the simulated measurement function. */
#//define MAX_PRESSURE_VALUE                 1100                                 /**< Maximum pressure value as returned by the simulated measurement function. */
//#define PRESSURE_VALUE_INCREMENT           5                                    /**< Value by which the temperature value is incremented/decremented for each call to the simulated measurement function. */

#if !defined ZB_ED_ROLE
#error Define ZB_ED_ROLE to compile End Device source code.
#endif

static sensor_device_ctx_t m_dev_ctx;


ZB_ZCL_DECLARE_BASIC_ATTRIB_LIST_EXT(basic_attr_list,
                                     &m_dev_ctx.basic_attr.zcl_version,
                                     &m_dev_ctx.basic_attr.app_version,
                                     &m_dev_ctx.basic_attr.stack_version,
                                     &m_dev_ctx.basic_attr.hw_version,
                                     m_dev_ctx.basic_attr.mf_name,
                                     m_dev_ctx.basic_attr.model_id,
                                     m_dev_ctx.basic_attr.date_code,
                                     &m_dev_ctx.basic_attr.power_source,
                                     m_dev_ctx.basic_attr.location_id,
                                     &m_dev_ctx.basic_attr.ph_env,
                                     m_dev_ctx.basic_attr.sw_ver);

                                    

ZB_ZCL_DECLARE_POWER_CONFIG_BATTERY_ATTRIB_LIST_EXT(power_config_attr_list,
                                        &m_dev_ctx.power_attr.battery_voltage,
                                        &m_dev_ctx.power_attr.battery_size,
                                        &m_dev_ctx.power_attr.battery_quantity,
                                        &m_dev_ctx.power_attr.battery_rated_voltage,
                                        &m_dev_ctx.power_attr.battery_alarm_mask,
                                        &m_dev_ctx.power_attr.battery_voltage_min_threshold,
                                        &m_dev_ctx.power_attr.battery_percentage_remaining,
                                        &m_dev_ctx.power_attr.battery_voltage_threshold1,
                                        &m_dev_ctx.power_attr.battery_voltage_threshold2,
                                        &m_dev_ctx.power_attr.battery_voltage_threshold3,
                                        &m_dev_ctx.power_attr.battery_percentage_min_threshold,
                                        &m_dev_ctx.power_attr.battery_percentage_threshold1,
                                        &m_dev_ctx.power_attr.battery_percentage_threshold2,
                                        &m_dev_ctx.power_attr.battery_percentage_threshold3,
                                        &m_dev_ctx.power_attr.battery_alarm_state);


ZB_ZCL_DECLARE_TANKLEVEL_ATTRIB_LIST(tanklevel_attr_list, 
                                     &m_dev_ctx.tank_level_attr.present_value,
                                     &m_dev_ctx.tank_level_attr.min_present_value,
                                     &m_dev_ctx.tank_level_attr.max_present_value,
                                     &m_dev_ctx.tank_level_attr.status_flag);


ZB_DECLARE_TANKLEVEL_SENSOR_CLUSTER_LIST(tanklevel_sensor_clusters,
                                     basic_attr_list,
                                     tanklevel_attr_list,
                                     power_config_attr_list);

ZB_ZCL_DECLARE_TANKLEVEL_SENSOR_EP(multi_sensor_ep,
                               TANKLEVEL_SENSOR_ENDPOINT,
                               tanklevel_sensor_clusters);

ZBOSS_DECLARE_DEVICE_CTX_1_EP(tanklevel_sensor_ctx, multi_sensor_ep);


APP_TIMER_DEF(zb_app_timer);


/**@brief Function for the Timer initialization.
 *
 * @details Initializes the timer module. This creates and starts application timers.
 */
static void timers_init(void)
{
    ret_code_t err_code;

    // Initialize timer module.
    err_code = app_timer_init();
    APP_ERROR_CHECK(err_code);
}

/**@brief Function for initializing the nrf log module.
 */
static void log_init(void)
{
    ret_code_t err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);

    NRF_LOG_DEFAULT_BACKENDS_INIT();
}

/**@brief Function for initializing all clusters attributes.
 */
static void tanklevel_sensor_clusters_attr_init(void)
{
    /* Basic cluster attributes data */
    m_dev_ctx.basic_attr.zcl_version   = ZB_ZCL_VERSION;
    m_dev_ctx.basic_attr.app_version   = SENSOR_INIT_BASIC_APP_VERSION;
    m_dev_ctx.basic_attr.stack_version = SENSOR_INIT_BASIC_STACK_VERSION;
    m_dev_ctx.basic_attr.hw_version    = SENSOR_INIT_BASIC_HW_VERSION;

    /* Use ZB_ZCL_SET_STRING_VAL to set strings, because the first byte should
     * contain string length without trailing zero.
     *
     * For example "test" string wil be encoded as:
     *   [(0x4), 't', 'e', 's', 't']
     */
    ZB_ZCL_SET_STRING_VAL(m_dev_ctx.basic_attr.mf_name,
                          SENSOR_INIT_BASIC_MANUF_NAME,
                          ZB_ZCL_STRING_CONST_SIZE(SENSOR_INIT_BASIC_MANUF_NAME));

    ZB_ZCL_SET_STRING_VAL(m_dev_ctx.basic_attr.model_id,
                          SENSOR_INIT_BASIC_MODEL_ID,
                          ZB_ZCL_STRING_CONST_SIZE(SENSOR_INIT_BASIC_MODEL_ID));

    ZB_ZCL_SET_STRING_VAL(m_dev_ctx.basic_attr.date_code,
                          SENSOR_INIT_BASIC_DATE_CODE,
                          ZB_ZCL_STRING_CONST_SIZE(SENSOR_INIT_BASIC_DATE_CODE));

    m_dev_ctx.basic_attr.power_source = SENSOR_INIT_BASIC_POWER_SOURCE;

    ZB_ZCL_SET_STRING_VAL(m_dev_ctx.basic_attr.location_id,
                          SENSOR_INIT_BASIC_LOCATION_DESC,
                          ZB_ZCL_STRING_CONST_SIZE(SENSOR_INIT_BASIC_LOCATION_DESC));


    m_dev_ctx.basic_attr.ph_env = SENSOR_INIT_BASIC_PH_ENV;

    /* Identify cluster attributes data */
 //   m_dev_ctx.identify_attr.identify_time        = ZB_ZCL_IDENTIFY_IDENTIFY_TIME_DEFAULT_VALUE;
     
     /**power configuration attributes data**/
    m_dev_ctx.power_attr.battery_percentage_remaining = 0x02;
    m_dev_ctx.power_attr.battery_quantity = ZB_POWER_CONFIG_BATTERY_QUANTITY;
    m_dev_ctx.power_attr.battery_size = ZB_ZCL_POWER_CONFIG_BATTERY_SIZE_AA;

    /* Temperature measurement cluster attributes data */
      m_dev_ctx.tank_level_attr.present_value                = 50;
      m_dev_ctx.tank_level_attr.min_present_value            = 10;
      m_dev_ctx.tank_level_attr.max_present_value            = 100;

   ZB_ZCL_SET_ATTRIBUTE(TANKLEVEL_SENSOR_ENDPOINT,
                        ZB_ZCL_CLUSTER_ID_POWER_CONFIG,
                        ZB_ZCL_CLUSTER_SERVER_ROLE,
                        ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_PERCENTAGE_REMAINING_ID,
                        (zb_uint8_t *)&m_dev_ctx.power_attr.battery_percentage_remaining,
                        ZB_FALSE);  
                                  
   ZB_ZCL_SET_ATTRIBUTE(TANKLEVEL_SENSOR_ENDPOINT,
                        ZB_ZCL_CLUSTER_ID_POWER_CONFIG,
                        ZB_ZCL_CLUSTER_SERVER_ROLE,
                        ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_QUANTITY_ID,
                        (zb_uint8_t *)&m_dev_ctx.power_attr.battery_quantity,
                        ZB_FALSE);
}

/**@brief Function for initializing LEDs.
 */

void ReadRemainigBatteryPercentage(zb_uint8_t ui8BatteryPercentage)
{
   zb_zcl_status_t zcl_status;

   zcl_status = zb_zcl_set_attr_val(TANKLEVEL_SENSOR_ENDPOINT, 
                                     ZB_ZCL_CLUSTER_ID_POWER_CONFIG, 
                                     ZB_ZCL_CLUSTER_SERVER_ROLE, 
                                     ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_PERCENTAGE_REMAINING_ID, 
                                     &ui8BatteryPercentage , 
                                     ZB_FALSE);
   if(zcl_status != ZB_ZCL_STATUS_SUCCESS)
   {
      NRF_LOG_INFO("Set Battery percentage value fail. zcl_status: %d", zcl_status);
   }
}

static zb_void_t leds_init(void)
{
    ret_code_t error_code;

    /* Initialize LEDs and buttons - use BSP to control them. */
    error_code = bsp_init(BSP_INIT_LEDS, NULL);
    APP_ERROR_CHECK(error_code);

    bsp_board_leds_off();
}


/**@brief Function for initializing the sensor simulators.
 */
/*static void sensor_simulator_init(void)
{
    m_temperature_sim_cfg.min          = MIN_TEMPERATURE_VALUE;
    m_temperature_sim_cfg.max          = MAX_TEMPERATURE_VALUE;
    m_temperature_sim_cfg.incr         = TEMPERATURE_VALUE_INCREMENT;
    m_temperature_sim_cfg.start_at_max = false;

    sensorsim_init(&m_temperature_sim_state, &m_temperature_sim_cfg);

    m_pressure_sim_cfg.min          = MIN_PRESSURE_VALUE;
    m_pressure_sim_cfg.max          = MAX_PRESSURE_VALUE;
    m_pressure_sim_cfg.incr         = PRESSURE_VALUE_INCREMENT;
    m_pressure_sim_cfg.start_at_max = false;

    sensorsim_init(&m_pressure_sim_state, &m_pressure_sim_cfg);
}*/


/**@brief Zigbee stack event handler.
 *
 * @param[in]   bufid   Reference to the Zigbee stack buffer used to pass signal.
 */
void zboss_signal_handler(zb_bufid_t bufid)
{
    zb_zdo_app_signal_hdr_t  * p_sg_p      = NULL;
    zb_zdo_app_signal_type_t   sig         = zb_get_app_signal(bufid, &p_sg_p);
    zb_ret_t                   status      = ZB_GET_APP_SIGNAL_STATUS(bufid);

    /* Update network status LED */
    zigbee_led_status_update(bufid, ZIGBEE_NETWORK_STATE_LED);

    switch (sig)
    {
        case ZB_BDB_SIGNAL_DEVICE_REBOOT:
            /* fall-through */
        case ZB_BDB_SIGNAL_STEERING:
            /* Call default signal handler. */
            ZB_ERROR_CHECK(zigbee_default_signal_handler(bufid));
            if (status == RET_OK)
            {
 //               ret_code_t err_code = app_timer_start(zb_app_timer, APP_TIMER_TICKS(1000), NULL);
 //               APP_ERROR_CHECK(err_code);
            }
            break;

        default:
            /* Call default signal handler. */
            ZB_ERROR_CHECK(zigbee_default_signal_handler(bufid));
            break;
    }

    if (bufid)
    {
        zb_buf_free(bufid);
    }
}

/**@brief Function for application main entry.
 */
int main(void)
{
    zb_ret_t       zb_err_code;
    ret_code_t     err_code;
    zb_ieee_addr_t ieee_addr;

    /* Initialize loging system and GPIOs. */
    timers_init();
    log_init();
    leds_init();

    /* Create Timer for reporting attribute */
//    err_code = app_timer_create(&zb_app_timer, APP_TIMER_MODE_REPEATED, zb_app_timer_handler);
    APP_ERROR_CHECK(err_code);

    /* Set Zigbee stack logging level and traffic dump subsystem. */
    ZB_SET_TRACE_LEVEL(ZIGBEE_TRACE_LEVEL);
    ZB_SET_TRACE_MASK(ZIGBEE_TRACE_MASK);
    ZB_SET_TRAF_DUMP_OFF();

    /* Initialize Zigbee stack. */
    ZB_INIT("tanklevel_sensor");

    /* Set device address to the value read from FICR registers. */
    zb_osif_get_ieee_eui64(ieee_addr);
    zb_set_long_address(ieee_addr);

    /* Set static long IEEE address. */
    zb_set_network_ed_role(IEEE_CHANNEL_MASK);
    zigbee_erase_persistent_storage(ERASE_PERSISTENT_CONFIG);

    zb_set_ed_timeout(ED_AGING_TIMEOUT_64MIN);
    zb_set_keepalive_timeout(ZB_MILLISECONDS_TO_BEACON_INTERVAL(3000));
    zb_set_rx_on_when_idle(ZB_FALSE);

    /* Initialize application context structure. */
    UNUSED_RETURN_VALUE(ZB_MEMSET(&m_dev_ctx, 0, sizeof(m_dev_ctx)));

    /* Register temperature sensor device context (endpoints). */
    ZB_AF_REGISTER_DEVICE_CTX(&tanklevel_sensor_ctx);

    /* Initialize sensor device attibutes */
    tanklevel_sensor_clusters_attr_init();

    /** Start Zigbee Stack. */
    zb_err_code = zboss_start_no_autostart();
    ZB_ERROR_CHECK(zb_err_code);

    while(1)
    {
        zboss_main_loop_iteration();
        UNUSED_RETURN_VALUE(NRF_LOG_PROCESS());
    }
}


/**
 * @}
 */
/**
 * Copyright (c) 2018 - 2020, Nordic Semiconductor ASA
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form, except as embedded into a Nordic
 *    Semiconductor ASA integrated circuit in a product or a software update for
 *    such product, 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.
 *
 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * 4. This software, with or without modification, must only be used with a
 *    Nordic Semiconductor ASA integrated circuit.
 *
 * 5. Any software provided in binary form under this license must not be reverse
 *    engineered, decompiled, modified and/or disassembled.
 *
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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 ZB_MULTI_SENSOR_H__
#define ZB_MULTI_SENSOR_H__

#include "zboss_api.h"
#include "zboss_api_addons.h"
//#include "zb_zcl_pressure_measurement.h"
#include "zb_zcl_analog_input.h"
#include "zb_zcl_power_config.h"

#define ZB_HA_CUSTOM1_ANALOG_INPUT_DEVICE_ID    0xfff2


/* Basic cluster attributes initial values. For more information, see section 3.2.2.2 of the ZCL specification. */
#define SENSOR_INIT_BASIC_APP_VERSION       01                                  /**< Version of the application software (1 byte). */
#define SENSOR_INIT_BASIC_STACK_VERSION     10                                  /**< Version of the implementation of the Zigbee stack (1 byte). */
#define SENSOR_INIT_BASIC_HW_VERSION        02                                  /**< Version of the hardware of the device (1 byte). */
#define SENSOR_INIT_BASIC_MANUF_NAME        "Eurotronic"                            /**< Manufacturer name (32 bytes). */
#define SENSOR_INIT_BASIC_MODEL_ID          "TankLevelSensor"                       /**< Model number assigned by the manufacturer (32-bytes long string). */
#define SENSOR_INIT_BASIC_DATE_CODE         "20210812"                          /**< Date provided by the manufacturer of the device in ISO 8601 format (YYYYMMDD), for the first 8 bytes. The remaining 8 bytes are manufacturer-specific. */
#define SENSOR_INIT_BASIC_POWER_SOURCE      ZB_ZCL_BASIC_POWER_SOURCE_BATTERY /**< Type of power source or sources available for the device. For possible values, see section 3.2.2.2.8 of the ZCL specification. */
#define SENSOR_INIT_BASIC_LOCATION_DESC     "Office desk"                       /**< Description of the physical location of the device (16 bytes). You can modify it during the commisioning process. */
#define SENSOR_INIT_BASIC_PH_ENV            ZB_ZCL_BASIC_ENV_UNSPECIFIED        /**< Description of the type of physical environment. For possible values, see section 3.2.2.2.10 of the ZCL specification. */

#define TANKLEVEL_SENSOR_ENDPOINT               1                                  /**< Device endpoint. Used to receive light controlling commands. */


/* Power config cluster attributes*/
typedef struct
{
    zb_uint8_t battery_voltage;
    zb_uint8_t battery_size;
    zb_uint8_t battery_quantity;
    zb_uint8_t battery_rated_voltage;
    zb_uint8_t battery_alarm_mask;
    zb_uint8_t battery_voltage_min_threshold;
    zb_uint8_t battery_percentage_remaining;
    zb_uint8_t battery_voltage_threshold1;
    zb_uint8_t battery_voltage_threshold2;
    zb_uint8_t battery_voltage_threshold3;
    zb_uint8_t battery_percentage_min_threshold;
    zb_uint8_t battery_percentage_threshold1;
    zb_uint8_t battery_percentage_threshold2;
    zb_uint8_t battery_percentage_threshold3;
    zb_uint32_t battery_alarm_state;
}zb_zcl_power_attrs_t;

/* Main application customizable context. Stores all settings and static values. */
typedef struct
{
    zb_zcl_basic_attrs_ext_t            basic_attr;
    zb_zcl_level_measurement_attrs_t    tank_level_attr;
    zb_zcl_power_attrs_t                power_attr;
} sensor_device_ctx_t;


#define ZB_ZCL_TANKLEVEL_REPORT_ATTR_COUNT             1
//#define ZB_TANKLEVEL_SENSOR_REPORT_ATTR_COUNT  1                                    /**< Number of attributes mandatory for reporting in the Temperature and Pressure Measurement cluster. */
#define ZB_DEVICE_VER_TANKLEVEL_SENSOR         1                                    /**< Multisensor device version. */
#define ZB_TANKLEVEL_SENSOR_IN_CLUSTER_NUM     3                                    /**< Number of the input (server) clusters in the multisensor device. */
#define ZB_TANKLEVEL_SENSOR_OUT_CLUSTER_NUM    0                                    /**< Number of the output (client) clusters in the multisensor device. */

#define ZB_POWER_CONFIG_BATTERY_QUANTITY  0x02

#define ZB_TANKLEVEL_SENSOR_REPORT_ATTR_COUNT (ZB_ZCL_TANKLEVEL_REPORT_ATTR_COUNT    \
                                            + ZB_ZCL_POWER_CONFIG_REPORT_ATTR_COUNT)


/** @brief Declares cluster list for the multisensor device.
 *
 *  @param cluster_list_name            Cluster list variable name.
 *  @param basic_attr_list              Attribute list for the Basic cluster.
 *  @param identify_attr_list           Attribute list for the Identify cluster.
 *  @param temp_measure_attr_list       Attribute list for the Temperature Measurement cluster.
 *  @param pressure_measure_attr_list   Attribute list for the Pressure Measurement cluster.
 */
#define ZB_DECLARE_TANKLEVEL_SENSOR_CLUSTER_LIST(                   \
      cluster_list_name,                                            \
      basic_attr_list,                                              \
      tanklevel_attr_list,                                          \
      power_config_attr_list)                                       \
      zb_zcl_cluster_desc_t cluster_list_name[] =                   \
      {                                                             \
        ZB_ZCL_CLUSTER_DESC(                                        \
          ZB_ZCL_CLUSTER_ID_BASIC,                                  \
          ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t),        \
          (basic_attr_list),                                        \
          ZB_ZCL_CLUSTER_SERVER_ROLE,                               \
          ZB_ZCL_MANUF_CODE_INVALID                                 \
        ),                                                          \
        ZB_ZCL_CLUSTER_DESC(                                        \
          ZB_ZCL_CLUSTER_ID_ANALOG_INPUT,                           \
          ZB_ZCL_ARRAY_SIZE(tanklevel_attr_list, zb_zcl_attr_t),    \
          (tanklevel_attr_list),                                    \
          ZB_ZCL_CLUSTER_SERVER_ROLE,                               \
          ZB_ZCL_MANUF_CODE_INVALID                                 \
        ),                                                          \
          ZB_ZCL_CLUSTER_DESC(                                      \
          ZB_ZCL_CLUSTER_ID_POWER_CONFIG,                           \
          ZB_ZCL_ARRAY_SIZE(power_config_attr_list, zb_zcl_attr_t), \
          (power_config_attr_list),                                 \
          ZB_ZCL_CLUSTER_SERVER_ROLE,                               \
          ZB_ZCL_MANUF_CODE_INVALID                                 \
        )                                                           \
      }


/** @brief Declares simple descriptor for the "Device_name" device.
 *  
 *  @param ep_name          Endpoint variable name.
 *  @param ep_id            Endpoint ID.
 *  @param in_clust_num     Number of the supported input clusters.
 *  @param out_clust_num    Number of the supported output clusters.
 */
#define ZB_ZCL_DECLARE_TANKLEVEL_SENSOR_DESC(ep_name, ep_id, in_clust_num, out_clust_num) \
  ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num);                                \
  ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num) simple_desc_##ep_name =         \
  {                                                                                   \
    ep_id,                                                                            \
    ZB_AF_HA_PROFILE_ID,                                                              \
    ZB_HA_CUSTOM1_ANALOG_INPUT_DEVICE_ID,                                             \
    ZB_DEVICE_VER_TANKLEVEL_SENSOR,                                                   \
    0,                                                                                \
    in_clust_num,                                                                     \
    out_clust_num,                                                                    \
    {                                                                                 \
      ZB_ZCL_CLUSTER_ID_BASIC,                                                        \
      ZB_ZCL_CLUSTER_ID_ANALOG_INPUT,                                                 \
      ZB_ZCL_CLUSTER_ID_POWER_CONFIG,                                                 \
    }                                                                                 \
  }

/** @brief Declares endpoint for the multisensor device.
 *   
 *  @param ep_name          Endpoint variable name.
 *  @param ep_id            Endpoint ID.
 *  @param cluster_list     Endpoint cluster list.
 */
#define ZB_ZCL_DECLARE_TANKLEVEL_SENSOR_EP(ep_name, ep_id, cluster_list)              \
  ZB_ZCL_DECLARE_TANKLEVEL_SENSOR_DESC(ep_name,                                       \
      ep_id,                                                                      \
      ZB_TANKLEVEL_SENSOR_IN_CLUSTER_NUM,                                             \
      ZB_TANKLEVEL_SENSOR_OUT_CLUSTER_NUM);                                           \
  ZBOSS_DEVICE_DECLARE_REPORTING_CTX(reporting_info## device_ctx_name,            \
                                     ZB_TANKLEVEL_SENSOR_REPORT_ATTR_COUNT);          \
  ZB_AF_DECLARE_ENDPOINT_DESC(ep_name, ep_id,                                     \
      ZB_AF_HA_PROFILE_ID,                                                        \
      0,                                                                          \
      NULL,                                                                       \
      ZB_ZCL_ARRAY_SIZE(cluster_list, zb_zcl_cluster_desc_t),                     \
      cluster_list,                                                               \
      (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name,                           \
      ZB_TANKLEVEL_SENSOR_REPORT_ATTR_COUNT, reporting_info## device_ctx_name, 0, NULL)



#endif // ZB_MULTI_SENSOR_H__
/* ZBOSS Zigbee 3.0
 *
 * Copyright (c) 2012-2018 DSR Corporation, Denver CO, USA.
 * http://www.dsr-zboss.com
 * http://www.dsr-corporation.com
 * All rights reserved.
 *
 *
 * Use in source and binary forms, redistribution in binary form only, with
 * or without modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions in binary form, except as embedded into a Nordic
 *    Semiconductor ASA integrated circuit in a product or a software update for
 *    such product, 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.
 *
 * 2. Neither the name of Nordic Semiconductor ASA nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * 3. This software, with or without modification, must only be used with a Nordic
 *    Semiconductor ASA integrated circuit.
 *
 * 4. Any software provided in binary form under this license must not be reverse
 *    engineered, decompiled, modified and/or disassembled.
 *
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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.
PURPOSE: Binary Input cluster
*/

#ifndef ZB_ZCL_ANALOG_INPUT_H__
#define ZB_ZCL_ANALOG_INPUT_H__


#include "zcl/zb_zcl_common.h"
#include "zcl/zb_zcl_commands.h"
#include "zboss_api.h"
#include "zboss_api_addons.h"
#include "zb_zcl_power_config.h"
#include "sdk_config.h"


/**@brief Analog Input cluster attributes according to ZCL Specification 4.5.2.1.1. */
typedef struct
{
    float  present_value;
    float  min_present_value;
    float  max_present_value;
    zb_uint8_t status_flag;
} zb_zcl_level_measurement_attrs_t;




/** @brief Binary Input cluster attribute identifiers. */
enum zb_zcl_analog_input_attr_e
{
  
  /** The Description attribute, of type Character string, MAY be used to hold a
   *  description of the usage of the input, output or value, as appropriate
   *  to the cluster. */
  ZB_ZCL_ATTR_ANALOG_INPUT_DESCRIPTION_ID               = 0x001C,

  /** @brief OutOfService attribute */
  ZB_ZCL_ATTR_ANALOG_INPUT_OUT_OF_SERVICE_ID            = 0x0051,
 
  /** @brief PresentValue attribute */
  ZB_ZCL_ATTR_ANALOG_INPUT_PRESENT_VALUE_ID             = 0x0055,

   /** @brief MaximumPresentValue attribute */
  ZB_ZCL_ATTR_ANALOG_INPUT_MAX_PRESENT_VALUE_ID         = 0X0041,

   /** @brief MinimumPresentValue attribute */
  ZB_ZCL_ATTR_ANALOG_INPUT_MIN_PRESENT_VALUE_ID         = 0X0045,


  /** The Reliability attribute, of type 8-bit enumeration, provides an indication
   *  of whether the PresentValue or the operation of the physical input,
   *  output or value in question (as appropriate for the cluster) is reliable
   *  as far as can be determined and, if not, why not. */
  ZB_ZCL_ATTR_ANALOG_INPUT_RELIABILITY_ID               = 0x0067,

  /** @brief StatusFlag attribute */
  ZB_ZCL_ATTR_ANALOG_INPUT_STATUS_FLAG_ID               = 0x006F,
  /** The ApplicationType attribute is an unsigned 32-bit integer that indicates
   *  the specific application usage for this cluster. */
  ZB_ZCL_ATTR_ANALOG_INPUT_APPLICATION_TYPE_ID          = 0x0100,
};


/** @brief Default value for Description attribute */
#define ZB_ZCL_ANALOG_INPUT_DESCRIPTION_DEFAULT_VALUE {0}

/*! @brief OutOfService attribute default value */
#define ZB_ZCL_ANALOG_INPUT_OUT_OF_SERVICE_DEFAULT_VALUE ZB_FALSE

/** @brief Default value for Reliability attribute */
#define ZB_ZCL_ANALOG_INPUT_RELIABILITY_DEFAULT_VALUE ((zb_uint8_t)0x00)

/*! @brief StatusFlag attribute default value */
#define ZB_ZCL_ANALOG_INPUT_STATUS_FLAG_DEFAULT_VALUE ZB_ZCL_ANALOG_INPUT_STATUS_FLAG_NORMAL

/*! @brief StatusFlag attribute minimum value */
#define ZB_ZCL_ANALOG_INPUT_STATUS_FLAG_MIN_VALUE 0

/*! @brief StatusFlag attribute maximum value */
#define ZB_ZCL_ANALOG_INPUT_STATUS_FLAG_MAX_VALUE 0x0F

#define ZB_ZCL_ANALOG_INPUT_PRESENT_VALUE 0

/* Optionally, access to this attribute may be changed to READ_WRITE*/ 
//#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_ANALOG_INPUT_OUT_OF_SERVICE_ID(data_ptr) \
//{                                                                   \
//  ZB_ZCL_ATTR_BINARY_INPUT_OUT_OF_SERVICE_ID,                       \
//  ZB_ZCL_ATTR_TYPE_BOOL,                                            \
//  ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_WRITE_OPTIONAL, \
//  (zb_voidp_t) data_ptr                                             \
//}

/* Optionally, access to this attribute may be changed to READ_WRITE */
#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_ANALOG_INPUT_PRESENT_VALUE_ID(data_ptr) \
{                                                                   \
  ZB_ZCL_ATTR_ANALOG_INPUT_PRESENT_VALUE_ID,                        \
  ZB_ZCL_ATTR_TYPE_SINGLE,                                            \
  ZB_ZCL_ATTR_ACCESS_READ_WRITE | ZB_ZCL_ATTR_ACCESS_REPORTING, \
  (zb_voidp_t) data_ptr                                             \
}

#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_ANALOG_INPUT_MAX_PRESENT_VALUE_ID(data_ptr) \
{                                                                   \
  ZB_ZCL_ATTR_ANALOG_INPUT_MAX_PRESENT_VALUE_ID,                        \
  ZB_ZCL_ATTR_TYPE_SINGLE,                                            \
  ZB_ZCL_ATTR_ACCESS_READ_WRITE | ZB_ZCL_ATTR_ACCESS_REPORTING, \
  (zb_voidp_t) data_ptr                                             \
}

#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_ANALOG_INPUT_MIN_PRESENT_VALUE_ID(data_ptr) \
{                                                                   \
  ZB_ZCL_ATTR_ANALOG_INPUT_MIN_PRESENT_VALUE_ID,                        \
  ZB_ZCL_ATTR_TYPE_SINGLE,                                            \
  ZB_ZCL_ATTR_ACCESS_READ_WRITE | ZB_ZCL_ATTR_ACCESS_REPORTING, \
  (zb_voidp_t) data_ptr                                             \
}

#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_ANALOG_INPUT_STATUS_FLAG_ID(data_ptr) \
{                                                                   \
  ZB_ZCL_ATTR_ANALOG_INPUT_STATUS_FLAG_ID,                          \
  ZB_ZCL_ATTR_TYPE_8BITMAP,                                         \
  ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING,      \
  (zb_voidp_t) data_ptr                                             \
}



/** @brief Declare attribute list for Binary Input cluster
    @param attr_list - attribute list name
    @param out_of_service - pointer to variable to store OutOfService attribute value
    @param present_value -  pointer to variable to store PresentValue attribute value
    @param status_flag -  pointer to variable to store StatusFlag attribute value
*/
//#define ZB_ZCL_DECLARE_TANKLEVEL_ATTRIB_LIST(                                     \
//    attr_list, present_value)                           \
//  ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list)                                        \
// // ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_ANALOG_INPUT_OUT_OF_SERVICE_ID, (out_of_service)) \
//  ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_ANALOG_INPUT_PRESENT_VALUE_ID, (present_value))   \
// // ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_ANALOG_INPUT_STATUS_FLAG_ID, (status_flag))       \
//  ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST
 
#define ZB_ZCL_DECLARE_TANKLEVEL_ATTRIB_LIST( attr_list, present_value, max_present_value, min_present_value, status_flag)                   \
    ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list)                                           \
    ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_ANALOG_INPUT_PRESENT_VALUE_ID, (present_value))      \
    ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_ANALOG_INPUT_MIN_PRESENT_VALUE_ID, (min_present_value))      \
    ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_ANALOG_INPUT_MAX_PRESENT_VALUE_ID, (max_present_value))      \
    ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_ANALOG_INPUT_STATUS_FLAG_ID, (status_flag))       \
    ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST

zb_void_t zb_zcl_analog_input_init_server(void);
zb_void_t zb_zcl_analog_input_init_client(void);
#define ZB_ZCL_CLUSTER_ID_ANALOG_INPUT_SERVER_ROLE_INIT zb_zcl_analog_input_init_server
#define ZB_ZCL_CLUSTER_ID_ANALOG_INPUT_CLIENT_ROLE_INIT zb_zcl_analog_input_init_client


/**
 *  @brief StatusFlag attribute values.
 *  @see ZCL spec 3.14.10.3.
 */

enum zb_zcl_analog_input_status_flag_value_e
{
  ZB_ZCL_ANALOG_INPUT_STATUS_FLAG_NORMAL    = 0x00,       /**< Normal (default) state. */
  ZB_ZCL_ANALOG_INPUT_STATUS_FLAG_IN_ALARM  = 0x01,       /**< In alarm bit. */
  ZB_ZCL_ANALOG_INPUT_STATUS_FLAG_FAULT     = 0x02,       /**< Fault bit. */
  ZB_ZCL_ANALOG_INPUT_STATUS_FLAG_OVERRIDEN = 0x04,       /**< Overriden bit. */
  ZB_ZCL_ANALOG_INPUT_STATUS_FLAG_OUT_OF_SERVICE = 0x08,  /**< Out of service bit. */
};





/** @brief Set normal operating mode
    @param ep - endpoint number
*/
#define ZB_ZCL_ANALOG_INPUT_SET_NORMAL_MODE(ep)                           \
{                                                                         \
  zb_uint8_t val;                                                         \
                                                                          \
  val = ZB_FALSE;                                                         \
  ZB_ZCL_SET_ATTRIBUTE(ep, ZB_ZCL_CLUSTER_ID_ANALOG_INPUT,                \
                       ZB_ZCL_CLUSTER_SERVER_ROLE,                        \
                       ZB_ZCL_ATTR_ANALOG_INPUT_OUT_OF_SERVICE_ID,        \
                       &val, ZB_FALSE);                                   \
                                                                          \
  val = ZB_ZCL_ANALOG_INPUT_STATUS_FLAG_NORMAL;                           \
  ZB_ZCL_SET_ATTRIBUTE(ep, ZB_ZCL_CLUSTER_ID_ANALOG_INPUT,                \
                       ZB_ZCL_CLUSTER_SERVER_ROLE,                        \
                       ZB_ZCL_ATTR_ANALOG_INPUT_STATUS_FLAG_ID,           \
                       &val, ZB_FALSE);                                   \
}

///** @brief Set Out of service operating mode
//    @param ep - endpoint number
//*/
#define ZB_ZCL_ANALOG_INPUT_SET_OUT_OF_SERVICE(ep)                                          \
{                                                                                           \
  zb_zcl_attr_t *attr_desc;                                                                 \
  zb_uint8_t val;                                                                           \
                                                                                            \
  val = ZB_TRUE;                                                                            \
  ZB_ZCL_SET_ATTRIBUTE(ep, ZB_ZCL_CLUSTER_ID_ANALOG_INPUT,                                  \
                       ZB_ZCL_CLUSTER_SERVER_ROLE,                                          \
                       ZB_ZCL_ATTR_ANALOG_INPUT_OUT_OF_SERVICE_ID,                          \
                       &val, ZB_FALSE);                                                     \
                                                                                            \
  attr_desc = zb_zcl_get_attr_desc_a(ep, ZB_ZCL_CLUSTER_ID_ANALOG_INPUT,                    \
                                     ZB_ZCL_CLUSTER_SERVER_ROLE,                            \
                                     ZB_ZCL_ATTR_ANALOG_INPUT_STATUS_FLAG_ID);              \
  if (attr_desc)                                                                            \
  {                                                                                         \
    val = *(zb_uint8_t*)attr_desc->data_p | ZB_ZCL_ANALOG_INPUT_STATUS_FLAG_OUT_OF_SERVICE; \
    ZB_ZCL_SET_ATTRIBUTE(ep, ZB_ZCL_CLUSTER_ID_ANALOG_INPUT,                                \
                         ZB_ZCL_CLUSTER_SERVER_ROLE,                                        \
                         ZB_ZCL_ATTR_ANALOG_INPUT_STATUS_FLAG_ID,                           \
                         &val, ZB_FALSE);                                                   \
  }                                                                                         \
}

///** @brief Set overriden operating mode
//   @param ep - endpoint number
//*/
#define ZB_ZCL_ANALOG_INPUT_SET_OVERRIDEN_MODE(ep)                                     \
{                                                                                      \
  zb_zcl_attr_t *attr_desc;                                                            \
  zb_uint8_t val;                                                                      \
                                                                                       \
  attr_desc = zb_zcl_get_attr_desc_a(ep, ZB_ZCL_CLUSTER_ID_ANALOG_INPUT,               \
                                     ZB_ZCL_CLUSTER_SERVER_ROLE,                       \
                         ZB_ZCL_ATTR_ANALOG_INPUT_STATUS_FLAG_ID);                     \
  if (attr_desc)                                                                       \
  {                                                                                    \
    val = *(zb_uint8_t*)attr_desc->data_p | ZB_ZCL_ANALOG_INPUT_STATUS_FLAG_OVERRIDEN; \
    ZB_ZCL_SET_ATTRIBUTE(ep, ZB_ZCL_CLUSTER_ID_ANALOG_INPUT,                           \
                         ZB_ZCL_CLUSTER_SERVER_ROLE,                                   \
                         ZB_ZCL_ATTR_ANALOG_INPUT_STATUS_FLAG_ID,                      \
                         &val, ZB_FALSE);                                              \
  }                                                                                    \
}



#endif /* ZB_ZCL_ANALOG_INPUT_H */

Parents Reply Children
No Data
Related