15 #ifndef VISIONTRANSFER_PARAMETERTRANSFER_H 16 #define VISIONTRANSFER_PARAMETERTRANSFER_H 18 #include "visiontransfer/networking.h" 19 #include "visiontransfer/parameterinfo.h" 20 #include "visiontransfer/tokenizer.h" 21 #include "visiontransfer/parameterset.h" 27 #include <condition_variable> 142 void writeParameter(
const char*
id,
const T& value,
bool synchronous=
true);
185 void setParameterUpdateCallback(std::function<
void(
const std::string& uid)> callback);
201 static constexpr
int SOCKET_TIMEOUT_MS = 500;
202 static constexpr
int SOCKET_RECONNECT_INTERVAL_MS = 2000;
205 static constexpr
unsigned char MESSAGE_READ_INT = 0x01;
206 static constexpr
unsigned char MESSAGE_READ_DOUBLE = 0x02;
207 static constexpr
unsigned char MESSAGE_READ_BOOL = 0x03;
208 static constexpr
unsigned char MESSAGE_WRITE_INT = 0x04;
209 static constexpr
unsigned char MESSAGE_WRITE_DOUBLE = 0x05;
210 static constexpr
unsigned char MESSAGE_WRITE_BOOL = 0x06;
211 static constexpr
unsigned char MESSAGE_ENUMERATE_PARAMS = 0x07;
218 static constexpr
unsigned int RECV_BUF_SIZE = 1024*1024;
219 char recvBuf[RECV_BUF_SIZE];
220 unsigned int recvBufBytes;
221 unsigned int pollDelay;
223 std::string networkErrorString;
227 bool featureDisabledTransactions;
230 std::shared_ptr<std::thread> receiverThread;
237 mutable std::mutex readyMutex;
239 mutable std::condition_variable readyCond;
243 std::mutex socketModificationMutex;
245 std::map<int, std::condition_variable> waitConds;
247 std::map<int, std::mutex> waitCondMutexes;
249 std::map<int, std::pair<bool, std::string> > lastSetRequestResult;
252 std::function<void(const std::string&)> parameterUpdateCallback;
254 thread_local
static bool transactionInProgress;
255 thread_local
static std::vector<std::pair<std::string, std::string> > transactionQueuedWrites;
258 void attemptConnection();
261 void waitNetworkReady()
const;
267 void blockingCallThisThread(std::function<
void()>,
int waitMaxMilliseconds=1000);
269 void receiverRoutine();
272 void readParameter(
unsigned char messageType,
const char*
id,
unsigned char* dest,
int length);
273 void recvData(
unsigned char* dest,
int length);
275 std::map<std::string, ParameterInfo> recvEnumeration();
278 void writeParameterTransactionGuardedImpl(
const char*
id,
const T& value);
281 void writeParameterTransactionUnguardedImpl(
const char*
id,
const T& value);
283 void sendNetworkCommand(
const std::string& cmdline);
void transactionCommitQueue()
Complete the started parameter transaction.
void writeIntParameter(const char *id, int value)
Writes an integer value to a parameter of the parameter server.
Allows a configuration of device parameters over the network.
void writeParameter(const char *id, const T &value, bool synchronous=true)
Writes a scalar value to a parameter of the parameter server.
void writeParameterTransactionUnguarded(const char *id, const T &value)
Writes a scalar value to a parameter of the parameter server, using 'fire-and-forget' for real-time c...
ParameterTransfer(const char *address, const char *service="7683")
Creates an object and connects to the given server.
bool readBoolParameter(const char *id)
Reads a boolean value from the parameter server.
std::map< std::string, ParameterInfo > getAllParameters()
Enumerates all parameters as reported by the device.
void transactionStartQueue()
Start batch parameter transaction.
void writeParameterTransactionGuarded(const char *id, const T &value)
Writes a scalar value to a parameter of the parameter server, transparently deferring for a batch upd...
param::ParameterSet & getParameterSet()
Returns a reference to the internal parameter set (once the network handshake is complete) ...
double readDoubleParameter(const char *id)
Reads a double precision floating point value from the parameter server.
void writeBoolParameter(const char *id, bool value)
Writes a boolean value to a parameter of the parameter server.
int readIntParameter(const char *id)
Reads an integer value from the parameter server.
void writeDoubleParameter(const char *id, double value)
Writes a double precision floating point value to a parameter of the parameter server.