/**
* @file application_configuration.h
* 
*  @brief  public methods for application_configuration.c
*
* $Rev: 1 $
* $Author: Morten & Suyash $
* $Date: 2010-05-27 17:11:30 -0700 (Thu, 27 May 2010) $
*
* YOU ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE PROVIDED “AS IS” WITHOUT WARRANTY 
* OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, 
* TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL TEXAS INSTRUMENTS 
* OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, 
* BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
* INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, 
* LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY 
* CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
*/

#ifndef APPLICATION_CONFIGURATION_H
#define APPLICATION_CONFIGURATION_H

/*Define the Sensor Monitor Demo Application endpoints and application profile identifier contants*/
#define APP_PROFILE_ID                   0xD7D7
#define APP_PROFILE_ID_LSB               0x10
#define APP_PROFILE_ID_MSB               0x0F

#define SRCE_REPORT_ID_LSB                1
#define SRCE_REPORT_ID_MSB                0
#define SRCE_REPORT_ID                    0x0001
#define SRCE_REPORT_SZ                    4
#define SRCE_REPORT_TEMP                  0
#define SRCE_REPORT_BUSV                  1
#define SRCE_REPORT_PARENT_ADDR           2

#define SINK_ENDPOINT_ID                  2
#define SINK_DEVICE_ID                       0x4567 
#define SINK_DEVICE_VERSION               1
#define SINK_LATENCY                      0
#define SINK_CLUSTER_IN_CNT               1
#define SINK_CLUSTER_OUT_CNT              0

#define SRCE_ENDPOINT_ID                  1
#define SRCE_DEVICE_ID                       0x4567
#define SRCE_DEVICE_VERSION               1
#define SRCE_LATENCY                      0
#define SRCE_CLUSTER_IN_CNT               0
#define SRCE_CLUSTER_OUT_CNT              1

/*Not used in sensor monitor demo code */
/*default values used when creating applicationConfigurations in Simple API or AFZDO*/
#define DEFAULT_ENDPOINT        0xD7 
#define DEFAULT_PROFILE_ID      0xD7D7
#define DEVICE_ID               0x4567
#define DEVICE_VERSION          0x89

/*Values for latencyRequested field of struct applicationConfiguration. Not used in Simple API.*/
#define LATENCY_NORMAL          0
#define LATENCY_FAST_BEACONS    1
#define LATENCY_SLOW_BEACONS    2

/* Bit mask for ZNPEvtFlags.*/
#define ZNP_EVT_NONE         0x0000
#define ZNP_START_CNF        0x0001
#define ZNP_BIND_CNF         0x0002
#define ZNP_ALLOW_BIND_CNF   0x0004
#define ZNP_SEND_DATA_CNF    0x0008
#define ZNP_READ_CFG_RSP     0x0010
#define ZNP_FIND_DEV_CNF     0x0020
#define ZNP_DEV_INFO_RSP     0x0040
#define ZNP_RCV_DATA_IND     0x0080
#define ZNP_SYS_RESET_IND    0x8000

/*Bit mask for ZNPIndFlags.*/
#define ZNP_BIND_SUCCESS     0x0001
#define ZNP_SEND_SUCCESS     0x0002

/*To test network connection status in sensor monitor demo application*/
#define ZNP_NWK_CONN (                      \
  (ZNPNwkState == DEV_END_DEVICE_UNAUTH) || \
  (ZNPNwkState == DEV_END_DEVICE)        || \
  (ZNPNwkState == DEV_ROUTER)            || \
  (ZNPNwkState == DEV_ZB_COORD)             \
)
#define ZNP_NWK_RTR (                       \
  (ZNPNwkState == DEV_ROUTER)            || \
  (ZNPNwkState == DEV_ZB_COORD)             \
)
#define ZNP_NWK_COOR  (ZNPNwkState == DEV_ZB_COORD)


/** This is a set of application configuration parameters. These parameters affect the way our particular Zigbee Application will behave. */
struct applicationConfiguration
{
  /** The Zigbee Endpoint. Simple API only supports one endpoint. Must use the same value of endpoint for all devices in the network.*/
  unsigned char endPoint;
  
  /** The Application Profile ID as assigned by the Zigbee Association. Must use the same application profile for all devices in the network. */
  unsigned int profileId;
  
