diff --git a/CMakeLists.txt b/CMakeLists.txt index 41c3110..0ba8e57 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,14 +14,14 @@ set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) include(ExternalAnalyzerSDK) set(SOURCES -src/SerialAnalyzer.cpp -src/SerialAnalyzer.h -src/SerialAnalyzerResults.cpp -src/SerialAnalyzerResults.h -src/SerialAnalyzerSettings.cpp -src/SerialAnalyzerSettings.h -src/SerialSimulationDataGenerator.cpp -src/SerialSimulationDataGenerator.h +src/MySerialAnalyzer.cpp +src/MySerialAnalyzer.h +src/MySerialAnalyzerResults.cpp +src/MySerialAnalyzerResults.h +src/MySerialAnalyzerSettings.cpp +src/MySerialAnalyzerSettings.h +src/MySerialSimulationDataGenerator.cpp +src/MySerialSimulationDataGenerator.h ) add_analyzer_plugin(serial_analyzer SOURCES ${SOURCES}) diff --git a/README.md b/README.md index fadcab7..be56f4b 100644 --- a/README.md +++ b/README.md @@ -127,3 +127,8 @@ For debug and release builds, respectively. A single serial word +## Bitrate change setting +Sometimes you capture an async signal where the bitrate changes according to certain parameters: for instance a handshake can determine what maximum speed can be used, and then this speed is applied. The 'Bitrate change' field can be used to instruct the analyser to change bitrate at different times in the capture data. + +The format of this field is any number of time:bitrate, separated by spaces. For instance if the field contains `0:9600 1.568:115200` it means the beginning of the capture will use 9600 bits/s, and starting at 1.568s, it changes to 115200 bits/s. +The change will be made at any edge after the entered time; a small X marker will be added to this edge to witness the change. diff --git a/src/SerialAnalyzer.cpp b/src/MySerialAnalyzer.cpp similarity index 82% rename from src/SerialAnalyzer.cpp rename to src/MySerialAnalyzer.cpp index 61bf5ce..af65f8e 100644 --- a/src/SerialAnalyzer.cpp +++ b/src/MySerialAnalyzer.cpp @@ -1,20 +1,21 @@ -#include "SerialAnalyzer.h" -#include "SerialAnalyzerSettings.h" +#include "MySerialAnalyzer.h" +#include "MySerialAnalyzerSettings.h" #include +#include +#include - -SerialAnalyzer::SerialAnalyzer() : Analyzer2(), mSettings( new SerialAnalyzerSettings() ), mSimulationInitilized( false ) +MySerialAnalyzer::MySerialAnalyzer() : Analyzer2(), mSettings( new MySerialAnalyzerSettings() ), mSimulationInitilized( false ) { SetAnalyzerSettings( mSettings.get() ); UseFrameV2(); } -SerialAnalyzer::~SerialAnalyzer() +MySerialAnalyzer::~MySerialAnalyzer() { KillThread(); } -void SerialAnalyzer::ComputeSampleOffsets() +void MySerialAnalyzer::ComputeSampleOffsets() { ClockGenerator clock_generator; clock_generator.Init( mSettings->mBitRate, mSampleRateHz ); @@ -23,7 +24,7 @@ void SerialAnalyzer::ComputeSampleOffsets() U32 num_bits = mSettings->mBitsPerTransfer; - if( mSettings->mSerialMode != SerialAnalyzerEnums::Normal ) + if( mSettings->mSerialMode != MySerialAnalyzerEnums::Normal ) num_bits++; mSampleOffsets.push_back( clock_generator.AdvanceByHalfPeriod( 1.5 ) ); // point to the center of the 1st bit (past the start bit) @@ -47,24 +48,24 @@ void SerialAnalyzer::ComputeSampleOffsets() } -void SerialAnalyzer::SetupResults() +void MySerialAnalyzer::SetupResults() { // Unlike the worker thread, this function is called from the GUI thread // we need to reset the Results object here because it is exposed for direct access by the GUI, and it can't be deleted from the // WorkerThread - mResults.reset( new SerialAnalyzerResults( this, mSettings.get() ) ); + mResults.reset( new MySerialAnalyzerResults( this, mSettings.get() ) ); SetAnalyzerResults( mResults.get() ); mResults->AddChannelBubblesWillAppearOn( mSettings->mInputChannel ); } -void SerialAnalyzer::WorkerThread() +void MySerialAnalyzer::WorkerThread() { mSampleRateHz = GetSampleRate(); ComputeSampleOffsets(); U32 bits_per_transfer = mSettings->mBitsPerTransfer; - if( mSettings->mSerialMode != SerialAnalyzerEnums::Normal ) + if( mSettings->mSerialMode != MySerialAnalyzerEnums::Normal ) bits_per_transfer++; // used for HLA byte count, this should not include an extra bit for MP/MDB @@ -95,6 +96,13 @@ void SerialAnalyzer::WorkerThread() if( mSerial->GetBitState() == mBitLow ) mSerial->AdvanceToNextEdge(); + BRTime mBRChange = mSettings->mBRChange ; + BRTime::iterator iter ; + + if (!mBRChange.empty()) { + iter=mBRChange.begin() ; + } + for( ;; ) { // we're starting high. (we'll assume that we're not in the middle of a byte. @@ -104,6 +112,20 @@ void SerialAnalyzer::WorkerThread() // we're now at the beginning of the start bit. We can start collecting the data. U64 frame_starting_sample = mSerial->GetSampleNumber(); + // change bitrate according to settings + if ( !mBRChange.empty() && iter != mBRChange.end()) { + // look for last entry in mBrChange smaller than current time + while ( iter != std::prev(mBRChange.end(),1) && (frame_starting_sample >= (float) mSampleRateHz * std::next(iter,1)->first)) { + iter++ ; + } + // if different, apply new bitrate + if (iter->second != mSettings->mBitRate) { + mResults->AddMarker(frame_starting_sample, AnalyzerResults::X, mSettings->mInputChannel) ; + mSettings->mBitRate = iter->second ; + ComputeSampleOffsets(); + } + } + U64 data = 0; bool parity_error = false; bool framing_error = false; @@ -125,16 +147,16 @@ void SerialAnalyzer::WorkerThread() if( mSettings->mInverted == true ) data = ( ~data ) & bit_mask; - if( mSettings->mSerialMode != SerialAnalyzerEnums::Normal ) + if( mSettings->mSerialMode != MySerialAnalyzerEnums::Normal ) { // extract the MSB U64 msb = data >> ( bits_per_transfer - 1 ); msb &= 0x1; - if( mSettings->mSerialMode == SerialAnalyzerEnums::MpModeMsbOneMeansAddress ) + if( mSettings->mSerialMode == MySerialAnalyzerEnums::MpModeMsbOneMeansAddress ) { mp_is_address = msb == 0x1; } - else if( mSettings->mSerialMode == SerialAnalyzerEnums::MpModeMsbZeroMeansAddress ) + else if( mSettings->mSerialMode == MySerialAnalyzerEnums::MpModeMsbZeroMeansAddress ) { mp_is_address = msb == 0x0; } @@ -248,7 +270,7 @@ void SerialAnalyzer::WorkerThread() framev2.AddString( "error", "framing" ); } - if( mSettings->mSerialMode != SerialAnalyzerEnums::Normal ) + if( mSettings->mSerialMode != MySerialAnalyzerEnums::Normal ) { framev2.AddBoolean( "address", mp_is_address ); } @@ -268,7 +290,7 @@ void SerialAnalyzer::WorkerThread() } } -bool SerialAnalyzer::NeedsRerun() +bool MySerialAnalyzer::NeedsRerun() { if( mSettings->mUseAutobaud == false ) return false; @@ -309,7 +331,7 @@ bool SerialAnalyzer::NeedsRerun() } } -U32 SerialAnalyzer::GenerateSimulationData( U64 minimum_sample_index, U32 device_sample_rate, +U32 MySerialAnalyzer::GenerateSimulationData( U64 minimum_sample_index, U32 device_sample_rate, SimulationChannelDescriptor** simulation_channels ) { if( mSimulationInitilized == false ) @@ -321,24 +343,24 @@ U32 SerialAnalyzer::GenerateSimulationData( U64 minimum_sample_index, U32 device return mSimulationDataGenerator.GenerateSimulationData( minimum_sample_index, device_sample_rate, simulation_channels ); } -U32 SerialAnalyzer::GetMinimumSampleRateHz() +U32 MySerialAnalyzer::GetMinimumSampleRateHz() { return mSettings->mBitRate * 4; } -const char* SerialAnalyzer::GetAnalyzerName() const +const char* MySerialAnalyzer::GetAnalyzerName() const { - return "Async Serial"; + return "My Async Serial"; } const char* GetAnalyzerName() { - return "Async Serial"; + return "My Async Serial"; } Analyzer* CreateAnalyzer() { - return new SerialAnalyzer(); + return new MySerialAnalyzer(); } void DestroyAnalyzer( Analyzer* analyzer ) diff --git a/src/SerialAnalyzer.h b/src/MySerialAnalyzer.h similarity index 65% rename from src/SerialAnalyzer.h rename to src/MySerialAnalyzer.h index 9172be8..c3bca39 100644 --- a/src/SerialAnalyzer.h +++ b/src/MySerialAnalyzer.h @@ -1,16 +1,16 @@ -#ifndef SERIAL_ANALYZER_H -#define SERIAL_ANALYZER_H +#ifndef MYSERIAL_ANALYZER_H +#define MYSERIAL_ANALYZER_H #include -#include "SerialAnalyzerResults.h" -#include "SerialSimulationDataGenerator.h" +#include "MySerialAnalyzerResults.h" +#include "MySerialSimulationDataGenerator.h" -class SerialAnalyzerSettings; -class SerialAnalyzer : public Analyzer2 +class MySerialAnalyzerSettings; +class MySerialAnalyzer : public Analyzer2 { public: - SerialAnalyzer(); - virtual ~SerialAnalyzer(); + MySerialAnalyzer(); + virtual ~MySerialAnalyzer(); virtual void SetupResults(); virtual void WorkerThread(); @@ -23,17 +23,17 @@ class SerialAnalyzer : public Analyzer2 #pragma warning( push ) #pragma warning( \ - disable : 4251 ) // warning C4251: 'SerialAnalyzer::<...>' : class <...> needs to have dll-interface to be used by clients of class + disable : 4251 ) // warning C4251: 'MySerialAnalyzer::<...>' : class <...> needs to have dll-interface to be used by clients of class protected: // functions void ComputeSampleOffsets(); protected: // vars - std::auto_ptr mSettings; - std::auto_ptr mResults; + std::auto_ptr mSettings; + std::auto_ptr mResults; AnalyzerChannelData* mSerial; - SerialSimulationDataGenerator mSimulationDataGenerator; + MySerialSimulationDataGenerator mSimulationDataGenerator; bool mSimulationInitilized; // Serial analysis vars: @@ -52,4 +52,4 @@ extern "C" ANALYZER_EXPORT const char* __cdecl GetAnalyzerName(); extern "C" ANALYZER_EXPORT Analyzer* __cdecl CreateAnalyzer(); extern "C" ANALYZER_EXPORT void __cdecl DestroyAnalyzer( Analyzer* analyzer ); -#endif // SERIAL_ANALYZER_H +#endif // MYSERIAL_ANALYZER_H diff --git a/src/SerialAnalyzerResults.cpp b/src/MySerialAnalyzerResults.cpp similarity index 90% rename from src/SerialAnalyzerResults.cpp rename to src/MySerialAnalyzerResults.cpp index fe437d1..ca19975 100644 --- a/src/SerialAnalyzerResults.cpp +++ b/src/MySerialAnalyzerResults.cpp @@ -1,21 +1,21 @@ -#include "SerialAnalyzerResults.h" +#include "MySerialAnalyzerResults.h" #include -#include "SerialAnalyzer.h" -#include "SerialAnalyzerSettings.h" +#include "MySerialAnalyzer.h" +#include "MySerialAnalyzerSettings.h" #include #include #include -SerialAnalyzerResults::SerialAnalyzerResults( SerialAnalyzer* analyzer, SerialAnalyzerSettings* settings ) +MySerialAnalyzerResults::MySerialAnalyzerResults( MySerialAnalyzer* analyzer, MySerialAnalyzerSettings* settings ) : AnalyzerResults(), mSettings( settings ), mAnalyzer( analyzer ) { } -SerialAnalyzerResults::~SerialAnalyzerResults() +MySerialAnalyzerResults::~MySerialAnalyzerResults() { } -void SerialAnalyzerResults::GenerateBubbleText( U64 frame_index, Channel& /*channel*/, +void MySerialAnalyzerResults::GenerateBubbleText( U64 frame_index, Channel& /*channel*/, DisplayBase display_base ) // unrefereced vars commented out to remove warnings. { // we only need to pay attention to 'channel' if we're making bubbles for more than one channel (as set by @@ -32,7 +32,7 @@ void SerialAnalyzerResults::GenerateBubbleText( U64 frame_index, Channel& /*chan parity_error = true; U32 bits_per_transfer = mSettings->mBitsPerTransfer; - if( mSettings->mSerialMode != SerialAnalyzerEnums::Normal ) + if( mSettings->mSerialMode != MySerialAnalyzerEnums::Normal ) bits_per_transfer--; char number_str[ 128 ]; @@ -91,7 +91,7 @@ void SerialAnalyzerResults::GenerateBubbleText( U64 frame_index, Channel& /*chan } } -void SerialAnalyzerResults::GenerateExportFile( const char* file, DisplayBase display_base, U32 /*export_type_user_id*/ ) +void MySerialAnalyzerResults::GenerateExportFile( const char* file, DisplayBase display_base, U32 /*export_type_user_id*/ ) { // export_type_user_id is only important if we have more than one export type. std::stringstream ss; @@ -102,7 +102,7 @@ void SerialAnalyzerResults::GenerateExportFile( const char* file, DisplayBase di void* f = AnalyzerHelpers::StartFile( file ); - if( mSettings->mSerialMode == SerialAnalyzerEnums::Normal ) + if( mSettings->mSerialMode == MySerialAnalyzerEnums::Normal ) { // Normal case -- not MP mode. ss << "Time [s],Value,Parity Error,Framing Error" << std::endl; @@ -198,7 +198,7 @@ void SerialAnalyzerResults::GenerateExportFile( const char* file, DisplayBase di AnalyzerHelpers::EndFile( f ); } -void SerialAnalyzerResults::GenerateFrameTabularText( U64 frame_index, DisplayBase display_base ) +void MySerialAnalyzerResults::GenerateFrameTabularText( U64 frame_index, DisplayBase display_base ) { ClearTabularText(); Frame frame = GetFrame( frame_index ); @@ -212,7 +212,7 @@ void SerialAnalyzerResults::GenerateFrameTabularText( U64 frame_index, DisplayBa parity_error = true; U32 bits_per_transfer = mSettings->mBitsPerTransfer; - if( mSettings->mSerialMode != SerialAnalyzerEnums::Normal ) + if( mSettings->mSerialMode != MySerialAnalyzerEnums::Normal ) bits_per_transfer--; char number_str[ 128 ]; @@ -257,14 +257,14 @@ void SerialAnalyzerResults::GenerateFrameTabularText( U64 frame_index, DisplayBa } } -void SerialAnalyzerResults::GeneratePacketTabularText( U64 /*packet_id*/, +void MySerialAnalyzerResults::GeneratePacketTabularText( U64 /*packet_id*/, DisplayBase /*display_base*/ ) // unrefereced vars commented out to remove warnings. { ClearResultStrings(); AddResultString( "not supported" ); } -void SerialAnalyzerResults::GenerateTransactionTabularText( +void MySerialAnalyzerResults::GenerateTransactionTabularText( U64 /*transaction_id*/, DisplayBase /*display_base*/ ) // unrefereced vars commented out to remove warnings. { ClearResultStrings(); diff --git a/src/SerialAnalyzerResults.h b/src/MySerialAnalyzerResults.h similarity index 62% rename from src/SerialAnalyzerResults.h rename to src/MySerialAnalyzerResults.h index d217f39..d8a074d 100644 --- a/src/SerialAnalyzerResults.h +++ b/src/MySerialAnalyzerResults.h @@ -1,5 +1,5 @@ -#ifndef SERIAL_ANALYZER_RESULTS -#define SERIAL_ANALYZER_RESULTS +#ifndef MYSERIAL_ANALYZER_RESULTS +#define MYSERIAL_ANALYZER_RESULTS #include @@ -7,14 +7,14 @@ #define PARITY_ERROR_FLAG ( 1 << 1 ) #define MP_MODE_ADDRESS_FLAG ( 1 << 2 ) -class SerialAnalyzer; -class SerialAnalyzerSettings; +class MySerialAnalyzer; +class MySerialAnalyzerSettings; -class SerialAnalyzerResults : public AnalyzerResults +class MySerialAnalyzerResults : public AnalyzerResults { public: - SerialAnalyzerResults( SerialAnalyzer* analyzer, SerialAnalyzerSettings* settings ); - virtual ~SerialAnalyzerResults(); + MySerialAnalyzerResults( MySerialAnalyzer* analyzer, MySerialAnalyzerSettings* settings ); + virtual ~MySerialAnalyzerResults(); virtual void GenerateBubbleText( U64 frame_index, Channel& channel, DisplayBase display_base ); virtual void GenerateExportFile( const char* file, DisplayBase display_base, U32 export_type_user_id ); @@ -25,8 +25,8 @@ class SerialAnalyzerResults : public AnalyzerResults protected: // functions protected: // vars - SerialAnalyzerSettings* mSettings; - SerialAnalyzer* mAnalyzer; + MySerialAnalyzerSettings* mSettings; + MySerialAnalyzer* mAnalyzer; }; -#endif // SERIAL_ANALYZER_RESULTS +#endif // MYSERIAL_ANALYZER_RESULTS diff --git a/src/SerialAnalyzerSettings.cpp b/src/MySerialAnalyzerSettings.cpp similarity index 69% rename from src/SerialAnalyzerSettings.cpp rename to src/MySerialAnalyzerSettings.cpp index 4311589..78d664f 100644 --- a/src/SerialAnalyzerSettings.cpp +++ b/src/MySerialAnalyzerSettings.cpp @@ -1,12 +1,13 @@ -#include "SerialAnalyzerSettings.h" +#include "MySerialAnalyzerSettings.h" #include #include #include +#include #pragma warning( disable : 4800 ) // warning C4800: 'U32' : forcing value to bool 'true' or 'false' (performance warning) -SerialAnalyzerSettings::SerialAnalyzerSettings() +MySerialAnalyzerSettings::MySerialAnalyzerSettings() : mInputChannel( UNDEFINED_CHANNEL ), mBitRate( 9600 ), mBitsPerTransfer( 8 ), @@ -15,10 +16,10 @@ SerialAnalyzerSettings::SerialAnalyzerSettings() mShiftOrder( AnalyzerEnums::LsbFirst ), mInverted( false ), mUseAutobaud( false ), - mSerialMode( SerialAnalyzerEnums::Normal ) + mSerialMode( MySerialAnalyzerEnums::Normal ) { mInputChannelInterface.reset( new AnalyzerSettingInterfaceChannel() ); - mInputChannelInterface->SetTitleAndTooltip( "Input Channel", "Standard Async Serial" ); + mInputChannelInterface->SetTitleAndTooltip( "Input Channel", "My Standard Async Serial" ); mInputChannelInterface->SetChannel( mInputChannel ); mBitRateInterface.reset( new AnalyzerSettingInterfaceInteger() ); @@ -27,6 +28,10 @@ SerialAnalyzerSettings::SerialAnalyzerSettings() mBitRateInterface->SetMin( 1 ); mBitRateInterface->SetInteger( mBitRate ); + mBitRateChangeInterface.reset(new AnalyzerSettingInterfaceText() ); + mBitRateChangeInterface->SetTitleAndTooltip( "Bitrate changes", "Timestamp:Bitrate, separated by spaces." ); + mBitRateChangeInterface->SetTextType(AnalyzerSettingInterfaceText::NormalText); + mUseAutobaudInterface.reset( new AnalyzerSettingInterfaceBool() ); mUseAutobaudInterface->SetTitleAndTooltip( "", "With Autobaud turned on, the analyzer will run as usual, with the current bit rate. At the same time, it will also keep " @@ -94,15 +99,16 @@ SerialAnalyzerSettings::SerialAnalyzerSettings() mSerialModeInterface.reset( new AnalyzerSettingInterfaceNumberList() ); mSerialModeInterface->SetTitleAndTooltip( "Mode", "" ); - mSerialModeInterface->AddNumber( SerialAnalyzerEnums::Normal, "Normal", "" ); - mSerialModeInterface->AddNumber( SerialAnalyzerEnums::MpModeMsbZeroMeansAddress, "MP - Address indicated by MSB=0", + mSerialModeInterface->AddNumber( MySerialAnalyzerEnums::Normal, "Normal", "" ); + mSerialModeInterface->AddNumber( MySerialAnalyzerEnums::MpModeMsbZeroMeansAddress, "MP - Address indicated by MSB=0", "Multi-processor, 9-bit serial" ); - mSerialModeInterface->AddNumber( SerialAnalyzerEnums::MpModeMsbOneMeansAddress, "MDB - Address indicated by MSB=1 (TX only)", + mSerialModeInterface->AddNumber( MySerialAnalyzerEnums::MpModeMsbOneMeansAddress, "MDB - Address indicated by MSB=1 (TX only)", "Multi-drop, 9-bit serial" ); mSerialModeInterface->SetNumber( mSerialMode ); AddInterface( mInputChannelInterface.get() ); AddInterface( mBitRateInterface.get() ); + AddInterface( mBitRateChangeInterface.get() ); AddInterface( mBitsPerTransferInterface.get() ); AddInterface( mStopBitsInterface.get() ); AddInterface( mParityInterface.get() ); @@ -119,14 +125,66 @@ SerialAnalyzerSettings::SerialAnalyzerSettings() AddChannel( mInputChannel, "Serial", false ); } -SerialAnalyzerSettings::~SerialAnalyzerSettings() +MySerialAnalyzerSettings::~MySerialAnalyzerSettings() +{ +} + +/* + * Fills mBRChange map according to mBitRateChange string contents + * eg: if mBitRatechange contains "0:9600 7.765:250000" + * mBRChange will contain { 0 => 9600, 7.765 => 250000} + */ +void MySerialAnalyzerSettings::SyncBitRateChange() { + mBRChange.clear() ; + + if (mBitRateChangeStr.empty()) return ; + + std::string s=mBitRateChangeStr; + std::string delimiter = " " ; + std::vector token; + + size_t pos = 0 ; + + float time ; + U32 bitrate ; + + // parse string separated by spaces, and fill array of found tokens + while ((pos = s.find(delimiter)) != std::string::npos) { + std::string t=s.substr(0,pos); + // std::cout << "token:{" << t << "}" << std::endl ; + s.erase(0,pos+delimiter.length()); + + if (t.empty()) { // multiple spaces + continue ; + } + + token.push_back(t) ; + } + + // remaining of the string after last seen separator + if (!s.empty()) { + token.push_back(s) ; + } + + // parse every token and fill mBRChange + for (const std::string&t : token) { + if (sscanf(t.c_str(),"%f:%u",&time, &bitrate) != 2) { // parsing error + // std::cout << "parsing error {" << token[mszBRChange] << "}" << std::endl ; + //TODO: display error to user. + continue; + } + + mBRChange[time] = bitrate ; + } + + return ; } -bool SerialAnalyzerSettings::SetSettingsFromInterfaces() +bool MySerialAnalyzerSettings::SetSettingsFromInterfaces() { if( AnalyzerEnums::Parity( U32( mParityInterface->GetNumber() ) ) != AnalyzerEnums::None ) - if( SerialAnalyzerEnums::Mode( U32( mSerialModeInterface->GetNumber() ) ) != SerialAnalyzerEnums::Normal ) + if( MySerialAnalyzerEnums::Mode( U32( mSerialModeInterface->GetNumber() ) ) != MySerialAnalyzerEnums::Normal ) { SetErrorText( "Sorry, but we don't support using parity at the same time as MP mode." ); return false; @@ -134,13 +192,16 @@ bool SerialAnalyzerSettings::SetSettingsFromInterfaces() mInputChannel = mInputChannelInterface->GetChannel(); mBitRate = mBitRateInterface->GetInteger(); + mBitRateChangeStr = mBitRateChangeInterface->GetText(); + SyncBitRateChange() ; + mBitsPerTransfer = U32( mBitsPerTransferInterface->GetNumber() ); mStopBits = mStopBitsInterface->GetNumber(); mParity = AnalyzerEnums::Parity( U32( mParityInterface->GetNumber() ) ); mShiftOrder = AnalyzerEnums::ShiftOrder( U32( mShiftOrderInterface->GetNumber() ) ); mInverted = bool( U32( mInvertedInterface->GetNumber() ) ); mUseAutobaud = mUseAutobaudInterface->GetValue(); - mSerialMode = SerialAnalyzerEnums::Mode( U32( mSerialModeInterface->GetNumber() ) ); + mSerialMode = MySerialAnalyzerEnums::Mode( U32( mSerialModeInterface->GetNumber() ) ); ClearChannels(); AddChannel( mInputChannel, "Serial", true ); @@ -148,10 +209,11 @@ bool SerialAnalyzerSettings::SetSettingsFromInterfaces() return true; } -void SerialAnalyzerSettings::UpdateInterfacesFromSettings() +void MySerialAnalyzerSettings::UpdateInterfacesFromSettings() { mInputChannelInterface->SetChannel( mInputChannel ); mBitRateInterface->SetInteger( mBitRate ); + mBitRateChangeInterface->SetText( mBitRateChangeStr.c_str()) ; mBitsPerTransferInterface->SetNumber( mBitsPerTransfer ); mStopBitsInterface->SetNumber( mStopBits ); mParityInterface->SetNumber( mParity ); @@ -161,15 +223,15 @@ void SerialAnalyzerSettings::UpdateInterfacesFromSettings() mSerialModeInterface->SetNumber( mSerialMode ); } -void SerialAnalyzerSettings::LoadSettings( const char* settings ) +void MySerialAnalyzerSettings::LoadSettings( const char* settings ) { SimpleArchive text_archive; text_archive.SetString( settings ); const char* name_string; // the first thing in the archive is the name of the protocol analyzer that the data belongs to. text_archive >> &name_string; - if( strcmp( name_string, "SaleaeAsyncSerialAnalyzer" ) != 0 ) - AnalyzerHelpers::Assert( "SaleaeAsyncSerialAnalyzer: Provided with a settings string that doesn't belong to us;" ); + if( strcmp( name_string, "SaleaeAsyncMySerialAnalyzer" ) != 0 ) + AnalyzerHelpers::Assert( "SaleaeAsyncMySerialAnalyzer: Provided with a settings string that doesn't belong to us;" ); text_archive >> mInputChannel; text_archive >> mBitRate; @@ -185,21 +247,27 @@ void SerialAnalyzerSettings::LoadSettings( const char* settings ) if( text_archive >> use_autobaud ) mUseAutobaud = use_autobaud; - SerialAnalyzerEnums::Mode mode; + MySerialAnalyzerEnums::Mode mode; if( text_archive >> *( U32* )&mode ) mSerialMode = mode; + const char * bitratechange_string ; + if ( text_archive >> &bitratechange_string ) { + mBitRateChangeStr = name_string ; + SyncBitRateChange() ; + } + ClearChannels(); AddChannel( mInputChannel, "Serial", true ); UpdateInterfacesFromSettings(); } -const char* SerialAnalyzerSettings::SaveSettings() +const char* MySerialAnalyzerSettings::SaveSettings() { SimpleArchive text_archive; - text_archive << "SaleaeAsyncSerialAnalyzer"; + text_archive << "SaleaeAsyncMySerialAnalyzer"; text_archive << mInputChannel; text_archive << mBitRate; text_archive << mBitsPerTransfer; @@ -211,6 +279,7 @@ const char* SerialAnalyzerSettings::SaveSettings() text_archive << mUseAutobaud; text_archive << mSerialMode; + text_archive << mBitRateChangeStr.c_str() ; return SetReturnString( text_archive.GetString() ); } diff --git a/src/SerialAnalyzerSettings.h b/src/MySerialAnalyzerSettings.h similarity index 63% rename from src/SerialAnalyzerSettings.h rename to src/MySerialAnalyzerSettings.h index c742510..7eccb80 100644 --- a/src/SerialAnalyzerSettings.h +++ b/src/MySerialAnalyzerSettings.h @@ -1,10 +1,11 @@ -#ifndef SERIAL_ANALYZER_SETTINGS -#define SERIAL_ANALYZER_SETTINGS +#ifndef MYSERIAL_ANALYZER_SETTINGS +#define MYSERIAL_ANALYZER_SETTINGS #include #include +#include -namespace SerialAnalyzerEnums +namespace MySerialAnalyzerEnums { enum Mode { @@ -14,11 +15,13 @@ namespace SerialAnalyzerEnums }; }; -class SerialAnalyzerSettings : public AnalyzerSettings +typedef std::map BRTime ; + +class MySerialAnalyzerSettings : public AnalyzerSettings { public: - SerialAnalyzerSettings(); - virtual ~SerialAnalyzerSettings(); + MySerialAnalyzerSettings(); + virtual ~MySerialAnalyzerSettings(); virtual bool SetSettingsFromInterfaces(); void UpdateInterfacesFromSettings(); @@ -28,17 +31,25 @@ class SerialAnalyzerSettings : public AnalyzerSettings Channel mInputChannel; U32 mBitRate; + + std::string mBitRateChangeStr; // string containing when to change bitrate, in the form time:bitrate, separated by spaces + + // this will contain when to change baudrate. Keys: timestamp, value: baudrate to set. + BRTime mBRChange ; + U32 mBitsPerTransfer; AnalyzerEnums::ShiftOrder mShiftOrder; double mStopBits; AnalyzerEnums::Parity mParity; bool mInverted; bool mUseAutobaud; - SerialAnalyzerEnums::Mode mSerialMode; + MySerialAnalyzerEnums::Mode mSerialMode; protected: + void SyncBitRateChange(); std::auto_ptr mInputChannelInterface; std::auto_ptr mBitRateInterface; + std::auto_ptr mBitRateChangeInterface; std::auto_ptr mBitsPerTransferInterface; std::auto_ptr mShiftOrderInterface; std::auto_ptr mStopBitsInterface; @@ -48,4 +59,4 @@ class SerialAnalyzerSettings : public AnalyzerSettings std::auto_ptr mSerialModeInterface; }; -#endif // SERIAL_ANALYZER_SETTINGS +#endif // MYSERIAL_ANALYZER_SETTINGS diff --git a/src/SerialSimulationDataGenerator.cpp b/src/MySerialSimulationDataGenerator.cpp similarity index 84% rename from src/SerialSimulationDataGenerator.cpp rename to src/MySerialSimulationDataGenerator.cpp index fdae3e9..0f22e27 100644 --- a/src/SerialSimulationDataGenerator.cpp +++ b/src/MySerialSimulationDataGenerator.cpp @@ -1,15 +1,15 @@ -#include "SerialSimulationDataGenerator.h" -#include "SerialAnalyzerSettings.h" +#include "MySerialSimulationDataGenerator.h" +#include "MySerialAnalyzerSettings.h" -SerialSimulationDataGenerator::SerialSimulationDataGenerator() +MySerialSimulationDataGenerator::MySerialSimulationDataGenerator() { } -SerialSimulationDataGenerator::~SerialSimulationDataGenerator() +MySerialSimulationDataGenerator::~MySerialSimulationDataGenerator() { } -void SerialSimulationDataGenerator::Initialize( U32 simulation_sample_rate, SerialAnalyzerSettings* settings ) +void MySerialSimulationDataGenerator::Initialize( U32 simulation_sample_rate, MySerialAnalyzerSettings* settings ) { mSimulationSampleRateHz = simulation_sample_rate; mSettings = settings; @@ -45,14 +45,14 @@ void SerialSimulationDataGenerator::Initialize( U32 simulation_sample_rate, Seri mNumBitsMask |= 0x1; } - if( mSettings->mSerialMode == SerialAnalyzerEnums::MpModeMsbOneMeansAddress ) + if( mSettings->mSerialMode == MySerialAnalyzerEnums::MpModeMsbOneMeansAddress ) mMpModeAddressMask = 0x1ull << ( mSettings->mBitsPerTransfer ); - if( mSettings->mSerialMode == SerialAnalyzerEnums::MpModeMsbZeroMeansAddress ) + if( mSettings->mSerialMode == MySerialAnalyzerEnums::MpModeMsbZeroMeansAddress ) mMpModeDataMask = 0x1ull << ( mSettings->mBitsPerTransfer ); } -U32 SerialSimulationDataGenerator::GenerateSimulationData( U64 largest_sample_requested, U32 sample_rate, +U32 MySerialSimulationDataGenerator::GenerateSimulationData( U64 largest_sample_requested, U32 sample_rate, SimulationChannelDescriptor** simulation_channels ) { U64 adjusted_largest_sample_requested = @@ -60,7 +60,7 @@ U32 SerialSimulationDataGenerator::GenerateSimulationData( U64 largest_sample_re while( mSerialSimulationData.GetCurrentSampleNumber() < adjusted_largest_sample_requested ) { - if( mSettings->mSerialMode == SerialAnalyzerEnums::Normal ) + if( mSettings->mSerialMode == MySerialAnalyzerEnums::Normal ) { CreateSerialByte( mValue++ ); @@ -98,7 +98,7 @@ U32 SerialSimulationDataGenerator::GenerateSimulationData( U64 largest_sample_re return 1; // we are retuning the size of the SimulationChannelDescriptor array. In our case, the "array" is length 1. } -void SerialSimulationDataGenerator::CreateSerialByte( U64 value ) +void MySerialSimulationDataGenerator::CreateSerialByte( U64 value ) { // assume we start high @@ -109,7 +109,7 @@ void SerialSimulationDataGenerator::CreateSerialByte( U64 value ) value = ~value; U32 num_bits = mSettings->mBitsPerTransfer; - if( mSettings->mSerialMode != SerialAnalyzerEnums::Normal ) + if( mSettings->mSerialMode != MySerialAnalyzerEnums::Normal ) num_bits++; BitExtractor bit_extractor( value, mSettings->mShiftOrder, num_bits ); diff --git a/src/SerialSimulationDataGenerator.h b/src/MySerialSimulationDataGenerator.h similarity index 64% rename from src/SerialSimulationDataGenerator.h rename to src/MySerialSimulationDataGenerator.h index 0995404..6f6324d 100644 --- a/src/SerialSimulationDataGenerator.h +++ b/src/MySerialSimulationDataGenerator.h @@ -1,21 +1,21 @@ -#ifndef SERIAL_SIMULATION_DATA_GENERATOR -#define SERIAL_SIMULATION_DATA_GENERATOR +#ifndef MYSERIAL_SIMULATION_DATA_GENERATOR +#define MYSERIAL_SIMULATION_DATA_GENERATOR #include -class SerialAnalyzerSettings; +class MySerialAnalyzerSettings; -class SerialSimulationDataGenerator +class MySerialSimulationDataGenerator { public: - SerialSimulationDataGenerator(); - ~SerialSimulationDataGenerator(); + MySerialSimulationDataGenerator(); + ~MySerialSimulationDataGenerator(); - void Initialize( U32 simulation_sample_rate, SerialAnalyzerSettings* settings ); + void Initialize( U32 simulation_sample_rate, MySerialAnalyzerSettings* settings ); U32 GenerateSimulationData( U64 newest_sample_requested, U32 sample_rate, SimulationChannelDescriptor** simulation_channelss ); protected: - SerialAnalyzerSettings* mSettings; + MySerialAnalyzerSettings* mSettings; U32 mSimulationSampleRateHz; BitState mBitLow; BitState mBitHigh;