#include "ProtoFecBus.h"
#include "Runtime.h"

extern "C" {
	#include "uart_fec_std_drv.h"
	#include "fdcan_task.h"
}

#define Priority0	0
#define Priority1	1
#define Priority2	2
#define Priority3	3

#define FecFrmTX 	0
#define FecFrmACK 	1
#define FecFrmRX 	1
#define FecFrmRXFORMMAS 	0

#define FecCtlAddr 1

#define FecHeader 0x7E
#define FecEnding 0x7E

#define CommAckTimeout  59//6s通讯超时  unit 100ms

//(1024*1024)
#define dFecBus_AddrCount 	62//2-63
#define dFecBus_BufEntrySize_Event	16

//16 bytes 为单位
#define dFecBus_OneBufCount							(1024)
#define dFecBus_DownEventBufCount				(1024)
#define dFecBus_UpEventBufCount					(1024*62)
#define dFecBus_CurrentEventBufCount		(1024*62)
#define dFecBus_HistoryEventBufCount		(1024)

#define dAddrSdram_FECDownEventBuf			dAddrSdram_FECStdBuf
#define dAddrSdram_FECUpEventBuf				(dAddrSdram_FECDownEventBuf + dFecBus_DownEventBufCount)
#define dAddrSdram_FECCurrentEventBuf		(dAddrSdram_FECUpEventBuf + dFecBus_UpEventBufCount)
#define dAddrSdram_FECHistoryEventBuf 	(dAddrSdram_FECCurrentEventBuf + dFecBus_CurrentEventBufCount)

void TFecBus::Init()
{
	u32 x = 0;
	u32 y = 0;
	u32 aAddr;
	
	uMsgOutIndex = 1;
	RxGetFlag = 0;
	RxHandleFlag = 0;
	TxSetFlag = 0;
	
	RxMsg.avalibel = 0;
	RxMsg.UsingMsgIndex = 0;
	RxMsg.FrmCount = 0;
	for(x=0;x<128;x++)
		for(y=0;y<16;y++)
			RxMsg.body[x].D8[y] = 0;
	
	RxMsgState = ackMsgSectionEnd;
	
	for(x=0;x<258;x++){
		uDataRX.da32[x] = 0;
		uDataTX.da32[x] = 0;
	}
	
	OnTransmite.AckOk = 1;
	OnTransmite.RetryTimes = 0;
	OnTransmite.OnGoing = 0;
	OnTransmite.TimeOutTick = 0;
	
	CommPrm.CuuerntAddr = 2;
	CommPrm.Phase = FecPolling;
	CommPrm.State = FecCommExit;
	//CommPrm.Phase = FecSetUpComm;
	//CommPrm.State = FecCommQueryVer44;
	CommPrm.SetDownEventFlag = 0;
	CommPrm.SetDownCmdFlag = 0;
	CommPrm.TimeoutTick = 0;
	CommPrm.NoAckTick = 0;
	
	CommPrm.SetDownPath.Addr = 2;
	
	for(x=0;x<64;x++){
		CommPrm.Register[x] = 0;
	}
	
	CommPrm.DownEventCount = 0;
	for(x=0; x<dFecBus_DownEventBufCount; x++){
		aAddr = dAddrSdram_FECDownEventBuf + (x * dFecBus_BufEntrySize_Event);
		for(y = 0;y<(dFecBus_BufEntrySize_Event/4);y++)
			*(volatile unsigned int *)(aAddr + (y*4)) = 0;
	} 
	
	for(y = 0;y<64;y++){
		CommPrm.UpEventCount[y] = 0;
		CommPrm.UpEventSRTick[y] = 0;
	}
	for(x=0; x<dFecBus_UpEventBufCount; x++){
		aAddr = dAddrSdram_FECUpEventBuf + (x * dFecBus_BufEntrySize_Event);
		for(y = 0;y<(dFecBus_BufEntrySize_Event/4);y++)
			*(volatile unsigned int *)(aAddr + (y*4)) = 0;
	}
	
	for(y = 0;y<64;y++){
		CommPrm.CurrentEventCount[y] = 0;
		CommPrm.CurrentEventSRTick[y] = 0;
	}
	for(x=0; x<dFecBus_CurrentEventBufCount; x++){
		aAddr = dAddrSdram_FECCurrentEventBuf + (x * dFecBus_BufEntrySize_Event);
		for(y = 0;y<(dFecBus_BufEntrySize_Event/4);y++)
			*(volatile unsigned int *)(aAddr + (y*4)) = 0;
	}
	
	CommPrm.HistoryEventCount = 0;
	for(x=0; x<dFecBus_HistoryEventBufCount; x++){
		aAddr = dAddrSdram_FECHistoryEventBuf + (x * dFecBus_BufEntrySize_Event);
		for(y = 0;y<(dFecBus_BufEntrySize_Event/4);y++)
			*(volatile unsigned int *)(aAddr + (y*4)) = 0;
	}
}

void TFecBus::ResetCallBack()
{
	Init();
}

void TFecBus::Init(u8 aAddr, TFecBusType aBusType)
{
	unsigned int i,x;
	PublishMsgRxList.PollIndex = 0;
	PublishMsgRxList.Recent.PollIndex = 0;
	for(i=0; i<FecPublishEventRxBufCount; i++){
		PublishMsgRxList.Items[i].State = 0;
	}
	for(i=0; i<FecRecentUsingCount; i++){
		PublishMsgRxList.Recent.List[i] = 0;	
	}
	BusType = aBusType;
}

void TFecBus::MsgOutIndexInc()
{
	uMsgOutIndex++;
	if(uMsgOutIndex > 63)uMsgOutIndex = 1;
}

u16 TFecBus::Crc16(u8 *pD, u8 Len) const
{
	u16 aCrc = 0xFFFF;
	for (int i = 0; i < Len; i++){
		aCrc ^= static_cast<unsigned short>(pD[i]);
		for (int j = 0; j < 8; j++){
			if (aCrc & 0x0001){
			    aCrc = (aCrc >> 1) ^ 0xA001;
			}else{
			    aCrc = aCrc >> 1;
			}
		}
	}
	return aCrc;
}

void TFecBus::getSysTime(void)
{
	dateTime.Year = (DateTime.Date.Split.Year/16*10) + (DateTime.Date.Split.Year & 0x0F);
	dateTime.Mon  = (DateTime.Date.Split.Month/16*10) + (DateTime.Date.Split.Month & 0x0F);
	dateTime.Day  = (DateTime.Date.Split.Day/16*10) + (DateTime.Date.Split.Day & 0x0F);
	dateTime.Hour = (DateTime.Time.Split.Hour/16*10) + (DateTime.Time.Split.Hour & 0x0F);
	dateTime.Min  = (DateTime.Time.Split.Minute/16*10) + (DateTime.Time.Split.Minute & 0x0F);
	dateTime.Sec  = (DateTime.Time.Split.Second/16*10) + (DateTime.Time.Split.Second & 0x0F);
}

u32 TFecBus::GetNewPublishCount(void)
{
	u32 i, cnt;
	cnt = 0;
	for(i=0; i<FecRecentUsingCount; i++){
		if(PublishMsgRxList.Recent.List[i] == 1){
			
		}
	}
	for(i=0; i<FecPublishEventRxBufCount; i++){
		if(PublishMsgRxList.Items[i].State == 1) 
			cnt++;
	}
	return cnt;
}

u32 TFecBus::GetNewPublishEmerGyCount(void)
{
	u32 i, cnt;
	cnt = 0;
	for(i=0; i<FecPublishEventRxBufCount; i++){
		if(PublishMsgRxList.Items[i].State == 1){ 
			if(PublishMsgRxList.Items[i].Body[0] == 0x11)
				cnt++;
		}
	}
	return cnt;
}

void TFecBus::SetBusType(TFecBusType bsType)
{
	BusType = bsType;
}

u8 TFecBus::FindIdleMsgIndex(void)
{
	//return 1..63, else is Busy Now
	u32 i,n, fd;
	fd = 0;
	n = MsgReference.PollIndex +1;
	for(i=n; i<64; i++){
		if(MsgReference.body[i].Busy == 0){
			return i;
		}
	}
	for(i=0; i<n; i++){
		if(MsgReference.body[i].Busy == 0){
			return i;
		}
	}
	return 0;
}

//----------------------------------------------RX--------------------------------------------
void TFecBus::iBufProcess()
{
	u32 i = 0;
	u32 a = 0;
	u32 x = 0;
	
	if(RxGetFlag){
		RxGetFlag = 0;
		
		OnTransmite.AckOk = 1;
		OnTransmite.RetryTimes = 0;
		OnTransmite.OnGoing = 0;
		OnTransmite.TimeOutTick = 0;
		
		if(RxMsg.UsingMsgIndex){
			RxMsg.UsingMsgIndex = 0;
			if((2 == RxMsg.body[0].spl.Dlen)&&(0x0F == RxMsg.body[0].spl.DPFC[0])&&(0 == RxMsg.body[0].spl.DPFC[1])){
				uDataRX.body.FrmType = RxMsg.body[0].spl.FrmType;
				uDataRX.body.DestAddr = RxMsg.body[0].spl.DestAddr;
				uDataRX.body.Priority = RxMsg.body[0].spl.Priority;
				uDataRX.body.SrcAddr = RxMsg.body[0].spl.SrcAddr;
				uDataRX.body.MsgIndex = RxMsg.body[0].spl.MsgIndex;
			
				if(!RxMsg.FrmCount)return;
				uDataRX.body.Dlen = (RxMsg.FrmCount - 1) * 8 + RxMsg.body[RxMsg.FrmCount].spl.Dlen;
			
				if(uDataRX.body.Dlen > (128*8))return;
			
				for(i=1;i<=RxMsg.FrmCount;i++){
					for(x=0;x<RxMsg.body[i].spl.Dlen;x++){
						uDataRX.body.DPFC[a] = RxMsg.body[i].spl.DPFC[x];
						a++;
					}
				}
				RxHandleFlag = 1;
			}
		}else{
			if(RxMsg.body[0].spl.Dlen <= 8){
				uDataRX.body.FrmType = RxMsg.body[0].spl.FrmType;
				uDataRX.body.DestAddr = RxMsg.body[0].spl.DestAddr;
				uDataRX.body.Priority = RxMsg.body[0].spl.Priority;
				uDataRX.body.SrcAddr = RxMsg.body[0].spl.SrcAddr;
				uDataRX.body.MsgIndex = RxMsg.body[0].spl.MsgIndex;
				uDataRX.body.Dlen = RxMsg.body[0].spl.Dlen;
				
				for(i=0;i<RxMsg.body[0].spl.Dlen;i++){
					uDataRX.body.DPFC[i] = RxMsg.body[0].spl.DPFC[i];
				}
				
				RxHandleFlag = 1;
			}
		}
	}
}

