Skip to content

Commit

Permalink
Changed Filter::SetDefaultName() to produce sane defaults for almost …
Browse files Browse the repository at this point in the history
…all filters. Still overridden in a few specialized cases. Fixes #281.
  • Loading branch information
azonenberg committed May 18, 2022
1 parent c911666 commit 7967adb
Show file tree
Hide file tree
Showing 228 changed files with 154 additions and 1,217 deletions.
106 changes: 105 additions & 1 deletion scopehal/Filter.cpp
Expand Up @@ -44,6 +44,8 @@ set<Filter*> Filter::m_filters;
mutex Filter::m_cacheMutex;
map<pair<WaveformBase*, float>, vector<int64_t> > Filter::m_zeroCrossingCache;

map<string, unsigned int> Filter::m_instanceCount;

Gdk::Color Filter::m_standardColors[STANDARD_COLOR_COUNT] =
{
Gdk::Color("#336699"), //COLOR_DATA
Expand Down Expand Up @@ -71,6 +73,7 @@ Filter::Filter(
, m_usingDefault(true)
{
m_physical = false;
m_instanceNum = 0;
m_filters.emplace(this);

//Load our OpenCL kernel, if we have one
Expand Down Expand Up @@ -200,7 +203,11 @@ void Filter::EnumProtocols(vector<string>& names)
Filter* Filter::CreateFilter(const string& protocol, const string& color)
{
if(m_createprocs.find(protocol) != m_createprocs.end())
return m_createprocs[protocol](color);
{
auto f = m_createprocs[protocol](color);
f->m_instanceNum = (m_instanceCount[protocol] ++);
return f;
}

LogError("Invalid filter name: %s\n", protocol.c_str());
return NULL;
Expand Down Expand Up @@ -1400,3 +1407,100 @@ void Filter::AdvanceToTimestampScaled(WaveformBase* wfm, size_t& i, size_t len,
while( ((i+1) < len) && ( (wfm->m_offsets[i+1] * wfm->m_timescale) <= timestamp) )
i ++;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Naming

/**
@brief Sets the name of a filter based on its inputs
This method may be overridden in derived classes for specialized applications, but there is no need to do so in
typical filters.
*/
void Filter::SetDefaultName()
{
//Start with our immediate inputs
set<StreamDescriptor> inputs;
for(auto i : m_inputs)
inputs.emplace(i);

//If we're a measurement, stop
//We want to see the full list of inputs as-is
if(m_category == CAT_MEASUREMENT)
{
}

//Walk filter graph back to find source nodes
else
{
//Replace each input with its ancestor
while(true)
{
bool changed = false;
set<StreamDescriptor> next;

for(auto i : inputs)
{
//If the channel is not a filter, it's a scope channel.
//Pass through unchanged.
auto f = dynamic_cast<Filter*>(i.m_channel);
if(!f)
next.emplace(i);

//It's a filter. Does it have any inputs?
//If not, it's an import or waveform generation filter. Pass through unchanged.
else if(f->GetInputCount() == 0)
next.emplace(i);

//Filter that has inputs. Use them.
else
{
for(size_t j=0; j<f->GetInputCount(); j++)
next.emplace(f->GetInput(j));
changed = true;
}
}

if(!changed)
break;
inputs = next;
}
}

//Sort the inputs alphabetically (up to now, they're sorted by the std::set)
vector<string> sorted;
for(auto i : inputs)
sorted.push_back(i.GetName());
sort(sorted.begin(), sorted.end());

string inames = "";
for(auto s : sorted)
{
if(s == "NULL")
continue;

if(inames.length() > 12)
{
inames += ", ...";
break;
}

if(inames != "")
inames += ",";
inames += s;
}

//Format final output: remove spaces from display name, add instance number
auto pname = GetProtocolDisplayName();
string pname2;
for(auto c : pname)
{
if(isalpha(c))
pname2 += c;
}
string name = pname2 + +"_" + to_string(m_instanceNum + 1) + "(" + inames + ")";

m_hwname = name;
m_displayname = name;

}
12 changes: 11 additions & 1 deletion scopehal/Filter.h
Expand Up @@ -111,7 +111,7 @@ class Filter : public OscilloscopeChannel
*/
virtual void ClearSweeps();

virtual void SetDefaultName() =0;
virtual void SetDefaultName();

Category GetCategory()
{ return m_category; }
Expand Down Expand Up @@ -233,6 +233,13 @@ class Filter : public OscilloscopeChannel
///@brief Signal emitted when the set of output streams changes
sigc::signal<void> m_outputsChangedSignal;

/**
@brief Instance number (for auto naming)
Starts at 0 for the first filter of a given class type created, then increments
*/
unsigned int m_instanceNum;

protected:
//Common text formatting
virtual std::string GetTextForAsciiChannel(int i, size_t stream);
Expand Down Expand Up @@ -260,6 +267,9 @@ class Filter : public OscilloscopeChannel
//Object enumeration
static std::set<Filter*> m_filters;

//Instance naming
static std::map<std::string, unsigned int> m_instanceCount;

//Caching
static std::mutex m_cacheMutex;
static std::map<std::pair<WaveformBase*, float>, std::vector<int64_t> > m_zeroCrossingCache;
Expand Down
8 changes: 0 additions & 8 deletions scopeprotocols/ACCoupleFilter.cpp
Expand Up @@ -74,14 +74,6 @@ bool ACCoupleFilter::NeedsConfig()
return false;
}

void ACCoupleFilter::SetDefaultName()
{
char hwname[256];
snprintf(hwname, sizeof(hwname), "AC(%s)", GetInputDisplayName(0).c_str());
m_hwname = hwname;
m_displayname = m_hwname;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Actual decoder logic

Expand Down
1 change: 0 additions & 1 deletion scopeprotocols/ACCoupleFilter.h
Expand Up @@ -45,7 +45,6 @@ class ACCoupleFilter : public Filter
virtual bool NeedsConfig();

static std::string GetProtocolName();
virtual void SetDefaultName();

virtual float GetVoltageRange(size_t stream);
virtual bool ValidateChannel(size_t i, StreamDescriptor stream);
Expand Down
8 changes: 0 additions & 8 deletions scopeprotocols/ADL5205Decoder.cpp
Expand Up @@ -70,14 +70,6 @@ bool ADL5205Decoder::NeedsConfig()
return true;
}

void ADL5205Decoder::SetDefaultName()
{
char hwname[256];
snprintf(hwname, sizeof(hwname), "ADL5205(%s)", GetInputDisplayName(0).c_str());
m_hwname = hwname;
m_displayname = m_hwname;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Actual decoder logic

Expand Down
1 change: 0 additions & 1 deletion scopeprotocols/ADL5205Decoder.h
Expand Up @@ -70,7 +70,6 @@ class ADL5205Decoder : public Filter
virtual bool NeedsConfig();

static std::string GetProtocolName();
virtual void SetDefaultName();

virtual bool ValidateChannel(size_t i, StreamDescriptor stream);

Expand Down
9 changes: 0 additions & 9 deletions scopeprotocols/AutocorrelationFilter.cpp
Expand Up @@ -86,15 +86,6 @@ bool AutocorrelationFilter::NeedsConfig()
return true;
}

void AutocorrelationFilter::SetDefaultName()
{
char hwname[256];
snprintf(hwname, sizeof(hwname), "Autocorrelation(%s)", GetInputDisplayName(0).c_str());

m_hwname = hwname;
m_displayname = m_hwname;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Actual decoder logic

Expand Down
1 change: 0 additions & 1 deletion scopeprotocols/AutocorrelationFilter.h
Expand Up @@ -45,7 +45,6 @@ class AutocorrelationFilter : public Filter
virtual bool NeedsConfig();

static std::string GetProtocolName();
virtual void SetDefaultName();

virtual float GetVoltageRange(size_t stream);
virtual float GetOffset(size_t stream);
Expand Down
8 changes: 0 additions & 8 deletions scopeprotocols/BaseMeasurement.cpp
Expand Up @@ -61,14 +61,6 @@ bool BaseMeasurement::ValidateChannel(size_t i, StreamDescriptor stream)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Accessors

void BaseMeasurement::SetDefaultName()
{
char hwname[256];
snprintf(hwname, sizeof(hwname), "Base(%s)", GetInputDisplayName(0).c_str());
m_hwname = hwname;
m_displayname = m_hwname;
}

string BaseMeasurement::GetProtocolName()
{
return "Base";
Expand Down
1 change: 0 additions & 1 deletion scopeprotocols/BaseMeasurement.h
Expand Up @@ -45,7 +45,6 @@ class BaseMeasurement : public Filter
virtual bool NeedsConfig();

static std::string GetProtocolName();
virtual void SetDefaultName();

virtual float GetVoltageRange(size_t stream);
virtual float GetOffset(size_t stream);
Expand Down
8 changes: 0 additions & 8 deletions scopeprotocols/CANDecoder.cpp
Expand Up @@ -76,14 +76,6 @@ string CANDecoder::GetProtocolName()
return "CAN";
}

void CANDecoder::SetDefaultName()
{
char hwname[256];
snprintf(hwname, sizeof(hwname), "CAN(%s)", GetInputDisplayName(0).c_str());
m_hwname = hwname;
m_displayname = m_hwname;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Actual decoder logic

Expand Down
1 change: 0 additions & 1 deletion scopeprotocols/CANDecoder.h
Expand Up @@ -90,7 +90,6 @@ class CANDecoder : public PacketDecoder
virtual bool NeedsConfig();

static std::string GetProtocolName();
virtual void SetDefaultName();

std::vector<std::string> GetHeaders();

Expand Down
18 changes: 0 additions & 18 deletions scopeprotocols/CTLEFilter.cpp
Expand Up @@ -82,24 +82,6 @@ bool CTLEFilter::NeedsConfig()
return true;
}

void CTLEFilter::SetDefaultName()
{
char hwname[256];
snprintf(
hwname,
sizeof(hwname),
"CTLE(%s, %s, %s, %s, %s)",
GetInputDisplayName(0).c_str(),
m_parameters[m_dcGainName].ToString().c_str(),
m_parameters[m_zeroFreqName].ToString().c_str(),
m_parameters[m_poleFreq1Name].ToString().c_str(),
m_parameters[m_poleFreq2Name].ToString().c_str()
);

m_hwname = hwname;
m_displayname = m_hwname;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Actual decoder logic

Expand Down
1 change: 0 additions & 1 deletion scopeprotocols/CTLEFilter.h
Expand Up @@ -47,7 +47,6 @@ class CTLEFilter : public DeEmbedFilter
virtual bool NeedsConfig();

static std::string GetProtocolName();
virtual void SetDefaultName();

PROTOCOL_DECODER_INITPROC(CTLEFilter)

Expand Down
8 changes: 0 additions & 8 deletions scopeprotocols/ClockRecoveryFilter.cpp
Expand Up @@ -83,14 +83,6 @@ bool ClockRecoveryFilter::ValidateChannel(size_t i, StreamDescriptor stream)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Accessors

void ClockRecoveryFilter::SetDefaultName()
{
char hwname[256];
snprintf(hwname, sizeof(hwname), "ClockRec(%s)", GetInputDisplayName(0).c_str());
m_hwname = hwname;
m_displayname = m_hwname;
}

string ClockRecoveryFilter::GetProtocolName()
{
return "Clock Recovery (PLL)";
Expand Down
1 change: 0 additions & 1 deletion scopeprotocols/ClockRecoveryFilter.h
Expand Up @@ -46,7 +46,6 @@ class ClockRecoveryFilter : public Filter
virtual bool NeedsConfig();

static std::string GetProtocolName();
virtual void SetDefaultName();

virtual bool ValidateChannel(size_t i, StreamDescriptor stream);

Expand Down
11 changes: 0 additions & 11 deletions scopeprotocols/CurrentShuntFilter.cpp
Expand Up @@ -88,17 +88,6 @@ bool CurrentShuntFilter::NeedsConfig()
return true;
}

void CurrentShuntFilter::SetDefaultName()
{
char hwname[256];
snprintf(hwname, sizeof(hwname), "Shunt(%s, %s)",
GetInputDisplayName(0).c_str(),
m_parameters[m_resistanceName].ToString().c_str());

m_hwname = hwname;
m_displayname = m_hwname;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Actual decoder logic

Expand Down
1 change: 0 additions & 1 deletion scopeprotocols/CurrentShuntFilter.h
Expand Up @@ -45,7 +45,6 @@ class CurrentShuntFilter : public Filter
virtual bool NeedsConfig();

static std::string GetProtocolName();
virtual void SetDefaultName();

virtual float GetVoltageRange(size_t stream);
virtual float GetOffset(size_t stream);
Expand Down
8 changes: 0 additions & 8 deletions scopeprotocols/DCDMeasurement.cpp
Expand Up @@ -60,14 +60,6 @@ bool DCDMeasurement::ValidateChannel(size_t i, StreamDescriptor stream)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Accessors

void DCDMeasurement::SetDefaultName()
{
char hwname[256];
snprintf(hwname, sizeof(hwname), "DCD(%s)", GetInputDisplayName(0).c_str());
m_hwname = hwname;
m_displayname = m_hwname;
}

string DCDMeasurement::GetProtocolName()
{
return "DCD";
Expand Down
1 change: 0 additions & 1 deletion scopeprotocols/DCDMeasurement.h
Expand Up @@ -47,7 +47,6 @@ class DCDMeasurement : public Filter
virtual bool NeedsConfig();

static std::string GetProtocolName();
virtual void SetDefaultName();

virtual float GetVoltageRange(size_t stream);
virtual float GetOffset(size_t stream);
Expand Down

0 comments on commit 7967adb

Please sign in to comment.