Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: b032de744d9f
Choose a base ref
...
head repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 5265d8311585
Choose a head ref
  • 1 commit
  • 9 files changed
  • 1 contributor

Commits on May 11, 2020

  1. Copy the full SHA
    5265d83 View commit details
5 changes: 5 additions & 0 deletions scopehal/Unit.cpp
Original file line number Diff line number Diff line change
@@ -134,6 +134,11 @@ string Unit::PrettyPrint(double value)
scale = "";
value_rescaled = value;
break;
case UNIT_COUNTS:
unit = "";
scale = "";
value_rescaled = value; //TODO: scientific notation flag?
break;

default:
return "Invalid unit";
3 changes: 2 additions & 1 deletion scopehal/Unit.h
Original file line number Diff line number Diff line change
@@ -53,7 +53,8 @@ class Unit
UNIT_OHMS, //Resistance
UNIT_BITRATE, //Bits per second
UNIT_PERCENT, //Dimensionless ratio
UNIT_DB //Dimensionless ratio
UNIT_DB, //Dimensionless ratio
UNIT_COUNTS //Dimensionless ratio (histogram)

//TODO: more here
};
1 change: 1 addition & 0 deletions scopeprotocols/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ set(SCOPEPROTOCOLS_SOURCES
FallMeasurementDecoder.cpp
FFTDecoder.cpp
FrequencyMeasurementDecoder.cpp
HorizontalBathtubDecoder.cpp
I2CDecoder.cpp
IBM8b10bDecoder.cpp
JtagDecoder.cpp
17 changes: 14 additions & 3 deletions scopeprotocols/EyeDecoder2.cpp
Original file line number Diff line number Diff line change
@@ -36,9 +36,11 @@ using namespace std;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Construction / destruction

EyeCapture2::EyeCapture2(size_t width, size_t height)
EyeCapture2::EyeCapture2(size_t width, size_t height, float center)
: m_width(width)
, m_height(height)
, m_totalUIs(0)
, m_centerVoltage(center)
{
size_t npix = width*height;
m_accumdata = new int64_t[npix];
@@ -48,6 +50,8 @@ EyeCapture2::EyeCapture2(size_t width, size_t height)
m_outdata[i] = 0;
m_accumdata[i] = 0;
}

m_uiWidth = 1;
}

EyeCapture2::~EyeCapture2()
@@ -377,10 +381,13 @@ void EyeDecoder2::Refresh()
//TODO: timestamps? do we need those?
EyeCapture2* cap = dynamic_cast<EyeCapture2*>(m_data);
if(cap == NULL)
cap = new EyeCapture2(m_width, m_height);
cap = new EyeCapture2(m_width, m_height, 0); //TODO: make center configurable (scopehal:#1)
cap->m_timescale = 1;
int64_t* data = cap->GetAccumData();

//Midpoint of the eye voltage
double center = cap->GetCenterVoltage();

//Process the eye
size_t iclock = 0;
double awidth = 0;
@@ -416,7 +423,7 @@ void EyeDecoder2::Refresh()
//LogDebug("offset = %ld, twidth = %ld\n",offset, twidth);

//Find (and sanity check) the Y coordinate
size_t pixel_y = round( (samp.m_sample * yscale) + ymid );
size_t pixel_y = round( ((samp.m_sample - center) * yscale) + ymid );
if(pixel_y >= m_height)
continue;
int64_t* row = data + pixel_y*m_width;
@@ -441,6 +448,10 @@ void EyeDecoder2::Refresh()
}
}
m_uiWidth = round(awidth / nwidth);
cap->m_uiWidth = m_uiWidth;

//Count total number of UIs we've integrated
cap->IntegrateUIs(clock->GetDepth());

