#ifndef CSTATION_H
#define CSTATION_H

/*******************************************************************************
*                                                                              *
* Société de Transports de Montréal.                                    	   *
* 2012                                                                         *
*                                                                              *
* Projet Zones Tests                                                           *
*                                                                              *
*                                                                              *
*                                                                              *
*******************************************************************************/
/*
    Description:
    Description du fichier si nécessaire.

*/

/* ************************************************************************** */
/* Revision:
### 20121210 JFM
    Verision d'origine.

### YYYYMMDD Description du besoin ou du bug
    Description du changement.
 */

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

#include "GlobalDefine.h"
#ifndef WINDOWS_OS
#include "ExternalIOMgr.h"
#endif
//#include "Seaio430driver.h"
//#include "Seaio440driver.h"
//#include "Seaio470driver.h"
#include "InputModule.h"
#include "OutputModule.h"
#include "MixedModule.h"
#include "LazerProbesMgr.h"
#include "LazerProbe.h"
#include "ZTData.h"
//#include "CDVItem.h"
#include "IOManager.h"
#include "CDV.h"


//Masques des sorties génériques communes à toutes les stations
typedef struct eGenericOutputMasks
{
	unsigned int OutputVP1Mask;
	unsigned int OutputVP2Mask;
	unsigned int OutputVP3Mask;
	unsigned int OutputVP4Mask;
	unsigned int OutputVP5Mask;
	unsigned int OutputVP6Mask;
	unsigned int OutputVF1Mask;
	unsigned int OutputVF2Mask;
	unsigned int OutputVF3Mask;
	unsigned int OutputVF4Mask;
	unsigned int OutputVF5Mask;
	unsigned int OutputWP1Mask;
	unsigned int OutputWP2Mask;
	unsigned int OutputWP3Mask;
	unsigned int OutputWP4Mask;
	unsigned int OutputWP5Mask;
	unsigned int OutputWP6Mask;
	unsigned int OutputDPEMask;
	unsigned int OutputDPIMask;
	unsigned int OutputV00Mask;
	unsigned int OutputDPGMask;
	unsigned int OutputDFRMask;
	unsigned int OutputRFMask;
	unsigned int OutputRF2Mask;
	unsigned int OutputVELMask;
	unsigned int OutputVEL2Mask;
	unsigned int OutputDPI2Mask;
    unsigned int OutputDPE2Mask;
	unsigned int OutputV002Mask;
    unsigned int OutputPEQ1Mask;
    unsigned int OutputPEQ2Mask;
    unsigned int OutputWatchdogMask;
}GenericOutputMasks_t;

//Identificatieurs des sorties génériques communes à toutes les stations
enum eGenericOutputIDs
{
    GENERIC_OUTPUT_VP1_ID,
    GENERIC_OUTPUT_VP2_ID,
    GENERIC_OUTPUT_VP3_ID,
    GENERIC_OUTPUT_VP4_ID,
    GENERIC_OUTPUT_VP5_ID,
    GENERIC_OUTPUT_VP6_ID,

    GENERIC_OUTPUT_DPE_ID,
    GENERIC_OUTPUT_DPI_ID,
    GENERIC_OUTPUT_V00_ID,

    GENERIC_OUTPUT_VF1_ID,
    GENERIC_OUTPUT_VF2_ID,
    GENERIC_OUTPUT_VF3_ID,
    GENERIC_OUTPUT_VF4_ID,
    GENERIC_OUTPUT_VF5_ID,

    GENERIC_OUTPUT_DPG_ID,
    GENERIC_OUTPUT_DFR_ID,
    GENERIC_OUTPUT_RF_ID,
    GENERIC_OUTPUT_VEL_ID,
    GENERIC_OUTPUT_VEL2_ID,

    GENERIC_OUTPUT_WP1_ID,
    GENERIC_OUTPUT_WP2_ID,
    GENERIC_OUTPUT_WP3_ID,
    GENERIC_OUTPUT_WP4_ID,
    GENERIC_OUTPUT_WP5_ID,
    GENERIC_OUTPUT_WP6_ID,

