Skip to content

Commit

Permalink
Merge pull request #669 from 602p/protocolwaveform_refactor
Browse files Browse the repository at this point in the history
Refactor GetText/GetColor to be properties on protocol waveforms
  • Loading branch information
azonenberg committed Aug 20, 2022
2 parents 11f0c65 + 7d0f6af commit 0367608
Show file tree
Hide file tree
Showing 87 changed files with 3,485 additions and 3,781 deletions.
6 changes: 2 additions & 4 deletions scopeexports/CSVExportWizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,7 @@ void CSVExportWizard::on_apply()

case Stream::STREAM_TYPE_PROTOCOL:
{
auto reffilt = dynamic_cast<Filter*>(streams[0].m_channel);
fprintf(fp, ",%s", reffilt->GetText(i, streams[0].m_stream).c_str());
fprintf(fp, ",%s", timebaseWaveform->GetText(i).c_str());
}
break;

Expand Down Expand Up @@ -415,9 +414,8 @@ void CSVExportWizard::on_apply()
//First-hit "interpolation"
case Stream::STREAM_TYPE_PROTOCOL:
{
auto filt = dynamic_cast<Filter*>(streams[j].m_channel);
if(firstHit)
fprintf(fp, ",%s", filt->GetText(k, streams[i].m_stream).c_str());
fprintf(fp, ",%s", w->GetText(k).c_str());
else
fprintf(fp, ",");
}
Expand Down
1 change: 1 addition & 0 deletions scopehal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ set(SCOPEHAL_SOURCES
RohdeSchwarzHMC8012Multimeter.cpp
RohdeSchwarzHMC804xPowerSupply.cpp

StandardColors.cpp
Filter.cpp
FilterParameter.cpp
ImportFilter.cpp
Expand Down
47 changes: 0 additions & 47 deletions scopehal/Filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,6 @@ 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
Gdk::Color("#c000a0"), //COLOR_CONTROL
Gdk::Color("#ffff00"), //COLOR_ADDRESS
Gdk::Color("#808080"), //COLOR_PREAMBLE
Gdk::Color("#00ff00"), //COLOR_CHECKSUM_OK
Gdk::Color("#ff0000"), //COLOR_CHECKSUM_BAD
Gdk::Color("#ff0000"), //COLOR_ERROR
Gdk::Color("#404040") //COLOR_IDLE
};

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Construction / destruction

Expand Down Expand Up @@ -1083,41 +1071,6 @@ void Filter::LoadParameters(const YAML::Node& node, IDTable& table)
}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Complex protocol decodes

Gdk::Color Filter::GetColor(size_t /*i*/, size_t /*stream*/)
{
return m_standardColors[COLOR_ERROR];
}

string Filter::GetText(size_t /*i*/, size_t /*stream*/)
{
return "(unimplemented)";
}

string Filter::GetTextForAsciiChannel(int i, size_t stream)
{
AsciiWaveform* capture = dynamic_cast<AsciiWaveform*>(GetData(stream));
if(capture != NULL)
{
char c = capture->m_samples[i];
char sbuf[16] = {0};
if(isprint(c))
sbuf[0] = c;
else if(c == '\r') //special case common non-printable chars
return "\\r";
else if(c == '\n')
return "\\n";
else if(c == '\b')
return "\\b";
else
snprintf(sbuf, sizeof(sbuf), "\\x%02x", 0xFF & c);
return sbuf;
}
return "";
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Interpolation helpers

Expand Down
30 changes: 0 additions & 30 deletions scopehal/Filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,30 +213,6 @@ class Filter : public OscilloscopeChannel

virtual void LoadParameters(const YAML::Node& node, IDTable& table);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Color table (TODO: probably should be refactored)

/**
@brief Standard colors for protocol decode overlays.
Do not change ordering, add new items to the end only.
*/
enum FilterColor
{
COLOR_DATA, //protocol data
COLOR_CONTROL, //generic control sequences
COLOR_ADDRESS, //addresses or device IDs
COLOR_PREAMBLE, //preambles, start bits, and other constant framing
COLOR_CHECKSUM_OK, //valid CRC/checksum
COLOR_CHECKSUM_BAD, //invalid CRC/checksum
COLOR_ERROR, //malformed traffic
COLOR_IDLE, //downtime between frames

STANDARD_COLOR_COUNT
};

static Gdk::Color m_standardColors[STANDARD_COLOR_COUNT];

protected:

///Group used for the display menu
Expand Down Expand Up @@ -266,10 +242,6 @@ class Filter : public OscilloscopeChannel
DigitalWaveform* SetupDigitalOutputWaveform(WaveformBase* din, size_t stream, size_t skipstart, size_t skipend);

public:
//Text formatting for CHANNEL_TYPE_COMPLEX decodes
virtual Gdk::Color GetColor(size_t i, size_t stream);
virtual std::string GetText(size_t i, size_t stream);

//Helpers for sub-sample interoplation
static float InterpolateTime(AnalogWaveform* cap, size_t a, float voltage);
static float InterpolateTime(AnalogWaveform* p, AnalogWaveform* n, size_t a, float voltage);
Expand Down Expand Up @@ -330,8 +302,6 @@ class Filter : public OscilloscopeChannel
unsigned int m_instanceNum;

protected:
//Common text formatting
virtual std::string GetTextForAsciiChannel(int i, size_t stream);

#ifdef HAVE_OPENCL

Expand Down
45 changes: 45 additions & 0 deletions scopehal/StandardColors.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/***********************************************************************************************************************
* *
* libscopehal *
* *
* Copyright (c) 2012-2022 Andrew D. Zonenberg and contributors *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
* following conditions are met: *
* *
* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
* following disclaimer. *
* *
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
* following disclaimer in the documentation and/or other materials provided with the distribution. *
* *
* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
* derived from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
***********************************************************************************************************************/

#include "StandardColors.h"

namespace StandardColors
{
Gdk::Color colors[StandardColors::STANDARD_COLOR_COUNT] =
{
Gdk::Color("#336699"), //COLOR_DATA
Gdk::Color("#c000a0"), //COLOR_CONTROL
Gdk::Color("#ffff00"), //COLOR_ADDRESS
Gdk::Color("#808080"), //COLOR_PREAMBLE
Gdk::Color("#00ff00"), //COLOR_CHECKSUM_OK
Gdk::Color("#ff0000"), //COLOR_CHECKSUM_BAD
Gdk::Color("#ff0000"), //COLOR_ERROR
Gdk::Color("#404040") //COLOR_IDLE
};
}
56 changes: 56 additions & 0 deletions scopehal/StandardColors.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/***********************************************************************************************************************
* *
* libscopehal v0.1 *
* *
* Copyright (c) 2012-2022 Andrew D. Zonenberg and contributors *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
* following conditions are met: *
* *
* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
* following disclaimer. *
* *
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
* following disclaimer in the documentation and/or other materials provided with the distribution. *
* *
* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
* derived from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
***********************************************************************************************************************/

#ifndef StandardColors_h
#define StandardColors_h

#include <gtkmm.h>

// TODO: This doesn't seem like it belongs in scopehal

namespace StandardColors
{
enum FilterColor
{
COLOR_DATA, //protocol data
COLOR_CONTROL, //generic control sequences
COLOR_ADDRESS, //addresses or device IDs
COLOR_PREAMBLE, //preambles, start bits, and other constant framing
COLOR_CHECKSUM_OK, //valid CRC/checksum
COLOR_CHECKSUM_BAD, //invalid CRC/checksum
COLOR_ERROR, //malformed traffic
COLOR_IDLE, //downtime between frames

STANDARD_COLOR_COUNT
};

extern Gdk::Color colors[STANDARD_COLOR_COUNT];
}

#endif // StandardColors_h
13 changes: 12 additions & 1 deletion scopehal/Waveform.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#include <vector>
#include <AlignedAllocator.h>

#include "StandardColors.h"

/**
@brief Wrapper around a primitive data type that has an empty default constructor.
Expand Down Expand Up @@ -174,6 +176,16 @@ class WaveformBase
m_durations.resize(size);
}

virtual std::string GetText(size_t /*i*/)
{
return "(unimplemented)";
}

