From 903404a2234197c556df89a82b33008cdf44f40e Mon Sep 17 00:00:00 2001 From: John Date: Thu, 23 May 2024 14:04:12 -0400 Subject: [PATCH] fix sensor validation --- cartofacade/capi_test.go | 2 +- viam-cartographer/src/carto_facade/carto_facade.cc | 12 +++++++++++- .../src/carto_facade/carto_facade_test.cc | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cartofacade/capi_test.go b/cartofacade/capi_test.go index 0faab712..d579cead 100644 --- a/cartofacade/capi_test.go +++ b/cartofacade/capi_test.go @@ -214,7 +214,7 @@ func TestCGoAPIWithoutMovementSensor(t *testing.T) { cfgBad := GetBadTestConfig() vc, err = NewCarto(cfgBad, algoCfg, &pvcl) // initialize viam_carto incorrectly - test.That(t, err, test.ShouldResemble, errors.New("VIAM_CARTO_COMPONENT_REFERENCE_INVALID")) + test.That(t, err, test.ShouldResemble, errors.New("VIAM_CARTO_LIDAR_CONFIG_INVALID")) test.That(t, vc, test.ShouldNotBeNil) algoCfg = GetTestAlgoConfig(false) diff --git a/viam-cartographer/src/carto_facade/carto_facade.cc b/viam-cartographer/src/carto_facade/carto_facade.cc index 58188598..8b463d63 100644 --- a/viam-cartographer/src/carto_facade/carto_facade.cc +++ b/viam-cartographer/src/carto_facade/carto_facade.cc @@ -117,7 +117,7 @@ config from_viam_carto_config(viam_carto_config vcc) { c.lidar_config = vcc.lidar_config; if (c.camera.empty()) { - throw VIAM_CARTO_COMPONENT_REFERENCE_INVALID; + throw VIAM_CARTO_LIDAR_CONFIG_INVALID; } validate_lidar_config(c.lidar_config); @@ -640,6 +640,16 @@ void CartoFacade::AddLidarReading(const viam_carto_lidar_reading *sr) { << CartoFacadeState::STARTED; throw VIAM_CARTO_NOT_IN_STARTED_STATE; } + + bstring camera_sensor = to_bstring(config.camera); + bool known_sensor = biseq(camera_sensor, sr->lidar); + bdestroy(camera_sensor); + if (!known_sensor) { + VLOG(1) << "expected sensor: " << to_std_string(sr->lidar) << " to be " + << config.camera; + throw VIAM_CARTO_UNKNOWN_SENSOR_NAME; + } + std::string lidar_reading = to_std_string(sr->lidar_reading); if (lidar_reading.length() == 0) { throw VIAM_CARTO_LIDAR_READING_EMPTY; diff --git a/viam-cartographer/src/carto_facade/carto_facade_test.cc b/viam-cartographer/src/carto_facade/carto_facade_test.cc index cc40cfcc..16ec7445 100644 --- a/viam-cartographer/src/carto_facade/carto_facade_test.cc +++ b/viam-cartographer/src/carto_facade/carto_facade_test.cc @@ -185,7 +185,7 @@ BOOST_AUTO_TEST_CASE(CartoFacade_init_validate) { VIAM_CARTO_THREE_D, no_camera, no_movement_sensor, true, ""); BOOST_TEST(viam_carto_init(&vc, lib, vcc_empty_component_ref, ac) == - VIAM_CARTO_COMPONENT_REFERENCE_INVALID); + VIAM_CARTO_LIDAR_CONFIG_INVALID); ac = viam_carto_algo_config_setup(true); // Test config validation with invalid lidar config