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: c4409184fa99
Choose a base ref
...
head repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c7c77ed95303
Choose a head ref
  • 1 commit
  • 11 files changed
  • 1 contributor

Commits on May 23, 2020

  1. Copy the full SHA
    c7c77ed View commit details
16 changes: 14 additions & 2 deletions scopehal/ProtocolDecoder.cpp
Original file line number Diff line number Diff line change
@@ -80,7 +80,11 @@ void ProtocolDecoderParameter::ParseString(string str)
else if(suffix == 'm')
scale = 0.001f;
else if(suffix == 'u') //TODO: handle μ
scale = 0.000001f;
scale = 1e-6f;
else if(suffix == 'n')
scale = 1e-9f;
else if(suffix == 'p')
scale = 1e-12f;
}

switch(m_type)
@@ -125,8 +129,16 @@ string ProtocolDecoderParameter::ToString()
snprintf(str_out, sizeof(str_out), "%f M", m_floatval / 1000000.0f);
else if(fabs(m_floatval) > 1000.0f)
snprintf(str_out, sizeof(str_out), "%f k", m_floatval / 1000.0f);
else
else if(fabs(m_floatval) > 1)
snprintf(str_out, sizeof(str_out), "%f", m_floatval);
else if(fabs(m_floatval) > 1e-3)
snprintf(str_out, sizeof(str_out), "%f m", m_floatval * 1e3f);
else if(fabs(m_floatval) > 1e-6)
snprintf(str_out, sizeof(str_out), "%f u", m_floatval * 1e6f);
else if(fabs(m_floatval) > 1e-9)
snprintf(str_out, sizeof(str_out), "%f n", m_floatval * 1e9f);
else
snprintf(str_out, sizeof(str_out), "%f p", m_floatval * 1e12f);
break;
case TYPE_BOOL:
case TYPE_INT:
1 change: 0 additions & 1 deletion scopemeasurements/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ include_directories(${GTKMM_INCLUDE_DIRS} ${SIGCXX_INCLUDE_DIRS})
link_directories(${GTKMM_LIBRARY_DIRS} ${SIGCXX_LIBRARY_DIRS})

