Skip to content

Commit e45d834

Browse files
authored
Merge branch 'master' into feature/osi-traffic-participants-combined
2 parents 00e872f + e345aad commit e45d834

File tree

6 files changed

+183
-35
lines changed

6 files changed

+183
-35
lines changed

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ addons:
6161
- doxygen-gui
6262
- graphviz
6363
- python3-setuptools
64+
- python3-pip
65+
- python3-wheel
6466

6567

6668
jobs:
@@ -78,6 +80,8 @@ jobs:
7880
- cd ..
7981
- python3 setup.py build
8082
- python3 setup.py sdist
83+
- python3 -m pip install -U pip
84+
- python3 -m pip install .
8185
- cd build
8286
- cmake --build . --target install
8387
- cd ..
@@ -103,6 +107,8 @@ jobs:
103107
- cd ..
104108
- python3 setup.py build
105109
- python3 setup.py sdist
110+
- python3 -m pip install -U pip
111+
- python3 -m pip install .
106112
- cd build
107113
- cmake --build . --target install
108114
- cd ..
@@ -128,6 +134,8 @@ jobs:
128134
- cd ..
129135
- python3 setup.py build
130136
- python3 setup.py sdist
137+
- python3 -m pip install -U pip
138+
- python3 -m pip install .
131139
- cd build
132140
- cmake --build . --target install
133141
- cd ..

doc/howtocontribute.rst

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,82 @@ Introduction
77
------------
88

99
The purpose of this document is to help contributors get started with
10-
the Open Simulation Interface (OSI) codebase.
10+
the ASAM Open Simulation Interface (OSI) codebase.
11+
12+
As an open-source standardisation project, we welcome and encourage the community to submit patches directly to the project. In our collaborative open source environment, standards and methods for submitting changes help reduce the chaos that can result from an active development community.
13+
14+
This document explains how to participate in project conversations, log bugs and enhancement requests, and submit patches to the project so your patch will be accepted quickly in the codebase.
15+
16+
Licensing
17+
---------
18+
19+
OSI uses the Mozilla Public License, v. 2.0. (as found in the LICENSE file in the project’s GitHub repo).
20+
21+
The license tells you what rights you have as a developer, provided by the copyright holder. It is important that the contributor fully understands the licensing rights and agrees to them. Sometimes the copyright holder isn’t the contributor, such as when the contributor is doing work on behalf of a company.
22+
23+
Developer Certification of Origin (DCO)
24+
---------------------------------------
25+
26+
To make a good faith effort to ensure licensing criteria are met, the OSI project requires the Developer Certificate of Origin (DCO) process to be followed.
27+
28+
The DCO is an attestation attached to every contribution made by every developer. In the commit message of the contribution, (described more fully later in this document), the developer simply adds a Signed-off-by statement and thereby agrees to the DCO.
29+
30+
When a developer submits a patch, it is a commitment that the contributor has the right to submit the patch per the license. The DCO agreement is shown below and `online <http://developercertificate.org/>`_.
31+
::
32+
33+
Developer's Certificate of Origin 1.1
34+
35+
By making a contribution to this project, I certify that:
36+
37+
(a) The contribution was created in whole or in part by me and I
38+
have the right to submit it under the open source license
39+
indicated in the file; or
40+
41+
(b) The contribution is based upon previous work that, to the
42+
best of my knowledge, is covered under an appropriate open
43+
source license and I have the right under that license to
44+
submit that work with modifications, whether created in whole
45+
or in part by me, under the same open source license (unless
46+
I am permitted to submit under a different license), as
47+
Indicated in the file; or
48+
49+
(c) The contribution was provided directly to me by some other
50+
person who certified (a), (b) or (c) and I have not modified
51+
it.
52+
53+
(d) I understand and agree that this project and the contribution
54+
are public and that a record of the contribution (including
55+
all personal information I submit with it, including my
56+
sign-off) is maintained indefinitely and may be redistributed
57+
consistent with this project or the open source license(s)
58+
involved.
59+
60+
DCO Sign-Off Methods
61+
--------------------
62+
63+
The DCO requires a sign-off message in the following format appear on each commit in the pull request:
64+
::
65+
66+
Signed-off-by: Firstname Lastname <email@address.com>
67+
68+
The DCO text can either be manually added to your commit body, or you can add either ``-s`` or ``--signoff`` to your usual Git commit commands. If you forget to add the sign-off you can also amend a previous commit with the sign-off by running ``git commit --amend -s``. You can add sign-offs to multiple commits (including commits originally authored by others, if you are authorized to do so) using ``git rebase --signoff``. If you’ve pushed your changes to GitHub already you’ll need to force push your branch after this with ``git push --force-with-lease``.
69+
70+
If you want to be reminded to add the sign-off for commits in your repository, you can add the following commit-message git hook to your repository:
71+
72+
.. code:: shell
73+
74+
#!/bin/sh
75+
#
76+
# Check for DCO/Signed-off-by in message
77+
#
78+
79+
if ! grep -q "^Signed-off-by: " "$1"
80+
then
81+
echo "Aborting commit: Commit message is not signed off" >&2
82+
exit 1
83+
fi
84+
85+
Placing this script into a file called ``.git/hooks/commit-msg`` and making it executable (e.g. using ``chmod a+x .git/hooks/commit-msg`` on unixoid operating systems) will prevent commits without a sign-off.
1186

