Time-of-Flight Library(ToF) 3.13.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
10namespace chronoptics {
11namespace tof {
12
13/** The possible depth streams that can be streamed from the camera
14 */
15enum 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*/
24class 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*/
49class 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/** DEPRECATED, use KeaCamera. Connect to a camera directly using the gige
125 * interface
126*/
127class GigeInterface : public detail::Base<tof_gige_interface, tof_gige_interface_delete> {
128 public:
129 /** Construct from pointer */
130 GigeInterface(tof_gige_interface_t ptr) {
131 this->ptr_ = ptr;
132 }
133
134 /** Create an instance of the gige interface
135 * @param port The port to use for GVCP communication, if 0 is specified it
136 * will use an OS assigned port
137 */
138 GigeInterface(uint16_t port = 0) {
139 this->ptr_ = tof_gige_interface_new(port, TOF_ERROR_HANDLER{});
140 }
141
142 /** Detect all the cameras on the network
143 * @return A list of discovery messages
144 */
145 std::vector<DiscoveryMessage> discover() {
146 size_t size = tof_gige_interface_discover(this->ptr_, nullptr, 0, TOF_ERROR_HANDLER{});
147 std::vector<DiscoveryMessage> vec;
148 vec.reserve(size);
149 for (size_t i = 0; i < size; i++)
150 vec.emplace_back(static_cast<tof_discovery_message_t>(nullptr));
151 auto data = reinterpret_cast<tof_discovery_message_t*>(vec.data());
152 size = tof_gige_interface_discover(this->ptr_, data, vec.size(), TOF_ERROR_HANDLER{});
153 return vec;
154 }
155
156 /** Returns a message of the first camera that responded
157 * @return A discovery message
158 */
160 DiscoveryMessage new_discovery_message(static_cast<tof_discovery_message_t>(nullptr));
161 auto ptr = reinterpret_cast<tof_discovery_message_t*>(&new_discovery_message);
162 *ptr = tof_gige_interface_discover_one(this->ptr_, TOF_ERROR_HANDLER{});
163 return new_discovery_message;
164 }
165
166 /** Detect a specific camera on the network, will throw an error if it can't
167 * find the camera
168 * @param serial Serial number of camera to find
169 * @return A discovery message
170 */
171 DiscoveryMessage find(StringView serial) {
172 DiscoveryMessage new_discovery_message(static_cast<tof_discovery_message_t>(nullptr));
173 auto ptr = reinterpret_cast<tof_discovery_message_t*>(&new_discovery_message);
174 *ptr = tof_gige_interface_find(this->ptr_, serial, TOF_ERROR_HANDLER{});
175 return new_discovery_message;
176 }
177
178 /** Connect to the camera and gain exclusive access
179 * @param message Discovery message of the camera to connect to
180 */
181 void connect(const DiscoveryMessage &message) {
182 return tof_gige_interface_connect(this->ptr_, *reinterpret_cast<const tof_discovery_message_t*>(&message), TOF_ERROR_HANDLER{});
183 }
184
185 /** Disconnect from the camera
186 */
187 void disconnect() {
188 return tof_gige_interface_disconnect(this->ptr_, TOF_ERROR_HANDLER{});
189 }
190
191 /** Check whether a connection is still maintained with the camera
192 * @return Is connected
193 */
194 bool is_connected() const {
195 return tof_gige_interface_is_connected(this->ptr_, TOF_ERROR_HANDLER{});
196 }
197
198 /** Get stream packet size
199 * @return The packet size
200 */
201 uint16_t get_stream_packet_size() const {
202 return tof_gige_interface_get_stream_packet_size(this->ptr_, TOF_ERROR_HANDLER{});
203 }
204
205 /** Set stream packet size
206 * @param packet_size The packet size
207 */
208 void set_stream_packet_size(uint16_t packet_size) {
209 return tof_gige_interface_set_stream_packet_size(this->ptr_, packet_size, TOF_ERROR_HANDLER{});
210 }
211
212 /** Test whether using the set packet size works
213 * @param port Port to send test packets to
214 * @return Packet size works
215 */
216 bool test_stream_packet_size(uint16_t port = 0) {
217 return tof_gige_interface_test_stream_packet_size(this->ptr_, port, TOF_ERROR_HANDLER{});
218 }
219
220 /** Get delay between network packets
221 * @return The delay, depending on the camera software it is in nanoseconds or
222 * in cpu instruction
223 */
224 uint32_t get_delay() const {
225 return tof_gige_interface_get_delay(this->ptr_, TOF_ERROR_HANDLER{});
226 }
227
228 /** Set delay between network packets
229 * @param delay The delay, depending on the camera software it is in
230 * nanoseconds or in cpu instruction
231 */
232 void set_delay(uint32_t delay) {
233 return tof_gige_interface_set_delay(this->ptr_, delay, TOF_ERROR_HANDLER{});
234 }
235
236 /** Download camera configuration from the camera
237 * @param port Port to download configuration on
238 * @return Camera configuration
239 */
241 CameraConfig new_camera_config(static_cast<tof_camera_config_t>(nullptr));
242 auto ptr = reinterpret_cast<tof_camera_config_t*>(&new_camera_config);
243 *ptr = tof_gige_interface_download_configuration(this->ptr_, port, TOF_ERROR_HANDLER{});
244 return new_camera_config;
245 }
246
247 /** Download calibration from the camera
248 * @param port Port to download configuration on
249 * @return Calibration
250 */
252 Calibration new_calibration(static_cast<tof_calibration_t>(nullptr));
253 auto ptr = reinterpret_cast<tof_calibration_t*>(&new_calibration);
254 *ptr = tof_gige_interface_download_calibration(this->ptr_, port, TOF_ERROR_HANDLER{});
255 return new_calibration;
256 }
257
258 /** Upload camera configuration to the camera
259 * @param config Camera configuration
260 * @param port Port to download configuration on
261 */
262 void upload_configuration(const CameraConfig &config, uint16_t port = 0) {
263 return tof_gige_interface_upload_configuration(this->ptr_, *reinterpret_cast<const tof_camera_config_t*>(&config), port, TOF_ERROR_HANDLER{});
264 }
265
266 /** Check whether this camera is capable of streaming the specified type
267 * @param stream Depth stream type
268 * @return Is capable
269 */
270 bool depth_stream_capable(DepthStreamType stream) const {
271 return tof_gige_interface_depth_stream_capable(this->ptr_, static_cast<tof_depth_stream_type>(stream), TOF_ERROR_HANDLER{});
272 }
273
274 /** Start the depth stream
275 * @param stream Depth stream type
276 * @param port Port to receive depth data on
277 */
278 void start_depth_stream(DepthStreamType stream, uint16_t port = 0) {
279 return tof_gige_interface_start_depth_stream(this->ptr_, static_cast<tof_depth_stream_type>(stream), port, TOF_ERROR_HANDLER{});
280 }
281
282 /** Stop the depth stream
283 */
285 return tof_gige_interface_stop_depth_stream(this->ptr_, TOF_ERROR_HANDLER{});
286 }
287
288 /** Returns true if a depth frame is available
289 * @return Depth frame available
290 */
291 bool has_depth_data() const {
292 return tof_gige_interface_has_depth_data(this->ptr_, TOF_ERROR_HANDLER{});
293 }
294
295 /** Get a depth frame
296 * @return Depth frame
297 */
299 Data new_data(static_cast<tof_data_t>(nullptr));
300 auto ptr = reinterpret_cast<tof_data_t*>(&new_data);
301 *ptr = tof_gige_interface_get_depth_data(this->ptr_, TOF_ERROR_HANDLER{});
302 return new_data;
303 }
304
305 /** Check whether camera supports an image stream
306 * @return Camera supports an image stream
307 */
308 bool image_stream_capable() const {
309 return tof_gige_interface_image_stream_capable(this->ptr_, TOF_ERROR_HANDLER{});
310 }
311
312 /** Start image stream
313 * @param port Port to receive image data on
314 */
315 void start_image_stream(uint16_t port = 0) {
316 return tof_gige_interface_start_image_stream(this->ptr_, port, TOF_ERROR_HANDLER{});
317 }
318
319 /** Stop image stream
320 */
322 return tof_gige_interface_stop_image_stream(this->ptr_, TOF_ERROR_HANDLER{});
323 }
324
325 /** Check whether image frame is available
326 * @return Image frame available
327 */
328 bool has_image_data() const {
329 return tof_gige_interface_has_image_data(this->ptr_, TOF_ERROR_HANDLER{});
330 }
331
332 /** Get image frame
333 * @return Image data
334 */
336 Data new_data(static_cast<tof_data_t>(nullptr));
337 auto ptr = reinterpret_cast<tof_data_t*>(&new_data);
338 *ptr = tof_gige_interface_get_image_data(this->ptr_, TOF_ERROR_HANDLER{});
339 return new_data;
340 }
341
342 /** Get the image frame into the supplied pointer
343 * @param pointer The pointer to the data to write into
344 * @param capacity The amount of data the pointer can hold
345 * @param callback Callback that will be called when pointer is no longer in
346 * use
347 * @return Image data
348 */
349 Data get_image_data_into_pointer(uint8_t* pointer, size_t capacity, user_pointer_destructed_fn &callback) {
350 Data new_data(static_cast<tof_data_t>(nullptr));
351 auto ptr = reinterpret_cast<tof_data_t*>(&new_data);
352 *ptr = tof_gige_interface_get_image_data_into_pointer(this->ptr_, pointer, capacity, user_pointer_destructed_cb_handler, &callback, TOF_ERROR_HANDLER{});
353 return new_data;
354 }
355
356 /** Get the image frame into the supplied pointer
357 * @param pointer The pointer to the data to write into
358 * @param capacity The amount of data the pointer can hold
359 * @param callback Callback that will be called when pointer is no longer in
360 * use
361 * @param callback_user_data User data that will be passed back when the function pointer is called
362 * @return Image data
363 */
364 Data get_image_data_into_pointer(uint8_t* pointer, size_t capacity, tof_user_pointer_destructed_t callback, void* callback_user_data) {
365 Data new_data(static_cast<tof_data_t>(nullptr));
366 auto ptr = reinterpret_cast<tof_data_t*>(&new_data);
367 *ptr = tof_gige_interface_get_image_data_into_pointer(this->ptr_, pointer, capacity, callback, callback_user_data, TOF_ERROR_HANDLER{});
368 return new_data;
369 }
370
371 /** Get whether the camera is persistent ip capable
372 * @return Persistent IP capable
373 */
375 return tof_gige_interface_persistent_ip_capable(this->ptr_, TOF_ERROR_HANDLER{});
376 }
377
378 /** Get the current persistent ip settings
379 * @return Persistent IP
380 */
382 PersistentIp new_persistent_ip(static_cast<tof_persistent_ip_t>(nullptr));
383 auto ptr = reinterpret_cast<tof_persistent_ip_t*>(&new_persistent_ip);
384 *ptr = tof_gige_interface_get_persistent_ip(this->ptr_, TOF_ERROR_HANDLER{});
385 return new_persistent_ip;
386 }
387
388 /** Set the persistent ip settings. The persistent ip settings will be active
389 * on next reboot.
390 * @param persistent_ip The persistent ip
391 */
392 void set_persistent_ip(const PersistentIp &persistent_ip) {
393 return tof_gige_interface_set_persistent_ip(this->ptr_, *reinterpret_cast<const tof_persistent_ip_t*>(&persistent_ip), TOF_ERROR_HANDLER{});
394 }
395
396 /** Get the capacity for amount of user pointers that can be registered
397 * @return User pointer capacity
398 */
400 return tof_gige_interface_get_user_pointer_capacity(this->ptr_, TOF_ERROR_HANDLER{});
401 }
402
403 /** Set the capacity for amount of user pointers that can be registered
404 * @param capacity User pointer capacity
405 */
406 void set_user_pointer_capacity(size_t capacity) {
407 return tof_gige_interface_set_user_pointer_capacity(this->ptr_, capacity, TOF_ERROR_HANDLER{});
408 }
409
410 /** Add a pointer that will be filled with depth data. This method allows you
411 * to fill data straight into your own data structure without any additional
412 * copying.
413 * @param pointer The pointer to the data to write into
414 * @param capacity The amount of data the pointer can hold
415 * @param callback Callback that will be called when pointer is no longer in
416 * use
417 */
418 void add_depth_user_pointer(uint8_t* pointer, size_t capacity, user_pointer_destructed_fn &callback) {
419 return tof_gige_interface_add_depth_user_pointer(this->ptr_, pointer, capacity, user_pointer_destructed_cb_handler, &callback, TOF_ERROR_HANDLER{});
420 }
421
422 /** Add a pointer that will be filled with depth data. This method allows you
423 * to fill data straight into your own data structure without any additional
424 * copying.
425 * @param pointer The pointer to the data to write into
426 * @param capacity The amount of data the pointer can hold
427 * @param callback Callback that will be called when pointer is no longer in
428 * use
429 * @param callback_user_data User data that will be passed back when the function pointer is called
430 */
431 void add_depth_user_pointer(uint8_t* pointer, size_t capacity, tof_user_pointer_destructed_t callback, void* callback_user_data) {
432 return tof_gige_interface_add_depth_user_pointer(this->ptr_, pointer, capacity, callback, callback_user_data, TOF_ERROR_HANDLER{});
433 }
434
435 /** Get the tof library version running on the camera
436 * @return Version
437 */
438 const char* version() {
439 return tof_gige_interface_version(this->ptr_, TOF_ERROR_HANDLER{});
440 }
441
442 /** Check whether the camera is capable of software trigger
443 * @return Software trigger capable
444 */
446 return tof_gige_interface_software_trigger_capable(this->ptr_, TOF_ERROR_HANDLER{});
447 }
448
449 /** Software trigger the camera
450 */
452 return tof_gige_interface_software_trigger(this->ptr_, TOF_ERROR_HANDLER{});
453 }
454
455};
456
457} // tof
458} // chronoptics
459
460#endif
This class contains all the calibration information.
Definition: calibration.hpp:38
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.
DEPRECATED, use KeaCamera.
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.
CameraConfig download_configuration(uint16_t port=0)
Download camera configuration from the camera.
std::vector< DiscoveryMessage > discover()
Detect all the cameras on the network.
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.
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.
bool software_trigger_capable()
Check whether the camera is capable of software trigger.
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.
const char * version()
Get the tof library version running on the camera.
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 software_trigger()
Software trigger 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.
const char * get_ip() const
Get the IP address.
void set_netmask(StringView netmask)
Set the netmask.
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.