#ifndef PROTOINNERCAN_H_
#define PROTOINNERCAN_H_

#include "gType.h"

#define InnerEventRxCount	128
#define InnerRecentUsingCount	16

#define InnerFastTxBufCount	10000
#define InnerEventTxBufCount	50000

extern const unsigned char  CmdActiveDefaultSet[256][10];

typedef enum{
	FastCall = 0,
	StdCall = 1,
	NetNormalCall = 2,
	SimEvent =3,
	PortSync
}TInnerCanCmdCallType;

typedef enum{
	etFire = 1,
	etFireCancel = 2,
	etFault =3,
	etFaultCancel =4,
	etSuperVi,
	etSuperViCancel,
	etLinkageStart,
	etLinkageStartCancel,
	etLinkageFeedBack,
	etLinkageFeedBackCancel,
	
	etOperate,
	etReport,
	etBusPadAction,
	etDirectPadAction,
	etBusPadRequst,
	etDirectPadRequst,
	etStartDelay,
	
	etFireSimulate,
	etSuperViSimulate,
	etLinkageStartSimulate,
	etDirectPadReport,
	etConfig,
}TInnerEventType;

typedef enum{
	ftSmoke = 1,
	ftTempe =2,
	ftHandset,
}TInnerMsgFireType;

typedef enum{
	stPreAlram = 1,
	stPreAlramCanel =2,
	stThreholdHi,
	stThreholdLow,
	stDoorOpen,
	stDoorClose,
	stManualTouck = 0,
	stDevOffLine = 1,
	stPowerVoltageInputLow,
	stWaterGageLow,
	stWaterPressureLow,
	stBatteryError,
}TInnerMsgSuperViType;

typedef enum{
	ttDevOffLine = 1,
	ttDevFault = 2,	//回路部件故障
	ttDevFaultCancle,	//回路部件故障恢复
	ttCirt,		//线路故障
	ttBoardErr,		//板卡故障
	ttMainPowerErr,	//主电故障
	ttStandbyPowerErr,	//备电故障
	tt24VErr,			//24V故障
	ttBatErr,			//电池故障
	ttEarthContactErr,	//接地故障
	ttTrialTimeOut,		//试用期到期故障
	ttOther,			//其他故障
	ttValueErr,			//故障统一成一条指令
	tbDevManualReport,

}TInnerMsgFaultType;

typedef enum{
	neReset = 0,
	
}TInnerNormalEvent;

