/*******************************************************************************
*                                                                              *
* Société de Transports de Montréal.                                    	   *
* 2012                                                                         *
*                                                                              *
* Projet Zones Tests                                                           *
*                                                                              *
*                                                                              *
*                                                                              *
*******************************************************************************/
/*
    Description:
	Classe instantiable dérivée de la classe de base CStation.  Les paramètres
	physiques de la station sont définis et initialisés ici.  Ils sont ensuite
	accédés de manière générique à travers la classe CStation.
	Les paramètres dépend du câblage de l'armoire ZT et de la configuration
	particulière des CDVs de la station.
    
*/

/* ************************************************************************** */
/* Revision:
### 20121220 JFM
    Verision d'origine.
    
### YYYYMMDD Description du besoin ou du bug
    Description du changement.
 */

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

#include "Snowdon.h"
#include <QtGlobal>

CSnowdonStation::CSnowdonStation()
{
    //All the inherited variables from base class must be initialized here
    //according to the physical implementation in the station.
    mNbExtInputModules430 = SNOWDON_NB_EXTERNAL_INPUT_430_MODULES;
    mNbExtOutputModules440 = SNOWDON_NB_EXTERNAL_OUTPUT_440_MODULES;
    mNbExtMixedModules470 = SNOWDON_NB_EXTERNAL_MIXED_470_MODULES;
    mStationPhysicalKey = SNOWDON_STATION_KEY;
    //Initialize mask structures
    //

    mStationInputMasks.InputZT1S1Mask = SNOWDON_ZT1_S1_MASK;
    mStationInputMasks.InputZT1S2Mask = SNOWDON_ZT1_S2_MASK;
    mStationInputMasks.InputZT1PIMask = SNOWDON_ZT1_PI_MASK;
    mStationInputMasks.InputZT1PEMask = SNOWDON_ZT1_PE_MASK;
    mStationInputMasks.InputZT1FNMask = SNOWDON_ZT1_FN_MASK;
    mStationInputMasks.InputZT2S1Mask = SNOWDON_ZT2_S1_MASK;
    mStationInputMasks.InputZT2PIMask = SNOWDON_ZT2_PI_MASK;
    mStationInputMasks.InputZT2PEMask = SNOWDON_ZT2_PE_MASK;

    //External (ethernet) input module masks
    mStationInputMasks.InputZT1ITIMask = SNOWDON_IN_ZT1_ITI_MASK;
    mStationInputMasks.InputZT2ITIMask = SNOWDON_IN_ZT2_ITI_MASK;
    mStationInputMasks.InputZT1ANMask = SNOWDON_IN_ZT1_AN_MASK;
    mStationInputMasks.InputZT2ANMask = SNOWDON_IN_ZT2_AN_MASK;
    mStationInputMasks.InputZT1ARFMask = SNOWDON_IN_ZT1_ARF_MASK;
    mStationInputMasks.InputZT2ARFMask = SNOWDON_IN_ZT2_ARF_MASK;
    mStationInputMasks.InputStationIDMask = SNOWDON_IN_STATION_ID_MASK;

    //Logic input masks
    mStationInputMasks.InputCDVZT1ApproachMask = SNOWDON_IN_CDV_22C_MASK;
    mStationInputMasks.InputCDVZT1Mask = SNOWDON_IN_CDV_22B_MASK;

    //No ZT2 at Snowdon...
    mStationInputMasks.InputCDVZT2ApproachMask = 0;
    mStationInputMasks.InputCDVZT2Mask = 0;

    //Output masks
    mStationOutputMasks.OutputVP1Mask = SNOWDON_OUT_VP1_MASK;
    mStationOutputMasks.OutputVP2Mask = SNOWDON_OUT_VP2_MASK;
    mStationOutputMasks.OutputVP3Mask = SNOWDON_OUT_VP3_MASK;
    mStationOutputMasks.OutputVP4Mask = SNOWDON_OUT_VP4_MASK;
    mStationOutputMasks.OutputVP5Mask = SNOWDON_OUT_VP5_MASK;
    mStationOutputMasks.OutputVP6Mask = SNOWDON_OUT_VP6_MASK;
    mStationOutputMasks.OutputVF1Mask = SNOWDON_OUT_VF1_MASK;
    mStationOutputMasks.OutputVF2Mask = SNOWDON_OUT_VF2_MASK;
    mStationOutputMasks.OutputVF3Mask = SNOWDON_OUT_VF3_MASK;
    mStationOutputMasks.OutputVF4Mask = SNOWDON_OUT_VF4_MASK;
    mStationOutputMasks.OutputVF5Mask = SNOWDON_OUT_VF5_MASK;
    mStationOutputMasks.OutputWP1Mask = SNOWDON_OUT_WP1_MASK;
    mStationOutputMasks.OutputWP2Mask = SNOWDON_OUT_WP2_MASK;
    mStationOutputMasks.OutputWP3Mask = SNOWDON_OUT_WP3_MASK;
    mStationOutputMasks.OutputWP4Mask = SNOWDON_OUT_WP4_MASK;
    mStationOutputMasks.OutputWP5Mask = SNOWDON_OUT_WP5_MASK;
    mStationOutputMasks.OutputWP6Mask = SNOWDON_OUT_WP6_MASK;
    mStationOutputMasks.OutputDPEMask = SNOWDON_OUT_DPE_MASK;
    mStationOutputMasks.OutputDPIMask = SNOWDON_OUT_DPI_MASK;
    mStationOutputMasks.OutputV00Mask = SNOWDON_OUT_V00_MASK;
    mStationOutputMasks.OutputDPGMask = SNOWDON_OUT_DPG_MASK;
    mStationOutputMasks.OutputDFRMask = SNOWDON_OUT_DFR_MASK;
    mStationOutputMasks.OutputRFMask = SNOWDON_OUT_RF_MASK;
    mStationOutputMasks.OutputRF2Mask = SNOWDON_OUT_RF2_MASK;
    mStationOutputMasks.OutputVELMask = SNOWDON_OUT_VEL_MASK;
    mStationOutputMasks.OutputVEL2Mask = SNOWDON_OUT_VEL2_MASK;
    mStationOutputMasks.OutputDPI2Mask = SNOWDON_OUT_DPI2_MASK;
    mStationOutputMasks.OutputDPE2Mask = SNOWDON_OUT_DPE2_MASK;
    mStationOutputMasks.OutputV002Mask = SNOWDON_OUT_V002_MASK;
    mStationOutputMasks.OutputPEQ1Mask = SNOWDON_OUT_PEQ1_MASK;
    mStationOutputMasks.OutputPEQ2Mask = SNOWDON_OUT_PEQ2_MASK;
    mStationOutputMasks.OutputWatchdogMask = SNOWDON_OUT_WATCHDOG_MASK;

	mAnalogAcqChannels.SDFAcquisitionChannel = SNOWDON_SDF_ACQUISITION_CHANNEL;

    mStationHasZT2 = false;
    mTextualStationName = "Snowdon";
	mTextualShortName = "SNW5";
}

