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

Commits on Mar 11, 2020

  1. Copy the full SHA
    74a0408 View commit details
40 changes: 8 additions & 32 deletions scopehal/LeCroyOscilloscope.cpp
Original file line number Diff line number Diff line change
@@ -955,38 +955,14 @@ Oscilloscope::TriggerMode LeCroyOscilloscope::PollTrigger()

bool LeCroyOscilloscope::ReadWaveformBlock(string& data)
{
//First packet is just a header "DAT1,\n" or "DESC,\n". Throw it away.
//In some rare circumstances, such as when the user touches front panel controls,
//it appears we can get a blank line before this. Ignore that.
string header = ReadData();

//Second block is a header including the message length. Parse that.
string lhdr = ReadSingleBlockString();
unsigned int num_bytes = atoi(lhdr.c_str() + 2);
if(num_bytes == 0)
{
ReadData();
return true;
}

//Read the data
data.clear();
while(true)
{
string payload = ReadData();
data += payload;
if(data.size() >= num_bytes)
break;
}

//Throw away the newline at the end
ReadData();

if(data.size() != num_bytes)
{
LogError("bad rx block size (got %zu, expected %u)\n", data.size(), num_bytes);
return false;
}
//Prefix "DESC,\n" or "DAT1,\n". Always seems to be 6 chars and start with a D.
//Next is the length header. Looks like #9000000346. #9 followed by nine ASCII length digits.
//Ignore that too.
string tmp = ReadSingleBlockString();
size_t offset = tmp.find("D");

//Copy the rest of the block
data = tmp.substr(offset + 16);

return true;
}
1 change: 0 additions & 1 deletion scopehal/LeCroyOscilloscope.h
Original file line number Diff line number Diff line change
@@ -164,7 +164,6 @@ class LeCroyOscilloscope
void BulkCheckChannelEnableState();

virtual bool SendCommand(std::string cmd, bool eoi=true) = 0;
virtual std::string ReadData() =0;
virtual std::string ReadSingleBlockString(bool trimNewline = false) =0;

bool ReadWaveformBlock(std::string& data);
33 changes: 9 additions & 24 deletions scopehal/LeCroyVICPOscilloscope.cpp
Original file line number Diff line number Diff line change
@@ -65,32 +65,17 @@ bool LeCroyVICPOscilloscope::SendCommand(string cmd, bool eoi)
return true;
}

/**
@brief Read exactly one packet from the socket
*/
string LeCroyVICPOscilloscope::ReadData()
{
return m_transport->ReadReply();
}

string LeCroyVICPOscilloscope::ReadSingleBlockString(bool trimNewline)
{
while(true)
{
string payload = ReadData();
string payload = m_transport->ReadReply();

//Skip empty blocks
if(payload.empty() || payload == "\n")
continue;

if(trimNewline && (payload.length() > 0) )
{
int iend = payload.length() - 1;
if(trimNewline && (payload[iend] == '\n'))
payload.resize(iend);
}

payload += "\0";
return payload;
if(trimNewline && (payload.length() > 0) )
{
int iend = payload.length() - 1;
if(trimNewline && (payload[iend] == '\n'))
payload.resize(iend);
}

payload += "\0";
return payload;
}
1 change: 0 additions & 1 deletion scopehal/LeCroyVICPOscilloscope.h
Original file line number Diff line number Diff line change
@@ -48,7 +48,6 @@ class LeCroyVICPOscilloscope

protected:
virtual bool SendCommand(std::string cmd, bool eoi=true);
virtual std::string ReadData();
virtual std::string ReadSingleBlockString(bool trimNewline = false);

VICPSocketTransport* m_transport;
2 changes: 1 addition & 1 deletion scopehal/SiglentSCPIOscilloscope.h
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ class SiglentSCPIOscilloscope
protected:
virtual void DetectAnalogChannels();
virtual bool SendCommand(std::string cmd, bool eoi=true);
virtual std::string ReadData();
std::string ReadData();
virtual std::string ReadSingleBlockString(bool trimNewline = false);

void ReadWaveDescriptorBlock(SiglentWaveformDesc_t *descriptor, unsigned int channel);
77 changes: 44 additions & 33 deletions scopehal/VICPSocketTransport.cpp
Original file line number Diff line number Diff line change
@@ -41,11 +41,11 @@ using namespace std;
// Construction / destruction

VICPSocketTransport::VICPSocketTransport(string hostname, unsigned short port)
: m_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
: m_nextSequence(1)
, m_lastSequence(1)
, 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);

@@ -111,39 +111,50 @@ bool VICPSocketTransport::SendCommand(string cmd)

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

uint8_t op = header[0];
//OP_EOI terminates a block

//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)
string payload;
while(true)
{
LogError("Bad VICP reserved field\n");
return "";
//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 "";
}

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

//Skip empty blocks, or just newlines
if( (len == 0) || (rxbuf == "\n"))
{}

//Actual frame data
else
payload += rxbuf;

//Check EOI flag
if(header[0] & OP_EOI)
break;
}

//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;
return payload;
}

void VICPSocketTransport::SendRawData(size_t len, const unsigned char* buf)