typedef enum{
	cmUndefine =0,
	cmSyncBeat =1,
	cmReset =2,
	cmMuteBell,
	cmSelfCheck,
	cmBroadcastTime,
	cmInspection ,
	//7
	cmPublishAlram,
	cmPublishPreAlram,
	cmPublishPreAlramResume,
	cmTakeChargeAlram,
	cmTakeChargeAlramResume,
	cmConfirmAlram,
	cmThresholdHiAlram,
	cmThresholdLowAlram,
	//15
	cmManualStart,	//手动启动
	cmManualStop,	//手动停止
	cmAutoDelayStart,	//自动延时启动
	cmAutoStart,	//自动启动
	cmAutoStop,		//自动停止
	cmAck,		//应答
	cmAckStop,		//停止应答
	cmAckMiss,		//应答缺失
	cmAckHydrant,	//消火栓应答
	cmAckFireAreaHydrant,	//防火区消火栓应答
	//防火区与声光
	//25
	cmVAAlramStart,		//声光启动
	cmVAAlramStop,		//声光停止
	cmFireAreaVAAlramStart,	//防火区声光启动
	cmFireAreaVAAlramStop,	//防火区声光停止
	cmFireAreaStart,		//防火区启动
	cmFireAreaStop,		//防火区停止
	//31
	cmMainManualAutoState,		//主机手自动状态
	cmDirCtlManualAutoState,	//多线盘手自动状态
	//故障	
	//33	0x21
	cmPortModuleErr,		//回路部件故障
	cmPortModuleErrRecover,	//回路部件故障恢复
	cmCircuitErr,		//线路故障
	cmOtherErr,			//板卡故障
	cmMainPowerErr,		//主电故障
	cmBKPowerErr,		//备电故障
	cmDC24PowerrErr,		//24V故障
	cmBatteryPowerrErr,	//电池故障
	cmGNDConnectErr,		//接地故障
	cmTrialTimeUpErr,		//试用期到期故障
	xxcmOtherErr,			//其他故障
	cmSYSErr,			//故障统一成一条指令
	
	//45~53
	cmAllPortAutoRegist,
	cmSinglePortAutoRegist,
	cmSinglePortAddrManualRegist,
	cmClearAllRegist,
	cmClearSinglePortRegist,
	cmClearSinglePortAddrRegist,
	cmPortRegistProgress,
	cmPortRegistFinished,
	cmPortRegistAbort,

	//54~66
	cmQueryVer,
	cmQueryPortReg,
	cmQueryRunState,
	cmQueryRuntimeData,
	cmQueryStaticData,
	cmQueryMacCode,
	cmQuerySens,
	cmQueryAnalogRawData,
	cmQueryVoltage,
	cmQueryPortRunParam,
	cmQueryAbout,
	cmQueryCmdConfirm,
	cmQueryPortPowerSet,
	
	//67~77
	cmEpDeviceMask,
	cmEpDeviceMaskRemove,
	cmMaskRemoveAll,
	cmDeviceConfig,
	cmDeviceSetSens,
	cmDeviceSetLogicAddr,
	cmQueryDisplayPadAddrSegment,
	cmSetDisplayPadAddrSegment,
	cmSetDisplayPadPositionInf,
	cmSendDisplayPadInf,
	cmAddDisplayPadAddrSegment,

	//78~88
	cmBusCtlPadConfig,
	cmBusCtlPadAction,
	cmBusCtlPadState,
	cmBusCtlPadNoAck,
	cmBusCtlPadAckOk,
	cmBusCtlPadAllAckOk,
	cmBusCtlPadAckLack,
	cmBusCtlPadAutoOnActive,
	cmBusCtlPadAutoNotActive,
	cmBusCtlPadConfigReq,
	cmBusCtlPadManualState,
	
	//89~97
	cmDirectCtlPadConfig,
	cmDirectCtlPadAction,
	cmDirectCtlPadSilence,
	cmDirectCtlPadManualState,
	cmDirectCtlPadChannelState,
	cmDirectCtlPadLinkageState,
	cmDirectCtlPadAutoNotActive,
	cmDirectPadConfigReq,
	cmDirectCtlPadQueryPort,
	
	//98
	cmVIrtualAlram,
	cmVIrtualAlramCancle,
	cmVIrtualStart,
	smVIrtualStop,
	cmVIrtualAck,
	cmVIrtualAckStop,
	cm104,
	cm105,
	cm106,
	cmDevLightOn,
	cmDevMute,
	cmDuplicateAddrCheckStart,
	
	//110
	cmDuplicateAddrCheckPrg,
	cmDuplicateAddrData,
	cmDuplicateAddrCheckEnd,
	cm113,
	cm114,
	cm115,
	cmSetConfigAddrSegment,
	cmQueryStaticDataAddrSegment,
	cmDuplicateAddrEpDeviceLed,
	cm119,
	
	cmEnterAdjustMode,
	cmExitAdjustMode,
	cm122,
	cm123,
	cm124,
	cm125,
	cm126,
	cmCtrlPowerOn,
	cmAckHydrantCommon,
	cmAckHydrantCancel,
	
	cmAlternatingSpeakerSL,
	cm131,
	cm132,
	cm133,
	cm134,
	cm135,
	cm136,
	cm137,
	cm138,
	cm139,
	
	cmVIrtualSuperVi,
	cm141,
	cm142,
	cm143,
	cm144,
	cm145,
	cm146,
	cm147,
	cm148,
	cm149,
	
	cmQueryBoardModel,
	cmBusDataSyncRegisterReq,
	cmBusDataSyncRegister,
	cmBusDataSyncRegisterRes,
	cmBusDataSyncIsolationReq,
	cmBusDataSyncIsolation,
	cmBusDataSyncIsolationRes,
	cmBusDataSynAlarmLinkage,
	cmBusDataSynAlarmLinkageRes,
	cm159,

	
	/*
	cmReportFireDelay,		//报告火警延时
	cmReportSuperVisoryDelay,	//报告监管事件延时
	cmReportTroubleDelay,		//报告故障延时
	cmReportEventDelay,		//报告事件延时
	
	//注册 Device List
	cmRegCheckDeviceExist,
	cmRegRescanDevList,
	cmRegQueryRescanDevListDone,
	cmRegRequstDeviceList,
	
	//发布状态____________________________________
	//调试模式 mode
	cmAdjustModeEnter,		
	cmAdjustModeExit,
	cmAdjustModeCompare,
	cmAdjustModeCompareCancel,
	
	//允许 手动
	cmManualAllow,
	cmManualNotAllow,
	cmManualCompareAllow,
	cmManualCompareAllowCancel,
	
	//自动模式 mode
	cmAutoAllow,
	cmAutoNotAllow,
	cmAutoCompareAllow,
	cmAutoCompareAllowCancel,

	//喷洒设定 mode
	cmSplashAllow,		
	cmSplashNotAllow,
	cmSplashCompare,
	cmSplashCompareCancel,
	
	//屏蔽
	cmMaskAll,
	cmMaskAllRecover,
	cmMaskTypeDevice,
	cmMaskTypeDeviceRecover,
	cmMask,
	cmMaskRecover,
	cmMaskAllTemp,
	cmMaskAllTempRecover,
	cmMaskStateCompare,
	cmMaskStateCompareRecover,
	
	//按类激活或取消火报状态
	cmFireAlramSetTypeActive,
	cmFireAlramSetTypeDeActive,
	cmFireAlramQueryByType,
	cmFireAlramSetActive,
	cmFireAlramSetDeActive,
	cmFireAlramQueryByPath,

	//按地址激活或取消灭火行为 	一级路径，二级路径
	cmExtinguishSetTypeEnter,
	cmExtinguishSetTypeExit,
	cmExtinguishQueryStateByType,
	cmExtinguishEnter,
	cmExtinguishExit,
	cmExtinguishQueryStateByPath,
	cmExtinguishEnterViaUserCode,
	cmExtinguishExitViaUserCode,
	cmExtinguishGetState,
	cmExtinguishGetStateViaUserCode,
	
	//按类型设定状态
	cmStateSetByType,
	
	//按设定状态		1级路径 2级路径 3级路径
	cmBehaviorSet1,		//以1个行为类型设定设备状态
	cmBehaviorSet2,		//以2个行为类型设定状态
	cmBehaviorSet3,		//以3个行为类型设定状态
	cmBehaviorSet4,		//以4个行为类型设定状态
	cmBehaviorSet1AndPrm1,		//以1个行为类型设定设备状态带一个参数
	cmBehaviorSetViaUserCodeSet1,	//以1个行为类型设定设备状态
	cmBehaviorSetViaUserCodeSet2,	//以2个行为类型设定状态
	cmBehaviorSetViaUserCodeSet3,	//以3个行为类型设定状态
	cmBehaviorSetViaUserCodeSet4,	//以4个行为类型设定状态
	cmBehaviorSetViaUserCodeSet1AndPrm1,	//以1个行为类型设定设备状态带一个参数

	//读取状态			一级路径类型，二级路径类型
	cmStateRead,
	//按用户码读取设备状态
	cmStateReadViaUserCode,	
	//主动上报状态
	cmStateReport,
	
	//读取设备属性		一级路径类型，二级路径类型
	cmPropertyRead,
	cmPropertyReadViaUserCode,
	//参数 读写			一级路径类型，二级路径类型
	cmDevParameterWrite,
	cmDevParameterRead,
	
	//Query 查讯， 这些会触发一个 多 Section 回复	一级路径类型，二级路径类型
	cmQueryDevDescp,		
	
	//手动盘主动报告手动开关是否激活
	cmHandPadManualAllowReport,
	//查询手动盘手动开关是否激活
	cmHandPadManualAllowQuery,
	//手动盘主动报告状态
	cmHandPadSwitchStateReport,
	//查询手动盘开关状态
	cmHandPadSwitchStateQuery,
	
	//多线盘主动报告手动开关是否激活
	cmDirectCtlManualAllowReport,
	//查询多线盘手动开关是否激活
	cmDirectCtlManualAllowQuery,
	//多线盘主动报告自动开关是否激活
	cmDirectCtlAutoAllowReport,
	//查询多线盘自动开关是否激活
	cmDirectCtlAutoAllowQuery,
	//查询多线盘开关状态
	cmDirectCtlSwitchStateQuery,
	//查询多线盘通道状态
	cmDirectCtlChannelQuery,
	//多线盘输出运行时负载状态
	cmDirectCtlLoadStateQuery,
	//多线盘通道类型指派
	cmDirectCtlChannelTypeAssign,
	//多线盘通道类型查询
	cmDirectCtlChannelTypeQuery,
	
	//读取版本
	cmQueryVer,
	//停止查询当前
	cmQUeryBrokeAnyway,
	//读取运行时原生数据	一级路径类型，二级路径类型
	cmQueryDevRawData,
	
	//显示盘 Display pad
	cmDisplayPadSet,	//
	cmDisplayPadItemSet,
	cmDisplayPadAddItem,
	cmDisplayPadReqCtl,
	cmDisplayPadCtlReturn,
	cmDisplayPadReqInf,
	cmDisplayPadReqPevInf,
	cmDisplayPadReqNextInf,
	cmDisplayPadMsgSend,
	cmDisplayPadMsgSendTime,	//追加显示盘上一条信息时间戳

	
	cmDescpStringRead,			
	cmDescpStringWrite,
	cmDescpStringErase,	
	
	cmInterLinkPublish,	
	cmInterLinkWrite,	
	cmInterLinkDelete,
	cmInterLinkActive,
	cmInterLinkDeActive,
	cmInterLinkDeActiveUnExe ,

	
	//设置二级总线断路器 (如果回路中的断路器可寻址，可见)
	cmBusBreakDoBreak,
	cmBusBreakDoContact,
	
	//回路数据备份复制, 覆盖，可用于回路交换，卡替换
	//cmPortDataRead_1,
	//cmPortDataWrite_1,
	cmRequstTime,
	
	//向数据持有端请求传输块数据     		属性(数据导入表，配置表，参数表，修正表，可烧录文件)
	cmBlockRead,
	//主动传输块数据到有对应用途的 设备    	属性(数据导入表，配置表，参数表，修正表，可烧录文件)
	cmBlockTransmite,
	
	cmPublishPowerLostTime,
	cmPublishEnergy,
	
	cmManualInspectionStart,
	cmManualInspectionDataGet,
	cmMonthlyInspectionStart,
	cmMonthlyInspectionDataGet,
	cmAnnuallyInspectionStart,
	cmAnnuallyInspectionDataGet,
	
	//扩展检流板设置
	cmExternCurrentReportEvent,*/
}TInnerCommand;

