Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sort PDUs by CAN message priority #14

Merged
merged 1 commit into from
Feb 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion tsgen/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def generate_intermediate_server(self):
self._sensor_schema = {}
pdus = {}

for id, message in enumerate(self._dbc.messages):
for id, message in enumerate(self.sort_dbc_messages(self._dbc.messages)):

pdus[message.name] = self.create_pdu(message, id)

Expand All @@ -241,6 +241,13 @@ def save_output(file_name, json_data):
save_output(self.SENSORS_FILE_NAME, self._sensor_schema)
save_output(self.SCHEMA_FILE_NAME, self._telemetry_schema)

def sort_dbc_messages(self,
messages: list[cantools.database.can.Message]):
"""Returns a the messages in a DBC, sorted by CAN ID with lowest CAN IDs
first
"""
return sorted(messages, key=lambda x: x.frame_id)

def create_pdu(self,
message: cantools.database.can.Message,
id: int) -> dict:
Expand Down