From 27df0e44be2fd0c08dcebfe32b6169fedb530a0b Mon Sep 17 00:00:00 2001 From: ClemensLinnhoff Date: Mon, 27 May 2024 15:27:34 +0200 Subject: [PATCH 1/6] Add three more top-level messages Signed-off-by: ClemensLinnhoff --- osi3trace/osi2read.py | 2 +- osi3trace/osi_trace.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/osi3trace/osi2read.py b/osi3trace/osi2read.py index c6bee861e..7ad96a902 100644 --- a/osi3trace/osi2read.py +++ b/osi3trace/osi2read.py @@ -28,7 +28,7 @@ def command_line_arguments(): "--type", "-t", help="Name of the type used to serialize data.", - choices=["SensorView", "GroundTruth", "SensorData"], + choices=["SensorView", "GroundTruth", "SensorData", "TrafficUpdate", "TrafficCommand", "TrafficCommandUpdate"], default="SensorView", type=str, required=False, diff --git a/osi3trace/osi_trace.py b/osi3trace/osi_trace.py index 2b54e6d44..70a36021b 100644 --- a/osi3trace/osi_trace.py +++ b/osi3trace/osi_trace.py @@ -8,12 +8,18 @@ from osi3.osi_sensorview_pb2 import SensorView from osi3.osi_groundtruth_pb2 import GroundTruth from osi3.osi_sensordata_pb2 import SensorData +from osi3.osi_trafficupdate_pb2 import TrafficUpdate +from osi3.osi_trafficcommand_pb2 import TrafficCommand +from osi3.osi_trafficcommandupdate_pb2 import TrafficCommandUpdate MESSAGES_TYPE = { "SensorView": SensorView, "GroundTruth": GroundTruth, "SensorData": SensorData, + "TrafficUpdate": TrafficUpdate, + "TrafficCommand": TrafficCommand, + "TrafficCommandUpdate": TrafficCommandUpdate } From 8f5a8fc5d80ce646c770d34b905a5f7f0a3c3d20 Mon Sep 17 00:00:00 2001 From: ClemensLinnhoff Date: Mon, 27 May 2024 15:32:17 +0200 Subject: [PATCH 2/6] Formatting Signed-off-by: ClemensLinnhoff --- osi3trace/osi2read.py | 9 ++++++++- osi3trace/osi_trace.py | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/osi3trace/osi2read.py b/osi3trace/osi2read.py index 7ad96a902..d987ec5b0 100644 --- a/osi3trace/osi2read.py +++ b/osi3trace/osi2read.py @@ -28,7 +28,14 @@ def command_line_arguments(): "--type", "-t", help="Name of the type used to serialize data.", - choices=["SensorView", "GroundTruth", "SensorData", "TrafficUpdate", "TrafficCommand", "TrafficCommandUpdate"], + choices=[ + "SensorView", + "GroundTruth", + "SensorData", + "TrafficUpdate", + "TrafficCommand", + "TrafficCommandUpdate", + ], default="SensorView", type=str, required=False, diff --git a/osi3trace/osi_trace.py b/osi3trace/osi_trace.py index 70a36021b..43d66029c 100644 --- a/osi3trace/osi_trace.py +++ b/osi3trace/osi_trace.py @@ -19,7 +19,7 @@ "SensorData": SensorData, "TrafficUpdate": TrafficUpdate, "TrafficCommand": TrafficCommand, - "TrafficCommandUpdate": TrafficCommandUpdate + "TrafficCommandUpdate": TrafficCommandUpdate, } From 91cc877c599f1be4630f4f3bf14620113d86d8f1 Mon Sep 17 00:00:00 2001 From: "Pierre R. Mai" Date: Sun, 9 Jun 2024 19:58:16 +0200 Subject: [PATCH 3/6] Add remaining missing top-level interfaces and tests Add all remaining top-level interfaces, fix documentation list of said interfaces and add tests for all interfaces to the osi_trace tests. Signed-off-by: Pierre R. Mai --- doc/architecture/architecture_overview.adoc | 2 +- osi3trace/osi2read.py | 11 +- osi3trace/osi_trace.py | 6 + tests/test_osi_trace.py | 441 +++++++++++++++++++- 4 files changed, 443 insertions(+), 17 deletions(-) diff --git a/doc/architecture/architecture_overview.adoc b/doc/architecture/architecture_overview.adoc index 7a9e98828..3e522947b 100644 --- a/doc/architecture/architecture_overview.adoc +++ b/doc/architecture/architecture_overview.adoc @@ -8,7 +8,7 @@ OSI contains an object-based environment description that uses the message forma Google developed and maintains the Protocol Buffer library. OSI defines top-level messages that are used to exchange data between separate models. Top-level messages define the `GroundTruth` interface, the `SensorData` interface, and – since OSI version 3.0.0 – the interfaces `SensorView` and `SensorViewConfiguration`. -Further top-level messages that were added in later versions of OSI are `TrafficCommand`, `TrafficUpdate`, `MotionRequest`, and `StreamingUpdate`. +Further top-level messages that were added in later versions of OSI are `TrafficCommand`, `TrafficCommandUpdate`, `TrafficUpdate`, `MotionRequest`, and `StreamingUpdate`. The following figure shows the interfaces and models involved in modeling a sensor. diff --git a/osi3trace/osi2read.py b/osi3trace/osi2read.py index d987ec5b0..4575d78b0 100644 --- a/osi3trace/osi2read.py +++ b/osi3trace/osi2read.py @@ -5,7 +5,7 @@ python3 osi2read.py -d trace.osi -o myreadableosifile """ -from osi3trace.osi_trace import OSITrace +from osi3trace.osi_trace import OSITrace, MESSAGES_TYPE import argparse import pathlib @@ -28,14 +28,7 @@ def command_line_arguments(): "--type", "-t", help="Name of the type used to serialize data.", - choices=[ - "SensorView", - "GroundTruth", - "SensorData", - "TrafficUpdate", - "TrafficCommand", - "TrafficCommandUpdate", - ], + choices=list(MESSAGES_TYPE.keys()), default="SensorView", type=str, required=False, diff --git a/osi3trace/osi_trace.py b/osi3trace/osi_trace.py index 43d66029c..541647b62 100644 --- a/osi3trace/osi_trace.py +++ b/osi3trace/osi_trace.py @@ -8,18 +8,24 @@ from osi3.osi_sensorview_pb2 import SensorView from osi3.osi_groundtruth_pb2 import GroundTruth from osi3.osi_sensordata_pb2 import SensorData +from osi3.osi_sensorviewconfiguration_pb2 import SensorViewConfiguration from osi3.osi_trafficupdate_pb2 import TrafficUpdate from osi3.osi_trafficcommand_pb2 import TrafficCommand from osi3.osi_trafficcommandupdate_pb2 import TrafficCommandUpdate +from osi3.osi_motionrequest_pb2 import MotionRequest +from osi3.osi_streamingupdate_pb2 import StreamingUpdate MESSAGES_TYPE = { "SensorView": SensorView, "GroundTruth": GroundTruth, "SensorData": SensorData, + "SensorViewConfiguration": SensorViewConfiguration, "TrafficUpdate": TrafficUpdate, "TrafficCommand": TrafficCommand, "TrafficCommandUpdate": TrafficCommandUpdate, + "MotionRequest": MotionRequest, + "StreamingUpdate": StreamingUpdate, } diff --git a/tests/test_osi_trace.py b/tests/test_osi_trace.py index 428cecbb5..93b0d7791 100644 --- a/tests/test_osi_trace.py +++ b/tests/test_osi_trace.py @@ -4,15 +4,24 @@ from osi3trace.osi_trace import OSITrace from osi3.osi_sensorview_pb2 import SensorView +from osi3.osi_groundtruth_pb2 import GroundTruth +from osi3.osi_sensordata_pb2 import SensorData +from osi3.osi_sensorviewconfiguration_pb2 import SensorViewConfiguration +from osi3.osi_trafficupdate_pb2 import TrafficUpdate +from osi3.osi_trafficcommand_pb2 import TrafficCommand +from osi3.osi_trafficcommandupdate_pb2 import TrafficCommandUpdate +from osi3.osi_motionrequest_pb2 import MotionRequest +from osi3.osi_streamingupdate_pb2 import StreamingUpdate + import struct class TestOSITrace(unittest.TestCase): - def test_osi_trace(self): + def test_osi_trace_sv(self): with tempfile.TemporaryDirectory() as tmpdirname: - path_output = os.path.join(tmpdirname, "output.txth") - path_input = os.path.join(tmpdirname, "input.osi") - create_sample(path_input) + path_output = os.path.join(tmpdirname, "output_sv.txth") + path_input = os.path.join(tmpdirname, "input_sv.osi") + create_sample_sv(path_input) trace = OSITrace(path_input) with open(path_output, "wt") as f: @@ -22,10 +31,122 @@ def test_osi_trace(self): self.assertTrue(os.path.exists(path_output)) + def test_osi_trace_gt(self): + with tempfile.TemporaryDirectory() as tmpdirname: + path_output = os.path.join(tmpdirname, "output_gt.txth") + path_input = os.path.join(tmpdirname, "input_gt.osi") + create_sample_gt(path_input) + + trace = OSITrace(path_input, "GroundTruth") + with open(path_output, "wt") as f: + for message in trace: + f.write(str(message)) + trace.close() + + self.assertTrue(os.path.exists(path_output)) + + def test_osi_trace_sd(self): + with tempfile.TemporaryDirectory() as tmpdirname: + path_output = os.path.join(tmpdirname, "output_sd.txth") + path_input = os.path.join(tmpdirname, "input_sd.osi") + create_sample_sd(path_input) + + trace = OSITrace(path_input, "SensorData") + with open(path_output, "wt") as f: + for message in trace: + f.write(str(message)) + trace.close() + + self.assertTrue(os.path.exists(path_output)) + + def test_osi_trace_svc(self): + with tempfile.TemporaryDirectory() as tmpdirname: + path_output = os.path.join(tmpdirname, "output_svc.txth") + path_input = os.path.join(tmpdirname, "input_svc.osi") + create_sample_svc(path_input) + + trace = OSITrace(path_input, "SensorViewConfiguration") + with open(path_output, "wt") as f: + for message in trace: + f.write(str(message)) + trace.close() + + self.assertTrue(os.path.exists(path_output)) + + def test_osi_trace_tu(self): + with tempfile.TemporaryDirectory() as tmpdirname: + path_output = os.path.join(tmpdirname, "output_tu.txth") + path_input = os.path.join(tmpdirname, "input_tu.osi") + create_sample_tu(path_input) + + trace = OSITrace(path_input, "TrafficUpdate") + with open(path_output, "wt") as f: + for message in trace: + f.write(str(message)) + trace.close() + + self.assertTrue(os.path.exists(path_output)) + + def test_osi_trace_tc(self): + with tempfile.TemporaryDirectory() as tmpdirname: + path_output = os.path.join(tmpdirname, "output_tc.txth") + path_input = os.path.join(tmpdirname, "input_tc.osi") + create_sample_tc(path_input) + + trace = OSITrace(path_input, "TrafficCommand") + with open(path_output, "wt") as f: + for message in trace: + f.write(str(message)) + trace.close() + + self.assertTrue(os.path.exists(path_output)) + + def test_osi_trace_tcu(self): + with tempfile.TemporaryDirectory() as tmpdirname: + path_output = os.path.join(tmpdirname, "output_tcu.txth") + path_input = os.path.join(tmpdirname, "input_tcu.osi") + create_sample_tcu(path_input) + + trace = OSITrace(path_input, "TrafficCommandUpdate") + with open(path_output, "wt") as f: + for message in trace: + f.write(str(message)) + trace.close() + + self.assertTrue(os.path.exists(path_output)) + + def test_osi_trace_mr(self): + with tempfile.TemporaryDirectory() as tmpdirname: + path_output = os.path.join(tmpdirname, "output_mr.txth") + path_input = os.path.join(tmpdirname, "input_mr.osi") + create_sample_mr(path_input) + + trace = OSITrace(path_input, "MotionRequest") + with open(path_output, "wt") as f: + for message in trace: + f.write(str(message)) + trace.close() + + self.assertTrue(os.path.exists(path_output)) + + def test_osi_trace_su(self): + with tempfile.TemporaryDirectory() as tmpdirname: + path_output = os.path.join(tmpdirname, "output_su.txth") + path_input = os.path.join(tmpdirname, "input_su.osi") + create_sample_su(path_input) + + trace = OSITrace(path_input, "StreamingUpdate") + with open(path_output, "wt") as f: + for message in trace: + f.write(str(message)) + trace.close() + + self.assertTrue(os.path.exists(path_output)) + def test_osi_trace_offsets_robustness(self): with tempfile.TemporaryDirectory() as tmpdirname: - path_input = os.path.join(tmpdirname, "input.osi") - create_sample(path_input) + path_input = os.path.join(tmpdirname, "input_robust.osi") + create_sample_sv(path_input) trace = OSITrace(path_input) # Test whether the function can handle be run multiple times safely @@ -37,10 +158,19 @@ def test_osi_trace_offsets_robustness(self): self.assertEqual(offsets, offsets2) -def create_sample(path): +def create_sample_sv(path): f = open(path, "ab") sensorview = SensorView() + sensorview.version.version_major = 3 + sensorview.version.version_minor = 0 + sensorview.version.version_patch = 0 + + sensorview.timestamp.seconds = 0 + sensorview.timestamp.nanos = 0 + + sensorview.sensor_id.value = 42 + sv_ground_truth = sensorview.global_ground_truth sv_ground_truth.version.version_major = 3 sv_ground_truth.version.version_minor = 0 @@ -55,6 +185,9 @@ def create_sample(path): # Generate 10 OSI messages for 9 seconds for i in range(10): # Increment the time + sensorview.timestamp.seconds += 1 + sensorview.timestamp.nanos += 100000 + sv_ground_truth.timestamp.seconds += 1 sv_ground_truth.timestamp.nanos += 100000 @@ -77,3 +210,297 @@ def create_sample(path): f.write(struct.pack(" Date: Mon, 10 Jun 2024 08:38:40 +0200 Subject: [PATCH 4/6] Refactor message type accessor, improve tests Signed-off-by: Pierre R. Mai --- osi3trace/osi2read.py | 4 ++-- osi3trace/osi_trace.py | 5 +++++ tests/test_osi_trace.py | 27 +++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/osi3trace/osi2read.py b/osi3trace/osi2read.py index 4575d78b0..a75bb9a76 100644 --- a/osi3trace/osi2read.py +++ b/osi3trace/osi2read.py @@ -5,7 +5,7 @@ python3 osi2read.py -d trace.osi -o myreadableosifile """ -from osi3trace.osi_trace import OSITrace, MESSAGES_TYPE +from osi3trace.osi_trace import OSITrace import argparse import pathlib @@ -28,7 +28,7 @@ def command_line_arguments(): "--type", "-t", help="Name of the type used to serialize data.", - choices=list(MESSAGES_TYPE.keys()), + choices=OSITrace.message_types(), default="SensorView", type=str, required=False, diff --git a/osi3trace/osi_trace.py b/osi3trace/osi_trace.py index 541647b62..1cc829bef 100644 --- a/osi3trace/osi_trace.py +++ b/osi3trace/osi_trace.py @@ -37,6 +37,11 @@ def map_message_type(type_name): """Map the type name to the protobuf message type.""" return MESSAGES_TYPE[type_name] + @staticmethod + def message_types(): + """Message types that OSITrace supports.""" + return list(MESSAGES_TYPE.keys()) + def __init__(self, path=None, type_name="SensorView", cache_messages=False): self.type = self.map_message_type(type_name) self.file = None diff --git a/tests/test_osi_trace.py b/tests/test_osi_trace.py index 93b0d7791..09240277b 100644 --- a/tests/test_osi_trace.py +++ b/tests/test_osi_trace.py @@ -26,7 +26,10 @@ def test_osi_trace_sv(self): trace = OSITrace(path_input) with open(path_output, "wt") as f: for message in trace: + self.assertIsInstance(message, SensorView) f.write(str(message)) + + self.assertEqual(len(trace.retrieve_offsets()), 10) trace.close() self.assertTrue(os.path.exists(path_output)) @@ -40,7 +43,10 @@ def test_osi_trace_gt(self): trace = OSITrace(path_input, "GroundTruth") with open(path_output, "wt") as f: for message in trace: + self.assertIsInstance(message, GroundTruth) f.write(str(message)) + + self.assertEqual(len(trace.retrieve_offsets()), 10) trace.close() self.assertTrue(os.path.exists(path_output)) @@ -54,7 +60,10 @@ def test_osi_trace_sd(self): trace = OSITrace(path_input, "SensorData") with open(path_output, "wt") as f: for message in trace: + self.assertIsInstance(message, SensorData) f.write(str(message)) + + self.assertEqual(len(trace.retrieve_offsets()), 10) trace.close() self.assertTrue(os.path.exists(path_output)) @@ -68,7 +77,10 @@ def test_osi_trace_svc(self): trace = OSITrace(path_input, "SensorViewConfiguration") with open(path_output, "wt") as f: for message in trace: + self.assertIsInstance(message, SensorViewConfiguration) f.write(str(message)) + + self.assertEqual(len(trace.retrieve_offsets()), 1) trace.close() self.assertTrue(os.path.exists(path_output)) @@ -82,7 +94,10 @@ def test_osi_trace_tu(self): trace = OSITrace(path_input, "TrafficUpdate") with open(path_output, "wt") as f: for message in trace: + self.assertIsInstance(message, TrafficUpdate) f.write(str(message)) + + self.assertEqual(len(trace.retrieve_offsets()), 10) trace.close() self.assertTrue(os.path.exists(path_output)) @@ -96,7 +111,10 @@ def test_osi_trace_tc(self): trace = OSITrace(path_input, "TrafficCommand") with open(path_output, "wt") as f: for message in trace: + self.assertIsInstance(message, TrafficCommand) f.write(str(message)) + + self.assertEqual(len(trace.retrieve_offsets()), 10) trace.close() self.assertTrue(os.path.exists(path_output)) @@ -110,7 +128,10 @@ def test_osi_trace_tcu(self): trace = OSITrace(path_input, "TrafficCommandUpdate") with open(path_output, "wt") as f: for message in trace: + self.assertIsInstance(message, TrafficCommandUpdate) f.write(str(message)) + + self.assertEqual(len(trace.retrieve_offsets()), 10) trace.close() self.assertTrue(os.path.exists(path_output)) @@ -124,7 +145,10 @@ def test_osi_trace_mr(self): trace = OSITrace(path_input, "MotionRequest") with open(path_output, "wt") as f: for message in trace: + self.assertIsInstance(message, MotionRequest) f.write(str(message)) + + self.assertEqual(len(trace.retrieve_offsets()), 10) trace.close() self.assertTrue(os.path.exists(path_output)) @@ -138,7 +162,10 @@ def test_osi_trace_su(self): trace = OSITrace(path_input, "StreamingUpdate") with open(path_output, "wt") as f: for message in trace: + self.assertIsInstance(message, StreamingUpdate) f.write(str(message)) + + self.assertEqual(len(trace.retrieve_offsets()), 10) trace.close() self.assertTrue(os.path.exists(path_output)) From af726652c560f38a092edc759243fa3f9b57a318 Mon Sep 17 00:00:00 2001 From: "Pierre R. Mai" Date: Mon, 10 Jun 2024 11:43:49 +0200 Subject: [PATCH 5/6] Add HostVehicleData support to OSITrace Closes #817. Signed-off-by: Pierre R. Mai --- doc/architecture/architecture_overview.adoc | 2 +- osi3trace/osi_trace.py | 2 + tests/test_osi_trace.py | 56 +++++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/doc/architecture/architecture_overview.adoc b/doc/architecture/architecture_overview.adoc index 3e522947b..31f28c154 100644 --- a/doc/architecture/architecture_overview.adoc +++ b/doc/architecture/architecture_overview.adoc @@ -8,7 +8,7 @@ OSI contains an object-based environment description that uses the message forma Google developed and maintains the Protocol Buffer library. OSI defines top-level messages that are used to exchange data between separate models. Top-level messages define the `GroundTruth` interface, the `SensorData` interface, and – since OSI version 3.0.0 – the interfaces `SensorView` and `SensorViewConfiguration`. -Further top-level messages that were added in later versions of OSI are `TrafficCommand`, `TrafficCommandUpdate`, `TrafficUpdate`, `MotionRequest`, and `StreamingUpdate`. +Further top-level messages that were added in later versions of OSI are `HostVehicleData`, `TrafficCommand`, `TrafficCommandUpdate`, `TrafficUpdate`, `MotionRequest`, and `StreamingUpdate`. The following figure shows the interfaces and models involved in modeling a sensor. diff --git a/osi3trace/osi_trace.py b/osi3trace/osi_trace.py index 1cc829bef..bc496fb69 100644 --- a/osi3trace/osi_trace.py +++ b/osi3trace/osi_trace.py @@ -7,6 +7,7 @@ from osi3.osi_sensorview_pb2 import SensorView from osi3.osi_groundtruth_pb2 import GroundTruth +from osi3.osi_hostvehicledata_pb2 import HostVehicleData from osi3.osi_sensordata_pb2 import SensorData from osi3.osi_sensorviewconfiguration_pb2 import SensorViewConfiguration from osi3.osi_trafficupdate_pb2 import TrafficUpdate @@ -19,6 +20,7 @@ MESSAGES_TYPE = { "SensorView": SensorView, "GroundTruth": GroundTruth, + "HostVehicleData": HostVehicleData, "SensorData": SensorData, "SensorViewConfiguration": SensorViewConfiguration, "TrafficUpdate": TrafficUpdate, diff --git a/tests/test_osi_trace.py b/tests/test_osi_trace.py index 09240277b..7c3845572 100644 --- a/tests/test_osi_trace.py +++ b/tests/test_osi_trace.py @@ -5,6 +5,7 @@ from osi3trace.osi_trace import OSITrace from osi3.osi_sensorview_pb2 import SensorView from osi3.osi_groundtruth_pb2 import GroundTruth +from osi3.osi_hostvehicledata_pb2 import HostVehicleData from osi3.osi_sensordata_pb2 import SensorData from osi3.osi_sensorviewconfiguration_pb2 import SensorViewConfiguration from osi3.osi_trafficupdate_pb2 import TrafficUpdate @@ -51,6 +52,23 @@ def test_osi_trace_gt(self): self.assertTrue(os.path.exists(path_output)) + def test_osi_trace_hvd(self): + with tempfile.TemporaryDirectory() as tmpdirname: + path_output = os.path.join(tmpdirname, "output_hvd.txth") + path_input = os.path.join(tmpdirname, "input_hvd.osi") + create_sample_hvd(path_input) + + trace = OSITrace(path_input, "HostVehicleData") + with open(path_output, "wt") as f: + for message in trace: + self.assertIsInstance(message, HostVehicleData) + f.write(str(message)) + + self.assertEqual(len(trace.retrieve_offsets()), 10) + trace.close() + + self.assertTrue(os.path.exists(path_output)) + def test_osi_trace_sd(self): with tempfile.TemporaryDirectory() as tmpdirname: path_output = os.path.join(tmpdirname, "output_sd.txth") @@ -280,6 +298,44 @@ def create_sample_gt(path): f.close() +def create_sample_hvd(path): + f = open(path, "ab") + hostvehicledata = HostVehicleData() + + hostvehicledata.version.version_major = 3 + hostvehicledata.version.version_minor = 0 + hostvehicledata.version.version_patch = 0 + + hostvehicledata.timestamp.seconds = 0 + hostvehicledata.timestamp.nanos = 0 + + hostvehicledata.host_vehicle_id.value = 114 + + # Generate 10 OSI messages for 9 seconds + for i in range(10): + # Increment the time + hostvehicledata.timestamp.seconds += 1 + hostvehicledata.timestamp.nanos += 100000 + + hostvehicledata.location.dimension.length = 5 + hostvehicledata.location.dimension.width = 2 + hostvehicledata.location.dimension.height = 1 + + hostvehicledata.location.position.x = 0.0 + i + hostvehicledata.location.position.y = 0.0 + hostvehicledata.location.position.z = 0.0 + + hostvehicledata.location.orientation.roll = 0.0 + hostvehicledata.location.orientation.pitch = 0.0 + hostvehicledata.location.orientation.yaw = 0.0 + + """Serialize""" + bytes_buffer = hostvehicledata.SerializeToString() + f.write(struct.pack(" Date: Mon, 10 Jun 2024 11:56:33 +0200 Subject: [PATCH 6/6] Add missing trace file prefix adjust to common order Fixes #816. Signed-off-by: Pierre R. Mai --- doc/architecture/trace_file_naming.adoc | 26 ++- osi3trace/osi_trace.py | 8 +- tests/test_osi_trace.py | 204 ++++++++++++------------ 3 files changed, 125 insertions(+), 113 deletions(-) diff --git a/doc/architecture/trace_file_naming.adoc b/doc/architecture/trace_file_naming.adoc index 2c4bf46da..1c73ed90c 100644 --- a/doc/architecture/trace_file_naming.adoc +++ b/doc/architecture/trace_file_naming.adoc @@ -14,23 +14,35 @@ The names of OSI trace files should have the following format: **Types** -`sd`:: -Trace file contains `SensorData` messages. - `sv`:: Trace file contains `SensorView` messages. +`svc`:: +Trace file contains `SensorViewConfiguration` messages. + `gt`:: Trace file contains `GroundTruth` messages. -`tu`:: -Trace file contains `TrafficUpdate` messages. +`hvd`:: +Trace file contains `HostVehicleData` messages. + +`sd`:: +Trace file contains `SensorData` messages. `tc`:: Trace file contains `TrafficCommand` messages. -`hvd`:: -Trace file contains `HostVehicleData` messages. +`tcu`:: +Trace file contains `TrafficCommandUpdate` messages. + +`tu`:: +Trace file contains `TrafficUpdate` messages. + +`mr`:: +Trace file contains `MotionRequest` messages. + +`su`:: +Trace file contains `StreamingUpdate` messages. **Example** diff --git a/osi3trace/osi_trace.py b/osi3trace/osi_trace.py index bc496fb69..3c0577023 100644 --- a/osi3trace/osi_trace.py +++ b/osi3trace/osi_trace.py @@ -6,26 +6,26 @@ import struct from osi3.osi_sensorview_pb2 import SensorView +from osi3.osi_sensorviewconfiguration_pb2 import SensorViewConfiguration from osi3.osi_groundtruth_pb2 import GroundTruth from osi3.osi_hostvehicledata_pb2 import HostVehicleData from osi3.osi_sensordata_pb2 import SensorData -from osi3.osi_sensorviewconfiguration_pb2 import SensorViewConfiguration -from osi3.osi_trafficupdate_pb2 import TrafficUpdate from osi3.osi_trafficcommand_pb2 import TrafficCommand from osi3.osi_trafficcommandupdate_pb2 import TrafficCommandUpdate +from osi3.osi_trafficupdate_pb2 import TrafficUpdate from osi3.osi_motionrequest_pb2 import MotionRequest from osi3.osi_streamingupdate_pb2 import StreamingUpdate MESSAGES_TYPE = { "SensorView": SensorView, + "SensorViewConfiguration": SensorViewConfiguration, "GroundTruth": GroundTruth, "HostVehicleData": HostVehicleData, "SensorData": SensorData, - "SensorViewConfiguration": SensorViewConfiguration, - "TrafficUpdate": TrafficUpdate, "TrafficCommand": TrafficCommand, "TrafficCommandUpdate": TrafficCommandUpdate, + "TrafficUpdate": TrafficUpdate, "MotionRequest": MotionRequest, "StreamingUpdate": StreamingUpdate, } diff --git a/tests/test_osi_trace.py b/tests/test_osi_trace.py index 7c3845572..9d74f5a9d 100644 --- a/tests/test_osi_trace.py +++ b/tests/test_osi_trace.py @@ -4,13 +4,13 @@ from osi3trace.osi_trace import OSITrace from osi3.osi_sensorview_pb2 import SensorView +from osi3.osi_sensorviewconfiguration_pb2 import SensorViewConfiguration from osi3.osi_groundtruth_pb2 import GroundTruth from osi3.osi_hostvehicledata_pb2 import HostVehicleData from osi3.osi_sensordata_pb2 import SensorData -from osi3.osi_sensorviewconfiguration_pb2 import SensorViewConfiguration -from osi3.osi_trafficupdate_pb2 import TrafficUpdate from osi3.osi_trafficcommand_pb2 import TrafficCommand from osi3.osi_trafficcommandupdate_pb2 import TrafficCommandUpdate +from osi3.osi_trafficupdate_pb2 import TrafficUpdate from osi3.osi_motionrequest_pb2 import MotionRequest from osi3.osi_streamingupdate_pb2 import StreamingUpdate @@ -35,6 +35,23 @@ def test_osi_trace_sv(self): self.assertTrue(os.path.exists(path_output)) + def test_osi_trace_svc(self): + with tempfile.TemporaryDirectory() as tmpdirname: + path_output = os.path.join(tmpdirname, "output_svc.txth") + path_input = os.path.join(tmpdirname, "input_svc.osi") + create_sample_svc(path_input) + + trace = OSITrace(path_input, "SensorViewConfiguration") + with open(path_output, "wt") as f: + for message in trace: + self.assertIsInstance(message, SensorViewConfiguration) + f.write(str(message)) + + self.assertEqual(len(trace.retrieve_offsets()), 1) + trace.close() + + self.assertTrue(os.path.exists(path_output)) + def test_osi_trace_gt(self): with tempfile.TemporaryDirectory() as tmpdirname: path_output = os.path.join(tmpdirname, "output_gt.txth") @@ -86,40 +103,6 @@ def test_osi_trace_sd(self): self.assertTrue(os.path.exists(path_output)) - def test_osi_trace_svc(self): - with tempfile.TemporaryDirectory() as tmpdirname: - path_output = os.path.join(tmpdirname, "output_svc.txth") - path_input = os.path.join(tmpdirname, "input_svc.osi") - create_sample_svc(path_input) - - trace = OSITrace(path_input, "SensorViewConfiguration") - with open(path_output, "wt") as f: - for message in trace: - self.assertIsInstance(message, SensorViewConfiguration) - f.write(str(message)) - - self.assertEqual(len(trace.retrieve_offsets()), 1) - trace.close() - - self.assertTrue(os.path.exists(path_output)) - - def test_osi_trace_tu(self): - with tempfile.TemporaryDirectory() as tmpdirname: - path_output = os.path.join(tmpdirname, "output_tu.txth") - path_input = os.path.join(tmpdirname, "input_tu.osi") - create_sample_tu(path_input) - - trace = OSITrace(path_input, "TrafficUpdate") - with open(path_output, "wt") as f: - for message in trace: - self.assertIsInstance(message, TrafficUpdate) - f.write(str(message)) - - self.assertEqual(len(trace.retrieve_offsets()), 10) - trace.close() - - self.assertTrue(os.path.exists(path_output)) - def test_osi_trace_tc(self): with tempfile.TemporaryDirectory() as tmpdirname: path_output = os.path.join(tmpdirname, "output_tc.txth") @@ -154,6 +137,23 @@ def test_osi_trace_tcu(self): self.assertTrue(os.path.exists(path_output)) + def test_osi_trace_tu(self): + with tempfile.TemporaryDirectory() as tmpdirname: + path_output = os.path.join(tmpdirname, "output_tu.txth") + path_input = os.path.join(tmpdirname, "input_tu.osi") + create_sample_tu(path_input) + + trace = OSITrace(path_input, "TrafficUpdate") + with open(path_output, "wt") as f: + for message in trace: + self.assertIsInstance(message, TrafficUpdate) + f.write(str(message)) + + self.assertEqual(len(trace.retrieve_offsets()), 10) + trace.close() + + self.assertTrue(os.path.exists(path_output)) + def test_osi_trace_mr(self): with tempfile.TemporaryDirectory() as tmpdirname: path_output = os.path.join(tmpdirname, "output_mr.txth") @@ -257,6 +257,31 @@ def create_sample_sv(path): f.close() +def create_sample_svc(path): + f = open(path, "ab") + sensorviewconfig = SensorViewConfiguration() + + sensorviewconfig.version.version_major = 3 + sensorviewconfig.version.version_minor = 0 + sensorviewconfig.version.version_patch = 0 + + sensorviewconfig.sensor_id.value = 42 + + sensorviewconfig.mounting_position.position.x = 0.8 + sensorviewconfig.mounting_position.position.y = 1.0 + sensorviewconfig.mounting_position.position.z = 0.5 + + sensorviewconfig.mounting_position.orientation.roll = 0.10 + sensorviewconfig.mounting_position.orientation.pitch = 0.15 + sensorviewconfig.mounting_position.orientation.yaw = 0.25 + + """Serialize""" + bytes_buffer = sensorviewconfig.SerializeToString() + f.write(struct.pack("