#include "MainCtl.h"

#define dNetStateCtlUsingByte			16384
#define dNetStateCtlUsingInt			4096
#define dNetStateCtlPortUsingByte		256

void TThisMainCtl::ClearVisioInf(void)
{
	CountAllDevice = 0;
	CountRootDev = 0;
	CountPort =0;
	CountHandCtl =0;
	CountDirectCtl =0;
	CountMotherBoard =0;
	CountCommBoard =0;
	CountEpAll =0;
	CountEp.UnDefine =0;
	CountEp.Unknown =0;
	CountEp.Smoker =0;
	CountEp.Tempe =0;
	CountEp.SmokeTempe = 0;
	CountEp.HandReport =0;
	CountEp.Fire_hydrant_Kp = 0;
	CountEp.Input =0;
	CountEp.Output =0;
	CountEp.InOut =0;
	CountEp.VaAlram =0;
	CountEp.DisplayPad =0;
	CountEp.LnkPs =0;
	CountHandCtlPad =0;
	CountDirectCtlPad =0;
}

void TThisMainCtl::ClearNormalInf(void)
{
	CountEpNormal.Unknown =0;
	CountEpNormal.UnDefine =0;
	CountEpNormal.Smoker =0;
	CountEpNormal.Tempe =0;
	CountEpNormal.SmokeTempe = 0;
	CountEpNormal.HandReport =0;
	CountEpNormal.Fire_hydrant_Kp = 0;
	CountEpNormal.Input =0;
	CountEpNormal.Output =0;
	CountEpNormal.InOut =0;
	CountEpNormal.VaAlram =0;
	CountEpNormal.DisplayPad =0;
	CountEpNormal.LnkPs =0;
}

void TThisMainCtl::ClearFaultInf(void)
{
	CountEpFault.Unknown =0;
	CountEpFault.UnDefine =0;
	CountEpFault.Smoker =0;
	CountEpFault.Tempe =0;
	CountEpFault.SmokeTempe = 0;
	CountEpFault.HandReport =0;
	CountEpFault.Fire_hydrant_Kp = 0;
	CountEpFault.Input =0;
	CountEpFault.Output =0;
	CountEpFault.InOut =0;
	CountEpFault.VaAlram =0;
	CountEpFault.DisplayPad =0;
	CountEpFault.LnkPs =0;
}

void TThisMainCtl::ClearMaskInf(void)
{
	CountEpMask.Unknown =0;
	CountEpMask.UnDefine =0;
	CountEpMask.Smoker =0;
	CountEpMask.Tempe =0;
	CountEpMask.SmokeTempe = 0;
	CountEpMask.HandReport =0;
	CountEpMask.Fire_hydrant_Kp = 0;
	CountEpMask.Input =0;
	CountEpMask.Output =0;
	CountEpMask.InOut =0;
	CountEpMask.VaAlram =0;
	CountEpMask.DisplayPad =0;
	CountEpMask.LnkPs =0;
}