void TFecBus::uDataRXTask()
{
	//uMsgInIndex == uMsgOutIndex
	//uDataRX.body.DPFC[0] == uDataTX.body.DPFC[0]
	if((0x01 == uDataRX.body.DestAddr)&&(CommPrm.CuuerntAddr == uDataRX.body.SrcAddr)){//(uDataRX.body.SrcAddr > 1)&&(uDataRX.body.SrcAddr < 64)&&
		CommPrm.GetAddr = uDataRX.body.SrcAddr;
		
		if(FecFrmRXFORMMAS == uDataRX.body.FrmType){//接收2-63主发
			switch(uDataRX.body.DPFC[0]){
				case FecFunInformedEmergencyEvent: //17 通告紧急事件
					if((FecPolling == CommPrm.Phase)&&(FecCommPolling33Ack == CommPrm.State)){
						CommPrm.AckStatus = 3;
						fMsgRX_Cmd17To19n41_42(CommPrm.GetAddr,&CommPrm.UpEventData);
						AddUpEventList(CommPrm.GetAddr, &CommPrm.UpEventData);
					}else
					if((FecDownEvent == CommPrm.Phase)&&(FecCommPolling33Ack == CommPrm.State)){
						CommPrm.AckStatus = 2;
						fMsgRX_Cmd17To19n41_42(CommPrm.GetAddr,&CommPrm.UpEventData);
						AddUpEventList(CommPrm.GetAddr, &CommPrm.UpEventData);
					}
					break;
				
				case FecFunInformedGeneralEvent: //18 通告一般事件
					if((FecPolling == CommPrm.Phase)&&(FecCommPolling33Ack == CommPrm.State)){
						CommPrm.AckStatus = 3;
						fMsgRX_Cmd17To19n41_42(CommPrm.GetAddr,&CommPrm.UpEventData);
						AddUpEventList(CommPrm.GetAddr, &CommPrm.UpEventData);
					}else
					if((FecDownEvent == CommPrm.Phase)&&(FecCommPolling33UpAck == CommPrm.State)){
						CommPrm.AckStatus = 2;
						fMsgRX_Cmd17To19n41_42(CommPrm.GetAddr,&CommPrm.UpEventData);
						AddUpEventList(CommPrm.GetAddr, &CommPrm.UpEventData);
					}
					break;
				
				case FecFunInformedAdjustEvent: //19 通告调试事件
					if((FecPolling == CommPrm.Phase)&&(FecCommPolling33Ack == CommPrm.State)){
						CommPrm.AckStatus = 3;
						fMsgRX_Cmd17To19n41_42(CommPrm.GetAddr,&CommPrm.UpEventData);
						AddUpEventList(CommPrm.GetAddr, &CommPrm.UpEventData);
					}else
					if((FecDownEvent == CommPrm.Phase)&&(FecCommPolling33UpAck == CommPrm.State)){
						CommPrm.AckStatus = 2;
						fMsgRX_Cmd17To19n41_42(CommPrm.GetAddr,&CommPrm.UpEventData);
						AddUpEventList(CommPrm.GetAddr, &CommPrm.UpEventData);
					}
					break;
				
				case FecFunInformedHeartbeat: //20 通告心跳
					break;
				
				default: //未识别命令
					break;
			}
		}else
		if(FecFrmRX == uDataRX.body.FrmType){//接收2-63回复
			switch(uDataRX.body.DPFC[0]){
				case FecFunSyncSysTick: //0 同步系统节拍
					if((FecDownCmd == CommPrm.Phase)&&(FecCommSyncSysTick00Ack == CommPrm.State)){
						CommPrm.AckStatus = 1;
					}
					break;		
		
				case FecFunSysReset: //1 系统复位
					if((FecDownCmd == CommPrm.Phase)&&(FecCommSysReset01Ack == CommPrm.State)){
						CommPrm.AckStatus = 1;
					}
					break;
				
				case FecFunSysMute: //2 系统消音
					if((FecDownCmd == CommPrm.Phase)&&(FecCommSysMute02Ack == CommPrm.State)){
						CommPrm.AckStatus = 1;
					}
					break;
				
				case FecFunSysSlefCheck: //3 系统自检
					if((FecDownCmd == CommPrm.Phase)&&(FecCommSysSlefCheck03Ack == CommPrm.State)){
						CommPrm.AckStatus = 1;
					}
					break;
				
				case FecFunSyncTime: //4 广播时钟
					if((FecSetUpComm == CommPrm.Phase)&&(FecCommSyncTime04Ack == CommPrm.State)){
						CommPrm.AckStatus = 1;
					}else
					if((FecDownCmd == CommPrm.Phase)&&(FecCommSyncTime04Ack == CommPrm.State)){
						CommPrm.AckStatus = 1;
					}
					break;
				
				case FecFunPublishEmergencyEvent: //5 通告紧急事件
					if((FecDownEvent == CommPrm.Phase)&&(FecCommDownEvent05Ack == CommPrm.State)){
						CommPrm.AckStatus = 1;
					}
					break;
				
				case FecFunPublishGeneralEvent: //6 通告一般事件
					if((FecDownEvent == CommPrm.Phase)&&(FecCommDownEvent06Ack == CommPrm.State)){
						CommPrm.AckStatus = 1;
					}
					break;
				
				case FecFunPublishAdjustEvent: //7 通告调试事件
					if((FecDownEvent == CommPrm.Phase)&&(FecCommDownEvent07Ack == CommPrm.State)){
						CommPrm.AckStatus = 1;
					}
					break;
	
				case FecFunStateAck: //15 状态码应答，或结束帧标志
					if((FecSetUpComm == CommPrm.Phase)&&(FecCommQueryCurrentEvent41Ack == CommPrm.State)){
						fMsgRX_Cmd15(CommPrm.GetAddr,CommPrm.AckCode);
						//CommPrm.AckStatus = 1;//1接收正确(在41命令)  2当前事件接收完成
						if(ackEventOver == CommPrm.AckCode)CommPrm.AckStatus = 2;
					}else
					if((FecDownCmd == CommPrm.Phase)&&(FecCommQueryCurrentEvent41Ack == CommPrm.State)){
						fMsgRX_Cmd15(CommPrm.GetAddr,CommPrm.AckCode);
						//CommPrm.AckStatus = 1;//1接收正确(在41命令)  2当前事件接收完成
						if(ackEventOver == CommPrm.AckCode)CommPrm.AckStatus = 2;
					}else
					if((FecDownCmd == CommPrm.Phase)&&(FecCommQueryHistoryEvent42Ack == CommPrm.State)){
						fMsgRX_Cmd15(CommPrm.GetAddr,CommPrm.AckCode);
						//CommPrm.AckStatus = 1;//1接收正确(在41命令)  2当前事件接收完成
						if(ackEventOver == CommPrm.AckCode)CommPrm.AckStatus = 2;
					}
					break;
	
				case FecFunInspectionDevice: //33 设备巡检
					if((FecPolling == CommPrm.Phase)&&(FecCommPolling33Ack == CommPrm.State)){
						CommPrm.AckStatus = 1;
					}else
					if((FecDownCmd == CommPrm.Phase)&&(FecCommPolling33Ack == CommPrm.State)){
						CommPrm.AckStatus = 1;
					}else
					if((FecDownEvent == CommPrm.Phase)&&(FecCommPolling33UpAck == CommPrm.State)){
						CommPrm.AckStatus = 3;
					}
					break;
				
				case FecFunQueryDeviceState: //34 查设备状态
					if((FecDownCmd == CommPrm.Phase)&&(FecCommQueryDeviceState34Ack == CommPrm.State)){
						fMsgRX_Cmd34(CommPrm.CuuerntAddr, CommPrm.GetCmd34DeviceState);
						CommPrm.AckStatus = 1;
					}
					break;
				
				case FecFunQueryDeviceConfig: //35 查设备配置
					if((FecDownCmd == CommPrm.Phase)&&(FecCommQueryDeviceConfig35Ack == CommPrm.State)){
						fMsgRX_Cmd35(CommPrm.CuuerntAddr, CommPrm.GetCmd35ConfigCode);
						CommPrm.AckStatus = 1;
					}
					break;
				
				case FecFunQueryDeviceIdf: //36 查设备标识
					if((FecDownCmd == CommPrm.Phase)&&(FecCommQueryDeviceIdf36Ack == CommPrm.State)){
						fMsgRX_Cmd36(CommPrm.CuuerntAddr, CommPrm.GetCmd36DeviceIdf);
						CommPrm.AckStatus = 1;
					}
					break;
				
				case FecFunQueryDeviceParameter: //37 查设备参量
					if((FecDownCmd == CommPrm.Phase)&&(FecCommQueryDeviceParameter37Ack == CommPrm.State)){
						fMsgRX_Cmd37(CommPrm.CuuerntAddr, CommPrm.GetCmd37DevicePrmType, CommPrm.GetCmd37DevicePrmValue);
						CommPrm.AckStatus = 1;
					}
					break;
				
				case FecFunQueryDeviceDescp: //38 查设备注释
					if((FecDownCmd == CommPrm.Phase)&&(FecCommQueryDeviceDescp38Ack == CommPrm.State)){
						fMsgRX_Cmd38_40(CommPrm.CuuerntAddr, &CommPrm.GetCmd38To40Data);
						CommPrm.AckStatus = 1;
					}
					break;
				
				case FecFunQueryDeviceProgram: //39 查设备编程
					if((FecDownCmd == CommPrm.Phase)&&(FecCommQueryDeviceProgram39Ack == CommPrm.State)){
						fMsgRX_Cmd38_40(CommPrm.CuuerntAddr, &CommPrm.GetCmd38To40Data);
						CommPrm.AckStatus = 1;
					}
					break;
				
				case FecFunQueryDeviceRegisterInfo: //40 查注册登记信息
					if((FecDownCmd == CommPrm.Phase)&&(FecCommQueryDeviceRegisterInfo40Ack == CommPrm.State)){
						fMsgRX_Cmd38_40(CommPrm.CuuerntAddr, &CommPrm.GetCmd38To40Data);
						CommPrm.AckStatus = 1;
					}
					break;
				
				case FecQueryCurrentEvent: //41 查设备当前事件
					if((FecSetUpComm == CommPrm.Phase)&&(FecCommQueryCurrentEvent41Ack == CommPrm.State)){
						fMsgRX_Cmd17To19n41_42(CommPrm.GetAddr,&CommPrm.CurrentEventData);
						AddCurrentEventList(CommPrm.GetAddr, &CommPrm.CurrentEventData);
						//CommPrm.getCurrentEventTick++;
						CommPrm.AckStatus = 1;
					}else
					if((FecDownCmd == CommPrm.Phase)&&(FecCommQueryCurrentEvent41Ack == CommPrm.State)){
						fMsgRX_Cmd17To19n41_42(CommPrm.GetAddr,&CommPrm.CurrentEventData);
						AddCurrentEventList(CommPrm.GetAddr, &CommPrm.CurrentEventData);
						//CommPrm.getCurrentEventTick++;
						CommPrm.AckStatus = 1;
					}
					break;
				
				case FecQueryHistoryEvent: //42 查设备历史事件
					if((FecDownCmd == CommPrm.Phase)&&(FecCommQueryHistoryEvent42Ack == CommPrm.State)){
						fMsgRX_Cmd17To19n41_42(CommPrm.GetAddr,&CommPrm.HistoryEventData);
						AddHistoryEventList(&CommPrm.HistoryEventData);
						CommPrm.AckStatus = 1;
					}
					break;
				
				case FecStopQueryDeviceEvent: //43 停止查询设备事件
					if((FecDownCmd == CommPrm.Phase)&&(FecCommStopQueryDeviceEvent43Ack == CommPrm.State)){
						CommPrm.AckStatus = 1;
					}
					break;
				
				case FecQueryFECBusVer: //44 查FECBus协议版本号
					if((FecSetUpComm == CommPrm.Phase)&&(FecCommQueryVer44Ack == CommPrm.State)){
						fMsgRX_Cmd44(CommPrm.GetAddr,CommPrm.GetCmd44Ver);
						CommPrm.AckStatus = 1;
					}else
					if((FecPolling == CommPrm.Phase)&&(FecCommPolling33Ack == CommPrm.State)){
						fMsgRX_Cmd44(CommPrm.GetAddr,CommPrm.GetCmd44Ver);
						CommPrm.AckStatus = 2;//跳到注册
					}else
					if((FecDownCmd == CommPrm.Phase)&&(FecCommQueryVer44Ack == CommPrm.State)){
						fMsgRX_Cmd44(CommPrm.GetAddr,CommPrm.GetCmd44Ver);
						CommPrm.AckStatus = 1;
					}
					break;
				
				case FecQueryDeviceList: //45 查设备列表
					if((FecDownCmd == CommPrm.Phase)&&(FecCommQueryDeviceList45Ack == CommPrm.State)){
						fMsgRX_Cmd45(CommPrm.GetAddr,&CommPrm.GetCmd45Data);
						CommPrm.AckStatus = 1;
					}
					break;
				
				default: //未识别命令
					break;
			}
		}
	}else{
		//地址错误
		//参数错误
	}
}

unsigned int TFecBus::fMsgRX_Cmd00To07(u8 aSrcAddr)
{
	if((aSrcAddr < 2)||(aSrcAddr > 63))return 1;
	
	aSrcAddr = uDataRX.body.SrcAddr;
	
	return 0;
}

unsigned int TFecBus::fMsgRX_Cmd15(u8 aSrcAddr, u8 aState)
{
	if((aSrcAddr < 2)||(aSrcAddr > 63))return 1;
	
	aSrcAddr = uDataRX.body.SrcAddr;
	aState = uDataRX.body.DPFC[1];
	
	return 0;
}

unsigned int TFecBus::fMsgRX_Cmd17To19n41_42(u8 aSrcAddr, TFecEventBufBody * pFecEvent)
{
	unsigned int i = 0;
	
	if((aSrcAddr < 2)||(aSrcAddr > 63))return 1;
	
	aSrcAddr = uDataRX.body.SrcAddr;
	for(i= 0;i<16;i++){
		pFecEvent->D8[i] = uDataRX.body.DPFC[i+1];
	}
	
	return 0;
}

u32 TFecBus::fMsgRX_Cmd33(u8 aSrcAddr)
{
	if((aSrcAddr < 2)||(aSrcAddr > 63))return 1;
	
	aSrcAddr = uDataRX.body.SrcAddr;
	
	return 0;
}

u32 TFecBus::fMsgRX_Cmd34(u8 aSrcAddr, TFecStateCode aStateCode)
{
	unsigned short aState;
	
	if((aSrcAddr < 2)||(aSrcAddr > 63))return 1;

	aSrcAddr = uDataRX.body.SrcAddr;
	
	aState = uDataRX.body.DPFC[2];
	aState<<=8;
	aState|= uDataRX.body.DPFC[1];
	aStateCode.D16 = aState;

	return 0;
}

u32 TFecBus::fMsgRX_Cmd35(u8 aSrcAddr, u16 aConfigCode)
{
	u16 aD16;
	
	if((aSrcAddr < 2)||(aSrcAddr > 63))return 1;
	
	aSrcAddr = uDataRX.body.SrcAddr;
	
	aD16 = uDataRX.body.DPFC[2];
	aD16<<=8;
	aD16|= uDataRX.body.DPFC[1];
	aConfigCode = aD16;
	
	return 0;
}

u32 TFecBus::fMsgRX_Cmd36(u8 aSrcAddr, u8 * aIdfCode)
{
	u32 i = 0;
	
	if((aSrcAddr < 2)||(aSrcAddr > 63))return 1;
	
	aSrcAddr = uDataRX.body.SrcAddr;
	
	for(i=0;i<7;i++)
		aIdfCode[i] = uDataRX.body.DPFC[i+1];
	
	return 0;
}

u32 TFecBus::fMsgRX_Cmd37(u8 aSrcAddr, TParameterType aPrmType, u16 aPrm)
{
	u16 aD16 = 0;
	
	if((aSrcAddr < 2)||(aSrcAddr > 63))return 1;
	
	aSrcAddr = uDataRX.body.SrcAddr;

	aPrmType = (TParameterType)uDataRX.body.DPFC[1];
	aD16 = uDataRX.body.DPFC[3];
	aD16<<=8;
	aD16|= uDataRX.body.DPFC[2];
	aPrm = aD16;

	return 0;
}

u32 TFecBus::fMsgRX_Cmd38_40(u8 aSrcAddr, TGetCmd38_40Data * pData)
{
	u32 i= 0;
	
	aSrcAddr = uDataRX.body.SrcAddr;
	if((aSrcAddr < 2)||(aSrcAddr > 63))return 1;
	
	pData->CtlNum = uDataRX.body.DPFC[1];
	pData->UnitNum = uDataRX.body.DPFC[2];
	pData->DevNum = uDataRX.body.DPFC[3];
	pData->Len = uDataRX.body.DPFC[4];
	
	for(i=0;i<pData->Len;i++)
		pData->Value[i] = uDataRX.body.DPFC[i+5];
	
	return 0;
}

u32 TFecBus::fMsgRX_Cmd43(u8 aSrcAddr)
{
	if((aSrcAddr < 2)||(aSrcAddr > 63))return 1;
	
	aSrcAddr = uDataRX.body.SrcAddr;
	
	return 0;
}

u32 TFecBus::fMsgRX_Cmd44(u8 aSrcAddr, u16 aVer)
{
	u16 aD16 = 0;
	
	if((aSrcAddr < 2)||(aSrcAddr > 63))return 1;
	
	aSrcAddr = uDataRX.body.SrcAddr;
	
	aD16 = uDataRX.body.DPFC[2];
	aD16<<=8;
	aD16|= uDataRX.body.DPFC[1];
	aVer = aD16;
	
	return 0;
}

