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: 89af3a78732f
Choose a base ref
...
head repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 4daa10974e2c
Choose a head ref
  • 2 commits
  • 9 files changed
  • 1 contributor

Commits on Mar 14, 2020

  1. Copy the full SHA
    3d6ed37 View commit details
  2. Copy the full SHA
    4daa109 View commit details
Showing with 215 additions and 79 deletions.
  1. +74 −0 scopehal/Bijection.h
  2. +71 −0 scopehal/IDTable.h
  3. +3 −24 scopehal/Measurement.cpp
  4. +1 −1 scopehal/Measurement.h
  5. +45 −18 scopehal/Oscilloscope.cpp
  6. +6 −11 scopehal/Oscilloscope.h
  7. +7 −24 scopehal/ProtocolDecoder.cpp
  8. +6 −1 scopehal/ProtocolDecoder.h
  9. +2 −0 scopehal/scopehal.h
74 changes: 74 additions & 0 deletions scopehal/Bijection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/***********************************************************************************************************************
* *
* 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 Bijection class
*/
#ifndef Bijection_h
#define Bijection_h

/**
@brief A one-to-one mapping from objects of type T1 to type T2, which must be different types
For now insert-only, elements can be inserted or iterated but not removed.
*/
template<class T1, class T2>
class Bijection
{
public:

typedef std::map<T1, T2> forwardType;
typedef std::map<T2, T1> reverseType;

typename forwardType::const_iterator begin()
{ return m_forwardMap.begin(); }

typename forwardType::const_iterator end()
{ return m_forwardMap.end(); }

void emplace(T1 a, T2 b)
{
m_forwardMap[a] = b;
m_reverseMap[b] = a;
}

const T1& operator[](T2 key)
{ return m_reverseMap[key]; }

const T2& operator[](T1 key)
{ return m_forwardMap[key]; }

protected:
forwardType m_forwardMap;
reverseType m_reverseMap;
};

#endif
71 changes: 71 additions & 0 deletions scopehal/IDTable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/***********************************************************************************************************************
* *
* 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 IDTable class
*/
#ifndef IDTable_h
#define IDTable_h

class IDTable : public Bijection<int, void*>
{
public:
IDTable()
: m_nextID(1)
{
emplace(0, NULL);
}

int emplace(void* p)
{
if(HasID(p))
return m_reverseMap[p];

int id = m_nextID ++;
Bijection::emplace(id, p);
return id;
}

void emplace(int id, void* p)
{
Bijection::emplace(id, p);
}

bool HasID(void* p)
{
return (m_reverseMap.find(p) != m_reverseMap.end());
}

protected:
int m_nextID;
};

#endif
27 changes: 3 additions & 24 deletions scopehal/Measurement.cpp
Original file line number Diff line number Diff line change
@@ -566,24 +566,13 @@ string FloatMeasurement::GetValueAsString()
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Serialization

