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

Commits on Dec 17, 2020

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    4fd83b8 View commit details
  2. Copy the full SHA
    23735bb View commit details
7 changes: 5 additions & 2 deletions scopehal/SCPILxiTransport.cpp
Original file line number Diff line number Diff line change
@@ -173,15 +173,15 @@ void SCPILxiTransport::SendRawData(size_t len, const unsigned char* buf)
lxi_send(m_device, const_cast<char*>(reinterpret_cast<const char*>(buf)), len, m_timeout);
}

void SCPILxiTransport::ReadRawData(size_t len, unsigned char* buf)
size_t SCPILxiTransport::ReadRawData(size_t len, unsigned char* buf)
{
// Data in the staging buffer is assumed to always be a consequence of a SendCommand request.
// Since we fetch all the reply data in one go, once all this data has been fetched, we mark
// the staging buffer as depleted and don't issue a new lxi_receive until a new SendCommand
// is issued.

if (!m_staging_buf)
return;
return 0;

if (!m_data_depleted)
{
@@ -211,7 +211,10 @@ void SCPILxiTransport::ReadRawData(size_t len, unsigned char* buf)
// When this happens, the SCPIDevice is fetching more data from device than what
// could be expected from the SendCommand that was issued.
LogDebug("ReadRawData: data depleted.\n");
return 0;
}

return len;
}

bool SCPILxiTransport::IsCommandBatchingSupported()
2 changes: 1 addition & 1 deletion scopehal/SCPILxiTransport.h
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ class SCPILxiTransport : public SCPITransport

virtual bool SendCommand(const std::string& cmd);
virtual std::string ReadReply(bool endOnSemicolon = true);
virtual void ReadRawData(size_t len, unsigned char* buf);
virtual size_t ReadRawData(size_t len, unsigned char* buf);
virtual void SendRawData(size_t len, const unsigned char* buf);

virtual bool IsCommandBatchingSupported();
3 changes: 2 additions & 1 deletion scopehal/SCPINullTransport.cpp
Original file line number Diff line number Diff line change
@@ -88,8 +88,9 @@ void SCPINullTransport::SendRawData(size_t /*len*/, const unsigned char* /*buf*/
{
}

void SCPINullTransport::ReadRawData(size_t /*len*/, unsigned char* /*buf*/)
size_t SCPINullTransport::ReadRawData(size_t /*len*/, unsigned char* /*buf*/)
{
return 0;
}

bool SCPINullTransport::IsCommandBatchingSupported()
2 changes: 1 addition & 1 deletion scopehal/SCPINullTransport.h
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ class SCPINullTransport : public SCPITransport

virtual bool SendCommand(const std::string& cmd);
virtual std::string ReadReply(bool endOnSemicolon = true);
virtual void ReadRawData(size_t len, unsigned char* buf);
virtual size_t ReadRawData(size_t len, unsigned char* buf);
virtual void SendRawData(size_t len, const unsigned char* buf);

virtual bool IsCommandBatchingSupported();
6 changes: 4 additions & 2 deletions scopehal/SCPISocketTransport.cpp
Original file line number Diff line number Diff line change
@@ -137,9 +137,11 @@ void SCPISocketTransport::SendRawData(size_t len, const unsigned char* buf)
m_socket.SendLooped(buf, len);
}

void SCPISocketTransport::ReadRawData(size_t len, unsigned char* buf)
size_t SCPISocketTransport::ReadRawData(size_t len, unsigned char* buf)
{
m_socket.RecvLooped(buf, len);
if(!m_socket.RecvLooped(buf, len))
return 0;
return len;
}

bool SCPISocketTransport::IsCommandBatchingSupported()
2 changes: 1 addition & 1 deletion scopehal/SCPISocketTransport.h
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ class SCPISocketTransport : public SCPITransport

virtual bool SendCommand(const std::string& cmd);
virtual std::string ReadReply(bool endOnSemicolon = true);
virtual void ReadRawData(size_t len, unsigned char* buf);
virtual size_t ReadRawData(size_t len, unsigned char* buf);
virtual void SendRawData(size_t len, const unsigned char* buf);

virtual bool IsCommandBatchingSupported();
7 changes: 5 additions & 2 deletions scopehal/SCPITMCTransport.cpp
Original file line number Diff line number Diff line change
@@ -148,15 +148,15 @@ void SCPITMCTransport::SendRawData(size_t len, const unsigned char* buf)
write(m_handle, (const char *)buf, len);
}

