#ifndef _INCLUDES_H_
#define _INCLUDES_H_

#include "CH57x_common.h"		//CH57X 库包含头文件
#include "usart.h"
#include "key.h"
#include "dwg.h"
#include "SPI_SRAM.h"
#include "flash.h"
#include "rtc.h"
#include "rw_logging.h"
#include "check_fun.h"
#include "DBG.h"
#include "SRAM_Variable_Address.h"
#include "BLV_Authorize.h"
#include "Log_api.h"


/**/
#include <cm_backtrace.h>
/*网络*/
#include "net.h"
#include "DNS.h"
#include "md5.h"
#include "BLV_NET_Function.h"
#include "Udp_Internal_Protocol.h"
#include "mqtt.h"
#include "aLiYun.h"
/*485文件*/
#include "BLV_Device_Control.h"
#include "BLV_485_Protocol.h"
#include "PC_DeviceTest_Fun.h"

#include "BLV_485_Dev_Touch_SwiFun.h"		//T1触摸开关驱动
#include "BLV_485_Dev_TempFun.h"			//T1温控器驱动
#include "BLV_485_Dev_CardFun.h"			//T1插卡取电驱动
#include "BLV_BUS_Dev_C5IOFun.h"			//BLV_Cx IO驱动程序
#include "BLV_BUS_Dev_C5MusicFun.h"			//BLV_Cx Music驱动程序
#include "BLV_485_Dev_IrSendFun.h"			//红外转发驱动
#include "BLV_485_Dev_C7TFun.h"				//C7T驱动程序
#include "BLV_485_Dev_PWMFun.h"				//4路PWM调光驱动
#include "BLV_485_Dev_A9RELAYFun.h"			//A9继电器扩展驱动
#include "BLV_485_Dev_XiaoBaoFun.h"			//小宝语音驱动
#include "BLV_485_Dev_WeixinLockFun.h"		//RF 微信锁驱动
#include "BLV_BUS_Dev_C12DimmingFun.h" 		//BLV_Cx Dimming驱动程序
#include "BLV_485_Dev_RGB_Light_BeltFun.h"	//RBG灯带驱动
#include "BLV_485_Dev_TempT1Fun.h"			//T1温控器驱动 - 新版
#include "BLV_485_Dev_MusicFun.h"      //背景音乐驱动总表
#include "BLV_485_Dev_PirFun.h"				//485红外驱动
#include "BLV_485_Dev_LEDFun.h"				//调光驱动总表
#include "BLV_485_Dev_TimeFun.h"      //时间设备驱动
#include "BLV_485_Dev_IN_CH6.h"
#include "Blv_485_Dev_CurtainFun.h"   //485窗帘驱动
#include "BLV_485_Dev_AirDetectFun.h"
#include "BLV_485_Dev_AirRevealFun.h"
#include "BLV_485_Dev_CardStateFun.h"
#include "BLV_485_Dev_FreshAirFun.h"
#include "BLV_485_Dev_FloorHeatFun.h"
#include "BLV_TempPrompt_Action.h"
#include "BLV_Bus_Dev_PB20Fun.h"
#include "BLV_485_Dev_PB20_LED_Fun.h"
#include "BLV_485_Dev_PB20_Strip_Fun.h"
#include "BLV_485_Dev_PB20_Relay_Fun.h"
#include "BLV_485_Dev_LCDFun.h"
#include "BLV_Nor_Dev_NoCard.h"
#include "BLV_Nor_Dev_VirtualCard.h"
#include "BLV_485_Dev_Rotary_SwitchFun.h"
#include "BLV_Nor_Dev_VirtualTimeFun.h"
#include "BLV_Nor_Dev_ColorTemp.h"
#include "BLV_485_Dev_BinShen_Curtain.h"
#include "BLV_485_Dev_BLE_Music.h"
#include "BLV_Nor_Dev_CarbonFun.h"
#include "BLV_Nor_Dev_Scene_Restore.h"
#include "BLV_Nor_Dev_GlobalSet.h"
#include "BLV_485_Dev_EnergyMonitor.h"
#include "BLV_Nor_Dev_ServiceFun.h"
#include "BLV_485_Dev_ShangJingTianIrSendFun.h"

