#ifndef _BLV_ALL_DEV_INIT_H_
#define _BLV_ALL_DEV_INIT_H_


#include "stdint.h"
#include "BLV_Dev_Action.h"

#define DEVDATALEN  12

typedef uint8_t (*Dev_Data_Init_ptr)(CFG_Dev_AddP CfgDevAdd);							//定义传递参数为空，返回值为空的函数指针类型，用于所有设备信息初始化
//typedef void (*Dev_Data_Get_ptr)(void);								//定义传递参数为空，返回值为空的函数指针类型，用于所有设备信息得到

typedef struct    
{
	uint8_t DevType;											//枚举型的变量  所有支持的设备
	Dev_Data_Init_ptr DevNodeDataInit;  	          //设备节点内容  设备信息初始化，主要是 数据初始化 函数指针初始化  
	
}__attribute__ ((__packed__))Struct_Dev_Data_Get;													//配置类型与枚举型的变量的对应关系结构体

typedef enum
{
 ENUM_RS485_DEV_PRO_00,   //0号协议        //0
 ENUM_RS485_DEV_PRO_01,   //1号协议        //1
 ENUM_RS485_DEV_PRO_02,   //2号协议        //2
 ENUM_RS485_DEV_PRO_03,   //3号协议        //3
 ENUM_RS485_DEV_PRO_04,   //4号协议        //4
 ENUM_RS485_DEV_PRO_05,   //5号协议        //5
 ENUM_RS485_DEV_PRO_06,	  //6号协议        //6
 ENUM_RS485_DEV_PRO_07,   //7号协议        //7
 ENUM_RS485_DEV_PRO_08,   //8号协议        //8
 ENUM_RS485_DEV_PRO_09,   //9号协议        //9
 ENUM_RS485_DEV_PRO_10,   //10号协议       //10
 ENUM_RS485_DEV_PRO_11,   //11号协议       //11
 ENUM_RS485_DEV_PRO_12,		//12号协议       //12
 ENUM_RS485_DEV_PRO_13,   //13号协议       //13
 ENUM_RS485_DEV_PRO_14,   //14号协议       //14
 ENUM_RS485_DEV_PRO_15,   //15号协议       //15
 ENUM_RS485_DEV_PRO_16,   //16号协议       //16
 ENUM_RS485_DEV_PRO_17,   //17号协议       //17
 ENUM_RS485_DEV_PRO_18,   //18号协议       //18
 ENUM_RS485_DEV_PRO_19,   //19号协议       //19
// ENUM_RS485_DEV_PRO_20,   //当前协议总数的最大值          //20
	
}enum_RS485Protocol;                 //同类设备可以按照协议进行分类


/*************************************************************************************/
/*Logic 文件数据解析相关定义*/

#define Logic_FrameType_LogicInfo		0x01	//配置信息
#define Logic_FrameType_Global			0x02	//全局信息
#define Logic_FrameType_DeviceExist		0x03	//设备存在
#define Logic_FrameType_DeviceAction	0x04	//设备动作
#define Logic_FrameType_VoiceMap		0x05	//语音映射信息

#define Logic_FrameType_DevCheckMap     0x07    //设备巡检回路信息

#define Logic_FrameType_VCCondition     0x08    //无卡取电条件信息
#define Logic_FrameType_VCPortInfor     0x09    //无卡取电映射端口信息
#define Logic_FrameType_VCProperty      0x0B    //无卡取电设备属性

#define Logic_FrameType_ColorTempMap	0x0A	//色温调节端口映射

typedef enum{
	Logic_D_Hear_L,
	Logic_D_Hear_H,
	Logic_D_Len_L,
	Logic_D_Len_H,
	Logic_D_CRC_L,
	Logic_D_CRC_H,
	Logic_D_Frame_L,
	Logic_D_Frame_H,
	Logic_D_FrameNum_L,
	Logic_D_FrameNum_H,
	Logic_D_FrameType,
	Logic_D_Para,
}LOGIC_INFO_E;

#define LogicFile_DeviceInfo_InputSet	79			//逻辑文件中设备存在数据信息里的输入设置下标  2022-05-30 保留字节从32->64

