#ifndef __IKONKE_MODULE_DEFINE_H_____________________________
#define __IKONKE_MODULE_DEFINE_H_____________________________

#include "stdint.h"

// choose the type of equipment, ZC(Coordinator), ZR(Router), ZED(End Device).
#define Z30_DEVICE_ZC							(0)
#define Z30_DEVICE_ZR							(1)
#define Z30_DEVICE_ZED							(2)
#define Z30_DEVICE_ZED_SLEEPY					(3)

#define Z30_DEVICE_DTYPE						(Z30_DEVICE_ZR)
//是否需要OTA
#define Z30_DEVICE_OTA_ENABLE					true

//产测总开关， 是否有老化或单板和整机测试
#define Z30_DEVICE_FACTORY_TEST_ENABLE			true
// 定义是否需要老化，目前一般路由设备需要
#define Z30_DEVICE_AGING_ENABLE					false
//单板测试，目前一般是休眠设备需要
#define Z30_DEVICE_SINGLE_BOARD_ENABLE			false
//整机测试， 目前一般是休眠设备需要
#define Z30_DEVICE_FULL_DEVICE_ENBALE			false

//sleepy device battery define, used to implement rejoin mechanism, different battery different rejoin time
#define BATTERY_LARGE_CAPCITY					1
#define BATTERY_SMALL_CAPCITY					2
//定义休眠设备电池类型
#define SLEEPY_DEVICE_BATTERY_TYPE         	 	BATTERY_LARGE_CAPCITY

#if SLEEPY_DEVICE_BATTERY_TYPE == BATTERY_LARGE_CAPCITY
#define SHORT_POLL_TIME_AFTER_JOIN_NWK_S		(30)
#elif
#define SHORT_POLL_TIME_AFTER_JOIN_NWK_S		(15)
#endif

//休眠设备是否是控制设备， 比如门锁,暂时未使用
#define SLEEPY_DEVICE_CONTROL_ENABEL			true

#if SLEEPY_DEVICE_CONTROL_ENABEL
#define SHORT_POLL_WAKE_TIME_S	(30)
#else
#define SHORT_POLL_WAKE_TIME_S	(6)
#endif

// Real time IO operation, no optimization!!!
#define _IO										volatile

#define CLUSTER_BASIC_ID							0X0000	// Basic Cluster用于获取子设备基本信息
#define CLUSTER_POWER_ID							0X0001	// 电量
#define CLUSTER_IDENTIFY_ID							0X0003	// Identify
#define CLUSTER_GROUPS_ID							0X0004	// Groups
#define CLUSTER_SCENES_ID							0X0005	// Scenes
#define CLUSTER_ONOFF_ID							0X0006	// 开关
#define CLUSTER_LEVEL_CONTROL_ID					0X0008	// Level Control
#define CLUSTER_IAS_ZONE_ID							0X0500	// IAS Zone(安防探测设备)
#define CLUSTER_IAS_WD_ID							0X0502	// IAS WD(安防报警设备)
#define CLUSTER_TEMP_ID								0X0402	// 温度
#define CLUSTER_HUMI_ID								0X0405	// 湿度
#define CLUSTER_WINDOW_COVERING_ID					0X0102	// 窗帘
#define CLUSTER_ELECTRICAL_MEASUREMENT_ID			0X0B04	// 电气测量
#define CLUSTER_OPTTUNNEL_ID						0XFCC0	// 自定义Cluster-0XFC01，用于实现私有协议
#define CLUSTER_MULTI_CONTROL_ON_OFF_ID				0XFCC6	// 自定义，用于实现ON-OFF多控,只用于绑定表是否多控判断
#define CLUSTER_MULTI_CONTROL_WINDOW_COVERING_OPTTUNNEL_ID	0XFCC7	// 自定义Cluster， 用于实现window-covering多控
#define CLUSTER_UNKNOW								0XFFFF

#define ATTRIBUTE_UNKNOW							0XFFFF

//未知的GPIO引脚定义
#define	PORT_UNKNOW									0xFF
#define PIN_UNKNOW									0XFF

