AnalyzerExamples/HdlcAnalyzer/HdlcAnalyzer.cpp
BitState HdlcAnalyzer::BitSyncReadBit()
{
	// Re-sync
	if ( mHdlc->GetSampleOfNextEdge() < mHdlc->GetSampleNumber() + mSamplesInHalfPeriod * 0.20 )
	{
		mHdlc->AdvanceToNextEdge();
	}

	BitState ret;

	mHdlc->Advance ( mSamplesInHalfPeriod * 0.5 );
	BitState bit = mHdlc->GetBitState(); // sample the bit

	if ( bit == mPreviousBitState )
	{
		mConsecutiveOnes++;
		if ( mReadingFrame && mConsecutiveOnes == 5 )
		{
			U64 currentPos = mHdlc->GetSampleNumber();

			// Check for 0-bit insertion (i.e. line toggle)
			if ( mHdlc->GetSampleOfNextEdge() < currentPos + mSamplesInHalfPeriod )
			{
				// Advance to the next edge to re-synchronize the analyzer
				mHdlc->AdvanceToNextEdge();
				// Mark the bit-stuffing
				mResults->AddMarker ( mHdlc->GetSampleNumber() , AnalyzerResults::Dot, mSettings->mInputChannel );
				mHdlc->Advance ( mSamplesInHalfPeriod * 0.5 );

				mPreviousBitState = mHdlc->GetBitState();
				mConsecutiveOnes = 0;
			}
			else // Abort!
			{
				mConsecutiveOnes = 0;
				mAbtFrame = CreateFrame ( HDLC_ABORT_SEQ, mHdlc->GetSampleNumber(), mHdlc->GetSampleNumber() + mSamplesIn8Bits );
				mAbortFrame = true;
			}

		}
		else
		{
			mPreviousBitState = bit;
		}

		ret = BIT_HIGH;
	}
	else // bit changed so it's a 0
	{
		mConsecutiveOnes = 0;
		mPreviousBitState = bit;
		ret = BIT_LOW;
	}

	mHdlc->Advance ( mSamplesInHalfPeriod * 0.5 );

	// Re-sync
	if ( mHdlc->GetSampleOfNextEdge() < mHdlc->GetSampleNumber() + mSamplesInHalfPeriod * 0.20 )
	{
		mHdlc->AdvanceToNextEdge();
	}

	return ret;
}
// Read bit with bit-stuffing

Read bit with bit-stuffing
Read bit with bit - stuffing
BitState HdlcAnalyzer::BitSyncReadBit()
{
	if ( mHdlc->GetSampleOfNextEdge() < mHdlc->GetSampleNumber() + mSamplesInHalfPeriod * 0.20 )
	{
		mHdlc->AdvanceToNextEdge();
	}
	BitState ret;
	mHdlc->Advance ( mSamplesInHalfPeriod * 0.5 );
	BitState bit = mHdlc->GetBitState(); 
	if ( bit == mPreviousBitState )
	{
		mConsecutiveOnes++;
		if ( mReadingFrame && mConsecutiveOnes == 5 )
		{
			U64 currentPos = mHdlc->GetSampleNumber();
			if ( mHdlc->GetSampleOfNextEdge() < currentPos + mSamplesInHalfPeriod )
			{
				mHdlc->AdvanceToNextEdge();
				mResults->AddMarker ( mHdlc->GetSampleNumber() , AnalyzerResults::Dot, mSettings->mInputChannel );
				mHdlc->Advance ( mSamplesInHalfPeriod * 0.5 );
				mPreviousBitState = mHdlc->GetBitState();
				mConsecutiveOnes = 0;
			}
			else 
			{
				mConsecutiveOnes = 0;
				mAbtFrame = CreateFrame ( HDLC_ABORT_SEQ, mHdlc->GetSampleNumber(), mHdlc->GetSampleNumber() + mSamplesIn8Bits );
				mAbortFrame = true;
			}
		}
		else
		{
			mPreviousBitState = bit;
		}
		ret = BIT_HIGH;
	}
	else 
	{
		mConsecutiveOnes = 0;
		mPreviousBitState = bit;
		ret = BIT_LOW;
	}
	mHdlc->Advance ( mSamplesInHalfPeriod * 0.5 );
	if ( mHdlc->GetSampleOfNextEdge() < mHdlc->GetSampleNumber() + mSamplesInHalfPeriod * 0.20 )
	{
		mHdlc->AdvanceToNextEdge();
	}
	return ret;
}
BitState HdlcAnalyzer :: BitSyncReadBit ( ) { if ( mHdlc -> GetSampleOfNextEdge ( ) < mHdlc -> GetSampleNumber ( ) + mSamplesInHalfPeriod * 0.20 ) { mHdlc -> AdvanceToNextEdge ( ) ; } BitState ret ; mHdlc -> Advance ( mSamplesInHalfPeriod * 0.5 ) ; BitState bit = mHdlc -> GetBitState ( ) ; if ( bit == mPreviousBitState ) { mConsecutiveOnes ++ ; if ( mReadingFrame && mConsecutiveOnes == 5 ) { U64 currentPos = mHdlc -> GetSampleNumber ( ) ; if ( mHdlc -> GetSampleOfNextEdge ( ) < currentPos + mSamplesInHalfPeriod ) { mHdlc -> AdvanceToNextEdge ( ) ; mResults -> AddMarker ( mHdlc -> GetSampleNumber ( ) , AnalyzerResults :: Dot , mSettings -> mInputChannel ) ; mHdlc -> Advance ( mSamplesInHalfPeriod * 0.5 ) ; mPreviousBitState = mHdlc -> GetBitState ( ) ; mConsecutiveOnes = 0 ; } else { mConsecutiveOnes = 0 ; mAbtFrame = CreateFrame ( HDLC_ABORT_SEQ , mHdlc -> GetSampleNumber ( ) , mHdlc -> GetSampleNumber ( ) + mSamplesIn8Bits ) ; mAbortFrame = true ; } } else { mPreviousBitState = bit ; } ret = BIT_HIGH ; } else { mConsecutiveOnes = 0 ; mPreviousBitState = bit ; ret = BIT_LOW ; } mHdlc -> Advance ( mSamplesInHalfPeriod * 0.5 ) ; if ( mHdlc -> GetSampleOfNextEdge ( ) < mHdlc -> GetSampleNumber ( ) + mSamplesInHalfPeriod * 0.20 ) { mHdlc -> AdvanceToNextEdge ( ) ; } return ret ; }
Read bit with bit-stuffing
Read bit with bit - stuffing
// Re-sync
 // sample the bit
 // Check for 0-bit insertion (i.e. line toggle)
 // Advance to the next edge to re-synchronize the analyzer
 // Mark the bit-stuffing
 // Abort!
 // bit changed so it's a 0
 // Re-sync