string Measurement::SerializeConfiguration(std::map<void*, int>& idmap, int& nextID, string nick)
string Measurement::SerializeConfiguration(IDTable& table, string nick)
{
//Name ourself. Note that serialization may not be topologically sorted!
//It's possible another measurement may depend on us, and allocate an ID for us in advance
int id;
if(idmap.find(this) == idmap.end())
{
id = nextID ++;
idmap[this] = id;
}
else
id = idmap[this];

//Save basic info
char tmp[1024];
snprintf(tmp, sizeof(tmp), " : %%\n");
string config = tmp;
snprintf(tmp, sizeof(tmp), " id: %d\n", id);
snprintf(tmp, sizeof(tmp), " id: %d\n", table.emplace(this));
config += tmp;

//Config
@@ -601,17 +590,7 @@ string Measurement::SerializeConfiguration(std::map<void*, int>& idmap, int& nex
if(chan == NULL)
snprintf(tmp, sizeof(tmp), " %s: 0\n", m_signalNames[i].c_str());
else
{
if(idmap.find(chan) == idmap.end())
{
id = nextID ++;
idmap[chan] = id;
}
else
id = idmap[chan];

snprintf(tmp, sizeof(tmp), " %-20s %d\n", (m_signalNames[i] + ":").c_str(), id);
}
snprintf(tmp, sizeof(tmp), " %-20s %d\n", (m_signalNames[i] + ":").c_str(), table.emplace(chan));

config += tmp;
}
2 changes: 1 addition & 1 deletion scopehal/Measurement.h
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@ class Measurement
/**
@brief Serialize this measurement's configuration to a string
*/
virtual std::string SerializeConfiguration(std::map<void*, int>& idmap, int& nextID, std::string nick);
virtual std::string SerializeConfiguration(IDTable& table, std::string nick);

protected:

63 changes: 45 additions & 18 deletions scopehal/Oscilloscope.cpp
Original file line number Diff line number Diff line change
@@ -68,14 +68,6 @@ Oscilloscope::~Oscilloscope()
m_pendingWaveforms.clear();
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// File loading

void Oscilloscope::LoadConfiguration(const YAML::Node& node, std::map<void*, int>& idmap)
{
LogDebug("load config\n");
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Enumeration

@@ -192,17 +184,13 @@ bool Oscilloscope::AcquireDataFifo()
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Serialization

string Oscilloscope::SerializeConfiguration(map<void*, int>& idmap, int& nextID)
string Oscilloscope::SerializeConfiguration(IDTable& table)
{
//Name ourself
int id = nextID ++;
idmap[this] = id;

//Save basic scope info
char tmp[1024];
snprintf(tmp, sizeof(tmp), " : \n");
string config = tmp;
snprintf(tmp, sizeof(tmp), " id: %d\n", id);
snprintf(tmp, sizeof(tmp), " id: %d\n", table.emplace(this));
config += tmp;
snprintf(tmp, sizeof(tmp), " nick: \"%s\"\n", m_nickname.c_str());
config += tmp;
@@ -227,13 +215,10 @@ string Oscilloscope::SerializeConfiguration(map<void*, int>& idmap, int& nextID)
if(!chan->IsPhysicalChannel())
continue; //skip any kind of math functions etc

id = nextID ++;
idmap[chan] = id;

//Basic channel info
snprintf(tmp, sizeof(tmp), " : \n");
config += tmp;
snprintf(tmp, sizeof(tmp), " id: %d\n", id);
snprintf(tmp, sizeof(tmp), " id: %d\n", table.emplace(chan));
config += tmp;
snprintf(tmp, sizeof(tmp), " index: %zu\n", i);
config += tmp;
@@ -300,5 +285,47 @@ string Oscilloscope::SerializeConfiguration(map<void*, int>& idmap, int& nextID)
}
}

//TODO: Serialize trigger and timebase configuration

return config;
}

void Oscilloscope::LoadConfiguration(const YAML::Node& node, IDTable& table)
{
//Currently no global config to load (TODO: triggers)

//Load the channels
auto& chans = node["channels"];
for(auto it : chans)
{
auto& cnode = it.second;
auto chan = m_channels[cnode["index"].as<int>()];
table.emplace(cnode["id"].as<int>(), chan);

//Ignore name/type.
//These are only needed for offline scopes to create a representation of the original instrument.

chan->m_displaycolor = cnode["color"].as<string>();
chan->m_displayname = cnode["nick"].as<string>();

if(cnode["enabled"].as<int>())
chan->Enable();
else
chan->Disable();

string coupling = cnode["coupling"].as<string>();
if(coupling == "dc_50")
chan->SetCoupling(OscilloscopeChannel::COUPLE_DC_50);
else if(coupling == "dc_1M")
chan->SetCoupling(OscilloscopeChannel::COUPLE_DC_1M);
else if(coupling == "ac_1M")
chan->SetCoupling(OscilloscopeChannel::COUPLE_AC_1M);
else if(coupling == "gnd")
chan->SetCoupling(OscilloscopeChannel::COUPLE_GND);

chan->SetAttenuation(cnode["attenuation"].as<float>());
chan->SetBandwidthLimit(cnode["bwlimit"].as<int>());
chan->SetVoltageRange(cnode["vrange"].as<float>());
chan->SetOffset(cnode["offset"].as<float>());
}
}
17 changes: 6 additions & 11 deletions scopehal/Oscilloscope.h
Original file line number Diff line number Diff line change
@@ -54,11 +54,6 @@ class Oscilloscope : public virtual Instrument
Oscilloscope();
virtual ~Oscilloscope();