#include "BLV_Dev_Action.h"
#include "BLV_All_Dev_Init.h"
#include "BLV_Nor_DevFun.h"
#include "BLV_Logic_Edit.h"
#include "mqtt.h"
#include "aLiYun.h"
#include "BLV_485_Dev_YangGeLockFun.h"
//#if UDPServer_Internal_Flag

//#include "UDPServer_Internal_Protocol.h"	//新服务器通讯相关

//#endif

#if (LOGIC_FILE_EN==0x00)
/*项目逻辑开始头文件*/
#include "BLV_Logic_FangFeiYuan_Edit.h"
#include "BLV_Logic_NanBuGaoErFu_Edit.h"
#include "BLV_Logic_JinJiangDuCheng_Edit.h"
#include "BLV_Logic_Lize_Edit.h"
#include "BLV_Logic_GaoXiongHanLai_Edit.h"
#include "BLV_Logic_LuZhou_Edit.h"
#include "BLV_Logic_YiWuRuiGe_Edit.h"
#include "BLV_Logic_ChengDuZAMX_Edit.h"
#include "BLV_Logic_MingYueSuitRoom_Edit.h"
#include "BLV_Logic_ChaoHu_Edit.h"
#include "BLV_Logic_BaiYin_Edit.h"
#include "BLV_Logic_KeChuang_Edit.h"
#include "BLV_Logic_C12ZhanTing_Edit.h"
#include "BLV_Logic_ShiJiYuan_Edit.h"
#include "BLV_Logic_FuLaiHuaKai_Edit.h"
#include "BLV_Logic_HaoTian_Edit.h"
#include "BLV_Logic_ShangShangZuo_Edit.h"
#include "BLV_Logic_ChangPingChaoMan_Edit.h"
#include "BLV_Logic_ZGZMAX_Edit.h"
#include "BLV_Logic_DianJing_Edit.h"
#include "BLV_Logic_GuiZhouBanShiChu_Edit.h"
#include "BLV_Logic_TianFengDengShi_Edit.h"
#include "BLV_Logic_C5ChuChang_Edit.h"
#include "BLV_Logic_LanYueDianJing_Edit.h"
#include "BLV_Logic_ShuYu_Edit.h"
#include "BLV_Logic_KuErLe_Edit.h"
#include "BLV_Logic_HuiZhouChaoMan_Edit.h"
#include "BLV_Logic_WuYue_Edit.h"   
#include "BLV_Logic_FeiJieDianJing_Edit.h"
#include "BLV_Logic_GuangZhouChaoMan_Edit.h"
#include "BLV_Logic_TianQuanHuiGuan_Edit.h"
#include "BLV_Logic_ChaoManNanHai_Edit.h"
#include "BLV_Logic_C12ZhanXiang_Edit.h"
#include "BLV_Logic_LiuYueLiu_Edit.h"
#include "BLV_Logic_TianJinZMAX_Edit.h"
#include "BLV_Logic_YunDuan_Edit.h"
#include "BLV_Logic_C5ZhanBan_Edit.h"
#include "BLV_Logic_QingHai_Edit.h"
#include "BLV_Logic_WYN_Edit.h"
#include "BLV_Logic_WenDeMu_Edit.h"
#include "BLV_Logic_WangYu_Edit.h"
#include "BLV_Logic_QDgaizao_Edit.h"
#include "BLV_Logic_WuHuDianJing_Edit.h"
#include "BLV_Logic_LiangZhi_Edit.h"
#include "BLV_Logic_ChangShaWYN_Edit.h"
#include "BLV_Logic_ZhuJiang_Edit.h"
#include "BLV_Logic_BeijingErHuan_Edit.h"  
#include "BLV_Logic_BaiSeYueZi_Edit.h"
#include "BLV_Logic_YanCheng_Edit.h"
#include "BLV_Logic_MaYi_Edit.h"
#include "BLV_Logic_XinShengYue_Edit.h"
#include "BLV_Logic_KaiYuan_Edit.h"
#include "BLV_Logic_ChunLong_Edit.h"
#include "BLV_Logic_HaiLin_Edit.h"
#include "BLV_Logic_PuHua_Edit.h"
#include "BLV_Logic_HaErBin_Edit.h"
#include "BLV_Logic_JiaYi_Edit.h"
#include "BLV_Logic_LongTing_Edit.h"
#include "BLV_Logic_XuZhou_Edit.h"
#include "BLV_Logic_HeGe_Edit.h"
#include "BLV_Logic_LiFeng_Edit.h"
#include "BLV_Logic_ShenZhenWYN_Edit.h"
#include "BLV_Logic_ZhuHaoZB_Edit.h"  
#include "BLV_Logic_GSZTC9_Edit.h"
#include "BLV_Logic_JiaoZuoHSBD_Edit.h" 
#include "BLV_Logic_ZhanXiangC12_Edit.h"
#include "BLV_Logic_YuYaoChaoMan_Edit.h"  
#include "BLV_Logic_WanZaiWYN_Edit.h"
#include "BLV_Logic_C5Modle_Edit.h"
#include "BLV_Logic_GuanTaoLF_Edit.h" 
#include "BLV_Logic_DaZhouYR_Edit.h" 
#include "BLV_Logic_C12PadZX_Edit.h"
#include "BLV_Logic_WYNHaoMian_Edit.h"
#include "BLV_Logic_TuoHaiMY_Edit.h"  
#include "BLV_Logic_AnQiGao_Edit.h"
#include "BLV_Logic_JinJiangHengHe_Edit.h" 
#include "BLV_Logic_XinChao_Edit.h"
#include "BLV_Logic_JiAn_Edit.h"
#include "BLV_Logic_XiYuan_Edit.h"
#include "BLV_Logic_HongHao_Edit.h"
#include "BLV_Logic_YiYou_Edit.h"
#include "BLV_Logic_WaiMaoC12_Edit.h"  
#include "BLV_Logic_HaiLin_Edit.h"
#include "BLV_Logic_QiangDianC9_Edit.h"
#include "BLV_Logic_ChiFeng_Edit.h" 
#include "BLV_Logic_OuChuangYuan_Edit.h"
#include "BLV_Logic_YuCiWYN_Edit.h"
#include "BLV_Logic_MiDu_Edit.h"
#include "BLV_Logic_TianJinZMAXC12_Edit.h" 
#include "BLV_Logic_YunYingQJ_Edit.h" 
#include "BLV_Logic_MMDB_Edit.h" 
#include "BLV_Logic_ZZZMAX_Edit.h"
#include "BLV_Logic_YinChuanMZDX_Edit.h"
#include "BLV_Logic_ManYue_Edit.h"
#include "BLV_Logic_SiJiJinZuo_Edit.h"
#include "BLV_Logic_BuErJin_Edit.h"
#include "BLV_Logic_Pakistan_Edit.h"
#include "BLV_Logic_JinHai_Edit.h"
#include "BLV_Logic_TongHuaHongYuan_Edit.h"
#include "BLV_Logic_SJJZ2_Edit.h"
#include "BLV_Logic_HaiRong_Edit.h"
#include "BLV_Logic_BeijingZMAXC12_Edit.h" 
#include "BLV_Logic_ChaoMan_Edit.h"
#include "BLV_Logic_LeChen_Edit.h"
#include "BLV_Logic_HZMYZMAXC12_Edit.h"   
#include "BLV_Logic_BeiJingHuiYi_Edit.h"
#include "BLV_Logic_YZZTC12_Edit.h"
#include "BLV_Logic_HuangShanMinSu_Edit.h"
#include "BLV_Logic_CaiFu1Hao_Edit.h"
#include "BLV_Logic_HaiLuo_Edit.h"
#include "BLV_Logic_WYNRL_Edit.h"
#include "BLV_Logic_CMXG_Edit.h"
#include "BLV_Logic_YongLi_Edit.h"
#include "BLV_Logic_YuJiuDian_Edit.h"
#include "BLV_Logic_WYNXiZangNaQu_Edit.h"
#include "BLV_Logic_WangYuDJ_Edit.h"
#include "BLV_Logic_YangLuo_Edit.h"
#include "BLV_Logic_HongYuan_Edit.h"
#include "BLV_Logic_YanYuan_Edit.h"
#include "BLV_Logic_YiLiSi_Edit.h"
#include "BLV_Logic_GuangXin_Edit.h"
#include "BLV_Logic_TaiWanVVO_Edit.h"
#include "BLV_Logic_ChangAn_Edit.h"
#include "BLV_Logic_LiTing_Edit.h"
#include "BLV_Logic_JingDu_Edit.h"
#include "BLV_Logic_XinJiangMinSu_Edit.h"
#include "BLV_Logic_HaoXiangYuan_Edit.h"
#include "BLV_Logic_AMan_Edit.h"
#include "BLV_Logic_ZMAXChengDuHZZX_Edit.h"
#include "BLV_Logic_NanChengHengLi_Edit.h"
#include "BLV_Logic_BoErMan_Edit.h"
#include "BLV_Logic_NCGX_Edit.h"
#include "BLV_Logic_JYJD_Edit.h"
#include "BLV_Logic_GuChengChaoMan_Edit.h"
#include "BLV_Logic_GongSiJieDai_Edit.h"
#include "BLV_Logic_ManYueLanTing_Edit.h"
#include "BLV_Logic_EErDuoSi_Edit.h"
#include "BLV_Logic_WanZaiWeiYeNa_Edit.h"
#include "BLV_Logic_ChaoManJiLin_Edit.h"
#include "BLV_Logic_TaiZhouST_Edit.h"
#include "BLV_Logic_YunJin_Edit.h"
#include "BLV_Logic_GaoQiaoMinSu_Edit.h"
#include "BLV_Logic_YiLangYangBanJian_Edit.h"
#include "BLV_Logic_DeZhouChaoMan_Edit.h"
#include "BLV_Logic_HeMeiQinTang_Edit.h"
#include "BLV_Logic_C5ZhanXiang_Edit.h"
#include "BLV_Logic_AnQiGaoSW_Edit.h"
/*项目逻辑结束头文件*/