void TThisMainCtl::LoadVisioInf()
{
	unsigned int sPath0,sPath1,aType0,aType1;
	int i, j;
	unsigned int aIndex, aCount;
	unsigned char aType;
	
	ClearVisioInf();
	
	CountPort = fData.Split.PortCount;
	CountHandCtl = fData.Split.HandCtlCount;
	CountDirectCtl = fData.Split.DirectCtlCount;
	CountMotherBoard = fData.Split.MotherBoardCount;
	CountCommBoard = fData.Split.CommModuleCount;
	CountEpAll =0;
	for(i=0; i<dPORT_MAX_COUNT; i++){
		if(fData.Split.ExistTablePort[i] == 0xA5){
			for(j=0; j<250; j++){
				if(Port[i].ExistTable[j]){
					CountEpAll++;
					aType = Port[i].dTypeTable[j];
					if(aType == 0){
						CountEp.UnDefine++;
					}else
					if(  (aType == dgTYPE_SMOKE_DETECTOR)  ){
						     CountEp.Smoker++;
					}else
					if(  aType ==  dgTYPE_TEMPE_DETECTOR ){
						     CountEp.Tempe++;
					}else
					if(  (aType == dgTYPE_HAND_REPORT ) ){
						     CountEp.HandReport++;
					}else
					if(  (aType == dgTYPE_FIRE_HydrantKp ) ){
						     CountEp.Fire_hydrant_Kp++;
					}else
					if(  (aType == dgTYPE_IN_MODULE ) ){
						     CountEp.Input++;
					}else
					if(   (aType == dgTYPE_INOUT_MODULE_NonSource) ||
						(aType == dgTYPE_INOUT_MODULE_Source) ){
						     CountEp.InOut++;
					}else
					if(  (aType == dgTYPE_OUT_MODULE) ){
						     CountEp.Output++;
					}else
					if(  (aType == dgType_VAALRAM )  ){
						     CountEp.VaAlram++;
					}else
					if(  aType == dgTYPE_DISPLAY_PAD ){
						     CountEp.DisplayPad++;
					}else
					if(  aType == dgTYPE_LINKAGE_POWERSUPLY ){
						     CountEp.LnkPs++;
					}else{
						CountEp.Unknown++;
					}
						
				}
			}
		}
	}
	
	for(i=0; i<dHANDCTL_MAX_COUNT; i++){
		if(MainCtl.fData.Split.ExistTableHandCtl[i] == 0xA5){
			CountHandCtlPad += HandCtlBoard[i].fData.HandCtl.ResistedCount;
		}
	}
	
	for(i=0; i<dDIRECTCTL_MAX_COUNT; i++){
		if(MainCtl.fData.Split.ExistTableDirectCtl[i] == 0xA5){
			CountHandCtlPad += DirectCtlBoard[i].fData.HandCtl.ResistedCount;
		}
	}
	
	CountRootDev = CountPort +	CountHandCtl + CountDirectCtl + CountMotherBoard;
	CountAllDevice = 	CountRootDev + CountEpAll;
}

void TThisMainCtl::LoadNormalInf()
{
	unsigned int sPath0,sPath1,aType0,aType1;
	int i, j;
	unsigned int aIndex, aCount;
	unsigned char aType;
	
	ClearNormalInf();
	
	for(i=0; i<dPORT_MAX_COUNT; i++){
		if(fData.Split.ExistTablePort[i] == 0xA5){
			for(j=0; j<250; j++){
				if(Port[i].ExistTable[j]){
					aType = Port[i].dTypeTable[j];
					if(  (Port[i].StateTable[j] & (dEpStateBitFault + dEpStateBitMask)) == 0) {
						if(aType == 0){
							CountEpNormal.UnDefine++;
						}else
						if(  (aType == dgTYPE_SMOKE_DETECTOR)  ){
							     CountEpNormal.Smoker++;
						}else
						if(  aType ==  dgTYPE_TEMPE_DETECTOR ){
							     CountEpNormal.Tempe++;
						}else
						if(  (aType == dgTYPE_HAND_REPORT ) ){
							     CountEpNormal.HandReport++;
						}else
						if(  (aType == dgTYPE_FIRE_HydrantKp ) ){
							     CountEpNormal.Fire_hydrant_Kp++;
						}else
						if(  (aType == dgTYPE_IN_MODULE ) ){
							     CountEpNormal.Input++;
						}else
						if(   (aType == dgTYPE_INOUT_MODULE_NonSource) ||
							(aType == dgTYPE_INOUT_MODULE_Source) ){
							     CountEpNormal.InOut++;
						}else
						if(  (aType == dgTYPE_OUT_MODULE) ){
							     CountEpNormal.Output++;
						}else
						if(  (aType == dgType_VAALRAM )  ){
							     CountEpNormal.VaAlram++;
						}else
						if(  aType == dgTYPE_DISPLAY_PAD ){
							     CountEpNormal.DisplayPad++;
						}else
						if(  aType == dgTYPE_LINKAGE_POWERSUPLY ){
							     CountEpNormal.LnkPs++;
						}else{
							CountEpNormal.Unknown++;
						}
					}
				}
			}
		}
	}
}