typedef enum{
	//(数据导入表，配置表，参数表，修正表，可烧录文件)
	dtData,
	dtConfig,
	dtParameter,
	dtAlterTable,
	dtBurnfiles,
	dtExeFile,
}TInnerDataType;

typedef enum{
	rqNotReqReturn = 0,	//无需要回复			不需要接收端回复
	rqAck = 1,			//需求回复接收确认
	rqState,			//需求回复状态			
	rqExeResult,		//需求回复执行结果		设置状态，设置输入输出，设置等等
	rqDetails,			//需求回复详情			查询，读参数，读取状态， 等等  时使用  可以触发 多块， 多片段传输

	ackOK,			//回复接收确认

	ackExeState,		//回复执行状态
	ackInProcesser,		//正在执行
	ackExecuteDone,		//回复执行完成
	ackDetails,

	//以下为回复的状态，或执行结果
	ackStateOK,				
	ackStateOverSize,		
	ackParseError,		
	ackInvalidData,	
	ackBusy,	
	ackDevFault,
	ackUnknown,
	ackReqError,
	ackSubDevNotExist,	//代理回复， 访问二级路径时， 二级路径所属一级路径持有者可以代理回复
	
	//以下为 多块，多片段发送 控制字 
	//收到以下控制字，各自有默认的回复类型， 不需外加 回复请求
	bsAckOK,
	bsAckRepeat,
	bsExeDone,
	bsExeNotDone,
	bsMultiBlockInit,		//数据持有端发出 初始化一个多块传输 添加参数描述   byte数量， 块数量， 数据属性(数据导入表，配置表，参数表，修正表，可烧录文件)
	bsWaitForCompleted,		//		可选回复， 表示当前片段接收正确，等待继续传输。
	bsCheckIntact,		//数据持有端发出  询问接收者是否完整 ， 完整的返回接收完整，  否则回复 第一包Byte0=bsRequestBlockX， ,第二包 Byte0 = bsRequestSectionX ，然后主发端重新发送片段
	bsIntact,				//		接收完整
	bsExecute,			//数据持有端发出   根据数据属性描述，执行文件	， 要求接收端返回执行结果。
	bsRequestBlockX,			//		请求切换到 块 X 
	bsRequestSectionX,		//		请求发送   片段 X 
	
	
	bsBlockX,			//数据持有端发出   切换到 Block X ，接收端回复描述详情
	bsSection0 = 50,			//数据持有端发出   初始化开始传输片段，   接收端可选回复描述详情
	//以下数据持有端发出   以下可选需求即时回复， 或者可以选在在主动传输完成后询问接收者状态
	bsSection1  = 51,
	bsSection2,
	bsSection3,
	bsSection4,
	bsSection5,
	bsSection6,
	bsSection7,
	bsSection8,
	bsSection9,
	bsSection10,
	bsSection11,
	bsSection12,
	bsSection13,
	bsSection14,
	bsSection15,
	bsSection16,
	bsSection17,
	bsSection18,
	bsSection19,
	//max = 250
	bsSectionEnd = 251,
}TInnerControlByte;

