added cycletime + fix last frame
This commit is contained in:
@@ -28,189 +28,110 @@ void TLC59731Analyzer::WorkerThread()
|
|||||||
mSampleRateHz = GetSampleRate();
|
mSampleRateHz = GetSampleRate();
|
||||||
|
|
||||||
mSerial = GetAnalyzerChannelData( mSettings.mInputChannel );
|
mSerial = GetAnalyzerChannelData( mSettings.mInputChannel );
|
||||||
|
bool run = 1;
|
||||||
|
|
||||||
while( SamplesToNS( mSerial->GetSampleOfNextEdge() - mSerial->GetSampleNumber() ) < TLL_MIN || mSerial->GetBitState() == BIT_HIGH )
|
while( run )
|
||||||
{
|
{
|
||||||
mSerial->AdvanceToNextEdge();
|
while( SamplesToNS( mSerial->GetSampleOfNextEdge() - mSerial->GetSampleNumber() ) < TLL_MIN || mSerial->GetBitState() == BIT_HIGH )
|
||||||
}
|
|
||||||
while( mSerial->GetBitState() != BIT_HIGH )
|
|
||||||
{
|
|
||||||
mSerial->AdvanceToNextEdge(); // wait for rising
|
|
||||||
}
|
|
||||||
|
|
||||||
U32 data = 0;
|
|
||||||
// measure cycletime
|
|
||||||
// start of bit
|
|
||||||
U64 SoB = mSerial->GetSampleNumber();
|
|
||||||
U64 starting_sample = SoB;
|
|
||||||
mSerial->AdvanceToNextEdge(); // falling edge
|
|
||||||
if( SamplesToNS( mSerial->GetSampleOfNextEdge() - SoB ) <= MAX_CYCLETIME )
|
|
||||||
{
|
|
||||||
mSerial->AdvanceToNextEdge(); // rising edge of second 0
|
|
||||||
cycleTime = SamplesToNS( mSerial->GetSampleNumber() - SoB );
|
|
||||||
SoB = mSerial->GetSampleNumber();
|
|
||||||
}
|
|
||||||
|
|
||||||
while( 1 )
|
|
||||||
{
|
|
||||||
mSerial->AdvanceToNextEdge(); // falling edge
|
|
||||||
if( SamplesToNS( mSerial->GetSampleOfNextEdge() - SoB ) < cycleTime / 2.0 + 1000 )
|
|
||||||
{
|
{
|
||||||
// 1
|
|
||||||
data <<= 1;
|
|
||||||
data |= 1;
|
|
||||||
mSerial->AdvanceToNextEdge(); // rising edge of second pulse of 1
|
|
||||||
mSerial->AdvanceToNextEdge(); // falling edge of second ṕulse of 1
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// 0
|
|
||||||
data <<= 1;
|
|
||||||
}
|
|
||||||
if( SamplesToNS( mSerial->GetSampleOfNextEdge() - SoB ) < cycleTime * 2 )
|
|
||||||
{
|
|
||||||
mSerial->AdvanceToNextEdge(); // rising edge of next bit
|
|
||||||
SoB = mSerial->GetSampleNumber();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if( SamplesToNS( mSerial->GetSampleOfNextEdge() - SoB ) < cycleTime * 5.5 ||
|
|
||||||
SamplesToNS( mSerial->GetSampleOfNextEdge() - SoB ) > cycleTime * 8 )
|
|
||||||
{
|
|
||||||
// EOS end of sequence
|
|
||||||
Frame frame;
|
|
||||||
frame.mData1 = data;
|
|
||||||
frame.mFlags = 0;
|
|
||||||
frame.mStartingSampleInclusive = starting_sample;
|
|
||||||
frame.mEndingSampleInclusive = mSerial->GetSampleNumber();
|
|
||||||
mResults->AddFrame( frame );
|
|
||||||
ReportProgress( frame.mEndingSampleInclusive );
|
|
||||||
|
|
||||||
FrameV2 framev2;
|
|
||||||
framev2.AddInteger("data", frame.mData1);
|
|
||||||
mResults->AddFrameV2(framev2, "ledData", frame.mStartingSampleInclusive, frame.mEndingSampleInclusive);
|
|
||||||
mResults->CommitResults();
|
|
||||||
|
|
||||||
data = 0;
|
|
||||||
mSerial->AdvanceToNextEdge();
|
mSerial->AdvanceToNextEdge();
|
||||||
|
}
|
||||||
|
while( mSerial->GetBitState() != BIT_HIGH )
|
||||||
|
{
|
||||||
|
mSerial->AdvanceToNextEdge(); // wait for rising
|
||||||
|
}
|
||||||
|
|
||||||
|
U32 data = 0;
|
||||||
|
U32 bitCtr = 1;
|
||||||
|
// measure cycletime
|
||||||
|
// start of bit
|
||||||
|
U64 SoB = mSerial->GetSampleNumber();
|
||||||
|
U64 starting_sample = SoB;
|
||||||
|
mSerial->AdvanceToNextEdge(); // falling edge
|
||||||
|
if( SamplesToNS( mSerial->GetSampleOfNextEdge() - SoB ) <= MAX_CYCLETIME )
|
||||||
|
{
|
||||||
|
mSerial->AdvanceToNextEdge(); // rising edge of second 0
|
||||||
|
cycleTime = SamplesToNS( mSerial->GetSampleNumber() - SoB );
|
||||||
SoB = mSerial->GetSampleNumber();
|
SoB = mSerial->GetSampleNumber();
|
||||||
starting_sample = SoB;
|
}
|
||||||
|
|
||||||
|
while( 1 )
|
||||||
|
{
|
||||||
|
mSerial->AdvanceToNextEdge(); // falling edge
|
||||||
|
// test if bits for one exist
|
||||||
|
if( mSerial->WouldAdvancingCauseTransition( NSToSamples( cycleTime / 2 ) ) )
|
||||||
|
{
|
||||||
|
// 1
|
||||||
|
data <<= 1;
|
||||||
|
data |= 1;
|
||||||
|
mSerial->AdvanceToNextEdge(); // rising edge of second pulse of 1
|
||||||
|
mSerial->AdvanceToNextEdge(); // falling edge of second pulse of 1
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 0
|
||||||
|
data <<= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !mSerial->WouldAdvancingCauseTransition( NSToSamples( 8 * cycleTime ) ) )
|
||||||
|
{
|
||||||
|
Frame frame;
|
||||||
|
frame.mData1 = data;
|
||||||
|
frame.mFlags = 0;
|
||||||
|
frame.mStartingSampleInclusive = starting_sample;
|
||||||
|
frame.mEndingSampleInclusive = mSerial->GetSampleNumber();
|
||||||
|
mResults->AddFrame( frame );
|
||||||
|
ReportProgress( frame.mEndingSampleInclusive );
|
||||||
|
|
||||||
|
FrameV2 framev2;
|
||||||
|
framev2.AddInteger( "data", frame.mData1 );
|
||||||
|
framev2.AddInteger( "cycletime", cycleTime );
|
||||||
|
mResults->AddFrameV2( framev2, "ledData", frame.mStartingSampleInclusive, frame.mEndingSampleInclusive );
|
||||||
|
mResults->CommitResults();
|
||||||
|
|
||||||
|
mSerial->Advance( NSToSamples( 8 * cycleTime ) );
|
||||||
|
|
||||||
|
if( !mSerial->DoMoreTransitionsExistInCurrentData() )
|
||||||
|
{
|
||||||
|
run = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if( SamplesToNS( mSerial->GetSampleOfNextEdge() - SoB ) < cycleTime * 2 )
|
||||||
|
{
|
||||||
|
mSerial->AdvanceToNextEdge(); // rising edge of next bit
|
||||||
|
SoB = mSerial->GetSampleNumber();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if( SamplesToNS( mSerial->GetSampleOfNextEdge() - SoB ) < cycleTime * 5.5 )
|
||||||
|
// ||
|
||||||
|
// SamplesToNS( mSerial->GetSampleOfNextEdge() - SoB ) > cycleTime * 8 )
|
||||||
|
{
|
||||||
|
// EOS end of sequence
|
||||||
|
Frame frame;
|
||||||
|
frame.mData1 = data;
|
||||||
|
frame.mFlags = 0;
|
||||||
|
frame.mStartingSampleInclusive = starting_sample;
|
||||||
|
frame.mEndingSampleInclusive = mSerial->GetSampleNumber();
|
||||||
|
mResults->AddFrame( frame );
|
||||||
|
ReportProgress( frame.mEndingSampleInclusive );
|
||||||
|
|
||||||
|
FrameV2 framev2;
|
||||||
|
framev2.AddInteger( "data", frame.mData1 );
|
||||||
|
framev2.AddInteger( "cycletime", cycleTime );
|
||||||
|
mResults->AddFrameV2( framev2, "ledData", frame.mStartingSampleInclusive, frame.mEndingSampleInclusive );
|
||||||
|
mResults->CommitResults();
|
||||||
|
|
||||||
|
data = 0;
|
||||||
|
mSerial->AdvanceToNextEdge();
|
||||||
|
SoB = mSerial->GetSampleNumber();
|
||||||
|
starting_sample = SoB;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 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 ) );
|
|
||||||
|
|
||||||
// bool firstRun = 1;
|
|
||||||
// U64 startEdge, starting_sample;
|
|
||||||
// U8 bits = 0;
|
|
||||||
|
|
||||||
// while( 1 )
|
|
||||||
// {
|
|
||||||
// if( firstRun )
|
|
||||||
// {
|
|
||||||
// startEdge = mSerial->GetSampleNumber();
|
|
||||||
// starting_sample = startEdge;
|
|
||||||
// mSerial->AdvanceToNextEdge(); // falling edge
|
|
||||||
// cycleTime = SamplesToNS( mSerial->GetSampleOfNextEdge() - startEdge );
|
|
||||||
// firstRun = false;
|
|
||||||
// bits = 1;
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// }
|
|
||||||
// U32 data = 0;
|
|
||||||
// U8 bits = 2;
|
|
||||||
// mSerial->AdvanceToNextEdge(); // rising edge
|
|
||||||
// startEdge = mSerial->GetSampleNumber();
|
|
||||||
// mSerial->AdvanceToNextEdge(); // falling edge // second zero
|
|
||||||
|
|
||||||
// while( 1 )
|
|
||||||
// {
|
|
||||||
// if( SamplesToNS( mSerial->GetSampleOfNextEdge() - startEdge ) < cycleTime / 2 )
|
|
||||||
// {
|
|
||||||
// // one
|
|
||||||
// data <<= 1;
|
|
||||||
// data |= 1;
|
|
||||||
// bits += 1;
|
|
||||||
// mResults->AddMarker( startEdge, AnalyzerResults::One, mSettings.mInputChannel );
|
|
||||||
// }
|
|
||||||
// else if( SamplesToNS( mSerial->GetSampleOfNextEdge() - startEdge ) < cycleTime * 2 )
|
|
||||||
// {
|
|
||||||
// // zero
|
|
||||||
// data <<= 1;
|
|
||||||
// bits += 1;
|
|
||||||
// mResults->AddMarker( startEdge, AnalyzerResults::Zero, mSettings.mInputChannel );
|
|
||||||
// }
|
|
||||||
// else if( SamplesToNS( mSerial->GetSampleOfNextEdge() - startEdge ) < cycleTime * 5.5 )
|
|
||||||
// {
|
|
||||||
// }
|
|
||||||
// else if( SamplesToNS( mSerial->GetSampleOfNextEdge() - startEdge ) > cycleTime * 8 )
|
|
||||||
// {
|
|
||||||
// // cleanup
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if( bits == 32 )
|
|
||||||
// {
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// mSerial->AdvanceToNextEdge(); // rising edge
|
|
||||||
// startEdge = mSerial->GetSampleOfNextEdge();
|
|
||||||
// mSerial->AdvanceToNextEdge(); // falling edge
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// Frame frame;
|
|
||||||
// frame.mData1 = data;
|
|
||||||
// frame.mFlags = 0;
|
|
||||||
// frame.mStartingSampleInclusive = starting_sample;
|
|
||||||
// frame.mEndingSampleInclusive = mSerial->GetSampleNumber();
|
|
||||||
|
|
||||||
// mResults->AddFrame( frame );
|
|
||||||
// mResults->CommitResults();
|
|
||||||
// ReportProgress( frame.mEndingSampleInclusive );
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 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 TLC59731Analyzer::NeedsRerun()
|
bool TLC59731Analyzer::NeedsRerun()
|
||||||
|
|||||||
@@ -14,38 +14,44 @@
|
|||||||
|
|
||||||
class ANALYZER_EXPORT TLC59731Analyzer : public Analyzer2
|
class ANALYZER_EXPORT TLC59731Analyzer : public Analyzer2
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TLC59731Analyzer();
|
TLC59731Analyzer();
|
||||||
virtual ~TLC59731Analyzer();
|
virtual ~TLC59731Analyzer();
|
||||||
|
|
||||||
virtual void SetupResults();
|
virtual void SetupResults();
|
||||||
virtual void WorkerThread();
|
virtual void WorkerThread();
|
||||||
|
|
||||||
virtual U32 GenerateSimulationData( U64 newest_sample_requested, U32 sample_rate, SimulationChannelDescriptor** simulation_channels );
|
virtual U32 GenerateSimulationData( U64 newest_sample_requested, U32 sample_rate, SimulationChannelDescriptor** simulation_channels );
|
||||||
virtual U32 GetMinimumSampleRateHz();
|
virtual U32 GetMinimumSampleRateHz();
|
||||||
|
|
||||||
virtual const char* GetAnalyzerName() const;
|
virtual const char* GetAnalyzerName() const;
|
||||||
virtual bool NeedsRerun();
|
virtual bool NeedsRerun();
|
||||||
U64 SamplesToNS(U64 samples) { return (samples * 1000000000) / mSampleRateHz; }
|
U64 SamplesToNS( U64 samples )
|
||||||
|
{
|
||||||
|
return ( samples * 1000000000 ) / mSampleRateHz;
|
||||||
|
}
|
||||||
|
U32 NSToSamples( U64 time )
|
||||||
|
{
|
||||||
|
return ( time * mSampleRateHz ) / 1000000000;
|
||||||
|
}
|
||||||
|
|
||||||
protected: //vars
|
protected: // vars
|
||||||
TLC59731AnalyzerSettings mSettings;
|
TLC59731AnalyzerSettings mSettings;
|
||||||
std::unique_ptr<TLC59731AnalyzerResults> mResults;
|
std::unique_ptr<TLC59731AnalyzerResults> mResults;
|
||||||
AnalyzerChannelData* mSerial;
|
AnalyzerChannelData* mSerial;
|
||||||
|
|
||||||
TLC59731SimulationDataGenerator mSimulationDataGenerator;
|
TLC59731SimulationDataGenerator mSimulationDataGenerator;
|
||||||
bool mSimulationInitilized;
|
bool mSimulationInitilized;
|
||||||
|
|
||||||
//Serial analysis vars:
|
|
||||||
U32 mSampleRateHz;
|
|
||||||
U64 cycleTime;
|
|
||||||
U32 mStartOfStopBitOffset;
|
|
||||||
U32 mEndOfStopBitOffset;
|
|
||||||
|
|
||||||
|
// Serial analysis vars:
|
||||||
|
U32 mSampleRateHz;
|
||||||
|
U64 cycleTime;
|
||||||
|
U32 mStartOfStopBitOffset;
|
||||||
|
U32 mEndOfStopBitOffset;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern "C" ANALYZER_EXPORT const char* __cdecl GetAnalyzerName();
|
extern "C" ANALYZER_EXPORT const char* __cdecl GetAnalyzerName();
|
||||||
extern "C" ANALYZER_EXPORT Analyzer* __cdecl CreateAnalyzer( );
|
extern "C" ANALYZER_EXPORT Analyzer* __cdecl CreateAnalyzer();
|
||||||
extern "C" ANALYZER_EXPORT void __cdecl DestroyAnalyzer( Analyzer* analyzer );
|
extern "C" ANALYZER_EXPORT void __cdecl DestroyAnalyzer( Analyzer* analyzer );
|
||||||
|
|
||||||
#endif //TLC59731_ANALYZER_H
|
#endif // TLC59731_ANALYZER_H
|
||||||
|
|||||||
Reference in New Issue
Block a user