@@ -79,8 +79,9 @@ SCPITransport* SCPITransport::CreateTransport(const string& transport, const str
79
79
@brief Pushes a command into the transmit FIFO then returns immediately.
80
80
81
81
This command will actually be sent the next time FlushCommandQueue() is called.
82
+ @param settle_time Rate limiting time for this specific command, see `EnableRateLimiting()´
82
83
*/
83
- void SCPITransport::SendCommandQueued (const string& cmd)
84
+ void SCPITransport::SendCommandQueued (const string& cmd, std::chrono::milliseconds settle_time )
84
85
{
85
86
lock_guard<mutex> lock (m_queueMutex);
86
87
@@ -116,7 +117,8 @@ void SCPITransport::SendCommandQueued(const string& cmd)
116
117
auto it = m_txQueue.begin ();
117
118
while (it != m_txQueue.end ())
118
119
{
119
- tmp = *it;
120
+ auto pair = *it;
121
+ tmp = pair.first ;
120
122
121
123
// Split off subject, if we have one
122
124
// (ignore leading colon)
@@ -142,7 +144,7 @@ void SCPITransport::SendCommandQueued(const string& cmd)
142
144
{
143
145
LogTrace (" Deduplicating redundant %s command %s and pushing new command %s\n " ,
144
146
ncmd.c_str (),
145
- (*it) .c_str (),
147
+ pair. first .c_str (),
146
148
cmd.c_str ());
147
149
148
150
auto oldit = it;
@@ -159,18 +161,35 @@ void SCPITransport::SendCommandQueued(const string& cmd)
159
161
160
162
}
161
163
162
- m_txQueue.push_back (cmd);
164
+ // Create a pair with cmd and settle_time
165
+ std::pair<std::string, std::chrono::milliseconds> pair;
166
+ pair = make_pair (cmd, settle_time);
167
+
168
+ // Push to queue
169
+ m_txQueue.push_back (pair);
163
170
164
171
LogTrace (" %zu commands now queued\n " , m_txQueue.size ());
165
172
}
166
173
167
174
/* *
168
175
@brief Block until it's time to send the next command when rate limiting.
176
+
177
+ @param settle_time Rate limiting time for this specific command, see `EnableRateLimiting()´
169
178
*/
170
- void SCPITransport::RateLimitingWait ()
179
+ void SCPITransport::RateLimitingWait (std::chrono::milliseconds settle_time )
171
180
{
172
181
this_thread::sleep_until (m_nextCommandReady);
173
- m_nextCommandReady = chrono::system_clock::now () + m_rateLimitingInterval;
182
+
183
+ if (settle_time == std::chrono::milliseconds (0 ))
184
+ {
185
+ // Use the configured rate limit
186
+ m_nextCommandReady = chrono::system_clock::now () + m_rateLimitingInterval;
187
+ }
188
+ else
189
+ {
190
+ // Use the specified settle_time
191
+ m_nextCommandReady = chrono::system_clock::now () + settle_time;
192
+ }
174
193
}
175
194
176
195
/* *
@@ -179,7 +198,7 @@ void SCPITransport::RateLimitingWait()
179
198
bool SCPITransport::FlushCommandQueue ()
180
199
{
181
200
// Grab the queue, then immediately release the mutex so we can do more queued sends
182
- list<string> tmp;
201
+ std:: list<std::pair<std:: string, std::chrono::milliseconds> > tmp;
183
202
{
184
203
lock_guard<mutex> lock (m_queueMutex);
185
204
tmp = std::move (m_txQueue);
@@ -190,11 +209,11 @@ bool SCPITransport::FlushCommandQueue()
190
209
LogTrace (" %zu commands being flushed\n " , tmp.size ());
191
210
192
211
lock_guard<recursive_mutex> lock (m_netMutex);
193
- for (auto str : tmp)
212
+ for (auto pair : tmp)
194
213
{
195
214
if (m_rateLimitingEnabled)
196
- RateLimitingWait ();
197
- SendCommand (str );
215
+ RateLimitingWait (pair. second );
216
+ SendCommand (pair. first );
198
217
}
199
218
return true ;
200
219
}
@@ -203,24 +222,26 @@ bool SCPITransport::FlushCommandQueue()
203
222
@brief Sends a command (flushing any pending/queued commands first), then returns the response.
204
223
205
224
This is an atomic operation requiring no mutexing at the caller side.
225
+ @param settle_time Rate limiting time for this specific command, see `EnableRateLimiting()´
206
226
*/
207
- string SCPITransport::SendCommandQueuedWithReply (string cmd, bool endOnSemicolon)
227
+ string SCPITransport::SendCommandQueuedWithReply (string cmd, bool endOnSemicolon, std::chrono::milliseconds settle_time )
208
228
{
209
229
FlushCommandQueue ();
210
- return SendCommandImmediateWithReply (cmd, endOnSemicolon);
230
+ return SendCommandImmediateWithReply (cmd, endOnSemicolon, settle_time );
211
231
}
212
232
213
233
/* *
214
234
@brief Sends a command (jumping ahead of the queue), then returns the response.
215
235
216
236
This is an atomic operation requiring no mutexing at the caller side.
237
+ @param settle_time Rate limiting time for this specific command, see `EnableRateLimiting()´
217
238
*/
218
- string SCPITransport::SendCommandImmediateWithReply (string cmd, bool endOnSemicolon)
239
+ string SCPITransport::SendCommandImmediateWithReply (string cmd, bool endOnSemicolon, std::chrono::milliseconds settle_time )
219
240
{
220
241
lock_guard<recursive_mutex> lock (m_netMutex);
221
242
222
243
if (m_rateLimitingEnabled)
223
- RateLimitingWait ();
244
+ RateLimitingWait (settle_time );
224
245
225
246
SendCommand (cmd);
226
247
@@ -229,26 +250,28 @@ string SCPITransport::SendCommandImmediateWithReply(string cmd, bool endOnSemico
229
250
230
251
/* *
231
252
@brief Sends a command (jumping ahead of the queue) which does not require a response.
253
+ @param settle_time Rate limiting time for this specific command, see `EnableRateLimiting()´
232
254
*/
233
- void SCPITransport::SendCommandImmediate (string cmd)
255
+ void SCPITransport::SendCommandImmediate (string cmd, std::chrono::milliseconds settle_time )
234
256
{
235
257
lock_guard<recursive_mutex> lock (m_netMutex);
236
258
237
259
if (m_rateLimitingEnabled)
238
- RateLimitingWait ();
260
+ RateLimitingWait (settle_time );
239
261
240
262
SendCommand (cmd);
241
263
}
242
264
243
265
/* *
244
266
@brief Sends a command (jumping ahead of the queue) which reads a binary block response
267
+ @param settle_time Rate limiting time for this specific command, see `EnableRateLimiting()´
245
268
*/
246
- void * SCPITransport::SendCommandImmediateWithRawBlockReply (string cmd, size_t & len)
269
+ void * SCPITransport::SendCommandImmediateWithRawBlockReply (string cmd, size_t & len, std::chrono::milliseconds settle_time )
247
270
{
248
271
lock_guard<recursive_mutex> lock (m_netMutex);
249
272
250
273
if (m_rateLimitingEnabled)
251
- RateLimitingWait ();
274
+ RateLimitingWait (settle_time );
252
275
SendCommand (cmd);
253
276
254
277
// Read the length
0 commit comments