typedef enum{
	bcNone		=	0,
	bcMakeActive	=	1,
	bcMakeDeActive,
	bcMakeChannelActive,
	bcMakeChannelDeActive,
	bcFireAlarmEnter,
	bcFireAlarmExit,
	bcExtinguishEnter,
	bcExtinguishExit,
	bcMakeMask,
	bcMakeUnMask,
	bcStopQueryReply,
	bcSetBackLightOn,
	bcSetBackLightOff,
	bcSetShowIndexPrv,
	bcSetShowIndexNext,
	bcSetShowIndex,
	bcVaAlramBellOn,
	bcVaAlramBellOff,
	bcVaAlramLightOn,
	bcVaAlramLightOff,
	bcVaAlramFullOn,
	bcVaAlramAllOff,
	bcAdjustModeEnter,
	bcAdjustModeExit,
	bcManualAllow,
	bcManualNotAllow,
	bcAutomaticAllow,
	bcAutomaticNotAllow,
	bcSplashNotAllow,
	bcSplashAllow,
	bcInterLinkActive,
	bcInterLinkDeActive,
	bcSetBrokerBroke,
	bcSetBrokerContact,
	bcRequstLocalInterLinkTakeCtl,
	bcRequstLocalInterLinkReturnCtl,
}TBehaviorCode;

typedef union{
	unsigned int D32[2];
	unsigned char D8[8];
	struct{
		unsigned char rqAck;
		unsigned char Byte1;
		unsigned char Byte2;
		unsigned char Byte3;
		unsigned char Byte4;
		unsigned char Byte5;
		unsigned char Byte6;
		unsigned char Byte7;
	}Common;
}TStateSetDataMapping;

typedef struct{
	TCanHeaderID Ide;
	union{
		unsigned int D32[2];
		unsigned char D8[8];
	}Data;
	unsigned char Dlc;
	unsigned char Ava;
	unsigned short DelayMs;
}TInnerCanMsg;

typedef struct{
	int WriteIndex;
	int ReadIndex;
	struct{
		TCanHeaderID Ide;
		union{
			unsigned int D32[2];
			unsigned char D8[8];
		}Data;
		unsigned int Dlc;
	}wBody, rBody;
}TOutBuf;

class TInnerCan{
	private:
		static const unsigned int Buf4GuiInxMax =  32;
		unsigned char ThisAddr;
		struct{
			unsigned char iType;
			TStateSetDataMapping StateSet;
		}ItemTx;
	public:
		struct{
			unsigned int started;
			unsigned char *pData;
			unsigned int Len;
			unsigned int BlockCount;
			unsigned int SectionCount;
		}File;
		
		//TInnerSectionMsg	SectionTx;
		//TInnerSectionMsg 	SectionRx;
		///TInnerBlockRx	BlockRx;
		
		TInnerCanMsg aRxMsg;
		TInnerCanMsg aTxMsg;
		
		TInnerCanMsg oBufMsg;
		
		TOutBuf OutBufFast;
		TOutBuf OutBuf;
		unsigned char tData[8];
		unsigned int ShouldSyncTime;

		struct{
			unsigned char Inx_In;
			unsigned char Inx_Out;
			struct{
				TCanHeaderID Ide;
				unsigned char Da[8];
				unsigned int Len;
			}Body[Buf4GuiInxMax];
			void Insert(TCanHeaderID aIde, unsigned char *aDa, unsigned int aLen){
				Inx_In++;
				if(Inx_In >= Buf4GuiInxMax)Inx_In = 0;
				Body[Inx_In].Ide.D32 = aIde.D32;
				for(int i=0, x=0; (i<aLen) && (x<8); i++, x++)Body[Inx_In].Da[i] = aDa[i];
				Body[Inx_In].Len = aLen>8 ? 8: aLen; 
			}
			void Reset(){
				Inx_In = 0;
				Inx_Out = 0;
			}
		}Buf4GuiSend;
	public:
		TInnerCan(){};
		TInnerCan(unsigned char aAddr){
			Init(aAddr);
			Buf4GuiSend.Reset();
		}
		void Init(unsigned char aAddr){
			unsigned int i,x;
			ThisAddr = aAddr;

			aRxMsg.Ava = 0;
			aTxMsg.Ava = 0;
			
			OutBufFast.ReadIndex = 0;
			OutBufFast.WriteIndex = 0;
			
			OutBuf.ReadIndex = 0;
			OutBuf.WriteIndex = 0;
			
			ShouldSyncTime = 0;
			
			Buf4GuiSend.Reset();
		}
		
		void ProcesserPublishEmergencyRx(void);
		void ProcesserPublishRx(void);
		
		unsigned int GetNewPublishCount(void);
		unsigned int GetNewPublishEmerGencyCount(void);
	
		unsigned int FileInit(unsigned char pData, unsigned int len);
		unsigned int FileGetData(unsigned char *aPd, unsigned int aBlock, unsigned int aSection);
		
		void LoadPreset(u8 aCmd);
		void SetTarget(u8 aPathLevel);
		void SetTarget(u8 aPathLevel,  unsigned char Path1);
		void SetTarget(u8 aPathLevel,  unsigned char Path1, unsigned char Path2);
		void SetTarget(u8 aPathLevel,  unsigned char Path1, unsigned char Path2, unsigned char Path3);
		void CanBusFill(void);
		