void TThisMainCtl::LoadFaultInf()
{
	unsigned int sPath0,sPath1,aType0,aType1;
	int i, j;
	unsigned int aIndex, aCount;
	unsigned char aType;
	
	ClearFaultInf();
	
	for(i=0; i<dPORT_MAX_COUNT; i++){
		if(fData.Split.ExistTablePort[i] == 0xA5){
			for(j=0; j<250; j++){
				if(Port[i].ExistTable[j]){
					aType = Port[i].dTypeTable[j];
					if(Port[i].StateTable[j] & dEpStateBitFault){
						if(aType == 0){
							CountEpFault.UnDefine++;
						}else
						if(  (aType == dgTYPE_SMOKE_DETECTOR)  ){
							     CountEpFault.Smoker++;
						}else
						if(  aType ==  dgTYPE_TEMPE_DETECTOR ){
							     CountEpFault.Tempe++;
						}else
						if(  (aType == dgTYPE_HAND_REPORT ) ){
							     CountEpFault.HandReport++;
						}else
						if(  (aType == dgTYPE_FIRE_HydrantKp ) ){
							     CountEpFault.Fire_hydrant_Kp++;
						}else
						if(  (aType == dgTYPE_IN_MODULE ) ){
							     CountEpFault.Input++;
						}else
						if(   (aType == dgTYPE_INOUT_MODULE_NonSource) ||
							(aType == dgTYPE_INOUT_MODULE_Source) ){
							     CountEpFault.InOut++;
						}else
						if(  (aType == dgTYPE_OUT_MODULE) ){
							     CountEpFault.Output++;
						}else
						if(  (aType == dgType_VAALRAM )  ){
							     CountEpFault.VaAlram++;
						}else
						if(  aType == dgTYPE_DISPLAY_PAD ){
							     CountEpFault.DisplayPad++;
						}else
						if(  aType == dgTYPE_LINKAGE_POWERSUPLY ){
							     CountEpFault.LnkPs++;
						}else{
							CountEpFault.Unknown++;
						}
					}
				}
			}
		}
	}
}

void TThisMainCtl::LoadMaskInf()
{
	unsigned int sPath0,sPath1,aType0,aType1;
	int i, j;
	unsigned int aIndex, aCount;
	unsigned char aType;
	
	ClearMaskInf();
	
	for(i=0; i<dPORT_MAX_COUNT; i++){
		
		if(fData.Split.ExistTablePort[i] == 0xA5){
			for(j=0; j<250; j++){
				if(Port[i].ExistTable[j]){
					aType = Port[i].dTypeTable[j];
					if(Port[i].StateTable[j] & dEpStateBitMask){
						if(aType == 0){
							CountEpMask.UnDefine++;
						}else
						if(  (aType == dgTYPE_SMOKE_DETECTOR)  ){
							     CountEpMask.Smoker++;
						}else
						if(  aType ==  dgTYPE_TEMPE_DETECTOR ){
							     CountEpMask.Tempe++;
						}else
						if(  (aType == dgTYPE_HAND_REPORT ) ){
							     CountEpMask.HandReport++;
						}else
						if(  (aType == dgTYPE_FIRE_HydrantKp ) ){
							     CountEpMask.Fire_hydrant_Kp++;
						}else
						if(  (aType == dgTYPE_IN_MODULE ) ){
							     CountEpMask.Input++;
						}else
						if(   (aType == dgTYPE_INOUT_MODULE_NonSource) ||
							(aType == dgTYPE_INOUT_MODULE_Source) ){
							     CountEpMask.InOut++;
						}else
						if(  (aType == dgTYPE_OUT_MODULE) ){
							     CountEpMask.Output++;
						}else
						if(  (aType == dgType_VAALRAM )  ){
							     CountEpMask.VaAlram++;
						}else
						if(  aType == dgTYPE_DISPLAY_PAD ){
							     CountEpMask.DisplayPad++;
						}else
						if(  aType == dgTYPE_LINKAGE_POWERSUPLY ){
							     CountEpMask.LnkPs++;
						}else{
							CountEpMask.Unknown++;
						}
					}	
				}
			}
		}
	}
}

void TThisMainCtl::ClearState()
{
	int i,x;
	for(i=0; i<dPORT_MAX_COUNT; i++){
		Port[i].ResetCallBack();
	}
	for(i=0; i<dHANDCTL_MAX_COUNT; i++){
		HandCtlBoard[i].ResetCallBack();
	}
	for(i=0; i<dDIRECTCTL_MAX_COUNT; i++){
		DirectCtlBoard[i].ResetCallBack();
	}
	MotherBoard.ResetCallBack();
}

void TThisMainCtl::RecallCrcFaultMsg()
{
	if(MainCtl.CrcFlag.PortList)
		CtlCenter.ieAddBrdFault(41,TBoardFaultType::StoragePortList);
}