//串口通信协议OPCODE
#define UART_MSG_QUERY_INFO_OPCODE					0x0000
#define UART_MSG_WRITE_INSTALL_CODE_OPCODE			0x0001
#define UART_MSG_READ_INSTALL_CODE_OPCODE			0x0002
#define UART_MSG_READ_DEVICE_SNAP_OPCODE			0x0010
#define UART_MSG_JOIN_NWK_REQUEST_OPCODE			0x0100
#define UART_MSG_LEAVE_NWK_REQUEST_OPCODE			0x0101
#define UART_MSG_QUERY_NWK_STATUS_REQUEST_OPCODE	0x0102
#define UART_MSG_NWK_STATUS_NOTIFY_OPCODE			0x0103
#define UART_MSG_READ_ATTRIBUTE_REQUEST_OPCODE		0x0104
#define UART_MSG_WRITE_ATTRIBUTE_REQUEST_OPCODE		0x0105
#define UART_MSG_ZCL_COMMAND_REQUEST_OPCODE			0x0106
#define UART_MSG_BIND_REQUEST_OPCODE				0x0110
#define UART_MSG_GATEWAY_NWK_CHANNEL_ONOFF_OPCODE	0x00FC
#define UART_MSG_PRIVATE_PROTOCOL_CONTROL_CHILD_DEVICE_START_OPCODE	0xF000
#define UART_MSG_PRIVATE_PROTOCOL_CONTROL_CHILD_DEVICE_END_OPCODE	0xF0FF
#define UART_MSG_TTS_OPCODE							0xF100

//factory test message opcode
#define UART_MSG_QUERY_DEVICE_INFO_OPCODE			0xED01
#define UART_MSG_CONFIG_DEVICE_SLEEP_OPCODE			0xED02
#define UART_MSG_EXIT_FACTORY_TEST_OPCODE			0xED04
#define	UART_MSG_QUERY_FACTORY_INFO_OPCODE			0xED05

#define UART_MSG_READ_MAC_REQUEST_OPCODE			0x0120
#define UART_MSG_GPIO_TEST_OPCODE					0xED10
#define UART_MSG_READ_RSSI_REQUEST_OPCODE			0xED12

//offline voice panel
#define UART_MSG_HOST_SNAP_REQUEST_OPCODE			0x1000
#define UART_MSG_CTRL_HOST_ONOFF_OPCODE				0x1001  //zigbee module control panel
#define UART_MSG_HOST_ONOFF_NOTIFY_OPCODE			0x1002 //panel onoff status changed notify zigbee
#define UART_MSG_HOST_TRIGGER_SCENE_NOTIFY_OPCODE	0x1003	//pannel recall scene notify zigbees
#define UART_MSG_KEY_LIGHT_SCENE_TRANSFORM_OPCODE	0x1004
#define UART_MSG_TIME_SET_OPCODE					0x1005
#define UART_MSG_TIME_GET_OPCODE					0x1006
#define UART_MSG_DEVICE_OPERATOR_OPCODE				0x1007
#define UART_MSG_FILE_UPDATE_NOTIFY_OPCODE			0x1008
#define UART_MSG_FILE_DATA_REQUEST_OPCODE			0x1009
#define UART_MSG_FILE_UPDATE_STATUS_NOTIFY			0x100A


 //bangde human body sensor
#define UART_MSG_BODY_TRIGGER_START_REPORT_OPCODE	0xED03
//bangde sos button
#define UART_MSG_SOS_REPORT_OPCODE					0xED03
//bangde scene button
#define UART_MSG_BUTTON_SCENE_REPORT_OPCODE			0xED03
//bangde environment sensor
#define UART_MSG_QUERY_TEMP_HUMI_INFO_OPCODE		0xED03
//bangde door sensor
#define UART_MSG_BUTTON_ONOFF_REPORT_OPCODE			0xED03

//offline voice panel
//define opcode for private cluster
#define NWK_CHANNEL_ONOFF							(uint8_t)(UART_MSG_GATEWAY_NWK_CHANNEL_ONOFF_OPCODE)
#define SNAP_INFO    								(uint8_t)(UART_MSG_HOST_SNAP_REQUEST_OPCODE)
//#define ONOFF_CONTROL								(uint8_t)(UART_MSG_CTRL_HOST_ONOFF_OPCODE)
#define SCENE_TRGGER								(uint8_t)(UART_MSG_HOST_TRIGGER_SCENE_NOTIFY_OPCODE)
#define KEY_FUNCTION								(uint8_t)(UART_MSG_KEY_LIGHT_SCENE_TRANSFORM_OPCODE)
#define TIME_SET									(uint8_t)(UART_MSG_TIME_SET_OPCODE)
#define TIME_GET									(uint8_t)(UART_MSG_TIME_GET_OPCODE)
#define DEVICE_OPT									(uint8_t)(UART_MSG_DEVICE_OPERATOR_OPCODE)
#define FILE_UPDATE_NOTIFY							(uint8_t)(UART_MSG_FILE_UPDATE_NOTIFY_OPCODE)
#define FILE_DATA_REQUEST							(uint8_t)(UART_MSG_FILE_DATA_REQUEST_OPCODE )
#define FILE_STATUS_STATUS							(uint8_t)(UART_MSG_FILE_UPDATE_STATUS_NOTIFY)

