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

Commits on Feb 10, 2020

  1. Copy the full SHA
    4c85bd0 View commit details
  2. Copy the full SHA
    d48dec1 View commit details
  3. Copy the full SHA
    2341138 View commit details
  4. Copy the full SHA
    ef7afd2 View commit details
  5. Copy the full SHA
    eee3219 View commit details
350 changes: 350 additions & 0 deletions scopehal/AntikernelLogicAnalyzer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,350 @@
/***********************************************************************************************************************
* *
* 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 Implementation of AntikernelLogicAnalyzer
*/

#include "scopehal.h"
#include "OscilloscopeChannel.h"
#include "AntikernelLogicAnalyzer.h"
#include "ProtocolDecoder.h"

using namespace std;

enum opcodes_t
{
CMD_NOP,
CMD_SET_MATCH_ALL,
CMD_SET_TRIG_OFFSET,
CMD_SET_TRIG_MODE,
CMD_SET_COMPARE_TARGET,
CMD_ARM,
CMD_STOP,
CMD_FORCE,
CMD_GET_STATUS,
CMD_GET_NAME_LEN,
CMD_GET_CHANNEL_COUNT,
CMD_GET_NAME,
CMD_GET_WIDTH
};

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

/**
@brief Connects to a UART and reads the stuff off it
*/
AntikernelLogicAnalyzer::AntikernelLogicAnalyzer(SCPITransport* transport)
{
m_transport = transport;

//TODO: read IDN info some other way, since it's not really scpi

LoadChannels();
ResetTriggerConditions();
}

AntikernelLogicAnalyzer::~AntikernelLogicAnalyzer()
{

}

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

void AntikernelLogicAnalyzer::SendCommand(uint8_t opcode)
{
m_transport->SendRawData(1, &opcode);
}

void AntikernelLogicAnalyzer::SendCommand(uint8_t opcode, uint8_t chan)
{
uint8_t buf[2] = {opcode, chan};
m_transport->SendRawData(2, buf);
}

uint8_t AntikernelLogicAnalyzer::Read1ByteReply()
{
uint8_t ret;
m_transport->ReadRawData(1, &ret);
return ret;
}

unsigned int AntikernelLogicAnalyzer::GetInstrumentTypes()
{
return INST_OSCILLOSCOPE;
}

string AntikernelLogicAnalyzer::GetName()
{
return "NoName";
}

string AntikernelLogicAnalyzer::GetVendor()
{
return "Antikernel ILA";
}

string AntikernelLogicAnalyzer::GetSerial()
{
return "NoSerialNumber";
}

void AntikernelLogicAnalyzer::LoadChannels()
{
LogDebug("Logic analyzer: loading channel metadata\n");
LogIndenter li;

//Get the number of channels
SendCommand(CMD_GET_CHANNEL_COUNT);
uint8_t nchans = Read1ByteReply();

//Get the length of the names
SendCommand(CMD_GET_NAME_LEN);
uint8_t namelen = Read1ByteReply();
LogDebug("We have %d channels, %d chars per name\n", nchans, namelen);

char* namebuf = new char[namelen + 1];

//Read each name
for(size_t i=0; i<nchans; i++)
{
//Get the width of this channel
SendCommand(CMD_GET_WIDTH, i);
uint8_t width = Read1ByteReply();

SendCommand(CMD_GET_NAME, i);
m_transport->ReadRawData(namelen, (unsigned char*)namebuf);

//Names currently come off in reversed order with null padding after.
//Correct this.
namebuf[namelen] = '\0';
string realname;
for(ssize_t j=namelen; j>=0; j--)
{
if(namebuf[j] == 0)
continue;
realname += namebuf[j];
}

//Invert the order
LogDebug("Channel: %s (%d bits wide)\n", realname.c_str(), width);
}

delete[] namebuf;
}

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

Oscilloscope::TriggerType AntikernelLogicAnalyzer::GetTriggerType()
{
return TRIGGER_TYPE_COMPLEX;
}