		void CmdSendReset();
		void OBufFastInsert(unsigned char Pri, unsigned char Cmd, unsigned char *Data, unsigned char Len);
		void OBufInsert(unsigned char Pri, unsigned char Cmd, unsigned char *Data, unsigned char Len);
		void OBufPrcRecordAndEvent();
		void OBufCheckSend();
		
		void CheckSend2MasterMachine();
		
		void CmdSendCustom(TCanHeaderID aIde, unsigned char *p, unsigned int aLen);
		unsigned int CmdSendCustomWithReturn(TCanHeaderID aIde, unsigned char *p, unsigned int aLen);
		
		void BusPadGoAction(unsigned char P0, unsigned char aKeyNum);
		void DirectUpLoad(unsigned char aCmd, unsigned char *Data);
		void DirectRequest(unsigned char aCmd, unsigned char *Data);
		
		void SendCmdBroadcastFast(unsigned char aCdt);
		void SendCmdClearRegData();
		void SendCmdMaskRemoveAll();
		
		
		//按类型设定状态 //f State Set
		void fStateSetHandPadChannel(u8 aOnOff);
		void fStateSetHandPadChannel(u8 aPath1, u8 aOnOff);
		void fStateSetHandPadChannel(u8 aPath1, u8 aPath2, u8 aOnOff);
		//void fStateSetHandPadChannel(u8 aPath1, u8 aPath2, u8 aPath3, u8 aOnOff);
		void fStateSetDirectCtlChannel(u8 aOnOff);
		void fStateSetDirectCtlChannel(u8 aPath1, u8 aOnOff);
		void fStateSetDirectCtlChannel(u8 aPath1, u8 aPath2, u8 aOnOff);
		//void fStateSetDirectCtlChannel(u8 aPath1, u8 aPath2, u8 aPath3, u8 aOnOff);
		void fStateSetPort(u8 aIntv1, u8 aIntv2);
		void fStateSetPort(u8 aPath1, u8 aIntv1, u8 aIntv2);
		void fStateSetMotherBoard(u8 aLocalInterLinkSelfRun);
		void fStateSetMotherBoard(u8 aPath1, u8 aLocalInterLinkSelfRun);
		void fStateSetCommBoard(u8 aEn1, u8 aEn2, u8 aEn3, u8 aEn4);
		void fStateSetCommBoard(u8 aPath1, u8 aEn1, u8 aEn2, u8 aEn3, u8 aEn4);
		void fStateSetDisplayPad(u8 IsShow, u8 BackLightOnOff, u8 BeepOnOff, u8 IndexLongShow, u8 IndexShortShow);					//IndexLongShow : Mask Value = 0xFF; //IndexShortShow : Mask Value = 0xFF;
		void fStateSetDisplayPad(u8 aPath1, u8 IsShow, u8 BackLightOnOff, u8 BeepOnOff, u8 IndexLongShow, u8 IndexShortShow);			//IndexLongShow : Mask Value = 0xFF; //IndexShortShow : Mask Value = 0xFF;
		void fStateSetDisplayPad(u8 aPath1, u8 aPath2, u8 IsShow, u8 BackLightOnOff, u8 BeepOnOff, u8 IndexLongShow, u8 IndexShortShow);	//IndexLongShow : Mask Value = 0xFF; //IndexShortShow : Mask Value = 0xFF;
		void fStateSetIsoOutput(u8 aGroupOnOff);							// 4 channel  0..3 Bit
		void fStateSetIsoOutput(u8 aPath1,  u8 aGroupOnOff);					// 4 channel  0..3 Bit
		void fStateSetIsoOutput(u8 aPath1, u8 aPath2, u8 aGroupOnOff);			// 4 channel  0..3 Bit
		//void fStateSetIsoOutput(u8 aPath1, u8 aPath2, u8 aPath3, u8 aGroupOnOff);	// 4 channel  0..3 Bit
		void fStateSetIsoInOut(u8 aGroupOnOff);							// 2 channel  0..1 Bit
		void fStateSetIsoInOut(u8 aPath1,  u8 aGroupOnOff);					// 2 channel  0..1 Bit
		void fStateSetIsoInOut(u8 aPath1, u8 aPath2, u8 aGroupOnOff);			// 2 channel  0..1 Bit
		//void fStateSetIsoInOut(u8 aPath1, u8 aPath2, u8 aPath3, u8 aGroupOnOff);	// 2 channel  0..1 Bit
		void fStateSetVaAlram(u8 aBellOnOff, u8 aLightOnOff);
		void fStateSetVaAlram(u8 aPath1, u8 aBellOnOff, u8 aLightOnOff);
		void fStateSetVaAlram(u8 aPath1, u8 aPath2, u8 aBellOnOff, u8 aLightOnOff);
		void fStateSetBroke(u8 aBroke);
		void fStateSetBroke(u8 aPath1, u8 aBroke);
		void fStateSetBroke(u8 aPath1, u8 aPath2, u8 aBroke);
		void fStateSetExtCurrentSensor(u8 aEnable);
		void fStateSetExtCurrentSensor(u8 aPath1, u8 aEnable);
		void fStateSetExtCurrentSensor(u8 aPath1, u8 aPath2, u8 aEnable);
		void fStateSetIsoOutputChannel(u8 aOnOff);
		void fStateSetIsoOutputChannel(u8 aPath1, u8 aOnOff);
		void fStateSetIsoOutputChannel(u8 aPath1, u8 aPath2, u8 aOnOff);
		void fStateSetIsoOutputChannel(u8 aPath1, u8 aPath2, u8 aPath3, u8 aOnOff);
		void fStateSetIsoInOutChannel(u8 aOnOff);
		void fStateSetIsoInOutChannel(u8 aPath1, u8 aOnOff);
		void fStateSetIsoInOutChannel(u8 aPath1, u8 aPath2, u8 aOnOff);
		void fStateSetIsoInOutChannel(u8 aPath1, u8 aPath2, u8 aPath3, u8 aOnOff);
		