u32 TFecBus::fMsgRX_Cmd45(u8 aSrcAddr, TGetCmd45Data * pTData)
{
	unsigned int i = 0;
	
	if((aSrcAddr < 2)||(aSrcAddr > 63))return 1;
	
	aSrcAddr = uDataRX.body.SrcAddr;
	
	if(1 == CommPrm.GetCmd45Data.type){
		CommPrm.GetCmd45Data.Count = uDataRX.body.DPFC[1];
		
		for(i=0;i<CommPrm.GetCmd45Data.Count;i++){
			CommPrm.GetCmd45Data.Body.d8[i*3+0] = uDataRX.body.DPFC[i*3+2];
			CommPrm.GetCmd45Data.Body.d8[i*3+1] = uDataRX.body.DPFC[i*3+3];
			CommPrm.GetCmd45Data.Body.d8[i*3+2] = uDataRX.body.DPFC[i*3+4];
		}
	}else
	if(2 == CommPrm.GetCmd45Data.type){
		CommPrm.GetCmd45Data.CtlNum = uDataRX.body.DPFC[1];
		CommPrm.GetCmd45Data.Count = uDataRX.body.DPFC[2];
		
		for(i=0;i<CommPrm.GetCmd45Data.Count;i++){
			CommPrm.GetCmd45Data.Body.d8[i*3+0] = uDataRX.body.DPFC[i*3+3];
			CommPrm.GetCmd45Data.Body.d8[i*3+1] = uDataRX.body.DPFC[i*3+4];
			CommPrm.GetCmd45Data.Body.d8[i*3+2] = uDataRX.body.DPFC[i*3+5];
		}
	}else
	if(3 == CommPrm.GetCmd45Data.type){
		CommPrm.GetCmd45Data.CtlNum = uDataRX.body.DPFC[1];
		CommPrm.GetCmd45Data.UnitNum = uDataRX.body.DPFC[2];
		CommPrm.GetCmd45Data.Count = uDataRX.body.DPFC[3];
		
		for(i=0;i<CommPrm.GetCmd45Data.Count;i++){
			CommPrm.GetCmd45Data.Body.d8[i*3+0] = uDataRX.body.DPFC[i*3+4];
			CommPrm.GetCmd45Data.Body.d8[i*3+1] = uDataRX.body.DPFC[i*3+5];
			CommPrm.GetCmd45Data.Body.d8[i*3+2] = uDataRX.body.DPFC[i*3+6];
		}
	}else
	if(4 == CommPrm.GetCmd45Data.type){
		CommPrm.GetCmd45Data.CtlNum = uDataRX.body.DPFC[1];
		CommPrm.GetCmd45Data.UnitNum = uDataRX.body.DPFC[2];
		CommPrm.GetCmd45Data.DevNum = uDataRX.body.DPFC[3];
		CommPrm.GetCmd45Data.Count = uDataRX.body.DPFC[4];
		
		for(i=0;i<CommPrm.GetCmd45Data.Count;i++){
			CommPrm.GetCmd45Data.Body.d8[i*3+0] = uDataRX.body.DPFC[i*3+5];
			CommPrm.GetCmd45Data.Body.d8[i*3+1] = uDataRX.body.DPFC[i*3+6];
			CommPrm.GetCmd45Data.Body.d8[i*3+2] = uDataRX.body.DPFC[i*3+7];
		}
	}
	
	return 0;
}

//-----------------------------------------------------TX--------------------------------------------
void TFecBus::fMsgTX00_SysSyncTick(u8 aDestAddr)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority0;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 1;
	uDataTX.body.DPFC[0] = FecFunSyncSysTick;
	
	uSetTXData();
}

void TFecBus::fMsgTX01_SysReset(u8 aDestAddr, u8 aCtlNum)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority1;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 2;
	uDataTX.body.DPFC[0] = FecFunSysReset;
	uDataTX.body.DPFC[1] = aCtlNum;
	
	uSetTXData();
}

void TFecBus::fMsgTX02_SysMute(u8 aDestAddr, u8 aCtlNum)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority1;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 2;
	uDataTX.body.DPFC[0] = FecFunSysMute;
	uDataTX.body.DPFC[1] = aCtlNum;	
	
	uSetTXData();
}

void TFecBus::fMsgTX03_SysSelfCheck(u8 aDestAddr, u8 aCtlNum)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority3;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 2;
	uDataTX.body.DPFC[0] = FecFunSysSlefCheck;
	uDataTX.body.DPFC[1] = aCtlNum;
	
	uSetTXData();
}

void TFecBus::fMsgTX04_SyncTime(u8 aDestAddr, u8 aCtlNum, u8 aY, u8 aMon, u8 aDay, u8 aH, u8 aMin, u8 aSec)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority3;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 8;
	uDataTX.body.DPFC[0] = FecFunSyncTime;
	uDataTX.body.DPFC[1] = aCtlNum;
	uDataTX.body.DPFC[2] = aY;
	uDataTX.body.DPFC[3] = aMon;
	uDataTX.body.DPFC[4] = aDay;
	uDataTX.body.DPFC[5] = aH;
	uDataTX.body.DPFC[6] = aMin;
	uDataTX.body.DPFC[7] = aSec;
	
	uSetTXData();
}

void TFecBus::fMsgTX05_PublishEmergencyEvent(u8 aDestAddr, TFecEventBufBody * pEvent)
{
	u32 i = 0;
	
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority1;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 17;
	uDataTX.body.DPFC[0] = FecFunPublishEmergencyEvent;
	for(i=0;i<16;i++){
		uDataTX.body.DPFC[i+1] = pEvent->D8[i];
	}
	
	uSetTXData();
}

void TFecBus::fMsgTX06_PublishGeneralEvent(u8 aDestAddr, TFecEventBufBody * pEvent)
{
	u32 i = 0;
	
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority3;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 17;
	uDataTX.body.DPFC[0] = FecFunPublishGeneralEvent;
	for(i=0;i<16;i++){
		uDataTX.body.DPFC[i+1] = pEvent->D8[i];
	}
	
	uSetTXData();
}

void TFecBus::fMsgTX07_PublishAdjustEvent(u8 aDestAddr, TFecEventBufBody * pEvent)
{
	u32 i = 0;
	
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority3;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 17;
	uDataTX.body.DPFC[0] = FecFunPublishAdjustEvent;
	for(i=0;i<16;i++){
		uDataTX.body.DPFC[i+1] = pEvent->D8[i];
	}
	
	uSetTXData();
}

void TFecBus::fMsgTX15_Ack_StateAck(u8 aDestAddr, TFecAckCode aState)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmACK;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority3;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 2;
	uDataTX.body.DPFC[0] = FecFunStateAck;
	uDataTX.body.DPFC[1] = aState;
	
	uSetTXData();
}

void TFecBus::fMsgRpy17_Ack_PublishEmergencyEvent(u8 aDestAddr)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmACK;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority1;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 1;
	uDataTX.body.DPFC[0] = FecFunInformedEmergencyEvent;
	
	uSetTXData();
}

void TFecBus::fMsgRpy18_Ack_InformedGeneralEvent(u8 aDestAddr)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmACK;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority3;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 1;
	uDataTX.body.DPFC[0] = FecFunInformedGeneralEvent;
	
	uSetTXData();
}

void TFecBus::fMsgRpy19_Ack_InformedAdjustEvent(u8 aDestAddr)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmACK;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority3;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 1;
	uDataTX.body.DPFC[0] = FecFunInformedAdjustEvent;
	
	uSetTXData();
}

void TFecBus::fMsgTX33_InspectionDevice(u8 aDestAddr)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority2;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 1;
	uDataTX.body.DPFC[0] = FecFunInspectionDevice;
	
	uSetTXData();
}

void TFecBus::fMsgTX34_QueryDeviceState(u8 aDestAddr)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority2;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 1;
	uDataTX.body.DPFC[0] = FecFunQueryDeviceState;
	
	uSetTXData();
}

void TFecBus::fMsgTX34_QueryDeviceState(u8 aDestAddr, u8 aCtlNum)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority2;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 2;
	uDataTX.body.DPFC[0] = FecFunQueryDeviceState;
	uDataTX.body.DPFC[1] = aCtlNum;
	
	uSetTXData();
}

void TFecBus::fMsgTX34_QueryDeviceState(u8 aDestAddr, u8 aCtlNum, u8 aUnitNum)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority2;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 3;
	uDataTX.body.DPFC[0] = FecFunQueryDeviceState;
	uDataTX.body.DPFC[1] = aCtlNum;
	uDataTX.body.DPFC[2] = aUnitNum;
	
	uSetTXData();
}

void TFecBus::fMsgTX34_QueryDeviceState(u8 aDestAddr, u8 aCtlNum, u8 aUnitNum, u8 aDev)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority2;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 4;
	uDataTX.body.DPFC[0] = FecFunQueryDeviceState;
	uDataTX.body.DPFC[1] = aCtlNum;
	uDataTX.body.DPFC[2] = aUnitNum;
	uDataTX.body.DPFC[3] = aDev;
	
	uSetTXData();
}

void TFecBus::fMsgTX35_QueryDeviceConfig(u8 aDestAddr)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority2;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 1;
	uDataTX.body.DPFC[0] = FecFunQueryDeviceConfig;
	
	uSetTXData();
}

void TFecBus::fMsgTX35_QueryDeviceConfig(u8 aDestAddr, u8 aCtlNum)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority2;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 2;
	uDataTX.body.DPFC[0] = FecFunQueryDeviceConfig;
	uDataTX.body.DPFC[1] = aCtlNum;
	
	uSetTXData();
}

void TFecBus::fMsgTX35_QueryDeviceConfig(u8 aDestAddr, u8 aCtlNum, u8 aUnitNum)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority2;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 3;
	uDataTX.body.DPFC[0] = FecFunQueryDeviceConfig;
	uDataTX.body.DPFC[1] = aCtlNum;
	uDataTX.body.DPFC[2] = aUnitNum;
	
	uSetTXData();
}

void TFecBus::fMsgTX35_QueryDeviceConfig(u8 aDestAddr, u8 aCtlNum, u8 aUnitNum, u8 aDev)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority2;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 4;
	uDataTX.body.DPFC[0] = FecFunQueryDeviceConfig;
	uDataTX.body.DPFC[1] = aCtlNum;
	uDataTX.body.DPFC[2] = aUnitNum;
	uDataTX.body.DPFC[3] = aDev;
	
	uSetTXData();
}

void TFecBus::fMsgTX36_QueryDeviceIdf(u8 aDestAddr)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority2;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 1;
	uDataTX.body.DPFC[0] = FecFunQueryDeviceIdf;
	
	uSetTXData();
}
void TFecBus::fMsgTX36_QueryDeviceIdf(u8 aDestAddr, u8 aCtlNum)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority2;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 2;
	uDataTX.body.DPFC[0] = FecFunQueryDeviceIdf;
	uDataTX.body.DPFC[1] = aCtlNum;
	
	uSetTXData();
}

void TFecBus::fMsgTX36_QueryDeviceIdf(u8 aDestAddr, u8 aCtlNum, u8 aUnitNum)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority2;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 3;
	uDataTX.body.DPFC[0] = FecFunQueryDeviceIdf;
	uDataTX.body.DPFC[1] = aCtlNum;
	uDataTX.body.DPFC[2] = aUnitNum;
	
	uSetTXData();
}

void TFecBus::fMsgTX36_QueryDeviceIdf(u8 aDestAddr, u8 aCtlNum, u8 aUnitNum, u8 aDev)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority2;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 4;
	uDataTX.body.DPFC[0] = FecFunQueryDeviceIdf;
	uDataTX.body.DPFC[1] = aCtlNum;
	uDataTX.body.DPFC[2] = aUnitNum;
	uDataTX.body.DPFC[3] = aDev;
	
	uSetTXData();
}

void TFecBus::fMsgTX37_QueryDeviceParameter(u8 aDestAddr, TFecItemPath * pPath)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority2;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 5;
	uDataTX.body.DPFC[0] = FecFunQueryDeviceParameter;
	uDataTX.body.DPFC[1] = pPath->CtlNum;
	uDataTX.body.DPFC[2] = pPath->UnitNum;
	uDataTX.body.DPFC[3] = pPath->DevNum;
	uDataTX.body.DPFC[4] = pPath->ChannelNum;
	
	uSetTXData();
}

void TFecBus::fMsgTX38_QueryDeviceDescp(u8 aDestAddr, u8 aCtlNum, u8 aUnitNum, u8 aDev)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority2;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 4;
	uDataTX.body.DPFC[0] = FecFunQueryDeviceDescp;
	uDataTX.body.DPFC[1] = aCtlNum;
	uDataTX.body.DPFC[2] = aUnitNum;
	uDataTX.body.DPFC[3] = aDev;
	
	uSetTXData();
}

void TFecBus::fMsgTX39_QueryDeviceProgram(u8 aDestAddr, u8 aCtlNum, u8 aUnitNum, u8 aDev)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority2;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 4;
	uDataTX.body.DPFC[0] = FecFunQueryDeviceProgram;
	uDataTX.body.DPFC[1] = aCtlNum;
	uDataTX.body.DPFC[2] = aUnitNum;
	uDataTX.body.DPFC[3] = aDev;
	
	uSetTXData();
}

void TFecBus::fMsgTX40_QueryDeviceRegisterInfo(u8 aDestAddr, u8 aCtlNum, u8 aUnitNum)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority2;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 3;
	uDataTX.body.DPFC[0] = FecFunQueryDeviceRegisterInfo;
	uDataTX.body.DPFC[1] = aCtlNum;
	uDataTX.body.DPFC[2] = aUnitNum;
	
	uSetTXData();
}

void TFecBus::fMsgTX40_QueryDeviceRegisterInfo(u8 aDestAddr, u8 aCtlNum, u8 aUnitNum, u8 aDev)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority2;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 4;
	uDataTX.body.DPFC[0] = FecFunQueryDeviceRegisterInfo;
	uDataTX.body.DPFC[1] = aCtlNum;
	uDataTX.body.DPFC[2] = aUnitNum;
	uDataTX.body.DPFC[3] = aDev;
	
	uSetTXData();
}

void TFecBus::fMsgTX41_QueryCurrentEvent(u8 aDestAddr, u8 aCtlNum, TFecEventCode aEvent)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority2;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 4;
	uDataTX.body.DPFC[0] = FecQueryCurrentEvent;
	uDataTX.body.DPFC[1] = aCtlNum;
	uDataTX.body.DPFC[2] = aEvent & 0xFF;
	uDataTX.body.DPFC[3] = (aEvent>>8) & 0xFF;
	
	uSetTXData();
}

void TFecBus::fMsgTX42_QueryHistoryEvent(u8 aDestAddr, u8 aCtlNum, TFecEventCode aEvent, u8 aSY, u8 aSM, u8 aSD)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority2;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 7;
	uDataTX.body.DPFC[0] = FecQueryHistoryEvent;
	uDataTX.body.DPFC[1] = aCtlNum;
	uDataTX.body.DPFC[2] = aEvent & 0xFF;
	uDataTX.body.DPFC[3] = (aEvent>>8) & 0xFF;
	uDataTX.body.DPFC[4] = aSY;
	uDataTX.body.DPFC[5] = aSM;
	uDataTX.body.DPFC[6] = aSD;
	
	uSetTXData();
}

void TFecBus::fMsgTX43_StopQueryDeviceEvent(u8 aDestAddr, u8 aCtlNum)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority2;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 2;
	uDataTX.body.DPFC[0] = FecStopQueryDeviceEvent;
	uDataTX.body.DPFC[1] = aCtlNum;
	
	uSetTXData();
}

void TFecBus::fMsgTX44_QueryFECBusVer(u8 aDestAddr)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority2;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 1;
	uDataTX.body.DPFC[0] = FecQueryFECBusVer;
	
	uSetTXData();
}

void TFecBus::fMsgTX45_QueryDeviceList(u8 aDestAddr)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority2;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 1;
	uDataTX.body.DPFC[0] = FecQueryDeviceList;
	
	uSetTXData();
	
	CommPrm.GetCmd45Data.type = 1;
}

void TFecBus::fMsgTX45_QueryDeviceList(u8 aDestAddr, u8 aCtlNum)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority2;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 2;
	uDataTX.body.DPFC[0] = FecQueryDeviceList;
	uDataTX.body.DPFC[1] = aCtlNum;
	
	uSetTXData();
	
	CommPrm.GetCmd45Data.type = 2;
}

