Skip to content

Commit

Permalink
Generate decode and encode from JSON over YAML, (#60)
Browse files Browse the repository at this point in the history
* Added my format script to gitignore

* Experimental handling of CAN Error Frame

* Changes

* Now using JSON over YAML

* Handle Remote frame

* Set CAN Socket to accept errors

* SocketOptions now included

* Updated submodule ref

* Fixed ref?

---------

Co-authored-by: Jack Rubacha <[email protected]>
  • Loading branch information
harrison-e and jr1221 authored Oct 4, 2024
1 parent 5304a72 commit 547a8da
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "Embedded-Base"]
path = Embedded-Base
url = https://github.com/Northeastern-Electric-Racing/Embedded-Base
url = ../Embedded-Base
31 changes: 16 additions & 15 deletions calypsogen.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import importlib.util
import json
import sys

# Full path to the directory containing the cangen module
Expand All @@ -16,7 +17,7 @@
cangen = importlib.util.module_from_spec(spec)
spec.loader.exec_module(cangen)

decode_data = open("./src/decode_data.rs", "w")
decode_data = open("./src/decode_data.rs", "w") or field["send"]
decode_master_mapping = open("./src/decode_master_mapping.rs", "w")

encode_data = open("./src/encode_data.rs", "w")
Expand All @@ -25,23 +26,23 @@
format_data = open("./src/format_data.rs", "w")


bms_messages = cangen.YAMLParser().parse(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/bms.yaml", "r"))
mpu_messages = cangen.YAMLParser().parse(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/mpu.yaml", "r"))
wheel_messages = cangen.YAMLParser().parse(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/wheel.yaml", "r"))
dti_messages = cangen.YAMLParser().parse(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/dti.yaml", "r"))
calypso_messages = cangen.YAMLParser().parse(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/calypso_cmd.yaml", "r"))
charger_messages = cangen.YAMLParser().parse(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/charger.yaml", "r"))
msb_messages = cangen.YAMLParser().parse(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/msb.yaml", "r"))
bms_messages = json.load(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/bms.json", "r"))
mpu_messages = json.load(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/mpu.json", "r"))
wheel_messages = json.load(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/wheel.json", "r"))
dti_messages = json.load(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/dti.json", "r"))
calypso_messages = json.load(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/calypso_cmd.json", "r"))
charger_messages = json.load(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/charger.json", "r"))
msb_messages = json.load(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/msb.json", "r"))


bms_messages.msgs.extend(mpu_messages.msgs)
bms_messages.msgs.extend(wheel_messages.msgs)
bms_messages.msgs.extend(dti_messages.msgs)
bms_messages.msgs.extend(charger_messages.msgs)
bms_messages.msgs.extend(calypso_messages.msgs)
bms_messages.msgs.extend(msb_messages.msgs)
bms_messages.extend(mpu_messages)
bms_messages.extend(wheel_messages)
bms_messages.extend(dti_messages)
bms_messages.extend(charger_messages)
bms_messages.extend(calypso_messages)
bms_messages.extend(msb_messages)

result = cangen.RustSynth().parse_messages(bms_messages.msgs)
result = cangen.RustSynthFromJSON().parse_messages(bms_messages)

decode_data.write(result.decode_data)
decode_data.close()
Expand Down

0 comments on commit 547a8da

Please sign in to comment.