Skip to content

Commit

Permalink
fixup! osi: Serialize OsiSensor active state
Browse files Browse the repository at this point in the history
  • Loading branch information
cassava committed Apr 22, 2024
1 parent a80863a commit 90cf719
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
1 change: 1 addition & 0 deletions osi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 2 additions & 13 deletions osi/include/cloe/component/osi_sensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include <osi3/osi_sensordata.pb.h> // for SensorData

#include <cloe/component.hpp> // for Component
#include <cloe/component.hpp> // for Component, Json
#include <cloe/utility/osi_utils.hpp> // for osi_to_json

namespace cloe {
Expand All @@ -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
33 changes: 33 additions & 0 deletions osi/src/cloe/component/osi_sensor.cpp
Original file line number Diff line number Diff line change
@@ -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 <cloe/component/osi_sensor.hpp>

#include <fable/json.hpp> // 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

0 comments on commit 90cf719

Please sign in to comment.