-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from UOA-FSAE/main
merge latest main for definitions
- Loading branch information
Showing
4 changed files
with
91 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# This workflow will install Python dependencies, run tests and lint with a single version of Python | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python | ||
|
||
name: Python application | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python 3.10 | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: "3.10" | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pyyaml | ||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | ||
- name: Run validator | ||
run: | | ||
python validator.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
can: | ||
- name: "can1" | ||
baudrate: 1000 | ||
- name: "can2" | ||
baudrate: 1000 | ||
- name: "can3" | ||
baudrate: 250 | ||
|
||
messages: | ||
- ID: 0x103 | ||
can_line: "can3" | ||
message: "AMSError" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
""" Validates definitions | ||
Checks to see if the names of all the messages in definitions are the correct name. | ||
""" | ||
import yaml | ||
|
||
|
||
def get_all_can_message_names() -> list: | ||
with open("fs-common-protobuf/can.proto", "r") as file: | ||
message_names = [] | ||
|
||
for line in file: | ||
line_parts = line.split(" ") | ||
if line_parts[0] == "message": | ||
message_names.append(line_parts[1]) | ||
|
||
return message_names | ||
|
||
|
||
def get_all_defined_messages() -> list: | ||
with open("definitions.yml", "r") as file: | ||
definitions = yaml.safe_load(file) | ||
message_names = [message['message'] for message in definitions['messages']] | ||
|
||
return message_names | ||
|
||
|
||
if __name__ == "__main__": | ||
can_message_names = get_all_can_message_names() | ||
print(f"all protobuf can message names = {can_message_names}") | ||
|
||
definition_message_names = get_all_defined_messages() | ||
print(f"all definition message names requested = {definition_message_names}") | ||
|
||
for definition_message_name in definition_message_names: | ||
if definition_message_name not in can_message_names: | ||
raise ValueError(f"{definition_message_name} not defined in can proto. \n" | ||
f"list of available message names are {can_message_names}") |