void TFecBus::fMsgTX45_QueryDeviceList(u8 aDestAddr, u8 aCtlNum, u8 aUnitNum)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority2;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 3;
	uDataTX.body.DPFC[0] = FecQueryDeviceList;
	uDataTX.body.DPFC[1] = aCtlNum;
	uDataTX.body.DPFC[2] = aUnitNum;
	
	uSetTXData();
	
	CommPrm.GetCmd45Data.type = 3;
}

void TFecBus::fMsgTX45_QueryDeviceList(u8 aDestAddr, u8 aCtlNum, u8 aUnitNum, u8 aDev)
{
	if(aDestAddr > 63)return;
	
	uDataTX.body.FrmType = FecFrmTX;
	uDataTX.body.DestAddr = aDestAddr;
	uDataTX.body.Priority = Priority2;
	uDataTX.body.SrcAddr = FecCtlAddr;
	uDataTX.body.Dlen = 4;
	uDataTX.body.DPFC[0] = FecQueryDeviceList;
	uDataTX.body.DPFC[1] = aCtlNum;
	uDataTX.body.DPFC[2] = aUnitNum;
	uDataTX.body.DPFC[3] = aDev;
	
	uSetTXData();
	
	CommPrm.GetCmd45Data.type = 4;
}

void TFecBus::uSetTXData()
{
	u32 x = 0,y = 0,section = 0;
	u16 crc_value;
	
	if(uDataTX.body.Dlen > 8){
		uMsgOut.avalibel = 1;
		uMsgOut.UsingMsgIndex = 1;
		uMsgOut.FrameTick = 0;
		if(uDataTX.body.Dlen % 8){
			uMsgOut.FrameNum = uDataTX.body.Dlen / 8 + 2;
		}else{
			uMsgOut.FrameNum = uDataTX.body.Dlen / 8 + 1;
		}
		if(uMsgOut.FrameNum > 4)return;
		uMsgOutIndex++;
		if(uMsgOutIndex > 63)uMsgOutIndex = 1;
		for(x=1;x<uMsgOut.FrameNum;x++){
			uMsgOut.Section[x].body.Header = FecHeader;
			uMsgOut.Section[x].body.FrmType = uDataTX.body.FrmType;
			uMsgOut.Section[x].body.DestAddr = uDataTX.body.DestAddr;
			uMsgOut.Section[x].body.Priority = uDataTX.body.Priority;
			uMsgOut.Section[x].body.SrcAddr = uDataTX.body.SrcAddr;
			uMsgOut.Section[x].body.MsgIndex = uMsgOutIndex;
			uMsgOut.Section[x].body.FrmIndex = x;
			if((uDataTX.body.Dlen - ((x - 1)*8)) > 8){
				uMsgOut.Section[x].body.Dlen = 8;
			}else{
				uMsgOut.Section[x].body.Dlen = uDataTX.body.Dlen - ((x - 1)*8);
			}
			for(y = 0;y < uMsgOut.Section[x].body.Dlen;y++){
				uMsgOut.Section[x].body.DPFC[y] = uDataTX.body.DPFC[(x-1)*8+y];
			}
			crc_value = Crc16(uMsgOut.Section[x].D8,(8 + uMsgOut.Section[x].body.Dlen));
			uMsgOut.Section[x].body.CrcLoByte = crc_value & 0xFF;
			uMsgOut.Section[x].body.CrcHiByte = (crc_value>>8) & 0xFF;
			uMsgOut.Section[x].body.Eop = FecEnding;
		}
		
		uMsgOut.Section[0].body.Header = FecHeader;
		uMsgOut.Section[0].body.FrmType = uDataTX.body.FrmType;
		uMsgOut.Section[0].body.DestAddr = uDataTX.body.DestAddr;
		uMsgOut.Section[0].body.Priority = uDataTX.body.Priority;
		uMsgOut.Section[0].body.SrcAddr = uDataTX.body.SrcAddr;
		uMsgOut.Section[0].body.MsgIndex = uMsgOutIndex;
		uMsgOut.Section[0].body.FrmIndex = 0;
		uMsgOut.Section[0].body.Dlen = 2;
		uMsgOut.Section[0].body.DPFC[0] = FecFunStateAck;
		uMsgOut.Section[0].body.DPFC[1] = ackMsgSectionEnd;
		crc_value = Crc16(uMsgOut.Section[0].D8,(8 + uMsgOut.Section[0].body.Dlen));
		uMsgOut.Section[0].body.CrcLoByte = crc_value & 0xFF;
		uMsgOut.Section[0].body.CrcHiByte = (crc_value>>8) & 0xFF;
		uMsgOut.Section[0].body.Eop = FecEnding;
 	}else{
		uMsgOut.avalibel = 1;
		uMsgOut.UsingMsgIndex = 0;
		
		uMsgOut.Section[0].body.Header = FecHeader;
		uMsgOut.Section[0].body.FrmType = uDataTX.body.FrmType;
		uMsgOut.Section[0].body.DestAddr = uDataTX.body.DestAddr;
		uMsgOut.Section[0].body.Priority = uDataTX.body.Priority;
		uMsgOut.Section[0].body.SrcAddr = uDataTX.body.SrcAddr;
		
		if(0 == uDataTX.body.DPFC[0]){
			uMsgOut.Section[0].body.MsgIndex = 0;
		}else{
			uMsgOutIndex++;
			if(uMsgOutIndex > 63)uMsgOutIndex = 1;
			uMsgOut.Section[0].body.MsgIndex = uMsgOutIndex;
		}
		
		uMsgOut.Section[0].body.FrmIndex = 0;
		uMsgOut.Section[0].body.Dlen = uDataTX.body.Dlen;
		
		for(x=0;x<uMsgOut.Section[0].body.Dlen;x++)
			uMsgOut.Section[0].body.DPFC[x] = uDataTX.body.DPFC[x];
		
		crc_value = Crc16(uMsgOut.Section[0].D8,(8 + uMsgOut.Section[0].body.Dlen));
		uMsgOut.Section[0].body.CrcLoByte = crc_value & 0xFF;
		uMsgOut.Section[0].body.CrcHiByte = (crc_value>>8) & 0xFF;
		uMsgOut.Section[0].body.Eop = FecEnding;
	}
	
	TxSetFlag = 1;
}

void TFecBus::uDataTXTask()//10ms
{
	unsigned int retry_time = 0;
	
	if(OnTransmite.OnGoing){
		OnTransmite.TimeOutTick++;
		
		retry_time = 99;//1000ms retry
			
		if(OnTransmite.TimeOutTick > retry_time){
			OnTransmite.TimeOutTick = 0;
			
			if(OnTransmite.RetryTimes < 3){
				OnTransmite.RetryFLAG = 1;
			}else{
				OnTransmite.RetryTimes = 0;
				OnTransmite.OnGoing = 0;
			}
		}
	}
	
	if(!fec_std_tx_is_busy()){
		if(TxSetFlag){
			if(uMsgOut.UsingMsgIndex){
				uMsgOut.FrameTick++;
				if(uMsgOut.FrameTick >= uMsgOut.FrameNum){
					uMsgOut.FrameTick = 0;
					TxSetFlag = 0;
				}
				set_fec_std_tx_data(uMsgOut.Section[uMsgOut.FrameTick].D8);
			}else{
				set_fec_std_tx_data(uMsgOut.Section[0].D8);
				TxSetFlag = 0;
			}
			OnTransmite.TimeOutTick = 0;
			OnTransmite.AckOk = 0;
			OnTransmite.OnGoing = 1;
		}else
		if(OnTransmite.RetryFLAG){
			if(uMsgOut.UsingMsgIndex){
				uMsgOut.FrameTick++;
				if(uMsgOut.FrameTick >= uMsgOut.FrameNum){
					uMsgOut.FrameTick = 0;
					OnTransmite.RetryFLAG = 0;
					OnTransmite.RetryTimes++;
				}
				set_fec_std_tx_data(uMsgOut.Section[uMsgOut.FrameTick].D8);
			}else{
				set_fec_std_tx_data(uMsgOut.Section[0].D8);
				OnTransmite.RetryFLAG = 0;
				OnTransmite.RetryTimes++;
			}
			
			OnTransmite.TimeOutTick = 0;
			OnTransmite.AckOk = 0;
			OnTransmite.OnGoing = 1; 
		}
	}
}

//表 C.13 查询设备历史事件数据帧 及其 应答数据帧
//>--------------->
void TFecBus::fMsgC7_QueryDevEventHistory	(TFecItemPath aPath, TFecEventCode aEvt, TsDateTime aDT)
{
	u32 i,idx;
	u32 CanExdId_29;
	u8 aPriority = 3;
	
	idx = FindIdleMsgIndex();
	if(BusType == UsingUart){
		for(i=0; i<1; i++){
			uMsgOut.Section[i].body.Header = 0x7E;
			uMsgOut.avalibel = 1;
			uMsgOut.Section[i].body.FrmType = 1;
			uMsgOut.Section[i].body.DestAddr = aPath.DevNum;
			uMsgOut.Section[i].body.Priority = aPriority;
			uMsgOut.Section[i].body.SrcAddr = ThisAddr;
			uMsgOut.Section[i].body.MsgIndex = idx;
			uMsgOut.Section[i].body.Eop = 0x7E;
		}
		i = 0;
		uMsgOut.Section[i].body.FrmIndex = 0;
		uMsgOut.Section[i].body.Dlen = 7;
		uMsgOut.Section[i].body.DPFC[0] = 0x2A;	//The Fuction Code
		uMsgOut.Section[i].body.DPFC[1] = aPath.CtlNum;	
		uMsgOut.Section[i].body.DPFC[2] = static_cast<unsigned char>(aEvt & 0x00FF);	
		uMsgOut.Section[i].body.DPFC[3] = static_cast<unsigned char>( (aEvt>>8) & 0x00FF);	
		uMsgOut.Section[i].body.DPFC[4] = aDT.Year;	
		uMsgOut.Section[i].body.DPFC[5] = aDT.Month;	
		uMsgOut.Section[i].body.DPFC[6] = aDT.Day;	
		uMsgOut.Section[i].body.DPFC[7] = 0;
	}else
	if(BusType == UsingCan){
		CanExdId_29 = 0;
		for(i=0; i<4; i++){
			cMsgOut.Section[i].avalibel = 1;
			CanExdId_29 |= 1<<27;
			CanExdId_29 |= (static_cast<unsigned int>(aPath.DevNum)) << 21;
			CanExdId_29 |= (static_cast<unsigned int>(aPriority))    << 19;
			CanExdId_29 |= (static_cast<unsigned int>(ThisAddr)) 	   << 13;
			CanExdId_29 |= (static_cast<unsigned int>(idx))    	   <<  7;
		}
		i = 0;
		CanExdId_29 |= static_cast<unsigned int>(0) ;
		cMsgOut.Section[i].body.spl.Dlen = 7;
		cMsgOut.Section[i].body.spl.DPFC[0] = 0x2A;	//The Fuction Code
		cMsgOut.Section[i].body.spl.DPFC[1] = aPath.CtlNum;	
		cMsgOut.Section[i].body.spl.DPFC[2] = static_cast<unsigned char>(aEvt & 0x00FF);	
		cMsgOut.Section[i].body.spl.DPFC[3] = static_cast<unsigned char>( (aEvt>>8) & 0x00FF);	
		cMsgOut.Section[i].body.spl.DPFC[4] = aDT.Year;	
		cMsgOut.Section[i].body.spl.DPFC[5] = aDT.Month;	
		cMsgOut.Section[i].body.spl.DPFC[6] = aDT.Day;	
		cMsgOut.Section[i].body.spl.DPFC[7] = 0;
	}		
}