1287

1388
Reporting issues
@@ -69,7 +144,7 @@ the commits are combined
69144
into one commit and merged into the master branch.
70145
Once a pull request is ready, it is reviewed and
71146
approved, then squashed using the ``--fast-forward`` option of Git in order to
72-
maintain a streamlined Git history.
147+
maintain a streamlined Git history. Pull requests without a Sign-Off message (see DCO above) will not be accepted.
73148

74149
**We also enforce a few hygiene rules**:
75150

doc/interfaceconventions.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ When adding new messages, enums, field messages and field enums to OSI we enforc
77

88
Message Naming
99
---------------
10-
A message definition should always be in camel case. This means that the first letter of each word in a message should be upper case without any spaces. See example below:
10+
A message definition should always be in PascalCase. This means that the first letter of each word in a message should be upper case without any spaces. See example below:
1111

1212
.. code-block:: protobuf
1313
@@ -37,7 +37,7 @@ All messages that are intended to be exchanged as a stand-alone message, i.e. no
3737
3838
Field Message Naming
3939
---------------------
40-
After defining a message fields can be added to it in snake case format. This means every letter is lower case and the words are connected through an underline character. See example below:
40+
After defining a message fields can be added to it in snake_case format. This means every letter is lower case and the words are connected through an underline character. See example below:
4141

4242
.. code-block:: protobuf
4343
@@ -55,7 +55,7 @@ All field numbers of 10000 and above are reserved for user-defined extensions an
5555

5656
Enum Naming
5757
------------
58-
The naming of an enum should be camel case. See example below:
58+
The naming of an enum should be PascalCase. See example below:
5959

6060
.. code-block:: protobuf
6161
@@ -70,7 +70,7 @@ The naming of an enum should be camel case. See example below:
7070
7171
Enum Field Naming
7272
------------
73-
The naming of an enum field should be all in upper case. The start should be converted from the enum name camel case to upper case snake case. It is mandatory to add to the first enum field name the postfix ``_UNKNOWN`` and to the second the postfix ``_OTHER``. After that the naming can be decided by the user. It is often mentioned that the value ``_UNKNOWN`` should not be used in a ``GroundTruth`` message as there are now uncertanties by definition in ``the truth``. These values are mostly used in messages like ``SensorData`` where the content is subject to interpretation. See example below:
73+
The naming of an enum field should be all in upper case. The start should be converted from the enum name PascalCase to UPPER_CASE_SNAKE_CASE. It is mandatory to add to the first enum field name the postfix ``_UNKNOWN`` and to the second the postfix ``_OTHER``. After that the naming can be decided by the user. It is often mentioned that the value ``_UNKNOWN`` should not be used in a ``GroundTruth`` message as there are now uncertanties by definition in ``the truth``. These values are mostly used in messages like ``SensorData`` where the content is subject to interpretation. See example below:
7474

