Skip to content

Commit

Permalink
Merge pull request #92 from ut-issl/main
Browse files Browse the repository at this point in the history
Release v0.1.2
  • Loading branch information
flap1 authored May 23, 2024
2 parents a92e3ba + afec234 commit 1641196
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 9 deletions.
106 changes: 102 additions & 4 deletions c2a_generator/wings_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ def generate(
aobc_csv_path: Optional[Path] = None,
tobc_csv_path: Optional[Path] = None,
mif_csv_path: Optional[Path] = None,
cmd_src: Optional[Path] = None,
el_src: Optional[Path] = None,
eh_src: Optional[Path] = None,
eh_base_id: int = 0,
eh_list: list = [],
) -> None:
data = []
el_list = []
eh_list = []
eh_id = eh_base_id
if aobc_csv_path:
aobc_bc_dict = csv_to_json(aobc_csv_path)
data.append({"obc_name": "AOBC", "bc": aobc_bc_dict, "el": [], "eh": []})
Expand All @@ -51,9 +55,103 @@ def generate(
continue
if not row["name"].strip():
continue
eh_list.append({"name": row["name"], "id": eh_base_id})
eh_base_id += 1
data.append({"obc_name": "MOBC", "bc": [], "el": [], "eh": eh_list})
eh_list.append({"name": row["name"], "id": eh_id})
eh_id += 1
if el_src:
with open(el_src, "r", encoding="utf-8") as src_file:
reader = csv.reader(src_file)
headers = next(reader)
dict_reader = csv.DictReader(src_file, fieldnames=headers)

# CMD_CODEの取得
CMD_LIST = []
if cmd_src:
with open(cmd_src, "r", encoding="utf-8") as cmd_src_file:
cmd_reader = csv.reader(cmd_src_file)
cmd_header = next(cmd_reader)
cmd_dict_reader = csv.DictReader(
cmd_src_file, fieldnames=cmd_header
)
code = 0
for cmd_row in cmd_dict_reader:
if not any(cmd_row):
continue
if cmd_row["enabled"] == "TRUE":
try:
cmd_row["code"] = f"0x{int(code):04X}"
code += 1
if code == 496: # 0x1F0, 0x1F1 を回避する
code += 2
except ValueError:
continue
CMD_LIST.append({"name": cmd_row["name"], "local_id": code})

# EH の取得
EH_LIST = []
if eh_src:
eh_id = eh_base_id
with open(eh_src, "r", encoding="utf-8") as eh_src_file:
eh_reader = csv.reader(eh_src_file)
eh_header = next(eh_reader)
eh_dict_reader = csv.DictReader(eh_src_file, fieldnames=eh_header)
for eh_row in eh_dict_reader:
if not any(eh_row):
continue
EH_LIST.append({"name": eh_row["name"], "local_id": int(eh_id)})
eh_id += 1

# EL の取得
EL_LIST = []
with open(el_src, "r", encoding="utf-8") as el_src_file:
el_reader = csv.reader(el_src_file)
el_header = next(el_reader)
el_dict_reader = csv.DictReader(el_src_file, fieldnames=el_header)
for el_row in el_dict_reader:
if not el_row["group_id"].strip():
continue
EL_LIST.append(
{
"name": el_row["group_name"],
"local_id": int(el_row["group_id"]),
}
)

last_el_dict = {}
for row in dict_reader:
if not any(row):
continue
if row["group_name"].strip():
if last_el_dict:
el_list.append(last_el_dict)
last_el_dict = {
"name": row["group_name"],
"group_id": int(row["group_id"]),
"type": [],
}
if row["local_name"].strip():
assert last_el_dict, "local_name must be under group_name"
if row["local_id"] == "uint32_t":
continue
if row["local_id"] in ["EL_GROUP"]:
for EL in EL_LIST:
last_el_dict["type"].append(EL)
elif row["local_id"] == "EH_RULE_ID":
for EH in EH_LIST:
last_el_dict["type"].append(EH)
elif row["local_id"] == "CMD_CODE":
for CMD in CMD_LIST:
last_el_dict["type"].append(CMD)
else:
last_el_dict["type"].append(
{
"name": row["local_name"],
"local_id": int(row["local_id"]),
}
)
else:
if last_el_dict:
el_list.append(last_el_dict)
data.append({"obc_name": "MOBC", "bc": [], "el": el_list, "eh": eh_list})
bcid = 0
for src_path, bcid_base in bct_src:
if bcid_base is not None:
Expand Down
10 changes: 6 additions & 4 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
c2a_generator.eh_rules_h.generate(
root_path / "design/eh.csv",
root_path / "src/src_user/Settings/System/EventHandlerRules/event_handler_rules.h",
base_id=9
base_id=9,
)
c2a_generator.eh_rules_c.generate(
root_path / "design/eh.csv",
Expand All @@ -33,7 +33,7 @@
#include "../../../Applications/UserDefined/Mission/mission_sequence.h"
#include "../../../Applications/UserDefined/Mission/rsi_sun_angle.h"
#include "../../../Applications/UserDefined/Com/comm_fdir.h"
"""
""",
)

# cmd
Expand Down Expand Up @@ -131,15 +131,17 @@
bct_src,
root_path
/ "../../../wings/aspnetapp/WINGS/ClientApp/src/assets/alias/c2a_onglai.json",
el_src=root_path / "design/el.csv",
cmd_src=root_path / "design/cmd.csv",
eh_src=root_path / "design/eh.csv",
eh_base_id=9,
eh_list=[],
)

c2a_generator.wings_json.generate(
bct_src,
root_path / "database/c2a_onglai.json",
el_src=root_path / "design/el.csv",
cmd_src=root_path / "design/cmd.csv",
eh_src=root_path / "design/eh.csv",
eh_base_id=9,
eh_list=[],
)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "c2a_generator"
version = "0.1.1"
version = "0.1.2"
description = "Add your description here"
authors = [
{ name = "flap1", email = "[email protected]" }
Expand Down

0 comments on commit 1641196

Please sign in to comment.