		//f ParameterSet
		void fParameterSetHandPadChannel(u8 aAssignType, u8 aAssignRank);
		void fParameterSetHandPadChannel(u8 aPath1, u8 aAssignType, u8 aAssignRank);
		void fParameterSetHandPadChannel(u8 aPath1, u8 aPath2, u8 aAssignType, u8 aAssignRank);

		void fParameterSetDirectCtlChannel(u8 aAssignType, u8 aAssignRank, u8 aCLow, u8 aCHi);				//aCLow aCHi	0=Ignore, 0=Default
		void fParameterSetDirectCtlChannel(u8 aPath1, u8 aAssignType, u8 aAssignRank, u8 aCLow, u8 aCHi);		//aCLow aCHi	0=Ignore, 0=Default
		void fParameterSetDirectCtlChannel(u8 aPath1, u8 aPath2, u8 aAssignType, u8 aAssignRank, u8 aCLow, u8 aCHi);//aCLow aCHi	0=Ignore, 0=Default

		void fParameterSetPort(u8 aSubItemCount, u8 aBrokeCurrent, u8 aShortCurrent, u8 aVLow);
		void fParameterSetPort(u8 aPath1, u8 aSubItemCount, u8 aBrokeCurrent, u8 aShortCurrent, u8 aVLow);
		void fParameterSetMotherBoard(u8 aSubItemCount);
		void fParameterSetMotherBoard(u8 aPath1, u8 aSubItemCount);
		
		void fParameterSetCommBoardChannel(u8 aPath1, u8 aChannel, u8 aCommType, u8 aSpeed, u8 aFerture);	//aFerture = BIt0..3 Bits Bit4..5 Stop Bits   Bit6..7 Parity
		
		void fParameterSetDisplayPad(u8 IsDefaultShow, u8 IndexLongShow, u8 IndexShortShow, u8 aIntv);					// Mask Value = 0xFF;
		void fParameterSetDisplayPad(u8 aPath1, u8 IsDefaultShow, u8 IndexLongShow, u8 IndexShortShow, u8 aIntv);			// Mask Value = 0xFF;
		void fParameterSetDisplayPad(u8 aPath1, u8 aPath2, u8 IsDefaultShow, u8 IndexLongShow, u8 IndexShortShow, u8 aIntv);	// Mask Value = 0xFF;
		
		void fParameterSetIsoInput(u8 aSens1, u8 aSens2, u8 aSens3, u8 aSens4);							
		void fParameterSetIsoInput(u8 aPath1, u8 aSens1, u8 aSens2, u8 aSens3, u8 aSens4);					
		void fParameterSetIsoInput(u8 aPath1, u8 aPath2, u8 aSens1, u8 aSens2, u8 aSens3, u8 aSens4);			
		
		void fParameterSetIsoInputChannel(u8 aAssignType, u8 aAssignRank);						
		void fParameterSetIsoInputChannel(u8 aPath1, u8 aAssignType, u8 aAssignRank);					
		void fParameterSetIsoInputChannel(u8 aPath1, u8 aPath2, u8 aAssignType, u8 aAssignRank);			
		void fParameterSetIsoInputChannel(u8 aPath1, u8 aPath2, u8 aPath3, u8 aAssignType, u8 aAssignRank);			
		
		void fParameterSetIsoOutput(u8 aThreshold1, u8 aThreshold2, u8 aThreshold3, u8 aThreshold4);		
		void fParameterSetIsoOutput(u8 aPath1,  u8 aThreshold1, u8 aThreshold2, u8 aThreshold3, u8 aThreshold4);					
		void fParameterSetIsoOutput(u8 aPath1, u8 aPath2, u8 aThreshold1, u8 aThreshold2, u8 aThreshold3, u8 aThreshold4);

		void fParameterSetIsoOutputChannel(u8 aAssignType, u8 aAssignRank);						
		void fParameterSetIsoOutputChannel(u8 aPath1, u8 aAssignType, u8 aAssignRank);					
		void fParameterSetIsoOutputChannel(u8 aPath1, u8 aPath2, u8 aAssignType, u8 aAssignRank);			
		void fParameterSetIsoOutputChannel(u8 aPath1, u8 aPath2, u8 aPath3, u8 aAssignType, u8 aAssignRank);	
	
		void fParameterSetIsoInOut(u8 aSens1, u8 aSens2, u8 aThreshold1, u8 aThreshold2);							
		void fParameterSetIsoInOut(u8 aPath1,  u8 aSens1, u8 aSens2, u8 aThreshold1, u8 aThreshold2);					
		void fParameterSetIsoInOut(u8 aPath1, u8 aPath2, u8 aSens1, u8 aSens2, u8 aThreshold1, u8 aThreshold2);	
		
		void fParameterSetVaAlram();	//No Any Function

		void fParameterSetBroke(u8 aBrokeCurrent, u8 aTimeDelay);
		void fParameterSetBroke(u8 aPath1, u8 aBrokeCurrent, u8 aTimeDelay);
		void fParameterSetBroke(u8 aPath1, u8 aPath2, u8 aBrokeCurrent, u8 aTimeDelay);
		
		void fParameterSetExtCurrentSensor(u8 aCRatio, u8 aLowThreshold, u8 aHiThreshold);
		void fParameterSetExtCurrentSensor(u8 aPath1, u8 aCRatio, u8 aLowThreshold, u8 aHiThreshold);
		void fParameterSetExtCurrentSensor(u8 aPath1, u8 aPath2, u8 aCRatio, u8 aLowThreshold, u8 aHiThreshold);
		
		void fParameterSetSmoke(u8 Sens, u8 aTimeDelay, u8 A, u8 B);
		void fParameterSetSmoke(u8 aPath1, u8 Sens, u8 aTimeDelay, u8 A, u8 B);
		void fParameterSetSmoke(u8 aPath1, u8 aPath2, u8 Sens, u8 aTimeDelay, u8 A, u8 B);
		
