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

Commits on Dec 16, 2020

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    4f97508 View commit details
  2. Copy the full SHA
    c03f7c3 View commit details
Showing with 631 additions and 556 deletions.
  1. +3 −0 scopehal/SCPIOscilloscope.h
  2. +58 −0 scopehal/SCPITransport.cpp
  3. +16 −0 scopehal/SCPITransport.h
  4. +546 −556 scopehal/TektronixOscilloscope.cpp
  5. +8 −0 scopehal/TektronixOscilloscope.h
3 changes: 3 additions & 0 deletions scopehal/SCPIOscilloscope.h
Original file line number Diff line number Diff line change
@@ -48,6 +48,9 @@ class SCPIOscilloscope : public Oscilloscope
virtual std::string GetName();
virtual std::string GetVendor();
virtual std::string GetSerial();

SCPITransport* GetTransport()
{ return m_transport; }
};

#endif
58 changes: 58 additions & 0 deletions scopehal/SCPITransport.cpp
Original file line number Diff line number Diff line change
@@ -69,3 +69,61 @@ SCPITransport* SCPITransport::CreateTransport(const string& transport, const str
LogError("Invalid transport name \"%s\"\n", transport.c_str());
return NULL;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Command batching

/**
@brief Pushes a command into the transmit FIFO then returns immediately.
This command will actually be sent the next time FlushCommandQueue() is called.
*/
void SCPITransport::SendCommandQueued(const string& cmd)
{
lock_guard<mutex> lock(m_queueMutex);
m_txQueue.push_back(cmd);
}

/**
@brief Pushes all pending commands from SendCommandQueued() calls and blocks until they are all sent.
*/
bool SCPITransport::FlushCommandQueue()
{
//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);
for(auto str : tmp)
SendCommand(str);

return true;
}

/**
@brief Sends a command (flushing any pending/queued commands first), then returns the response.
This is an atomic operation requiring no mutexing at the caller side.
*/
string SCPITransport::SendCommandWithReply(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);

tmp.push_back(cmd);
for(auto str : tmp)
SendCommand(str);

return ReadReply(endOnSemicolon);
}
16 changes: 16 additions & 0 deletions scopehal/SCPITransport.h
Original file line number Diff line number Diff line change
@@ -48,6 +48,16 @@ class SCPITransport
virtual std::string GetConnectionString() =0;
virtual std::string GetName() =0;

//Queued command API
void SendCommandQueued(const std::string& cmd);
std::string SendCommandWithReply(std::string cmd, bool endOnSemicolon = true);
bool FlushCommandQueue();

//Manual mutex locking for ReadRawData() etc
std::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;
@@ -64,9 +74,15 @@ class SCPITransport
static SCPITransport* CreateTransport(const std::string& transport, const std::string& args);

protected:

//Class enumeration
typedef std::map< std::string, CreateProcType > CreateMapType;
static CreateMapType m_createprocs;

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

#define TRANSPORT_INITPROC(T) \
Loading