#include "claserdriver_base.h"
#include "callsystem.h"
#include "cmotor.h"
#include "cmotordriver.h"
#include "logic_local_def.h"
#include "logic_io_define.h"
//bool m_gEnbaleLaserOpen = false;
CLaserDriver_Base::CLaserDriver_Base(const QString &name, int32_t id)
    :CLaserDriver(name, id)
{
    m_Variants.add_Variant(Var_Laser_ExtREC_ID,
                           QObject::trUtf8("Laser_ExtPec"), false, false,
                           Variant::TOXML);
    m_bEmissionOn = false;
    m_iEpulseFreq = 0;
    m_bInternalGate = false;
    m_bExternalGate = false;
    m_bError = true;
    m_bPreheat = false;
    m_dDiode = 0;
    m_iPreheatTimeSecs = 0;
    m_dTemperature = 0;	//温度
    m_dInnerPower = 0;	//内部功率
    m_dCurThgUseHours = 0;
#ifdef __SIMULATOR__
    m_bInternalGate = true;
    m_bInited = true;
    m_bError = false;
    m_bPreheat = false;
    m_bEmissionOn = true;
    m_bInternalGate = false;
    m_bExternalGate = true;
#endif // __SIMULATOR__
    QString x;
}

//使用IO GATE开关激光
int CLaserDriver_Base::OpenLaserGate(int32_t laserid, bool bOpen)
{
    CMotorDriver* pDriver = GET_CARD(MOTOR_DRIVER, CMotorDriver);
    Q_ASSERT(pDriver);
    //用GATE直接开激光
    pDriver->setio(IO_OUTPUT, OUT_BLUE, bOpen);
    pDriver->setio(IO_OUTPUT, OUT_LENS_Blow_Inner, bOpen);
    pDriver->setio(IO_OUTPUT, OUT_LENS_Blow_Outter, bOpen);
    pDriver->setio(IO_OUTPUT, OUT_LASERGATE, bOpen ? LASER_ON : LASER_OFF); //HACK:出光为0 不出光为1

    return RTN_SUCCESS1;
}

int CLaserDriver_Base::SetInnerGate(int laserId, bool bOpen)
{
    m_bInternalGate = bOpen;
    return RTN_SUCCESS1;
}

int CLaserDriver_Base::SetLDD(int32_t laserid, bool_t bOn)
{
    m_bEmissionOn = bOn;
    return 0;
}

int CLaserDriver_Base::SetGateSource(int32_t laserid, bool_t bExt)
{
    m_bExternalGate = bExt;
    return true;
}

int CLaserDriver_Base::SetEpulseFreq(int32_t laserid, int frequency)
{
    return RTN_SUCCESS1;
}

int CLaserDriver_Base::GetEpulseFreq(int32_t laserid, int& frequency)
{
    frequency = 0;
    return RTN_SUCCESS1;
}
