libvisiontransfer  8.1.0
parametertransfer.h
1 /*******************************************************************************
2  * Copyright (c) 2020 Nerian Vision GmbH
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *******************************************************************************/
14 
15 #ifndef VISIONTRANSFER_PARAMETERTRANSFER_H
16 #define VISIONTRANSFER_PARAMETERTRANSFER_H
17 
18 #include "visiontransfer/networking.h"
19 #include "visiontransfer/parameterinfo.h"
20 
21 #include <map>
22 
23 namespace visiontransfer {
24 namespace internal {
25 
40 public:
48  ParameterTransfer(const char* address, const char* service = "7683");
50 
61  int readIntParameter(int32_t id);
62 
74  double readDoubleParameter(int32_t id);
75 
86  bool readBoolParameter(int32_t id);
87 
98  void writeIntParameter(int32_t id, int32_t value);
99 
110  void writeDoubleParameter(int32_t id, double value);
111 
122  void writeBoolParameter(int32_t id, int32_t value);
123 
127  std::map<std::string, ParameterInfo> getAllParameters();
128 
129 private:
130  static constexpr int SOCKET_TIMEOUT_MS = 500;
131 
132  // Message types
133  static constexpr unsigned char MESSAGE_READ_INT = 0x01;
134  static constexpr unsigned char MESSAGE_READ_DOUBLE = 0x02;
135  static constexpr unsigned char MESSAGE_READ_BOOL = 0x03;
136  static constexpr unsigned char MESSAGE_WRITE_INT = 0x04;
137  static constexpr unsigned char MESSAGE_WRITE_DOUBLE = 0x05;
138  static constexpr unsigned char MESSAGE_WRITE_BOOL = 0x06;
139  static constexpr unsigned char MESSAGE_ENUMERATE_PARAMS = 0x07;
140 
141  SOCKET socket;
142 
143  void checkProtocolVersion();
144  void readParameter(unsigned char messageType, int32_t id, unsigned char* dest, int length);
145  void recvData(unsigned char* dest, int length);
146 
147  template<typename T>
148  void writeParameter(unsigned char messageType, int32_t id, T value);
149 
150  std::map<std::string, ParameterInfo> recvEnumeration();
151 };
152 
153 }} // namespace
154 
155 #endif
bool readBoolParameter(int32_t id)
Reads a boolean value from the parameter server.
int readIntParameter(int32_t id)
Reads an integer value from the parameter server.
Allows a configuration of device parameters over the network.
void writeBoolParameter(int32_t id, int32_t value)
Writes a boolean value to a parameter of the parameter server.
void writeIntParameter(int32_t id, int32_t value)
Writes an integer value to a parameter of the parameter server.
void writeDoubleParameter(int32_t id, double value)
Writes a double precision floating point value to a parameter of the parameter server.
ParameterTransfer(const char *address, const char *service="7683")
Creates an object and connects to the given server.
std::map< std::string, ParameterInfo > getAllParameters()
Enumerates all parameters as reported by the device.
double readDoubleParameter(int32_t id)
Reads a double precision floating point value from the parameter server.
Nerian Vision Technologies