void SCPITMCTransport::ReadRawData(size_t len, unsigned char* buf)
size_t SCPITMCTransport::ReadRawData(size_t len, unsigned char* buf)
{
// Data in the staging buffer is assumed to always be a consequence of a SendCommand request.
// Since we fetch all the reply data in one go, once all this data has been fetched, we mark
// the staging buffer as depleted and don't issue a new read until a new SendCommand
// is issued.

if (!m_staging_buf || !IsConnected())
return;
return 0;

if (!m_data_depleted)
{
@@ -207,7 +207,10 @@ void SCPITMCTransport::ReadRawData(size_t len, unsigned char* buf)
// When this happens, the SCPIDevice is fetching more data from device than what
// could be expected from the SendCommand that was issued.
LogDebug("ReadRawData: data depleted.\n");
return 0;
}

return len;
}

bool SCPITMCTransport::IsCommandBatchingSupported()
2 changes: 1 addition & 1 deletion scopehal/SCPITMCTransport.h
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ class SCPITMCTransport : public SCPITransport

virtual bool SendCommand(const std::string& cmd);
virtual std::string ReadReply(bool endOnSemicolon = true);
virtual void ReadRawData(size_t len, unsigned char* buf);
virtual size_t ReadRawData(size_t len, unsigned char* buf);
virtual void SendRawData(size_t len, const unsigned char* buf);

virtual bool IsCommandBatchingSupported();
82 changes: 68 additions & 14 deletions scopehal/SCPITransport.cpp
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@ using namespace std;
SCPITransport::CreateMapType SCPITransport::m_createprocs;

SCPITransport::SCPITransport()
: m_opcRequired(false)
{
}

@@ -97,10 +98,19 @@ bool SCPITransport::FlushCommandQueue()
m_txQueue.clear();
}

lock_guard<mutex> lock(m_netMutex);
lock_guard<recursive_mutex> lock(m_netMutex);
for(auto str : tmp)
{
SendCommand(str);

//Synchronize broken instruments without RX buffering
if(m_opcRequired)
{
uint8_t ignored[2];
SendCommand("*OPC?");
ReadRawData(2, ignored); //always returns "1\n"
}
}
return true;
}

@@ -109,21 +119,65 @@ bool SCPITransport::FlushCommandQueue()
This is an atomic operation requiring no mutexing at the caller side.
*/
string SCPITransport::SendCommandWithReply(string cmd, bool endOnSemicolon)
string SCPITransport::SendCommandQueuedWithReply(string cmd, bool endOnSemicolon)
{
//Grab the queue, then immediately release the mutex so we can do more queued sends
list<string> tmp;
{
lock_guard<mutex> lock(m_queueMutex);
tmp = move(m_txQueue);
m_txQueue.clear();
}

lock_guard<mutex> lock(m_netMutex);
FlushCommandQueue();
return SendCommandImmediateWithReply(cmd, endOnSemicolon);
}

tmp.push_back(cmd);
for(auto str : tmp)
SendCommand(str);
/**
@brief Sends a command (jumping ahead of the queue), then returns the response.
This is an atomic operation requiring no mutexing at the caller side.
*/
string SCPITransport::SendCommandImmediateWithReply(string cmd, bool endOnSemicolon)
{
lock_guard<recursive_mutex> lock(m_netMutex);
SendCommand(cmd);
return ReadReply(endOnSemicolon);
}

/**
@brief Sends a command (jumping ahead of the queue) which does not require a response.
*/
void SCPITransport::SendCommandImmediate(string cmd)
{
lock_guard<recursive_mutex> lock(m_netMutex);
SendCommand(cmd);

//Synchronize broken instruments without RX buffering
if(m_opcRequired)
{
uint8_t ignored[2];
SendCommand("*OPC?");
ReadRawData(2, ignored); //always returns "1\n"
}
}

/**
@brief Sends a command (jumping ahead of the queue) which reads a binary block response
*/
void* SCPITransport::SendCommandImmediateWithRawBlockReply(string cmd, size_t& len)
{
lock_guard<recursive_mutex> lock(m_netMutex);
SendCommand(cmd);

//Read the length
char tmplen[3] = {0};
if(2 != ReadRawData(2, (unsigned char*)tmplen)) //expect #n
return NULL;
if(tmplen[0] == 0) //Not sure how this happens, but sometimes occurs on Tek MSO6?
return NULL;
size_t ndigits = stoull(tmplen+1);

//Read the digits
char digits[10] = {0};
if(ndigits != ReadRawData(ndigits, (unsigned char*)digits))
return NULL;
len = stoull(digits);

//Read the actual data
unsigned char* buf = new unsigned char[len];
len = ReadRawData(len, buf);
return buf;
}
16 changes: 12 additions & 4 deletions scopehal/SCPITransport.h
Original file line number Diff line number Diff line change
@@ -50,17 +50,22 @@ class SCPITransport

