#include "claserdriver_pi.h"
#include "claser.h"
#include "callsystem.h"
#include "cmserialport.h"
#include "cmotor.h"
#include "cmotordriver.h"
#include "logic_local_def.h"
#include <QTime>
Q_DECLARE_METATYPE(char*)

CLaserDriver_PI::CLaserDriver_PI(const QString &name, int32_t id)
    :CLaserDriver_Base(name, id)
{
	m_bShutterOn = false;
}

CLaserDriver_PI::~CLaserDriver_PI()
{

}

int32_t CLaserDriver_PI::init_driver()
{
    m_pSerialPort->open();
    CLaser* pLaser = (CLaser*)FindChannel(LASER);
    Q_ASSERT(pLaser);
    BYTE  byFault;
    GetBroadFault(LASER, byFault);
    QTime time;
    time.start();
    int iWarmTime = m_Variants.get_VData(Var_LaserDriver_WarmTime_ID)->toInt();
    while (byFault == 2) {
        if (time.elapsed() > iWarmTime * 1000) {
            MQT_THROW_STR(QObject::trUtf8("Laser Warm Time out"));
        }
        GetBroadFault(LASER, byFault);
    }
    CPreciseTime timeCost, timeCostK;
    timeCost.StartTime();
    int32_t iTimeCount = 0;
    GetShutterStatus(LASER);
    bool_t bOn = pLaser->m_Variants.get_VData(Var_Laser_shutter_ID)->toBool();
    float64_t dCurrentThres = pLaser->m_Variants.get_VData(Var_Laser_Current_Thres_ID)->toDouble();
    int32_t iCurrenttime = m_Variants.get_VData(Var_LaserDriver_CurrentLoadTime_ID)->toDouble();
    //先开shutter
    //再开ldd
    if (!bOn) {
        SetLDD(LASER, FALSE);
        do {
            GetCurrent_Cur(LASER);
            double dCurrent = pLaser->m_Variants.get_VData(Var_Laser_Current_Cur_ID)->toDouble();
            if (dCurrent < dCurrentThres) {
                break;
            }
            iTimeCount = timeCost.GetTime() * 1000;
        } while (iTimeCount < iCurrenttime || iCurrenttime == 0);
        if (iTimeCount >= iCurrenttime) {
            MQT_THROW_STR(QObject::trUtf8("Set Current TimeOut"));
        }
        iTimeCount = 0;
        SetShutter(LASER, TRUE);

    }
    GetCurrent_Ref(LASER);
    double dCurrentRef = pLaser->m_Variants.get_VData(Var_Laser_Current_Ref_ID)->toDouble();
    SetCurrent_Ref(LASER, dCurrentRef);
    SetLDD(LASER, TRUE);
    timeCostK.StartTime();
    do {
        GetCurrent_Cur(LASER);
        double dCurrent = pLaser->m_Variants.get_VData(Var_Laser_Current_Cur_ID)->toDouble();
        _Sys_Instance_.m_SysMsg.SetMsg(QObject::trUtf8("Laser current on:%1(A)/%2(A)...")
                                  .arg(dCurrent, 0, 'f', 3)
                                  .arg(dCurrentRef, 0, 'f', 3));
        if (fabs(dCurrentRef - dCurrent) < dCurrentThres || dCurrent > dCurrentRef) {
            break;
        }
        iTimeCount = timeCostK.GetTime() * 1000;

    } while (iTimeCount < iCurrenttime || iCurrenttime == 0);
    if (iTimeCount > iCurrenttime) {
        MQT_THROW_STR(QObject::trUtf8("Set Current TimeOut"));
    }

    double dFreq = pLaser->m_Variants.get_VData(Var_Laser_Freq_ID)->toDouble();
    double dPower = pLaser->m_Variants.get_VData(Var_Laser_Power_ID)->toDouble();
    bool bGeteSource = pLaser->m_Variants.get_VData(Var_Laser_IntGate_ID)->toBool();
    bool bPrfSource = pLaser->m_Variants.get_VData(Var_Laser_ExtPRF_ID)->toBool();

    CLaserDriver_Base* pLaserDriver = (GET_CARD(LASER_DRIVER, CLaserDriver_Base));
    if (pLaserDriver) {
        bool bRecSource = pLaserDriver->m_Variants.get_VData(Var_Laser_ExtREC_ID)->toBool();
        //SetRECSource(LASER,bRecSource);
    }
    //设置激光器就打开了
    //设置内触发模式
    //SetGateSource(LASER,!bGeteSource);
    //SetPowerRate(LASER,dPower);
    //SetFreq(LASER,dFreq);
    //SetPRFSource(LASER,bPrfSource);

    //GetPowerRate(LASER);
    //GetFreq(LASER);
    //GetSerial(LASER);

    dword_t dwFPKTime =
        pLaser->m_Variants.get_VData(Var_Laser_FPKTime_ID)->toInt();
    //    SetFPKTime(LASER,dwFPKTime,true);
        //GetFPKTime(LASER);
    return CDriverCard::init_driver();
}

