Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting to change bitrate according to a timeframe #15

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
66 changes: 44 additions & 22 deletions src/SerialAnalyzer.cpp → src/MySerialAnalyzer.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
#include "SerialAnalyzer.h"
#include "SerialAnalyzerSettings.h"
#include "MySerialAnalyzer.h"
#include "MySerialAnalyzerSettings.h"
#include <AnalyzerChannelData.h>
#include <map>
#include <iterator>


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 );
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 );
}
Expand All @@ -268,7 +290,7 @@ void SerialAnalyzer::WorkerThread()
}
}

bool SerialAnalyzer::NeedsRerun()
bool MySerialAnalyzer::NeedsRerun()
{
if( mSettings->mUseAutobaud == false )
return false;
Expand Down Expand Up @@ -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 )
Expand All @@ -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 )
Expand Down
26 changes: 13 additions & 13 deletions src/SerialAnalyzer.h → src/MySerialAnalyzer.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#ifndef SERIAL_ANALYZER_H
#define SERIAL_ANALYZER_H
#ifndef MYSERIAL_ANALYZER_H
#define MYSERIAL_ANALYZER_H

#include <Analyzer.h>
#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();

Expand All @@ -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<SerialAnalyzerSettings> mSettings;
std::auto_ptr<SerialAnalyzerResults> mResults;
std::auto_ptr<MySerialAnalyzerSettings> mSettings;
std::auto_ptr<MySerialAnalyzerResults> mResults;
AnalyzerChannelData* mSerial;

SerialSimulationDataGenerator mSimulationDataGenerator;
MySerialSimulationDataGenerator mSimulationDataGenerator;
bool mSimulationInitilized;

// Serial analysis vars:
Expand All @@ -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
26 changes: 13 additions & 13 deletions src/SerialAnalyzerResults.cpp → src/MySerialAnalyzerResults.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#include "SerialAnalyzerResults.h"
#include "MySerialAnalyzerResults.h"
#include <AnalyzerHelpers.h>
#include "SerialAnalyzer.h"
#include "SerialAnalyzerSettings.h"
#include "MySerialAnalyzer.h"
#include "MySerialAnalyzerSettings.h"
#include <iostream>
#include <sstream>
#include <stdio.h>

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
Expand All @@ -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 ];
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 );
Expand All @@ -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 ];
Expand Down Expand Up @@ -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();
Expand Down
20 changes: 10 additions & 10 deletions src/SerialAnalyzerResults.h → src/MySerialAnalyzerResults.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#ifndef SERIAL_ANALYZER_RESULTS
#define SERIAL_ANALYZER_RESULTS
#ifndef MYSERIAL_ANALYZER_RESULTS
#define MYSERIAL_ANALYZER_RESULTS

#include <AnalyzerResults.h>

#define FRAMING_ERROR_FLAG ( 1 << 0 )
#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 );
Expand All @@ -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
Loading