typedef struct {
	uint8_t 	type;			//设备类型
	uint8_t 	addr;			//设备地址
	uint8_t 	port;			//设备端口
	uint32_t 	baud;			//设备波特率
	uint8_t 	version;		//设备协议版本
	uint8_t 	retry;			//通讯重发次数
	uint16_t 	writ_time;		//通讯等待时间
	uint8_t     ipaddr[4];      //域控中控设备属性
	uint8_t     parent_type;    //父设备类型
	uint8_t     parent_addr;    //父设备地址
	uint8_t     parent_port;    //父设备端口
	uint8_t     lin[5];         //无卡断电检测回路
	uint8_t     priproperty[10];//私有属性 
	uint8_t 	remain[42];		//保留字节
	uint16_t 	input_num;		//输入回路
	uint16_t 	output_num;		//输出回路
}__attribute__ ((__packed__))LOGICFILE_DEVICE_INFO;	//逻辑文件中 - 设备存在信息结构

typedef struct{
	uint64_t DevActionOutFlag:1;  	//动作输出使能 
	uint64_t RoomState:3; 			//房态  
	uint64_t EleCtrlFlag:1; 		//取电服务控制
	uint64_t EleState:3;         	//取电状态
	uint64_t DndState:3;        	//勿扰状态 
	uint64_t CleanState:3;       	//清理状态
	uint64_t CallState:3;       	//呼叫状态 
	uint64_t WashState:3; 			//洗衣状态 
	uint64_t CheckOutState:3; 		//退房状态
	uint64_t WaitState:3; 			//稍后状态
	uint64_t SosState:3; 			//SOS状态 
	uint64_t RentState:3; 			//预约待租状态 
	uint64_t LockState:3; 			//开锁状态 
	uint64_t LuggageState:3; 		//行李状态 
	uint64_t StrongState:3; 		//保险箱状态 
	uint64_t DoorState:3; 			//门磁状态 
	uint64_t WarningState:3; 		//提示音状态 
	uint64_t BacklightState:3;		//背光状态
	uint64_t SeasonState:3; 		//季节    
	uint64_t TimeState:3; 			//时间 
	uint64_t NeightState:3;  		//起夜状态 
	uint64_t RcuLockState:3; 		//1锁定  0正常
	uint64_t Reserve1:2; 			//保留2位
}__attribute__ ((__packed__))LOGIC_ACTIVE_CONDITION_G;	//逻辑文件中 - 设备条件结构

typedef struct {
	uint8_t type;			//动作设备类型
	uint8_t addr;			//动作设备地址
	uint16_t loop;			//动作设备回路
	uint8_t execute;		//设备执行方式
	uint8_t content;		//设备执行内容
	uint8_t delay_time;		//执行延时时间
	uint8_t delay_unit;		//执行延时时间单位
}__attribute__ ((__packed__))LOGIC_DEVICE_ACTIVE_G;		//逻辑动作数据结构

#if C8_TYPE

#define BusDevice_NumMax		10	//BUS设备上限
#define PollingDevice_NumMax	15	//轮询设备上限
#define ActiveDevice_NumMax		20	//主动设备上限
#define NorDevice_NumMax		34	//普通设备上限     

#else

#define BusDevice_NumMax		10	//BUS设备上限
#define PollingDevice_NumMax	20	//轮询设备上限
#define ActiveDevice_NumMax		34	//主动设备上限
#define NorDevice_NumMax		15	//普通设备上限      2022-09-23  普通设备上限增加5个，主动设备上限减少5个。

#endif

typedef struct {
	uint8_t 	Bus_device_num;
	uint8_t 	Active_device_num;
	uint8_t 	Polling_device_num;
	uint8_t 	Nor_device_num;
	
	uint16_t 	device_num;
	uint16_t 	active_num;
	uint16_t 	voicemap_num;
	uint16_t    devcheckmap_num;            //2023-11-27
	
	uint32_t 	Bus_device_addr[BusDevice_NumMax];
	uint32_t	Polling_device_addr[PollingDevice_NumMax];
	uint32_t	Active_device_addr[ActiveDevice_NumMax];
	uint32_t	Nor_device_addr[NorDevice_NumMax];
	
	uint32_t 	ColorTemp_Map_Addr;			//色温映射地址
}__attribute__ ((__packed__))LOGICFILE_Content_Of_Statistical;	//逻辑文件统计数据使用


/*************************************************************************************/

void BLV_Dev_Init(void);

void BlwMap_Dev_Add(uint8_t *DevBuf, uint8_t DevNum);
void BlwMap_AllDev_Ctrl(uint8_t *DevCtrl);
uint16_t MQTT_DevList_Get(uint8_t* buf);

#endif


                        