  /** A user-defined device ID field. Not used in Simple API, but when using AFZDO API a remote device can query for this using the ZDO_SIMPLE_DESC_REQ command. */
  unsigned int deviceId;
  
  /** A user-defined device ID field. Not used in Simple API, but when using AFZDO API a remote device can query for this using the ZDO_SIMPLE_DESC_REQ command. */ 
  unsigned char deviceVersion;
    
  /** A very simple Quality of Service (QoS) setting. Must be LATENCY_NORMAL, LATENCY_FAST_BEACONS, or LATENCY_SLOW_BEACONS. Not used in Simple API.*/
  unsigned char latencyRequested;
  
#define MAX_BINDING_CLUSTERS 32  /**< Maximum number of clusters available for binding */
  
  /** Number of Input Clusters for Binding. If not using binding then set to zero.*/
  unsigned char numberOfBindingInputClusters;

  /** List of Input Clusters for Binding. If not using binding then this does not apply. To allow another device to bind to this device, must use ZB_ALLOW_BIND on this device and must use ZB_BIND_DEVICE on the other device. */  
  unsigned int bindingInputClusters[MAX_BINDING_CLUSTERS];
  
  /** Number of Output Clusters for Binding. If not using binding then set to zero.*/  
  unsigned char numberOfBindingOutputClusters;

  /** List of Output Clusters for Binding. If not using binding then this does not apply. To bind to another device, that device must use ZB_ALLOW_BIND and this device must use ZB_BIND_DEVICE to create a binding. */    
  unsigned int bindingOutputClusters[MAX_BINDING_CLUSTERS];
};
struct applicationConfiguration sinkEP();
struct applicationConfiguration srceEP();


#define APP_BTN_INTERVAL                  2      /* Count button presses in a 2-second interval. */
#define APP_BLINK_LEDS                    TRUE  /* Turn LED status display on or off.*/
#define APP_BLINK_INTERVAL                1      /* Blink at 1-Hz.*/
#define APP_BLINK_ON_TIME                 1      /* LED on for 1 msec is visible.*/

/* This timeout for attempting to join must be greatly lengthened as channels are added to the
 * ZNP_NV_CHANLIST in sample_app.cfg.
 * It is a trial and error empirical process to find the right setting according to the number of
 * channels to be scanned and the channel access availability on each of those channels.
 */
#define APP_JOIN_TIME                     10      /*  6 secs to attempt to join.*/
#define APP_JOIN_WAIT                     20     /* 30 secs to sleep before re-attempt to join.*/
#define APP_BIND_TIME                     10     /* 10 secs to attempt to bind.*/
#define APP_BIND_WAIT                     20     /* 30 seconds = Effective time between bind req's , device first sends a bind req, wait for 10 sec for bind confirm, if not recvd sleeps for 20 secs and retires. Effective wait time between bind req = 30 seconds*/
#define APP_REJOIN_TRIGER_INTERVAL        1      /*rejoin process will trigger after 2 seconds when join fail was recongnized*/

#define APP_PMT_BIND                      0xFF   /* Allow binding indefinitely.*/
#define APP_DENY_BIND                     0x00   /* Dis-allow binding indefinitely.*/
#define APP_PMT_JOIN                      0xFF   /* Allow joining indefinitely.*/
#define APP_DENY_JOIN                     0x00   /* Dis-allow joining indefinitely.*/

#define APP_REPORT_INTERVAL               10     /* 10 secs between OTA reports.*/  
#define APP_REPORT_RETRY                  2      /*  2 secs between retries when no ack received.*/
#define APP_RETRY_CNT                     3      /* Number of retry attempts.*/
#define APP_DATA_CNF                      TRUE  /* Request APP-layer data confirmation.*/

#if APP_DATA_CNF
#define APP_POLL_INTERVAL                 0 
#define APP_RESPONSE_POLL                 100
#else
#define APP_POLL_INTERVAL                 0
#define APP_RESPONSE_POLL                 0
#endif

#define APP_STAT_LED                      0
#define APP_DATA_LED                      1

/* All devices besides the Coordinator-Sink are Sources. */
#define APP_SRCE  ((appFlags & appSinkingF) == 0)

/*channel for network operation*/
#define DEFAULT_CHANNEL 11   






















#endif
