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

Tlm Cmd DB の UTF-8 化 にともなう更新 #32

Merged
merged 4 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ $ python GenerateC2ACode.py
"db_prefix" : "SAMPLE_MOBC",
# TLM ID の定義域
"tlm_id_range" : ["0x00", "0x100"],
# 入力 Tlm Cmd DB のエンコーディング
"input_file_encoding" : "utf-8",
# 出力ファイルのエンコーディング
"output_file_encoding" : "utf-8",
# MOBCか?(他のOBCのtlm/cmdを取りまとめるか?) 0/1
Expand All @@ -47,6 +49,7 @@ $ python GenerateC2ACode.py
"is_enable" : 1,
"db_prefix" : "SAMPLE_AOBC",
"tlm_id_range" : ["0x90", "0xc0"],
"input_file_encoding" : "utf-8",
# DBがあるディレクトリへのパス(絶対でも相対でもOK)
"db_path" : "../../c2a_sample_aobc/src/src_user/Settings/TlmCmd/DataBase/",
# MOBC で保持するテレメの TLM ID の最大値(=テレメ種類数)
Expand All @@ -63,6 +66,7 @@ $ python GenerateC2ACode.py
"is_enable" : 1,
"db_prefix" : "SAMPLE_TOBC",
"tlm_id_range" : ["0xc0", "0xf0"],
"input_file_encoding" : "utf-8",
# DBがあるディレクトリへのパス(絶対でも相対でもOK)
"db_path" : ""../../c2a_sample_tobc/src/src_user/Settings/TlmCmd/DataBase/",
# MOBC で保持するテレメの TLM ID の最大値(=テレメ種類数)
Expand Down
28 changes: 20 additions & 8 deletions my_mod/load_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
def LoadCmdDb(settings):
cmd_db_path = settings["c2a_root_dir"] + r"src_user/Settings/TlmCmd/DataBase/CMD_DB/"

sgc_db, bct_db = LoadCmdCSV_(cmd_db_path, settings["db_prefix"])
sgc_db, bct_db = LoadCmdCSV_(
cmd_db_path, settings["db_prefix"], settings["input_file_encoding"]
)

other_obc_dbs = {}
if settings["is_main_obc"]:
Expand All @@ -27,14 +29,14 @@ def LoadCmdDb(settings):
return {"sgc": sgc_db, "bct": bct_db, "other_obc": other_obc_dbs}


def LoadCmdCSV_(cmd_db_path, db_prefix):
def LoadCmdCSV_(cmd_db_path, db_prefix, encoding):
sgc_db_path = cmd_db_path + db_prefix + "_CMD_DB_CMD_DB.csv" # single cmd
bct_db_path = cmd_db_path + db_prefix + "_CMD_DB_BCT.csv" # block cmd table

with open(sgc_db_path, mode="r", encoding="shift_jis") as fh:
with open(sgc_db_path, mode="r", encoding=encoding) as fh:
reader = csv.reader(fh)
sgc_db = [row for row in reader]
with open(bct_db_path, mode="r", encoding="shift_jis") as fh:
with open(bct_db_path, mode="r", encoding=encoding) as fh:
reader = csv.reader(fh)
bct_db = [row for row in reader]

Expand All @@ -46,7 +48,12 @@ def LoadTlmDb(settings):
settings["c2a_root_dir"] + r"src_user/Settings/TlmCmd/DataBase/TLM_DB/calced_data/"
)

tlm_db = LoadTlmCSV_(tlm_db_path, settings["db_prefix"], settings["tlm_id_range"])
tlm_db = LoadTlmCSV_(
tlm_db_path,
settings["db_prefix"],
settings["tlm_id_range"],
settings["input_file_encoding"],
)

other_obc_dbs = {}
if settings["is_main_obc"]:
Expand All @@ -57,7 +64,7 @@ def LoadTlmDb(settings):
return {"tlm": tlm_db, "other_obc": other_obc_dbs}


def LoadTlmCSV_(tlm_db_path, db_prefix, tlm_id_range):
def LoadTlmCSV_(tlm_db_path, db_prefix, tlm_id_range, encoding):
tlm_names = [file for file in os.listdir(tlm_db_path) if file.endswith(".csv")]
regex = r"^" + db_prefix + "_TLM_DB_"
tlm_names = [re.sub(regex, "", file) for file in tlm_names]
Expand All @@ -69,7 +76,7 @@ def LoadTlmCSV_(tlm_db_path, db_prefix, tlm_id_range):

for tlm_name in tlm_names:
tlm_sheet_path = tlm_db_path + db_prefix + "_TLM_DB_" + tlm_name + ".csv"
with open(tlm_sheet_path, mode="r", encoding="shift_jis") as fh:
with open(tlm_sheet_path, mode="r", encoding=encoding) as fh:
reader = csv.reader(fh)
sheet = [row for row in reader]
# pprint.pprint(sheet)
Expand Down Expand Up @@ -109,7 +116,11 @@ def LoadOtherObcCmd_(settings):
if not settings["other_obc_data"][i]["is_enable"]:
continue
cmd_db_path = settings["other_obc_data"][i]["db_path"] + r"CMD_DB/"
sgc_db, bct_db = LoadCmdCSV_(cmd_db_path, settings["other_obc_data"][i]["db_prefix"])
sgc_db, bct_db = LoadCmdCSV_(
cmd_db_path,
settings["other_obc_data"][i]["db_prefix"],
settings["other_obc_data"][i]["input_file_encoding"],
)
# other_obc_dbs.append(sgc_db)
other_obc_dbs[settings["other_obc_data"][i]["name"]] = sgc_db
# print(i)
Expand All @@ -131,6 +142,7 @@ def LoadOtherObcTlm(settings):
tlm_db_path,
settings["other_obc_data"][i]["db_prefix"],
settings["other_obc_data"][i]["tlm_id_range"],
settings["other_obc_data"][i]["input_file_encoding"],
)
other_obc_dbs[settings["other_obc_data"][i]["name"]] = tlm_db

Expand Down
3 changes: 3 additions & 0 deletions settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"c2a_root_dir" : "../../c2a/src/",
"db_prefix" : "SAMPLE_MOBC",
"tlm_id_range" : ["0x00", "0x100"],
"input_file_encoding" : "utf-8",
"output_file_encoding" : "utf-8",
"is_main_obc" : 1,
"other_obc_data" : [
Expand All @@ -10,6 +11,7 @@
"is_enable" : 1,
"db_prefix" : "SAMPLE_AOBC",
"tlm_id_range" : ["0x90", "0xc0"],
"input_file_encoding" : "utf-8",
"db_path" : "C:/c2a_sample_aobc/src/src_user/Settings/TlmCmd/DataBase/",
"max_tlm_num" : 256,
"driver_path" : "Aocs/",
Expand All @@ -22,6 +24,7 @@
"is_enable" : 1,
"db_prefix" : "SAMPLE_TOBC",
"tlm_id_range" : ["0xc0", "0xf0"],
"input_file_encoding" : "utf-8",
"db_path" : "C:/c2a_sample_tobc/src/src_user/Settings/TlmCmd/DataBase/",
"max_tlm_num" : 256,
"driver_path" : "Thermal/",
Expand Down