Skip to content
Open
2 changes: 2 additions & 0 deletions scopehal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ set(SCOPEHAL_SOURCES
FunctionGeneratorChannel.cpp
Load.cpp
LoadChannel.cpp
MockInstrument.cpp
Multimeter.cpp
MultimeterChannel.cpp
Oscilloscope.cpp
Expand Down Expand Up @@ -173,6 +174,7 @@ set(SCOPEHAL_SOURCES
LeCroyFWPOscilloscope.cpp
MagnovaOscilloscope.cpp
MockOscilloscope.cpp
MockPowerSupply.cpp
MultiLaneBERT.cpp
NanoVNA.cpp
OwonXDGFunctionGenerator.cpp
Expand Down
5 changes: 5 additions & 0 deletions scopehal/Instrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ string Instrument::GetChannelDisplayName(size_t i)
return m_channels[i]->GetHwname();
}

bool Instrument::IsOffline()
{
return false;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Serialization

Expand Down
8 changes: 8 additions & 0 deletions scopehal/Instrument.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ class Instrument
*/
virtual std::string GetTransportName() =0;

/**
@brief Checks if the instrument is currently online.

@return False if the Instrument object is actively connected to a physical scope.
True if working offline, a file import, etc.
*/
virtual bool IsOffline();

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Channel enumeration and identification

Expand Down
128 changes: 128 additions & 0 deletions scopehal/MockInstrument.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/***********************************************************************************************************************
* *
* libscopehal *
* *
* Copyright (c) 2012-2026 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. *
* *
***********************************************************************************************************************/

/**
@file
@brief Implementation of MockInstrument

@ingroup psudrivers
*/

#include "scopehal.h"
#include "MockInstrument.h"

using namespace std;

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

/**
@brief Initialize the driver
*/
MockInstrument::MockInstrument(const string& name,
const string& vendor,
const string& serial,
const std::string& transport,
const std::string& driver,
const std::string& args)
: SCPIInstrument(nullptr, false)
, m_name(name)
, m_vendor(vendor)
, m_serial(serial)
, m_transportName(transport)
, m_driver(driver)
, m_args(args)
{
// Use a null transport
m_transport = new SCPINullTransport(args);

//Clear warnings after preload for mock instruments
m_preloaders.push_back(sigc::mem_fun(*this, &MockInstrument::ClearWarnings));

m_serializers.push_back(sigc::mem_fun(*this, &MockInstrument::DoSerializeConfiguration));
}

MockInstrument::~MockInstrument()
{

}

void MockInstrument::ClearWarnings(int /*version*/, const YAML::Node& node, IDTable& table, ConfigWarningList& warnings)
{ // No warnings necessary for Mock instruments
warnings.m_warnings.erase(this);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Information queries

bool MockInstrument::IsOffline()
{
return true;
}

string MockInstrument::GetTransportName()
{
return m_transportName;
}

string MockInstrument::GetTransportConnectionString()
{
return m_args;
}

void MockInstrument::SetTransportConnectionString(const string& args)
{
m_args = args;
}

string MockInstrument::GetName() const
{
return m_name;
}

string MockInstrument::GetVendor() const
{
return m_vendor;
}

string MockInstrument::GetSerial() const
{
return m_serial;
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Serialization

void MockInstrument::DoSerializeConfiguration(YAML::Node& node, IDTable& /*table*/)
{
node["transport"] = GetTransportName();
node["args"] = GetTransportConnectionString();
node["driver"] = GetDriverName();
}
92 changes: 92 additions & 0 deletions scopehal/MockInstrument.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/***********************************************************************************************************************
* *
* libscopehal *
* *
* Copyright (c) 2012-2026 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. *
* *
***********************************************************************************************************************/

/**
@file
@brief Declaration of MockInstrument

@ingroup psudrivers
*/

#ifndef MockInstrument_h
#define MockInstrument_h

/**
@brief Base class for simulated instruments
*/
class MockInstrument: public virtual SCPIInstrument
{
public:
MockInstrument(
const std::string& name,
const std::string& vendor,
const std::string& serial,
const std::string& transport,
const std::string& driver,
const std::string& args
);
virtual ~MockInstrument();

//Device information
virtual bool IsOffline() override;

virtual std::string GetTransportConnectionString() override;
virtual void SetTransportConnectionString(const std::string& args);
virtual std::string GetTransportName() override;

virtual std::string GetName() const override;
virtual std::string GetVendor() const override;
virtual std::string GetSerial() const override;

// Serialization
void DoSerializeConfiguration(YAML::Node& node, IDTable& table);
void ClearWarnings(int version, const YAML::Node& node, IDTable& idmap, ConfigWarningList& warnings);

// SCPI
virtual void BackgroundProcessing() override {}

protected:

//standard *IDN? fields
std::string m_name;
std::string m_vendor;
std::string m_serial;
std::string m_fwVersion;

//Simulated transport information
std::string m_transportName;
std::string m_driver;
std::string m_args;

public:
virtual std::string GetDriverName() const override
{ return m_driver; }
};

#endif
54 changes: 4 additions & 50 deletions scopehal/MockOscilloscope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* *
* libscopehal *
* *
* Copyright (c) 2012-2024 Andrew D. Zonenberg and contributors *
* Copyright (c) 2012-2026 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 *
Expand Down Expand Up @@ -49,19 +49,10 @@ MockOscilloscope::MockOscilloscope(
const string& serial,
const std::string& transport,
const std::string& driver,
const std::string& args)
: m_name(name)
, m_vendor(vendor)
, m_serial(serial)
, m_extTrigger(NULL)
, m_transport(transport)
, m_driver(driver)
, m_args(args)
const std::string& args) : SCPIDevice(nullptr, false), SCPIInstrument(nullptr, false), MockInstrument(name, vendor, serial, transport, driver, args)
{
//Need to run this loader prior to the main Oscilloscope loader
m_loaders.push_front(sigc::mem_fun(*this, &MockOscilloscope::DoLoadConfiguration));

m_serializers.push_back(sigc::mem_fun(*this, &MockOscilloscope::DoSerializeConfiguration));
m_preloaders.push_front(sigc::mem_fun(*this, &MockOscilloscope::DoPreLoadConfiguration));
}

MockOscilloscope::~MockOscilloscope()
Expand All @@ -72,26 +63,11 @@ MockOscilloscope::~MockOscilloscope()
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Information queries

bool MockOscilloscope::IsOffline()
{
return true;
}

string MockOscilloscope::IDPing()
{
return "";
}

string MockOscilloscope::GetTransportName()
{
return m_transport;
}

string MockOscilloscope::GetTransportConnectionString()
{
return m_args;
}

unsigned int MockOscilloscope::GetInstrumentTypes() const
{
return INST_OSCILLOSCOPE;
Expand All @@ -102,21 +78,6 @@ uint32_t MockOscilloscope::GetInstrumentTypesForChannel(size_t /*i*/) const
return Instrument::INST_OSCILLOSCOPE;
}

string MockOscilloscope::GetName() const
{
return m_name;
}

string MockOscilloscope::GetVendor() const
{
return m_vendor;
}

string MockOscilloscope::GetSerial() const
{
return m_serial;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Triggering

Expand Down Expand Up @@ -165,14 +126,7 @@ bool MockOscilloscope::IsTriggerArmed()
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Serialization

void MockOscilloscope::DoSerializeConfiguration(YAML::Node& node, IDTable& /*table*/)
{
node["transport"] = GetTransportName();
node["args"] = GetTransportConnectionString();
node["driver"] = GetDriverName();
}

void MockOscilloscope::DoLoadConfiguration(int /*version*/, const YAML::Node& node, IDTable& table)
void MockOscilloscope::DoPreLoadConfiguration(int /*version*/, const YAML::Node& node, IDTable& table, ConfigWarningList& /*warnings*/)
{
//Load the channels
auto& chans = node["channels"];
Expand Down
Loading