diff --git a/osi/CMakeLists.txt b/osi/CMakeLists.txt index b103390de..e5a2f5e96 100644 --- a/osi/CMakeLists.txt +++ b/osi/CMakeLists.txt @@ -16,6 +16,7 @@ message(STATUS "-> Building cloe-osi library.") file(GLOB cloe-osi_PUBLIC_HEADERS "include/**/*.hpp") add_library(cloe-osi # find src -type f -name "*.cpp" \! -name "*_test.cpp" + src/cloe/component/osi_sensor.cpp src/cloe/utility/osi_ground_truth.cpp src/cloe/utility/osi_message_handler.cpp src/cloe/utility/osi_transceiver_tcp.cpp diff --git a/osi/include/cloe/component/osi_sensor.hpp b/osi/include/cloe/component/osi_sensor.hpp index 640c6f390..cdd048ed5 100644 --- a/osi/include/cloe/component/osi_sensor.hpp +++ b/osi/include/cloe/component/osi_sensor.hpp @@ -23,7 +23,7 @@ #include // for SensorData -#include // for Component +#include // for Component, Json #include // for osi_to_json namespace cloe { @@ -46,18 +46,7 @@ class OsiSensor : public Component { /** * Writes JSON representation into j. */ - Json active_state() const override { - return Json{ - {"sensor_data", this->get_json_str()}, - }; - } - - private: - std::string get_json_str() const { - std::string json_str; - cloe::utility::osi_to_json(this->get(), &json_str); - return json_str; - } + fable::Json active_state() const override; }; } // namespace cloe diff --git a/osi/src/cloe/component/osi_sensor.cpp b/osi/src/cloe/component/osi_sensor.cpp new file mode 100644 index 000000000..c16f2abb3 --- /dev/null +++ b/osi/src/cloe/component/osi_sensor.cpp @@ -0,0 +1,33 @@ +/* + * Copyright 2024 Robert Bosch GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include // for Json, parse_json + +namespace cloe { + +fable::Json OsiSensor::active_state() const { + std::string protobuf_json; + cloe::utility::osi_to_json(this->get(), &protobuf_json); + return fable::Json{ + {"sensor_data", fable::parse_json(protobuf_json)} + }; +} + +} // namespace cloe