7575
.. code-block:: protobuf
7676
@@ -92,12 +92,12 @@ Summary
9292
--------
9393
Here a small summary for the naming conventions:
9494

95-
Messages: camel case
95+
Messages: PascalCase
9696

97-
Message Fields: snake case
97+
Message Fields: snake_case
9898

99-
Enum: camel case
99+
Enum: PascalCase
100100

101-
Enum Fields: upper case, name of enum converted in upper case snake case and then following the specified name
101+
Enum Fields: Name of enum converted in UPPER_CASE_SNAKE_CASE and then following the specified name
102102

103103
After defining the messages do not forget to comment them. See also the `section for commenting <https://opensimulationinterface.github.io/osi-documentation/open-simulation-interface/doc/commenting.html>`_ of fields and messages.

format/OSITrace.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def __init__(self, path=None, type_name="SensorView"):
4444
self.type_name = type_name
4545
self.timestep_count = 0
4646
self.retrieved_scenario_size = 0
47+
self._int_length = len(struct.pack("<L", 0))
4748

4849
def from_file(self, path, type_name="SensorView", max_index=-1, format_type=None):
4950
"""Import a scenario from a file"""
@@ -161,19 +162,18 @@ def get_messages_in_index_range(self, begin, end):
161162
"""
162163
Yield an iterator over messages of indexes between begin and end included.
163164
"""
165+
self.scenario_file.seek(self.message_offsets[begin])
166+
abs_first_offset = self.message_offsets[begin]
167+
abs_last_offset = self.message_offsets[end] \
168+
if end < len(self.message_offsets) \
169+
else self.retrieved_scenario_size
164170

165-
if self.format_type == "separated":
166-
self.scenario_file.seek(self.message_offsets[begin])
167-
abs_first_offset = self.message_offsets[begin]
168-
abs_last_offset = self.message_offsets[end] \
169-
if end < len(self.message_offsets) \
170-
else self.retrieved_scenario_size
171-
172-
rel_message_offsets = [
173-
abs_message_offset - abs_first_offset
174-
for abs_message_offset in self.message_offsets[begin:end]
175-
]
171+
rel_message_offsets = [
172+
abs_message_offset - abs_first_offset
173+
for abs_message_offset in self.message_offsets[begin:end]
174+
]
176175