int32_t CLaserDriver_PI::exit_driver()
{

    if (m_bCloseLaser) {
        CLaser* pLaser = (CLaser*)FindChannel(LASER);
        Q_ASSERT(pLaser);
        SetLDD(LASER, FALSE);

        CPreciseTime timeCost;
        timeCost.StartTime();
        int32_t iTimeCount = 0;
        float64_t dCurrentThres = pLaser->m_Variants.get_VData(Var_Laser_Current_Thres_ID)->toDouble();
        int32_t iCurrenttime = m_Variants.get_VData(Var_LaserDriver_CurrentLoadTime_ID)->toInt();
        do {
            GetCurrent_Cur(LASER);
            double dCurrent = pLaser->m_Variants.get_VData(Var_Laser_Current_Cur_ID)->toDouble();
            _Sys_Instance_.m_SysMsg.SetMsg(QObject::trUtf8("Laser current off:%1(A)/%2(A)...")
                                      .arg(dCurrent, 0, 'f', 3)
                                      .arg(dCurrentThres, 0, 'f', 3));
            if (dCurrent < dCurrentThres) {
                break;
            }
            iTimeCount = timeCost.GetTime() * 1000;
        } while (iTimeCount < iCurrenttime || iCurrenttime == 0);
        if (iTimeCount >= iCurrenttime) {
            MQT_THROW_STR(QObject::trUtf8("Set Current TimeOut"));
        }
        SetShutter(LASER, FALSE);
    }
    m_pSerialPort->close();
    return RTN_SUCCESS1;
}


void CLaserDriver_PI::SendCommand(const char *pCommand, char* pResponse)
{
    QMutexLocker locker(&m_CardMutex);
    int isize = strlen(pCommand);
    LogRecord(std::string("send:") + pCommand);
    m_pSerialPort->send(pCommand, isize);
    int32_t irtn = m_pSerialPort->wait();
    m_pSerialPort->receive(pResponse, irtn);
    LogRecord(std::string("receive:") +pResponse);

}

//!
//! \brief CLaserDriver_PI::MakeSendCheckComm
//! \param byCommand
//! 发送的指令
//! \param pSendData
//! 发送的数据
//! \param iDataSSize
//! 发送的数据的大小
//! \param iDataRSize
//! 接收的数据大小
//! \param bWrite
//! 是否写入数据
//! \param pResponse
//! 存储返回数据的指针
//! \param byAddress
//!
void CLaserDriver_PI::MakeSendCheckComm(byte byCommand, byte *pSendData,
                                        int32_t iDataSSize, int32_t iDataRSize, bool_t bWrite, byte *pResponse,
                                        byte byAddress)
{
    char chComm[COMM_LEN];
    int32_t  iSizeCommand = 0;
    byte chSCommhex[COMM_LEN] = { 0 };
    WORD sum = 0;
    if (!bWrite) {
        iSizeCommand = 6;
        chSCommhex[0] = 0x01;
        chSCommhex[1] = 0x00;
        chSCommhex[2] = byAddress;//0x00;
        chSCommhex[3] = byCommand;
        sum = byCommand + byAddress + 1;
        chSCommhex[4] = byte(sum >> 8);
        chSCommhex[5] = byte(sum);
        //        int i;
        //        for (i=0;i<6;i++)
        //        {
        //            qDebug()<<chSCommhex[i];
        //        }
    } else {
        iSizeCommand = 6 + iDataSSize;
        chSCommhex[0] = 0x00;
        chSCommhex[1] = (byte)iDataSSize;
        chSCommhex[2] = byAddress;//0x00;
        chSCommhex[3] = byCommand;
        memcpy(chSCommhex + 4, pSendData, iDataSSize);
        for (int i = 0; i < iDataSSize + 4; i++) {
            sum += chSCommhex[i];
        }
        chSCommhex[4 + iDataSSize] = byte(sum >> 8);
        chSCommhex[5 + iDataSSize] = byte(sum);
        //        for ( int i=0;i<6+iDataSSize;i++)
        //        {
        //            qDebug()<<chSCommhex[i];
        //        }
    }

    memset(chComm, 0, COMM_LEN);

    HexToAsic((char*)chSCommhex, iSizeCommand, chComm);
    chComm[iSizeCommand * 2] = 0x0D;
    chComm[iSizeCommand * 2 + 1] = 0;
    MqDebug() << chComm;

    SendCommand(chComm, (char*)pResponse);
    CheckResponse(iDataRSize, bWrite, pResponse);
}

