-
Notifications
You must be signed in to change notification settings - Fork 0
/
ouster_clib.h
1097 lines (852 loc) · 24.9 KB
/
ouster_clib.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Comment out this line when using as DLL
#define ouster_clib_STATIC
/**
* @file ouster_clib.h
* @brief Ouster public API.
*
* This file contains the public API for ouster_clib.
*/
#ifndef OUSTER_CLIB_H
#define OUSTER_CLIB_H
/**
* @defgroup c C API
*
* @{
* @}
*/
/**
* @defgroup core Core
* @brief Core Ouster API functionality
*
* \ingroup c
* @{
*/
/**
* @defgroup options API defines
* @brief Defines for customizing compile time features.
* @{
*/
/** @def OUSTER_DEBUG
* Used for input parameter checking and cheap sanity checks. There are lots of
* asserts in every part of the code, so this will slow down applications.
*/
#if !defined(OUSTER_DEBUG) && !defined(OUSTER_NDEBUG)
#if defined(NDEBUG)
#define OUSTER_NDEBUG
#else
#define OUSTER_DEBUG
#endif
#endif
/** \def OUSTER_USE_DUMP
* Include dump or print struct functionality
*/
#ifndef OUSTER_USE_DUMP
#define OUSTER_USE_DUMP
#endif
/** \def OUSTER_USE_UDPCAP
* Include UDP capture and replay functionality
*/
#ifndef OUSTER_USE_UDPCAP
#define OUSTER_USE_UDPCAP
#endif
/** \def OUSTER_ENABLE_LOG
* Enable logging
*/
#if defined(OUSTER_ENABLE_LOG) && defined(OUSTER_DISABLE_LOG)
#error "invalid configuration: cannot both define OUSTER_ENABLE_LOG and OUSTER_DISABLE_LOG"
#endif
#ifndef OUSTER_ENABLE_LOG
#define OUSTER_ENABLE_LOG
#endif
#ifdef OUSTER_DISABLE_LOG
#undef OUSTER_ENABLE_LOG
#endif
/** @} */ // end of options
/** @} */ // end of core
/**
* @defgroup log Logging
* @brief Functionality logging
*
* \ingroup c
* @{
*/
#ifndef OUSTER_LOG_H
#define OUSTER_LOG_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
int32_t ouster_log_set_level(int32_t level);
/** Logging */
#ifdef OUSTER_ENABLE_LOG
void ouster_log_(int32_t level, char const * file, int32_t line, char const *fmt, ...);
void ouster_log_m4_(double const a[16]);
void ouster_log_m3_(double const a[9]);
void ouster_log_v3_(double const a[3]);
#define ouster_log(...) ouster_log_(0, __FILE__, __LINE__, __VA_ARGS__)
#define ouster_log_m4(...) ouster_log_m4_(__VA_ARGS__)
#define ouster_log_m3(...) ouster_log_m3_(__VA_ARGS__)
#define ouster_log_v3(...) ouster_log_v3_(__VA_ARGS__)
#else
#define ouster_log(...)
#define ouster_log_m4(...)
#define ouster_log_m3(...)
#define ouster_log_v3(...)
#endif
#ifdef __cplusplus
}
#endif
#endif // OUSTER_LOG_H
/** @} */
/**
* @defgroup types Types
* @brief Types
*
* \ingroup c
* @{
*/
#ifndef OUSTER_TYPES_H
#define OUSTER_TYPES_H
#include <stdint.h>
/*
Packet Header [256 bits]
https://github.com/ouster-lidar/ouster_example/blob/9d0971107f6f9c95e16afd727fa2534d01a0fe4e/ouster_client/src/parsing.cpp#L155
packet_header_size = legacy ? 0 : 32;
col_header_size = legacy ? 16 : 12;
channel_data_size = entry.chan_data_size;
col_footer_size = legacy ? 4 : 0;
packet_footer_size = legacy ? 0 : 32;
col_size = col_header_size + pixels_per_column * channel_data_size +
col_footer_size;
lidar_packet_size = packet_header_size + columns_per_packet * col_size +
packet_footer_size;
*/
/** The first bytes of the UDP LIDAR packet */
#define OUSTER_PACKET_HEADER_SIZE 32
/** The last bytes of the UDP LIDAR packet */
#define OUSTER_PACKET_FOOTER_SIZE 32
/** Bytes of a column header. Multiple of this column can appear in a packet */
#define OUSTER_COLUMN_HEADER_SIZE 12
/** Column does not have any footer */
#define OUSTER_COLUMN_FOOTER_SIZE 0
/** The max number of LIDAR rows of Ouster Sensors */
#define OUSTER_MAX_ROWS 128
/** Size for SOL_SOCKET, SO_RCVBUF */
#define OUSTER_DEFAULT_RCVBUF_SIZE (1024 * 1024)
/** Number of bytes in a IMU packet */
#define OUSTER_PACKET_IMU_SIZE 48
#define OUSTER_M_PI 3.14159265358979323846
#define ouster_unused(x) ((void)(x))
/** Translate C type to id. */
#define ouster_id(T) OUSTER_ID##T##ID_
#ifdef __cplusplus
extern "C"
{
#endif
typedef float ouster_f32_t;
typedef double ouster_f64_t;
/** Packet header.
* Identifies lidar data vs. other packets in stream.
* Packet Type is 0x1 for Lidar packets. */
typedef uint16_t ouster_packet_type_t;
/** Index of the lidar scan, increments every time the sensor completes a rotation, crossing the zero azimuth angle. */
typedef uint16_t ouster_frame_id_t;
/** Packet header Initialization ID.
* Updates on every reinit, which may be triggered by the user or an error, and every reboot.
* This value may also be obtained by running the HTTP command GET /api/v1 */
typedef uint32_t ouster_init_id_t;
/** Packet header. Serial number of the sensor.
* This value is unique to each sensor and can be found on a sticker affixed to the top of the sensor.
* In addition, this information is also available on the Sensor Web UI and by reading the field prod_sn from get_sensor_info.
*/
typedef uint64_t ouster_prod_sn_t;
/** Packet header.
* Indicates the shot limiting status of the sensor.
* Different codes indicates whether the sensor is in Normal Operation or in Shot Limiting.
* Please refer to Shot Limiting section for more details.
*/
typedef uint8_t ouster_shot_limiting_t;
/** Packet header.
* Indicates whether thermal shutdown is imminent.
* Please refer to Shot Limiting section for more details.
*/
typedef uint8_t ouster_thermal_shutdown_t;
/** Packet header.
* Countdown from 30s to indicate when shot limiting is imminent.
* Please refer to Shot Limiting section for more details.
*/
typedef uint8_t ouster_countdown_shot_limiting_t;
/** Packet header.
* Countdown from 30s to indicate that thermal shutdown is imminent.
* Please refer to Shot Limiting section for more details.
*/
typedef uint8_t ouster_countdown_thermal_shutdown_t;
/** Column header
* Timestamp of the measurement in nanoseconds. */
typedef uint64_t ouster_timestamp_t;
/** Column header
* Sequentially incrementing measurement counting up from 0 to 511, or 0 to 1023, or 0 to 2047 depending on lidar_mode. */
typedef uint16_t ouster_measurment_id_t;
/** Column header
* Indicates validity of the measurements.
* Status is 0x01 for valid measurements.
* Status is 0x00 for dropped or disabled columns. */
typedef uint32_t ouster_status_t;
/** Range */
typedef uint32_t ouster_field_range_t;
/** Intensity */
typedef uint16_t ouster_field_intensity_t;
/** Reflectivity */
typedef uint8_t ouster_field_reflectivity_t;
/** Ambient */
typedef uint16_t ouster_field_nearir_t;
typedef enum
{
ouster_id(ouster_f32_t),
ouster_id(ouster_f64_t),
ouster_id(ouster_measurment_id_t),
ouster_id(ouster_timestamp_t),
ouster_id(ouster_status_t),
ouster_id(ouster_frame_id_t),
ouster_id(ouster_packet_type_t),
ouster_id(ouster_init_id_t),
ouster_id(ouster_prod_sn_t),
ouster_id(ouster_countdown_thermal_shutdown_t),
ouster_id(ouster_countdown_shot_limiting_t),
ouster_id(ouster_thermal_shutdown_t),
ouster_id(ouster_shot_limiting_t),
ouster_id(ouster_field_range_t),
ouster_id(ouster_field_intensity_t),
ouster_id(ouster_field_reflectivity_t),
ouster_id(ouster_field_nearir_t),
OUSTER_TYPE_LAST
} ouster_type_t;
typedef enum
{
OUSTER_QUANTITY_RANGE = 1, // 1st return range in mm
OUSTER_QUANTITY_RANGE2 = 2, // 2nd return range in mm
OUSTER_QUANTITY_SIGNAL = 3, // 1st return signal in photons
OUSTER_QUANTITY_SIGNAL2 = 4, // 2nd return signal in photons
OUSTER_QUANTITY_REFLECTIVITY = 5, // 1st return reflectivity, calibrated by range and sensor///< sensitivity in FW 2.1+. See sensor docs for more details
OUSTER_QUANTITY_REFLECTIVITY2 = 6, // 2nd return reflectivity, calibrated by range and sensor///< sensitivity in FW 2.1+. See sensor docs for more details
OUSTER_QUANTITY_NEAR_IR = 7, // near_ir in photons
OUSTER_QUANTITY_FLAGS = 8, // 1st return flags
OUSTER_QUANTITY_FLAGS2 = 9, // 2nd return flags
OUSTER_QUANTITY_RAW_HEADERS = 40, // raw headers for packet/footer/column for dev use
OUSTER_QUANTITY_RAW32_WORD5 = 45, // raw word access to packet for dev use
OUSTER_QUANTITY_RAW32_WORD6 = 46, // raw word access to packet for dev use
OUSTER_QUANTITY_RAW32_WORD7 = 47, // raw word access to packet for dev use
OUSTER_QUANTITY_RAW32_WORD8 = 48, // raw word access to packet for dev use
OUSTER_QUANTITY_RAW32_WORD9 = 49, // raw word access to packet for dev use
OUSTER_QUANTITY_CUSTOM0 = 50, // custom user field
OUSTER_QUANTITY_CUSTOM1 = 51, // custom user field
OUSTER_QUANTITY_CUSTOM2 = 52, // custom user field
OUSTER_QUANTITY_CUSTOM3 = 53, // custom user field
OUSTER_QUANTITY_CUSTOM4 = 54, // custom user field
OUSTER_QUANTITY_CUSTOM5 = 55, // custom user field
OUSTER_QUANTITY_CUSTOM6 = 56, // custom user field
OUSTER_QUANTITY_CUSTOM7 = 57, // custom user field
OUSTER_QUANTITY_CUSTOM8 = 58, // custom user field
OUSTER_QUANTITY_CUSTOM9 = 59, // custom user field
OUSTER_QUANTITY_RAW32_WORD1 = 60, // raw word access to packet for dev use
OUSTER_QUANTITY_RAW32_WORD2 = 61, // raw word access to packet for dev use
OUSTER_QUANTITY_RAW32_WORD3 = 62, // raw word access to packet for dev use
OUSTER_QUANTITY_RAW32_WORD4 = 63, // raw word access to packet for dev use
OUSTER_QUANTITY_CHAN_FIELD_MAX = 64, // max which allows us to introduce future fields
} ouster_quantity_t;
typedef struct
{
uint32_t mask;
int offset;
int depth;
} ouster_extract_t;
typedef struct
{
int frame_id;
int last_mid;
int mid_loss;
int num_valid_pixels;
} ouster_lidar_t;
typedef struct
{
ouster_quantity_t q[OUSTER_QUANTITY_CHAN_FIELD_MAX];
} ouster_field_desc_t;
/*
IMU UDP Packets are 48 Bytes long and by default are sent to Port 7503 at 100 Hz. Data is organized in little endian format.
IMU Diagnostic Time [64 bit unsigned int] - timestamp of monotonic system time since boot in nanoseconds.
Accelerometer Read Time [64 bit unsigned int] - timestamp for accelerometer time relative to timestamp_mode in nanoseconds.
Gyroscope Read Time [64 bit unsigned int] - timestamp for gyroscope time relative to timestamp_mode in nanoseconds.
Acceleration in X-axis [32 bit float] - acceleration in g.
Acceleration in Y-axis [32 bit float] - acceleration in g.
Acceleration in Z-axis [32 bit float] - acceleration in g.
Angular Velocity about X-axis [32 bit float] - Angular velocity in deg per sec.
Angular Velocity about Y-axis [32 bit float] - Angular velocity in deg per sec.
Angular Velocity about Z-axis [32 bit float] - Angular velocity in deg per sec.
*/
typedef struct
{
/** timestamp of monotonic system time since boot in nanoseconds */
uint64_t sys_ts;
/** timestamp for accelerometer time relative to timestamp_mode in nanoseconds */
uint64_t acc_ts;
/** timestamp for gyroscope time relative to timestamp_mode in nanoseconds */
uint64_t gyro_ts;
/** acceleration in g */
float acc[3];
/** Angular velocity in deg per sec */
float angvel[3];
} ouster_imu_packet_t;
typedef struct
{
ouster_quantity_t quantity;
int rows;
int cols;
int depth;
int rowsize;
int size;
void *data;
} ouster_field_t;
typedef struct
{
int w;
int h;
double *direction;
double *offset;
} ouster_lut_t;
/*
https://static.ouster.dev/sensor-docs/image_route1/image_route2/sensor_data/sensor-data.html#single-return-profile
RRRR Y0SS NN00
|--- | |- |-
4 1 2 2
0 4 6 8
*/
typedef enum
{
OUSTER_PROFILE_LIDAR_LEGACY = 1,
/** Dual Return Profile */
OUSTER_PROFILE_RNG19_RFL8_SIG16_NIR16_DUAL = 2,
/** Single Return Profile */
OUSTER_PROFILE_RNG19_RFL8_SIG16_NIR16 = 3,
/** Low Data Rate Profile */
OUSTER_PROFILE_RNG15_RFL8_NIR8 = 4,
OUSTER_PROFILE_FIVE_WORDS_PER_PIXEL = 5,
OUSTER_PROFILE_COUNT
} ouster_profile_t;
typedef struct
{
/** The configured port where Ouster Sensor will send LIDAR UDP packets */
int udp_port_lidar;
/** The configured port where Ouster Sensor will send IMU UDP packets */
int udp_port_imu;
/** This will not change when configuring azimuth window */
int columns_per_frame;
/** This will not change when configuring azimuth window */
int columns_per_packet;
/** This is number of rows */
int pixels_per_column;
/** This is the pixel format */
ouster_profile_t profile;
int channel_data_size;
int col_size;
/** UDP packet size for LIDAR packets */
int lidar_packet_size;
/** This is used to destagg hightmap range image from LiDAR */
int pixel_shift_by_row[OUSTER_MAX_ROWS];
/** These are parameters to convert a hightmap range image from LiDAR to 3D points */
double beam_altitude_angles[OUSTER_MAX_ROWS];
double beam_azimuth_angles[OUSTER_MAX_ROWS];
double beam_to_lidar_transform[16];
double lidar_origin_to_beam_origin_mm;
double lidar_to_sensor_transform[16];
/** Start of azimuth window.
* This will change when configuring azimuth window. */
int mid0;
/** End of azimuth window.
* This will change when configuring azimuth window. */
int mid1;
/** Width of azimuth window.
* This will change when configuring azimuth window. */
int midw;
ouster_extract_t extract[OUSTER_QUANTITY_CHAN_FIELD_MAX];
} ouster_meta_t;
typedef struct
{
ouster_timestamp_t ts;
ouster_status_t status;
ouster_measurment_id_t mid;
} ouster_column_t;
typedef struct
{
ouster_frame_id_t frame_id;
ouster_packet_type_t packet_type;
ouster_init_id_t init_id;
ouster_prod_sn_t prod_sn;
ouster_countdown_thermal_shutdown_t countdown_thermal_shutdown;
ouster_countdown_shot_limiting_t countdown_shot_limiting;
ouster_thermal_shutdown_t thermal_shutdown;
ouster_shot_limiting_t shot_limiting;
} ouster_lidar_header_t;
#ifdef __cplusplus
}
#endif
#endif // OUSTER_TYPES_H
/** @} */
/**
* @defgroup os_api OS API
* @brief API of OS
*
* \ingroup c
* @{
*/
#ifndef OUSTER_OUSTER_OS_API_H
#define OUSTER_OUSTER_OS_API_H
#include <stdint.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef void *(*ouster_os_api_malloc_t)(size_t size);
typedef void *(*ouster_os_api_realloc_t)(void *ptr, size_t size);
typedef void *(*ouster_os_api_calloc_t)(size_t size);
typedef void (*ouster_os_api_free_t)(void *ptr);
typedef void (*ouster_os_api_log_t)(int32_t level, const char *file, int32_t line, const char *msg);
typedef void (*ouster_os_api_abort_t)(void);
typedef struct ouster_os_api_t {
/* Memory management */
ouster_os_api_malloc_t malloc_;
ouster_os_api_realloc_t realloc_;
ouster_os_api_calloc_t calloc_;
ouster_os_api_free_t free_;
/* Trace level */
int32_t log_level_;
/* Logging */
ouster_os_api_log_t log_;
/* Application termination */
ouster_os_api_abort_t abort_;
} ouster_os_api_t;
extern ouster_os_api_t ouster_os_api;
extern int64_t ouster_os_api_malloc_count;
extern int64_t ouster_os_api_realloc_count;
extern int64_t ouster_os_api_calloc_count;
extern int64_t ouster_os_api_free_count;
#ifndef ouster_os_malloc
#define ouster_os_malloc(size) ouster_os_api.malloc_(size)
#endif
#ifndef ouster_os_free
#define ouster_os_free(ptr) ouster_os_api.free_(ptr)
#endif
#ifndef ouster_os_realloc
#define ouster_os_realloc(ptr, size) ouster_os_api.realloc_(ptr, size)
#endif
#ifndef ouster_os_calloc
#define ouster_os_calloc(size) ouster_os_api.calloc_(size)
#endif
#ifndef ouster_os_abort
#define ouster_os_abort(size) ouster_os_api.abort_()
#endif
void ouster_os_set_api_defaults(void);
#ifdef __cplusplus
}
#endif
#endif // OUSTER_OUSTER_OS_API_H
/** @} */
/**
* @defgroup assert Assertion
* @brief Functionality for sanity checks
*
* \ingroup c
* @{
*/
#ifndef OUSTER_ASSERT_H
#define OUSTER_ASSERT_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef OUSTER_DEBUG
#include <stdint.h>
#include <stdlib.h>
int ouster_assert_(
const char *expr,
const char *file,
int32_t line,
const char *fn,
const char *fmt,
...
);
/** Assert.
* Aborts if condition is false, disabled in debug mode. */
#define ouster_assert(expr, ...) ((expr) ? (void)0: (void)(ouster_assert_(#expr, __FILE__, __LINE__, __func__, __VA_ARGS__), abort()))
/** Assert.
* Aborts if condition is false, disabled in debug mode. */
#define ouster_assert_notnull(expr) ouster_assert(expr, "%s", "Should not be NULL")
#else
#define ouster_assert(expr, ...) ouster_unused(expr)
#define ouster_assert_notnull(expr) ouster_unused(expr)
#endif // OUSTER_DEBUG
#ifdef __cplusplus
}
#endif
#endif // OUSTER_ASSERT_H
/** @} */
/**
* @defgroup field Fields and destagger
* @brief Provides network functionality
*
* \ingroup c
* @{
*/
#ifndef OUSTER_FIELD_H
#define OUSTER_FIELD_H
#ifndef OUSTER_META_H
#define OUSTER_META_H
#ifdef __cplusplus
extern "C" {
#endif
void ouster_meta_parse(char const *jsonstr, ouster_meta_t *out_meta);
#ifdef __cplusplus
}
#endif
#endif // OUSTER_META_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
void ouster_field_init(ouster_field_t fields[], int count, ouster_meta_t *meta);
void ouster_field_fini(ouster_field_t fields[], int count);
void ouster_destagger(void *data, int cols, int rows, int depth, int rowsize, int pixel_shift_by_row[]);
void ouster_field_destagger(ouster_field_t fields[], int count, ouster_meta_t *meta);
void ouster_field_apply_mask_u32(ouster_field_t *field, ouster_meta_t *meta);
void ouster_field_zero(ouster_field_t fields[], int count);
void ouster_field_cpy(ouster_field_t dst[], ouster_field_t src[], int count);
#ifdef __cplusplus
}
#endif
#endif // OUSTER_FIELD_H
/** @} */
/**
* @defgroup fs Files
* @brief Read files
*
* \ingroup c
* @{
*/
#ifndef OUSTER_FS_H
#define OUSTER_FS_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Convert fs_readfile error to string
*
* @param filename filename
* @param buf out error buffer string
* @param len error buffer string length
* @return int the length that got written to buffer string
*/
int ouster_fs_readfile_failed_reason(char const *filename, char *buf, int len);
/** Prints current working directory */
void ouster_fs_pwd();
/** Read whole file and allocates memory
*
* @param path filename to read
*/
char *ouster_fs_readfile(char const *path);
#ifdef __cplusplus
}
#endif
#endif // OUSTER_FS_H
/** @} */
#ifndef OUSTER_LIDAR_H
#define OUSTER_LIDAR_H
#ifdef __cplusplus
extern "C" {
#endif
void ouster_lidar_header_get(char const *buf, ouster_lidar_header_t *dst);
void ouster_column_get1(char const *colbuf, void *dst, int type);
void ouster_column_get(char const *colbuf, ouster_column_t *dst);
void ouster_lidar_get_fields(ouster_lidar_t *lidar, ouster_meta_t *meta, char const *buf, ouster_field_t *fields, int fcount);
#ifdef __cplusplus
}
#endif
#endif // OUSTER_LIDAR_H
/**
* @defgroup lut XYZ vector field lookup table
* @brief Provides a vector field that converts image to pointcloud
*
* \ingroup c
* @{
*/
#ifndef OUSTER_LUT_H
#define OUSTER_LUT_H
#ifdef __cplusplus
extern "C" {
#endif
/** Inits a xyz lut table from meta configuration
*
* @param lut The xyz lut table
* @param meta meta configuration
*/
void ouster_lut_init(ouster_lut_t *lut, ouster_meta_t const *meta);
/** Frees memory of xyz lut table
*
* @param lut The xyz lut table
*/
void ouster_lut_fini(ouster_lut_t *lut);
/** Converts 2D hightmap to pointcloud
*
* @param lut Input LUT unit vector direction field
* @param range Input Raw LiDAR Sensor RANGE field 2D hightmap
* @param xyz Output Image pointcloud
*/
void ouster_lut_cartesian_f64(ouster_lut_t const *lut, uint32_t const *range, void *out, int out_stride);
/** Converts 2D hightmap to pointcloud
*
* @param lut Input LUT unit vector direction field
* @param range Input Raw LiDAR Sensor RANGE field 2D hightmap
* @param xyz Output Image pointcloud
*/
void ouster_lut_cartesian_f32(ouster_lut_t const *lut, uint32_t const *range, void *out, int out_stride);
void ouster_lut_cartesian_f32_single(ouster_lut_t const *lut, float x, float y, float mag, float *out);
/** Allocates size for xyz pointcloud
*
* @param lut Input LUT unit vector direction field
*/
double *ouster_lut_alloc(ouster_lut_t const *lut);
#ifdef __cplusplus
}
#endif
#endif // OUSTER_LUT_H
/** @} */
/**
* @defgroup net Network and sockets
* @brief Provides network functionality
*
* \ingroup c
* @{
*/
#ifndef OUSTER_NET_H
#define OUSTER_NET_H
#include <stdint.h>
// #define INET6_ADDRSTRLEN 46
#define OUSTER_NET_ADDRSTRLEN 46
#define OUSTER_NET_UDP_MAX_SIZE 65535
#define OUSTER_NET_FLAGS_NONBLOCK 0x0001
#define OUSTER_NET_FLAGS_REUSE 0x0002
#define OUSTER_NET_FLAGS_IPV6ONLY 0x0004
#define OUSTER_NET_FLAGS_IPV4 0x0008
#define OUSTER_NET_FLAGS_IPV6 0x0010
#define OUSTER_NET_FLAGS_UDP 0x0020
#define OUSTER_NET_FLAGS_TCP 0x0040
#define OUSTER_NET_FLAGS_BIND 0x0100
#define OUSTER_NET_FLAGS_CONNECT 0x0200
#ifdef __cplusplus
extern "C" {
#endif
typedef struct
{
int flags;
int rcvbuf_size;
int port;
char const *hint_service;
char const *hint_name;
int rcvtimeout_sec;
char const *group;
} ouster_net_sock_desc_t;
typedef struct
{
char data[OUSTER_NET_ADDRSTRLEN];
} ouster_net_addr_t;
/** Set a IPv4 address
*
* @param addr The address
* @param ip The IPv4 address
*/
void ouster_net_addr_set_ip4(ouster_net_addr_t *addr, char const *ip);
/** Set a port
*
* @param addr The address
* @param ip The port
*/
void ouster_net_addr_set_port(ouster_net_addr_t *addr, int port);
/**
* @brief Send data from a socket to a network address
*
* @param sock The source socket filedescriptor
* @param buf Data to send
* @param size Data size to send
* @param flags
* @param addr Destinationnetwork address
* @return Returns the number sent, or -1 for errors.
*/
int ouster_net_sendto(int sock, char *buf, int size, int flags, ouster_net_addr_t *addr);
int ouster_net_create(ouster_net_sock_desc_t *desc);
int64_t ouster_net_read(int sock, char *buf, int len);
uint64_t ouster_net_select(int socks[], int n, const int timeout_sec, const int timeout_usec);
int32_t ouster_net_get_port(int sock);
#ifdef __cplusplus
}
#endif
#endif // OUSTER_NET_H
/** @} */
/**
* @defgroup sock UDP Capture
* @brief This creates sockets
*
* \ingroup ouster_sock
* @{
*/
#ifndef OUSTER_SOCK_H
#define OUSTER_SOCK_H
#ifdef __cplusplus
extern "C"
{
#endif
int ouster_sock_create_udp_lidar(int port, int rcvbuf_size);
int ouster_sock_create_udp_imu(int port, int rcvbuf_size);
int ouster_sock_create_tcp(char const *hint_name, int port);
#ifdef __cplusplus
}
#endif
#endif // OUSTER_SOCK_H
/** @} */
/**
* @defgroup vec Growable vector
* @brief Functionality for appending data to vector
*
* \ingroup c
* @{
*/
#ifndef OUSTER_VEC_H
#define OUSTER_VEC_H
#ifdef __cplusplus
extern "C" {
#endif
#define OUSTER_OFFSET(o, offset) (void *)(((uintptr_t)(o)) + ((uintptr_t)(offset)))
typedef struct
{
int cap;
int count;
int esize;
void *data;
} ouster_vec_t;
void ouster_vec_init(ouster_vec_t *v, int esize, int cap);
void ouster_vec_append(ouster_vec_t *v, void const *data, int n, float factor);
int test_ouster_vec();
#ifdef __cplusplus
}
#endif
#endif // OUSTER_VEC_H
/** @} */
/**
* @defgroup http HTTP request
* @brief Functionality for getting HTTP response from HTTP request
*
* \ingroup c
* @{
*/
#ifndef OUSTER_HTTP_H
#define OUSTER_HTTP_H
#ifdef __cplusplus
extern "C" {
#endif
#define OUSTER_HTTP_GET_METADATA "/api/v1/sensor/metadata"
#define OUSTER_HTTP_GET_FIRMWARE "/api/v1/system/firmware"
void ouster_http_request(int sock, char const *host, char const *path, ouster_vec_t *v);
#ifdef __cplusplus
}
#endif
#endif // OUSTER_HTTP_H
/** @} */
#ifdef OUSTER_NO_UDPCAP
#undef OUSTER_USE_UDPCAP
#endif
#ifdef OUSTER_NO_DUMP
#undef OUSTER_USE_DUMP
#endif
#ifdef OUSTER_USE_UDPCAP
/**
* @defgroup udpcap UDP Capture/Replay
* @brief Functionality for capturing and replaying UDP packets
*
* \ingroup c
* @{
*/
#ifndef OUSTER_UDPCAP_H
#define OUSTER_UDPCAP_H
#ifdef __cplusplus
extern "C" {
#endif