Time-of-Flight Library(ToF)  3.2.2
gige_interface.hpp
1 #ifndef _CHRONOPTICS_TOF_GIGE_INTERFACE_HPP_
2 #define _CHRONOPTICS_TOF_GIGE_INTERFACE_HPP_
3 
4 #include <chronoptics/tof/gige_interface.h>
5 
6 #include <chronoptics/tof/camera_config.hpp>
7 #include <chronoptics/tof/calibration.hpp>
8 #include <chronoptics/tof/data.hpp>
9 
10 namespace chronoptics {
11 namespace tof {
12 
13 /** The possible depth streams that can be streamed from the camera
14  */
15 enum class DepthStreamType {
16  RAW = 0, /** Stream raw data */
17  RADIAL_INTENSITY = 1, /** Stream both radial and intensity */
18  RADIAL = 2, /** Stream radial */
19  INTENSITY = 3, /** Stream intensity */
20 };
21 
22 /** A gige discovery message containing camera information
23 */
24 class DiscoveryMessage : public detail::Base<tof_discovery_message, tof_discovery_message_delete> {
25  public:
26  /** Construct from pointer */
27  DiscoveryMessage(tof_discovery_message_t ptr = nullptr) {
28  this->ptr_ = ptr;
29  }
30 
31  /** Get the camera's ip address
32  * @return Ip address
33  */
34  const char* ip() const {
35  return tof_discovery_message_ip(this->ptr_, TOF_ERROR_HANDLER{});
36  }
37 
38  /** Get the camera's serial
39  * @return Serial
40  */
41  const char* serial() const {
42  return tof_discovery_message_serial(this->ptr_, TOF_ERROR_HANDLER{});
43  }
44 
45 };
46 
47 /** A persistent ip data structure
48 */
49 class PersistentIp : public detail::Base<tof_persistent_ip, tof_persistent_ip_delete> {
50  public:
51  /** Construct from pointer */
52  PersistentIp(tof_persistent_ip_t ptr = nullptr) {
53  this->ptr_ = ptr;
54  }
55 
56  /** Create persistent ip
57  * @param ip IP address
58  * @param netmask Netmask
59  * @param gateway Gateway
60  * @param enabled Enable or disable persistent ip
61  */
62  PersistentIp(StringView ip, StringView netmask, StringView gateway, bool enabled) {
63  this->ptr_ = tof_persistent_ip_new(ip, netmask, gateway, enabled, TOF_ERROR_HANDLER{});
64  }
65 
66  /** Get the IP address
67  * @return the IP address
68  */
69  const char* get_ip() const {
70  return tof_persistent_ip_get_ip(this->ptr_, TOF_ERROR_HANDLER{});
71  }
72 
73  /** Set the IP address
74  * @param ip the IP address
75  */
76  void set_ip(StringView ip) {
77  return tof_persistent_ip_set_ip(this->ptr_, ip, TOF_ERROR_HANDLER{});
78  }
79 
80  /** Get the netmask
81  * @return The netmask
82  */
83  const char* get_netmask() const {
84  return tof_persistent_ip_get_netmask(this->ptr_, TOF_ERROR_HANDLER{});
85  }
86 
87  /** Set the netmask
88  * @param netmask The netmask
89  */
90  void set_netmask(StringView netmask) {
91  return tof_persistent_ip_set_netmask(this->ptr_, netmask, TOF_ERROR_HANDLER{});
92  }
93 
94  /** Get the gateway
95  * @return The gateway
96  */
97  const char* get_gateway() const {
98  return tof_persistent_ip_get_gateway(this->ptr_, TOF_ERROR_HANDLER{});
99  }
100 
101  /** Set the gateway
102  * @param gateway The gateway
103  */
104  void set_gateway(StringView gateway) {
105  return tof_persistent_ip_set_gateway(this->ptr_, gateway, TOF_ERROR_HANDLER{});
106  }
107 
108  /** Get if persistent ip is enabled
109  * @return Is enabled
110  */
111  bool get_enabled() const {
112  return tof_persistent_ip_get_enabled(this->ptr_, TOF_ERROR_HANDLER{});
113  }
114 
115  /** Set if persistent ip is enabled
116  * @param enabled Is enabled
117  */
118  void set_enabled(bool enabled) {
119  return tof_persistent_ip_set_enabled(this->ptr_, enabled, TOF_ERROR_HANDLER{});
120  }
121 
122 };
123 
124 /** Connect to a camera directly using the gige interface
125 */
126 class GigeInterface : public detail::Base<tof_gige_interface, tof_gige_interface_delete> {
127  public:
128  /** Construct from pointer */
129  GigeInterface(tof_gige_interface_t ptr) {
130  this->ptr_ = ptr;
131  }
132 
133  /** Create an instance of the gige interface
134  * @param port The port to use for GVCP communication, if 0 is specified it
135  * will use an OS assigned port
136  */
137  GigeInterface(uint16_t port = 0) {
138  this->ptr_ = tof_gige_interface_new(port, TOF_ERROR_HANDLER{});
139  }
140 
141  /** Detect all the cameras on the network
142  * @return A list of discovery messages
143  */
144  std::vector<DiscoveryMessage> discover() {
145  size_t size = tof_gige_interface_discover(this->ptr_, nullptr, 0, TOF_ERROR_HANDLER{});
146  std::vector<DiscoveryMessage> vec;
147  vec.reserve(size);
148  for (size_t i = 0; i < size; i++)
149  vec.emplace_back(static_cast<tof_discovery_message_t>(nullptr));
150  auto data = reinterpret_cast<tof_discovery_message_t*>(vec.data());
151  size = tof_gige_interface_discover(this->ptr_, data, vec.size(), TOF_ERROR_HANDLER{});
152  return vec;
153  }
154 
155  /** Returns a message of the first camera that responded
156  * @return A discovery message
157  */
159  DiscoveryMessage new_discovery_message(static_cast<tof_discovery_message_t>(nullptr));
160  auto ptr = reinterpret_cast<tof_discovery_message_t*>(&new_discovery_message);
161  *ptr = tof_gige_interface_discover_one(this->ptr_, TOF_ERROR_HANDLER{});
162  return new_discovery_message;
163  }
164 
165  /** Detect a specific camera on the network, will throw an error if it can't
166  * find the camera
167  * @param serial Serial number of camera to find
168  * @return A discovery message
169  */
170  DiscoveryMessage find(StringView serial) {
171  DiscoveryMessage new_discovery_message(static_cast<tof_discovery_message_t>(nullptr));
172  auto ptr = reinterpret_cast<tof_discovery_message_t*>(&new_discovery_message);
173  *ptr = tof_gige_interface_find(this->ptr_, serial, TOF_ERROR_HANDLER{});
174  return new_discovery_message;
175  }
176 
177  /** Connect to the camera and gain exclusive access
178  * @param message Discovery message of the camera to connect to
179  */
180  void connect(const DiscoveryMessage &message) {
181  return tof_gige_interface_connect(this->ptr_, *reinterpret_cast<const tof_discovery_message_t*>(&message), TOF_ERROR_HANDLER{});
182  }
183 
184  /** Disconnect from the camera
185  */
186  void disconnect() {
187  return tof_gige_interface_disconnect(this->ptr_, TOF_ERROR_HANDLER{});
188  }
189 
190  /** Check whether a connection is still maintained with the camera
191  * @return Is connected
192  */
193  bool is_connected() const {
194  return tof_gige_interface_is_connected(this->ptr_, TOF_ERROR_HANDLER{});
195  }
196 
197  /** Get stream packet size
198  * @return The packet size
199  */
200  uint16_t get_stream_packet_size() const {
201  return tof_gige_interface_get_stream_packet_size(this->ptr_, TOF_ERROR_HANDLER{});
202  }
203 
204  /** Set stream packet size
205  * @param packet_size The packet size
206  */
207  void set_stream_packet_size(uint16_t packet_size) {
208  return tof_gige_interface_set_stream_packet_size(this->ptr_, packet_size, TOF_ERROR_HANDLER{});
209  }
210 
211  /** Test whether using the set packet size works
212  * @param port Port to send test packets to
213  * @return Packet size works
214  */
215  bool test_stream_packet_size(uint16_t port = 0) {
216  return tof_gige_interface_test_stream_packet_size(this->ptr_, port, TOF_ERROR_HANDLER{});
217  }
218 
219  /** Get delay between network packets
220  * @return The delay, depending on the camera software it is in nanoseconds or
221  * in cpu instruction
222  */
223  uint32_t get_delay() const {
224  return tof_gige_interface_get_delay(this->ptr_, TOF_ERROR_HANDLER{});
225  }
226 
227  /** Set delay between network packets
228  * @param delay The delay, depending on the camera software it is in
229  * nanoseconds or in cpu instruction
230  */
231  void set_delay(uint32_t delay) {
232  return tof_gige_interface_set_delay(this->ptr_, delay, TOF_ERROR_HANDLER{});
233  }
234 
235  /** Download camera configuration from the camera
236  * @param port Port to download configuration on
237  * @return Camera configuration
238  */
240  CameraConfig new_camera_config(static_cast<tof_camera_config_t>(nullptr));
241  auto ptr = reinterpret_cast<tof_camera_config_t*>(&new_camera_config);
242  *ptr = tof_gige_interface_download_configuration(this->ptr_, port, TOF_ERROR_HANDLER{});
243  return new_camera_config;
244  }
245 
246  /** Download calibration from the camera
247  * @param port Port to download configuration on
248  * @return Calibration
249  */
250  Calibration download_calibration(uint16_t port = 0) {
251  Calibration new_calibration(static_cast<tof_calibration_t>(nullptr));
252  auto ptr = reinterpret_cast<tof_calibration_t*>(&new_calibration);
253  *ptr = tof_gige_interface_download_calibration(this->ptr_, port, TOF_ERROR_HANDLER{});
254  return new_calibration;
255  }
256 
257  /** Upload camera configuration to the camera
258  * @param config Camera configuration
259  * @param port Port to download configuration on
260  */
261  void upload_configuration(const CameraConfig &config, uint16_t port = 0) {
262  return tof_gige_interface_upload_configuration(this->ptr_, *reinterpret_cast<const tof_camera_config_t*>(&config), port, TOF_ERROR_HANDLER{});
263  }
264 
265  /** Check whether this camera is capable of streaming the specified type
266  * @param stream Depth stream type
267  * @return Is capable
268  */
269  bool depth_stream_capable(DepthStreamType stream) const {
270  return tof_gige_interface_depth_stream_capable(this->ptr_, static_cast<tof_depth_stream_type>(stream), TOF_ERROR_HANDLER{});
271  }
272 
273  /** Start the depth stream
274  * @param stream Depth stream type
275  * @param port Port to receive depth data on
276  */
277  void start_depth_stream(DepthStreamType stream, uint16_t port = 0) {
278  return tof_gige_interface_start_depth_stream(this->ptr_, static_cast<tof_depth_stream_type>(stream), port, TOF_ERROR_HANDLER{});
279  }
280 
281  /** Stop the depth stream
282  */
284  return tof_gige_interface_stop_depth_stream(this->ptr_, TOF_ERROR_HANDLER{});
285  }
286 
287  /** Returns true if a depth frame is available
288  * @return Depth frame available
289  */
290  bool has_depth_data() const {
291  return tof_gige_interface_has_depth_data(this->ptr_, TOF_ERROR_HANDLER{});
292  }
293 
294  /** Get a depth frame
295  * @return Depth frame
296  */
298  Data new_data(static_cast<tof_data_t>(nullptr));
299  auto ptr = reinterpret_cast<tof_data_t*>(&new_data);
300  *ptr = tof_gige_interface_get_depth_data(this->ptr_, TOF_ERROR_HANDLER{});
301  return new_data;
302  }
303 
304  /** Check whether camera supports an image stream
305  * @return Camera supports an image stream
306  */
307  bool image_stream_capable() const {
308  return tof_gige_interface_image_stream_capable(this->ptr_, TOF_ERROR_HANDLER{});
309  }
310 
311  /** Start image stream
312  * @param port Port to receive image data on
313  */
314  void start_image_stream(uint16_t port = 0) {
315  return tof_gige_interface_start_image_stream(this->ptr_, port, TOF_ERROR_HANDLER{});
316  }
317 
318  /** Stop image stream
319  */
321  return tof_gige_interface_stop_image_stream(this->ptr_, TOF_ERROR_HANDLER{});
322  }
323 
324  /** Check whether image frame is available
325  * @return Image frame available
326  */
327  bool has_image_data() const {
328  return tof_gige_interface_has_image_data(this->ptr_, TOF_ERROR_HANDLER{});
329  }
330 
331  /** Get image frame
332  * @return Image data
333  */
335  Data new_data(static_cast<tof_data_t>(nullptr));
336  auto ptr = reinterpret_cast<tof_data_t*>(&new_data);
337  *ptr = tof_gige_interface_get_image_data(this->ptr_, TOF_ERROR_HANDLER{});
338  return new_data;
339  }
340 
341  /** Get the image frame into the supplied pointer
342  * @param pointer The pointer to the data to write into
343  * @param capacity The amount of data the pointer can hold
344  * @param callback Callback that will be called when pointer is no longer in
345  * use
346  * @return Image data
347  */
348  Data get_image_data_into_pointer(uint8_t* pointer, size_t capacity, user_pointer_destructed_fn &callback) {
349  Data new_data(static_cast<tof_data_t>(nullptr));
350  auto ptr = reinterpret_cast<tof_data_t*>(&new_data);
351  *ptr = tof_gige_interface_get_image_data_into_pointer(this->ptr_, pointer, capacity, user_pointer_destructed_cb_handler, &callback, TOF_ERROR_HANDLER{});
352  return new_data;
353  }
354 
355  /** Get the image frame into the supplied pointer
356  * @param pointer The pointer to the data to write into
357  * @param capacity The amount of data the pointer can hold
358  * @param callback Callback that will be called when pointer is no longer in
359  * use
360  * @param callback_user_data User data that will be passed back when the function pointer is called
361  * @return Image data
362  */
363  Data get_image_data_into_pointer(uint8_t* pointer, size_t capacity, tof_user_pointer_destructed_t callback, void* callback_user_data) {
364  Data new_data(static_cast<tof_data_t>(nullptr));
365  auto ptr = reinterpret_cast<tof_data_t*>(&new_data);
366  *ptr = tof_gige_interface_get_image_data_into_pointer(this->ptr_, pointer, capacity, callback, callback_user_data, TOF_ERROR_HANDLER{});
367  return new_data;
368  }
369 
370  /** Get whether the camera is persistent ip capable
371  * @return Persistent IP capable
372  */
373  bool persistent_ip_capable() const {
374  return tof_gige_interface_persistent_ip_capable(this->ptr_, TOF_ERROR_HANDLER{});
375  }
376 
377  /** Get the current persistent ip settings
378  * @return Persistent IP
379  */
381  PersistentIp new_persistent_ip(static_cast<tof_persistent_ip_t>(nullptr));
382  auto ptr = reinterpret_cast<tof_persistent_ip_t*>(&new_persistent_ip);
383  *ptr = tof_gige_interface_get_persistent_ip(this->ptr_, TOF_ERROR_HANDLER{});
384  return new_persistent_ip;
385  }
386 
387  /** Set the persistent ip settings. The persistent ip settings will be active
388  * on next reboot.
389  * @param persistent_ip The persistent ip
390  */
391  void set_persistent_ip(const PersistentIp &persistent_ip) {
392  return tof_gige_interface_set_persistent_ip(this->ptr_, *reinterpret_cast<const tof_persistent_ip_t*>(&persistent_ip), TOF_ERROR_HANDLER{});
393  }
394 
395  /** Get the capacity for amount of user pointers that can be registered
396  * @return User pointer capacity
397  */
398  size_t get_user_pointer_capacity() const {
399  return tof_gige_interface_get_user_pointer_capacity(this->ptr_, TOF_ERROR_HANDLER{});
400  }
401 
402  /** Set the capacity for amount of user pointers that can be registered
403  * @param capacity User pointer capacity
404  */
405  void set_user_pointer_capacity(size_t capacity) {
406  return tof_gige_interface_set_user_pointer_capacity(this->ptr_, capacity, TOF_ERROR_HANDLER{});
407  }
408 
409  /** Add a pointer that will be filled with depth data. This method allows you
410  * to fill data straight into your own data structure without any additional
411  * copying.
412  * @param pointer The pointer to the data to write into
413  * @param capacity The amount of data the pointer can hold
414  * @param callback Callback that will be called when pointer is no longer in
415  * use
416  */
417  void add_depth_user_pointer(uint8_t* pointer, size_t capacity, user_pointer_destructed_fn &callback) {
418  return tof_gige_interface_add_depth_user_pointer(this->ptr_, pointer, capacity, user_pointer_destructed_cb_handler, &callback, TOF_ERROR_HANDLER{});
419  }
420 
421  /** Add a pointer that will be filled with depth data. This method allows you
422  * to fill data straight into your own data structure without any additional
423  * copying.
424  * @param pointer The pointer to the data to write into
425  * @param capacity The amount of data the pointer can hold
426  * @param callback Callback that will be called when pointer is no longer in
427  * use
428  * @param callback_user_data User data that will be passed back when the function pointer is called
429  */
430  void add_depth_user_pointer(uint8_t* pointer, size_t capacity, tof_user_pointer_destructed_t callback, void* callback_user_data) {
431  return tof_gige_interface_add_depth_user_pointer(this->ptr_, pointer, capacity, callback, callback_user_data, TOF_ERROR_HANDLER{});
432  }
433 
434  /** Get the tof library version running on the camera
435  * @return Version
436  */
437  const char* version() {
438  return tof_gige_interface_version(this->ptr_, TOF_ERROR_HANDLER{});
439  }
440 
441 };
442 
443 } // tof
444 } // chronoptics
445 
446 #endif
This class contains all the calibration information.
Definition: calibration.hpp:13
This class allows you to view/edit the camera settings.
This is the class that contains depth or image data.
Definition: data.hpp:31
A gige discovery message containing camera information.
const char * ip() const
Get the camera's ip address.
const char * serial() const
Get the camera's serial.
DiscoveryMessage(tof_discovery_message_t ptr=nullptr)
Construct from pointer.
Connect to a camera directly using the gige interface.
DiscoveryMessage discover_one()
Returns a message of the first camera that responded.
bool depth_stream_capable(DepthStreamType stream) const
Check whether this camera is capable of streaming the specified type.
std::vector< DiscoveryMessage > discover()
Detect all the cameras on the network.
CameraConfig download_configuration(uint16_t port=0)
Download camera configuration from the camera.
void disconnect()
Disconnect from the camera.
void set_stream_packet_size(uint16_t packet_size)
Set stream packet size.
void start_image_stream(uint16_t port=0)
Start image stream.
void stop_depth_stream()
Stop the depth stream.
GigeInterface(tof_gige_interface_t ptr)
Construct from pointer.
const char * version()
Get the tof library version running on the camera.
void add_depth_user_pointer(uint8_t *pointer, size_t capacity, tof_user_pointer_destructed_t callback, void *callback_user_data)
Add a pointer that will be filled with depth data.
GigeInterface(uint16_t port=0)
Create an instance of the gige interface.
bool image_stream_capable() const
Check whether camera supports an image stream.
void connect(const DiscoveryMessage &message)
Connect to the camera and gain exclusive access.
Data get_image_data()
Get image frame.
bool persistent_ip_capable() const
Get whether the camera is persistent ip capable.
Calibration download_calibration(uint16_t port=0)
Download calibration from the camera.
uint32_t get_delay() const
Get delay between network packets.
size_t get_user_pointer_capacity() const
Get the capacity for amount of user pointers that can be registered.
Data get_depth_data()
Get a depth frame.
void start_depth_stream(DepthStreamType stream, uint16_t port=0)
Start the depth stream.
bool has_depth_data() const
Returns true if a depth frame is available.
uint16_t get_stream_packet_size() const
Get stream packet size.
bool test_stream_packet_size(uint16_t port=0)
Test whether using the set packet size works.
void set_user_pointer_capacity(size_t capacity)
Set the capacity for amount of user pointers that can be registered.
void set_persistent_ip(const PersistentIp &persistent_ip)
Set the persistent ip settings.
void add_depth_user_pointer(uint8_t *pointer, size_t capacity, user_pointer_destructed_fn &callback)
Add a pointer that will be filled with depth data.
Data get_image_data_into_pointer(uint8_t *pointer, size_t capacity, tof_user_pointer_destructed_t callback, void *callback_user_data)
Get the image frame into the supplied pointer.
void upload_configuration(const CameraConfig &config, uint16_t port=0)
Upload camera configuration to the camera.
void set_delay(uint32_t delay)
Set delay between network packets.
PersistentIp get_persistent_ip() const
Get the current persistent ip settings.
bool has_image_data() const
Check whether image frame is available.
void stop_image_stream()
Stop image stream.
DiscoveryMessage find(StringView serial)
Detect a specific camera on the network, will throw an error if it can't find the camera.
bool is_connected() const
Check whether a connection is still maintained with the camera.
Data get_image_data_into_pointer(uint8_t *pointer, size_t capacity, user_pointer_destructed_fn &callback)
Get the image frame into the supplied pointer.
A persistent ip data structure.
void set_gateway(StringView gateway)
Set the gateway.
bool get_enabled() const
Get if persistent ip is enabled.
void set_enabled(bool enabled)
Set if persistent ip is enabled.
void set_netmask(StringView netmask)
Set the netmask.
const char * get_ip() const
Get the IP address.
const char * get_netmask() const
Get the netmask.
PersistentIp(tof_persistent_ip_t ptr=nullptr)
Construct from pointer.
void set_ip(StringView ip)
Set the IP address.
PersistentIp(StringView ip, StringView netmask, StringView gateway, bool enabled)
Create persistent ip.
const char * get_gateway() const
Get the gateway.