Skip to content

Commit 26dde03

Browse files
tobifalkcassava
authored andcommitted
osi: Renaming and cleanup
1 parent 1eb0a15 commit 26dde03

18 files changed

+171
-240
lines changed

optional/osi/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ file(GLOB cloe-osi_PUBLIC_HEADERS "include/**/*.hpp")
1717
add_library(cloe-osi
1818
# find src -type f -name "*.cpp" \! -name "*_test.cpp"
1919
src/osi/utility/osi_ground_truth.cpp
20-
src/osi/utility/osi_omni_sensor.cpp
20+
src/osi/utility/osi_message_handler.cpp
2121
src/osi/utility/osi_transceiver_tcp.cpp
2222
src/osi/utility/osi_utils.cpp
2323

optional/osi/include/osi/utility/osi_ground_truth.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131

3232
#include "osi/utility/osi_utils.hpp" // for osi_require, ..
3333

34-
namespace osii {
34+
namespace cloeosi {
3535

3636
/**
3737
* OsiGroundTruth provides convenient access to auxiliary ground truth
38-
* information while processing an OSI message.
38+
* information while converting an OSI message to Cloe data.
3939
*/
4040
class OsiGroundTruth {
4141
public:
@@ -115,4 +115,4 @@ class OsiGroundTruth {
115115
std::map<int, Eigen::Vector3d> mov_obj_dimensions_;
116116
};
117117

118-
} // namespace osii
118+
} // namespace cloeosi

optional/osi/include/osi/utility/osi_omni_sensor.hpp renamed to optional/osi/include/osi/utility/osi_message_handler.hpp

+30-43
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
* SPDX-License-Identifier: Apache-2.0
1717
*/
1818
/**
19-
* \file osi_omni_sensor.hpp
20-
* \see osi_omni_sensor.cpp
19+
* \file osi_message_handler.hpp
20+
* \see osi_message_handler.cpp
2121
*/
2222

2323
#pragma once
@@ -42,7 +42,7 @@
4242
#include "osi/utility/osi_transceiver.hpp" // for OsiTransceiver
4343
#include "osi/utility/osi_utils.hpp"
4444

45-
namespace osii {
45+
namespace cloeosi {
4646

4747
/**
4848
* Convert OSI timestamp to Cloe time format.
@@ -171,111 +171,98 @@ struct SensorMockConf : public cloe::Confable {
171171
/**
172172
* Base class for an OSI sensor which is connected via TCP.
173173
*/
174-
class OsiOmniSensor {
174+
class OsiMsgHandler {
175175
public:
176-
virtual ~OsiOmniSensor() = default;
177-
OsiOmniSensor() = delete;
176+
virtual ~OsiMsgHandler() = default;
177+
OsiMsgHandler() = delete;
178178

179179
/**
180-
* Create a new instance of OsiOmniSensor with the given OsiTransceiver.
180+
* Create a new instance of OsiMsgHandler with the given OsiTransceiver.
181181
*/
182-
OsiOmniSensor(std::unique_ptr<OsiTransceiver>&& osi_transceiver, uint64_t owner_id)
182+
OsiMsgHandler(std::unique_ptr<OsiTransceiver>&& osi_transceiver, uint64_t owner_id)
183183
: osi_comm_(std::move(osi_transceiver)), owner_id_(owner_id) {
184184
ground_truth_ = std::make_unique<OsiGroundTruth>();
185185
}
186186

187187
/**
188-
* Create a new instance of OsiOmniSensor with the given new OsiTransceiver.
188+
* Create a new instance of OsiMsgHandler with the given new OsiTransceiver.
189189
*
190-
* WARNING: If you use this constructor, please realize that OsiOmniSensor
190+
* WARNING: If you use this constructor, please realize that OsiMsgHandler
191191
* takes ownership of the pointer you pass in.
192192
*/
193-
OsiOmniSensor(OsiTransceiver* osi_transceiver, uint64_t owner_id)
193+
OsiMsgHandler(OsiTransceiver* osi_transceiver, uint64_t owner_id)
194194
: osi_comm_(osi_transceiver), owner_id_(owner_id) {
195195
ground_truth_ = std::make_unique<OsiGroundTruth>();
196196
}
197197

198198
/**
199-
* Receive and process the incoming osi3::SensorData messages.
199+
* Receive and process the incoming osi3 messages.
200200
*/
201-
void step_sensor_data(const cloe::Sync& s, const bool& restart, cloe::Duration& sim_time);
202-
203-
/**
204-
* Receive and process the incoming osi3::SensorView messages.
205-
*/
206-
void step_sensor_view(const cloe::Sync& s, const bool& restart, cloe::Duration& sim_time);
207-
208-
/**
209-
* Receive and process the incoming osi3::GroundTruth messages.
210-
*/
211-
void step_ground_truth(const cloe::Sync& s, const bool& restart, cloe::Duration& sim_time);
212-
213-
/**
214-
* Receive and process the incoming messages.
215-
*/
216-
//virtual void step(const cloe::Sync& s, const bool& restart, cloe::Duration& sim_time) = 0;
201+
template <typename T>
202+
void process_osi_msgs(const cloe::Sync& s, const bool& restart, cloe::Duration& osi_time);
217203

218204
/**
219205
* Store the initial timestamp.
220206
* Note that the osi time does not necessarily start at zero.
221207
*/
222-
virtual void process(const osi3::Timestamp& timestamp);
208+
void handle_first_message(const osi3::Timestamp& timestamp);
223209

224210
/**
225211
* Translate OSI SensorData to Cloe data objects.
226212
*
227213
* \param osi_sd SensorData message to be processed.
228-
* \param sim_time Simulation time to be set.
214+
* \param osi_time Timestamp of the OSI message.
229215
*/
230-
virtual void process_received_msg(osi3::SensorData* osi_sd, cloe::Duration& sim_time);
216+
virtual void process_received_msg(osi3::SensorData* osi_sd, cloe::Duration& osi_time);
231217

232218
/**
233219
* Translate OSI SensorView to Cloe data objects.
234220
*
235221
* \param osi_sv SensorView message to be processed.
236-
* \param sim_time Simulation time to be set.
222+
* \param osi_time Timestamp of the OSI message.
237223
*/
238-
virtual void process_received_msg(osi3::SensorView* osi_sv, cloe::Duration& sim_time);
224+
virtual void process_received_msg(osi3::SensorView* osi_sv, cloe::Duration& osi_time);
239225

240226
/**
241227
* Translate OSI GroundTruth to Cloe data objects.
242228
*
243229
* \param osi_gt GroundTruth message to be processed.
244-
* \param sim_time Simulation time to be set.
230+
* \param osi_time Timestamp of the OSI message.
245231
*/
246-
virtual void process_received_msg(osi3::GroundTruth* osi_gt, cloe::Duration& sim_time);
232+
virtual void process_received_msg(osi3::GroundTruth* osi_gt, cloe::Duration& osi_time);
247233

248234
/**
249235
* Translate OSI GroundTruth to Cloe data objects.
250236
*
251237
* \param osi_gt GroundTruth message to be processed.
252238
*/
253-
virtual void process(const osi3::GroundTruth& osi_gt);
239+
virtual void convert_to_cloe_data(const osi3::GroundTruth& osi_gt);
254240

255241
/**
256242
* Translate OSI SensorView to Cloe data objects.
257243
*
258244
* \param osi_sv SensorView message to be processed, including ground truth.
259245
*/
260-
virtual void process(const osi3::SensorView& osi_sv);
246+
virtual void convert_to_cloe_data(const osi3::SensorView& osi_sv);
261247

262248
/**
263249
* Translate OSI ego base information made available to the sensor model
264250
* from other components, or use ground truth.
265251
* \param osi_mo MovingObject (ground truth) used as fallback.
266252
* \param osi_hv Pointer to HostVehicleData message to be processed (if available).
267253
*/
268-
virtual void process(const osi3::MovingObject& osi_ego, const osi3::HostVehicleData* osi_hv);
254+
virtual void convert_to_cloe_data(const osi3::MovingObject& osi_ego,
255+
const osi3::HostVehicleData* osi_hv);
269256

270257
/**
271258
* Translate OSI detected moving object information to Cloe data objects.
272259
*
273260
* \param osi_eh DetectedEntityHeader message to be processed (if available).
274261
* \param osi_mo DetectedMovingObject message to be processed.
275262
*/
276-
virtual void process(const bool has_eh,
277-
const osi3::DetectedEntityHeader& osi_eh,
278-
const osi3::DetectedMovingObject& osi_mo);
263+
virtual void convert_to_cloe_data(const bool has_eh,
264+
const osi3::DetectedEntityHeader& osi_eh,
265+
const osi3::DetectedMovingObject& osi_mo);
279266

280267
void detected_moving_objects_from_ground_truth();
281268

@@ -334,7 +321,7 @@ class OsiOmniSensor {
334321
*/
335322
virtual void clear_cache() { osi_comm_->clear_cache(); }
336323

337-
friend void to_json(cloe::Json& j, const OsiOmniSensor& c) {
324+
friend void to_json(cloe::Json& j, const OsiMsgHandler& c) {
338325
j = cloe::Json{
339326
{"osi_connection", *c.osi_comm_},
340327
};
@@ -363,4 +350,4 @@ class OsiOmniSensor {
363350
/// Use alternative source for required data or overwrite incoming data, if requested.
364351
std::shared_ptr<const SensorMockConf> mock_{nullptr};
365352
};
366-
} // namespace osii
353+
} // namespace cloeosi

optional/osi/include/osi/utility/osi_transceiver.hpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <osi3/osi_sensordata.pb.h> // for SensorData
2828
#include <osi3/osi_groundtruth.pb.h> // for GroundTruth
2929

30-
namespace osii {
30+
namespace cloeosi {
3131

3232
/**
3333
* OsiError may be thrown when an error is detected in the OSI protocol.
@@ -43,7 +43,7 @@ class OsiError : public cloe::Error {
4343
};
4444

4545
/**
46-
* OsiTransceiver is an interface for a OSI connection via TCP.
46+
* OsiTransceiver is an interface for OSI message exchange, e.g. via TCP.
4747
*/
4848
class OsiTransceiver {
4949
public:
@@ -84,21 +84,21 @@ class OsiTransceiver {
8484
/**
8585
* Non-blocking function to return all received osi::SensorData messages.
8686
*/
87-
virtual std::vector<std::shared_ptr<osi3::SensorData>> receive_sensor_data() = 0;
87+
virtual void receive_osi_msgs(std::vector<std::shared_ptr<osi3::SensorData>>& msgs) = 0;
8888

8989
/**
9090
* Non-blocking function to return all received osi::SensorView messages.
9191
*/
92-
virtual std::vector<std::shared_ptr<osi3::SensorView>> receive_sensor_view() = 0;
92+
virtual void receive_osi_msgs(std::vector<std::shared_ptr<osi3::SensorView>>& msgs) = 0;
9393

9494
/**
9595
* Non-blocking function to return all received osi::GroundTruth messages.
9696
*/
97-
virtual std::vector<std::shared_ptr<osi3::GroundTruth>> receive_ground_truth() = 0;
97+
virtual void receive_osi_msgs(std::vector<std::shared_ptr<osi3::GroundTruth>>& msgs) = 0;
9898

9999
virtual void to_json(cloe::Json& j) const = 0;
100100

101101
friend void to_json(cloe::Json& j, const OsiTransceiver& t) { t.to_json(j); }
102102
};
103103

104-
} // namespace osii
104+
} // namespace cloeosi

optional/osi/include/osi/utility/osi_transceiver_tcp.hpp

+11-22
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include "osi/utility/osi_transceiver.hpp" // for OsiTransceiver
3737
#include "osi/utility/osi_utils.hpp" // for osi_logger
3838

39-
namespace osii {
39+
namespace cloeosi {
4040

4141
/**
4242
* OsiTransceiverTcp implements an OsiTransceiver via TCP.
@@ -57,31 +57,23 @@ class OsiTransceiverTcp : public OsiTransceiver, public cloe::utility::TcpTransc
5757
return this->tcp_available_data() >= static_cast<std::streamsize>(sizeof(osi3::GroundTruth));
5858
}
5959

60-
std::vector<std::shared_ptr<osi3::SensorData>> receive_sensor_data() override {
61-
std::vector<std::shared_ptr<osi3::SensorData>> msgs;
60+
void receive_osi_msgs(std::vector<std::shared_ptr<osi3::SensorData>>& msgs) override {
61+
if (msgs.size() > 0) {
62+
osi_logger()->warn(
63+
"OsiTransceiverTcp: Non-zero length of message vector before retrieval: {}", msgs.size());
64+
}
6265
while (this->has_sensor_data()) {
6366
num_received_++;
6467
msgs.push_back(this->receive_sensor_data_wait());
6568
}
66-
return msgs;
6769
}
6870

69-
std::vector<std::shared_ptr<osi3::SensorView>> receive_sensor_view() override {
70-
std::vector<std::shared_ptr<osi3::SensorView>> msgs;
71-
while (this->has_sensor_view()) {
72-
num_received_++;
73-
msgs.push_back(this->receive_sensor_view_wait());
74-
}
75-
return msgs;
71+
void receive_osi_msgs(std::vector<std::shared_ptr<osi3::SensorView>>& /*msgs*/) override {
72+
throw OsiError("OsiTransceiverTcp: Retrieval of osi3::SensorView not yet implemented.");
7673
}
7774

78-
std::vector<std::shared_ptr<osi3::GroundTruth>> receive_ground_truth() override {
79-
std::vector<std::shared_ptr<osi3::GroundTruth>> msgs;
80-
while (this->has_ground_truth()) {
81-
num_received_++;
82-
msgs.push_back(this->receive_ground_truth_wait());
83-
}
84-
return msgs;
75+
void receive_osi_msgs(std::vector<std::shared_ptr<osi3::GroundTruth>>& /*msgs*/) override {
76+
throw OsiError("OsiTransceiverTcp: Retrieval of osi3::GroundTruth not yet implemented.");
8577
}
8678

8779
void to_json(cloe::Json& j) const override {
@@ -101,9 +93,6 @@ class OsiTransceiverTcp : public OsiTransceiver, public cloe::utility::TcpTransc
10193
* Synchronous (blocking) method to receive a SensorData message.
10294
*/
10395
std::shared_ptr<osi3::SensorData> receive_sensor_data_wait();
104-
std::shared_ptr<osi3::SensorView> receive_sensor_view_wait();
105-
std::shared_ptr<osi3::GroundTruth>
106-
receive_ground_truth_wait(); // TODO(tobias): change to template function
10796

10897
private:
10998
// Statistics for interest's sake
@@ -121,4 +110,4 @@ class OsiTransceiverTcpFactory : public cloe::utility::TcpTransceiverFactory<Osi
121110
const char* instance_name() const override { return "OsiTransceiverTcp"; }
122111
};
123112

124-
} // namespace osii
113+
} // namespace cloeosi

optional/osi/include/osi/utility/osi_utils.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
((test_expr) ? (void)0 : throw cloe::ModelError("OSI message: {} required!", name))
4242
#endif
4343

44-
namespace osii {
44+
namespace cloeosi {
4545

4646
inline cloe::Logger osi_logger() { return cloe::logger::get("vtd/osi"); }
4747

@@ -98,4 +98,4 @@ void pose_to_osi_position_orientation(const Eigen::Isometry3d&, osi3::BaseMoving
9898
*/
9999
void osi_transform_base_moving(const osi3::BaseMoving& base_ref, osi3::BaseMoving& base);
100100

101-
} // namespace osii
101+
} // namespace cloeosi

optional/osi/src/osi/utility/osi_ground_truth.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <osi3/osi_object.pb.h> // for MovingObject
2626
#include <cloe/simulator.hpp> // for ModelError
2727

28-
namespace osii {
28+
namespace cloeosi {
2929

3030
const osi3::MovingObject* OsiGroundTruth::get_moving_object(const uint64_t id) const {
3131
for (auto osi_obj = gt_ptr_->moving_object().begin(); osi_obj != gt_ptr_->moving_object().end();
@@ -58,4 +58,4 @@ void OsiGroundTruth::set(const osi3::GroundTruth& osi_gt) {
5858
}
5959
}
6060

61-
} // namespace osii
61+
} // namespace cloeosi

0 commit comments

Comments
 (0)