cap->Normalize();
SetData(cap);
23 changes: 22 additions & 1 deletion scopeprotocols/EyeDecoder2.h
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@
class EyeCapture2 : public CaptureChannelBase
{
public:
EyeCapture2(size_t width, size_t height);
EyeCapture2(size_t width, size_t height, float center);
virtual ~EyeCapture2();

float* GetData()
@@ -50,13 +50,33 @@ class EyeCapture2 : public CaptureChannelBase

void Normalize();

size_t GetTotalUIs()
{ return m_totalUIs; }

float GetCenterVoltage()
{ return m_centerVoltage; }

size_t GetHeight()
{ return m_height; }

size_t GetWidth()
{ return m_width; }

void IntegrateUIs(size_t uis)
{ m_totalUIs += uis; }

float m_uiWidth;

protected:
size_t m_width;
size_t m_height;

float* m_outdata;
int64_t* m_accumdata;

size_t m_totalUIs;
float m_centerVoltage;

public:
//Not really applicable for eye patterns, but...
virtual size_t GetDepth() const;
@@ -84,6 +104,7 @@ class EyeDecoder2 : public ProtocolDecoder

virtual double GetVoltageRange();

//TODO: this should be a property of the capture, not the decode
int64_t GetUIWidth()
{ return m_uiWidth; }

164 changes: 164 additions & 0 deletions scopeprotocols/HorizontalBathtubDecoder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/***********************************************************************************************************************
* *
* ANTIKERNEL v0.1 *
* *
* Copyright (c) 2012-2020 Andrew D. Zonenberg *
* 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 "scopeprotocols.h"
#include "HorizontalBathtubDecoder.h"

using namespace std;

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

HorizontalBathtubDecoder::HorizontalBathtubDecoder(string color)
: ProtocolDecoder(OscilloscopeChannel::CHANNEL_TYPE_ANALOG, color, CAT_ANALYSIS)
{
m_yAxisUnit = Unit(Unit::UNIT_COUNTS);

//Set up channels
m_signalNames.push_back("din");
m_channels.push_back(NULL);

m_midpoint = 0.5;
m_range = 1;

m_voltageName = "Voltage";
m_parameters[m_voltageName] = ProtocolDecoderParameter(ProtocolDecoderParameter::TYPE_FLOAT);
m_parameters[m_voltageName].SetFloatVal(0);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory methods

bool HorizontalBathtubDecoder::ValidateChannel(size_t i, OscilloscopeChannel* channel)
{
if( (i == 0) && (dynamic_cast<EyeDecoder2*>(channel) != NULL) )
return true;
return false;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Accessors

void HorizontalBathtubDecoder::SetDefaultName()
{
char hwname[256];
snprintf(hwname, sizeof(hwname), "HBathtub(%s, %.2f)",
m_channels[0]->m_displayname.c_str(),
m_parameters[m_voltageName].GetFloatVal()
);
m_hwname = hwname;
m_displayname = m_hwname;
}

string HorizontalBathtubDecoder::GetProtocolName()
{
return "Horz Bathtub";
}

bool HorizontalBathtubDecoder::IsOverlay()
{
//we create a new analog channel
return false;
}

bool HorizontalBathtubDecoder::NeedsConfig()
{
return true;
}

double HorizontalBathtubDecoder::GetVoltageRange()
{
return m_range;
}

double HorizontalBathtubDecoder::GetOffset()
{
return -m_midpoint;
}

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

void HorizontalBathtubDecoder::Refresh()
{
//Get the input data
if(m_channels[0] == NULL)
{
SetData(NULL);
return;
}
EyeCapture2* din = dynamic_cast<EyeCapture2*>(m_channels[0]->GetData());
if(din == NULL)
{
SetData(NULL);
return;
}

float threshold = m_parameters[m_voltageName].GetFloatVal();

//Find the eye bin for this height
float yscale = din->GetHeight() / m_channels[0]->GetVoltageRange();
float ymid = din->GetHeight()/2;
float center = din->GetCenterVoltage();

//Sanity check we're not off the eye
size_t ybin = round( (threshold-center)*yscale + ymid);
if(ybin >= din->GetHeight())
return;

//Horizontal scale: one eye is two UIs wide
double ps_per_width = 2*din->m_uiWidth;
double ps_per_pixel = ps_per_width / din->GetWidth();

//Create the output
AnalogCapture* cap = new AnalogCapture;

//Extract the single scanline we're interested in
int64_t* row = din->GetAccumData() + ybin*din->GetWidth();
m_range = 0;
for(size_t i=0; i<din->GetWidth(); i++)
{
int64_t sample = row[i];
if(sample > m_range)
m_range = sample;

cap->m_samples.push_back(AnalogSample(i*ps_per_pixel - din->m_uiWidth, ps_per_pixel, sample));
}

//Scale so we don't quite touch the edges of the plot
m_range *= 1.05;
m_midpoint = m_range/2;

SetData(cap);

//Copy start time etc from the input. Timestamps are in picoseconds.
cap->m_timescale = din->m_timescale;
cap->m_startTimestamp = din->m_startTimestamp;
cap->m_startPicoseconds = din->m_startPicoseconds;
}
67 changes: 67 additions & 0 deletions scopeprotocols/HorizontalBathtubDecoder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/***********************************************************************************************************************
* *
* ANTIKERNEL v0.1 *
* *
* Copyright (c) 2012-2020 Andrew D. Zonenberg *
* 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. *
* *
***********************************************************************************************************************/

/**
@file
@author Andrew D. Zonenberg
@brief Declaration of HorizontalBathtubDecoder
*/
#ifndef HorizontalBathtubDecoder_h
#define HorizontalBathtubDecoder_h

#include "../scopehal/ProtocolDecoder.h"

class HorizontalBathtubDecoder : public ProtocolDecoder
{
public:
HorizontalBathtubDecoder(std::string color);

virtual void Refresh();

virtual bool NeedsConfig();
virtual bool IsOverlay();

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

virtual double GetVoltageRange();
virtual double GetOffset();

virtual bool ValidateChannel(size_t i, OscilloscopeChannel* channel);

PROTOCOL_DECODER_INITPROC(HorizontalBathtubDecoder)

protected:
std::string m_voltageName;

double m_midpoint;
double m_range;
};

#endif
1 change: 1 addition & 0 deletions scopeprotocols/scopeprotocols.cpp
Original file line number Diff line number Diff line change
@@ -60,6 +60,7 @@ void ScopeProtocolStaticInit()
AddDecoderClass(FallMeasurementDecoder);
AddDecoderClass(FFTDecoder);
AddDecoderClass(FrequencyMeasurementDecoder);
AddDecoderClass(HorizontalBathtubDecoder);
AddDecoderClass(IBM8b10bDecoder);
AddDecoderClass(I2CDecoder);
AddDecoderClass(JtagDecoder);
1 change: 1 addition & 0 deletions scopeprotocols/scopeprotocols.h
Original file line number Diff line number Diff line change
@@ -61,6 +61,7 @@
#include "FallMeasurementDecoder.h"
#include "FFTDecoder.h"
#include "FrequencyMeasurementDecoder.h"
#include "HorizontalBathtubDecoder.h"
#include "IBM8b10bDecoder.h"
#include "I2CDecoder.h"
#include "JtagDecoder.h"