void CLaserDriver_PI::CheckResponse(int32_t iDataRSize, bool_t bWrite, byte *pResponse)
{

    byte byRComm[COMM_LEN] = { 0 };
    if (bWrite) {
        iDataRSize = 1;
    }

    if (strlen((char*)pResponse) != (iDataRSize + 6) * 2 + 1) {
        MQT_THROW_STR(QObject::trUtf8("Laser ComPort Response Count:%1 Incorrect")
                      .arg((strlen((char*)pResponse) - 1) / 2 - 6));
    }
    AsicToHex((char*)pResponse, (iDataRSize + 6) * 2, (char*)byRComm);
    MqDebug() << (char*)pResponse;
    //    for (int  i=0;i<6+iDataRSize;i++)
    //    {
    //        qDebug()<<byRComm[i];
    //    }

    if (byRComm[0] == 0x06) {
        MQT_THROW_STR(QObject::trUtf8("Laser;ComPort Command has illage Word"));

    }
    if ((byRComm[0] != 0x03 && !bWrite) ||
        (byRComm[0] != 0x02 && bWrite)) {
        MQT_THROW_STR(QObject::trUtf8("Laser;ComPort Response First Byte Incorrect"));
    }
    WORD sum = 0;
    int i;
    for (i = 0; i < iDataRSize + 4; i++) {
        sum += byRComm[i];
    }
    if (byRComm[4 + iDataRSize] != BYTE(sum >> 8) ||
        byRComm[5 + iDataRSize] != BYTE(sum)) {
        MQT_THROW_STR(QObject::trUtf8("Laser;ComPort Response Check Sum Incorrect"));
    }
    memcpy(pResponse, (char*)byRComm + 4, iDataRSize);
    pResponse[iDataRSize] = 0;
}

void CLaserDriver_PI::HexToAsic(char* pHex, int iSizeHex, char* pAsic)
{
    for (int i = 0; i < iSizeHex; i++) {
        byte byHI, byLOW;
        byHI = (pHex[i] >> 4) & 0x0F;
        byLOW = pHex[i] & 0x0F;
        HexToAsic(byHI, pAsic[i * 2]);
        HexToAsic(byLOW, pAsic[i * 2 + 1]);
    }
}

void CLaserDriver_PI::HexToAsic(char Hex, char& Asic)
{
    if (Hex >= 0 && Hex <= 9) {
        Asic = Hex + 0x30;
    } else if (Hex >= 0x0A && Hex <= 0x0F) {
        Asic = Hex - 10 + 0x41;
    }
}

void CLaserDriver_PI::AsicToHex(char* pAsic, int iSizeASC, char *pHex)
{
    for (int i = 0; i < iSizeASC; i += 2) {
        byte byHI, byLOW;
        AsicToHex(pAsic[i], byHI);
        AsicToHex(pAsic[i + 1], byLOW);
        pHex[i / 2] = byHI << 4 | byLOW;
    }
}

void CLaserDriver_PI::AsicToHex(char Asic, byte &Hex)
{
    if (Asic >= '0'&&Asic <= '9') {
        Hex = Asic - '0' + 0;
    } else if (Asic >= 'A'&&Asic <= 'F') {
        Hex = Asic - 'A' + 10;
    } else if (Asic >= 'a'&&Asic <= 'f') {
        Hex = Asic - 'a' + 10;
    }
}

int CLaserDriver_PI::GetBroadFault(int32_t laserid, BYTE &byFault)
{
    UNUSED(laserid);
    byte ch_response[RESPONSELENGTH] = { 0 };
    MakeSendCheckComm(0x0D, NULL, 0, 2, FALSE, ch_response);
    byFault = ch_response[1];
    return RTN_SUCCESS1;
}