/**
@brief Load instrument and channel configuration from a save file
*/
virtual void LoadConfiguration(const YAML::Node& node, std::map<void*, int>& idmap);

/**
@brief Instruments are allowed to cache configuration settings to reduce round trip queries to the device.
@@ -405,14 +400,14 @@ class Oscilloscope : public virtual Instrument
/**
@brief Serializes this oscilloscope's configuration to a YAML string.
Both idmap and nextID are expected to be modified by this function.
@param idmap Map of pointers to integer IDs
@param nextID The next ID value to use
@return YAML block with this oscilloscope's configuration
*/
virtual std::string SerializeConfiguration(std::map<void*, int>& idmap, int& nextID);
virtual std::string SerializeConfiguration(IDTable& table);

/**
@brief Load instrument and channel configuration from a save file
*/
virtual void LoadConfiguration(const YAML::Node& node, IDTable& idmap);

public:
bool HasPendingWaveforms();
31 changes: 7 additions & 24 deletions scopehal/ProtocolDecoder.cpp
Original file line number Diff line number Diff line change
@@ -554,24 +554,18 @@ void ProtocolDecoder::FindZeroCrossings(AnalogCapture* data, float threshold, st
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Serialization

string ProtocolDecoder::SerializeConfiguration(std::map<void*, int>& idmap, int& nextID)
void ProtocolDecoder::LoadConfiguration(const YAML::Node& node, IDTable& table)
{
//Name ourself. Note that serialization may not be topologically sorted!
//It's possible another decoder may depend on us, and allocate an ID for us in advance
int id;
if(idmap.find(this) == idmap.end())
{
id = nextID ++;
idmap[this] = id;
}
else
id = idmap[this];

}

string ProtocolDecoder::SerializeConfiguration(IDTable& table)
{
//Save basic decode info
char tmp[1024];
snprintf(tmp, sizeof(tmp), " : \n");
string config = tmp;
snprintf(tmp, sizeof(tmp), " id: %d\n", id);
snprintf(tmp, sizeof(tmp), " id: %d\n", table.emplace(this));
config += tmp;

//Channel info
@@ -593,18 +587,7 @@ string ProtocolDecoder::SerializeConfiguration(std::map<void*, int>& idmap, int&
if(chan == NULL)
snprintf(tmp, sizeof(tmp), " %-20s 0\n", (m_signalNames[i] + ":").c_str());
else
{
if(idmap.find(chan) == idmap.end())
{
id = nextID ++;
idmap[chan] = id;
}
else
id = idmap[chan];

snprintf(tmp, sizeof(tmp), " %-20s %d\n", (m_signalNames[i] + ":").c_str(), id);
}

snprintf(tmp, sizeof(tmp), " %-20s %d\n", (m_signalNames[i] + ":").c_str(), table.emplace(chan));
config += tmp;
}

7 changes: 6 additions & 1 deletion scopehal/ProtocolDecoder.h
Original file line number Diff line number Diff line change
@@ -150,7 +150,12 @@ class ProtocolDecoder : public OscilloscopeChannel
/**
@brief Serialize this decoder's configuration to a string
*/
virtual std::string SerializeConfiguration(std::map<void*, int>& idmap, int& nextID);
virtual std::string SerializeConfiguration(IDTable& table);

/**
@brief Load configuration from a save file
*/
virtual void LoadConfiguration(const YAML::Node& node, IDTable& table);

protected:

Loading