//<-----------------<
void TFecBus::fMsgC13_Reply_QueryDevEventHistory	(TFecItemPath aPath,          u16 aDtc,        u16 aEvt,  u16 aDevState, TsDateTime aDT)			//42
{
	u32 i,idx;
	u32 CanExdId_29;
	u8 aPriority = 3;
	
	idx = FindIdleMsgIndex();
	if(BusType == UsingUart){
		for(i=0; i<4; i++){
			uMsgOut.Section[i].body.Header = 0x7E;
			uMsgOut.avalibel = 1;
			uMsgOut.Section[i].body.FrmType = 1;
			uMsgOut.Section[i].body.DestAddr = aPath.DevNum;
			uMsgOut.Section[i].body.Priority = aPriority;
			uMsgOut.Section[i].body.SrcAddr = ThisAddr;
			uMsgOut.Section[i].body.MsgIndex = idx;
			uMsgOut.Section[i].body.Eop = 0x7E;
		}
		i = 0;
		uMsgOut.Section[i].body.FrmIndex = 1;
		uMsgOut.Section[i].body.Dlen = 8;
		uMsgOut.Section[i].body.DPFC[0] = 0x2A;	//The Fuction Code
		uMsgOut.Section[i].body.DPFC[1] = aPath.CtlNum;	
		uMsgOut.Section[i].body.DPFC[2] = aPath.UnitNum;	
		uMsgOut.Section[i].body.DPFC[3] = aPath.DevNum;	
		uMsgOut.Section[i].body.DPFC[4] = aPath.ChannelNum;	
		uMsgOut.Section[i].body.DPFC[5] = static_cast<unsigned char>(aDtc & 0x00FF);	
		uMsgOut.Section[i].body.DPFC[6] = static_cast<unsigned char>( (aDtc>>8) & 0x00FF);	
		uMsgOut.Section[i].body.DPFC[7] = static_cast<unsigned char>(aEvt & 0x00FF);
		uMsgOut.Section[i].body.CrcLoByte = 0;
		uMsgOut.Section[i].body.CrcHiByte = 0;
		i = 1;
		uMsgOut.Section[i].body.FrmIndex = 2;
		uMsgOut.Section[i].body.Dlen = 8;
		uMsgOut.Section[i].body.DPFC[0] = static_cast<unsigned char>( (aEvt>>8) & 0x00FF);
		uMsgOut.Section[i].body.DPFC[1] = static_cast<unsigned char>(aDevState & 0x00FF);	
		uMsgOut.Section[i].body.DPFC[2] = static_cast<unsigned char>( (aDevState>>8) & 0x00FF);	
		uMsgOut.Section[i].body.DPFC[3] = aDT.Year;	
		uMsgOut.Section[i].body.DPFC[4] = aDT.Month;
		uMsgOut.Section[i].body.DPFC[5] = aDT.Day;
		uMsgOut.Section[i].body.DPFC[6] = aDT.Hour;
		uMsgOut.Section[i].body.DPFC[7] = aDT.Minute;
		uMsgOut.Section[i].body.CrcLoByte = 0;
		uMsgOut.Section[i].body.CrcHiByte = 0;
		i = 2;
		uMsgOut.Section[i].body.FrmIndex = 3;
		uMsgOut.Section[i].body.Dlen = 1;
		uMsgOut.Section[i].body.DPFC[0] = aDT.Second;
		uMsgOut.Section[i].body.DPFC[1] = 0;	
		uMsgOut.Section[i].body.DPFC[2] = 0;	
		uMsgOut.Section[i].body.DPFC[3] = 0;	
		uMsgOut.Section[i].body.DPFC[4] = 0;
		uMsgOut.Section[i].body.DPFC[5] = 0;
		uMsgOut.Section[i].body.DPFC[6] = 0;
		uMsgOut.Section[i].body.DPFC[7] = 0;
		uMsgOut.Section[i].body.CrcLoByte = 0;
		uMsgOut.Section[i].body.CrcHiByte = 0;
		i = 3;
		uMsgOut.Section[i].body.FrmIndex = 0;
		uMsgOut.Section[i].body.Dlen = 2;
		uMsgOut.Section[i].body.DPFC[0] = 0x0F;	// End this Index
		uMsgOut.Section[i].body.DPFC[1] = 0x00;	
		uMsgOut.Section[i].body.DPFC[2] = 0;	
		uMsgOut.Section[i].body.DPFC[3] = 0;	
		uMsgOut.Section[i].body.DPFC[4] = 0;
		uMsgOut.Section[i].body.DPFC[5] = 0;
		uMsgOut.Section[i].body.DPFC[6] = 0;
		uMsgOut.Section[i].body.DPFC[7] = 0;
		uMsgOut.Section[i].body.CrcLoByte = 0;
		uMsgOut.Section[i].body.CrcHiByte = 0;
	}else
	if(BusType == UsingCan){
		CanExdId_29 = 0;
		for(i=0; i<4; i++){
			cMsgOut.Section[i].avalibel = 1;
			CanExdId_29 |= 1<<27;
			CanExdId_29 |= (static_cast<unsigned int>(aPath.DevNum)) << 21;
			CanExdId_29 |= (static_cast<unsigned int>(aPriority))    << 19;
			CanExdId_29 |= (static_cast<unsigned int>(ThisAddr)) 	   << 13;
			CanExdId_29 |= (static_cast<unsigned int>(idx))    	   <<  7;
		}
		i = 0;
		CanExdId_29 |= static_cast<unsigned int>(1) ;
		cMsgOut.Section[i].body.spl.Dlen = 8;
		cMsgOut.Section[i].body.spl.DPFC[0] = 0x2A;	//The Fuction Code
		cMsgOut.Section[i].body.spl.DPFC[1] = aPath.CtlNum;	
		cMsgOut.Section[i].body.spl.DPFC[2] = aPath.UnitNum;	
		cMsgOut.Section[i].body.spl.DPFC[3] = aPath.DevNum;	
		cMsgOut.Section[i].body.spl.DPFC[4] = aPath.ChannelNum;	
		cMsgOut.Section[i].body.spl.DPFC[5] = static_cast<unsigned char>(aDtc & 0x00FF);	
		cMsgOut.Section[i].body.spl.DPFC[6] = static_cast<unsigned char>( (aDtc>>8) & 0x00FF);	
		cMsgOut.Section[i].body.spl.DPFC[7] = static_cast<unsigned char>(aEvt & 0x00FF);
		i = 1;
		CanExdId_29 |= static_cast<unsigned int>(2) ;
		cMsgOut.Section[i].body.spl.Dlen = 8;
		cMsgOut.Section[i].body.spl.DPFC[0] = static_cast<unsigned char>( (aEvt>>8) & 0x00FF);
		cMsgOut.Section[i].body.spl.DPFC[1] = static_cast<unsigned char>(aDevState & 0x00FF);	
		cMsgOut.Section[i].body.spl.DPFC[2] = static_cast<unsigned char>( (aDevState>>8) & 0x00FF);	
		cMsgOut.Section[i].body.spl.DPFC[3] = aDT.Year;	
		cMsgOut.Section[i].body.spl.DPFC[4] = aDT.Month;
		cMsgOut.Section[i].body.spl.DPFC[5] = aDT.Day;
		cMsgOut.Section[i].body.spl.DPFC[6] = aDT.Hour;
		cMsgOut.Section[i].body.spl.DPFC[7] = aDT.Minute;
		i = 2;
		CanExdId_29 |= static_cast<unsigned int>(3) ;
		cMsgOut.Section[i].body.spl.Dlen = 1;
		cMsgOut.Section[i].body.spl.DPFC[0] = aDT.Second;
		cMsgOut.Section[i].body.spl.DPFC[1] = 0;	
		cMsgOut.Section[i].body.spl.DPFC[2] = 0;	
		cMsgOut.Section[i].body.spl.DPFC[3] = 0;	
		cMsgOut.Section[i].body.spl.DPFC[4] = 0;
		cMsgOut.Section[i].body.spl.DPFC[5] = 0;
		cMsgOut.Section[i].body.spl.DPFC[6] = 0;
		cMsgOut.Section[i].body.spl.DPFC[7] = 0;
		i = 3;
		CanExdId_29 |= static_cast<unsigned int>(0) ;
		cMsgOut.Section[i].body.spl.Dlen = 2;
		cMsgOut.Section[i].body.spl.DPFC[0] = 0x0F;	// End this Index
		cMsgOut.Section[i].body.spl.DPFC[1] = 0x00;	
		cMsgOut.Section[i].body.spl.DPFC[2] = 0;	
		cMsgOut.Section[i].body.spl.DPFC[3] = 0;	
		cMsgOut.Section[i].body.spl.DPFC[4] = 0;
		cMsgOut.Section[i].body.spl.DPFC[5] = 0;
		cMsgOut.Section[i].body.spl.DPFC[6] = 0;
		cMsgOut.Section[i].body.spl.DPFC[7] = 0;
	}	
}

void TFecBus::fMsgC13_Reply_QueryDevEventHistory	(TFecItemPath aPath, TFecDevTypeCode aDtc, TFecEventCode aEvt,  u16 aDevState, TsDateTime aDT)			//42
{
	u16 tDtc, tEvt;
	tDtc = static_cast<unsigned short>(aDtc);
	tEvt = static_cast<unsigned short>(aEvt);
	fMsgC13_Reply_QueryDevEventHistory(aPath, tDtc, tEvt, aDevState, aDT);
}


//表 C.14 查询设备列表应答数据帧 >_________________________________________________________________________
void TFecBus::LongReplyClearTx(void)
{
	LongReplyTx.PkgCount = 0;
	LongReplyTx.Body.D32[0] = 0;
	LongReplyTx.Body.D32[1] = 0;
}

void TFecBus::C14_DevList_CtlClearTx(void)
{
	LongReplyTx.PkgCount = 0;
	LongReplyClearTx();
	LongReplyTx.Body.CtlListInf.CtlCount = 0;
}
	
void TFecBus::C14_DevList_UnitClearTx(void)
{
	LongReplyTx.PkgCount = 0;
	LongReplyClearTx();
	LongReplyTx.Body.UnitListInf.UnitCount = 0;
}
	
void TFecBus::C14_DevList_DevClearTx(void)
{
	LongReplyTx.PkgCount = 0;
	LongReplyClearTx();
	LongReplyTx.Body.DevListInf.DevCount = 0;
}
	
void TFecBus::C14_DevList_ChlClearTx(void)
{
	LongReplyTx.PkgCount = 0;
	LongReplyClearTx();
	LongReplyTx.Body.ChannelListInf.ChannelCount = 0;
}

void TFecBus::C14_DevList_CtlAdd	(u8 aCtlNum, 	TFecDevTypeCode aDtc)	//Add Item to 控制器列表
{
	u32 i;
	if(aCtlNum < 64){
		i = LongReplyTx.Body.CtlListInf.CtlCount;
		if(i < 64){
			LongReplyTx.Body.CtlListInf.List[i].CtlNum = aCtlNum;
			LongReplyTx.Body.CtlListInf.List[i].DevTypeLoByte = static_cast<unsigned char>(aDtc & 0x00FF) ;
			LongReplyTx.Body.CtlListInf.List[i].DevTypeHiByte = static_cast<unsigned char>( (aDtc >> 8) & 0x00FF ) ;
		}
		LongReplyTx.Body.CtlListInf.CtlCount++;
	}
}

void TFecBus::C14_DevList_UnitAdd		(u8 aCtlNum, u8 aUnitNum, 				TFecDevTypeCode aDtc)	//Add Item to 单元列表
{
	
}

void TFecBus::C14_DevList_DevAdd		(u8 aCtlNum, u8 aUnitNum, u8 aDev, 			TFecDevTypeCode aDtc)	//Add Item to 设备列表
{
	
}

void TFecBus::C14_DevList_ChlAdd		(u8 aCtlNum, u8 aUnitNum, u8 aDev, u8 aChl, 	TFecDevTypeCode aDtc)	//Add Item to 通道列表
{
	
}

void fMsgC14_Reply_QueryDevList_Ctl		(void)	//45		//查询控制器列表
{
	
}

void fMsgC14_Reply_QueryDevList_Unit	(void)	//45		//查询单元列表
{
	
}

void fMsgC14_Reply_QueryDevList_Dev		(void)	//45		//查询设备列表
{
	
}

void fMsgC14_Reply_QueryDevList_Chl		(void)	//45		//查询通道列表
{
	
}

//___________________________________________________________________________________________________< C14


//通讯阶段   下发事件，下发命令，建立连接
//通讯状态   巡检，功能码
//建立连接

void TFecBus::Task10ms(void)
{
	uDataTXTask();
	if(CommPrm.NoAckTick)CommPrm.NoAckTick--;
}

void TFecBus::Task100ms(void)
{
	if(CommPrm.TimeoutTick < 10000)CommPrm.TimeoutTick++;
	else CommPrm.TimeoutTick = 10000;
}

void TFecBus::SetCommAddr(u8 addr)
{
	CommPrm.CuuerntAddr = addr;
}

void TFecBus::SetRegister(u8 aAddr)
{
	CommPrm.Register[aAddr] = 1;
}

u8 TFecBus::GetRegisterStatus(u8 aAddr)
{
	return CommPrm.Register[aAddr];
}

void TFecBus::SetLogout(u8 aAddr)
{
	CommPrm.Register[aAddr] = 0;
}

void TFecBus::SetUpCommTask(void)
{
	switch(CommPrm.State){
		case FecCommExit : 	
			if((CommPrm.CuuerntAddr < 63)&&(CommPrm.CuuerntAddr > 1)){
				CommPrm.CuuerntAddr++;
				CommPrm.Phase = FecSetUpComm;
				CommPrm.State = FecCommQueryVer44;
			}else
			if(63 == CommPrm.CuuerntAddr){
				CommPrm.CuuerntAddr = 2;
				CommPrm.Phase = FecPolling;
				CommPrm.State = FecCommPolling33;
			}			
			break;
		
		case FecCommQueryVer44 : 	
			fMsgTX44_QueryFECBusVer(CommPrm.CuuerntAddr);//发44
			CommPrm.State = FecCommQueryVer44Ack;
			CommPrm.AckStatus = 0;
			CommPrm.TimeoutTick = 0;
			break;
		
		case FecCommQueryVer44Ack : 	//等待44回复
			if(CommPrm.AckStatus){
				CommPrm.State = FecCommSyncTime04;
				SetRegister(CommPrm.CuuerntAddr);
			}else
			if(CommPrm.TimeoutTick > CommAckTimeout){
				CommPrm.TimeoutTick = 0;
				CommPrm.State = FecCommExit;
			}
			break;
		
		case FecCommSyncTime04 : //发04
			getSysTime();
			fMsgTX04_SyncTime(CommPrm.CuuerntAddr, 0, \
												dateTime.Year, \
												dateTime.Mon, \
												dateTime.Day, \
												dateTime.Hour, \
												dateTime.Min, \
												dateTime.Sec);
			CommPrm.State = FecCommSyncTime04Ack;
			CommPrm.AckStatus = 0;
			CommPrm.TimeoutTick = 0;
			break;
		
		case FecCommSyncTime04Ack :			//等待04回复
			if(CommPrm.AckStatus){
				CommPrm.State = FecCommQueryCurrentEvent41;
			}else
			if(CommPrm.TimeoutTick > CommAckTimeout){
				CommPrm.TimeoutTick = 0;
				CommPrm.State = FecCommExit;
			}
			break;
		
		case FecCommQueryCurrentEvent41 :
			fMsgTX41_QueryCurrentEvent(CommPrm.CuuerntAddr, 0, evtRsv0);
			//直到事件结束，下一个地址44，...................退出进入巡检
			ClearCurrentEventList(CommPrm.CuuerntAddr);
			CommPrm.State = FecCommQueryCurrentEvent41Ack;
			CommPrm.AckStatus = 0;
			CommPrm.TimeoutTick = 0;
			break;
		
		case FecCommQueryCurrentEvent41Ack :	
			if(1 == CommPrm.AckStatus){
				//fMsgTX15_Ack_StateAck(CommPrm.CuuerntAddr, ackRecDataCorrect);
				if(1 == EventCodePrm[CommPrm.CurrentEventData.Data.EventCode]){
					fMsgRpy18_Ack_InformedGeneralEvent(CommPrm.CuuerntAddr);
				}else
				if(2 == EventCodePrm[CommPrm.CurrentEventData.Data.EventCode]){
					fMsgRpy17_Ack_PublishEmergencyEvent(CommPrm.CuuerntAddr);
				}
				CommPrm.AckStatus = 0;
				CommPrm.TimeoutTick = 0;
			}else
			if(2 == CommPrm.AckStatus){
				CommPrm.State = FecCommQueryCurrentEvent41Ending;
				CommPrm.TimeoutTick = 0;
				CommPrm.State = FecCommExit;
			}else
			if(CommPrm.TimeoutTick > CommAckTimeout){
				CommPrm.TimeoutTick = 0;
				CommPrm.State = FecCommExit;
			}
			break;
		
		case FecCommQueryCurrentEvent41Ending :
			CommPrm.State = FecCommExit;
			break;
		
		default : 
			CommPrm.CuuerntAddr = 2;
			CommPrm.Phase = FecPolling;
			CommPrm.State = FecCommPolling33;
			break;
	}
}

void TFecBus::ClearDownEventList()
{	
	CommPrm.DownEventCount = 0;
	CommPrm.DownEventTick = 0;
}

void TFecBus::AddDownEventList(TFecEventBufBody * pEvent)
{
	u32 i;
	u32 aSAddr;
	
	if(CommPrm.DownEventCount >= dFecBus_DownEventBufCount)return;
	
	aSAddr = dAddrSdram_FECDownEventBuf + (CommPrm.DownEventCount * dFecBus_BufEntrySize_Event);
	for(i = 0;i<(dFecBus_BufEntrySize_Event/4);i++)
		*(volatile unsigned int *)(aSAddr + (i*4)) = pEvent->D32[i];
	
	CommPrm.DownEventCount++;
}

void TFecBus::SetDownEventData(u32 Ord)
{
	u32 i;
	u32 aSAddr;
	
	if(Ord >= dFecBus_DownEventBufCount)return;
	
	aSAddr = dAddrSdram_FECDownEventBuf + (Ord * dFecBus_BufEntrySize_Event);
	for(i = 0;i<(dFecBus_BufEntrySize_Event/4);i++)
		CommPrm.DownEventData.D32[i] = (*(volatile unsigned int *)(aSAddr + (i*4)));
}