int CLaserDriver_PI::SetFreq(int32_t laserid, float64_t dFreq)
{
    //HACK:测试直接返回
    CLaser* pLaser = (CLaser*)FindChannel(laserid);
    Q_ASSERT(pLaser);
    DWORD dwFreq = int(dFreq * 1000);
    BYTE sBuff[3] = { (BYTE)(dwFreq >> 16),BYTE(dwFreq >> 8),(BYTE)dwFreq };
    byte ch_response[RESPONSELENGTH] = { 0 };
    MakeSendCheckComm(0x21, sBuff, 3, 3, TRUE, ch_response);
    pLaser->m_Variants.set_VData(Var_Laser_Freq_ID, dFreq);
    return RTN_SUCCESS1;
}

int CLaserDriver_PI::GetFreq(int32_t laserid)
{
    CLaser* pLaser = (CLaser*)FindChannel(laserid);
    Q_ASSERT(pLaser);
    byte ch_response[RESPONSELENGTH] = { 0 };
    MakeSendCheckComm(0x21, NULL, 0, 3, FALSE, ch_response);
    DWORD dwFreq = DWORD(ch_response[0]) << 16 |
        DWORD(ch_response[1]) << 8 |
        ch_response[2];
    float64_t dFreq = dwFreq / 1000.0;
    pLaser->m_Variants.set_VData(Var_Laser_Freq_ID, dFreq);
    return RTN_SUCCESS1;
}

int CLaserDriver_PI::OpenLaserGate(int32_t laserid, bool bOpen)
{
	return CLaserDriver_Base::OpenLaserGate(laserid, bOpen);
}

int CLaserDriver_PI::SetPowerRate(int32_t laserid, float64_t dPower)
{
    //HACK:测试设置为15%
    CLaser* pLaser = (CLaser*)FindChannel(laserid);
    Q_ASSERT(pLaser);
    DWORD dwPowerRate = dPower * 10;
    BYTE sBuff[2] = { BYTE(dwPowerRate >> 8),(BYTE)dwPowerRate };
    byte ch_response[RESPONSELENGTH] = { 0 };
    MakeSendCheckComm(0x55, sBuff, 2, 2, TRUE, ch_response);
    pLaser->m_Variants.set_VData(Var_Laser_Power_ID, dPower);
    return RTN_SUCCESS1;
}

int CLaserDriver_PI::GetPowerRate(int32_t laserid)
{
    CLaser* pLaser = (CLaser*)FindChannel(laserid);
    Q_ASSERT(pLaser);
    byte ch_response[RESPONSELENGTH] = { 0 };
    MakeSendCheckComm(0x55, NULL, 0, 2, FALSE, ch_response);
    DWORD dwPowerRate = DWORD(ch_response[0]) << 8 | ch_response[1];
    float64_t dPower = dwPowerRate / 10.0;
    pLaser->m_Variants.set_VData(Var_Laser_Power_ID, dPower);
    return RTN_SUCCESS1;
}

//!
//! \brief CLaserDriver_PI::SetGateSource
//! 设置激光器的触发模式
//! \param laserid
//! \param bInt
//! true是内触发 false 外触发
//! \return
//!
int CLaserDriver_PI::SetGateSource(int32_t laserid, bool_t bInt)
{
    CLaser* pLaser = (CLaser*)FindChannel(laserid);
    Q_ASSERT(pLaser);
    BYTE sBuff = bInt ? 0x00 : 0x01;
    byte ch_response[RESPONSELENGTH] = { 0 };
    MakeSendCheckComm(0x24, &sBuff, 1, 1, TRUE, ch_response);
    pLaser->m_Variants.set_VData(Var_Laser_IntGate_ID, bInt ? true : false);
	m_bExternalGate = bInt;

    return RTN_SUCCESS1;
}

int CLaserDriver_PI::SetRECSource(int32_t laserid, bool_t bInt)
{
    BYTE sBuff = bInt ? 0x01 : 0x00;
    byte ch_response[RESPONSELENGTH] = { 0 };
    MakeSendCheckComm(0x25, &sBuff, 1, 1, TRUE, ch_response);
    m_Variants.get_VData(Var_Laser_ExtREC_ID)->setValue(bInt ? true : false);
    return RTN_SUCCESS1;
}

