From 0684e3afa4af660ccfc795d49015c3a468a1cb9c Mon Sep 17 00:00:00 2001 From: Marcus10110 Date: Wed, 31 Jul 2024 13:15:09 -0700 Subject: [PATCH 1/6] Step1: remove auto_ptr. (still need to fix access) --- docs/Analyzer_API.md | 4 ++-- src/SimpleSerialAnalyzer.h | 4 ++-- src/SimpleSerialAnalyzerSettings.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/Analyzer_API.md b/docs/Analyzer_API.md index 717fafc..fbb39e5 100644 --- a/docs/Analyzer_API.md +++ b/docs/Analyzer_API.md @@ -673,8 +673,8 @@ extern "C" ANALYZER_EXPORT void __cdecl DestroyAnalyzer( Analyzer* analyzer ); You’ll also need these member variables: ```c++ -std::auto_ptr< {YourName}AnalyzerSettings > mSettings; -std::auto_ptr< {YourName}AnalyzerResults > mResults; +{YourName}AnalyzerSettings mSettings; +{YourName}AnalyzerResults mResults; {YourName}SimulationDataGenerator mSimulationDataGenerator; bool mSimulationInitialized; ``` diff --git a/src/SimpleSerialAnalyzer.h b/src/SimpleSerialAnalyzer.h index 69ae85d..8eef32a 100644 --- a/src/SimpleSerialAnalyzer.h +++ b/src/SimpleSerialAnalyzer.h @@ -22,8 +22,8 @@ class ANALYZER_EXPORT SimpleSerialAnalyzer : public Analyzer2 virtual bool NeedsRerun(); protected: //vars - std::auto_ptr< SimpleSerialAnalyzerSettings > mSettings; - std::auto_ptr< SimpleSerialAnalyzerResults > mResults; + SimpleSerialAnalyzerSettings mSettings; + SimpleSerialAnalyzerResults mResults; AnalyzerChannelData* mSerial; SimpleSerialSimulationDataGenerator mSimulationDataGenerator; diff --git a/src/SimpleSerialAnalyzerSettings.h b/src/SimpleSerialAnalyzerSettings.h index 1b34136..2ac432e 100644 --- a/src/SimpleSerialAnalyzerSettings.h +++ b/src/SimpleSerialAnalyzerSettings.h @@ -20,8 +20,8 @@ class SimpleSerialAnalyzerSettings : public AnalyzerSettings U32 mBitRate; protected: - std::auto_ptr< AnalyzerSettingInterfaceChannel > mInputChannelInterface; - std::auto_ptr< AnalyzerSettingInterfaceInteger > mBitRateInterface; + AnalyzerSettingInterfaceChannel mInputChannelInterface; + AnalyzerSettingInterfaceInteger mBitRateInterface; }; #endif //SIMPLESERIAL_ANALYZER_SETTINGS From fa24236c78c35c5feb195f1bb411d6d6d86519f4 Mon Sep 17 00:00:00 2001 From: Marcus10110 Date: Wed, 31 Jul 2024 13:24:21 -0700 Subject: [PATCH 2/6] switch from using pointers to direct access. --- src/SimpleSerialAnalyzer.cpp | 28 ++++++++++++++------------ src/SimpleSerialAnalyzerSettings.cpp | 30 ++++++++++++++-------------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/SimpleSerialAnalyzer.cpp b/src/SimpleSerialAnalyzer.cpp index ff54965..e0ec1f3 100644 --- a/src/SimpleSerialAnalyzer.cpp +++ b/src/SimpleSerialAnalyzer.cpp @@ -4,10 +4,11 @@ SimpleSerialAnalyzer::SimpleSerialAnalyzer() : Analyzer2(), - mSettings( new SimpleSerialAnalyzerSettings() ), + mSettings(), + mResults(this, &mSettings), mSimulationInitilized( false ) { - SetAnalyzerSettings( mSettings.get() ); + SetAnalyzerSettings( &mSettings ); } SimpleSerialAnalyzer::~SimpleSerialAnalyzer() @@ -17,22 +18,23 @@ SimpleSerialAnalyzer::~SimpleSerialAnalyzer() void SimpleSerialAnalyzer::SetupResults() { - mResults.reset( new SimpleSerialAnalyzerResults( this, mSettings.get() ) ); - SetAnalyzerResults( mResults.get() ); - mResults->AddChannelBubblesWillAppearOn( mSettings->mInputChannel ); + // SetupResults is called each time the analyzer is run. Because the same instance can be used for multiple runs, we need to clear the results each time. + mResults = SimpleSerialAnalyzerResults( this, &mSettings ); + SetAnalyzerResults( &mResults ); + mResults.AddChannelBubblesWillAppearOn( mSettings.mInputChannel ); } void SimpleSerialAnalyzer::WorkerThread() { mSampleRateHz = GetSampleRate(); - mSerial = GetAnalyzerChannelData( mSettings->mInputChannel ); + 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 ) ); + 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( ; ; ) { @@ -48,7 +50,7 @@ void SimpleSerialAnalyzer::WorkerThread() 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 ); + mResults.AddMarker( mSerial->GetSampleNumber(), AnalyzerResults::Dot, mSettings.mInputChannel ); if( mSerial->GetBitState() == BIT_HIGH ) data |= mask; @@ -66,8 +68,8 @@ void SimpleSerialAnalyzer::WorkerThread() frame.mStartingSampleInclusive = starting_sample; frame.mEndingSampleInclusive = mSerial->GetSampleNumber(); - mResults->AddFrame( frame ); - mResults->CommitResults(); + mResults.AddFrame( frame ); + mResults.CommitResults(); ReportProgress( frame.mEndingSampleInclusive ); } } @@ -81,7 +83,7 @@ U32 SimpleSerialAnalyzer::GenerateSimulationData( U64 minimum_sample_index, U32 { if( mSimulationInitilized == false ) { - mSimulationDataGenerator.Initialize( GetSimulationSampleRate(), mSettings.get() ); + mSimulationDataGenerator.Initialize( GetSimulationSampleRate(), &mSettings ); mSimulationInitilized = true; } @@ -90,7 +92,7 @@ U32 SimpleSerialAnalyzer::GenerateSimulationData( U64 minimum_sample_index, U32 U32 SimpleSerialAnalyzer::GetMinimumSampleRateHz() { - return mSettings->mBitRate * 4; + return mSettings.mBitRate * 4; } const char* SimpleSerialAnalyzer::GetAnalyzerName() const diff --git a/src/SimpleSerialAnalyzerSettings.cpp b/src/SimpleSerialAnalyzerSettings.cpp index 174dc7d..372738f 100644 --- a/src/SimpleSerialAnalyzerSettings.cpp +++ b/src/SimpleSerialAnalyzerSettings.cpp @@ -4,20 +4,20 @@ SimpleSerialAnalyzerSettings::SimpleSerialAnalyzerSettings() : mInputChannel( UNDEFINED_CHANNEL ), - mBitRate( 9600 ) + mBitRate( 9600 ), + mInputChannelInterface(), + mBitRateInterface() { - mInputChannelInterface.reset( new AnalyzerSettingInterfaceChannel() ); - mInputChannelInterface->SetTitleAndTooltip( "Serial", "Standard Simple Serial" ); - mInputChannelInterface->SetChannel( mInputChannel ); + mInputChannelInterface.SetTitleAndTooltip( "Serial", "Standard Simple Serial" ); + mInputChannelInterface.SetChannel( mInputChannel ); - mBitRateInterface.reset( new AnalyzerSettingInterfaceInteger() ); - mBitRateInterface->SetTitleAndTooltip( "Bit Rate (Bits/S)", "Specify the bit rate in bits per second." ); - mBitRateInterface->SetMax( 6000000 ); - mBitRateInterface->SetMin( 1 ); - mBitRateInterface->SetInteger( mBitRate ); + mBitRateInterface.SetTitleAndTooltip( "Bit Rate (Bits/S)", "Specify the bit rate in bits per second." ); + mBitRateInterface.SetMax( 6000000 ); + mBitRateInterface.SetMin( 1 ); + mBitRateInterface.SetInteger( mBitRate ); - AddInterface( mInputChannelInterface.get() ); - AddInterface( mBitRateInterface.get() ); + AddInterface( &mInputChannelInterface ); + AddInterface( &mBitRateInterface ); AddExportOption( 0, "Export as text/csv file" ); AddExportExtension( 0, "text", "txt" ); @@ -33,8 +33,8 @@ SimpleSerialAnalyzerSettings::~SimpleSerialAnalyzerSettings() bool SimpleSerialAnalyzerSettings::SetSettingsFromInterfaces() { - mInputChannel = mInputChannelInterface->GetChannel(); - mBitRate = mBitRateInterface->GetInteger(); + mInputChannel = mInputChannelInterface.GetChannel(); + mBitRate = mBitRateInterface.GetInteger(); ClearChannels(); AddChannel( mInputChannel, "Simple Serial", true ); @@ -44,8 +44,8 @@ bool SimpleSerialAnalyzerSettings::SetSettingsFromInterfaces() void SimpleSerialAnalyzerSettings::UpdateInterfacesFromSettings() { - mInputChannelInterface->SetChannel( mInputChannel ); - mBitRateInterface->SetInteger( mBitRate ); + mInputChannelInterface.SetChannel( mInputChannel ); + mBitRateInterface.SetInteger( mBitRate ); } void SimpleSerialAnalyzerSettings::LoadSettings( const char* settings ) From 70129049001c67beab822eaf474dcbd164270798 Mon Sep 17 00:00:00 2001 From: Marcus10110 Date: Wed, 31 Jul 2024 13:24:32 -0700 Subject: [PATCH 3/6] update API docs. --- docs/Analyzer_API.md | 64 ++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 35 deletions(-) diff --git a/docs/Analyzer_API.md b/docs/Analyzer_API.md index fbb39e5..ad1a774 100644 --- a/docs/Analyzer_API.md +++ b/docs/Analyzer_API.md @@ -172,8 +172,6 @@ One of the services the Analyzer SDK provides is a means for users to edit your - ```AnalyzerSettingInterfaceText``` - Allows a user to enter some text into a textbox. - ```AnalyzerSettingInterfaceBool``` - Provides the user with a checkbox. -```AnalyzerSettingsInterface``` types should be declared as pointers. We’re using the ```std::auto_ptr``` type, which largely acts like a standard (raw) pointer. It’s a simple form of what’s called a “smart pointer” and it automatically calls ```delete``` on its contents when it goes out of scope. - ## {YourName}AnalyzerSettings.cpp ### The Constructor @@ -182,15 +180,10 @@ First, initialize all your settings variables to their default values. Second, ### Setting up each AnalyzerSettingInterface object -First, we create the object (call new) and assign the value to the interface’s pointer. Note that we’re using ```std::auto_ptr```, so this means calling the member function ```reset()```. For standard (raw pointers), you would do something like: -```c++ -mInputChannelInterface = new AnalyzerSettingInterfaceChannel(); -``` - -Next, we call the member function ```SetTitleAndTooltip()```. The title will appear to the left of the input element. Note that often times you won’t need a title, but you should use one for ```Channels```. The tooltip shows up when hovering over the input element. +Ee call the member function ```SetTitleAndTooltip()```. The title will appear to the left of the input element. Note that often times you won’t need a title, but you should use one for ```Channels```. The tooltip shows up when hovering over the input element. ```c++ void SetTitleAndTooltip( const char* title, const char* tooltip ); -mInputChannelInterface->SetTitleAndTooltip( "Serial", "Standard Async Serial" ); +mInputChannelInterface.SetTitleAndTooltip( "Serial", "Standard Async Serial" ); ``` Finally, We’ll want to set the value. The interface object is, well, an interface to our settings variables. When setting up the interface, we copy the value from our settings variable to the interface. When the user makes a change, we copy the value in the interface to our settings variable. The function names for this differ depending on the type of interface. ```c++ @@ -292,7 +285,7 @@ After assigning the interface values to your settings variables, you also need t ```c++ bool SimpleSerialAnalyzerSettings::SetSettingsFromInterfaces() { - mInputChannel = mInputChannelInterface->GetChannel(); + mInputChannel = mInputChannelInterface.GetChannel(); mBitRate = mBitRateInterface->GetInteger(); ClearChannels(); AddChannel( mInputChannel, "Simple Serial", true ); @@ -307,7 +300,7 @@ bool SimpleSerialAnalyzerSettings::SetSettingsFromInterfaces() ```c++ void SimpleSerialAnalyzerSettings::UpdateInterfacesFromSettings() { - mInputChannelInterface->SetChannel( mInputChannel ); + mInputChannelInterface.SetChannel( mInputChannel ); mBitRateInterface->SetInteger( mBitRate ); } ``` @@ -692,13 +685,14 @@ Your constructor will look something like this ```c++ {YourName}Analyzer::{YourName}Analyzer() : Analyzer(), -mSettings( new {YourName}AnalyzerSettings() ), +mSettings(), +mResults(this, &mSettings), mSimulationInitialized( false ) { -SetAnalyzerSettings( mSettings.get() ); +SetAnalyzerSettings( &mSettings ); } ``` -Note that here you’re calling the base class constructor, ```new()```'ing your ```AnalyzerSettings``` derived class, and providing the base class with a pointer to your ```AnalyzerSettings``` - derived object. +Note that here you’re calling the base class constructor and providing the base class with a pointer to your ```AnalyzerSettings``` - derived object. ## Destructor This only thing your destructor must do is call ```KillThread```. This is a base class member function and will make sure your class destructs in the right order. @@ -727,7 +721,7 @@ U32 {YourName}Analyzer::GenerateSimulationData( U64 minimum_sample_index, U32 de { if( mSimulationInitialized == false ) { - mSimulationDataGenerator.Initialize( GetSimulationSampleRate(), mSettings.get() ); + mSimulationDataGenerator.Initialize( GetSimulationSampleRate(), &mSettings ); mSimulationInitialized = true; } return mSimulationDataGenerator.GenerateSimulationData( minimum_sample_index, device_sample_rate, simulation_channels ); @@ -740,7 +734,7 @@ This function is called to see if the user’s selected sample rate is sufficien ```c++ U32 SerialAnalyzer::GetMinimumSampleRateHz() { - return mSettings->mBitRate * 4; + return mSettings.mBitRate * 4; } ``` @@ -769,17 +763,17 @@ delete analyzer; ``` ## ```{YourName}Analyzer::WorkerThread()``` -Ok, now that everything else is taken care of, let’s look at the most important part of the analyzer in detail. First, we’ll ```new``` our ```AnalyzerResults``` derived object. +Ok, now that everything else is taken care of, let’s look at the most important part of the analyzer in detail. First, we’ll reset our ```AnalyzerResults``` derived object. This is because your analyzer class instance may be re-used for multiple runs, so at the beginning of each run, the generated results must be reset. ```c++ -mResults.reset( new {YourName}AnalyzerResults( this, mSettings.get() ) ); +mResults = {YourName}AnalyzerResults( this, &mSettings ); ``` Well provide a pointer to our results to the base class: ```c++ -SetAnalyzerResults( mResults.get() ); +SetAnalyzerResults( &mResults ); ``` Let’s indicate which channels we’ll be displaying results on (in the form of bubbles). Usually this will only be one channel. (Except in the case of SPI, where we’ll want to put bubbles on both the MISO and MISO lines.) Only indicate where we will display bubbles – other markup, like tick marks, arrows, etc, are not bubbles, and should not be reported here. ```c++ -mResults->AddChannelBubblesWillAppearOn( mSettings->mInputChannel ); +mResults.AddChannelBubblesWillAppearOn( mSettings.mInputChannel ); ``` We’ll probably want to know (and save in a member variable) the sample rate. ```c++ @@ -787,7 +781,7 @@ mSampleRateHz = GetSampleRate(); ``` Now we need to get access to the data itself. We’ll need to get pointers to ```AnalyzerChannelData``` objects for each channel we’ll need data from. For Serial, we’ll just need one. For SPI, we might need 4. Etc. ```c++ -mSerial = GetAnalyzerChannelData( mSettings->mInputChannel ); +mSerial = GetAnalyzerChannelData( mSettings.mInputChannel ); ``` # Traversing the Data @@ -868,8 +862,8 @@ if( such_and_such_error == true ) frame.mFlags |= SUCH_AND_SUCH_ERROR_FLAG | DISPLAY_AS_ERROR_FLAG; if( such_and_such_warning == true ) frame.mFlags |= SUCH_AND_SUCH_WARNING_FLAG | DISPLAY_AS_WARNING_FLAG; -mResults->AddFrame( frame ); -mResults->CommitResults(); +mResults.AddFrame( frame ); +mResults.CommitResults(); ReportProgress( frame.mEndingSampleInclusive ); ``` @@ -892,7 +886,7 @@ void AddMarker( U64 sample_number, MarkerType marker_type, Channel& channel ); ``` For example, from ```SerialAnalyzer.cpp``` : ```c++ -mResults->AddMarker( marker_location, AnalyzerResults::Dot, mSettings->mInputChannel ); +mResults.AddMarker( marker_location, AnalyzerResults::Dot, mSettings.mInputChannel ); ``` Currently, the available graphical artifacts are @@ -1135,7 +1129,7 @@ SimpleSerialAnalyzerSettings* settings ) { mSimulationSampleRateHz = simulation_sample_rate; mSettings = settings; - mSerialSimulationData.SetChannel( mSettings->mInputChannel ); + mSerialSimulationData.SetChannel( mSettings.mInputChannel ); mSerialSimulationData.SetSampleRate( simulation_sample_rate ); mSerialSimulationData.SetInitialBitState( BIT_HIGH ); } @@ -1179,7 +1173,7 @@ simulation_channel ) } void SimpleSerialSimulationDataGenerator::CreateSerialByte() { - U32 samples_per_bit = mSimulationSampleRateHz / mSettings->mBitRate; + U32 samples_per_bit = mSimulationSampleRateHz / mSettings.mBitRate; U8 byte = mSerialText[ mStringIndex ]; mStringIndex++; if( mStringIndex == mSerialText.size() ) @@ -1254,22 +1248,22 @@ void SerialSimulationDataGenerator::CreateSerialByte( U64 value ) // assume we start high mSerialSimulationData.Transition(); // low-going edge for start bit mSerialSimulationData.Advance( mClockGenerator.AdvanceByHalfPeriod() ); // add - start bit time if( mSettings->mInverted == true ) value = ~value; - U32 num_bits = mSettings->mBitsPerTransfer; - BitExtractor bit_extractor( value, mSettings->mShiftOrder, num_bits ); + start bit time if( mSettings.mInverted == true ) value = ~value; + U32 num_bits = mSettings.mBitsPerTransfer; + BitExtractor bit_extractor( value, mSettings.mShiftOrder, num_bits ); for( U32 i = 0; i < num_bits; i++ ) { mSerialSimulationData.TransitionIfNeeded( bit_extractor.GetNextBit() ); mSerialSimulationData.Advance( mClockGenerator.AdvanceByHalfPeriod() ); } - if( mSettings->mParity == AnalyzerEnums::Even ) + if( mSettings.mParity == AnalyzerEnums::Even ) { if( AnalyzerHelpers::IsEven( AnalyzerHelpers::GetOnesCount( value ) ) == true ) mSerialSimulationData.TransitionIfNeeded( mBitLow ); // we want to add a zero bit else mSerialSimulationData.TransitionIfNeeded( mBitHigh ); // we want to add a one bit mSerialSimulationData.Advance( mClockGenerator.AdvanceByHalfPeriod() ); } - else if( mSettings->mParity == AnalyzerEnums::Odd ) + else if( mSettings.mParity == AnalyzerEnums::Odd ) { if( AnalyzerHelpers::IsOdd( AnalyzerHelpers::GetOnesCount( value ) ) == true ) mSerialSimulationData.TransitionIfNeeded( mBitLow ); // we want to @@ -1355,9 +1349,9 @@ U32 I2cSimulationDataGenerator::GenerateSimulationData( U64 largest_sample_reque ```c++ void SpiSimulationDataGenerator::OutputWord_CPHA1( U64 mosi_data, U64 miso_data ) { - BitExtractor mosi_bits( mosi_data, mSettings->mShiftOrder, mSettings - > mBitsPerTransfer ); - BitExtractor miso_bits( miso_data, mSettings->mShiftOrder, mSettings - > mBitsPerTransfer ); - U32 count = mSettings->mBitsPerTransfer; + BitExtractor mosi_bits( mosi_data, mSettings.mShiftOrder, mSettings - > mBitsPerTransfer ); + BitExtractor miso_bits( miso_data, mSettings.mShiftOrder, mSettings - > mBitsPerTransfer ); + U32 count = mSettings.mBitsPerTransfer; for( U32 i = 0; i < count; i++ ) { mClock->Transition(); // data invalid @@ -1381,7 +1375,7 @@ void SpiSimulationDataGenerator::CreateSpiTransaction() if( mEnable != NULL ) mEnable->Transition(); mSpiSimulationChannels.AdvanceAll( mClockGenerator.AdvanceByHalfPeriod( 2.0 ) ); - if( mSettings->mDataValidEdge == AnalyzerEnums::LeadingEdge ) + if( mSettings.mDataValidEdge == AnalyzerEnums::LeadingEdge ) { OutputWord_CPHA0( mValue, mValue + 1 ); mValue++; From 9a0511d7f28d2365137930098036efb9c66b34cf Mon Sep 17 00:00:00 2001 From: Marcus10110 Date: Wed, 31 Jul 2024 13:29:50 -0700 Subject: [PATCH 4/6] added missing include and removed forward declare, now that we're not using pointers for analyzer settings. --- src/SimpleSerialAnalyzer.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/SimpleSerialAnalyzer.h b/src/SimpleSerialAnalyzer.h index 8eef32a..43318bd 100644 --- a/src/SimpleSerialAnalyzer.h +++ b/src/SimpleSerialAnalyzer.h @@ -2,10 +2,9 @@ #define SIMPLESERIAL_ANALYZER_H #include +#include "SimpleSerialAnalyzerSettings.h" #include "SimpleSerialAnalyzerResults.h" #include "SimpleSerialSimulationDataGenerator.h" - -class SimpleSerialAnalyzerSettings; class ANALYZER_EXPORT SimpleSerialAnalyzer : public Analyzer2 { public: From 432743b06075192866145b68a7be5ea136f05ea5 Mon Sep 17 00:00:00 2001 From: Marcus10110 Date: Wed, 31 Jul 2024 13:57:47 -0700 Subject: [PATCH 5/6] switched mResults over to a unique_ptr, because resetting the class directly with the default assignment operator broke its mutexes. --- docs/Analyzer_API.md | 15 +++++++-------- src/SimpleSerialAnalyzer.cpp | 13 ++++++------- src/SimpleSerialAnalyzer.h | 4 +++- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/Analyzer_API.md b/docs/Analyzer_API.md index ad1a774..30b4231 100644 --- a/docs/Analyzer_API.md +++ b/docs/Analyzer_API.md @@ -667,7 +667,7 @@ extern "C" ANALYZER_EXPORT void __cdecl DestroyAnalyzer( Analyzer* analyzer ); You’ll also need these member variables: ```c++ {YourName}AnalyzerSettings mSettings; -{YourName}AnalyzerResults mResults; +std::unique_ptr<{YourName}AnalyzerResults> mResults; {YourName}SimulationDataGenerator mSimulationDataGenerator; bool mSimulationInitialized; ``` @@ -686,7 +686,6 @@ Your constructor will look something like this {YourName}Analyzer::{YourName}Analyzer() : Analyzer(), mSettings(), -mResults(this, &mSettings), mSimulationInitialized( false ) { SetAnalyzerSettings( &mSettings ); @@ -765,15 +764,15 @@ delete analyzer; ## ```{YourName}Analyzer::WorkerThread()``` Ok, now that everything else is taken care of, let’s look at the most important part of the analyzer in detail. First, we’ll reset our ```AnalyzerResults``` derived object. This is because your analyzer class instance may be re-used for multiple runs, so at the beginning of each run, the generated results must be reset. ```c++ -mResults = {YourName}AnalyzerResults( this, &mSettings ); +mResults.reset( new {YourName}AnalyzerResults( this, &mSettings ) ); ``` Well provide a pointer to our results to the base class: ```c++ -SetAnalyzerResults( &mResults ); +SetAnalyzerResults( mResults.get() ); ``` Let’s indicate which channels we’ll be displaying results on (in the form of bubbles). Usually this will only be one channel. (Except in the case of SPI, where we’ll want to put bubbles on both the MISO and MISO lines.) Only indicate where we will display bubbles – other markup, like tick marks, arrows, etc, are not bubbles, and should not be reported here. ```c++ -mResults.AddChannelBubblesWillAppearOn( mSettings.mInputChannel ); +mResults->AddChannelBubblesWillAppearOn( mSettings.mInputChannel ); ``` We’ll probably want to know (and save in a member variable) the sample rate. ```c++ @@ -862,8 +861,8 @@ if( such_and_such_error == true ) frame.mFlags |= SUCH_AND_SUCH_ERROR_FLAG | DISPLAY_AS_ERROR_FLAG; if( such_and_such_warning == true ) frame.mFlags |= SUCH_AND_SUCH_WARNING_FLAG | DISPLAY_AS_WARNING_FLAG; -mResults.AddFrame( frame ); -mResults.CommitResults(); +mResults->AddFrame( frame ); +mResults->CommitResults(); ReportProgress( frame.mEndingSampleInclusive ); ``` @@ -886,7 +885,7 @@ void AddMarker( U64 sample_number, MarkerType marker_type, Channel& channel ); ``` For example, from ```SerialAnalyzer.cpp``` : ```c++ -mResults.AddMarker( marker_location, AnalyzerResults::Dot, mSettings.mInputChannel ); +mResults->AddMarker( marker_location, AnalyzerResults::Dot, mSettings.mInputChannel ); ``` Currently, the available graphical artifacts are diff --git a/src/SimpleSerialAnalyzer.cpp b/src/SimpleSerialAnalyzer.cpp index e0ec1f3..ef44917 100644 --- a/src/SimpleSerialAnalyzer.cpp +++ b/src/SimpleSerialAnalyzer.cpp @@ -5,7 +5,6 @@ SimpleSerialAnalyzer::SimpleSerialAnalyzer() : Analyzer2(), mSettings(), - mResults(this, &mSettings), mSimulationInitilized( false ) { SetAnalyzerSettings( &mSettings ); @@ -19,9 +18,9 @@ SimpleSerialAnalyzer::~SimpleSerialAnalyzer() void SimpleSerialAnalyzer::SetupResults() { // SetupResults is called each time the analyzer is run. Because the same instance can be used for multiple runs, we need to clear the results each time. - mResults = SimpleSerialAnalyzerResults( this, &mSettings ); - SetAnalyzerResults( &mResults ); - mResults.AddChannelBubblesWillAppearOn( mSettings.mInputChannel ); + mResults.reset(new SimpleSerialAnalyzerResults( this, &mSettings )); + SetAnalyzerResults( mResults.get() ); + mResults->AddChannelBubblesWillAppearOn( mSettings.mInputChannel ); } void SimpleSerialAnalyzer::WorkerThread() @@ -50,7 +49,7 @@ void SimpleSerialAnalyzer::WorkerThread() 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 ); + mResults->AddMarker( mSerial->GetSampleNumber(), AnalyzerResults::Dot, mSettings.mInputChannel ); if( mSerial->GetBitState() == BIT_HIGH ) data |= mask; @@ -68,8 +67,8 @@ void SimpleSerialAnalyzer::WorkerThread() frame.mStartingSampleInclusive = starting_sample; frame.mEndingSampleInclusive = mSerial->GetSampleNumber(); - mResults.AddFrame( frame ); - mResults.CommitResults(); + mResults->AddFrame( frame ); + mResults->CommitResults(); ReportProgress( frame.mEndingSampleInclusive ); } } diff --git a/src/SimpleSerialAnalyzer.h b/src/SimpleSerialAnalyzer.h index 43318bd..15ee87d 100644 --- a/src/SimpleSerialAnalyzer.h +++ b/src/SimpleSerialAnalyzer.h @@ -5,6 +5,8 @@ #include "SimpleSerialAnalyzerSettings.h" #include "SimpleSerialAnalyzerResults.h" #include "SimpleSerialSimulationDataGenerator.h" +#include + class ANALYZER_EXPORT SimpleSerialAnalyzer : public Analyzer2 { public: @@ -22,7 +24,7 @@ class ANALYZER_EXPORT SimpleSerialAnalyzer : public Analyzer2 protected: //vars SimpleSerialAnalyzerSettings mSettings; - SimpleSerialAnalyzerResults mResults; + std::unique_ptr mResults; AnalyzerChannelData* mSerial; SimpleSerialSimulationDataGenerator mSimulationDataGenerator; From 371bdf451518d0b3ad38d30c6f0ccb658d4a40c9 Mon Sep 17 00:00:00 2001 From: Marcus10110 Date: Wed, 31 Jul 2024 14:04:00 -0700 Subject: [PATCH 6/6] fix minor typo in API docs. --- docs/Analyzer_API.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Analyzer_API.md b/docs/Analyzer_API.md index 30b4231..fcb4fce 100644 --- a/docs/Analyzer_API.md +++ b/docs/Analyzer_API.md @@ -180,7 +180,7 @@ First, initialize all your settings variables to their default values. Second, ### Setting up each AnalyzerSettingInterface object -Ee call the member function ```SetTitleAndTooltip()```. The title will appear to the left of the input element. Note that often times you won’t need a title, but you should use one for ```Channels```. The tooltip shows up when hovering over the input element. +First, call the member function ```SetTitleAndTooltip()```. The title will appear to the left of the input element. Note that often times you won’t need a title, but you should use one for ```Channels```. The tooltip shows up when hovering over the input element. ```c++ void SetTitleAndTooltip( const char* title, const char* tooltip ); mInputChannelInterface.SetTitleAndTooltip( "Serial", "Standard Async Serial" );