37#ifndef SCPITransport_h
38#define SCPITransport_h
52 virtual std::string GetConnectionString() =0;
53 virtual std::string GetName() =0;
73 std::recursive_mutex& GetMutex()
74 {
return m_netMutex; }
77 virtual void FlushRXBuffer(
void);
78 virtual bool SendCommand(
const std::string& cmd) =0;
79 virtual std::string ReadReply(
bool endOnSemicolon =
true, std::function<
void(
float)> progress =
nullptr) =0;
80 virtual size_t ReadRawData(
size_t len,
unsigned char* buf, std::function<
void(
float)> progress =
nullptr) =0;
81 virtual void SendRawData(
size_t len,
const unsigned char* buf) =0;
83 virtual bool IsCommandBatchingSupported() =0;
84 virtual bool IsConnected() =0;
97 m_rateLimitingEnabled =
true;
98 m_rateLimitingInterval = interval;
99 m_nextCommandReady = std::chrono::system_clock::now();
121 { m_dedupCommands.emplace(cmd); }
124 typedef SCPITransport* (*CreateProcType)(
const std::string& args);
125 static void DoAddTransportClass(std::string name, CreateProcType proc);
127 static void EnumTransports(std::vector<std::string>& names);
128 static SCPITransport* CreateTransport(
const std::string& transport,
const std::string& args);
134 typedef std::map< std::string, CreateProcType > CreateMapType;
135 static CreateMapType m_createprocs;
138 std::mutex m_queueMutex;
139 std::recursive_mutex m_netMutex;
140 std::list<std::string> m_txQueue;
143 std::set<std::string> m_dedupCommands;
146 bool m_rateLimitingEnabled;
147 std::chrono::system_clock::time_point m_nextCommandReady;
148 std::chrono::milliseconds m_rateLimitingInterval;
151#define TRANSPORT_INITPROC(T) \
152 static SCPITransport* CreateInstance(const std::string& args) \
154 return new T(args); \
156 virtual std::string GetName() override \
157 { return GetTransportName(); }
159#define AddTransportClass(T) SCPITransport::DoAddTransportClass(T::GetTransportName(), T::CreateInstance)
Abstraction of a transport layer for moving SCPI data between endpoints.
Definition: SCPITransport.h:47
void EnableRateLimiting(std::chrono::milliseconds interval)
Enables rate limiting. Rate limiting is only applied to the queued command API.
Definition: SCPITransport.h:95
void RateLimitingWait()
Block until it's time to send the next command when rate limiting.
Definition: SCPITransport.cpp:171
bool FlushCommandQueue()
Pushes all pending commands from SendCommandQueued() calls and blocks until they are all sent.
Definition: SCPITransport.cpp:180
void SendCommandQueued(const std::string &cmd)
Pushes a command into the transmit FIFO then returns immediately.
Definition: SCPITransport.cpp:84
void SendCommandImmediate(std::string cmd)
Sends a command (jumping ahead of the queue) which does not require a response.
Definition: SCPITransport.cpp:234
std::string SendCommandImmediateWithReply(std::string cmd, bool endOnSemicolon=true)
Sends a command (jumping ahead of the queue), then returns the response.
Definition: SCPITransport.cpp:219
void * SendCommandImmediateWithRawBlockReply(std::string cmd, size_t &len)
Sends a command (jumping ahead of the queue) which reads a binary block response.
Definition: SCPITransport.cpp:247
std::string SendCommandQueuedWithReply(std::string cmd, bool endOnSemicolon=true)
Sends a command (flushing any pending/queued commands first), then returns the response.
Definition: SCPITransport.cpp:208
void DeduplicateCommand(const std::string &cmd)
Adds a command to the set of commands which may be deduplicated in the queue.
Definition: SCPITransport.h:120