		void fParameterSetTempe(u8 aThreshold1, u8 aThreshold2, u8 aIndex);
		void fParameterSetTempe(u8 aPath1, u8 aThreshold1, u8 aThreshold2, u8 aIndex);
		void fParameterSetTempe(u8 aPath1, u8 aPath2, u8 aThreshold1, u8 aThreshold2, u8 aIndex);
			
		//Broadcast_____________________________________________
		unsigned int CmdSyncBeat();
		unsigned int CmdReset();
		unsigned int CmdMuteBell();
		unsigned int CmdSelfCheck();
		unsigned int CmdBroadcastTime();
		unsigned int CmdInspection();
		unsigned int CmdForceCheckTrouble();
		
		unsigned int CmdPublishFireAlram();
		unsigned int CmdPublishFireAlramResume();
		unsigned int CmdPublishSuperVisory();
		unsigned int CmdPublishSuperVisoryResume();
		unsigned int CmdPublishEvent();
		unsigned int CmdPublishEventResume();
		unsigned int CmdNoticeEvent();
		unsigned int CmdNoticeEventResume();

		unsigned int CmdRegCheckDeviceExist(u8 aPath1);
		unsigned int CmdRegCheckDeviceExist(u8 aPath1,u8 aPath2);
		unsigned int CmdRegCheckDeviceExist(u8 aPath1,u8 aPath2,u8 aPath3);
		unsigned int CmdRegRescanDevList(u8 aPath1);
		unsigned int CmdRegQueryRescanDevListDone(u8 aPath1);
		unsigned int CmdRegRequstDeviceList(u8 aPath1);
		//调试模式
		unsigned int CmdAdjustModeEnter(void);
		unsigned int CmdAdjustModeExit(void);
		unsigned int CmdAdjustModeCompare(u8 aActiveOrNot);
		unsigned int CmdAdjustModeCompareCancel(void);
		//手动
		unsigned int CmdManualAllow(void);
		unsigned int CmdManualNotAllow(void);
		unsigned int CmdManualCompareAllow(u8 aActiveOrNot);
		unsigned int CmdManualCompareAllowCancel(void);
		//自动
		unsigned int CmdAutoAllow();
		unsigned int CmdAutoNotAllow();
		unsigned int CmdAutoCompareAllow(u8 aActiveOrNot);
		unsigned int CmdAutoCompareAllowCancel();
		//喷洒设定 mode
		unsigned int CmdSplashAllow();
		unsigned int CmdSplashNotAllow();
		unsigned int CmdSplashCompare(u8 aActiveOrNot);
		unsigned int CmdSplashCompareCancel();
		//屏蔽
		unsigned int CmdMaskAll();
		unsigned int CmdMaskAllRecover();
		unsigned int CmdMaskTypeDevice(u8 aPath1, u8 aType);
		unsigned int CmdMaskTypeDevice(u8 aPath1,u8 aPath2, u8 aType);
		unsigned int CmdMaskTypeDevice(u8 aPath1,u8 aPath2,u8 aPath3, u8 aType);
		unsigned int CmdMaskTypeDeviceRecover(u8 aPath1, u8 aType);
		unsigned int CmdMaskTypeDeviceRecover(u8 aPath1,u8 aPath2, u8 aType);
		unsigned int CmdMaskTypeDeviceRecover(u8 aPath1,u8 aPath2,u8 aPath3, u8 aType);
		unsigned int CmdMask(u8 aPath1);
		unsigned int CmdMask(u8 aPath1,u8 aPath2);
		unsigned int CmdMask(u8 aPath1,u8 aPath2,u8 aPath3);
		unsigned int CmdMaskRecover(u8 aPath1);
		unsigned int CmdMaskRecover(u8 aPath1,u8 aPath2);
		unsigned int CmdMaskRecover(u8 aPath1,u8 aPath2,u8 aPath3);
		unsigned int CmdMaskAllTemp();
		unsigned int CmdMaskAllTempRecover();
		unsigned int CmdMaskStateCompare(u8 aPath1, u8 aActiveOrNot);
		unsigned int CmdMaskStateCompare(u8 aPath1,u8 aPath2, u8 aActiveOrNot);
		unsigned int CmdMaskStateCompare(u8 aPath1,u8 aPath2,u8 aPath3, u8 aActiveOrNot);
		unsigned int CmdMaskStateCompareRecover(u8 aPath1);
		unsigned int CmdMaskStateCompareRecover(u8 aPath1,u8 aPath2);
		unsigned int CmdMaskStateCompareRecover(u8 aPath1,u8 aPath2,u8 aPath3);
		
		//按类激活或取消火报状态
		unsigned int CmdFireAlramSetTypeActive(u8 aType);
		unsigned int CmdFireAlramSetTypeActive(u8 aPath1, u8 aType);
		unsigned int CmdFireAlramSetTypeActive(u8 aPath1,u8 aPath2, u8 aType);
		unsigned int CmdFireAlramSetTypeActive(u8 aPath1,u8 aPath2,u8 aPath3, u8 aType);
		unsigned int CmdFireAlramSetTypeDeActive(u8 aType);
		unsigned int CmdFireAlramSetTypeDeActive(u8 aPath1, u8 aType);
		unsigned int CmdFireAlramSetTypeDeActive(u8 aPath1,u8 aPath2, u8 aType);
		unsigned int CmdFireAlramSetTypeDeActive(u8 aPath1,u8 aPath2,u8 aPath3, u8 aType);
		unsigned int CmdFireAlramQueryByType(u8 aType, u8 aActiveOrNot);
		unsigned int CmdFireAlramQueryByType(u8 aPath1, u8 aType, u8 aActiveOrNot);
		unsigned int CmdFireAlramQueryByType(u8 aPath1,u8 aPath2, u8 aType, u8 aActiveOrNot);
		unsigned int CmdFireAlramQueryByType(u8 aPath1,u8 aPath2,u8 aPath3, u8 aType, u8 aActiveOrNot);
		