//Queued command API
void SendCommandQueued(const std::string& cmd);
std::string SendCommandWithReply(std::string cmd, bool endOnSemicolon = true);
std::string SendCommandQueuedWithReply(std::string cmd, bool endOnSemicolon = true);
void SendCommandImmediate(std::string cmd);
std::string SendCommandImmediateWithReply(std::string cmd, bool endOnSemicolon = true);
void* SendCommandImmediateWithRawBlockReply(std::string cmd, size_t& len);
bool FlushCommandQueue();
void SetOpcRequired()
{ m_opcRequired = true; }

//Manual mutex locking for ReadRawData() etc
std::mutex& GetMutex()
std::recursive_mutex& GetMutex()
{ return m_netMutex; }

//Immediate command API
virtual bool SendCommand(const std::string& cmd) =0;
virtual std::string ReadReply(bool endOnSemicolon = true) =0;
virtual void ReadRawData(size_t len, unsigned char* buf) =0;
virtual size_t ReadRawData(size_t len, unsigned char* buf) =0;
virtual void SendRawData(size_t len, const unsigned char* buf) =0;

virtual bool IsCommandBatchingSupported() =0;
@@ -81,8 +86,11 @@ class SCPITransport

//Queued commands waiting to be sent
std::mutex m_queueMutex;
std::mutex m_netMutex;
std::recursive_mutex m_netMutex;
std::list<std::string> m_txQueue;

//True if we need to *OPC? between consecutive commands
bool m_opcRequired;
};

#define TRANSPORT_INITPROC(T) \
6 changes: 4 additions & 2 deletions scopehal/SCPIUARTTransport.cpp
Original file line number Diff line number Diff line change
@@ -121,9 +121,11 @@ void SCPIUARTTransport::SendRawData(size_t len, const unsigned char* buf)
m_uart.Write(buf, len);
}

void SCPIUARTTransport::ReadRawData(size_t len, unsigned char* buf)
size_t SCPIUARTTransport::ReadRawData(size_t len, unsigned char* buf)
{
m_uart.Read(buf, len);
if(!m_uart.Read(buf, len))
return 0;
return len;
}

bool SCPIUARTTransport::IsCommandBatchingSupported()
2 changes: 1 addition & 1 deletion scopehal/SCPIUARTTransport.h
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ class SCPIUARTTransport : public SCPITransport

virtual bool SendCommand(const std::string& cmd);
virtual std::string ReadReply(bool endOnSemicolon = true);
virtual void ReadRawData(size_t len, unsigned char* buf);
virtual size_t ReadRawData(size_t len, unsigned char* buf);
virtual void SendRawData(size_t len, const unsigned char* buf);

virtual bool IsCommandBatchingSupported();
6 changes: 4 additions & 2 deletions scopehal/VICPSocketTransport.cpp
Original file line number Diff line number Diff line change
@@ -211,9 +211,11 @@ void VICPSocketTransport::SendRawData(size_t len, const unsigned char* buf)
m_socket.SendLooped(buf, len);
}

void VICPSocketTransport::ReadRawData(size_t len, unsigned char* buf)
size_t VICPSocketTransport::ReadRawData(size_t len, unsigned char* buf)
{
m_socket.RecvLooped(buf, len);
if(!m_socket.RecvLooped(buf, len))
return 0;
return len;
}

bool VICPSocketTransport::IsCommandBatchingSupported()
2 changes: 1 addition & 1 deletion scopehal/VICPSocketTransport.h
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ class VICPSocketTransport : public SCPITransport

virtual bool SendCommand(const std::string& cmd);
virtual std::string ReadReply(bool endOnSemicolon = true);
virtual void ReadRawData(size_t len, unsigned char* buf);
virtual size_t ReadRawData(size_t len, unsigned char* buf);
virtual void SendRawData(size_t len, const unsigned char* buf);

virtual bool IsCommandBatchingSupported();