    GENERIC_OUTPUT_DPI2_ID,
    GENERIC_OUTPUT_DPE2_ID,
    GENERIC_OUTPUT_V002_ID,

    GENERIC_OUTPUT_RF2_ID,

    GENERIC_OUTPUT_PEQ1_ID,
    GENERIC_OUTPUT_PEQ2_ID,

    GENERIC_OUTPUT_WATCHDOG_ID,

    GENERIC_OUTPUT_NB_ID
};

//Masques d'entrées génériques communes à toutes les stations
typedef struct eGenericInputMasks
{
	//PCI Input Module Masks
	unsigned int InputZT1S1Mask;
	unsigned int InputZT1S2Mask;
	unsigned int InputZT1PIMask;
	unsigned int InputZT1PEMask;
	unsigned int InputZT1FNMask;
	unsigned int InputZT2S1Mask;
	unsigned int InputZT2PIMask;
	unsigned int InputZT2PEMask;

	//External (ethernet) input module masks
	unsigned int InputZT1ITIMask;
	unsigned int InputZT2ITIMask;
	unsigned int InputZT1ANMask;
	unsigned int InputZT2ANMask;
	unsigned int InputZT1ARFMask;
	unsigned int InputZT2ARFMask;
	unsigned int InputStationIDMask;
    unsigned int InputZT1_StdITIMask;
    unsigned int InputZT1_AltITIMask;

	//Logic input masks
	unsigned int InputCDVZT1ApproachMask;
	unsigned int InputCDVZT1Mask;
	unsigned int InputCDVZT2ApproachMask;
	unsigned int InputCDVZT2Mask;

}GenericInputMasks_t;

enum eGenericInputIDs
{
    GENERIC_INPUT_ZT1_S1_ID,
    GENERIC_INPUT_ZT1_S2_ID,
    GENERIC_INPUT_ZT1_PI_ID,
    GENERIC_INPUT_ZT1_PE_ID,
    GENERIC_INPUT_ZT1_FN_ID,
    GENERIC_INPUT_ZT2_S1_ID,
    GENERIC_INPUT_ZT2_PI_ID,
    GENERIC_INPUT_ZT2_PE_ID,
    GENERIC_INPUT_ZT1_ITI_ID,
    GENERIC_INPUT_ZT2_ITI_ID,
    GENERIC_INPUT_ZT1_AN_ID,
    GENERIC_INPUT_ZT2_AN_ID,
    GENERIC_INPUT_ZT1_ARF_ID,
    GENERIC_INPUT_ZT2_ARF_ID,
    GENERIC_INPUT_STATION_ID_0_ID,
    GENERIC_INPUT_STATION_ID_1_ID,
    GENERIC_INPUT_STATION_ID_2_ID,
    GENERIC_INPUT_STATION_ID_3_ID,
    GENERIC_INPUT_NB_ID
};

#define STATION_KEY_ID_0_MASK 0x08000
#define STATION_KEY_ID_1_MASK 0x10000
#define STATION_KEY_ID_2_MASK 0x20000
#define STATION_KEY_ID_3_MASK 0x40000

typedef struct eGenericAnalogAcquisitionChannels
{
	unsigned int SDFAcquisitionChannel;

}GenericAnalogAcquisitionChannels_t;

class CStation
{
public:
	virtual ~CStation();

    GenericInputMasks_t mStationInputMasks;                 //Instance des masques d'entrées.  Initialisé dynamiquement au démarrage.
    GenericOutputMasks_t mStationOutputMasks;               //Instance des masques de sorties.  Initialisé dynamiquement au démarrage.
    GenericAnalogAcquisitionChannels_t mAnalogAcqChannels;  //Canaux d'acquisition analogiques.  Initialisé dynamiquement au démarrage.

    CStation();

