#include "vst_idle_transfer.h"
#include "vst_work_transfer.h"
#include "logic.h"
VST_Idle_Transfer::VST_Idle_Transfer(int iID, const QString &sName,
                                     VSM_Thread *pParent)
    :VST_Idle_Base(  iID,  sName, pParent)
{

}

void VST_Idle_Transfer::do_Msg(const V_Msg &msg)
{
    switch(msg.m_iID)
    {
    case VarMsg_All_Home:
    {
        if(!m_pNextState)
        {
            m_pNextState= new VST_Work_Base(VarState_Home_Count,
                                            QObject::trUtf8("All Home State"),
                                            m_pParent,this,0);
            ((VST_Work_Base*)m_pNextState)->m_iCount=300;
            ((VST_Work_Base*)m_pNextState)->m_VarMsgProcess.
                    pushback_Msg(VarMsg_All_Home_step,
                                 QObject::trUtf8("All Home Step Sig"));
            ((VST_Work_Base*)m_pNextState)->LoadMsgProcess();
        }
        m_pParent->SetState(m_pNextState);

		g_SecsManager.SendEvent(EVENT_InitStarted);
        break;
    }
	case VarMsg_StartAuto_ID:
	{
		m_gSystem.SetIndicatorLight(Qt::red,false);
		m_gSystem.SetIndicatorLight(Qt::yellow,false);
		m_gSystem.SetIndicatorLight(Qt::green,true);
		//如果是auto就恢复启动
		if(m_pParent->m_pHistoryState_Auto)
		{
			m_gSystem.EvtLog(QString("START"),QString(QObject::trUtf8("Resume Auto Work")+QString(",TRANS")));
			g_SecsManager.SendEvent(EVENT_JobResume);
		}
		else
		{
			m_gSystem.EvtLog(QString("FAS"),QObject::trUtf8("Full Auto Start"));
			g_SecsManager.SendEvent(EVENT_JobStarted);
		}
		break;
	}
	case VarMsg_Driver_ID:
		{
			V_Msg msg1=msg;
			Q_ASSERT(msg1.m_vlInput.size()>=2);
			int iDriverID=msg1.m_vlInput.at(0).toInt();
			int iDriverMsgID=msg1.m_vlInput.at(1).toInt();
			msg1.m_vlInput.pop_front();
			msg1.m_vlInput.pop_front();
			CDriverCard* pDriverCard= GET_CARD(iDriverID,CDriverCard);
			Q_ASSERT(pDriverCard);
			pDriverCard->do_msg(iDriverMsgID,msg1.m_vlInput,msg1.m_pvlOutput);
			break;
		}
    }
    VST_Idle_Base::do_Msg(msg);
}

void VST_Idle_Transfer::Enter()
{
	try
	{
		m_gSystem.SetIndicatorLight(Qt::red,false);
		m_gSystem.SetIndicatorLight(Qt::yellow,true);
		m_gSystem.SetIndicatorLight(Qt::green,false);
	}
	catch(QString& s)
	{
		MqDebug()<<s;
	}
}