virtual Gdk::Color GetColor(size_t /*i*/)
{
return StandardColors::colors[StandardColors::COLOR_ERROR];
}

/**
@brief Copies offsets/durations from one waveform to another.
Expand Down Expand Up @@ -217,6 +229,5 @@ typedef Waveform<EmptyConstructorWrapper<bool> > DigitalWaveform;
typedef Waveform<EmptyConstructorWrapper<float>> AnalogWaveform;

typedef Waveform< std::vector<bool> > DigitalBusWaveform;
typedef Waveform<char> AsciiWaveform;

#endif
23 changes: 9 additions & 14 deletions scopeprotocols/ADL5205Decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void ADL5205Decoder::Refresh()
size_t len = din->m_samples.size();

//Loop over the SPI events and process stuff
auto cap = new ADL5205Waveform;
auto cap = new ADL5205Waveform(m_displaycolor);
cap->m_timescale = din->m_timescale;
cap->m_startTimestamp = din->m_startTimestamp;
cap->m_startFemtoseconds = din->m_startFemtoseconds;
Expand Down Expand Up @@ -154,23 +154,18 @@ void ADL5205Decoder::Refresh()
SetData(cap, 0);
}

Gdk::Color ADL5205Decoder::GetColor(size_t /*i*/, size_t /*stream*/)
Gdk::Color ADL5205Waveform::GetColor(size_t /*i*/)
{
return Gdk::Color(m_displaycolor);
return Gdk::Color(m_color);
}

string ADL5205Decoder::GetText(size_t i, size_t /*stream*/)
string ADL5205Waveform::GetText(size_t i)
{
auto capture = dynamic_cast<ADL5205Waveform*>(GetData(0));
if(capture != NULL)
{
const ADL5205Symbol& s = capture->m_samples[i];
const ADL5205Symbol& s = m_samples[i];

char tmp[128];
snprintf(tmp, sizeof(tmp), "%s: FA=%d dB, gain=%d dB",
s.m_write ? "write" : "read", s.m_fa, s.m_gain);
return string(tmp);
}
return "";
char tmp[128];
snprintf(tmp, sizeof(tmp), "%s: FA=%d dB, gain=%d dB",
s.m_write ? "write" : "read", s.m_fa, s.m_gain);
return string(tmp);
}

14 changes: 10 additions & 4 deletions scopeprotocols/ADL5205Decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,22 @@ class ADL5205Symbol
}
};

typedef Waveform<ADL5205Symbol> ADL5205Waveform;
class ADL5205Waveform : public Waveform<ADL5205Symbol>
{
public:
ADL5205Waveform (const std::string& color) : Waveform<ADL5205Symbol>(), m_color(color) {};
virtual std::string GetText(size_t) override;
virtual Gdk::Color GetColor(size_t) override;

private:
const std::string& m_color;
};

class ADL5205Decoder : public Filter
{
public:
ADL5205Decoder(const std::string& color);

virtual std::string GetText(size_t i, size_t stream);
virtual Gdk::Color GetColor(size_t i, size_t stream);

virtual void Refresh();

static std::string GetProtocolName();
Expand Down

0 comments on commit 0367608

Please sign in to comment.