void TFecBus::EnterSetDownEvent(u8 aAddr)
{
	if((aAddr < 2)||(aAddr > 63))return;
	
	CommPrm.DownEventTick = 0;
	CommPrm.SetDownEventFlag = 1;
	CommPrm.SetDownPath.Addr = aAddr;
}


void TFecBus::ClearUpEventList(u8 aAddr)
{	
	if((aAddr < 2)||(aAddr > 63))return;
	
	CommPrm.UpEventCount[aAddr] = 0;
	CommPrm.UpEventSRTick[aAddr] = 0;
}

void TFecBus::AddUpEventList(u8 aAddr, TFecEventBufBody * pEvent)
{
	u32 i;
	u32 aSAddr;
	
	if((aAddr < 2)||(aAddr > 63))return;
	
	if(CommPrm.UpEventCount[aAddr] >= dFecBus_OneBufCount){
		CommPrm.UpEventCount[aAddr] = dFecBus_OneBufCount;
		aSAddr = dAddrSdram_FECUpEventBuf + ((aAddr-2) * dFecBus_OneBufCount) + (CommPrm.UpEventSRTick[aAddr] * dFecBus_BufEntrySize_Event);
		for(i = 0;i<(dFecBus_BufEntrySize_Event/4);i++)
			*(volatile unsigned int *)(aSAddr + (i*4)) = pEvent->D32[i];
	
		CommPrm.UpEventSRTick[aAddr]++;
	}else{
		aSAddr = dAddrSdram_FECUpEventBuf + ((aAddr-2) * dFecBus_OneBufCount) + (CommPrm.UpEventCount[aAddr] * dFecBus_BufEntrySize_Event);
		for(i = 0;i<(dFecBus_BufEntrySize_Event/4);i++)
			*(volatile unsigned int *)(aSAddr + (i*4)) = pEvent->D32[i];
	
		CommPrm.UpEventCount[aAddr]++;
	}
}

void TFecBus::ClearCurrentEventList(u8 aAddr)
{	
	if((aAddr < 2)||(aAddr > 63))return;
	
	CommPrm.CurrentEventCount[aAddr] = 0;
	CommPrm.CurrentEventSRTick[aAddr] = 0;
}

void TFecBus::AddCurrentEventList(u8 aAddr, TFecEventBufBody * pEvent)
{
	u32 i;
	u32 aSAddr;
	
	if((aAddr < 2)||(aAddr > 63))return;
	
	if(CommPrm.CurrentEventCount[aAddr] >= dFecBus_OneBufCount){
		CommPrm.CurrentEventCount[aAddr] = dFecBus_OneBufCount;
		aSAddr = dAddrSdram_FECCurrentEventBuf + ((aAddr-2) * dFecBus_OneBufCount) + (CommPrm.CurrentEventSRTick[aAddr] * dFecBus_BufEntrySize_Event);
		for(i = 0;i<(dFecBus_BufEntrySize_Event/4);i++)
			*(volatile unsigned int *)(aSAddr + (i*4)) = pEvent->D32[i];
		
		CommPrm.CurrentEventSRTick[aAddr]++;
	}else{
		aSAddr = dAddrSdram_FECCurrentEventBuf + ((aAddr-2) * dFecBus_OneBufCount) + (CommPrm.CurrentEventCount[aAddr] * dFecBus_BufEntrySize_Event);
		for(i = 0;i<(dFecBus_BufEntrySize_Event/4);i++)
			*(volatile unsigned int *)(aSAddr + (i*4)) = pEvent->D32[i];
		
		CommPrm.CurrentEventCount[aAddr]++;
	}
}

void TFecBus::ClearHistoryEventList()
{	
	CommPrm.HistoryEventCount = 0;
	CommPrm.HistoryEventSRTick = 0;
}

void TFecBus::AddHistoryEventList(TFecEventBufBody * pEvent)
{
	u32 i;
	u32 aAddr;
	
	if(CommPrm.HistoryEventCount >= dFecBus_HistoryEventBufCount){
		CommPrm.HistoryEventCount = dFecBus_HistoryEventBufCount;
		aAddr = dAddrSdram_FECHistoryEventBuf + (CommPrm.HistoryEventSRTick * dFecBus_BufEntrySize_Event);
		for(i = 0;i<(dFecBus_BufEntrySize_Event/4);i++)
			*(volatile unsigned int *)(aAddr + (i*4)) = pEvent->D32[i];
		
		CommPrm.HistoryEventSRTick++;
	}else{
		aAddr = dAddrSdram_FECHistoryEventBuf + (CommPrm.HistoryEventCount * dFecBus_BufEntrySize_Event);
		for(i = 0;i<(dFecBus_BufEntrySize_Event/4);i++)
			*(volatile unsigned int *)(aAddr + (i*4)) = pEvent->D32[i];
		
		CommPrm.HistoryEventCount++;
	}
}

void TFecBus::DownEventTask(void)
{
	switch(CommPrm.State){
		case FecCommExit : 
			CommPrm.Phase = FecPolling;
			break;
		/*
		case FecCommPolling33 : 	
			fMsgTX33_InspectionDevice(CommPrm.CuuerntAddr);//发33
			CommPrm.State = FecCommPolling33Ack;
			CommPrm.AckStatus = 0;
			CommPrm.TimeoutTick = 0;
			break;
		*/
		case FecCommPolling33Ack : 	//等待回复
			if(1 == CommPrm.AckStatus){
				//set down event prm
				CommPrm.DownEventTick = 0;
				if(CommPrm.DownEventCount){
					SetDownEventData(CommPrm.DownEventTick);
					if(2 == EventCodePrm[CommPrm.DownEventData.Data.EventCode]){
						CommPrm.State = FecCommDownEvent05;
					}else
					if(1 == EventCodePrm[CommPrm.DownEventData.Data.EventCode]){
						CommPrm.State = FecCommDownEvent06;
					}
					CommPrm.DownEventTick++;
				}else{
					CommPrm.State = FecCommPolling33Up;
				}
			}else
			if(CommPrm.TimeoutTick > CommAckTimeout){
				CommPrm.TimeoutTick = 0;
				CommPrm.State = FecCommExit;
			}
			break;
		//按列表下发事件
		case FecCommDownEvent05 : //05下发事件
			fMsgTX05_PublishEmergencyEvent(CommPrm.CuuerntAddr, &CommPrm.DownEventData);//装载事件
			CommPrm.State = FecCommDownEvent05Ack;
			CommPrm.AckStatus = 0;
			CommPrm.TimeoutTick = 0;
			break;
		
		case FecCommDownEvent05Ack : //等待05回复
			if(CommPrm.AckStatus){
				if(CommPrm.DownEventTick < CommPrm.DownEventCount){
					SetDownEventData(CommPrm.DownEventTick);
					if(2 == EventCodePrm[CommPrm.DownEventData.Data.EventCode]){
						CommPrm.State = FecCommDownEvent05;
					}else
					if(1 == EventCodePrm[CommPrm.DownEventData.Data.EventCode]){
						CommPrm.State = FecCommDownEvent06;
					}
					CommPrm.DownEventTick++;
				}else{
					CommPrm.State = FecCommPolling33Up;
				}
			}else
			if(CommPrm.TimeoutTick > CommAckTimeout){
				CommPrm.TimeoutTick = 0;
				CommPrm.State = FecCommExit;
			}						
			break;
		
		case FecCommDownEvent06 : //06下发事件
			fMsgTX06_PublishGeneralEvent(CommPrm.CuuerntAddr, &CommPrm.DownEventData);
			CommPrm.State = FecCommDownEvent06Ack;
			CommPrm.AckStatus = 0;
			CommPrm.TimeoutTick = 0;
			break;
		
		case FecCommDownEvent06Ack : //等待06回复
			if(CommPrm.AckStatus){
				if(CommPrm.DownEventTick < CommPrm.DownEventCount){
					SetDownEventData(CommPrm.DownEventTick);
					if(2 == EventCodePrm[CommPrm.DownEventData.Data.EventCode]){
						CommPrm.State = FecCommDownEvent05;
					}else
					if(1 == EventCodePrm[CommPrm.DownEventData.Data.EventCode]){
						CommPrm.State = FecCommDownEvent06;
					}
					CommPrm.DownEventTick++;
				}else{
					CommPrm.State = FecCommPolling33Up;
				}
			}else
			if(CommPrm.TimeoutTick > CommAckTimeout){
				CommPrm.TimeoutTick = 0;
				CommPrm.State = FecCommExit;
			}	
			break;
		/*
		case FecCommDownEvent07 : //07下发事件
			CommPrm.DownEventTick++;
			if(CommPrm.DownEventTick > CommPrm.DownEventCount){
				CommPrm.State = FecCommPolling33Up;
			}else{
				fMsgTX07_PublishAdjustEvent(CommPrm.CuuerntAddr, &CommPrm.DownEventData);	
				CommPrm.State = FecCommDownEvent07Ack;
				CommPrm.AckStatus = 0;
				CommPrm.TimeoutTick = 0;
			}
			break;
		
		case FecCommDownEvent07Ack : //等待07回复
			if(CommPrm.AckStatus){
				//CommPrm.State = FecCommDownEvent05;
			}else
			if(CommPrm.TimeoutTick > CommAckTimeout){
				CommPrm.TimeoutTick = 0;
				CommPrm.State = FecCommExit;
			}
			break;
		*/	
		case FecCommPolling33Up :
			fMsgTX33_InspectionDevice(CommPrm.CuuerntAddr);//发33
			CommPrm.State = FecCommPolling33UpAck;
			CommPrm.AckStatus = 0;
			CommPrm.TimeoutTick = 0;
			break;
			
		case FecCommPolling33UpAck :
			if(3 == CommPrm.AckStatus){
				CommPrm.State = FecCommExit;
			}else
			if(2 == CommPrm.AckStatus){
				if(1 == EventCodePrm[CommPrm.UpEventData.Data.EventCode]){
					fMsgRpy18_Ack_InformedGeneralEvent(CommPrm.CuuerntAddr);
					CommPrm.NoAckTick = 3;//delay 30ms
					CommPrm.State = FecCommDelay;
				}else
				if(2 == EventCodePrm[CommPrm.UpEventData.Data.EventCode]){
					fMsgRpy17_Ack_PublishEmergencyEvent(CommPrm.CuuerntAddr);
					CommPrm.NoAckTick = 3;//delay 30ms
					CommPrm.State = FecCommDelay;
				}
			}else
			if(CommPrm.TimeoutTick > CommAckTimeout){
				CommPrm.TimeoutTick = 0;
				CommPrm.State = FecCommExit;
			}
			break;
			
		case FecCommDelay ://延时等待发送完
			if(0 == CommPrm.NoAckTick)CommPrm.State = FecCommPolling33Up;
			break;
		
		default : 
			CommPrm.Phase = FecPolling;
			CommPrm.State = FecCommExit;
			break;
	}
}

void TFecBus::EnterSetDownCmd(TFecFunctionCode aCmd, TFecCmdPath * aCmdPath)
{
	if((aCmdPath->Addr < 2)||(aCmdPath->Addr > 63))return;
	
	if((FecFunQueryDeviceState == aCmd)||(FecFunQueryDeviceConfig == aCmd)||(FecFunQueryDeviceIdf == aCmd)||(FecQueryDeviceList == aCmd)){
		if((aCmdPath->PathLevel)&&(aCmdPath->PathLevel < 5)){
			;
		}else return;
	}else
	if(FecQueryCurrentEvent == aCmd){
		if((aCmdPath->PathLevel > 2)&&(aCmdPath->PathLevel < 5)){
			;
		}else return;
	}
	
	CommPrm.SetDownCmdFlag = 1;
	CommPrm.SetDownPath.Addr = aCmdPath->Addr;
	
	switch(aCmd){
		case FecFunSyncSysTick ://0 同步系统节拍
			//CommPrm.State = FecCommSyncSysTick00;
			CommPrm.SetDownCmdState = FecCommSyncSysTick00;
			break;
		
		case FecFunSysReset ://1 系统复位
			CommPrm.SetDownCmdState = FecCommSysReset01;
			CommPrm.SetDownPath.CtlNum = aCmdPath->CtlNum;
			break;
		
		case FecFunSysMute ://2 系统消音
			CommPrm.SetDownCmdState = FecCommSysMute02;
			CommPrm.SetDownPath.CtlNum = aCmdPath->CtlNum;
			break;
		
		case FecFunSysSlefCheck ://3 系统自检
			CommPrm.SetDownCmdState = FecCommSysSlefCheck03;
			CommPrm.SetDownPath.CtlNum = aCmdPath->CtlNum;
			break;
		
		case FecFunSyncTime :// 设置时间
			CommPrm.SetDownCmdState = FecCommSyncTime04;
			CommPrm.SetDownPath.CtlNum = aCmdPath->CtlNum;
			break;
		
		case FecFunQueryDeviceState ://34 查设备状态
			CommPrm.SetDownCmdState = FecCommQueryDeviceState34;
			CommPrm.SetDownPath.CtlNum = aCmdPath->CtlNum;
			CommPrm.SetDownPath.UnitNum = aCmdPath->UnitNum;
			CommPrm.SetDownPath.DevNum = aCmdPath->DevNum;
			break;
		
		case FecFunQueryDeviceConfig ://35 查设备配置
			CommPrm.SetDownCmdState = FecCommQueryDeviceConfig35;
			CommPrm.SetDownPath.CtlNum = aCmdPath->CtlNum;
			CommPrm.SetDownPath.UnitNum = aCmdPath->UnitNum;
			CommPrm.SetDownPath.DevNum = aCmdPath->DevNum;
			break;
		
		case FecFunQueryDeviceIdf ://36 查设备标识
			CommPrm.SetDownCmdState = FecCommQueryDeviceIdf36;
			CommPrm.SetDownPath.CtlNum = aCmdPath->CtlNum;
			CommPrm.SetDownPath.UnitNum = aCmdPath->UnitNum;
			CommPrm.SetDownPath.DevNum = aCmdPath->DevNum;
			break;
		
		case FecFunQueryDeviceParameter ://37 查设备参量
			CommPrm.SetDownCmdState = FecCommQueryDeviceParameter37;
			CommPrm.SetDownPath.CtlNum = aCmdPath->CtlNum;
			CommPrm.SetDownPath.UnitNum = aCmdPath->UnitNum;
			CommPrm.SetDownPath.DevNum = aCmdPath->DevNum;
			CommPrm.SetDownPath.ChannelNum = aCmdPath->ChannelNum;
			break;
		
		case FecFunQueryDeviceDescp ://38 查设备注释
			CommPrm.SetDownCmdState = FecCommQueryDeviceDescp38;
			CommPrm.SetDownPath.CtlNum = aCmdPath->CtlNum;
			CommPrm.SetDownPath.UnitNum = aCmdPath->UnitNum;
			CommPrm.SetDownPath.DevNum = aCmdPath->DevNum;
			break;
		
		case FecFunQueryDeviceProgram ://39 查设备编程
			CommPrm.SetDownCmdState = FecCommQueryDeviceProgram39;
			CommPrm.SetDownPath.CtlNum = aCmdPath->CtlNum;
			CommPrm.SetDownPath.UnitNum = aCmdPath->UnitNum;
			CommPrm.SetDownPath.DevNum = aCmdPath->DevNum;
			break;
		
		case FecFunQueryDeviceRegisterInfo ://40 查注册登记信息
			CommPrm.SetDownCmdState = FecCommQueryDeviceRegisterInfo40;
			CommPrm.SetDownPath.CtlNum = aCmdPath->CtlNum;
			CommPrm.SetDownPath.UnitNum = aCmdPath->UnitNum;
			CommPrm.SetDownPath.DevNum = aCmdPath->DevNum;
			break;
		
		case FecQueryCurrentEvent :// 查询当前事件
			CommPrm.SetDownCmdState = FecCommQueryCurrentEvent41;
			CommPrm.SetDownPath.CtlNum = aCmdPath->CtlNum;
			CommPrm.SetDownPath.Event = aCmdPath->Event;
			break;
		
		case FecQueryHistoryEvent ://42 查设备历史事件
			CommPrm.SetDownCmdState = FecCommQueryHistoryEvent42;
			CommPrm.SetDownPath.CtlNum = aCmdPath->CtlNum;
			CommPrm.SetDownPath.Event = aCmdPath->Event;
			CommPrm.SetDownPath.SYear = aCmdPath->SYear;
			CommPrm.SetDownPath.SMon = aCmdPath->SMon;
			CommPrm.SetDownPath.SDay = aCmdPath->SDay;
			break;
		
		case FecStopQueryDeviceEvent ://43 停止查询设备事件
			CommPrm.SetDownCmdState = FecCommStopQueryDeviceEvent43;
			CommPrm.SetDownPath.CtlNum = aCmdPath->CtlNum;
			break;
		
		case FecQueryFECBusVer ://44 查询版本
			CommPrm.SetDownCmdState = FecCommQueryVer44;
			break;
		
		case FecQueryDeviceList ://45 查设备列表
			CommPrm.SetDownCmdState = FecCommQueryDeviceList45;
			CommPrm.SetDownPath.CtlNum = aCmdPath->CtlNum;
			CommPrm.SetDownPath.UnitNum = aCmdPath->UnitNum;
			CommPrm.SetDownPath.DevNum = aCmdPath->DevNum;
			CommPrm.SetDownPath.ChannelNum = aCmdPath->ChannelNum;
			break;
		
		default :
			CommPrm.Phase = FecPolling;
			CommPrm.SetDownCmdState = FecCommNone;
			break;
	}
}
void TFecBus::DownCmdAckHandle(void)
{
	if(CommPrm.AckStatus){
		CommPrm.State = FecCommExit;
	}else
	if(CommPrm.TimeoutTick > CommAckTimeout){
		CommPrm.TimeoutTick = 0;
		CommPrm.State = FecCommExit;
	}
}

