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

Commits on Mar 11, 2020

  1. Copy the full SHA
    492ab12 View commit details
1 change: 1 addition & 0 deletions scopehal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ set(SCOPEHAL_SOURCES

SCPITransport.cpp
SCPISocketTransport.cpp
VICPSocketTransport.cpp
SCPIDevice.cpp

Instrument.cpp
12 changes: 0 additions & 12 deletions scopehal/LeCroyOscilloscope.h
Original file line number Diff line number Diff line change
@@ -97,18 +97,6 @@ class LeCroyOscilloscope
virtual void SetTriggerType(Oscilloscope::TriggerType type);
virtual void SetTriggerForChannel(OscilloscopeChannel* channel, std::vector<TriggerType> triggerbits);

//VICP constant helpers
enum HEADER_OPS
{
OP_DATA = 0x80,
OP_REMOTE = 0x40,
OP_LOCKOUT = 0x20,
OP_CLEAR = 0x10,
OP_SRQ = 0x8,
OP_REQ = 0x4,
OP_EOI = 0x1
};

//DMM acquisition
virtual double GetVoltage();
virtual double GetPeakToPeak();
95 changes: 4 additions & 91 deletions scopehal/LeCroyVICPOscilloscope.cpp
Original file line number Diff line number Diff line change
@@ -40,84 +40,28 @@ using namespace std;

LeCroyVICPOscilloscope::LeCroyVICPOscilloscope(string hostname, unsigned short port)
: LeCroyOscilloscope(hostname, port)
, m_nextSequence(1)
, m_lastSequence(1)
{
LogDebug("Connecting to VICP oscilloscope at %s:%d\n", hostname.c_str(), port);

if(!m_socket.Connect(hostname, port))
{
LogError("Couldn't connect to socket\n");
return;
}
if(!m_socket.DisableNagle())
{
LogError("Couldn't disable Nagle\n");
return;
}
m_transport = new VICPSocketTransport(hostname, port);

//standard initialization
FlushConfigCache();
IdentifyHardware();
DetectAnalogChannels();
SharedCtorInit();
DetectOptions();

//TODO: make this switchable
SendCommand("DISP ON");
}

LeCroyVICPOscilloscope::~LeCroyVICPOscilloscope()
{
//SendCommand("DISP ON");
delete m_transport;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// VICP protocol logic

uint8_t LeCroyVICPOscilloscope::GetNextSequenceNumber(bool eoi)
{
m_lastSequence = m_nextSequence;

//EOI increments the sequence number.
//Wrap mod 256, but skip zero!
if(eoi)
{
m_nextSequence ++;
if(m_nextSequence == 0)
m_nextSequence = 1;
}

return m_lastSequence;
}

bool LeCroyVICPOscilloscope::SendCommand(string cmd, bool eoi)
{
//Operation and flags header
string payload;
uint8_t op = OP_DATA;
if(eoi)
op |= OP_EOI;
//TODO: remote, clear, poll flags
payload += op;
payload += 0x01; //protocol version number
payload += GetNextSequenceNumber(eoi);
payload += '\0'; //reserved

//Next 4 header bytes are the message length (network byte order)
uint32_t len = cmd.length();
payload += (len >> 24) & 0xff;
payload += (len >> 16) & 0xff;
payload += (len >> 8) & 0xff;
payload += (len >> 0) & 0xff;

//Add message data
payload += cmd;

//Actually send it
if(!m_socket.SendLooped((const unsigned char*)payload.c_str(), payload.size()))
return false;

m_transport->SendCommand(cmd);
return true;
}

@@ -126,38 +70,7 @@ bool LeCroyVICPOscilloscope::SendCommand(string cmd, bool eoi)
*/
string LeCroyVICPOscilloscope::ReadData()
{
//Read the header
unsigned char header[8];
if(!m_socket.RecvLooped(header, 8))
return "";

//Sanity check
if(header[1] != 1)
{
LogError("Bad VICP protocol version\n");
return "";
}
if(header[2] != m_lastSequence)
{
//LogError("Bad VICP sequence number %d (expected %d)\n", header[2], m_lastSequence);
//return "";
}
if(header[3] != 0)
{
LogError("Bad VICP reserved field\n");
return "";
}

//TODO: pay attention to header?

//Read the message data
uint32_t len = (header[4] << 24) | (header[5] << 16) | (header[6] << 8) | header[7];
string ret;
ret.resize(len);
if(!m_socket.RecvLooped((unsigned char*)&ret[0], len))
return "";

return ret;
return m_transport->ReadReply();
}

string LeCroyVICPOscilloscope::ReadSingleBlockString(bool trimNewline)
6 changes: 2 additions & 4 deletions scopehal/LeCroyVICPOscilloscope.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 *
@@ -52,9 +52,7 @@ class LeCroyVICPOscilloscope
virtual std::string ReadMultiBlockString();
virtual std::string ReadSingleBlockString(bool trimNewline = false);

uint8_t GetNextSequenceNumber(bool eoi);
uint8_t m_nextSequence;
uint8_t m_lastSequence;
VICPSocketTransport* m_transport;
};

#endif
154 changes: 154 additions & 0 deletions scopehal/VICPSocketTransport.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/***********************************************************************************************************************
* *
* 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 VICPSocketTransport
*/

#include "scopehal.h"

using namespace std;

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

VICPSocketTransport::VICPSocketTransport(string hostname, unsigned short port)
: m_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
, m_hostname(hostname)
, m_port(port)
, m_nextSequence(1)
, m_lastSequence(1)
{
LogDebug("Connecting to VICP oscilloscope at %s:%d\n", hostname.c_str(), port);

if(!m_socket.Connect(hostname, port))
{
LogError("Couldn't connect to socket\n");
return;
}
if(!m_socket.DisableNagle())
{
LogError("Couldn't disable Nagle\n");
return;
}
}

VICPSocketTransport::~VICPSocketTransport()
{
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Actual transport code


uint8_t VICPSocketTransport::GetNextSequenceNumber()
{
m_lastSequence = m_nextSequence;

//EOI increments the sequence number.
//Wrap mod 256, but skip zero!
m_nextSequence ++;
if(m_nextSequence == 0)
m_nextSequence = 1;

return m_lastSequence;
}

bool VICPSocketTransport::SendCommand(string cmd)
{
//Operation and flags header
string payload;
uint8_t op = OP_DATA | OP_EOI;

//TODO: remote, clear, poll flags
payload += op;
payload += 0x01; //protocol version number
payload += GetNextSequenceNumber();
payload += '\0'; //reserved

//Next 4 header bytes are the message length (network byte order)
uint32_t len = cmd.length();
payload += (len >> 24) & 0xff;
payload += (len >> 16) & 0xff;
payload += (len >> 8) & 0xff;
payload += (len >> 0) & 0xff;

//Add message data
payload += cmd;

//Actually send it
SendRawData(payload.size(), (const unsigned char*)payload.c_str());
return true;
}

string VICPSocketTransport::ReadReply()
{
//Read the header
unsigned char header[8];
ReadRawData(8, header);

//Sanity check
if(header[1] != 1)
{
LogError("Bad VICP protocol version\n");
return "";
}
if(header[2] != m_lastSequence)
{
//LogError("Bad VICP sequence number %d (expected %d)\n", header[2], m_lastSequence);
//return "";
}
if(header[3] != 0)
{
LogError("Bad VICP reserved field\n");
return "";
}

//TODO: pay attention to header?

//Read the message data
uint32_t len = (header[4] << 24) | (header[5] << 16) | (header[6] << 8) | header[7];
string ret;
ret.resize(len);
ReadRawData(len, (unsigned char*)&ret[0]);

return ret;
}

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

void VICPSocketTransport::ReadRawData(size_t len, unsigned char* buf)
{
m_socket.RecvLooped(buf, len);
}
Loading