#endif


#define ENTER_CRITICAL()    { __set_PRIMASK(1); }//(EA = 0)	关闭全局中断
#define EXIT_CRITICAL()     { __set_PRIMASK(0); }//(EA = 1) 打开全局中断

//#define SoftwareVer     "C1F_C5_WYN_211123"

/*Launcher的软件版本是在MCU Flash中的0x1000 - 20Byte*/
#define Launcher_SoftwareVer_Addr	0x1000		

#if (USE_CORE_TYPE == 1)    //使用C1F核心板
	#define MCU_TYPE	"BLV-C1F"				//机型编号
	#define APP_NAME 				"App_L4_C1F_45"		//APP名称 16Byte
	
	#if (USE_FLOOR_TYPE == 1)  //C5底板
		#define Center_Control_TYPE		"BLV-C5"				//主板型号
		#define RELAY_NUM   24    //C5继电器之前版本继电器是20，使用CSIO后继电器改为24个
		
		#if (SoftName_Custom_Enable == 0x00)	
			#if (LOGIC_FILE_EN == 0x01)
			#define SoftwareVer 		"C1F_A_L4_45_260325" 		//软件版本 20Byte    
			#else
			#define SoftwareVer 		"C1F_C5_Init220525 "		//软件版本 20Byte
			#endif
		#endif
		
		#ifndef SoftwareVer
			#if (LOGIC_FILE_EN == 0x01)
			#define SoftwareVer 		"C1F_Cx_Init220614 "		//软件版本 20Byte
			#else
			#define SoftwareVer 		"C1F_C5_Init220525 "		//软件版本 20Byte
			#endif
		#endif
	#elif (USE_FLOOR_TYPE == 2)  //C12底板
	
		#define Center_Control_TYPE		"BLV-C12"				//主板型号
		#define RELAY_NUM   13    //C12继电器13个
		
		#if (SoftName_Custom_Enable == 0x00)
			#define SoftwareVer 		"C1F_C12_CFG_220517A"		//软件版本 20Byte
		#endif
	#endif
	
	