set(SCOPEMEASUREMENTS_SOURCES
#EyeHeightMeasurement.cpp
#OvershootMeasurement.cpp
#PkPkVoltageMeasurement.cpp
#UndershootMeasurement.cpp
123 changes: 0 additions & 123 deletions scopemeasurements/EyeHeightMeasurement.cpp

This file was deleted.

1 change: 0 additions & 1 deletion scopemeasurements/scopemeasurements.cpp
Original file line number Diff line number Diff line change
@@ -43,7 +43,6 @@
void ScopeMeasurementStaticInit()
{
/*
AddMeasurementClass(EyeHeightMeasurement);
AddMeasurementClass(OvershootMeasurement);
AddMeasurementClass(PkPkVoltageMeasurement);
AddMeasurementClass(UndershootMeasurement);
1 change: 0 additions & 1 deletion scopemeasurements/scopemeasurements.h
Original file line number Diff line number Diff line change
@@ -40,7 +40,6 @@
#include "../scopehal/Waveform.h"
#include "../scopehal/Measurement.h"

#include "EyeHeightMeasurement.h"
#include "OvershootMeasurement.h"
#include "PkPkVoltageMeasurement.h"
#include "UndershootMeasurement.h"
1 change: 1 addition & 0 deletions scopeprotocols/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ set(SCOPEPROTOCOLS_SOURCES
EthernetProtocolDecoder.cpp
EyeBitRateMeasurementDecoder.cpp
EyeDecoder2.cpp
EyeHeightMeasurementDecoder.cpp
EyeJitterMeasurementDecoder.cpp
EyePeriodMeasurementDecoder.cpp
EyeWidthMeasurementDecoder.cpp
210 changes: 210 additions & 0 deletions scopeprotocols/EyeHeightMeasurementDecoder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
/***********************************************************************************************************************
* *
* 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 "EyeHeightMeasurementDecoder.h"
#include "EyeDecoder2.h"
#include <algorithm>

using namespace std;

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

EyeHeightMeasurementDecoder::EyeHeightMeasurementDecoder(string color)
: ProtocolDecoder(OscilloscopeChannel::CHANNEL_TYPE_ANALOG, color, CAT_MEASUREMENT)
{
m_xAxisUnit = Unit(Unit::UNIT_PS);
m_yAxisUnit = Unit(Unit::UNIT_VOLTS);

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

m_startname = "Begin Time";
m_parameters[m_startname] = ProtocolDecoderParameter(ProtocolDecoderParameter::TYPE_FLOAT);
m_parameters[m_startname].SetFloatVal(0);

m_endname = "End Time";
m_parameters[m_endname] = ProtocolDecoderParameter(ProtocolDecoderParameter::TYPE_FLOAT);
m_parameters[m_endname].SetFloatVal(0);

m_posname = "Midpoint Voltage";
m_parameters[m_posname] = ProtocolDecoderParameter(ProtocolDecoderParameter::TYPE_FLOAT);
m_parameters[m_posname].SetFloatVal(0);

m_min = 0;
m_max = 1;
}

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

bool EyeHeightMeasurementDecoder::ValidateChannel(size_t i, OscilloscopeChannel* channel)
{
if( (i == 0) && (channel->GetType() == OscilloscopeChannel::CHANNEL_TYPE_EYE) )
return true;
return false;
}

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

void EyeHeightMeasurementDecoder::SetDefaultName()
{
float vstart = m_parameters[m_startname].GetFloatVal();
float vend = m_parameters[m_endname].GetFloatVal();

char hwname[256];
snprintf(hwname, sizeof(hwname), "EyeHeight(%s, %.2f, %.2f)",
m_channels[0]->m_displayname.c_str(),
vstart,
vend);
m_hwname = hwname;
m_displayname = m_hwname;
}

string EyeHeightMeasurementDecoder::GetProtocolName()
{
return "Eye Height";
}

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

bool EyeHeightMeasurementDecoder::NeedsConfig()
{
//need manual config
return true;
}

double EyeHeightMeasurementDecoder::GetVoltageRange()
{
return m_max - m_min;
}

double EyeHeightMeasurementDecoder::GetOffset()
{
return - (m_min + m_max)/2;
}

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

void EyeHeightMeasurementDecoder::Refresh()
{
//Get the input data
if(m_channels[0] == NULL)
return;
auto din = dynamic_cast<EyeWaveform*>(m_channels[0]->GetData());
if(din == NULL)
return;

//Create the output
auto cap = new AnalogWaveform;

//Make sure times are in the right order, and convert from seconds to picoseconds
float tstart = m_parameters[m_startname].GetFloatVal() * 1e12;
float tend = m_parameters[m_endname].GetFloatVal() * 1e12;
if(tstart > tend)
{
float tmp = tstart;
tstart = tend;
tend = tmp;
}

//Convert times to bins
size_t width_bins = din->GetWidth();
float width_ps = din->m_uiWidth * 2;
float ps_per_bin = width_ps / width_bins;

//Find start/end time bins
size_t start_bin = round((tstart + din->m_uiWidth) / ps_per_bin);
size_t end_bin = round((tend + din->m_uiWidth) / ps_per_bin);
start_bin = min(start_bin, din->GetWidth());
end_bin = min(end_bin, din->GetWidth());

//Approximate center of the eye opening
float vrange = m_channels[0]->GetVoltageRange();
size_t height = din->GetHeight();
float volts_per_row = vrange / height;
float volts_at_bottom = din->GetCenterVoltage() - vrange/2;
float vmid = m_parameters[m_posname].GetFloatVal();
size_t mid_bin = round( (vmid - volts_at_bottom) / volts_per_row);
mid_bin = min(mid_bin, din->GetHeight()-1);

m_min = FLT_MAX;
m_max = 0;

float* data = din->GetData();
int64_t w = din->GetWidth();
float ber_max = FLT_EPSILON;
for(size_t x = start_bin; x <= end_bin; x ++)
{
//Search up and down from the midpoint to find the edges of the eye opening
size_t top_bin = mid_bin;
for(; top_bin < height; top_bin ++)
{
if(data[top_bin*w + x] > ber_max)
break;
}

size_t bot_bin = mid_bin;
for(; bot_bin > 0; bot_bin --)
{
if(data[bot_bin*w + x] > ber_max)
break;
}

//Convert from eye bins to volts
size_t height_bins = top_bin - bot_bin;
float height_volts = volts_per_row * height_bins;

//Output waveform generation
cap->m_offsets.push_back(round( (x*ps_per_bin) - din->m_uiWidth ));
cap->m_durations.push_back(round(ps_per_bin));
cap->m_samples.push_back(height_volts);
m_min = min(height_volts, m_min);
m_max = max(height_volts, m_max);
}

//Add some margin to the graph
m_min -= 0.025;
m_max += 0.025;

SetData(cap);

//Copy start time etc from the input. Timestamps are in picoseconds.
cap->m_timescale = 1;
cap->m_startTimestamp = din->m_startTimestamp;
cap->m_startPicoseconds = din->m_startPicoseconds;
}
Loading