/******************************************************************************* 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; }
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; }