#elif (USE_CORE_TYPE == 2)   //使用C1核心板
	#define MCU_TYPE	"BLV-C1"				//机型编号
	#define APP_NAME 				"BLV_C1_APP_V29"		//APP名称 16Byte
	#if (USE_FLOOR_TYPE == 1)  //C5底板
		#define Center_Control_TYPE		"BLV-C5"				//主板型号
		#define RELAY_NUM   24    //C5继电器24个
	
		#if (SoftName_Custom_Enable == 0x00)	
			#define SoftwareVer 		"C1_C5_211120B1"		//软件版本 20Byte
		#endif

	#elif (USE_FLOOR_TYPE == 2)  //C12底板
		
		#define Center_Control_TYPE		"BLV-C12"				//主板型号
		#define RELAY_NUM   13    //C12继电器13个
		
		#if (SoftName_Custom_Enable == 0x00)	
			#define SoftwareVer 		"C1_C12_MQTT_211117A2"		//软件版本 20Byte
		#endif
	#endif
#endif  //USE_CORE_TYPE == CORE_TYPE_C1F

/*网络-协议头带IP还是MAC地址后两位
	1：协议头带MAC地址
	0：协议头自带IP
*/
#define NET_Head_Agreement_MAC_EN	1

/*
2021-12-29 新增本地按键测试
如果使用本地按键测试，便定义以下宏
不使用的话，请不要定义以下宏
这个宏定义，放到私有文件或工程中。
*/
//#define MCU_Local_Test_Button_EN	0x01