void TFecBus::DownCmdTask(void)
{
	switch(CommPrm.State){
		case FecCommExit : 
			CommPrm.Phase = FecPolling;
			break;
		/*
		case FecCommPolling33 : 	
			fMsgTX33_InspectionDevice(CommPrm.CuuerntAddr);//发33
			CommPrm.State = FecCommPolling33Ack;
			CommPrm.AckStatus = 0;
			CommPrm.TimeoutTick = 0;
			break;
		*/
		case FecCommPolling33Ack : //等待回复
			CommPrm.State = CommPrm.SetDownCmdState;
			break;
		
		//按列设置下发命令
		case FecCommSyncSysTick00 ://0 同步系统节拍
			fMsgTX00_SysSyncTick(CommPrm.CuuerntAddr);
			CommPrm.State = FecCommSyncSysTick00Ack;
			CommPrm.AckStatus = 0;
			CommPrm.TimeoutTick = 0;
			break;
		
		case FecCommSyncSysTick00Ack :
			DownCmdAckHandle();
			break;
		
		case FecCommSysReset01 ://1 系统复位
			fMsgTX01_SysReset(CommPrm.CuuerntAddr, CommPrm.SetDownPath.CtlNum);
			CommPrm.State = FecCommSysReset01Ack;
			CommPrm.AckStatus = 0;
			CommPrm.TimeoutTick = 0;
			break;
		
		case FecCommSysReset01Ack :
			DownCmdAckHandle();
			break;
		
		case FecCommSysMute02 ://2 系统消音
			fMsgTX02_SysMute(CommPrm.CuuerntAddr, CommPrm.SetDownPath.CtlNum);
			CommPrm.State = FecCommSysMute02Ack;
			CommPrm.AckStatus = 0;
			CommPrm.TimeoutTick = 0;
			break;
		
		case FecCommSysMute02Ack :
			DownCmdAckHandle();
			break;
		
		case FecCommSysSlefCheck03 ://3 系统自检
			fMsgTX03_SysSelfCheck(CommPrm.CuuerntAddr, CommPrm.SetDownPath.CtlNum);
			CommPrm.State = FecCommSysSlefCheck03Ack;
			CommPrm.AckStatus = 0;
			CommPrm.TimeoutTick = 0;
			break;
		
		case FecCommSysSlefCheck03Ack :
			DownCmdAckHandle();
			break;
		
		case FecCommSyncTime04 :// 设置时间
			getSysTime();
			fMsgTX04_SyncTime(CommPrm.CuuerntAddr, CommPrm.SetDownPath.CtlNum, \
												dateTime.Year, \
												dateTime.Mon, \
												dateTime.Day, \
												dateTime.Hour, \
												dateTime.Min, \
												dateTime.Sec);
			CommPrm.State = FecCommSyncTime04Ack;
			CommPrm.AckStatus = 0;
			CommPrm.TimeoutTick = 0;
			break;
		
		case FecCommSyncTime04Ack :
			DownCmdAckHandle();
			break;
		
		case FecCommQueryDeviceState34 ://34 查设备状态
			if(1 == CommPrm.SetDownPath.PathLevel){
				fMsgTX34_QueryDeviceState(CommPrm.CuuerntAddr);
			}else
			if(2 == CommPrm.SetDownPath.PathLevel){
				fMsgTX34_QueryDeviceState(CommPrm.CuuerntAddr, CommPrm.SetDownPath.CtlNum);
			}else
			if(3 == CommPrm.SetDownPath.PathLevel){
				fMsgTX34_QueryDeviceState(CommPrm.CuuerntAddr, CommPrm.SetDownPath.CtlNum, CommPrm.SetDownPath.UnitNum);
			}else{
				fMsgTX34_QueryDeviceState(CommPrm.CuuerntAddr, CommPrm.SetDownPath.CtlNum, CommPrm.SetDownPath.UnitNum, CommPrm.SetDownPath.DevNum);
			}
			CommPrm.State = FecCommQueryDeviceState34Ack;
			CommPrm.AckStatus = 0;
			CommPrm.TimeoutTick = 0;
			break;
		
		case FecCommQueryDeviceState34Ack :
			DownCmdAckHandle();
			break;
		
		case FecCommQueryDeviceConfig35 ://35 查设备配置
			if(1 == CommPrm.SetDownPath.PathLevel){
				fMsgTX35_QueryDeviceConfig(CommPrm.CuuerntAddr);
			}else
			if(2 == CommPrm.SetDownPath.PathLevel){
				fMsgTX35_QueryDeviceConfig(CommPrm.CuuerntAddr, CommPrm.SetDownPath.CtlNum);
			}else
			if(3 == CommPrm.SetDownPath.PathLevel){
				fMsgTX35_QueryDeviceConfig(CommPrm.CuuerntAddr, CommPrm.SetDownPath.CtlNum, CommPrm.SetDownPath.UnitNum);
			}else{
				fMsgTX35_QueryDeviceConfig(CommPrm.CuuerntAddr, CommPrm.SetDownPath.CtlNum, CommPrm.SetDownPath.UnitNum, CommPrm.SetDownPath.DevNum);
			}
			CommPrm.State = FecCommQueryDeviceConfig35Ack;
			CommPrm.AckStatus = 0;
			CommPrm.TimeoutTick = 0;
			break;
		
		case FecCommQueryDeviceConfig35Ack :
			DownCmdAckHandle();
			break;
		
		case FecCommQueryDeviceIdf36 ://36 查设备标识
			if(1 == CommPrm.SetDownPath.PathLevel){
				fMsgTX36_QueryDeviceIdf(CommPrm.CuuerntAddr);
			}else
			if(2 == CommPrm.SetDownPath.PathLevel){
				fMsgTX36_QueryDeviceIdf(CommPrm.CuuerntAddr, CommPrm.SetDownPath.CtlNum);
			}else
			if(3 == CommPrm.SetDownPath.PathLevel){
				fMsgTX36_QueryDeviceIdf(CommPrm.CuuerntAddr, CommPrm.SetDownPath.CtlNum, CommPrm.SetDownPath.UnitNum);
			}else{
				fMsgTX36_QueryDeviceIdf(CommPrm.CuuerntAddr, CommPrm.SetDownPath.CtlNum, CommPrm.SetDownPath.UnitNum, CommPrm.SetDownPath.DevNum);
			}
			CommPrm.State = FecCommQueryDeviceIdf36Ack;
			CommPrm.AckStatus = 0;
			CommPrm.TimeoutTick = 0;
			break;
		
		case FecCommQueryDeviceIdf36Ack :
			DownCmdAckHandle();
			break;
		
		case FecCommQueryDeviceParameter37 ://37 查设备参量
			CommPrm.SetCmd37Path.CtlNum = CommPrm.SetDownPath.CtlNum & 0xFF;
			CommPrm.SetCmd37Path.UnitNum = CommPrm.SetDownPath.UnitNum & 0xFF;
			CommPrm.SetCmd37Path.DevNum = CommPrm.SetDownPath.DevNum & 0xFF;
			CommPrm.SetCmd37Path.ChannelNum = CommPrm.SetDownPath.ChannelNum & 0xFF;
			fMsgTX37_QueryDeviceParameter(CommPrm.CuuerntAddr, &CommPrm.SetCmd37Path);
			CommPrm.State = FecCommQueryDeviceParameter37Ack;
			CommPrm.AckStatus = 0;
			CommPrm.TimeoutTick = 0;
			break;
		
		case FecCommQueryDeviceParameter37Ack :
			DownCmdAckHandle();
			break;
		
		case FecCommQueryDeviceDescp38 ://38 查设备注释
			fMsgTX38_QueryDeviceDescp(CommPrm.CuuerntAddr, CommPrm.SetDownPath.CtlNum, CommPrm.SetDownPath.UnitNum, CommPrm.SetDownPath.DevNum);
			CommPrm.State = FecCommQueryDeviceDescp38Ack;
			CommPrm.AckStatus = 0;
			CommPrm.TimeoutTick = 0;
			break;
		
		case FecCommQueryDeviceDescp38Ack :
			DownCmdAckHandle();
			break;
		
		case FecCommQueryDeviceProgram39 ://39 查设备编程
			fMsgTX39_QueryDeviceProgram(CommPrm.CuuerntAddr, CommPrm.SetDownPath.CtlNum, CommPrm.SetDownPath.UnitNum, CommPrm.SetDownPath.DevNum);
			CommPrm.State = FecCommQueryDeviceProgram39Ack;
			CommPrm.AckStatus = 0;
			CommPrm.TimeoutTick = 0;
			break;
		
		case FecCommQueryDeviceProgram39Ack :
			DownCmdAckHandle();
			break;
		
		case FecCommQueryDeviceRegisterInfo40 ://40 查注册登记信息
			if(3 == CommPrm.SetDownPath.PathLevel){
				fMsgTX40_QueryDeviceRegisterInfo(CommPrm.CuuerntAddr, CommPrm.SetDownPath.CtlNum, CommPrm.SetDownPath.UnitNum);
			}else{
				fMsgTX40_QueryDeviceRegisterInfo(CommPrm.CuuerntAddr, CommPrm.SetDownPath.CtlNum, CommPrm.SetDownPath.UnitNum, CommPrm.SetDownPath.DevNum);
			}
			CommPrm.State = FecCommQueryDeviceRegisterInfo40Ack;
			CommPrm.AckStatus = 0;
			CommPrm.TimeoutTick = 0;
			break;
		
		case FecCommQueryDeviceRegisterInfo40Ack :
			DownCmdAckHandle();
			break;
		
		case FecCommQueryCurrentEvent41 :// 查询当前事件
			fMsgTX41_QueryCurrentEvent(CommPrm.CuuerntAddr, CommPrm.SetDownPath.CtlNum, CommPrm.SetDownPath.Event);
			ClearCurrentEventList(CommPrm.CuuerntAddr);
			CommPrm.State = FecCommQueryCurrentEvent41Ack;
			CommPrm.AckStatus = 0;
			CommPrm.TimeoutTick = 0;
			break;
		
		case FecCommQueryCurrentEvent41Ack :
			//43 停止查询设备事件
			if(1 == CommPrm.AckStatus){
				if((CommPrm.SetDownCmdFlag)&&(FecCommStopQueryDeviceEvent43 == CommPrm.SetDownCmdState)&&(CommPrm.SetDownPath.Addr == CommPrm.CuuerntAddr)){
					CommPrm.SetDownCmdFlag = 0;
					CommPrm.State = CommPrm.SetDownCmdState;
				}else
				if(1 == EventCodePrm[CommPrm.CurrentEventData.Data.EventCode]){
					fMsgRpy18_Ack_InformedGeneralEvent(CommPrm.CuuerntAddr);
				}else
				if(2 == EventCodePrm[CommPrm.CurrentEventData.Data.EventCode]){
					fMsgRpy17_Ack_PublishEmergencyEvent(CommPrm.CuuerntAddr);
				}
				CommPrm.AckStatus = 0;
				CommPrm.TimeoutTick = 0;
			}else
			if(2 == CommPrm.AckStatus){
				CommPrm.State = FecCommQueryCurrentEvent41Ending;
				CommPrm.TimeoutTick = 0;
				CommPrm.State = FecCommExit;
			}else
			if(CommPrm.TimeoutTick > CommAckTimeout){
				CommPrm.TimeoutTick = 0;
				CommPrm.State = FecCommExit;
			}
			break;
		
		case FecCommQueryCurrentEvent41Ending :
			CommPrm.State = FecCommExit;
			break;
		
		case FecCommQueryHistoryEvent42 ://42 查设备历史事件
			fMsgTX42_QueryHistoryEvent(CommPrm.CuuerntAddr, CommPrm.SetDownPath.CtlNum, CommPrm.SetDownPath.Event, \
																	CommPrm.SetDownPath.SYear, CommPrm.SetDownPath.SMon, CommPrm.SetDownPath.SDay);
			ClearHistoryEventList();
			CommPrm.State = FecCommQueryHistoryEvent42Ack;
			CommPrm.AckStatus = 0;
			CommPrm.TimeoutTick = 0;
			break;
		
		case FecCommQueryHistoryEvent42Ack :
			//43 停止查询设备事件
			if(1 == CommPrm.AckStatus){
				if((CommPrm.SetDownCmdFlag)&&(FecCommStopQueryDeviceEvent43 == CommPrm.SetDownCmdState)&&(CommPrm.SetDownPath.Addr == CommPrm.CuuerntAddr)){
					CommPrm.SetDownCmdFlag = 0;
					CommPrm.State = CommPrm.SetDownCmdState;
				}else
				if(1 == EventCodePrm[CommPrm.CurrentEventData.Data.EventCode]){
					fMsgRpy18_Ack_InformedGeneralEvent(CommPrm.CuuerntAddr);
				}else
				if(2 == EventCodePrm[CommPrm.CurrentEventData.Data.EventCode]){
					fMsgRpy17_Ack_PublishEmergencyEvent(CommPrm.CuuerntAddr);
				}
				CommPrm.AckStatus = 0;
				CommPrm.TimeoutTick = 0;
			}else
			if(2 == CommPrm.AckStatus){
				CommPrm.State = FecCommQueryHistoryEvent42Ending;
				CommPrm.TimeoutTick = 0;
				CommPrm.State = FecCommExit;
			}else
			if(CommPrm.TimeoutTick > CommAckTimeout){
				CommPrm.TimeoutTick = 0;
				CommPrm.State = FecCommExit;
			}
			break;
			
		case FecCommQueryHistoryEvent42Ending :
			CommPrm.State = FecCommExit;
			break;
		
		case FecCommStopQueryDeviceEvent43 ://43 停止查询设备事件
			fMsgTX43_StopQueryDeviceEvent(CommPrm.CuuerntAddr, CommPrm.SetDownPath.CtlNum);
			CommPrm.State = FecCommStopQueryDeviceEvent43Ack;
			CommPrm.AckStatus = 0;
			CommPrm.TimeoutTick = 0;
			break;
		
		case FecCommStopQueryDeviceEvent43Ack :
			DownCmdAckHandle();
			break;
		
		case FecCommQueryVer44 :// 44 查询版本
			fMsgTX44_QueryFECBusVer(CommPrm.CuuerntAddr);
			CommPrm.State = FecCommQueryVer44Ack;
			CommPrm.AckStatus = 0;
			CommPrm.TimeoutTick = 0;
			break;
		
		case FecCommQueryVer44Ack :
			DownCmdAckHandle();
			break;
		
		case FecCommQueryDeviceList45 ://45 查设备列表
			if(1 == CommPrm.SetDownPath.PathLevel){
				fMsgTX45_QueryDeviceList(CommPrm.CuuerntAddr);
			}else
			if(2 == CommPrm.SetDownPath.PathLevel){
				fMsgTX45_QueryDeviceList(CommPrm.CuuerntAddr, CommPrm.SetDownPath.CtlNum);
			}else
			if(3 == CommPrm.SetDownPath.PathLevel){
				fMsgTX45_QueryDeviceList(CommPrm.CuuerntAddr, CommPrm.SetDownPath.CtlNum, CommPrm.SetDownPath.UnitNum);
			}else{
				fMsgTX45_QueryDeviceList(CommPrm.CuuerntAddr, CommPrm.SetDownPath.CtlNum, CommPrm.SetDownPath.UnitNum, CommPrm.SetDownPath.DevNum);
			}
			CommPrm.State = FecCommQueryDeviceList45Ack;
			CommPrm.AckStatus = 0;
			CommPrm.TimeoutTick = 0;
			break;
		
		case FecCommQueryDeviceList45Ack :
			DownCmdAckHandle();
			break;
			
		default : 
			CommPrm.Phase = FecPolling;
			CommPrm.State = FecCommExit;
			break;
	}
}