int CLaserDriver_PI::SetPRFSource(int32_t laserid, bool_t bExt)
{
    CLaser* pLaser = (CLaser*)FindChannel(laserid);
    Q_ASSERT(pLaser);
    BYTE sBuff = bExt ? 0x01 : 0x00;
    byte ch_response[RESPONSELENGTH] = { 0 };
    MakeSendCheckComm(0x23, &sBuff, 1, 1, TRUE, ch_response);
    pLaser->m_Variants.set_VData(Var_Laser_ExtPRF_ID, bExt ? true : false);
    return RTN_SUCCESS1;
}

int CLaserDriver_PI::SetFPKTime(int32_t laserid, dword_t dwTime, bool bEnable)
{
    CLaser* pLaser = (CLaser*)FindChannel(laserid);
    Q_ASSERT(pLaser);
    BYTE sBuff = bEnable ? 0x01 : 0x00;
    byte ch_response[RESPONSELENGTH] = { 0 };
    MakeSendCheckComm(0x27, &sBuff, 1, 1, TRUE, ch_response);
    dwTime /= 10;
    BYTE sBuff1[2] = { (BYTE)(dwTime >> 8),(BYTE)dwTime };
    memset(ch_response, 0, RESPONSELENGTH);
    MakeSendCheckComm(0x28, sBuff1, 2, 2, TRUE, ch_response);
    pLaser->m_Variants.set_VData(Var_Laser_EnableFPK_ID, bEnable);
    pLaser->m_Variants.set_VData(Var_Laser_FPKTime_ID, int(dwTime));
    return RTN_SUCCESS1;
}

int CLaserDriver_PI::GetFPKTime(int32_t laserid)
{
    CLaser* pLaser = (CLaser*)FindChannel(laserid);
    Q_ASSERT(pLaser);
    byte ch_response[RESPONSELENGTH] = { 0 };
    MakeSendCheckComm(0x28, NULL, 0, 2, FALSE, ch_response);
    DWORD dwTime = (DWORD(ch_response[0]) << 8 | ch_response[1]);
    pLaser->m_Variants.set_VData(Var_Laser_FPKTime_ID, int(dwTime));
    return RTN_SUCCESS1;
}

int CLaserDriver_PI::SetLDD(int32_t laserid, bool_t bOn)
{
    UNUSED(laserid);

    BYTE sBuff = bOn ? 0x01 : 0x00;
    byte ch_response[RESPONSELENGTH] = { 0 };
    MakeSendCheckComm(0x10, &sBuff, 1, 1, TRUE, ch_response);
    return RTN_SUCCESS1;
}

int CLaserDriver_PI::SetShutter(int32_t laserid, bool_t bOn)
{
    UNUSED(laserid);

	m_bShutterOn = bOn;

    BYTE sBuff = bOn ? 0x01 : 0x00;
    byte ch_response[RESPONSELENGTH] = { 0 };
    MakeSendCheckComm(0x04, &sBuff, 1, 1, TRUE, ch_response);
    return RTN_SUCCESS1;
}

int CLaserDriver_PI::SetCurrent_Ref(int32_t laserid, double dCurrent)
{
    UNUSED(laserid);
    UNUSED(dCurrent);
    //    CLaser* pLaser=(CLaser*)FindChannel(laserid);
    //    Q_ASSERT(pLaser);
    //    DWORD dwCurrent=dCurrent*100;
    //    BYTE sBuff[2]={ BYTE(dwCurrent>>8),(BYTE)dwCurrent};
    //    MakeSendCheckComm(0x11,sBuff,2, 2,TRUE);
    //    pLaser->mparams[CLaser::CURRENT_REF]->setDataDirect(dCurrent);
    UNUSED(laserid);
    DWORD dwCurrent = dCurrent * 100;
    byte ch_response[RESPONSELENGTH] = { 0 };
    BYTE sBuff[2] = { BYTE(dwCurrent >> 8),(BYTE)dwCurrent };
    MakeSendCheckComm(0x11, sBuff, 2, 2, TRUE, ch_response);
    return RTN_SUCCESS1;
}

int CLaserDriver_PI::SetCurrent_Max(int32_t laserid, double dCurrent)
{
    UNUSED(laserid);
    UNUSED(dCurrent);
    return RTN_SUCCESS1;

}