typedef struct{
	uint16_t pro_coding;
	uint32_t pro_housetype;
	char pro_version[20];
	char pro_mcutype[16];
	char pro_floortype[16];
	char pro_remark[64];
	char remain[390];
}__attribute__ ((packed)) S_Project_Information;

/*这份设备集合包含有所有设备 干节点 网络  485  同一类设备必须放在一起*/
typedef enum
{
	Dev_Host_Invalid,      //无效设备    也可以被认为是场景
	Dev_Host_HVout,        //强电继电器             输出状态
	Dev_Host_LVinput,      //弱电输入               输入状态
	Dev_Host_LVoutput,     //弱电输出            输出状态
	Dev_Host_Service,      //服务信息   可配置数量  输出状态
	
	Dev_NodeCurtain,       //干节点窗帘 可配置数量  输出状态

	
/*485设备类型开始*/
	DEV_RS485_SWT,                	//6               //开关指示灯  输出状态 输入状态   485设备首地址  
	DEV_RS485_TEMP,			        //7               //空调1       空调状态
	DEV_RS485_INFRARED,				//8               //红外感应       备用 
	DEV_RS485_AirDetect, 			//9               //空气质量检测设备       备用
	DEV_RS485_CARD,					//10              //插卡取电   取电状态
	DEV_RS485_HEATER,				//11              //地暖       地暖状态
	Dev_RCU_NET,					//12              //RCU设备网络 
	DEV_RS485_CURTAIN,				//13              //窗帘        窗帘状态
	DEV_RS485_RELAY,				//14              //继电器      继电器状态  
	DEV_RS485_IR_SEND,				//15              //红外发送    红外转发状态
	DEV_RS485_DIMMING,				//16              //直流调光     调光状态
	DEV_RS485_TRAIC,				//17              //可控硅调光   可控硅状态
	DEV_RS485_STRIP,              	//18              //灯带         灯带状态
	DEV_RS485_CoreCtrl,           	//19              //中控         
	DEV_RS485_WxLock,             	//20              //微信锁       微信锁状态  福瑞狗的蓝牙锁默认0地址
	DEV_RS485_MUSIC,              	//21              //背景音乐     背景音乐状态
/*485设备类型结束*/	
	DEV_NET_ROOMSTATE,            	//22              //房态下发     
	
	Dev_Host_PWMLight,            	//23              //主机本地调光
	DEV_RS485_PWM,                	//24              //485PWM调光   PWM调光状态
	DEV_PB_LED,                   	//25              //总线调光     PBLED调光状态
	DEV_RCU_POWER,                	//26              //RCU电源
	
	DEV_RS485_A9_IO_SWT,          	//27              //A9IO开关    独立开关，没有协议区分
	DEV_RS485_A9_IO_EXP,          	//28              //A9IO扩展    独立扩展，没有协议区分
	DEV_RS485_A9_IO_POWER,        	//29              //A9IO电源    独立电源，没有协议区分 
	
	DEV_RS485_RFGatewayCycle,     	//30              //无线网关轮询   用于轮询控制轮询设备   给无线网关下发配置和询问网关状态
	DEV_RS485_RFGatewayHost,      	//31              //无线网关主动   用于主动控制主动设备   
	
	DEV_RS485_RFGatewayDoor,      	//32              //无线门磁
	DEV_RS485_AirReveal,          	//33              //空气参数显示设备
	DEV_RS485_RFGatewayRelayPir,  	//34              //无线继电器红外  驱动存放在继电器扩展板里面
	
	Dev_Host_TimeCtrl,            	//35              //时间同步
	
	Dev_Rs458_MonitorCtrl,        	//36              //监控控制
	
	Dev_Rs458_RotaryCtrl,         	//37              //旋钮开关控制
	
	Dev_BUS_C5IO,					//38			  //C5IO - 类型
	
	Dev_RS485_CardState,            //39              //插卡状态虚拟设备
	DEV_RS485_FreshAir,				//40			  //485新风设备
	DEV_RS485_FaceMach,             //41              //485人脸机
	DEV_Center_Control,             //42              //中控
	DEV_Domain_Control,             //43              //域控
	DEV_RS485_LCD,                  //44              //LCD
	DEV_Virtual_NoCard,             //45              //无卡断电
	DEV_Virtual_Card,               //46              //无卡取电2
	
	DEV_Virtual_Time,               //47              //虚拟时间设备
	
	Dev_Rs485_PB20 = 0x30,			//48			//PLC总控
	Dev_Rs485_PB20_LD = 0x31,		//49			//PLC - 恒流调光
	Dev_Rs485_PB20_LS = 0x32,		//50			//PLC - 恒压调光
	Dev_Rs485_PB20_Relay = 0x33,	//51			//PLC - 继电器
	
	DEV_Virtual_ColorTemp,			//52			  //色温调节功能
	
	Dev_485_BLE_Music,              //53              //蓝牙音频
	DEV_Carbon_Saved,			    //54			  //碳达人
	Dev_Scene_Restore,              //55              //场景还原
    Dev_Virtual_GlobalSet,          //56              //2025-07-14，YYW，全局设置
	
	Dev_Energy_Monitor,				//57			  //能耗检测	2025-08-27 
    
	Dev_Num_MAX,               //设备个数上限
}Enum_Dev_Type;              //设备类型集合

#define DIMMING(x)      (1<<x)

void Data_Receiving_Process(void);
void Environment_Variable_Init(void);
void BLV_Authorize_Task(void);
void BLV_NETUpload_Logging_Task(void);
void MCU_Flash_Read(uint8_t* pBuffer,uint16_t NumByteToRead,uint32_t ReadAddr);



#endif