//按地址巡检，下面有事件就上传
void TFecBus::SendPollingTask(void)
{
	switch(CommPrm.State){
		case FecCommExit : 
			if((CommPrm.CuuerntAddr < 63)&&(CommPrm.CuuerntAddr > 1)){
				CommPrm.CuuerntAddr++;
			}else
			if(63 == CommPrm.CuuerntAddr){
				CommPrm.CuuerntAddr = 2;
			}	
			CommPrm.Phase = FecPolling;
			CommPrm.State = FecCommPolling33;
			break;
		
		case FecCommPolling33 : 	
			fMsgTX33_InspectionDevice(CommPrm.CuuerntAddr);//发33
			CommPrm.State = FecCommPolling33Ack;
			CommPrm.AckStatus = 0;
			CommPrm.TimeoutTick = 0;		
			break;
		
		case FecCommPolling33Ack : //等待回复
			if(1 == CommPrm.AckStatus){
				if((CommPrm.SetDownCmdFlag)||(CommPrm.SetDownEventFlag)){
					if(CommPrm.CuuerntAddr != CommPrm.SetDownPath.Addr){
						CommPrm.CuuerntAddr = CommPrm.SetDownPath.Addr;
						fMsgTX33_InspectionDevice(CommPrm.CuuerntAddr);//发33
						CommPrm.State = FecCommPolling33Ack;
						CommPrm.AckStatus = 0;
						CommPrm.TimeoutTick = 0;
					}else{
						if(CommPrm.SetDownCmdFlag){
							CommPrm.SetDownCmdFlag = 0;
							CommPrm.Phase = FecDownCmd;
							CommPrm.CuuerntAddr = CommPrm.SetDownPath.Addr;
						}else
						if(CommPrm.SetDownEventFlag){
							CommPrm.SetDownEventFlag = 0;
							CommPrm.Phase = FecDownEvent;
							CommPrm.CuuerntAddr = CommPrm.SetDownPath.Addr;
						}
					}
				}else{
					CommPrm.State = FecCommExit;
				}
			}else
			if(2 == CommPrm.AckStatus){//建立连接，重新配置
				CommPrm.Phase = FecSetUpComm;
				CommPrm.State = FecCommSyncTime04;
			}else
			if(3 == CommPrm.AckStatus){//子系统有事件上传，上传完一个，再跳到巡检，知道上传完为止
				if(1 == EventCodePrm[CommPrm.UpEventData.Data.EventCode]){
					fMsgRpy18_Ack_InformedGeneralEvent(CommPrm.CuuerntAddr);
					CommPrm.NoAckTick = 3;//delay 30ms
				}else
				if(2 == EventCodePrm[CommPrm.UpEventData.Data.EventCode]){
					fMsgRpy17_Ack_PublishEmergencyEvent(CommPrm.CuuerntAddr);
					CommPrm.NoAckTick = 3;//delay 30ms
				}
				CommPrm.State = FecCommDelay;
			}else
			if(CommPrm.TimeoutTick > CommAckTimeout){
				CommPrm.TimeoutTick = 0;
				if(GetRegisterStatus(CommPrm.CuuerntAddr))SetLogout(CommPrm.CuuerntAddr);
				
				if((CommPrm.SetDownCmdFlag)||(CommPrm.SetDownEventFlag)){
					if(CommPrm.CuuerntAddr != CommPrm.SetDownPath.Addr){
						CommPrm.CuuerntAddr = CommPrm.SetDownPath.Addr;
						fMsgTX33_InspectionDevice(CommPrm.CuuerntAddr);//发33
						CommPrm.AckStatus = 0;
						CommPrm.TimeoutTick = 0;
					}else{
						if(CommPrm.SetDownCmdFlag){
							CommPrm.SetDownCmdFlag = 0;
						}
						if(CommPrm.SetDownEventFlag){
							CommPrm.SetDownEventFlag = 0;
						}
						CommPrm.State = FecCommExit;
					}
				}else{
					CommPrm.State = FecCommExit;
				}
			}
			
			if(CommPrm.AckStatus){
				if(!GetRegisterStatus(CommPrm.CuuerntAddr)){
					SetRegister(CommPrm.CuuerntAddr);
				}
			}
			break;
		
		case FecCommDelay ://延时等待发送完
			if(0 == CommPrm.NoAckTick)CommPrm.State = FecCommPolling33;
			break;
			
		default : 
			CommPrm.CuuerntAddr = 2;
			CommPrm.State = FecCommPolling33;
			break;
	}
}

void TFecBus::OperationTask(void)
{
	static unsigned char Ord = 0;
	
	if(RxHandleFlag){
		RxHandleFlag = 0;
		uDataRXTask();
	}
		
	switch(CommPrm.Phase){
		case FecNotConnected: //0 没有连接
			CommPrm.CuuerntAddr = 2;
			CommPrm.Phase = FecPolling;
			CommPrm.State = FecCommPolling33;
			break;
		
		case FecSetUpComm: //1 建立连接
			SetUpCommTask();
			break;
		
		case FecPolling: //2 巡检
			SendPollingTask();
			break;
		
		case FecDownEvent: //3 下发事件
			DownEventTask();
			break;
		
		case FecDownCmd: //4 设置命令
			DownCmdTask();
			break;
		
		default : 
			CommPrm.Phase = FecNotConnected;
			break;
	}
	
	DebugProcess();
}

void TFecBus::DebugProcess(void)
{
	static TFecCmdPath  aSetCmdPath;
	static TFecEventBufBody aSetEvent;
	u16 aEvent;
	
	if(SetDebug.Flag){
		SetDebug.Flag = 0;
		
		switch(SetDebug.Prm.Body.Cmd){
			case FecFunSyncSysTick ://0 同步系统节拍
			case FecFunSysReset ://1 系统复位
			case FecFunSysMute ://2 系统消音
			case FecFunSysSlefCheck ://3 系统自检
			case FecFunSyncTime ://4 广播时钟
			case FecFunInspectionDevice ://33 设备巡检
			case FecFunQueryDeviceState ://34 查设备状态
			case FecFunQueryDeviceConfig ://35 查设备配置
			case FecFunQueryDeviceIdf ://36 查设备标识
			case FecFunQueryDeviceParameter ://37 查设备参量
			case FecFunQueryDeviceDescp ://38 查设备注释
			case FecFunQueryDeviceProgram ://39 查设备编程
			case FecFunQueryDeviceRegisterInfo ://40 查注册登记信息
			case FecQueryCurrentEvent ://41 查设备当前事件
			case FecQueryHistoryEvent ://42 查设备历史事件
			case FecStopQueryDeviceEvent ://43 停止查询设备事件
			case FecQueryFECBusVer ://44 查FECBus协议版本号
			case FecQueryDeviceList ://45 查设备列表
				aSetCmdPath.Addr = SetDebug.Prm.Body.DesAddr;
				aSetCmdPath.CtlNum = SetDebug.Prm.Body.Data[0];
				aSetCmdPath.UnitNum = SetDebug.Prm.Body.Data[1];
				aSetCmdPath.DevNum = SetDebug.Prm.Body.Data[2];
				aSetCmdPath.ChannelNum = SetDebug.Prm.Body.Data[3];
				aSetCmdPath.PathLevel = SetDebug.Prm.Body.Data[4];
				aSetCmdPath.SYear = SetDebug.Prm.Body.Data[5];
				aSetCmdPath.SMon = SetDebug.Prm.Body.Data[6];
				aSetCmdPath.SDay = SetDebug.Prm.Body.Data[7];
				aEvent = SetDebug.Prm.Body.Data[8];
				aEvent<<=8;
				aEvent |= SetDebug.Prm.Body.Data[9];
				aSetCmdPath.Event = (TFecEventCode)aEvent;
				EnterSetDownCmd((TFecFunctionCode)SetDebug.Prm.Body.Cmd, &aSetCmdPath);
				break;
			
			case FecFunPublishEmergencyEvent ://5 通告紧急事件
			case FecFunPublishGeneralEvent ://6 通告一般事件
			case FecFunPublishAdjustEvent ://7 通告调试事件
				ClearDownEventList();
			
				aSetEvent.Data.CtlNum = 6;//控制器编号（1字节）
				aSetEvent.Data.UnitNum = 6;//单元编号（1字节）
				aSetEvent.Data.DeviceNum = 6; //设备编号（1字节）
				aSetEvent.Data.ChannelNum = 1; //通道编号（1字节）
				aSetEvent.Data.DeviceCode = ftFireSmokeDetecter; //设备类型代码（2字节）
				aSetEvent.Data.EventCode = evElevatorLanding; //事件代码（2字节）
				aSetEvent.Data.StateCode.D16 = 6; //状态代码（2字节）
				aSetEvent.Data.Year = 24;//年（1字节）
				aSetEvent.Data.Mon = 6;//月（1字节）
				aSetEvent.Data.Day = 6;//日（1字节）
				aSetEvent.Data.Hour = 6;//时（1字节）
				aSetEvent.Data.Min = 6;//分（1字节）
				aSetEvent.Data.Sec = 6;//秒（1字节）
				AddDownEventList(&aSetEvent);
			
				aSetEvent.Data.CtlNum = 5;//控制器编号（1字节）
				aSetEvent.Data.UnitNum = 5;//单元编号（1字节）
				aSetEvent.Data.DeviceNum = 5; //设备编号（1字节）
				aSetEvent.Data.ChannelNum = 1; //通道编号（1字节）
				aSetEvent.Data.DeviceCode = ftDisplayPad; //设备类型代码（2字节）
				aSetEvent.Data.EventCode = evFireAlarmElectrical; //事件代码（2字节）
				aSetEvent.Data.StateCode.D16 = 6; //状态代码（2字节）
				aSetEvent.Data.Year = 24;//年（1字节）
				aSetEvent.Data.Mon = 5;//月（1字节）
				aSetEvent.Data.Day = 5;//日（1字节）
				aSetEvent.Data.Hour = 5;//时（1字节）
				aSetEvent.Data.Min = 5;//分（1字节）
				aSetEvent.Data.Sec = 5;//秒（1字节）
				AddDownEventList(&aSetEvent);
			
				EnterSetDownEvent(SetDebug.Prm.Body.DesAddr);
				break;
			
			default :
				break;
		}
	}
}

void TFecBus::TriggerCmd01SysReset(void)
{
	SetDebug.Flag = 1;
	SetDebug.Prm.Body.DesAddr = 6;
	SetDebug.Prm.Body.Cmd = FecFunSysReset;
	SetDebug.Prm.Body.Data[0] = 0;//CtlNum
}

void TFecBus::TriggerCmd02SysMute(void)
{
	SetDebug.Flag = 1;
	SetDebug.Prm.Body.DesAddr = 6;
	SetDebug.Prm.Body.Cmd = FecFunSysMute;
	SetDebug.Prm.Body.Data[0] = 0;//CtlNum
}

void TFecBus::TrigerCmd03SysSlefCheck(void)
{
	SetDebug.Flag = 1;
	SetDebug.Prm.Body.DesAddr = 6;
	SetDebug.Prm.Body.Cmd = FecFunSysSlefCheck;
	SetDebug.Prm.Body.Data[0] = 0;//CtlNum
}

void TFecBus::TriggerCmd04SyncTime(void)
{
	SetDebug.Flag = 1;
	SetDebug.Prm.Body.DesAddr = 6;
	SetDebug.Prm.Body.Cmd = FecFunSyncTime;
	SetDebug.Prm.Body.Data[0] = 0;//CtlNum
}

//void EnterSetDownCmd(TFecFunctionCode aCmd, TFecCmdPath * aCmdPath);
//void EnterSetDownEvent(u8 aAddr);










