Skip to content

Commit ddff0cb

Browse files
tobifalkcassava
authored andcommitted
osi: Merge OsiSensor into cloe-osi
1 parent a9412f8 commit ddff0cb

File tree

2 files changed

+39
-75
lines changed

2 files changed

+39
-75
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 Robert Bosch GmbH
2+
* Copyright 2023 Robert Bosch GmbH
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,16 +21,10 @@
2121
*/
2222

2323
#pragma once
24-
#ifndef CLOE_COMPONENT_OSI_SENSOR_HPP_
25-
#define CLOE_COMPONENT_OSI_SENSOR_HPP_
2624

27-
#include <memory> // for shared_ptr
25+
#include <osi_sensordata.pb.h> // for SensorData
2826

29-
#include "osi_groundtruth.pb.h" // for GroundTruth
30-
#include "osi_sensordata.pb.h" // for SensorData
31-
#include "osi_sensorview.pb.h" // for SensorView
32-
33-
#include <cloe/component.hpp> // for Component, Json
27+
#include <cloe/component.hpp> // for Component
3428

3529
namespace cloe_osi {
3630

@@ -41,64 +35,10 @@ class OsiSensor : public cloe::Component {
4135
virtual ~OsiSensor() noexcept = default;
4236

4337
/**
44-
* Return OSI data, if available.
45-
*/
46-
47-
virtual std::shared_ptr<osi3::GroundTruth> ground_truth() = 0;
48-
49-
virtual std::shared_ptr<osi3::SensorView> sensor_view() = 0;
50-
51-
virtual std::shared_ptr<osi3::SensorData> sensor_data() = 0;
52-
53-
/**
54-
* Writes JSON representation into j.
38+
* Return OSI-SensorData
5539
*/
56-
cloe::Json active_state() const override {
57-
return cloe::Json{
58-
/*{"ground_truth", this->ground_truth()},
59-
{"sensor_view", this->sensor_view()},
60-
{"sensor_data", this->sensor_data()},*/
61-
};
62-
}
63-
};
64-
65-
class NopOsiSensor : public OsiSensor {
66-
public:
67-
using OsiSensor::OsiSensor;
68-
NopOsiSensor() : OsiSensor("nop_osi_sensor") {}
69-
virtual ~NopOsiSensor() noexcept = default;
70-
71-
std::shared_ptr<osi3::GroundTruth> ground_truth() override { return ground_truth_; }
72-
73-
std::shared_ptr<osi3::SensorView> sensor_view() override { return sensor_view_; }
74-
75-
std::shared_ptr<osi3::SensorData> sensor_data() override { return sensor_data_; }
76-
77-
void set_ground_truth(const osi3::GroundTruth& gt) {
78-
ground_truth_ = std::make_shared<osi3::GroundTruth>(gt);
79-
}
80-
81-
void set_sensor_view(const osi3::SensorView& view) {
82-
sensor_view_ = std::make_shared<osi3::SensorView>(view);
83-
}
84-
85-
void set_sensor_data(const osi3::SensorData& data) {
86-
sensor_data_ = std::make_shared<osi3::SensorData>(data);
87-
}
88-
89-
void reset() override {
90-
OsiSensor::reset();
91-
ground_truth_.reset();
92-
sensor_view_.reset();
93-
sensor_data_.reset();
94-
}
95-
96-
protected:
97-
std::shared_ptr<osi3::GroundTruth> ground_truth_{nullptr};
98-
std::shared_ptr<osi3::SensorView> sensor_view_{nullptr};
99-
std::shared_ptr<osi3::SensorData> sensor_data_{nullptr};
40+
virtual const std::shared_ptr<osi3::SensorData>& get() const = 0;
41+
virtual std::shared_ptr<osi3::SensorData>& get() = 0;
10042
};
10143

10244
} // namespace cloe_osi
103-
104-
#endif // CLOE_COMPONENT_OSI_SENSOR_HPP_

optional/osi/src/osi/component/osi_sensor_test.cpp

+33-9
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,39 @@
2626

2727
#include <osi/component/osi_sensor.hpp>
2828

29-
TEST(cloe_osi_sensor, sensor_data) {
30-
cloe_osi::NopOsiSensor sensor;
31-
osi3::SensorData sd;
32-
sd.mutable_version()->set_version_major(3);
33-
sd.mutable_timestamp()->set_seconds(1);
29+
class TestOsiSensor : public ::cloe_osi::OsiSensor {
30+
public:
31+
using OsiSensor::OsiSensor;
32+
TestOsiSensor() : OsiSensor("nop_osi_sensor") {}
33+
virtual ~TestOsiSensor() noexcept = default;
34+
35+
const std::shared_ptr<osi3::SensorData>& get() const override { return sensor_data_; };
36+
std::shared_ptr<osi3::SensorData>& get() override { return sensor_data_; }
37+
38+
void reset() override {
39+
OsiSensor::reset();
40+
sensor_data_.reset();
41+
}
3442

35-
sensor.set_sensor_data(sd);
43+
fable::Json active_state() const override {
44+
return fable::Json{
45+
{"name", this->name()},
46+
};
47+
}
3648

37-
ASSERT_TRUE(sensor.sensor_data()->has_version());
38-
ASSERT_TRUE(sensor.sensor_data()->has_timestamp());
39-
ASSERT_FALSE(sensor.sensor_data()->has_mounting_position());
49+
protected:
50+
std::shared_ptr<osi3::SensorData> sensor_data_{nullptr};
51+
};
52+
53+
TEST(cloe_osi_sensor, sensor_data) {
54+
TestOsiSensor sensor;
55+
{
56+
osi3::SensorData sd;
57+
sd.mutable_version()->set_version_major(3);
58+
sd.mutable_timestamp()->set_seconds(1);
59+
sensor.get() = std::make_shared<osi3::SensorData>(sd);
60+
}
61+
ASSERT_TRUE(sensor.get()->has_version());
62+
ASSERT_TRUE(sensor.get()->has_timestamp());
63+
ASSERT_FALSE(sensor.get()->has_mounting_position());
4064
}

0 commit comments

Comments
 (0)