37#ifndef SCPITransport_h
38#define SCPITransport_h
45 std::string description;
58 virtual std::string GetConnectionString() =0;
59 virtual std::string GetName() =0;
81 std::recursive_mutex& GetMutex()
82 {
return m_netMutex; }
85 virtual void FlushRXBuffer(
void);
86 virtual bool SendCommand(
const std::string&
cmd) =0;
87 virtual std::string ReadReply(
bool endOnSemicolon =
true, std::function<
void(
float)>
progress =
nullptr) =0;
88 virtual size_t ReadRawData(
size_t len,
unsigned char*
buf, std::function<
void(
float)>
progress =
nullptr) =0;
89 virtual void SendRawData(
size_t len,
const unsigned char*
buf) =0;
91 virtual bool IsCommandBatchingSupported() =0;
92 virtual bool IsConnected() =0;
105 m_rateLimitingEnabled =
true;
106 m_rateLimitingInterval = interval;
107 m_nextCommandReady = std::chrono::system_clock::now();
129 { m_dedupCommands.emplace(
cmd); }
133 typedef std::vector<TransportEndpoint> (*EnumEndpointsProcType)();
134 static void DoAddTransportClass(
const std::string& name, CreateProcType
proc, EnumEndpointsProcType
eproc);
136 static void EnumTransports(std::vector<std::string>&
names);
139 static std::vector<TransportEndpoint> EnumEndpoints(
const std::string&
transport);
140 static std::vector<TransportEndpoint> EnumTransportEndpoints();
146 typedef std::map< std::string, CreateProcType > CreateMapType;
147 static CreateMapType m_createprocs;
149 typedef std::map< std::string, EnumEndpointsProcType > EnumEndpointsMapType;
150 static EnumEndpointsMapType m_enumEndpointsProcs;
153 std::mutex m_queueMutex;
154 std::recursive_mutex m_netMutex;
155 std::list<std::string> m_txQueue;
158 std::set<std::string> m_dedupCommands;
161 bool m_rateLimitingEnabled;
162 std::chrono::system_clock::time_point m_nextCommandReady;
163 std::chrono::milliseconds m_rateLimitingInterval;
166#define TRANSPORT_INITPROC(T) \
167 static SCPITransport* CreateInstance(const std::string& args) \
169 return new T(args); \
171 virtual std::string GetName() override \
172 { return GetTransportName(); }
174#define AddTransportClass(T) SCPITransport::DoAddTransportClass(T::GetTransportName(), T::CreateInstance, T::EnumTransportEndpoints)
Definition AcceleratorBuffer.h:204
Abstraction of a transport layer for moving SCPI data between endpoints.
Definition SCPITransport.h:53
void EnableRateLimiting(std::chrono::milliseconds interval)
Enables rate limiting. Rate limiting is only applied to the queued command API.
Definition SCPITransport.h:103
virtual bool SetTimeouts(unsigned int txUs, unsigned int rxUs)
Base implementation does nothing.
Definition SCPITransport.cpp:306
void RateLimitingWait()
Block until it's time to send the next command when rate limiting.
Definition SCPITransport.cpp:174
bool FlushCommandQueue()
Pushes all pending commands from SendCommandQueued() calls and blocks until they are all sent.
Definition SCPITransport.cpp:183
void SendCommandQueued(const std::string &cmd)
Pushes a command into the transmit FIFO then returns immediately.
Definition SCPITransport.cpp:87
std::string SendCommandQueuedWithReply(const std::string &cmd, bool endOnSemicolon=true)
Sends a command (flushing any pending/queued commands first), then returns the response.
Definition SCPITransport.cpp:212
void SendCommandImmediate(const std::string &cmd)
Sends a command (jumping ahead of the queue) which does not require a response.
Definition SCPITransport.cpp:238
void * SendCommandImmediateWithRawBlockReply(const std::string &cmd, size_t &len)
Sends a command (jumping ahead of the queue) which reads a binary block response.
Definition SCPITransport.cpp:251
std::string SendCommandImmediateWithReply(const std::string &cmd, bool endOnSemicolon=true)
Sends a command (jumping ahead of the queue), then returns the response.
Definition SCPITransport.cpp:223
void DeduplicateCommand(const std::string &cmd)
Adds a command to the set of commands which may be deduplicated in the queue.
Definition SCPITransport.h:128
Definition SCPITransport.h:43