	unsigned int CheckStationKey(unsigned int ExternalInputs);
	unsigned int GetStationKeyValue(void){return mStationPhysicalKey;}
	unsigned int GetStationKey();
    QString GetStationTextualName(void){return mTextualStationName;}
	QString GetStationShortName(void){return mTextualShortName;}
	unsigned int BuildCDVList();

	QList<CCDV*> *GetCDVList(){return &mCDVList;}
	virtual unsigned int UpdateCDVs(unsigned int ExtInputData);
	virtual unsigned int UpdateStationMasks(unsigned int ExtInputData);
	virtual GenericInputMasks_t *GetInputMasks(void);
	virtual GenericAnalogAcquisitionChannels_t *GetAnalogAcqChannels(void);
    virtual bool IsCIZT1ITIActive(unsigned int ExtInputData);
    virtual bool IsCIZT2ITIActive(unsigned int ExtInputDAta);

	GenericOutputMasks_t *GetOutputMasks(void){return &mStationOutputMasks;}
	GenericAnalogAcquisitionChannels_t *GetAnalogChannels(){return &mAnalogAcqChannels;}
    virtual bool IsZT1ApproachCDVOccupied();
    virtual bool IsZT1AnalysisFinished();
    virtual bool IsZT1CDVOccupied();
    virtual int GetCurrentITI();
    bool IsZT1SubsequentCDVOccupied();
    bool IsZT2CDVOccupied();
    bool StationHasZT2();
    virtual bool IsZT1AlarmAutoAcquireCDVOccupied();
	bool IsZT2AlarmAutoAcquireCDVOccupied();
    bool IsZT2ApproachCDVOccupied();

    bool IsZT1ApproachPresent();

	CCDV *GetZT1ApproachCDV(){return mZT1ApproachCDV;}
	CCDV *GetZT1CDV(){return mZT1CDV;}
	CCDV *GetZT1AlarmAutoAcquireCDV(){return mZT1AlarmAutoAcquireCDV;}
	CCDV *GetZT2ApproachCDV(){return mZT2ApproachCDV;}
	CCDV *GetZT2CDV(){return mZT2CDV;}
	CCDV *GetZT2AlarmAutoAcquireCDV(){return mZT2AlarmAutoAcquireCDV;}



protected:
	CIOManager *mExtIOMgrPtr;
    unsigned int mNbExtInputModules430;     //Nombre de modules SEAIO430 installés dans le TO à cette station
    unsigned int mNbExtOutputModules440;    //Nombre de modules SEAIO440 installés dans le TO à cette station
    unsigned int mNbExtMixedModules470;     //Nombre de modules SEAIO470 installés dans le TO à cette station
    unsigned int mStationPhysicalKey;       //Clef physique de la station, chargée dynamiquement au démarrage.
    QString mTextualStationName,mTextualShortName;  //Noms textuels de la station
    QList<CCDV*> mCDVList;      //Liste des CDVs qui sont présents dans cette station
    bool mStationHasZT2;    //Flag indiquant si la station possède une ZT2

    CCDV *mZT1ApproachCDV,          //Pointeur vers le CDV d'approche ZT1 (celui qui précède le CDV ZT1).
         *mZT1SubsequentCDV,        //Pointeur vers le CDV qui suit le CDV ZT1
         *mZT1CDV,                  //Pointeur vers le CDV ZT1 (celui sur lequel les équipements sont installés)
         *mZT1AlarmAutoAcquireCDV;  //Pointeurs vers le CDV dont la libération déclenche l'acquisition automatique des alarmes ZT1 au PCC

    CCDV *mZT2ApproachCDV,          //Pointeur vers le CDV d'approche ZT2 (celui qui précède le CDV ZT2).
         *mZT2CDV,                  //Pointeur vers le CDV ZT2 (celui sur lequel les équipements sont installés)
         *mZT2AlarmAutoAcquireCDV;  //Pointeurs vers le CDV dont la libération déclenche l'acquisition automatique des alarmes ZT2 au PCC



private:
	virtual unsigned int BuildStationCDVList() = 0;
};

#endif // CSTATION_H