		unsigned int CmdFireAlramSetActive();
		unsigned int CmdFireAlramSetActive(u8 aPath1);
		unsigned int CmdFireAlramSetActive(u8 aPath1,u8 aPath2);
		unsigned int CmdFireAlramSetActive(u8 aPath1,u8 aPath2,u8 aPath3);
		unsigned int CmdFireAlramSetDeActive();
		unsigned int CmdFireAlramSetDeActive(u8 aPath1);
		unsigned int CmdFireAlramSetDeActive(u8 aPath1,u8 aPath2);
		unsigned int CmdFireAlramSetDeActive(u8 aPath1,u8 aPath2,u8 aPath3);
		unsigned int CmdFireAlramQueryByPath(u8 aActiveOrNot);
		unsigned int CmdFireAlramQueryByPath(u8 aPath1, u8 aActiveOrNot);
		unsigned int CmdFireAlramQueryByPath(u8 aPath1,u8 aPath2, u8 aActiveOrNot);
		unsigned int CmdFireAlramQueryByPath(u8 aPath1,u8 aPath2,u8 aPath3, u8 aActiveOrNot);
		
		//按地址激活或取消灭火行为 
		unsigned int CmdExtinguishSetTypeEnter(u8 aType);
		unsigned int CmdExtinguishSetTypeEnter(u8 aPath1, u8 aType);
		unsigned int CmdExtinguishSetTypeEnter(u8 aPath1,u8 aPath2, u8 aType);
		unsigned int CmdExtinguishSetTypeEnter(u8 aPath1,u8 aPath2,u8 aPath3, u8 aType);
		
		unsigned int CmdExtinguishSetTypeExit(u8 aType);
		unsigned int CmdExtinguishSetTypeExit(u8 aPath1, u8 aType);
		unsigned int CmdExtinguishSetTypeExit(u8 aPath1,u8 aPath2, u8 aType);
		unsigned int CmdExtinguishSetTypeExit(u8 aPath1,u8 aPath2,u8 aPath3, u8 aType);
		
		unsigned int CmdExtinguishQueryStateByType(u8 aType);
		unsigned int CmdExtinguishQueryStateByType(u8 aPath1, u8 aType);
		unsigned int CmdExtinguishQueryStateByType(u8 aPath1,u8 aPath2, u8 aType);
		unsigned int CmdExtinguishQueryStateByType(u8 aPath1,u8 aPath2,u8 aPath3, u8 aType);
		
		unsigned int CmdExtinguishEnter();
		unsigned int CmdExtinguishEnter(u8 aPath1);
		unsigned int CmdExtinguishEnter(u8 aPath1,u8 aPath2);
		unsigned int CmdExtinguishEnter(u8 aPath1,u8 aPath2,u8 aPath3);
		
		unsigned int CmdExtinguishExit();
		unsigned int CmdExtinguishExit(u8 aPath1);
		unsigned int CmdExtinguishExit(u8 aPath1,u8 aPath2);
		unsigned int CmdExtinguishExit(u8 aPath1,u8 aPath2,u8 aPath3);
		
		unsigned int CmdExtinguishQueryStateByPath(u8 aActiveOrNot);
		unsigned int CmdExtinguishQueryStateByPath(u8 aPath1,u8 aActiveOrNot);
		unsigned int CmdExtinguishQueryStateByPath(u8 aPath1,u8 aPath2,u8 aActiveOrNot);
		unsigned int CmdExtinguishQueryStateByPath(u8 aPath1,u8 aPath2,u8 aPath3, u8 aActiveOrNot);
		
		unsigned int CmdExtinguishGetState();
		unsigned int CmdExtinguishGetState(u8 aPath1);
		unsigned int CmdExtinguishGetState(u8 aPath1,u8 aPath2);
		unsigned int CmdExtinguishGetState(u8 aPath1,u8 aPath2,u8 aPath3);
		
		unsigned int CmdExtinguishEnterViaUserCode(unsigned int aUc);
		unsigned int CmdExtinguishExitViaUserCode(unsigned int aUc);
		unsigned int CmdExtinguishGetStateViaUserCode(unsigned int aUc);
		
		//unsigned int CmdStateSetByType(); //See 按类型设定状态 f State Set
		
		unsigned int CmdStateSet(TBehaviorCode aBehaviorCode);
		unsigned int CmdStateSet(u8 aPath1, TBehaviorCode aBehaviorCode);
		unsigned int CmdStateSet(u8 aPath1, u8 aPath2, TBehaviorCode aBehaviorCode);
		unsigned int CmdStateSet(u8 aPath1, u8 aPath2, u8 aPath3, TBehaviorCode aBehaviorCode);
		unsigned int CmdStateSet(TBehaviorCode aBehaviorCode, u8 aPrm);
		unsigned int CmdStateSet(u8 aPath1, TBehaviorCode aBehaviorCode, u8 aPrm);
		unsigned int CmdStateSet(u8 aPath1, u8 aPath2, TBehaviorCode aBehaviorCode, u8 aPrm);
		unsigned int CmdStateSet(u8 aPath1, u8 aPath2, u8 aPath3, TBehaviorCode aBehaviorCode, u8 aPrm);
		
		unsigned int CmdStateSetViaUserCode();
		
		unsigned int CmdStateRead();
		unsigned int CmdStateReadViaUserCode();
		unsigned int CmdStateReport();
		
		void GetEpUserCodeAreaNumDevType(unsigned char aP0, unsigned char aP1, unsigned int *pUc, unsigned short *pAreaNum, unsigned char *pDevType);
		
		int CheckPathKissAss(unsigned char aP0, unsigned char aP1);
		
		int CheckOutBufFastFinish();
		void SendCmdPowerOnFast();
		
		void ProcRxMsg(void);
		void TaskSecondUpdate();
		void ForceSecondUpdate();

};


























#endif


