// MotionController_ACS.h: interface for the CMotionController_ACS class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_MOTIONCONTROLLER_ACS_H__3E235D4B_C75D_4F13_A9B5_61EFB6BB5378__INCLUDED_)
#define AFX_MOTIONCONTROLLER_ACS_H__3E235D4B_C75D_4F13_A9B5_61EFB6BB5378__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#pragma warning(disable: 4481) // nonstandard extension used: override specifier 'override'

class CMotionController_ACS;

struct _ACS_CallBackStruct
{
    _ACS_CallBackStruct(int _interrupt, CMotionController_ACS* _pController, const char *str)
        : interrupt(_interrupt), pController(_pController), name(str)
    {
    }

    int interrupt;
    std::string name;
    CMotionController_ACS *pController;
};
typedef struct _ACS_CallBackStruct ACS_CallBackStruct;

class CMotionController_ACS : public CMotionControllerBase
{
public:
    CMotionController_ACS(int index);
    virtual ~CMotionController_ACS();

    BOOL Init(int &nNoOfMtr) override;
    void Close() override;

//  get Motion status of motor
    int GetMotionStatus(const CMtrProfile &mtrProfile) override;

// check motor in position signal
    BOOL IsInPosition(const CMtrProfile &mtrProfile) override;

    void   ProcessInt(unsigned __int64 Param, int interrupt, const std::string &name);
    HANDLE GetCommHandle();
private:
    const char *GetErrorString();
    bool        TestAcsResult(int line_nr, int result, char *code);
    void        _InstallCallBack(void *f, int interrupt, const char *name);
    void        UninstallCallbacks();

    std::vector<std::shared_ptr<ACS_CallBackStruct> > m_installedCallbacks;
    int                                               m_lastError;
    char                                              m_errorString[256];
    CMotionLogger                                     m_logger;
    HANDLE                                            m_hComm;

    bool TerminateStrayConnections();
};

#endif // !defined(AFX_MOTIONCONTROLLER_ACS_H__3E235D4B_C75D_4F13_A9B5_61EFB6BB5378__INCLUDED_)