unsigned int CSnowdonStation::BuildStationCDVList()
{
    CCDV *NewCDV;
    mCDVList.empty();

	NewCDV = new CCDV(0,SNOWDON_IN_CDV_20A_MASK,CDV_NORMAL_TYPE,"20A",1,0);
    mCDVList.append(NewCDV);

	NewCDV = new CCDV(0,SNOWDON_IN_CDV_20B_MASK,CDV_NORMAL_TYPE,"20B",1,1);
    mCDVList.append(NewCDV);

	NewCDV = new CCDV(0,SNOWDON_IN_CDV_20C_MASK,CDV_NORMAL_TYPE,"20C",1,2);
    mCDVList.append(NewCDV);

	NewCDV = new CCDV(0,SNOWDON_IN_CDV_21_MASK,CDV_NORMAL_TYPE,"21",1,3);
	NewCDV->SetInputMask(SNOWDON_IN_CDV_21_MASK);
	mCDVList.append(NewCDV);

	NewCDV = new CCDV(SNOWDON_IN_ZT1_ITI_MASK,SNOWDON_IN_CDV_22A_MASK,CDV_NORMAL_TYPE,"22A",1,4);
	mZT1AlarmAutoAcquireCDV = NewCDV;
    mCDV22A = NewCDV;
    mCDVList.append(NewCDV);

	NewCDV = new CCDV(SNOWDON_IN_ZT1_ITI_MASK,SNOWDON_IN_CDV_22B_MASK,CDV_NORMAL_TYPE,"22B (ZT1)",1,5);
    mZT1CDV = NewCDV;
    mCDVList.append(NewCDV);

	NewCDV = new CCDV(SNOWDON_IN_ZT1_ITI_MASK,SNOWDON_IN_CDV_22C_MASK,CDV_NORMAL_TYPE,"22C",1,6);
    mCDV22C = NewCDV;
    mCDVList.append(NewCDV);
    NewCDV->SetCDVDeck(true);

	NewCDV = new CCDV(SNOWDON_IN_ZT1_ITI_MASK,SNOWDON_IN_CDV_23_MASK,CDV_NORMAL_TYPE,"23",1,7);
    mZT1ApproachCDV = NewCDV;
    mCDVList.append(NewCDV);

	NewCDV = new CCDV(SNOWDON_IN_ZT1_ITI_MASK,SNOWDON_IN_CDV_24A_MASK,CDV_NORMAL_TYPE,"24A",1,8);
    mCDVList.append(NewCDV);

    return RET_OK;
}

bool CSnowdonStation::IsZT1AnalysisFinished()
{
    //At Snowdon, we must stop the ZT1 analysis when the CDV 22A is occupied or when ZT1 CDV (22B | 22C) is free.
    if(mCDV22A->IsOccupied() || !IsZT1CDVOccupied())
    {
        return true;
    }

    return false;
}

bool CSnowdonStation::IsZT1CDVOccupied()
{
    if(mZT1CDV->IsOccupied() || mCDV22C->IsOccupied())  //Combine CDV 22B and 22C as the ZT1 CDV because equipment is too close from the deck
    {
        return true;
    }

    return false;
}

