2016-10-03 21:08:53 +00:00
|
|
|
#include "SimpleSerialAnalyzer.h"
|
|
|
|
#include "SimpleSerialAnalyzerSettings.h"
|
|
|
|
#include <AnalyzerChannelData.h>
|
|
|
|
|
|
|
|
SimpleSerialAnalyzer::SimpleSerialAnalyzer()
|
2017-05-12 17:57:02 +00:00
|
|
|
: Analyzer2(),
|
2016-10-03 21:08:53 +00:00
|
|
|
mSettings( new SimpleSerialAnalyzerSettings() ),
|
|
|
|
mSimulationInitilized( false )
|
|
|
|
{
|
|
|
|
SetAnalyzerSettings( mSettings.get() );
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleSerialAnalyzer::~SimpleSerialAnalyzer()
|
|
|
|
{
|
|
|
|
KillThread();
|
|
|
|
}
|
|
|
|
|
2017-05-12 17:57:02 +00:00
|
|
|
void SimpleSerialAnalyzer::SetupResults()
|
2016-10-03 21:08:53 +00:00
|
|
|
{
|
|
|
|
mResults.reset( new SimpleSerialAnalyzerResults( this, mSettings.get() ) );
|
|
|
|
SetAnalyzerResults( mResults.get() );
|
|
|
|
mResults->AddChannelBubblesWillAppearOn( mSettings->mInputChannel );
|
2017-05-12 17:57:02 +00:00
|
|
|
}
|
2016-10-03 21:08:53 +00:00
|
|
|
|
2017-05-12 17:57:02 +00:00
|
|
|
void SimpleSerialAnalyzer::WorkerThread()
|
|
|
|
{
|
2016-10-03 21:08:53 +00:00
|
|
|
mSampleRateHz = GetSampleRate();
|
|
|
|
|
|
|
|
mSerial = GetAnalyzerChannelData( mSettings->mInputChannel );
|
|
|
|
|
|
|
|
if( mSerial->GetBitState() == BIT_LOW )
|
|
|
|
mSerial->AdvanceToNextEdge();
|
|
|
|
|
|
|
|
U32 samples_per_bit = mSampleRateHz / mSettings->mBitRate;
|
|
|
|
U32 samples_to_first_center_of_first_data_bit = U32( 1.5 * double( mSampleRateHz ) / double( mSettings->mBitRate ) );
|
|
|
|
|
|
|
|
for( ; ; )
|
|
|
|
{
|
|
|
|
U8 data = 0;
|
|
|
|
U8 mask = 1 << 7;
|
|
|
|
|
|
|
|
mSerial->AdvanceToNextEdge(); //falling edge -- beginning of the start bit
|
|
|
|
|
|
|
|
U64 starting_sample = mSerial->GetSampleNumber();
|
|
|
|
|
|
|
|
mSerial->Advance( samples_to_first_center_of_first_data_bit );
|
|
|
|
|
|
|
|
for( U32 i=0; i<8; i++ )
|
|
|
|
{
|
|
|
|
//let's put a dot exactly where we sample this bit:
|
|
|
|
mResults->AddMarker( mSerial->GetSampleNumber(), AnalyzerResults::Dot, mSettings->mInputChannel );
|
|
|
|
|
|
|
|
if( mSerial->GetBitState() == BIT_HIGH )
|
|
|
|
data |= mask;
|
|
|
|
|
|
|
|
mSerial->Advance( samples_per_bit );
|
|
|
|
|
|
|
|
mask = mask >> 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//we have a byte to save.
|
|
|
|
Frame frame;
|
|
|
|
frame.mData1 = data;
|
|
|
|
frame.mFlags = 0;
|
|
|
|
frame.mStartingSampleInclusive = starting_sample;
|
|
|
|
frame.mEndingSampleInclusive = mSerial->GetSampleNumber();
|
|
|
|
|
|
|
|
mResults->AddFrame( frame );
|
|
|
|
mResults->CommitResults();
|
|
|
|
ReportProgress( frame.mEndingSampleInclusive );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SimpleSerialAnalyzer::NeedsRerun()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
U32 SimpleSerialAnalyzer::GenerateSimulationData( U64 minimum_sample_index, U32 device_sample_rate, SimulationChannelDescriptor** simulation_channels )
|
|
|
|
{
|
|
|
|
if( mSimulationInitilized == false )
|
|
|
|
{
|
|
|
|
mSimulationDataGenerator.Initialize( GetSimulationSampleRate(), mSettings.get() );
|
|
|
|
mSimulationInitilized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mSimulationDataGenerator.GenerateSimulationData( minimum_sample_index, device_sample_rate, simulation_channels );
|
|
|
|
}
|
|
|
|
|
|
|
|
U32 SimpleSerialAnalyzer::GetMinimumSampleRateHz()
|
|
|
|
{
|
|
|
|
return mSettings->mBitRate * 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* SimpleSerialAnalyzer::GetAnalyzerName() const
|
|
|
|
{
|
|
|
|
return "Simple Serial";
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* GetAnalyzerName()
|
|
|
|
{
|
|
|
|
return "Simple Serial";
|
|
|
|
}
|
|
|
|
|
|
|
|
Analyzer* CreateAnalyzer()
|
|
|
|
{
|
|
|
|
return new SimpleSerialAnalyzer();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DestroyAnalyzer( Analyzer* analyzer )
|
|
|
|
{
|
|
|
|
delete analyzer;
|
|
|
|
}
|