176+
if self.format_type == "separated":
177177
message_sequence_len = abs_last_offset - \
178178
abs_first_offset - SEPARATOR_LENGTH
179179
serialized_messages_extract = self.scenario_file.read(
@@ -190,25 +190,26 @@ def get_messages_in_index_range(self, begin, end):
190190
yield message
191191

192192
elif self.format_type is None:
193-
self.scenario_file.seek(0)
194-
serialized_message = self.scenario_file.read()
195-
INT_LENGTH = len(struct.pack("<L", 0))
196-
message_length = 0
193+
message_sequence_len = abs_last_offset - abs_first_offset
194+
serialized_messages_extract = self.scenario_file.read(message_sequence_len)
195+
196+
for rel_index, rel_message_offset in enumerate(rel_message_offsets):
197+
rel_begin = rel_message_offset + self._int_length
198+
rel_end = (
199+
rel_message_offsets[rel_index + 1]
200+
if rel_index + 1 < len(rel_message_offsets)
201+
else message_sequence_len
202+
)
197203

198-
i = 0
199-
while i < len(serialized_message):
200204
message = MESSAGES_TYPE[self.type_name]()
201-
message_length = struct.unpack("<L", serialized_message[i:INT_LENGTH+i])[0]
202-
message.ParseFromString(serialized_message[i+INT_LENGTH:i+INT_LENGTH+message_length])
203-
i += message_length + INT_LENGTH
205+
serialized_message = serialized_messages_extract[rel_begin:rel_end]
206+
message.ParseFromString(serialized_message)
204207
yield message
205208

206209
else:
207210
self.scenario_file.close()
208211
raise Exception(f"The defined format {self.format_type} does not exist.")
209212

210-
self.scenario_file.close()
211-
212213
def make_readable(self, name, interval=None, index=None):
213214
self.scenario_file.seek(0)
214215
serialized_message = self.scenario_file.read()
@@ -235,7 +236,7 @@ def make_readable(self, name, interval=None, index=None):
235236

236237
if interval is None and index is not None:
237238
if type(index) == int:
238-
f.write(str(scenario.get_message_by_index(0)))
239+
f.write(str(self.get_message_by_index(0)))
239240
else:
240241
raise Exception("Argument 'index' needs to be of type 'int'")
241242

tests/test_invalid_enum.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_correct_enum_name(self):
4545
saveStatement = statement[matchSep.end():]
4646
statement = statement[:matchSep.end()]
4747

48-
# This section will check camelcase for enums and check enum name?
48+
# This section will check PascalCase for enums and check enum name?
4949

5050
if isEnum is True:
5151
matchName = re.search(r"\b\w[\S:]+\b", statement)
@@ -117,7 +117,7 @@ def test_invalid_enum(self):
117117
saveStatement = statement[matchSep.end():]
118118
statement = statement[:matchSep.end()]
119119

120-
# This section will check camelcase for enums and check enum name?
120+
# This section will check PascalCase for enums and check enum name?
121121

122122
if isEnum is True:
123123
matchName = re.search(r"\b\w[\S:]+\b", statement)

tests/test_osi_trace.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import os
2+
import tempfile
3+
import unittest
4+
5+
from format.OSITrace import OSITrace
6+
from osi3.osi_sensorview_pb2 import SensorView
7+
import struct
8+
9+
10+
class TestOSITrace(unittest.TestCase):
11+
def test_osi_trace(self):
12+
with tempfile.TemporaryDirectory() as tmpdirname:
13+
path_output = os.path.join(tmpdirname, "output.txth")
14+
path_input = os.path.join(tmpdirname, "input.osi")
15+
create_sample(path_input)
16+
17+
trace = OSITrace()
18+
trace.from_file(path=path_input)
19+
trace.make_readable(path_output, index=1)
20+
trace.scenario_file.close()
21+
22+
self.assertTrue(os.path.exists(path_output))
23+
24+
25+
def create_sample(path):
26+
f = open(path, "ab")
27+
sensorview = SensorView()
28+
29+
sv_ground_truth = sensorview.global_ground_truth
30+
sv_ground_truth.version.version_major = 3
31+
sv_ground_truth.version.version_minor = 0
32+
sv_ground_truth.version.version_patch = 0
33+
34+
sv_ground_truth.timestamp.seconds = 0
35+
sv_ground_truth.timestamp.nanos = 0
36+
37+
moving_object = sv_ground_truth.moving_object.add()
38+
moving_object.id.value = 114
39+
40+
# Generate 10 OSI messages for 9 seconds
41+
for i in range(10):
42+
# Increment the time
43+
sv_ground_truth.timestamp.seconds += 1
44+
sv_ground_truth.timestamp.nanos += 100000
45+
46+
moving_object.vehicle_classification.type = 2
47+
48+
moving_object.base.dimension.length = 5
49+
moving_object.base.dimension.width = 2
50+
moving_object.base.dimension.height = 1
51+
52+
moving_object.base.position.x = 0.0 + i
53+
moving_object.base.position.y = 0.0
54+
moving_object.base.position.z = 0.0
55+
56+
moving_object.base.orientation.roll = 0.0
57+
moving_object.base.orientation.pitch = 0.0
58+
moving_object.base.orientation.yaw = 0.0
59+
60+
"""Serialize"""
61+
bytes_buffer = sensorview.SerializeToString()
62+
f.write(struct.pack("<L", len(bytes_buffer)) + bytes_buffer)
63+
64+
f.close()

0 commit comments

Comments
 (0)