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

Commits on May 7, 2019

  1. Copy the full SHA
    1e547eb View commit details
Showing with 202 additions and 0 deletions.
  1. +1 −0 scopeprotocols/CMakeLists.txt
  2. +136 −0 scopeprotocols/DCOffsetDecoder.cpp
  3. +63 −0 scopeprotocols/DCOffsetDecoder.h
  4. +1 −0 scopeprotocols/scopeprotocols.cpp
  5. +1 −0 scopeprotocols/scopeprotocols.h
1 change: 1 addition & 0 deletions scopeprotocols/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ link_directories(${GTKMM_LIBRARY_DIRS} ${SIGCXX_LIBRARY_DIRS})
set(SCOPEPROTOCOLS_SOURCES
ACCoupleDecoder.cpp
ClockRecoveryDecoder.cpp
DCOffsetDecoder.cpp
DifferenceDecoder.cpp
Ethernet10BaseTDecoder.cpp
Ethernet100BaseTDecoder.cpp
136 changes: 136 additions & 0 deletions scopeprotocols/DCOffsetDecoder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/***********************************************************************************************************************
* *
* ANTIKERNEL v0.1 *
* *
* Copyright (c) 2012-2019 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 "../scopehal/scopehal.h"
#include "DCOffsetDecoder.h"
#include "../scopehal/AnalogRenderer.h"

using namespace std;

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

DCOffsetDecoder::DCOffsetDecoder(string color)
: ProtocolDecoder(OscilloscopeChannel::CHANNEL_TYPE_ANALOG, color, CAT_MATH)
{
//Set up channels
m_signalNames.push_back("din");
m_channels.push_back(NULL);

m_offsetname = "Offset";
m_parameters[m_offsetname] = ProtocolDecoderParameter(ProtocolDecoderParameter::TYPE_FLOAT);
m_parameters[m_offsetname].SetFloatVal(0);
}

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

ChannelRenderer* DCOffsetDecoder::CreateRenderer()
{
return new AnalogRenderer(this);
}

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

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

double DCOffsetDecoder::GetVoltageRange()
{
return m_channels[0]->GetVoltageRange();
}

string DCOffsetDecoder::GetProtocolName()
{
return "DC offset";
}

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

bool DCOffsetDecoder::NeedsConfig()
{
//we need the offset to be specified, duh
return true;
}

void DCOffsetDecoder::SetDefaultName()
{
char hwname[256];
float offset = m_parameters[m_offsetname].GetFloatVal();
if(offset >= 0)
snprintf(hwname, sizeof(hwname), "%s + %.3f", m_channels[0]->m_displayname.c_str(), offset);
else
snprintf(hwname, sizeof(hwname), "%s %.3f", m_channels[0]->m_displayname.c_str(), offset);
m_hwname = hwname;
m_displayname = m_hwname;
}

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

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

//We need meaningful data
if(din->GetDepth() == 0)
{
SetData(NULL);
return;
}

float offset = m_parameters[m_offsetname].GetFloatVal();

//Subtract all of our samples
AnalogCapture* cap = new AnalogCapture;
for(size_t i=0; i<din->m_samples.size(); i++)
{
AnalogSample sin = din->m_samples[i];
cap->m_samples.push_back(AnalogSample(sin.m_offset, sin.m_duration, sin.m_sample + offset));
}
SetData(cap);

//Copy our time scales from the input
cap->m_timescale = din->m_timescale;
}
63 changes: 63 additions & 0 deletions scopeprotocols/DCOffsetDecoder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/***********************************************************************************************************************
* *
* ANTIKERNEL v0.1 *
* *
* Copyright (c) 2012-2019 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 DCOffsetDecoder
*/
#ifndef DCOffsetDecoder_h
#define DCOffsetDecoder_h

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

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

virtual void Refresh();
virtual ChannelRenderer* CreateRenderer();

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

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

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

PROTOCOL_DECODER_INITPROC(DCOffsetDecoder)

protected:
std::string m_offsetname;
};

#endif
1 change: 1 addition & 0 deletions scopeprotocols/scopeprotocols.cpp
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@ void ScopeProtocolStaticInit()
{
AddDecoderClass(ACCoupleDecoder);
AddDecoderClass(ClockRecoveryDecoder);
AddDecoderClass(DCOffsetDecoder);
AddDecoderClass(DifferenceDecoder);
AddDecoderClass(Ethernet10BaseTDecoder);
AddDecoderClass(Ethernet100BaseTDecoder);
1 change: 1 addition & 0 deletions scopeprotocols/scopeprotocols.h
Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@

#include "ACCoupleDecoder.h"
#include "ClockRecoveryDecoder.h"
#include "DCOffsetDecoder.h"
#include "DifferenceDecoder.h"
#include "EthernetAutonegotiationDecoder.h"
#include "EthernetProtocolDecoder.h"