#ifndef TKGENERATOR_H
#define TKGENERATOR_H

#include "Station.h"
#include "ZTData.h"
#include <QTimer>
#include <QElapsedTimer>
#include <QObject>
#include "ExtIOThread.h"

#define TK_GENERATOR_SHOW_ZERO_TIMEOUT 1000 //the Low state time between two TKs
#define TK_GENERATOR_AUTOMATIC_SHOW_TK_TIMEOUT 2000 //the amount of time the TK must be emited in auto acquitment mode
#define TK_GENERATOR_MAX_ALARMS 4
#define TK_GENERATOR_MAX_PEQ 1
#define TK_GENERATOR_MAX_V00X 1

//enum eTKGeneratorStaes
//{
//    TK_ZT1_GENERATOR_SHOW_TK_STATE,
//    TK_ZT1_GENERATOR_WAIT_FOR_AN1_STATE,
//    TK_ZT1_GENERATOR_SHOW_ZERO_STATE,

//    TK_ZT1_GENERATOR_AUTO_SHOW_TK_AUTO_STATE,
//    TK_ZT1_GENERATOR_AUTO_WAIT_FOR_TIMEOUT_STATE,
//    TK_ZT1_GENERATOR_AUTO_SHOW_ZERO_STATE,

//	TK_ZT1_GENERATOR_FINISH_STATE,

//    TK_GENERATOR_ZT1_STANDBY_STATE,

//    TK_ZT2_GENERATOR_SHOW_TK_STATE,
//    TK_ZT2_GENERATOR_WAIT_FOR_AN2_STATE,
//    TK_ZT2_GENERATOR_SHOW_ZERO_STATE,

//    TK_ZT2_GENERATOR_AUTO_SHOW_TK_AUTO_STATE,
//    TK_ZT2_GENERATOR_AUTO_WAIT_FOR_TIMEOUT_STATE,
//    TK_ZT2_GENERATOR_AUTO_SHOW_ZERO_STATE,

//	TK_ZT2_GENERATOR_FINISH_STATE,

//    TK_GENERATOR_ZT2_STANDBY_STATE
//};

class CTKTransportInterface;

class CTKGenerator : public QObject
{
    Q_OBJECT
 public:
    CTKGenerator(CTKTransportInterface *IF);
    virtual ~CTKGenerator();


    CTKTransportInterface* mTKInterface;
//    void BindPointers(GenericOutputMasks_t *OutputMasks, COutputModule *OutputModule);
    //virtual void BindTransportInterface(CTKTransportInterface* IF) = 0;
    unsigned int ProcessDetectionsTK(CZTDetectionData *NewDetection);
    bool UpdateDetectionConfig(CZTDetectionFunctionConfig*);
    void ResetAlarmCount(int ZT);

  //  virtual unsigned int CancelAllTK() = 0;
    virtual unsigned int CancelMaintenanceCurrentTK() = 0;
    virtual unsigned int ExitMaintenance() = 0;
    virtual unsigned int EnterMaintenance() = 0;
    virtual unsigned int SetInputStates(bool AN1State, bool ZT1CDVState, bool AN2State, bool ZT2CDVState) = 0;
    virtual unsigned int BeginTKEmission() = 0;
    virtual unsigned int ClearTKForNewTrain() = 0;


    void LogTK(CZTDetectionData DetectionData);
    CZTDetectionFunctionConfig *GetDetectionConfig();


//	bool IsTKProcessing();
//	bool IsZT1TKProcessing();
//	bool IsZT2TKProcessing();

private:

    CZTDetectionFunctionConfig *mZTDetectionConfig;
//    GenericOutputMasks_t *mOutputMasks;

    //COutputModule *mOutputModule;


  //  QList<quint32> mZT1TKBuffer,mZT2TKBuffer;
   // QList<CZTDetectionData> mZT1TKDataList,mZT2TKDataList;
//    unsigned int mZT1TKGeneratorState,mZT2TKGeneratorState;
//    int mZT1CurTKIndex,mZT2CurTKIndex;
//    QTimer *mZT1TKStateMachineTimer;
//    QTimer *mZT2TKStateMachineTimer;
//    QElapsedTimer mZT1RefTimer,mZT2RefTimer;

 //   CTKTransportInterface *mTKInterface;

//    bool mAN1State, mZT1CDVState,mAN2State,mZT2CDVState;
//    bool mMaintenanceMode, mForceZT1Clear, mForceZT2Clear;

    //quint32 mClearZT1AlarmMask, mClearZT2AlarmMask;

//    quint32 IntegerToBCDZT1(quint32 Value);
//    quint32 IntegerToBCDZT2(quint32 Value);
//    quint32 IntegerToBCDFN(quint32 Value);

	int mAlarmCount[DETECTION_MAX_DETECTION_ID];

 //   void LogTK(quint32 Value);



public slots:
//	void ExecZT1SM();
//	void ExecZT2SM();

signals:
    void TKOutputStatesChanged(bool ZT1TKActive,bool ZT2TKActive);



};

#endif // TKGENERATOR_H
