Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix log file playback delay #768

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 43 additions & 29 deletions Sources/Replay/ReplayProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,12 @@ UINT CReplayProcess::sunReplayMonoshotThreadFunc( LPVOID pParam )
/// Get the number of messages to play
int nCount = pReplayDetails->m_nNoOfMessagesToPlay;
int nOffset = pReplayDetails->m_nUserSelectionIndex;



// Time Calculation
CArray<UINT,UINT> omTimeDelay;
CArray<DOUBLE,DOUBLE> omTimeDelay;
double accDelay = 0;
if( pReplayDetails->m_ouReplayFile.m_nTimeMode == defREPLAY_RETAIN_DELAY
&& nCount > 1 )
{
Expand All @@ -130,12 +133,8 @@ UINT CReplayProcess::sunReplayMonoshotThreadFunc( LPVOID pParam )
// Get the current entry
omStrNext = pReplayDetails->m_omEntries[ nIndex + nOffset + 1];
omStrCurr = pReplayDetails->m_omEntries[ nIndex + nOffset ];
UINT unTime = unTimeDiffBetweenMsg( omStrNext, omStrCurr,
DOUBLE unTime = unTimeDiffBetweenMsg( omStrNext, omStrCurr,
pReplayDetails->m_wLogReplayTimeMode );
if( unTime == 0 )
{
unTime = 1;
}
omTimeDelay.Add( unTime );
}
}
Expand All @@ -149,7 +148,7 @@ UINT CReplayProcess::sunReplayMonoshotThreadFunc( LPVOID pParam )
// Create the event object to wait for
HANDLE hEventReplayWait = CreateEvent(nullptr, FALSE, FALSE, nullptr);
// Assign the message delay time
int nDelay = pReplayDetails->m_ouReplayFile.m_unMsgTimeDelay;
double nDelay = (double) pReplayDetails->m_ouReplayFile.m_unMsgTimeDelay;
// main loop for message transmission.
for( int nIndex = 0;
pReplayDetails->m_bStopReplayThread == FALSE && nIndex < nCount;
Expand All @@ -163,10 +162,15 @@ UINT CReplayProcess::sunReplayMonoshotThreadFunc( LPVOID pParam )
{
nDelay = omTimeDelay[ nIndex ];
}
accDelay += nDelay;

if(accDelay >= 1){

timeSetEvent( nDelay, time.wPeriodMin,
timeSetEvent( (UINT)accDelay, time.wPeriodMin,
(LPTIMECALLBACK) hEventReplayWait, 0,
TIME_CALLBACK_EVENT_SET | TIME_ONESHOT);

}
}
// Send message in CAN bus if the message ID is valid
if ( pReplayDetails->m_omMsgList[ nCurrentIndex].
Expand Down Expand Up @@ -201,7 +205,10 @@ UINT CReplayProcess::sunReplayMonoshotThreadFunc( LPVOID pParam )
else
{
// Wait for the event
WaitForSingleObject(hEventReplayWait, INFINITE);
if(accDelay >= 1) {
WaitForSingleObject(hEventReplayWait, INFINITE);
accDelay -= (DOUBLE)(UINT)accDelay;
}
}
}
if (mmResult == TIMERR_NOERROR)
Expand Down Expand Up @@ -257,8 +264,8 @@ UINT CReplayProcess::sunReplayCyclicThreadFunc( LPVOID pParam )
int nCount = pReplayDetails->m_nNoOfMessagesToPlay;

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

CArray<DOUBLE,DOUBLE> omTimeDelay;
double accDelay = 0;
CString omStrCurr;
CString omStrNext;
UINT unMsgDelay = pReplayDetails->m_ouReplayFile.m_unMsgTimeDelay;
Expand All @@ -278,12 +285,8 @@ UINT CReplayProcess::sunReplayCyclicThreadFunc( LPVOID pParam )
// Get the current entry
omStrNext = pReplayDetails->m_omEntries[ nNextIndex ];
omStrCurr = pReplayDetails->m_omEntries[ nCurrentIndex ];
UINT unTime = unTimeDiffBetweenMsg( omStrNext, omStrCurr,
DOUBLE unTime = unTimeDiffBetweenMsg( omStrNext, omStrCurr,
pReplayDetails->m_wLogReplayTimeMode );
if( unTime == 0 )
{
unTime = 1;
}
omTimeDelay.Add( unTime );
}
else
Expand Down Expand Up @@ -315,9 +318,13 @@ UINT CReplayProcess::sunReplayCyclicThreadFunc( LPVOID pParam )
{
int nCurrentIndex = pReplayDetails->m_omSelectedIndex[ nIndex ];
// Set the event to wait
timeSetEvent( omTimeDelay[ nIndex ], time.wPeriodMin,

accDelay += omTimeDelay[ nIndex ];
if(accDelay >= 1){
timeSetEvent( (UINT)accDelay, time.wPeriodMin,
(LPTIMECALLBACK) hEventReplayWait, 0,
TIME_CALLBACK_EVENT_SET | TIME_ONESHOT);
}

// Send message in CAN bus if the message ID is valid
if ( pReplayDetails->m_omMsgList[ nCurrentIndex ].
Expand Down Expand Up @@ -348,7 +355,10 @@ UINT CReplayProcess::sunReplayCyclicThreadFunc( LPVOID pParam )
nIndex++;
nIndex %= nCount;
// Wait for the event
WaitForSingleObject(hEventReplayWait, INFINITE);
if(accDelay >= 1){
WaitForSingleObject(hEventReplayWait, INFINITE);
accDelay -= (DOUBLE)(UINT)accDelay;
}
}
if (mmResult == TIMERR_NOERROR)
{
Expand Down Expand Up @@ -635,7 +645,8 @@ UINT CReplayProcess::sunNIReplayThreadFunc( LPVOID pParam )
pReplayDetails->m_omThreadEvent.ResetEvent();
// Replay code here
// Time Calculation
CArray<UINT,UINT> omTimeDelay;
CArray<DOUBLE,DOUBLE> omTimeDelay;
double accDelay = 0;
// Get the item count
int nCount = (int)pReplayDetails->m_omEntries.GetSize();

Expand All @@ -657,12 +668,8 @@ UINT CReplayProcess::sunNIReplayThreadFunc( LPVOID pParam )
omStrNext = pReplayDetails->m_omEntries[ nIndex + 1 ];
// Get the current entry
omStrCurr = pReplayDetails->m_omEntries[ nIndex ];
UINT unTime = unTimeDiffBetweenMsg( omStrNext, omStrCurr,
DOUBLE unTime = unTimeDiffBetweenMsg( omStrNext, omStrCurr,
pReplayDetails->m_wLogReplayTimeMode );
if( unTime == 0 )
{
unTime = 1;
}
omTimeDelay.Add( unTime );
}
else
Expand Down Expand Up @@ -693,10 +700,12 @@ UINT CReplayProcess::sunNIReplayThreadFunc( LPVOID pParam )
while( pReplayDetails->m_bStopReplayThread == FALSE )
{
// Set the event to wait
timeSetEvent( omTimeDelay[ nIndex ], time.wPeriodMin,
(LPTIMECALLBACK) hEventReplayWait, 0,
TIME_CALLBACK_EVENT_SET | TIME_ONESHOT);

accDelay += omTimeDelay[ nIndex ];
if(accDelay >= 1){
timeSetEvent( (UINT)accDelay, time.wPeriodMin,
(LPTIMECALLBACK) hEventReplayWait, 0,
TIME_CALLBACK_EVENT_SET | TIME_ONESHOT);
}
// Send message in CAN bus if the message ID is valid
if ( pReplayDetails->m_omMsgList[ nIndex ].
m_uDataInfo.m_sCANMsg.m_unMsgID != -1 )
Expand Down Expand Up @@ -745,7 +754,12 @@ UINT CReplayProcess::sunNIReplayThreadFunc( LPVOID pParam )
// Wait for the event
if( pReplayDetails->m_bStopReplayThread == FALSE )
{
WaitForSingleObject(hEventReplayWait, INFINITE);
if(accDelay >= 1){

WaitForSingleObject(hEventReplayWait, INFINITE);
accDelay -= (DOUBLE)(UINT)accDelay;
}

}
}
if (mmResult == TIMERR_NOERROR)
Expand Down
10 changes: 5 additions & 5 deletions Sources/Replay/Utility_Replay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,11 @@ BOOL bIsModeMismatch( std::ifstream& omInReplayFile,
/* Modification By : Krishnaswamy B.N */
/* Modified On : 03.06.2004, Relative time is computed */
/******************************************************************************/
UINT unTimeDiffBetweenMsg( CString& omStrNextMsg,
DOUBLE unTimeDiffBetweenMsg( CString& omStrNextMsg,
CString& omStrCurMsg,
WORD wLogReplyTimeMode)
{
UINT unTimeDifference = 0;
DOUBLE unTimeDifference = 0;
CString omStrMsgCurTime ="";
CString omStrMsgNextTime ="";
CString omStrTemp ="";
Expand Down Expand Up @@ -445,14 +445,14 @@ UINT unTimeDiffBetweenMsg( CString& omStrNextMsg,
{
if(dCurTime < dNextTime)
{
unTimeDifference = (UINT)(dNextTime - dCurTime + 0.5);
unTimeDifference = (dNextTime - dCurTime);
}
}
else
{
if(dNextTime >0)
if(dNextTime > 0)
{
unTimeDifference = static_cast<UINT>(dNextTime) ;
unTimeDifference = dNextTime ;
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Replay/Utility_Replay.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void vConvStrtoByteArray(CByteArray* pomByteArrayBufTx,
BOOL bHexON);

// To get the time differenct between two message entries
UINT unTimeDiffBetweenMsg( CString& omStrNextMsg,
DOUBLE unTimeDiffBetweenMsg( CString& omStrNextMsg,
CString& omStrCurMsg,
WORD wLogReplyTimeMode);
BOOL bIsModeMismatch( std::ifstream& omInReplayFile,
Expand Down