|
5 | 5 | from osi3trace.osi_trace import OSITrace
|
6 | 6 | from osi3.osi_sensorview_pb2 import SensorView
|
7 | 7 | from osi3.osi_groundtruth_pb2 import GroundTruth
|
| 8 | +from osi3.osi_hostvehicledata_pb2 import HostVehicleData |
8 | 9 | from osi3.osi_sensordata_pb2 import SensorData
|
9 | 10 | from osi3.osi_sensorviewconfiguration_pb2 import SensorViewConfiguration
|
10 | 11 | from osi3.osi_trafficupdate_pb2 import TrafficUpdate
|
@@ -51,6 +52,23 @@ def test_osi_trace_gt(self):
|
51 | 52 |
|
52 | 53 | self.assertTrue(os.path.exists(path_output))
|
53 | 54 |
|
| 55 | + def test_osi_trace_hvd(self): |
| 56 | + with tempfile.TemporaryDirectory() as tmpdirname: |
| 57 | + path_output = os.path.join(tmpdirname, "output_hvd.txth") |
| 58 | + path_input = os.path.join(tmpdirname, "input_hvd.osi") |
| 59 | + create_sample_hvd(path_input) |
| 60 | + |
| 61 | + trace = OSITrace(path_input, "HostVehicleData") |
| 62 | + with open(path_output, "wt") as f: |
| 63 | + for message in trace: |
| 64 | + self.assertIsInstance(message, HostVehicleData) |
| 65 | + f.write(str(message)) |
| 66 | + |
| 67 | + self.assertEqual(len(trace.retrieve_offsets()), 10) |
| 68 | + trace.close() |
| 69 | + |
| 70 | + self.assertTrue(os.path.exists(path_output)) |
| 71 | + |
54 | 72 | def test_osi_trace_sd(self):
|
55 | 73 | with tempfile.TemporaryDirectory() as tmpdirname:
|
56 | 74 | path_output = os.path.join(tmpdirname, "output_sd.txth")
|
@@ -280,6 +298,44 @@ def create_sample_gt(path):
|
280 | 298 | f.close()
|
281 | 299 |
|
282 | 300 |
|
| 301 | +def create_sample_hvd(path): |
| 302 | + f = open(path, "ab") |
| 303 | + hostvehicledata = HostVehicleData() |
| 304 | + |
| 305 | + hostvehicledata.version.version_major = 3 |
| 306 | + hostvehicledata.version.version_minor = 0 |
| 307 | + hostvehicledata.version.version_patch = 0 |
| 308 | + |
| 309 | + hostvehicledata.timestamp.seconds = 0 |
| 310 | + hostvehicledata.timestamp.nanos = 0 |
| 311 | + |
| 312 | + hostvehicledata.host_vehicle_id.value = 114 |
| 313 | + |
| 314 | + # Generate 10 OSI messages for 9 seconds |
| 315 | + for i in range(10): |
| 316 | + # Increment the time |
| 317 | + hostvehicledata.timestamp.seconds += 1 |
| 318 | + hostvehicledata.timestamp.nanos += 100000 |
| 319 | + |
| 320 | + hostvehicledata.location.dimension.length = 5 |
| 321 | + hostvehicledata.location.dimension.width = 2 |
| 322 | + hostvehicledata.location.dimension.height = 1 |
| 323 | + |
| 324 | + hostvehicledata.location.position.x = 0.0 + i |
| 325 | + hostvehicledata.location.position.y = 0.0 |
| 326 | + hostvehicledata.location.position.z = 0.0 |
| 327 | + |
| 328 | + hostvehicledata.location.orientation.roll = 0.0 |
| 329 | + hostvehicledata.location.orientation.pitch = 0.0 |
| 330 | + hostvehicledata.location.orientation.yaw = 0.0 |
| 331 | + |
| 332 | + """Serialize""" |
| 333 | + bytes_buffer = hostvehicledata.SerializeToString() |
| 334 | + f.write(struct.pack("<L", len(bytes_buffer)) + bytes_buffer) |
| 335 | + |
| 336 | + f.close() |
| 337 | + |
| 338 | + |
283 | 339 | def create_sample_sd(path):
|
284 | 340 | f = open(path, "ab")
|
285 | 341 | sensordata = SensorData()
|
|
0 commit comments