From 72b0c8e46efb725db8ce90d9bbb600640eff4f50 Mon Sep 17 00:00:00 2001 From: Marcus10110 Date: Mon, 15 Jan 2024 16:43:41 -0800 Subject: [PATCH] Fix GetNearestTransitionChannel() to block until a new transition is found, to make the function behave consistently when running on real-time data as well as on completed captures. --- src/SMBusAnalyzer.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/SMBusAnalyzer.cpp b/src/SMBusAnalyzer.cpp index 7c688b9..c198734 100644 --- a/src/SMBusAnalyzer.cpp +++ b/src/SMBusAnalyzer.cpp @@ -42,11 +42,30 @@ AnalyzerChannelData* SMBusAnalyzer::AdvanceAllTo( U64 toSample ) AnalyzerChannelData* SMBusAnalyzer::GetNearestTransitionChannel() { + // if neither channel has more transitions, block for more data. + while( !mSMBDAT->DoMoreTransitionsExistInCurrentData() && !mSMBCLK->DoMoreTransitionsExistInCurrentData() ) + { + // DoMoreTransitionsExistInCurrentData will block for up to 250ms waiting for more data, and it will trigger a thread exit if the + // capture ends and there is still no more data. + } + if( !mSMBDAT->DoMoreTransitionsExistInCurrentData() ) - return mSMBCLK; + { + auto next_clk_edge = mSMBCLK->GetSampleOfNextEdge(); + if( !mSMBDAT->WouldAdvancingToAbsPositionCauseTransition( next_clk_edge ) ) + { + return mSMBCLK; + } + } if( !mSMBCLK->DoMoreTransitionsExistInCurrentData() ) - return mSMBDAT; + { + auto next_dat_edge = mSMBDAT->GetSampleOfNextEdge(); + if( !mSMBCLK->WouldAdvancingToAbsPositionCauseTransition( next_dat_edge ) ) + { + return mSMBDAT; + } + } if( mSMBDAT->GetSampleOfNextEdge() < mSMBCLK->GetSampleOfNextEdge() ) return mSMBDAT;