/**
*  @file simple_api.h
*
*  @brief  public methods for simple_api.c
*
* $Rev: 547 $
* $Author: dsmith, 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 SIMPLE_API_H
#define SIMPLE_API_H

#include "application_configuration.h"
#include "../HAL/hal_types.h"
#include "../HAL/hal_defs.h"

/* Device Info Constants*/
#define ZB_INFO_DEV_STATE                 0
#define ZB_INFO_IEEE_ADDR                 1
#define ZB_INFO_SHORT_ADDR                2
#define ZB_INFO_PARENT_SHORT_ADDR         3
#define ZB_INFO_PARENT_IEEE_ADDR          4
#define ZB_INFO_CHANNEL                   5
#define ZB_INFO_PAN_ID                    6
#define ZB_INFO_EXT_PAN_ID                7

/* SAPI SendDataRequest destinations*/
#define INVALID_NODE_ADDR                  0xFFFE
#define ZB_BINDING_ADDR                   INVALID_NODE_ADDR
#define ZB_BROADCAST_ADDR                 0xffff

/* SAPI Status Codes*/
#define ZB_ALREADY_IN_PROGRESS            0x20
#define ZB_TIMEOUT                        0x21
#define ZB_AF_FAILURE                     afStatus_FAILED
#define ZB_AF_MEM_FAIL                    afStatus_MEM_FAIL
#define ZB_AF_INVALID_PARAMETER           afStatus_INVALID_PARAMETER

/* Device types definitions ( from ZGlobals.h file )*/
#define ZG_DEVICETYPE_COORDINATOR         0x00
#define ZG_DEVICETYPE_ROUTER              0x01
#define ZG_DEVICETYPE_ENDDEVICE           0x02

/* Constants */
#define MT_SYS_RESET_IND  0x80     

/* The 5 LSB's of the 1st command field byte are for the subsystem. */
#define MT_SUBSYSTEM_MASK              0x1F
#define MT_SYS                         0x01
#define MT_SAPI                        0x06

/*ZNP Functions*/
void sapiRegisterApplication(struct applicationConfiguration ac);
void sapiRegisterGenericApplication();
void sapiStartApplication();
void setJoiningPermissions(unsigned int destination, unsigned char timeout);
void sendData(unsigned int destinationShortAddress, unsigned int clusterId, unsigned char* data, unsigned char dataLength);
void setallowbind(unsigned char timeout);
void binddevice(uint8 create, uint16 commandId, uint8 *pDestination);

/* ZNP Callback Functions*/
void BindConfirm();
void AllowBindConfirm(uint16 source);
void SendDataConfirm(uint8 handle, uint8 status);
void FindDeviceConfirm(uint8 searchType, uint8 searchKey, uint8 result);
void ReceiveDataIndication(uint16 source, uint16 command, uint16 len);

#endif
