LibMultiSense
LibMultiSense Documentation
Loading...
Searching...
No Matches
info_test.cc
Go to the documentation of this file.
1
37#include <gtest/gtest.h>
38
39#include <details/legacy/info.hh>
40#include <details/legacy/utilities.hh>
41
42using namespace multisense::legacy;
43
44crl::multisense::details::wire::SysDeviceInfo create_wire_info(const std::string &name, const std::string &key)
45{
46 using namespace crl::multisense::details;
47
49 info.key = key;
50 info.name = name;
51 info.buildDate = "2024";
52 info.serialNumber = "4501";
53 info.hardwareRevision = wire::SysDeviceInfo::HARDWARE_REV_MULTISENSE_KS21;
54 info.numberOfPcbs = 1;
55
56 wire::PcbInfo pcb;
57 pcb.name = name;
58 pcb.revision = 12345;
59 info.pcbs[0] = pcb;
60
61 info.imagerName = name;
62 info.imagerType = wire::SysDeviceInfo::IMAGER_TYPE_AR0239_COLOR;
63 info.imagerWidth = 1000;
64 info.imagerHeight = 1001;
65 info.lensName = name;
66 info.nominalBaseline = 0.21;
67 info.nominalFocalLength = 0.024;
68 info.nominalRelativeAperture = 0.1;
69 info.lightingType = wire::SysDeviceInfo::LIGHTING_TYPE_EXTERNAL;
70 info.numberOfLights = 1;
71
72 return info;
73}
74
76{
77 using namespace crl::multisense::details;
78
80 version.firmwareBuildDate = "1234-01-23";
81 version.firmwareVersion = 0x0522;
82 version.hardwareVersion = 123;
83 version.hardwareMagic = 567;
84 version.fpgaDna = 8906;
85
86 return version;
87}
88
89crl::multisense::details::wire::SysDeviceModes create_device_modes(int64_t sources, int32_t imager_width, int32_t imager_height)
90{
91 using namespace crl::multisense::details;
92
94
95 wire::DeviceMode mode0;
96 mode0.width = imager_width;
97 mode0.height = imager_height;
98 mode0.height = imager_height;
99 mode0.supportedDataSources = sources;
100 mode0.disparities = 64;
101
102 wire::DeviceMode mode1;
103 mode1.width = imager_width / 2;
104 mode1.height = imager_height / 2;
105 mode1.supportedDataSources = sources;
106 mode1.disparities = 128;
107
108 wire::DeviceMode mode2;
109 mode2.width = 1234;
110 mode2.height = 456;
111 mode2.supportedDataSources = sources;
112 mode2.disparities = 128;
113
114 modes.modes.push_back(mode0);
115 modes.modes.push_back(mode1);
116 modes.modes.push_back(mode2);
117
118 return modes;
119}
120
122{
123 using namespace crl::multisense::details;
124
125 wire::ImuInfo output;
126
127 output.maxSamplesPerMessage = 100;
128
130 rate0.sampleRate = 101.0f;
131 rate0.bandwidthCutoff = 201.0f;
132
134 rate1.sampleRate = 101.1f;
135 rate1.bandwidthCutoff = 202.0f;
136
138 range0.range = 10.2f;
139 range0.resolution = 0.2f;
140
141 wire::imu::Details detail0;
142 detail0.name = "accelerometer";
143 detail0.device = "device0";
144 detail0.units = "units0";
145
146 detail0.rates.push_back(rate0);
147 detail0.rates.push_back(rate1);
148 detail0.ranges.push_back(range0);
149
150 wire::imu::Details detail1;
151 detail1.name = "gyroscope";
152 detail1.device = "device1";
153 detail1.units = "units1";
154
155 detail1.rates.push_back(rate0);
156 detail1.rates.push_back(rate1);
157 detail1.ranges.push_back(range0);
158
159 output.details.push_back(detail0);
160 output.details.push_back(detail1);
161
162 return output;
163}
164
166{
167 using namespace multisense;
169 info.camera_name = name;
170 info.build_date = "2024";
171 info.serial_number = "4501";
172 info.hardware_revision = MultiSenseInfo::DeviceInfo::HardwareRevision::KS21;
173 info.pcb_info = {MultiSenseInfo::DeviceInfo::PcbInfo{name, 12345}};
174 info.imager_name = name;
175 info.imager_type = MultiSenseInfo::DeviceInfo::ImagerType::AR0239_COLOR;
176 info.imager_width = 1920;
177 info.imager_height = 1200;
178 info.lens_name = name;
179 info.nominal_stereo_baseline = 0.21;
180 info.nominal_focal_length = 0.024;
181 info.nominal_relative_aperture = 0.1;
182 info.lighting_type = MultiSenseInfo::DeviceInfo::LightingType::EXTERNAL;
183 info.number_of_lights = 1;
184
185 return info;
186}
187
189{
190 return multisense::MultiSenseInfo::NetworkInfo{ip_address, "test", "bar"};
191}
192
195 const std::string &key)
196{
197 using namespace crl::multisense::details;
198 using namespace multisense;
199
200 ASSERT_EQ(wire.key, key);
201 ASSERT_EQ(wire.name, info.camera_name);
202 ASSERT_EQ(wire.buildDate, info.build_date);
203 ASSERT_EQ(wire.serialNumber, info.serial_number);
204
205 switch (wire.hardwareRevision)
206 {
207 case wire::SysDeviceInfo::HARDWARE_REV_MULTISENSE_S7:
208 ASSERT_EQ(info.hardware_revision, MultiSenseInfo::DeviceInfo::HardwareRevision::S7); break;
209 case wire::SysDeviceInfo::HARDWARE_REV_MULTISENSE_S21:
210 ASSERT_EQ(info.hardware_revision, MultiSenseInfo::DeviceInfo::HardwareRevision::S21); break;
211 case wire::SysDeviceInfo::HARDWARE_REV_MULTISENSE_ST21:
212 ASSERT_EQ(info.hardware_revision, MultiSenseInfo::DeviceInfo::HardwareRevision::ST21); break;
213 case wire::SysDeviceInfo::HARDWARE_REV_MULTISENSE_C6S2_S27:
214 ASSERT_EQ(info.hardware_revision, MultiSenseInfo::DeviceInfo::HardwareRevision::S27); break;
215 case wire::SysDeviceInfo::HARDWARE_REV_MULTISENSE_S30:
216 ASSERT_EQ(info.hardware_revision, MultiSenseInfo::DeviceInfo::HardwareRevision::S30); break;
217 case wire::SysDeviceInfo::HARDWARE_REV_MULTISENSE_KS21:
218 ASSERT_EQ(info.hardware_revision, MultiSenseInfo::DeviceInfo::HardwareRevision::KS21); break;
219 case wire::SysDeviceInfo::HARDWARE_REV_MULTISENSE_MONOCAM:
220 ASSERT_EQ(info.hardware_revision, MultiSenseInfo::DeviceInfo::HardwareRevision::MONOCAM); break;
221 case wire::SysDeviceInfo::HARDWARE_REV_MULTISENSE_KS21_SILVER:
222 ASSERT_EQ(info.hardware_revision, MultiSenseInfo::DeviceInfo::HardwareRevision::KS21_SILVER); break;
223 case wire::SysDeviceInfo::HARDWARE_REV_MULTISENSE_ST25:
224 ASSERT_EQ(info.hardware_revision, MultiSenseInfo::DeviceInfo::HardwareRevision::ST25); break;
225 case wire::SysDeviceInfo::HARDWARE_REV_MULTISENSE_KS21i:
226 ASSERT_EQ(info.hardware_revision, MultiSenseInfo::DeviceInfo::HardwareRevision::KS21i); break;
227 default: {CRL_EXCEPTION("Unsupported hardware revision");}
228 }
229
230 ASSERT_EQ(wire.numberOfPcbs, info.pcb_info.size());
231
232 for (uint32_t i = 0; i < wire.numberOfPcbs ; ++i)
233 {
234 ASSERT_EQ(wire.pcbs[i].name, info.pcb_info[i].name);
235 ASSERT_EQ(wire.pcbs[i].revision, info.pcb_info[i].revision);
236 }
237
238 ASSERT_EQ(wire.imagerName, info.imager_name);
239 switch (wire.imagerType)
240 {
241 case wire::SysDeviceInfo::IMAGER_TYPE_CMV2000_GREY:
242 ASSERT_EQ(info.imager_type, MultiSenseInfo::DeviceInfo::ImagerType::CMV2000_GREY); break;
243 case wire::SysDeviceInfo::IMAGER_TYPE_CMV2000_COLOR:
244 ASSERT_EQ(info.imager_type, MultiSenseInfo::DeviceInfo::ImagerType::CMV2000_COLOR); break;
245 case wire::SysDeviceInfo::IMAGER_TYPE_CMV4000_GREY:
246 ASSERT_EQ(info.imager_type, MultiSenseInfo::DeviceInfo::ImagerType::CMV4000_GREY); break;
247 case wire::SysDeviceInfo::IMAGER_TYPE_CMV4000_COLOR:
248 ASSERT_EQ(info.imager_type, MultiSenseInfo::DeviceInfo::ImagerType::CMV4000_COLOR); break;
249 case wire::SysDeviceInfo::IMAGER_TYPE_FLIR_TAU2:
250 ASSERT_EQ(info.imager_type, MultiSenseInfo::DeviceInfo::ImagerType::FLIR_TAU2); break;
251 case wire::SysDeviceInfo::IMAGER_TYPE_AR0234_GREY:
252 ASSERT_EQ(info.imager_type, MultiSenseInfo::DeviceInfo::ImagerType::AR0234_GREY); break;
253 case wire::SysDeviceInfo::IMAGER_TYPE_AR0239_COLOR:
254 ASSERT_EQ(info.imager_type, MultiSenseInfo::DeviceInfo::ImagerType::AR0239_COLOR); break;
255 case wire::SysDeviceInfo::IMAGER_TYPE_TENUM1280:
256 ASSERT_EQ(info.imager_type, MultiSenseInfo::DeviceInfo::ImagerType::TENUM1280); break;
257 default: {CRL_EXCEPTION("Unsupported imager type");}
258 }
259 ASSERT_EQ(wire.imagerWidth, info.imager_width);
260 ASSERT_EQ(wire.imagerHeight, info.imager_height);
261
262 ASSERT_EQ(wire.lensName, info.lens_name);
263 ASSERT_EQ(wire.nominalBaseline, info.nominal_stereo_baseline);
264 ASSERT_EQ(wire.nominalFocalLength, info.nominal_focal_length);
266
267 switch (wire.lightingType)
268 {
269 case wire::SysDeviceInfo::LIGHTING_TYPE_NONE:
270 ASSERT_EQ(info.lighting_type, MultiSenseInfo::DeviceInfo::LightingType::NONE); break;
271 case wire::SysDeviceInfo::LIGHTING_TYPE_INTERNAL:
272 ASSERT_EQ(info.lighting_type, MultiSenseInfo::DeviceInfo::LightingType::INTERNAL); break;
273 case wire::SysDeviceInfo::LIGHTING_TYPE_EXTERNAL:
274 ASSERT_EQ(info.lighting_type, MultiSenseInfo::DeviceInfo::LightingType::EXTERNAL); break;
275 case wire::SysDeviceInfo::LIGHTING_TYPE_PATTERN_PROJECTOR:
276 ASSERT_EQ(info.lighting_type, MultiSenseInfo::DeviceInfo::LightingType::PATTERN_PROJECTOR); break;
277 case wire::SysDeviceInfo::LIGHTING_TYPE_OUTPUT_TRIGGER:
278 ASSERT_EQ(info.lighting_type, MultiSenseInfo::DeviceInfo::LightingType::OUTPUT_TRIGGER); break;
279 case wire::SysDeviceInfo::LIGHTING_TYPE_PATTERN_PROJECTOR_AND_OUTPUT_TRIGGER:
280 ASSERT_EQ(info.lighting_type, MultiSenseInfo::DeviceInfo::LightingType::PATTERN_PROJECTOR_OUTPUT_TRIGGER); break;
281 default: {CRL_EXCEPTION("Unsupported lighting type");}
282 }
283 ASSERT_EQ(wire.numberOfLights, info.number_of_lights);
284}
285
288{
289 ASSERT_EQ(wire.name, info.name);
290 ASSERT_EQ(wire.device, info.device);
291
292 ASSERT_EQ(wire.rates.size(), info.rates.size());
293 for (size_t i = 0 ; i < info.rates.size() ; ++i)
294 {
295 ASSERT_FLOAT_EQ(wire.rates[i].sampleRate, info.rates[i].sample_rate);
296 ASSERT_FLOAT_EQ(wire.rates[i].bandwidthCutoff, info.rates[i].bandwith_cutoff);
297 }
298
299 ASSERT_EQ(wire.ranges.size(), info.ranges.size());
300 for (size_t i = 0 ; i < info.ranges.size() ; ++i)
301 {
302 ASSERT_FLOAT_EQ(wire.ranges[i].range, info.ranges[i].range);
303 ASSERT_FLOAT_EQ(wire.ranges[i].resolution, info.ranges[i].resolution);
304 }
305}
306
309{
310 ASSERT_EQ(info0.ip_address, info1.ip_address);
311 ASSERT_EQ(info0.gateway, info1.gateway);
312 ASSERT_EQ(info0.netmask, info1.netmask);
313}
314
315TEST(convert, wire_to_info)
316{
317 const auto info = create_wire_info("test", "key");
318 check_equal(info, convert(info), "key");
319}
320
321TEST(convert, info_to_wire)
322{
323 const auto info = create_info("test");
324 check_equal(convert(info, "key"), info, "key");
325}
326
327TEST(convert, version)
328{
329 const auto version_wire = create_version();
330 const auto version = convert(version_wire);
331
332 const auto converted_version = get_version(version_wire.firmwareVersion);
333
334 ASSERT_EQ(version.firmware_build_date, version_wire.firmwareBuildDate);
335
336 //
337 // This must be equal
338 //
339 ASSERT_FALSE(version.firmware_version < converted_version);
340 ASSERT_FALSE(converted_version < version.firmware_version);
341
342 ASSERT_EQ(version.hardware_version, version_wire.hardwareVersion);
343}
344
345TEST(convert, device_modes)
346{
347 using namespace crl::multisense::details;
348 using namespace multisense;
349
350 const wire::IdType sources = wire::SOURCE_LUMA_LEFT | wire::SOURCE_LUMA_RECT_RIGHT | wire::SOURCE_DISPARITY;
351
352 constexpr uint32_t imager_width = 1920;
353 constexpr uint32_t imager_height = 1200;
354
355 const auto wire_modes = create_device_modes(sources, imager_width, imager_height);
356 const auto modes = convert(wire_modes);
357
358 ASSERT_EQ(modes.size(), wire_modes.modes.size());
359
360 for(size_t i = 0 ; i < modes.size() ; ++i)
361 {
362 ASSERT_EQ(modes[i].width, wire_modes.modes[i].width);
363 ASSERT_EQ(modes[i].height, wire_modes.modes[i].height);
364
365 ASSERT_EQ(modes[i].disparities, get_disparities(wire_modes.modes[i].disparities));
366
367 const auto full_sources = convert_sources(modes[i].supported_sources);
368 ASSERT_EQ(full_sources & 0x00000000FFFFFFFF, wire_modes.modes[i].supportedDataSources);
369 ASSERT_EQ(full_sources >> 32, wire_modes.modes[i].extendedDataSources);
370 }
371}
372
373TEST(convert, imu_source)
374{
375 using namespace crl::multisense::details;
376
377 const auto wire_info = create_imu_info();
378 const auto info = convert(wire_info);
379
380 for (size_t i = 0 ; i < wire_info.details.size() ; ++i)
381 {
382 const auto &detail = wire_info.details[i];
383
384 if (info.accelerometer && info.accelerometer->name == detail.name)
385 {
386 check_equal(detail, info.accelerometer.value());
387 }
388 else if (info.gyroscope && info.gyroscope->name == detail.name)
389 {
390 check_equal(detail, info.gyroscope.value());
391 }
392 else if (info.magnetometer && info.magnetometer->name == detail.name)
393 {
394 check_equal(detail, info.magnetometer.value());
395 }
396 else
397 {
398 ASSERT_TRUE(false);
399 }
400 }
401}
402
403TEST(convert, network_info_round_trip)
404{
405 const auto network_info = create_network_info("1.2.3.4");
406
407 const auto round_trip = convert(convert(network_info));
408
409 check_equal(network_info, round_trip);
410}
#define CRL_EXCEPTION(fmt,...)
Definition Exception.hh:85
std::vector< imu::Details > details
multisense::MultiSenseInfo::NetworkInfo create_network_info(const std::string &ip_address)
Definition info_test.cc:188
void check_equal(const crl::multisense::details::wire::SysDeviceInfo &wire, const multisense::MultiSenseInfo::DeviceInfo &info, const std::string &key)
Definition info_test.cc:193
crl::multisense::details::wire::SysDeviceInfo create_wire_info(const std::string &name, const std::string &key)
Definition info_test.cc:44
multisense::MultiSenseInfo::DeviceInfo create_info(const std::string &name)
Definition info_test.cc:165
crl::multisense::details::wire::ImuInfo create_imu_info()
Definition info_test.cc:121
crl::multisense::details::wire::VersionResponse create_version()
Definition info_test.cc:75
crl::multisense::details::wire::SysDeviceModes create_device_modes(int64_t sources, int32_t imager_width, int32_t imager_height)
Definition info_test.cc:89
TEST(convert, wire_to_info)
Definition info_test.cc:315
Info for the PCBs contained in the unit.
The Device information associated with the MultiSense.
LightingType lighting_type
The type of lighting used in the MultiSense.
float nominal_relative_aperture
The nominal relative aperture for the primary camera modules in f-stop.
std::vector< PcbInfo > pcb_info
Information about each PCB.
std::string serial_number
The unique serial number of the MultiSense This value can store at most 32 characters.
float nominal_stereo_baseline
The nominal stereo baseline in meters.
uint32_t number_of_lights
The number of lights the MultiSense controls.
uint32_t imager_width
The native width of the primary imager.
std::string imager_name
The name of the imager used by the primary camera.
HardwareRevision hardware_revision
The hardware revision of the MultiSense.
std::string lens_name
The name of the lens used for the primary camera For stereo cameras this is the Left/Right stereo pai...
std::string camera_name
The name of the MultiSense variant.
float nominal_focal_length
The nominal focal length for the primary lens in meters.
uint32_t imager_height
The native height of the primary imager.
ImagerType imager_type
The type of the imager.
std::string build_date
The date the MultiSense was manufactured This value can store at most 32 characters.
Info about the available IMU configurations.
std::vector< ImuRate > rates
The available rates supported by this operating mode.
std::vector< ImuRange > ranges
The available ranges supported by this operating mode.
std::string name
The name of the IMU sensor.
std::string device
The name of the IMU chip.
The network configuration for the MultiSense.
std::string gateway
The gateway of the camera (i.e.
std::string netmask
The netmask of the camera (i.e.
std::string ip_address
The ip address of the camera (i.e.