예제 #1
0
/*******************************************************************************
  Function Name  : sunNIReplayThreadFunc
  Input(s)       : pParam - Parameter to the thread
  Output         : -
  Functionality  : This is the Non Interactive thread function
  Member of      : CReplayProcess
  Author(s)      : Raja N
  Date Created   : 16.7.2005
  Modifications  :
*******************************************************************************/
UINT CReplayProcess::sunNIReplayThreadFunc( LPVOID pParam )
{
    CReplayProcess* pReplayDetails = (CReplayProcess*)pParam;

    if( pReplayDetails != NULL )
    {
        pReplayDetails->bSetbIsProtocolMismatch(false);
        pReplayDetails->bSetbIsInvalidMsg(false);
        // Reset the event
        pReplayDetails->m_omThreadEvent.ResetEvent();
        // Replay code here
        // Time Calculation
        CArray<UINT,UINT> omTimeDelay;
        // Get the item count
        bool bSessionFlag = false;
        bool bDetectSession = false;
        bool bDetectEOF = false;
        bool bEOFFlag = false;
        CString omStrCurr = "";
        CString omStrNext= "";
        // Init Message delay
        UINT unMsgDelay = pReplayDetails->m_ouReplayFile.m_unMsgTimeDelay;
        if( unMsgDelay == 0 )
        {
            unMsgDelay = 1;
        }
        //int nIndex; //nIndex declared outside


        // Add the cyclic delay at the end
        UINT unCycleDelay = pReplayDetails->m_ouReplayFile.m_unCycleTimeDelay;
        if( unCycleDelay == 0 )
        {
            unCycleDelay = 1;
        }

        UINT unSessionDelay=pReplayDetails->m_ouReplayFile.m_unSessionDelay;
        if( unSessionDelay == 0 )
        {
            unSessionDelay = 1;
        }
        TIMECAPS time;
        MMRESULT mmResult = TIMERR_NOERROR;
        if (timeGetDevCaps(&time, sizeof(TIMECAPS)) == TIMERR_NOERROR)
        {
            mmResult = timeBeginPeriod(time.wPeriodMin);
        }

        // Create the event object to wait for
        HANDLE hEventReplayWait = CreateEvent(NULL, FALSE, FALSE, NULL);
        // main loop for message transmission.
        UINT unTime;
        pReplayDetails->omInReplayFile.clear(); // clear eof and fail bits
        pReplayDetails->omInReplayFile.seekg(0, std::ios::beg);
        std::string strLine;

        while( pReplayDetails->m_bStopReplayThread == FALSE )
        {
            bool bIsProtocolMismatch = false;
            unMsgDelay = pReplayDetails->m_ouReplayFile.m_unMsgTimeDelay;
            if( unMsgDelay == 0 )
            {
                unMsgDelay = 1;
            }
            bSessionFlag = false;
            bEOFFlag = false;
            if(bDetectSession)
            {
                bSessionFlag = true;
                bDetectSession = false;
            }
            if(bDetectEOF)
            {
                bEOFFlag = true;
                bDetectEOF = false;
            }
            bool bIsComment = false;
            while(getline(pReplayDetails->omInReplayFile , strLine))
            {
                CUtilFunctions::Trim(strLine,' ');
                if(strLine.find(END_SESSION) != std::string::npos)
                {
                    bDetectSession = true ;
                }
                if(strLine.find(START_COMMENT) != std::string::npos)
                {
                    bIsComment = true;
                }
                if(strLine.find(END_COMMENT) != std::string::npos)
                {
                    bIsComment = false;
                }

                if(strLine.empty() || bIsComment)
                {
                    continue;
                }

                if(strLine.find("*") == std::string::npos)
                {
                    omStrCurr = omStrNext;
                    omStrNext = strLine.c_str();
                    if(omStrCurr.Compare("") == 0)
                    {
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
                if(strLine.find("*") != std::string::npos)
                {
                    if( strLine.find(defSTR_PROTOCOL_USED) != std::string::npos)
                    {
                        // If can related log file
                        if( strLine.find(defSTR_PROTOCOL_CAN) == std::string::npos)
                        {
                            pReplayDetails->m_omStrError = defSTR_LOG_PRTOCOL_MISMATCH;
                            bIsProtocolMismatch = true;
                            if(pReplayDetails->m_ouReplayFile.m_nReplayMode ==  defREPLAY_MODE_CYCLIC)
                            {
                                pReplayDetails->omInReplayFile.clear(); // clear eof and fail bits
                                pReplayDetails->omInReplayFile.seekg(0, std::ios::beg);
                                bDetectEOF = true;
                            }
                            else
                            {
                                pReplayDetails->m_bStopReplayThread = TRUE;
                            }
                            omStrCurr = omStrNext;
                            omStrNext = "";
                            break;
                        }
                    }


                }
            }
            if(omStrCurr.IsEmpty() && omStrNext.IsEmpty())
            {
                CReplayManager::ouGetReplayManager().vSendToTrace(defSTR_REPLAY_FILE_EMPTY);
                pReplayDetails->m_bStopReplayThread = TRUE;
                continue;
            }
            if(pReplayDetails->omInReplayFile.eof())
            {
                omStrCurr = omStrNext;
                omStrNext = "";
                bDetectEOF = true;
            }
            STCANDATA sCanMsg,sNxtCanMsg;
            bool bIsValidMessage = true;
            pReplayDetails->sGetCanMsg(omStrCurr,sCanMsg);
            if(omStrNext.IsEmpty() == FALSE)
            {
                bIsValidMessage = pReplayDetails->sGetCanMsg(omStrNext,sNxtCanMsg);
            }
            if(!bIsValidMessage)
            {
                pReplayDetails->m_omStrError = defSTR_LOG_INVALID_MESSAGE;
                if(!pReplayDetails->bGetbIsInvalidMsg())
                {
                    CReplayManager::ouGetReplayManager().vSendToTrace(defSTR_LOG_INVALID_MESSAGE);
                    pReplayDetails->bSetbIsInvalidMsg(true);
                }
                if(pReplayDetails->m_ouReplayFile.m_nReplayMode ==  defREPLAY_MODE_CYCLIC)
                {
                    pReplayDetails->omInReplayFile.clear(); // clear eof and fail bits
                    pReplayDetails->omInReplayFile.seekg(0, std::ios::beg);
                    bDetectEOF = true;
                    omStrNext = "";
                }
                else
                {
                    pReplayDetails->m_bStopReplayThread = TRUE;
                }


            }


            if( (pReplayDetails->m_ouReplayFile.m_nTimeMode ==
                    defREPLAY_RETAIN_DELAY) && bIsValidMessage && !bIsProtocolMismatch)
            {
                unTime = unTimeDiffBetweenMsg( omStrNext, omStrCurr,
                                               pReplayDetails->m_wLogReplayTimeMode );
                if( unTime == 0 )
                {
                    unTime = 1;
                }
                unMsgDelay = unTime;
            }

            if((pReplayDetails->m_ouReplayFile.m_nSessionMode == defREPLAY_SPECIFIC_SESSION_DELAY) && bDetectSession == true)
            {
                unMsgDelay = unSessionDelay;
            }

            if(bDetectEOF && pReplayDetails->m_ouReplayFile.m_nReplayMode ==    defREPLAY_MODE_CYCLIC)
            {
                unMsgDelay = unCycleDelay;
                pReplayDetails->omInReplayFile.clear(); // clear eof and fail bits
                pReplayDetails->omInReplayFile.seekg(0, std::ios::beg);
            }

            // Send message in CAN bus if the message ID is valid
            timeSetEvent( unMsgDelay, time.wPeriodMin,
                          (LPTIMECALLBACK) hEventReplayWait, NULL,
                          TIME_CALLBACK_EVENT_SET | TIME_ONESHOT);

            if (sCanMsg.m_uDataInfo.m_sCANMsg.m_unMsgID != -1 )
            {
                HRESULT hRet = 0;

                SFRAMEINFO_BASIC_CAN sBasicCanInfo;

                pReplayDetails->vFormatCANDataMsg(&sCanMsg, &sBasicCanInfo);
                bool bTobeBlocked = false;
                if( pReplayDetails->m_ouReplayFile.m_sFilterApplied.m_bEnabled == TRUE)
                {
                    EnterCriticalSection(&pReplayDetails->m_omCritSecFilter);
                    bTobeBlocked = pReplayDetails->m_ouReplayFile.m_sFilterApplied.bToBeBlocked(sBasicCanInfo);
                    LeaveCriticalSection(&pReplayDetails->m_omCritSecFilter);
                }

                if(bTobeBlocked == false )
                {
                    // Use HIL Function to send CAN message

                    hRet = s_pouDIL_CAN_Interface->DILC_SendMsg(s_dwClientID, sCanMsg.m_uDataInfo.m_sCANMsg);
                }

                if (hRet != 0)
                {
                    //::PostMessage(GUI_hDisplayWindow, WM_ERROR,
                    //            ERROR_DRIVER_API_FAIL, nZERO);
                }
            }
            // Update the index
            // if last message is already sent,
            // and it is a cyclic block then go to begining. Otherwise stop the
            // thread
            if( pReplayDetails->omInReplayFile.eof() )
            {
                if( pReplayDetails->m_ouReplayFile.m_nReplayMode ==
                        defREPLAY_MODE_MONOSHOT )
                {
                    pReplayDetails->m_bStopReplayThread = TRUE;
                }

            }
            // Wait for the event
            if( pReplayDetails->m_bStopReplayThread == FALSE)
            {
                WaitForSingleObject(hEventReplayWait, INFINITE);
            }

            if(bIsProtocolMismatch && bIsValidMessage)
            {
                if(!pReplayDetails->bGetbIsProtocolMismatch())
                {
                    CReplayManager::ouGetReplayManager().vSendToTrace(defSTR_LOG_PRTOCOL_MISMATCH);
                    pReplayDetails->bSetbIsProtocolMismatch(true);
                }

            }
        }
        if (mmResult == TIMERR_NOERROR)
        {
            timeEndPeriod(time.wPeriodMin);
        }
        CloseHandle(hEventReplayWait);
        pReplayDetails->m_omThreadEvent.SetEvent();

    }

    return 0;
}
예제 #2
0
UINT CReplayProcess::sunReplayMonoshotThreadFunc( LPVOID pParam )
{

    CReplayProcess* pReplayDetails = (CReplayProcess*)pParam;
    bool bNxtSessionFlag = false;
    bool bNxtEOFflag = false;
    bool bCurSessionFlag = false;
    bool bCurEOFflag = false;
    bool bCurProtocolMismatch = false;
    bool bNxtProtocolMismatch = false;
    bool bNxtInvalidMsg = false;
    bool bCurInvalidMsg = false;
    STCANDATA sNxtCanMsg;
    STCANDATA sCurCanMsg;

    ZeroMemory(&sCurCanMsg, sizeof(STCANDATA));

    if( pReplayDetails != nullptr )
    {
        CMsgReplayWnd* pWnd = (CMsgReplayWnd*)pReplayDetails->m_pReplayWndPtr;
        // Reset the event
        pReplayDetails->m_omThreadEvent.ResetEvent();
        // Disable List control
        // To avoid flickering avoid disabling for a step action
        if( pWnd != nullptr && pReplayDetails->m_nNoOfMessagesToPlay > 1)
        {
            pWnd->m_omMessageList.EnableWindow( FALSE );
        }
        // Replay code here
        /// Get the number of messages to play
        int nCount = pReplayDetails->m_nNoOfMessagesToPlay;
        int nOffset = pReplayDetails->m_nUserSelectionIndex;

        // Time Calculation
        CArray<UINT,UINT> omTimeDelay;

        TIMECAPS time;
        MMRESULT mmResult = TIMERR_NOERROR;
        if (timeGetDevCaps(&time, sizeof(TIMECAPS)) == TIMERR_NOERROR)
        {
            mmResult = timeBeginPeriod(time.wPeriodMin);
        }

        // Create the event object to wait for
        HANDLE hEventReplayWait = CreateEvent(nullptr, FALSE, FALSE, nullptr);
        // Assign the message delay time

        UINT unDelay;
        UINT unMsgDelay = pReplayDetails->m_ouReplayFile.m_unMsgTimeDelay;
        if( unMsgDelay == 0 )
        {
            unMsgDelay = 1;
        }
        
        UINT unSessionDelay = pReplayDetails->m_ouReplayFile.m_unSessionDelay;
        if( unSessionDelay == 0 )
        {
            unSessionDelay = 1;
        }

        // main loop for message transmission.
        BOOL bBreakPointFlag = FALSE;
        if(pReplayDetails->m_omBreakPoints[nOffset ] == TRUE)
        {
            bBreakPointFlag = TRUE;
        }
        for( int nIndex = 0;
                pReplayDetails->m_bStopReplayThread == FALSE &&( (pReplayDetails->m_omBreakPoints[ nIndex + nOffset ] == FALSE)||(bBreakPointFlag == TRUE));
                nIndex++ )
        {
            bBreakPointFlag = FALSE;
            int nCurrentIndex = nIndex + nOffset;
            if( ( nIndex + 1 ) <= nCount )
            {
                CString omStrCurr;
                CString omStrNext;
                omStrNext = pReplayDetails->omStrGetMsgFromLog(nIndex + nOffset + 1,sNxtCanMsg,bNxtSessionFlag, bNxtEOFflag,bNxtProtocolMismatch,bNxtInvalidMsg);
                omStrCurr = pReplayDetails->omStrGetMsgFromLog(nIndex + nOffset,sCurCanMsg, bCurSessionFlag, bCurEOFflag,bCurProtocolMismatch,bCurInvalidMsg);

                unDelay = unMsgDelay;
                if( pReplayDetails->m_ouReplayFile.m_nTimeMode ==
                        defREPLAY_RETAIN_DELAY )
                {
                    if(bCurEOFflag)
                    {
                        pReplayDetails->m_bStopReplayThread = TRUE;
                    }

                    UINT unTime = unTimeDiffBetweenMsg( omStrNext, omStrCurr,
                                                        pReplayDetails->m_wLogReplayTimeMode );
                    if( unTime == 0 )
                    {
                        unTime = 1;
                    }

                    unDelay = unTime;
                }

                if(bNxtSessionFlag && (pReplayDetails->m_ouReplayFile.m_nSessionMode == defREPLAY_SPECIFIC_SESSION_DELAY))
                {
                    unDelay = unSessionDelay;
                }


                timeSetEvent( unDelay, time.wPeriodMin,
                              (LPTIMECALLBACK) hEventReplayWait, 0,
                              TIME_CALLBACK_EVENT_SET | TIME_ONESHOT);
            }
            // Send message in CAN bus if the message ID is valid

            if ( sCurCanMsg.m_uDataInfo.m_sCANMsg.m_unMsgID != -1 )
            {
                HRESULT hRet = 0;
                SFRAMEINFO_BASIC_CAN sBasicCanInfo;

                pReplayDetails->vFormatCANDataMsg(&sCurCanMsg, &sBasicCanInfo);
                BOOL bTobeBlocked = FALSE;
                if( pReplayDetails->m_ouReplayFile.m_sFilterApplied.m_bEnabled == TRUE)
                {
                    EnterCriticalSection(&pReplayDetails->m_omCritSecFilter);
                    bTobeBlocked = pReplayDetails->m_ouReplayFile.m_sFilterApplied.bToBeBlocked(sBasicCanInfo);
                    LeaveCriticalSection(&pReplayDetails->m_omCritSecFilter);
                }
                if(bTobeBlocked == FALSE)
                {
                    // Use HIL Function to send CAN message

                    HRESULT hRet =  s_pouDIL_CAN_Interface->DILC_SendMsg(s_dwClientID,
                                    sCurCanMsg.
                                    m_uDataInfo.m_sCANMsg );
                }

            }
            // Increment cur sel to set to next sel
            pReplayDetails->m_nCurrentIndex = nCurrentIndex;
            // last message is already sent

            if(bNxtEOFflag || nCount == 1)
            {
                pReplayDetails->m_bStopReplayThread = TRUE;
            }
            else
            {
                // Wait for the event
                WaitForSingleObject(hEventReplayWait, INFINITE);
            }

            if(bNxtProtocolMismatch)
            {
                pReplayDetails->m_bStopReplayThread = TRUE;
                if(!pReplayDetails->bGetbIsProtocolMismatch())
                {
                    CReplayManager::ouGetReplayManager().vSendToTrace(defSTR_LOG_PRTOCOL_MISMATCH);
                    pReplayDetails->bSetbIsProtocolMismatch(true);
                }
            }
            else if(bNxtInvalidMsg && !bNxtEOFflag)
            {
                pReplayDetails->m_bStopReplayThread = TRUE;
                if(!pReplayDetails->bGetbIsInvalidMsg())
                {
                    CReplayManager::ouGetReplayManager().vSendToTrace(defSTR_LOG_INVALID_MESSAGE);
                    pReplayDetails->bSetbIsProtocolMismatch(true);
                }
            }

        }
        if (mmResult == TIMERR_NOERROR)
        {
            timeEndPeriod(time.wPeriodMin);
        }
        CloseHandle(hEventReplayWait);

        if( pWnd != nullptr )
        {
            pWnd->m_omMessageList.EnableWindow( );
            pWnd->m_eReplayState = REPLAY_TO_START;
            // Set the selection
            pReplayDetails->m_nCurrentIndex++;
            pReplayDetails->m_nCurrentIndex %= pReplayDetails->dwGetvecPegSize();
            pWnd->m_omMessageList.SetItemState( pReplayDetails->m_nCurrentIndex,
                                                LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
            pWnd->m_omMessageList.EnsureVisible(
                pReplayDetails->m_nCurrentIndex, FALSE );
        }
        pReplayDetails->m_omThreadEvent.SetEvent();
    }
    return 0;
}
예제 #3
0
/*******************************************************************************
  Function Name  : sunReplayCyclicThreadFunc
  Input(s)       : pParam - Parameter to the thread
  Output         : -
  Functionality  : This is the thread function for cyclic replay blocks
  Member of      : CReplayProcess
  Author(s)      : Raja N
  Date Created   : 16.7.2005
  Modifications  :
*******************************************************************************/
UINT CReplayProcess::sunReplayCyclicThreadFunc( LPVOID pParam )
{
    CReplayProcess* pReplayDetails = (CReplayProcess*)pParam;
    bool bNxtSessionFlag = false;
    bool bNxtEOFflag = false;
    bool bCurSessionFlag = false;
    bool bCurEOFflag = false;
    bool bCurProtocolMismatch = false;
    bool bNxtProtocolMismatch = false;
    bool bNxtInvalidMsg = false;
    bool bCurInvalidMsg = false;
    STCANDATA sNxtCanMsg;
    STCANDATA sCurCanMsg;

    if( pReplayDetails != nullptr )
    {
        CMsgReplayWnd* pWnd = (CMsgReplayWnd*)pReplayDetails->m_pReplayWndPtr;
        // Reset the event
        pReplayDetails->m_omThreadEvent.ResetEvent();
        // Disable List control
        if( pWnd != nullptr )
        {
            pWnd->m_omMessageList.EnableWindow( FALSE );
        }
        // Replay code here
        /// Get the number of messages to play
        int nCount = pReplayDetails->m_nNoOfMessagesToPlay;

        // Time Calculation
        CArray<UINT,UINT> omTimeDelay;

        CString omStrCurr;
        CString omStrNext;
        UINT unDelay;
        UINT unMsgDelay = pReplayDetails->m_ouReplayFile.m_unMsgTimeDelay;
        if( unMsgDelay == 0 )
        {
            unMsgDelay = 1;
        }
        int nIndex; //nIndex declared outside

        UINT unSessionDelay = pReplayDetails->m_ouReplayFile.m_unSessionDelay;
        if( unSessionDelay == 0 )
        {
            unSessionDelay = 1;
        }

        // Add the cyclic delay at the end
        UINT unCycleDelay = pReplayDetails->m_ouReplayFile.m_unCycleTimeDelay;
        if( unCycleDelay == 0 )
        {
            unCycleDelay = 1;
        }

        TIMECAPS time;
        MMRESULT mmResult = TIMERR_NOERROR;
        if (timeGetDevCaps(&time, sizeof(TIMECAPS)) == TIMERR_NOERROR)
        {
            mmResult = timeBeginPeriod(time.wPeriodMin);
        }

        // Create the event object to wait for
        HANDLE hEventReplayWait = CreateEvent(nullptr, FALSE, FALSE, nullptr);
        // main loop for message transmission.
        nIndex = 0;
        while( pReplayDetails->m_bStopReplayThread == FALSE )
        {
            int nCurrentIndex = pReplayDetails->m_omSelectedIndex[ nIndex ];
            int nNextIndex =  pReplayDetails->m_omSelectedIndex[ (nIndex + 1)%nCount ];
            omStrNext = pReplayDetails->omStrGetMsgFromLog(nNextIndex,sNxtCanMsg,bNxtSessionFlag,bNxtEOFflag,bNxtProtocolMismatch,bNxtInvalidMsg);
            omStrCurr = pReplayDetails->omStrGetMsgFromLog(nCurrentIndex,sCurCanMsg,bCurSessionFlag,bCurEOFflag,bCurProtocolMismatch,bCurInvalidMsg);
            unDelay = unMsgDelay;
            if( pReplayDetails->m_ouReplayFile.m_nTimeMode ==
                    defREPLAY_RETAIN_DELAY && (nIndex < nCount-1) )
            {

                UINT unTime = unTimeDiffBetweenMsg( omStrNext, omStrCurr,
                                                    pReplayDetails->m_wLogReplayTimeMode );
                if( unTime == 0 )
                {
                    unTime = 1;
                }
                unMsgDelay = unTime ;
            }


            if(bNxtSessionFlag && (pReplayDetails->m_ouReplayFile.m_nSessionMode == defREPLAY_SPECIFIC_SESSION_DELAY))
            {
                unDelay = unSessionDelay;
            }
            if(nIndex == nCount - 1)
            {
                unDelay = unCycleDelay;
            }

            timeSetEvent( unDelay, time.wPeriodMin,
                          (LPTIMECALLBACK) hEventReplayWait, NULL,
                          TIME_CALLBACK_EVENT_SET | TIME_ONESHOT);
            // Send message in CAN bus if the message ID is valid

            if ( sCurCanMsg.m_uDataInfo.m_sCANMsg.m_unMsgID != -1 )
            {
                HRESULT hRet = 0;

                SFRAMEINFO_BASIC_CAN sBasicCanInfo;

                pReplayDetails->vFormatCANDataMsg(&sCurCanMsg, &sBasicCanInfo);
                BOOL bTobeBlocked = FALSE;

                EnterCriticalSection(&pReplayDetails->m_omCritSecFilter);
                if( pReplayDetails->m_ouReplayFile.m_sFilterApplied.m_bEnabled == TRUE)
                {
                    bTobeBlocked = pReplayDetails->m_ouReplayFile.m_sFilterApplied.bToBeBlocked(sBasicCanInfo);
                }
                LeaveCriticalSection(&pReplayDetails->m_omCritSecFilter);

                if(bTobeBlocked == FALSE)
                {
                    // Use HIL Function to send CAN message

                    HRESULT hRet = s_pouDIL_CAN_Interface->DILC_SendMsg(s_dwClientID,sCurCanMsg.m_uDataInfo.m_sCANMsg );
                }

            }
            // Update index and wrap up to modula of message list size
            nIndex++;
            nIndex %= nCount;
            // Wait for the event
            WaitForSingleObject(hEventReplayWait, INFINITE);
        }
        if (mmResult == TIMERR_NOERROR)
        {
            timeEndPeriod(time.wPeriodMin);
        }
        CloseHandle(hEventReplayWait);

        if( pWnd != nullptr )
        {
            // Update the window
            pWnd->m_omMessageList.EnableWindow( );
            pWnd->m_eReplayState = REPLAY_TO_START;
        }
        pReplayDetails->m_omThreadEvent.SetEvent();
    }
    return 0;
}