// MotionController_ADVANTECH_ETHERCAT.h: interface for the CMotionController_ADVANTECH_ETHERCAT class.
//
//////////////////////////////////////////////////////////////////////
#pragma once

#include <vector>

#include "MotionControllerBase.h"

class CMotionController_ADVANTECH_ETHERCAT;
using stThreadParam = struct _stThreadParam
{
    int nId;
    CMotionController_ADVANTECH_ETHERCAT* pController;
    // ctor
    _stThreadParam(int _id, CMotionController_ADVANTECH_ETHERCAT* _pController)
    {
        nId         = _id;
        pController = _pController;
    }
};

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

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

    int GetCardId(int nIndex)
    {
        return m_cardInfo[nIndex].nId;
    }

    void SetAdvantechMotionInt(int nCardNo, int nAxisNo);
    bool m_bKillThread;

private:
    using stCardInfo = struct _stCardInfo
    {
        unsigned short nId;
        unsigned short nNumOfAxes;
        unsigned short nNumOfMotionSlaves;
        unsigned short nNumOfIoSlaves;

        _stCardInfo(unsigned short _Id, unsigned short _numOfAxes, unsigned short _numOfMotionSlaves, unsigned short _numOfIoSlaves)
        {
            nId                = _Id;
            nNumOfAxes         = _numOfAxes;
            nNumOfMotionSlaves = _numOfMotionSlaves;
            nNumOfIoSlaves     = _numOfIoSlaves;
        }
    };
    // methods

    // attributes
    std::vector<stCardInfo> m_cardInfo;
    std::map<std::string, ULONG> m_mapModelDeviceType;

    std::vector<stThreadParam> m_vecThdParam;
    CWinThread* m_pAdvantechIntThread[2];
};