//other child device opcode define


typedef enum {
	ERR_OK=0x00,
	ERR_EXIST=0x01,
	ERR_FORMAT=0x02,
	ERR_NOT_EXPECTED=0x03,
	ERR_WRITE_FAILED=0x04,
	ERR_READ_WRITE_TIMEOUT=0x05,
	ERR_NOT_EXIST=0x06,
	ERR_UNKNOW=0xFF,
}ERR_RET_E;

typedef enum {
	CMD_TYPE_GATEWAY_NWK_CHANNEL_ONOFF=0x00,
	CMD_TYPE_DIRECT,
//	CMD_TYPE_QUERY,
//	CMD_TYPE_ACTION,
	CMD_TYPE_VOICE_RECALL_SCENE,
	CMD_TYPE_GET_TIME,
	CMD_TYPE_SET_TIME,
	CMD_TYPE_KEY_FUNTION,
	CMD_TYPE_OPERATOR_CHILD_DEVICE_BY_GATEWAY,
	CMD_TYPE_FILE_UPDATE_NOTIFY,
	CMD_TYPE_GET_FILE_DATA,
	CMD_TYPE_NOTIFY_FILE_STATUS,
}CMD_TYPE_E;

typedef enum kk_error_type {
	KET_OK = 0,							// 正常（成功）

	KET_FAILED = -1,					// 失败
	KET_ERR_TIMEOUT = -2,				// 操作超时
	KET_ERR_MALLOC_FAILED = -3,			// malloc失败
	KET_NO_RESPONSE = -4,				//不需要ack

	KET_ERR_INVALID_FD = -100,			// 无效的FD
	KET_ERR_OPEN_FAIL = -101,			// 文件/socket等打开失败
	KET_ERR_CLOSE_FAILED = -102,		// 文件/socket等关闭失败
	KET_ERR_READ_FAILED = -103,			// 文件/socket等读取失败
	KET_ERR_WRITE_FAILED = -104,		// 文件/socket等写入失败

	KET_ERR_INVALID_POINTER = -200,		// 无效指针
	KET_ERR_INVALID_PARAM = -201,		// 无效参数

	KET_ERR_CMD_FORMAT = -301,			// 指令格式错误
	KET_ERR_CMD_PARSE_FAILED = -302,	// 指令解析错误
	KET_ERR_CMD_INVALID = -303,			// 指令无效
	KET_ERR_CMD_FAILED = -304,			// 指令操作失败

	KET_ERR_NON_EXIST = -900,			// 不存在
	KET_ERR_NO_PERMISSIONS = -901,		// 没有权限
	KET_ERR_PROCESS_ABORT = -902,		// 异常中断
	KET_ERR_NOT_READY = -903,			// not ready
	KET_ERR_OPRATE_ILLEGAL = -904,		// 非法操作
	KET_ERR_CRC_WRONG = -905,			// 校验错误
	KET_ERR_CONTENT_MISMATCH = -906,	// 内容不匹配
	KET_ERR_INSUFFICIENT_SPACE = -907,	// 空间不足
	KET_ERR_OPRATE_FAILED = -908,		// 操作失败
	KET_ERR_OPRATE_IN_PROGRESS = -908,	// 操作进行中
	KET_ERR_UNKNOW = -999,				// 位置错误
}kk_err_t;

typedef enum { Z3D_COORDINATOR = 0, Z3D_ROUTER, Z3D_ENDDEVICE }Z3DevTypeEm;

typedef void (*pFUNC_VOID)(void *);

typedef struct tag_common_opt_callback_st {
	pFUNC_VOID pfunc;
	void *param;
}CommonOptCallbackSt;

#endif
