// EMS.h: interface for the CEMS class.
//
//////////////////////////////////////////////////////////////////////
#pragma once

#include "RunTask.h"
#include "Input.h"
#include "Output.h"
#include "commondef.h"

class CEMS : public CRunTask
{
public:
    CEMS();
    virtual ~CEMS();

    bool CanMachineRun();
    bool IsEMSEnable() const;
    void UpdateMachineStart();
    void UpdateMachineStop();
    void UpdateUnitCount();
    void InitParameters();

    UINT RunThread() override;

    void SetEMSOutput(int nNo, COutput* copOutput);
    void SetEMSInput(int nNo, CInput* cipInput);
    void SetGuiWindow(HWND hwnd);

private:
    void CheckHostAllowMachineToRun();
    void CheckMachineStatus();
    void CheckUnitCountUpdate();
    void GetMainApp();

    CEvt m_evtSendUnitPulse;
    CEvt m_evtMachineStop;
    CEvt m_evtMachineStart;

    HWND m_hwndMainApp{ nullptr };

    CInput*  m_cipEMSStatus{ nullptr };
    COutput* m_copEMSCount{ nullptr };

    bool m_bEMSEnable{ false };
    bool m_bMsgSendOn{ false };
    bool m_bMsgSendOff{ false };

    int m_iEmsPulse{ 0 };
};
