void StateControllerNew::EvaluatePin(IPin *sourcePin, IMediaSample *mediaSample)
{
    if (sourcePin == &maneuverListInput)
    {
        cString maneuverFileString;
        {
            __adtf_sample_read_lock_mediadescription(maneuverListDescription, mediaSample, pCoder);

            std::vector<tSize> vecDynamicIDs;

            // retrieve number of elements by providing NULL as first parameter
            tSize bufferSize = 0;
            if (IS_OK(pCoder->GetDynamicBufferIDs(NULL, bufferSize)))
            {
                // create a buffer depending on the size element
                tChar pcBuffer[bufferSize];
                vecDynamicIDs.resize(bufferSize);

                // get the dynamic ids (we already got the first "static" size element)
                if (IS_OK(pCoder->GetDynamicBufferIDs(&(vecDynamicIDs.front()), bufferSize)))
                {
                    // iterate over all elements
                    for (tUInt32 nIdx = 0; nIdx < vecDynamicIDs.size(); ++nIdx)
                    {
                        // get the value and put it into the buffer
                        pCoder->Get(vecDynamicIDs[nIdx], (tVoid *) &pcBuffer[nIdx]);
                    }

                    maneuverFileString = (const tChar *) pcBuffer;
                }
            }
        }

        LoadManeuverList(maneuverFileString);

        return;
    }

    if (sourcePin == &juryInput)
    {
        tInt8 juryActionId = -2;
        tInt16 maneuverId = -1;

        {
            __adtf_sample_read_lock_mediadescription(juryDescription, mediaSample, pCoder);

            pCoder->Get("i8ActionID", (tVoid *) &juryActionId);
            pCoder->Get("i16ManeuverEntry", (tVoid *) &maneuverId);
        }

        switch (juryActions(juryActionId))
        {
            case action_GETREADY:
                JuryGetReady(maneuverId);
                break;
            case action_START:
                JuryStart(maneuverId);
                break;
            case action_STOP:
                JuryStop(maneuverId);
                break;
        }

        return;
    }

    if (sourcePin == &errorInput)
    {
        tBool isError = tFalse;
        {
            __adtf_sample_read_lock_mediadescription(boolDescription, mediaSample, pCoder);
            pCoder->Get("bValue", (tVoid *) &isError);
        }

        if (isError)
        {
            logger.Log("Received Error");
            SetState(tCarState::Error);
        }

        return;
    }

    if (sourcePin == &emergencyStopInput)
    {
        tBool isEmergencyStop = tFalse;
        {
            __adtf_sample_read_lock_mediadescription(boolDescription, mediaSample, pCoder);
            pCoder->Get("bEmergencyStop", (tVoid *) &isEmergencyStop);
        }

        if (isEmergencyStop)
        {
            logger.Log("Received EmergencyStop");
            SetState(tCarState::Startup);
        }

        return;
    }

    if (sourcePin == &incrementManeuverInput)
    {
        tBool incrementManeuver = tFalse;
        {
            __adtf_sample_read_lock_mediadescription(boolDescription, mediaSample, pCoder);
            pCoder->Get("bValue", (tVoid *) &incrementManeuver);
        }

        if (incrementManeuver)
        {
            IncrementManeuver();
        }

        return;
    }

    if (sourcePin == &readyInput)
    {
        tReadyModule::ReadyModuleEnum module = tReadyModule::Nothing;
        {
            __adtf_sample_read_lock_mediadescription(enumDescription, mediaSample, pCoder);
            pCoder->Get("tEnumValue", (tVoid *) &module);
        }

        logger.Log(cString::Format("Received ready from %s", tReadyModule::ToString(module).c_str()).GetPtr());
        modulesReady.push_back(module);

        if (tCarState::GetReady == carState && AreAllModulesReady())
        {
            logger.Log("All modules ready");
            SetState(tCarState::Ready);
        }

        return;
    }
}
Exemplo n.º 2
0
tResult cDriverModule::OnPinEvent(IPin* pSource, tInt nEventCode, tInt nParam1, tInt nParam2, IMediaSample* pMediaSample)
{

    RETURN_IF_POINTER_NULL(pMediaSample);
    RETURN_IF_POINTER_NULL(pSource);



    if (nEventCode == IPinEventSink::PE_MediaSampleReceived  )
    {      

        if (pSource == &m_JuryStructInputPin && m_pDescJuryStruct != NULL) 
        {
            tInt8 i8ActionID = -2;
            tInt16 i16entry = -1;

            {   // focus for sample read lock
                __adtf_sample_read_lock_mediadescription(m_pDescJuryStruct,pMediaSample,pCoder);
                // get the IDs for the items in the media sample 
                if(!m_bIDsJuryStructSet)
                {
                    pCoder->GetID("i8ActionID", m_szIDJuryStructI8ActionID);
                    pCoder->GetID("i16ManeuverEntry", m_szIDJuryStructI16ManeuverEntry);
                    m_bIDsJuryStructSet = tTrue;
                }      

                pCoder->Get(m_szIDJuryStructI8ActionID, (tVoid*)&i8ActionID);
                pCoder->Get(m_szIDJuryStructI16ManeuverEntry, (tVoid*)&i16entry);              
            }

            switch (juryActions(i8ActionID))
            {
            case action_GETREADY:
                if(m_bDebugModeEnabled)  LOG_INFO(cString::Format("Driver Module: Received Request Ready with maneuver ID %d",i16entry));
                emit SendRequestReady((int)i16entry);
                break;
            case action_START:
                if(m_bDebugModeEnabled)  LOG_INFO(cString::Format("Driver Module: Received Run with maneuver ID %d",i16entry));
                emit SendRun((int)i16entry);
                break;
            case action_STOP:
                if(m_bDebugModeEnabled)  LOG_INFO(cString::Format("Driver Module: Received Stop with maneuver ID %d",i16entry));
                emit SendStop((int)i16entry);
                break;
            }

        }
        else if (pSource == &m_ManeuverListInputPin && m_pDescManeuverList != NULL)
        {

            {   // focus for sample read lock
                __adtf_sample_read_lock_mediadescription(m_pDescManeuverList,pMediaSample,pCoder);

                
                std::vector<tSize> vecDynamicIDs;
               
                // retrieve number of elements by providing NULL as first paramter
                tSize szBufferSize = 0;
                if(IS_OK(pCoder->GetDynamicBufferIDs(NULL, szBufferSize)))
                {
                    // create a buffer depending on the size element
                    tChar* pcBuffer = new tChar[szBufferSize];
                    vecDynamicIDs.resize(szBufferSize);
                    // get the dynamic ids (we already got the first "static" size element)
                    if (IS_OK(pCoder->GetDynamicBufferIDs(&(vecDynamicIDs.front()), szBufferSize)))
                    {
                        // iterate over all elements
                        for (tUInt32 nIdx = 0; nIdx < vecDynamicIDs.size(); ++nIdx)
                        {
                            // get the value and put it into the buffer
                            pCoder->Get(vecDynamicIDs[nIdx], (tVoid*)&pcBuffer[nIdx]);
                        }

                        // set the resulting char buffer to the string object
                        m_strManeuverFileString = (const tChar*) pcBuffer;
                    }

                    // cleanup the buffer
                    delete pcBuffer;
                }
        
            }

            // trigger loading maneuver list and update the ui
            TriggerLoadManeuverList();
        }
    }
    RETURN_NOERROR;

}
Exemplo n.º 3
0
tResult cJuryModule::OnDataUpdate(const tString& strName, const tVoid* pData, const tSize& szSize)
{
    // called from the connection lib on new data

    // check data size
    RETURN_IF_POINTER_NULL(pData);
    if (szSize <= 0)
    {
        RETURN_ERROR(ERR_INVALID_ARG);
    }

    // check the name of the data
    if (strName == CONLIB_IN_PORT_NAME_DRIVER_STRUCT)
    {     
        // data from driver
        const tDriverStruct* sDriverData = (const tDriverStruct*) pData;
        
        //update the gui
        emit SetDriverState(sDriverData->i8StateID, sDriverData->i16ManeuverEntry);


        //update the timeline
        if (m_i16LastDriverEntryId < sDriverData->i16ManeuverEntry || m_i16LastDriverEntryId == -1 || sDriverData->i8StateID == -1 || sDriverData->i8StateID == 2)
        {
            // set the first time manually
            if (m_oLastReceiveTimestamp.isNull())
            {
                m_oLastReceiveTimestamp = QTime::currentTime();
                m_i16LastDriverEntryId = sDriverData->i16ManeuverEntry;
            }

            // calc the time diff
            tTimeStamp timeDiff = (m_oLastReceiveTimestamp.msecsTo(QTime::currentTime()));  //time in milliseconds
            QString Message;
            switch (stateCar(sDriverData->i8StateID))
            {
            case stateCar_READY:
                Message = "from " + QString::number(m_i16LastDriverEntryId) + " to " + QString::number(sDriverData->i16ManeuverEntry) + ": " + QString::number(timeDiff) + " msec: Ready";
                break;
            case stateCar_RUNNING:
                Message = "from " + QString::number(m_i16LastDriverEntryId) + " to " + QString::number(sDriverData->i16ManeuverEntry) + ": " + QString::number(timeDiff) + " msec: OK";
                break;
            case stateCar_COMPLETE:
                Message = "from " + QString::number(m_i16LastDriverEntryId) + " to " + QString::number(sDriverData->i16ManeuverEntry) + ": " + QString::number(timeDiff) + " msec: Complete";
                break;
            case stateCar_ERROR:
                Message = "from " + QString::number(m_i16LastDriverEntryId) + " to " + QString::number(sDriverData->i16ManeuverEntry) + ": " + QString::number(timeDiff) + " msec: Error";
                break;
            case stateCar_STARTUP:
                break;
            }
            // set the last time
            m_oLastReceiveTimestamp = QTime::currentTime();             
            m_i16LastDriverEntryId = sDriverData->i16ManeuverEntry;
            //update the ui
            SetLogText(Message);
        }

    }
    else if (strName == CONLIB_IN_PORT_NAME_JURY_STRUCT_LOOPBACK)
    {
        // data from jury loopback
        const tJuryStruct* sJuryLoopbackData = (const tJuryStruct*) pData;

        QString strText = QString("Loopback Jury: Received jury struct loopback with action ");
        switch(juryActions(sJuryLoopbackData->i8ActionID))
        {
        case action_GETREADY:
            strText += "GETREADY ";
            break;
        case action_START:
            strText += "START ";
            break;
        case action_STOP:
            strText += "STOP ";
            break;
        default:
            strText += "UNKNOWN ";
            break;
        }

        strText += QString(" and maneuver ") + QString::number(sJuryLoopbackData->i16ManeuverEntry);

        // write text to log (just for checking the connection)
        SetLogText(strText);
        //QMetaObject::invokeMethod(this, "OnAppendText", Qt::AutoConnection, Q_ARG(QString, strText));
    }
    else if (strName == CONLIB_IN_PORT_NAME_EMERGENCY_STOP_LOOPBACK)
    {
        // data from emergency loopback
        const tJuryEmergencyStop* sJuryLoopbackData = (const tJuryEmergencyStop*) pData;

        QString strText = QString("Loopback Emergency: Received emergency loopback with "); 
        strText += (sJuryLoopbackData->bEmergencyStop == true) ? QString("true") : QString("false");
        
        // write text to log (just for checking the connection)
        SetLogText(strText);
        //QMetaObject::invokeMethod(this, "OnAppendText", Qt::AutoConnection, Q_ARG(QString, strText));
    }
    else if (strName == CONLIB_IN_PORT_NAME_MANEUVER_LIST)
    {
        // data from maneuverlist loopback
        const tInt32* i32DataSize = (const tInt32*) pData;
        const tChar* pcString = (const tChar*) ((tChar*)pData + sizeof(tInt32));
        tString strManeuver(pcString);
        QString strText = QString("Loopback ManeuverList received"); 

        // check the data content
        if(*i32DataSize != (m_strManeuverList.size() + sizeof(char)))
        {
            strText += QString(" size does not match"); 
        }
        if(strManeuver != m_strManeuverList)
        {
            strText += QString(" content does not match"); 
        }
        
        strText += "!!!";

        // write text to log (just for checking the connection)
        SetLogText(strText);
        //QMetaObject::invokeMethod(this, "OnAppendText", Qt::AutoConnection, Q_ARG(QString, strText));
    }
    RETURN_NOERROR;

}