void AntikernelLogicAnalyzer::SetTriggerType(Oscilloscope::TriggerType /*type*/)
{
//no op, always complex pattern trigger
}

Oscilloscope::TriggerMode AntikernelLogicAnalyzer::PollTrigger()
{
return TRIGGER_MODE_RUN;
}

bool AntikernelLogicAnalyzer::AcquireData(bool toQueue)
{
LogDebug("Acquiring data...\n");
LogIndenter li;

return true;
}

void AntikernelLogicAnalyzer::StartSingleTrigger()
{

}

void AntikernelLogicAnalyzer::Start()
{
//printf("continuous capture not implemented\n");
}

void AntikernelLogicAnalyzer::Stop()
{

}

bool AntikernelLogicAnalyzer::IsTriggerArmed()
{
return true;
}

void AntikernelLogicAnalyzer::ResetTriggerConditions()
{
/*
for(size_t i=0; i<m_triggers.size(); i++)
m_triggers[i] = TRIGGER_TYPE_DONTCARE;
*/
}

void AntikernelLogicAnalyzer::SetTriggerForChannel(OscilloscopeChannel* /*channel*/, vector<TriggerType> /*triggerbits*/)
{
}

size_t AntikernelLogicAnalyzer::GetTriggerChannelIndex()
{
return 0;
}

void AntikernelLogicAnalyzer::SetTriggerChannelIndex(size_t /*i*/)
{

}

float AntikernelLogicAnalyzer::GetTriggerVoltage()
{
return 0;
}