int CLaserDriver_PI::GetCurrent_Cur(int32_t laserid)
{
    CLaser* pLaser = (CLaser*)FindChannel(laserid);
    Q_ASSERT(pLaser);
    byte ch_response[RESPONSELENGTH] = { 0 };
    MakeSendCheckComm(0x12, NULL, 0, 2, FALSE, ch_response);
    float64_t dCurrent = (WORD(ch_response[0]) << 8 | ch_response[1]) / 100.0;
    pLaser->m_Variants.set_VData(Var_Laser_Current_Cur_ID, dCurrent);
    return 0;
}

int CLaserDriver_PI::GetCurrent_Ref(int32_t laserid)
{

    CLaser* pLaser = (CLaser*)FindChannel(laserid);
    Q_ASSERT(pLaser);
    byte ch_response[RESPONSELENGTH] = { 0 };
    MakeSendCheckComm(0x11, NULL, 0, 2, FALSE, ch_response);
    float64_t dCurrent_Ref = (WORD(ch_response[0]) << 8 | ch_response[1]) / 100.0;
    pLaser->m_Variants.set_VData(Var_Laser_Current_Ref_ID, dCurrent_Ref);
    return 0;
}

int CLaserDriver_PI::GetCurrent_Max(int32_t laserid)
{

    UNUSED(laserid);
    return RTN_SUCCESS1;
}

int CLaserDriver_PI::GetShutterStatus(int32_t laserid)
{

    CLaser* pLaser = (CLaser*)FindChannel(laserid);
    Q_ASSERT(pLaser);
    byte ch_response[RESPONSELENGTH] = { 0 };
    MakeSendCheckComm(0x0F, NULL, 0, 5, FALSE, ch_response);
    bool bOn = ch_response[0] & 0x02;
    pLaser->m_Variants.set_VData(Var_Laser_shutter_ID, bOn);
    return RTN_SUCCESS1;
}

int CLaserDriver_PI::GetUVPower(int32_t laserid)
{
    CLaser* pLaser = (CLaser*)FindChannel(laserid);
    Q_ASSERT(pLaser);
    byte ch_response[RESPONSELENGTH] = { 0 };
    MakeSendCheckComm(0x71, NULL, 0, 4, FALSE, ch_response);
    int iPower = (int(ch_response[0]) << 24) |
        (int(ch_response[1]) << 16) |
        (int(ch_response[2]) << 8) |
        ch_response[3];
    double dUVPower = iPower / 100.0;

    pLaser->m_Variants.set_VData(Var_Laser_UVPower_ID, dUVPower);
    return RTN_SUCCESS1;
}

int CLaserDriver_PI::GetLaserTime(int32_t laserid)
{
    CLaser* pLaser = (CLaser*)FindChannel(laserid);
    Q_ASSERT(pLaser);
    byte ch_response[RESPONSELENGTH] = { 0 };
    MakeSendCheckComm(0x12, NULL, 0, 2, FALSE, ch_response);
    double dHours = (WORD(ch_response[0]) << 8 | ch_response[1]) / 10.0;
    pLaser->m_Variants.set_VData(Var_Laser_LaserTime_ID, int(dHours));
    return RTN_SUCCESS1;
}

int CLaserDriver_PI::GetSerial(int32_t laserid)
{
    CLaser* pLaser = (CLaser*)FindChannel(laserid);
    Q_ASSERT(pLaser);
    byte ch_response[RESPONSELENGTH] = { 0 };
    MakeSendCheckComm(0x01, NULL, 0, 6, FALSE, ch_response, 0x02);
    pLaser->m_Variants.set_VData(Var_Base_SerialID_ID, QString((char*)ch_response));
    return RTN_SUCCESS1;
}

void CLaserDriver_PI::do_msg(int iID, QVariantList& vlInput, V_MsgOutput* pvlOutput)
{
    switch (iID) {
        case SETRECSOURCE:
            Q_ASSERT(vlInput.size() >= 2);
            SetRECSource(vlInput[0].toInt(), vlInput[1].toBool());
            break;
		case GETSTATE:
			m_bShutterOn = GetShutterStatus(vlInput[0].toInt());
			//m_bEmissionOn = GetShutterStatus(vlInput[0].toInt());
			m_bExternalGate = GetShutterStatus(vlInput[0].toInt());
			break;
        default:
            CLaserDriver_Base::do_msg(iID, vlInput, pvlOutput);
            break;
    }
}