void AntikernelLogicAnalyzer::SetTriggerVoltage(float /*v*/)
{
//no-op, all channels are digital
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Channel configuration. Mostly empty stubs.

bool AntikernelLogicAnalyzer::IsChannelEnabled(size_t /*i*/)
{
return true;
}

void AntikernelLogicAnalyzer::EnableChannel(size_t /*i*/)
{
//no-op, all channels are always on
}

void AntikernelLogicAnalyzer::DisableChannel(size_t /*i*/)
{
//no-op, all channels are always on
}

OscilloscopeChannel::CouplingType AntikernelLogicAnalyzer::GetChannelCoupling(size_t /*i*/)
{
return OscilloscopeChannel::COUPLE_SYNTHETIC;
}

void AntikernelLogicAnalyzer::SetChannelCoupling(size_t /*i*/, OscilloscopeChannel::CouplingType /*type*/)
{
//no-op, all channels are digital
}

double AntikernelLogicAnalyzer::GetChannelAttenuation(size_t /*i*/)
{
return 1;
}

void AntikernelLogicAnalyzer::SetChannelAttenuation(size_t /*i*/, double /*atten*/)
{
//no-op, all channels are digital
}

int AntikernelLogicAnalyzer::GetChannelBandwidthLimit(size_t /*i*/)
{
return 0;
}

void AntikernelLogicAnalyzer::SetChannelBandwidthLimit(size_t /*i*/, unsigned int /*limit_mhz*/)
{
//no-op, all channels are digital
}

double AntikernelLogicAnalyzer::GetChannelVoltageRange(size_t /*i*/)
{
return 1;
}

void AntikernelLogicAnalyzer::SetChannelVoltageRange(size_t /*i*/, double /*range*/)
{
//no-op, all channels are digital
}

OscilloscopeChannel* AntikernelLogicAnalyzer::GetExternalTrigger()
{
return NULL;
}

double AntikernelLogicAnalyzer::GetChannelOffset(size_t /*i*/)
{
return 0;
}

void AntikernelLogicAnalyzer::SetChannelOffset(size_t /*i*/, double /*offset*/)
{
//no-op, all channels are digital
}

vector<uint64_t> AntikernelLogicAnalyzer::GetSampleRatesNonInterleaved()
{
//FIXME
vector<uint64_t> ret;
return ret;
}

vector<uint64_t> AntikernelLogicAnalyzer::GetSampleRatesInterleaved()
{
//FIXME
vector<uint64_t> ret;
return ret;
}

set<Oscilloscope::InterleaveConflict> AntikernelLogicAnalyzer::GetInterleaveConflicts()
{
//FIXME
set<Oscilloscope::InterleaveConflict> ret;
return ret;
}

vector<uint64_t> AntikernelLogicAnalyzer::GetSampleDepthsNonInterleaved()
{
//FIXME
vector<uint64_t> ret;
return ret;
}

vector<uint64_t> AntikernelLogicAnalyzer::GetSampleDepthsInterleaved()
{
//FIXME
vector<uint64_t> ret;
return ret;
}
102 changes: 102 additions & 0 deletions scopehal/AntikernelLogicAnalyzer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/***********************************************************************************************************************
* *
* 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 RedTinLogicAnalyzer
*/

#ifndef AntikernelLogicAnalyzer_h
#define AntikernelLogicAnalyzer_h

class AntikernelLogicAnalyzer
: public virtual Oscilloscope
, public SCPIDevice
{
public:
AntikernelLogicAnalyzer(SCPITransport* transport);
virtual ~AntikernelLogicAnalyzer();

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

//Channel configuration
virtual bool IsChannelEnabled(size_t i);
virtual void EnableChannel(size_t i);
virtual void DisableChannel(size_t i);
virtual OscilloscopeChannel::CouplingType GetChannelCoupling(size_t i);
virtual void SetChannelCoupling(size_t i, OscilloscopeChannel::CouplingType type);
virtual double GetChannelAttenuation(size_t i);
virtual void SetChannelAttenuation(size_t i, double atten);
virtual int GetChannelBandwidthLimit(size_t i);
virtual void SetChannelBandwidthLimit(size_t i, unsigned int limit_mhz);
virtual double GetChannelVoltageRange(size_t i);
virtual void SetChannelVoltageRange(size_t i, double range);
virtual OscilloscopeChannel* GetExternalTrigger();
virtual double GetChannelOffset(size_t i);
virtual void SetChannelOffset(size_t i, double offset);

//Triggering
virtual Oscilloscope::TriggerMode PollTrigger();
virtual bool AcquireData(bool toQueue = false);
virtual void Start();
virtual void StartSingleTrigger();
virtual void Stop();

virtual bool IsTriggerArmed();
virtual size_t GetTriggerChannelIndex();
virtual void SetTriggerChannelIndex(size_t i);
virtual float GetTriggerVoltage();
virtual void SetTriggerVoltage(float v);
virtual Oscilloscope::TriggerType GetTriggerType();
virtual void SetTriggerType(Oscilloscope::TriggerType type);

virtual std::vector<uint64_t> GetSampleRatesNonInterleaved();
virtual std::vector<uint64_t> GetSampleRatesInterleaved();
virtual std::set<InterleaveConflict> GetInterleaveConflicts();
virtual std::vector<uint64_t> GetSampleDepthsNonInterleaved();
virtual std::vector<uint64_t> GetSampleDepthsInterleaved();

virtual void ResetTriggerConditions();
virtual void SetTriggerForChannel(OscilloscopeChannel* channel, std::vector<TriggerType> triggerbits);

virtual unsigned int GetInstrumentTypes();

protected:
void LoadChannels();

void SendCommand(uint8_t opcode);
void SendCommand(uint8_t opcode, uint8_t chan);
uint8_t Read1ByteReply();
};

#endif

1 change: 1 addition & 0 deletions scopehal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ set(SCOPEHAL_SOURCES
Oscilloscope.cpp
SCPIOscilloscope.cpp
OscilloscopeChannel.cpp
AntikernelLogicAnalyzer.cpp
LeCroyOscilloscope.cpp
LeCroyVICPOscilloscope.cpp
SiglentSCPIOscilloscope.cpp
3 changes: 2 additions & 1 deletion scopehal/Oscilloscope.h
Original file line number Diff line number Diff line change
@@ -257,7 +257,8 @@ class Oscilloscope : public virtual Instrument
TRIGGER_TYPE_FALLING = 2,
TRIGGER_TYPE_RISING = 3,
TRIGGER_TYPE_CHANGE = 4,
TRIGGER_TYPE_DONTCARE = 5
TRIGGER_TYPE_DONTCARE = 5,
TRIGGER_TYPE_COMPLEX = 6 //complex pattern/protocol trigger
};

/**
7 changes: 5 additions & 2 deletions scopehal/RigolOscilloscope.cpp
Original file line number Diff line number Diff line change
@@ -44,8 +44,11 @@ RigolOscilloscope::RigolOscilloscope(SCPITransport* transport)
int model_number;
if(1 != sscanf(m_model.c_str(), "DS%d", &model_number))
{
LogError("Bad model number\n");
return;
if(1 != sscanf(m_model.c_str(), "MSO%d", &model_number))
{
LogError("Bad model number\n");
return;
}
}
int nchans = model_number % 10;
for(int i=0; i<nchans; i++)
7 changes: 6 additions & 1 deletion scopehal/SCPIDevice.cpp
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
* *
* ANTIKERNEL v0.1 *
* *
* Copyright (c) 2012-2019 Andrew D. Zonenberg *
* 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 *
@@ -34,6 +34,11 @@ using namespace std;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Construction / destruction

SCPIDevice::SCPIDevice()
{
//mostly used by not-quite-really-scpi devices that use SCPITransport but don't implement *IDN?
}

SCPIDevice::SCPIDevice(SCPITransport* transport)
: m_transport(transport)
{
3 changes: 2 additions & 1 deletion scopehal/SCPIDevice.h
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
* *
* ANTIKERNEL v0.1 *
* *
* Copyright (c) 2012-2019 Andrew D. Zonenberg *
* 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 *
@@ -36,6 +36,7 @@
class SCPIDevice
{
public:
SCPIDevice();
SCPIDevice(SCPITransport* transport);
virtual ~SCPIDevice();

7 changes: 6 additions & 1 deletion scopehal/SCPISocketTransport.cpp
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
* *
* ANTIKERNEL v0.1 *
* *
* Copyright (c) 2012-2019 Andrew D. Zonenberg *
* 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 *
@@ -91,6 +91,11 @@ string SCPISocketTransport::ReadReply()
return ret;
}

void SCPISocketTransport::SendRawData(size_t len, const unsigned char* buf)
{
m_socket.SendLooped(buf, len);
}

void SCPISocketTransport::ReadRawData(size_t len, unsigned char* buf)
{
m_socket.RecvLooped(buf, len);
3 changes: 2 additions & 1 deletion scopehal/SCPISocketTransport.h
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
* *
* ANTIKERNEL v0.1 *
* *
* Copyright (c) 2012-2019 Andrew D. Zonenberg *
* 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 *
@@ -50,6 +50,7 @@ class SCPISocketTransport : public SCPITransport
virtual bool SendCommand(std::string cmd);
virtual std::string ReadReply();
virtual void ReadRawData(size_t len, unsigned char* buf);
virtual void SendRawData(size_t len, const unsigned char* buf);

protected:
Socket m_socket;
3 changes: 2 additions & 1 deletion scopehal/SCPITransport.h
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
* *
* ANTIKERNEL v0.1 *
* *
* Copyright (c) 2012-2019 Andrew D. Zonenberg *
* 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 *
@@ -48,6 +48,7 @@ class SCPITransport
virtual bool SendCommand(std::string cmd) =0;
virtual std::string ReadReply() =0;
virtual void ReadRawData(size_t len, unsigned char* buf) =0;
virtual void SendRawData(size_t len, const unsigned char* buf) =0;
};

#endif