From 39e91ded60a628a28e950b780cd8830e88679a53 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 10 Nov 2020 07:10:30 +0000 Subject: [PATCH 001/141] Initial commit --- README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 000000000..08745d756 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# TlmCmdCodeGenerator + +TlmCmdDBからC2Aのコードを生成するためのスクリプト \ No newline at end of file From 7d2366c3b1638596141465cc7d8c446ee7742063 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 10 Nov 2020 16:13:54 +0900 Subject: [PATCH 002/141] add readme --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 08745d756..50cfffcbc 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,13 @@ # TlmCmdCodeGenerator +## これはなに? +TlmCmdDBからC2Aのコードを生成するためのスクリプト + +## 開発方針 +そこまで込み入った開発はしないので, + +- master +- develop + +ブランチのみ作成し,master pushは禁止する. + -TlmCmdDBからC2Aのコードを生成するためのスクリプト \ No newline at end of file From f6b6a65a2232db700686b909a7478e7d58e65bdb Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 10 Nov 2020 16:28:58 +0900 Subject: [PATCH 003/141] add empty files --- GenerateC2ACode.py | 0 requirements.txt | 0 settings.json | 0 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 GenerateC2ACode.py create mode 100644 requirements.txt create mode 100644 settings.json diff --git a/GenerateC2ACode.py b/GenerateC2ACode.py new file mode 100644 index 000000000..e69de29bb diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000..e69de29bb diff --git a/settings.json b/settings.json new file mode 100644 index 000000000..e69de29bb From 2628fbb577e301709542999a074c97e4815ca3e9 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sat, 14 Nov 2020 15:00:16 +0900 Subject: [PATCH 004/141] add code of load csv and generate cmd def --- GenerateC2ACode.py | 207 +++++++++++++++++++++++++++++++++++++++++++++ settings.json | 5 ++ 2 files changed, 212 insertions(+) diff --git a/GenerateC2ACode.py b/GenerateC2ACode.py index e69de29bb..f4b924a41 100644 --- a/GenerateC2ACode.py +++ b/GenerateC2ACode.py @@ -0,0 +1,207 @@ +# coding: UTF-8 +""" +python 3.7以上を要求 +""" + +import json +import csv +import os +import re # 正規表現 +import pprint + +# import sys +# import os +# import os.path +# import msvcrt # Enter不要な入力用 +# import subprocess + + +# 環境変数 +DEBUG = 0 +# 0 : Release +# 1 : all +SETTING_FILE_PATH = "settings.json" + + +def main(): + with open(SETTING_FILE_PATH, mode='r') as fh: + settings = json.load(fh) + # print(settings["c2a_root_dir"]); + + cmd_db = LoadCmdCSV(settings) + tlm_db = LoadTlmCSV(settings) + # pprint.pprint(cmd_db) + # pprint.pprint(tlm_db) + # print(tlm_db) + + GenerateCmdDef(settings, cmd_db['sgc']) + GenerateBctDef(settings, cmd_db['bct']) + + + + +def LoadCmdCSV(settings): + cmd_db_path = settings["c2a_root_dir"] + r"src_user/Settings/CmdTlm/DataBase/CMD_DB/" + sgc_db_path = cmd_db_path + settings["db_prefix"] + "_CMD_DB_CMD_DB.csv" # single cmd + bct_db_path = cmd_db_path + settings["db_prefix"] + "_CMD_DB_BCT.csv" # block cmd table + + with open(sgc_db_path, mode='r', encoding='shift_jis') 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: + reader = csv.reader(fh) + bct_db = [row for row in reader] + + # print(sgc_db) + # print(bct_db) + return {'sgc': sgc_db, 'bct': bct_db} + + +def LoadTlmCSV(settings): + tlm_db_path = settings["c2a_root_dir"] + r"src_user/Settings/CmdTlm/DataBase/TLM_DB/calced_data/" + + tlm_names = [file for file in os.listdir(tlm_db_path) if file.endswith(".csv")] + regex = r"^" + settings["db_prefix"] + "_TLM_DB_" + tlm_names = [re.sub(regex, "", file) for file in tlm_names] + tlm_names = [re.sub(".csv$", "", file) for file in tlm_names] + # pprint.pprint(tlm_names) + # print(len(tlm_names)) + + tlm_db = [] + + for tlm_name in tlm_names: + tlm_sheet_path = tlm_db_path + settings["db_prefix"] + "_TLM_DB_" + tlm_name + ".csv" + with open(tlm_sheet_path, mode='r', encoding='shift_jis') as fh: + reader = csv.reader(fh) + sheet = [row for row in reader] + # pprint.pprint(sheet) + # print(sheet) + tlm_id = sheet[1][2] # テレメIDを取得.マジックナンバーで指定してしまってる. + tlm_db.append({'tlm_id': tlm_id, 'tlm_name': tlm_name, 'data': sheet}) + # tlm_db.append({'tlm_id': tlm_id, 'tlm_name': tlm_name, 'data': 1}) + + tlm_db.sort(key=lambda x: x['tlm_id']) + return tlm_db; + + +def GenerateCmdDef(settings, sgc_db): + output_file_path = settings["c2a_root_dir"] + r"src_user/CmdTlm/" + output_file_name_base = "CommandDefinitions" + + DATA_SART_ROW = 3 + + body_c = "" + body_h = "" + # " cmd_table_[Cmd_CODE_NOP].cmd_func = Cmd_NOP;" + # " Cmd_CODE_NOP = 0x0000," + for i in range(DATA_SART_ROW, len(sgc_db)): + if sgc_db[i][0] != "": # Comment + continue + if sgc_db[i][0] == "" and sgc_db[i][1] == "": # CommentもNameも空白なら打ち切り + break + # print(sgc_db[i][1]) + cmd_name = sgc_db[i][1] + cmd_code = cmd_name.replace("Cmd_", "Cmd_CODE_") + # print(cmd_name) + # print(cmd_code) + body_c += " cmd_table_[" + cmd_code + "].cmd_func = " + cmd_name + ";\n" + body_h += " " + cmd_code + " = " + sgc_db[i][3] + ",\n" + + output_c = "" + output_h = "" + + output_c += ''' +#pragma section REPRO +/** + * @file CommandDefinitions.c + * @brief コマンド定義 + * @author 鈴本 遼 + * @date 2020/08/23 + */ +#include "CommandDefinitions.h" +#include "CommandSource.h" + +/* +This pattern is a "separator". +This should not be changed. +This should not be used in other places. +*/ +//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## + +void CA_load_cmd_table(CmdInfo cmd_table_[CMD_MAX_CMDS]) +{ +'''[1:] # 最初の改行を除く + + output_c += body_c + + output_c += ''' +} + +//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## +/* +This pattern is a "separator". +This should not be changed. +This should not be used in other places. +*/ + +#pragma section +'''[1:] # 最初の改行を除く + + + output_h += ''' +/** + * @file CommandDefinitions.h + * @brief コマンド定義 + * @author 鈴本 遼 + * @date 2020/08/23 + */ +#ifndef COMMAND_DEFINITIONS_H_ +#define COMMAND_DEFINITIONS_H_ + +#include "../../src_core/CmdTlm/CommandAnalyze.h" + +typedef enum +{ +/* +This pattern is a "separator". +This should not be changed. +This should not be used in other places. +*/ +//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## + +'''[1:] # 最初の改行を除く + + output_h += body_h + + output_h += ''' + +//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## +/* +This pattern is a "separator". +This should not be changed. +This should not be used in other places. +*/ + Cmd_ID_MAX +} CmdCode; + +void CA_load_cmd_table(CmdInfo cmd_table_[CMD_MAX_CMDS]); + +#endif +'''[1:] # 最初の改行を除く + + with open(output_file_path + output_file_name_base + ".c", mode='w', encoding='shift_jis') as fh: + fh.write(output_c) + with open(output_file_path + output_file_name_base + ".h", mode='w', encoding='shift_jis') as fh: + fh.write(output_h) + + +def GenerateBctDef(settings, bct_db): + output_file_path = settings["c2a_root_dir"] + r"src_user/CmdTlm/" + output_file_name = "BlockCommandDefinitions.h" + + +if __name__ == '__main__': + main() + + + diff --git a/settings.json b/settings.json index e69de29bb..29f027182 100644 --- a/settings.json +++ b/settings.json @@ -0,0 +1,5 @@ +{ + "c2a_root_dir" : "../../c2a_user_oss/SH7254R_C2A/", + "db_prefix" : "ISSL6U_MOBC", + "is_generated_sib" : 0 +} From e2bc4d8715c012152ec72261eda5445a6b2f1b19 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sat, 14 Nov 2020 15:34:18 +0900 Subject: [PATCH 005/141] add code of bct def --- GenerateC2ACode.py | 55 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/GenerateC2ACode.py b/GenerateC2ACode.py index f4b924a41..8545fb1b6 100644 --- a/GenerateC2ACode.py +++ b/GenerateC2ACode.py @@ -90,6 +90,8 @@ def GenerateCmdDef(settings, sgc_db): DATA_SART_ROW = 3 + output_c = "" + output_h = "" body_c = "" body_h = "" # " cmd_table_[Cmd_CODE_NOP].cmd_func = Cmd_NOP;" @@ -107,9 +109,6 @@ def GenerateCmdDef(settings, sgc_db): body_c += " cmd_table_[" + cmd_code + "].cmd_func = " + cmd_name + ";\n" body_h += " " + cmd_code + " = " + sgc_db[i][3] + ",\n" - output_c = "" - output_h = "" - output_c += ''' #pragma section REPRO /** @@ -199,6 +198,56 @@ def GenerateBctDef(settings, bct_db): output_file_path = settings["c2a_root_dir"] + r"src_user/CmdTlm/" output_file_name = "BlockCommandDefinitions.h" + DATA_SART_ROW = 2 + + output_h = "" + body_h = "" + # " cmd_table_[Cmd_CODE_NOP].cmd_func = Cmd_NOP;" + # " Cmd_CODE_NOP = 0x0000," + for i in range(DATA_SART_ROW, len(bct_db)): + comment = bct_db[i][0] + name = bct_db[i][1] + bc_id = bct_db[i][3] + + if comment == "" and name == "": # CommentもNameも空白なら打ち切り + break + + if comment == "**": # New Line Comment + body_h += "\n // " + name + "\n" + elif comment != "": # Comment + body_h += " // " + name + "\n" + else: + # " BC_SL_INITIAL_TO_INITIAL = 0," + body_h += " " + name + " = " + bc_id +",\n" + + output_h += ''' +/** + * @file BlockCommandDefinitions.h + * @brief ブロックコマンド定義 + * @author 鈴本 遼 + * @date 2020/11/14 + */ +#ifndef BLOCK_COMMAND_DEFINITIONS_H_ +#define BLOCK_COMMAND_DEFINITIONS_H_ + +// 登録されるBlockCommandTableのblock番号を規定 +typedef enum +{ +'''[1:] # 最初の改行を除く + + output_h += body_h + + output_h += ''' +} BC_DEFAULTS; + +void BC_load_defaults(void); + +#endif // BLOCK_COMMAND_DEFINISIONS_H_ +'''[1:] # 最初の改行を除く + + with open(output_file_path + output_file_name, mode='w', encoding='shift_jis') as fh: + fh.write(output_h) + if __name__ == '__main__': main() From 1983248ed5ca5cb631022fb1bfd5c6b84666ce7a Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sat, 14 Nov 2020 15:51:47 +0900 Subject: [PATCH 006/141] divide output source and code gen source --- GenerateC2ACode.py | 104 +++++++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 45 deletions(-) diff --git a/GenerateC2ACode.py b/GenerateC2ACode.py index 8545fb1b6..437a8954f 100644 --- a/GenerateC2ACode.py +++ b/GenerateC2ACode.py @@ -36,8 +36,7 @@ def main(): GenerateCmdDef(settings, cmd_db['sgc']) GenerateBctDef(settings, cmd_db['bct']) - - + GenerateTlmDef(settings, tlm_db) def LoadCmdCSV(settings): @@ -90,8 +89,6 @@ def GenerateCmdDef(settings, sgc_db): DATA_SART_ROW = 3 - output_c = "" - output_h = "" body_c = "" body_h = "" # " cmd_table_[Cmd_CODE_NOP].cmd_func = Cmd_NOP;" @@ -109,7 +106,44 @@ def GenerateCmdDef(settings, sgc_db): body_c += " cmd_table_[" + cmd_code + "].cmd_func = " + cmd_name + ";\n" body_h += " " + cmd_code + " = " + sgc_db[i][3] + ",\n" - output_c += ''' + OutputCmdDefC(output_file_path + output_file_name_base + ".c", body_c) + OutputCmdDefH(output_file_path + output_file_name_base + ".h", body_h) + +def GenerateBctDef(settings, bct_db): + output_file_path = settings["c2a_root_dir"] + r"src_user/CmdTlm/" + output_file_name = "BlockCommandDefinitions.h" + + DATA_SART_ROW = 2 + + body_h = "" + # " cmd_table_[Cmd_CODE_NOP].cmd_func = Cmd_NOP;" + # " Cmd_CODE_NOP = 0x0000," + for i in range(DATA_SART_ROW, len(bct_db)): + comment = bct_db[i][0] + name = bct_db[i][1] + bc_id = bct_db[i][3] + + if comment == "" and name == "": # CommentもNameも空白なら打ち切り + break + + if comment == "**": # New Line Comment + body_h += "\n // " + name + "\n" + elif comment != "": # Comment + body_h += " // " + name + "\n" + else: + # " BC_SL_INITIAL_TO_INITIAL = 0," + body_h += " " + name + " = " + bc_id +",\n" + + OutputBctDef(output_file_path + output_file_name, body_h) + + +def GenerateTlmDef(settings, tlm_db): + pass + + +def OutputCmdDefC(file_path, body): + output = "" + output += ''' #pragma section REPRO /** * @file CommandDefinitions.c @@ -131,9 +165,9 @@ def GenerateCmdDef(settings, sgc_db): { '''[1:] # 最初の改行を除く - output_c += body_c + output += body - output_c += ''' + output += ''' } //##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## @@ -147,7 +181,13 @@ def GenerateCmdDef(settings, sgc_db): '''[1:] # 最初の改行を除く - output_h += ''' + with open(file_path, mode='w', encoding='shift_jis') as fh: + fh.write(output) + + +def OutputCmdDefH(file_path, body): + output = "" + output += ''' /** * @file CommandDefinitions.h * @brief コマンド定義 @@ -170,9 +210,9 @@ def GenerateCmdDef(settings, sgc_db): '''[1:] # 最初の改行を除く - output_h += body_h + output += body - output_h += ''' + output += ''' //##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## /* @@ -188,39 +228,13 @@ def GenerateCmdDef(settings, sgc_db): #endif '''[1:] # 最初の改行を除く - with open(output_file_path + output_file_name_base + ".c", mode='w', encoding='shift_jis') as fh: - fh.write(output_c) - with open(output_file_path + output_file_name_base + ".h", mode='w', encoding='shift_jis') as fh: - fh.write(output_h) + with open(file_path, mode='w', encoding='shift_jis') as fh: + fh.write(output) -def GenerateBctDef(settings, bct_db): - output_file_path = settings["c2a_root_dir"] + r"src_user/CmdTlm/" - output_file_name = "BlockCommandDefinitions.h" - - DATA_SART_ROW = 2 - - output_h = "" - body_h = "" - # " cmd_table_[Cmd_CODE_NOP].cmd_func = Cmd_NOP;" - # " Cmd_CODE_NOP = 0x0000," - for i in range(DATA_SART_ROW, len(bct_db)): - comment = bct_db[i][0] - name = bct_db[i][1] - bc_id = bct_db[i][3] - - if comment == "" and name == "": # CommentもNameも空白なら打ち切り - break - - if comment == "**": # New Line Comment - body_h += "\n // " + name + "\n" - elif comment != "": # Comment - body_h += " // " + name + "\n" - else: - # " BC_SL_INITIAL_TO_INITIAL = 0," - body_h += " " + name + " = " + bc_id +",\n" - - output_h += ''' +def OutputBctDef(file_path, body): + output = "" + output += ''' /** * @file BlockCommandDefinitions.h * @brief ブロックコマンド定義 @@ -235,9 +249,9 @@ def GenerateBctDef(settings, bct_db): { '''[1:] # 最初の改行を除く - output_h += body_h + output += body - output_h += ''' + output += ''' } BC_DEFAULTS; void BC_load_defaults(void); @@ -245,8 +259,8 @@ def GenerateBctDef(settings, bct_db): #endif // BLOCK_COMMAND_DEFINISIONS_H_ '''[1:] # 最初の改行を除く - with open(output_file_path + output_file_name, mode='w', encoding='shift_jis') as fh: - fh.write(output_h) + with open(file_path, mode='w', encoding='shift_jis') as fh: + fh.write(output) if __name__ == '__main__': From 984ae11dd11bfd67aa8f3bbcb53eae95102820b2 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sat, 14 Nov 2020 17:10:15 +0900 Subject: [PATCH 007/141] add code of tlm def --- GenerateC2ACode.py | 197 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 189 insertions(+), 8 deletions(-) diff --git a/GenerateC2ACode.py b/GenerateC2ACode.py index 437a8954f..e6b894bcb 100644 --- a/GenerateC2ACode.py +++ b/GenerateC2ACode.py @@ -8,8 +8,8 @@ import os import re # 正規表現 import pprint +import sys -# import sys # import os # import os.path # import msvcrt # Enter不要な入力用 @@ -94,21 +94,25 @@ def GenerateCmdDef(settings, sgc_db): # " cmd_table_[Cmd_CODE_NOP].cmd_func = Cmd_NOP;" # " Cmd_CODE_NOP = 0x0000," for i in range(DATA_SART_ROW, len(sgc_db)): - if sgc_db[i][0] != "": # Comment - continue - if sgc_db[i][0] == "" and sgc_db[i][1] == "": # CommentもNameも空白なら打ち切り + comment = sgc_db[i][0] + name = sgc_db[i][1] + cmd_id = sgc_db[i][3] + if comment == "" and name == "": # CommentもNameも空白なら打ち切り break - # print(sgc_db[i][1]) - cmd_name = sgc_db[i][1] + if comment != "": # Comment + continue + # print(name) + cmd_name = name cmd_code = cmd_name.replace("Cmd_", "Cmd_CODE_") # print(cmd_name) # print(cmd_code) body_c += " cmd_table_[" + cmd_code + "].cmd_func = " + cmd_name + ";\n" - body_h += " " + cmd_code + " = " + sgc_db[i][3] + ",\n" + body_h += " " + cmd_code + " = " + cmd_id + ",\n" OutputCmdDefC(output_file_path + output_file_name_base + ".c", body_c) OutputCmdDefH(output_file_path + output_file_name_base + ".h", body_h) + def GenerateBctDef(settings, bct_db): output_file_path = settings["c2a_root_dir"] + r"src_user/CmdTlm/" output_file_name = "BlockCommandDefinitions.h" @@ -138,7 +142,95 @@ def GenerateBctDef(settings, bct_db): def GenerateTlmDef(settings, tlm_db): - pass + output_file_path = settings["c2a_root_dir"] + r"src_user/CmdTlm/" + output_file_name_base = "TelemetryDefinitions" + + DATA_SART_ROW = 7 + + body_c = "" + body_h = "" + + # "static int OBC_(unsigned char* contents, int max_len);" + # " OBC_ID = 0x00," + for tlm in tlm_db: + body_c += "static int " + tlm['tlm_name'] + "_(unsigned char* contents, int max_len);\n" + body_h += " " + tlm['tlm_name'] + "_ID = " + tlm['tlm_id'] + ",\n" + + body_c += "\n" + body_c += "void TF_load_tlm_table(TlmInfo tlm_table_[TLM_MAX_TLMS])\n" + body_c += "{\n" + for tlm in tlm_db: + # " tlm_table_[OBC_ID].tlm_func = OBC_;" + body_c += " tlm_table_[" + tlm['tlm_name'] + "_ID].tlm_func = " + tlm['tlm_name'] + "_;\n" + body_c += "}\n" + + for tlm in tlm_db: + func_code = "" + max_pos = "" + for i in range(DATA_SART_ROW, len(tlm['data'])): + comment = tlm['data'][i][0] + name = tlm['data'][i][1] + var_type = tlm['data'][i][2] + code = tlm['data'][i][3] + pos = tlm['data'][i][4] + if comment == "" and name == "": # CommentもNameも空白なら打ち切り + break + if comment != "": + continue + if name == "": + continue + if var_type == "": + continue + if code == "": + continue + if pos == "": + continue + + code = code.replace("@@", ",") + func_code += " " + if var_type == "int8_t": + func_code += "copy_i8_" + max_pos = int(pos) + 1 + elif var_type == "int16_t": + func_code += "copy_i16_" + max_pos = int(pos) + 2 + elif var_type == "int32_t": + func_code += "copy_i32_" + max_pos = int(pos) + 4 + elif var_type == "uint8_t": + func_code += "copy_u8_" + max_pos = int(pos) + 1 + elif var_type == "uint16_t": + func_code += "copy_u16_" + max_pos = int(pos) + 2 + elif var_type == "uint32_t": + func_code += "copy_u32_" + max_pos = int(pos) + 4 + elif var_type == "float": + func_code += "copy_float_" + max_pos = int(pos) + 4 + elif var_type == "double": + func_code += "copy_double_" + max_pos = int(pos) + 8 + else: + print("Error: Tlm DB Err at " + tlm['tlm_name'], file=sys.stderr) + sys.exit(1) + func_code += "(&contents[" + pos + "], " + code + ");\n" + + body_c += "\n" + body_c += "static int " + tlm['tlm_name'] + "_(unsigned char* contents, int max_len)\n" + body_c += "{\n" + body_c += "\n" + body_c += " if( " + str(max_pos) + " > max_len) { return TLM_TOO_SHORT_LEN; }\n" + body_c += "\n" + body_c += func_code + body_c += "\n" + body_c += " return " + str(max_pos) + ";\n" + body_c += "}\n" + + OutputTlmDefC(output_file_path + output_file_name_base + ".c", body_c) + OutputTlmDefH(output_file_path + output_file_name_base + ".h", body_h) + def OutputCmdDefC(file_path, body): @@ -263,6 +355,95 @@ def OutputBctDef(file_path, body): fh.write(output) +def OutputTlmDefC(file_path, body): + output = "" + output += ''' +#pragma section REPRO +/** + * @file TelemetryDefinitions.c + * @brief テレメトリ定義 + * @author 鈴本 遼 + * @date 2020/08/23 + */ +#include "TelemetryDefinitions.h" +#include "TelemetrySource.h" + +/* +This pattern is a "separator". +This should not be changed. +This should not be used in other places. +*/ +//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## +'''[1:] # 最初の改行を除く + + output += body + + output += ''' + +//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## +/* +This pattern is a "separator". +This should not be changed. +This should not be used in other places. +*/ + +#pragma section +'''[1:] # 最初の改行を除く + + + with open(file_path, mode='w', encoding='shift_jis') as fh: + fh.write(output) + + +def OutputTlmDefH(file_path, body): + output = "" + output += ''' +/** + * @file TelemetryDefinitions.h + * @brief テレメトリ定義 + * @author 鈴本 遼 + * @date 2020/08/23 + */ +#ifndef TELEMETRY_DEFINITIONS_H_ +#define TELEMETRY_DEFINITIONS_H_ + +#include "../../src_core/CmdTlm/TelemetryFrame.h" + +typedef enum +{ +/* +This pattern is a "separator". +This should not be changed. +This should not be used in other places. +*/ +//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## + +'''[1:] # 最初の改行を除く + + output += body + + output += ''' + +//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## +/* +This pattern is a "separator". +This should not be changed. +This should not be used in other places. +*/ + TLM_ID_MAX +} TLMID; + +void TF_load_tlm_table(TlmInfo tlm_table_[TLM_MAX_TLMS]); + + +#endif // TLM_FRAME_INCLUDE +'''[1:] # 最初の改行を除く + + with open(file_path, mode='w', encoding='shift_jis') as fh: + fh.write(output) + + + if __name__ == '__main__': main() From 7ab7e7bb1e3ef04bcfe7b84d1ed580ce4dc4350f Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sat, 14 Nov 2020 18:43:50 +0900 Subject: [PATCH 008/141] fix --- GenerateC2ACode.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/GenerateC2ACode.py b/GenerateC2ACode.py index e6b894bcb..32ffb3b58 100644 --- a/GenerateC2ACode.py +++ b/GenerateC2ACode.py @@ -232,7 +232,6 @@ def GenerateTlmDef(settings, tlm_db): OutputTlmDefH(output_file_path + output_file_name_base + ".h", body_h) - def OutputCmdDefC(file_path, body): output = "" output += ''' @@ -443,9 +442,6 @@ def OutputTlmDefH(file_path, body): fh.write(output) - if __name__ == '__main__': main() - - From 3b7463efc1f602b2c2e4e40f8975ae04a43187ca Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sat, 14 Nov 2020 18:48:19 +0900 Subject: [PATCH 009/141] add bct description --- GenerateC2ACode.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/GenerateC2ACode.py b/GenerateC2ACode.py index 32ffb3b58..fe534d715 100644 --- a/GenerateC2ACode.py +++ b/GenerateC2ACode.py @@ -126,6 +126,7 @@ def GenerateBctDef(settings, bct_db): comment = bct_db[i][0] name = bct_db[i][1] bc_id = bct_db[i][3] + description = bct_db[i][10] if comment == "" and name == "": # CommentもNameも空白なら打ち切り break @@ -136,7 +137,10 @@ def GenerateBctDef(settings, bct_db): body_h += " // " + name + "\n" else: # " BC_SL_INITIAL_TO_INITIAL = 0," - body_h += " " + name + " = " + bc_id +",\n" + if description == "": + body_h += " " + name + " = " + bc_id +",\n" + else: + body_h += " " + name + " = " + bc_id +", // " + description + "\n" OutputBctDef(output_file_path + output_file_name, body_h) From 52c3c181f0fdc238e5e7611ffbce36543f5d2258 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sat, 14 Nov 2020 18:49:31 +0900 Subject: [PATCH 010/141] add template --- .gitlab/merge_request_templates/template.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .gitlab/merge_request_templates/template.md diff --git a/.gitlab/merge_request_templates/template.md b/.gitlab/merge_request_templates/template.md new file mode 100644 index 000000000..29f2dc21b --- /dev/null +++ b/.gitlab/merge_request_templates/template.md @@ -0,0 +1,17 @@ +## Summary (概要) +ひとことで + +## Issue (イシュー) +Issueがすでに立っているならば,そのリンクを貼る + +## Detail (詳細) +詳しく + +## Impact (影響範囲) +大:推進系の動作がガラッと変わる,とか. + +## Priority (重要度) +大:◯◯までにはマージして欲しい!! + +## Note (補足) +何かあれば From 064f8d9b0132a5a1a978abf402dfdfc25ef5de2d Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sun, 15 Nov 2020 23:29:30 +0900 Subject: [PATCH 011/141] add print at exit --- GenerateC2ACode.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/GenerateC2ACode.py b/GenerateC2ACode.py index fe534d715..88cfa5abd 100644 --- a/GenerateC2ACode.py +++ b/GenerateC2ACode.py @@ -38,6 +38,9 @@ def main(): GenerateBctDef(settings, cmd_db['bct']) GenerateTlmDef(settings, tlm_db) + print("Completed!") + sys.exit(0) + def LoadCmdCSV(settings): cmd_db_path = settings["c2a_root_dir"] + r"src_user/Settings/CmdTlm/DataBase/CMD_DB/" From 739ecb9c35a9ba2c3618a6b595d666c46499461e Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sun, 15 Nov 2020 23:58:28 +0900 Subject: [PATCH 012/141] update for new naming policy --- GenerateC2ACode.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/GenerateC2ACode.py b/GenerateC2ACode.py index 88cfa5abd..a6bb10e0a 100644 --- a/GenerateC2ACode.py +++ b/GenerateC2ACode.py @@ -160,15 +160,15 @@ def GenerateTlmDef(settings, tlm_db): # "static int OBC_(unsigned char* contents, int max_len);" # " OBC_ID = 0x00," for tlm in tlm_db: - body_c += "static int " + tlm['tlm_name'] + "_(unsigned char* contents, int max_len);\n" - body_h += " " + tlm['tlm_name'] + "_ID = " + tlm['tlm_id'] + ",\n" + body_c += "static int Tlm_" + tlm['tlm_name'] + "_(unsigned char* contents, int max_len);\n" + body_h += " Tlm_CODE_" + tlm['tlm_name'] + " = " + tlm['tlm_id'] + ",\n" body_c += "\n" body_c += "void TF_load_tlm_table(TlmInfo tlm_table_[TLM_MAX_TLMS])\n" body_c += "{\n" for tlm in tlm_db: # " tlm_table_[OBC_ID].tlm_func = OBC_;" - body_c += " tlm_table_[" + tlm['tlm_name'] + "_ID].tlm_func = " + tlm['tlm_name'] + "_;\n" + body_c += " tlm_table_[Tlm_CODE_" + tlm['tlm_name'] + "].tlm_func = Tlm_" + tlm['tlm_name'] + "_;\n" body_c += "}\n" for tlm in tlm_db: @@ -225,7 +225,7 @@ def GenerateTlmDef(settings, tlm_db): func_code += "(&contents[" + pos + "], " + code + ");\n" body_c += "\n" - body_c += "static int " + tlm['tlm_name'] + "_(unsigned char* contents, int max_len)\n" + body_c += "static int Tlm_" + tlm['tlm_name'] + "_(unsigned char* contents, int max_len)\n" body_c += "{\n" body_c += "\n" body_c += " if( " + str(max_pos) + " > max_len) { return TLM_TOO_SHORT_LEN; }\n" @@ -318,8 +318,8 @@ def OutputCmdDefH(file_path, body): This should not be changed. This should not be used in other places. */ - Cmd_ID_MAX -} CmdCode; + Cmd_CODE_MAX +} CMD_CODE; void CA_load_cmd_table(CmdInfo cmd_table_[CMD_MAX_CMDS]); @@ -350,7 +350,7 @@ def OutputBctDef(file_path, body): output += body output += ''' -} BC_DEFAULTS; +} BC_DEFAULT_ID; void BC_load_defaults(void); @@ -436,8 +436,8 @@ def OutputTlmDefH(file_path, body): This should not be changed. This should not be used in other places. */ - TLM_ID_MAX -} TLMID; + TLM_CODE_MAX +} TLM_CODE; void TF_load_tlm_table(TlmInfo tlm_table_[TLM_MAX_TLMS]); From 09cf017b66c5e3d2df17ccc2a7d5bcb8624bb0d4 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Mon, 16 Nov 2020 00:03:14 +0900 Subject: [PATCH 013/141] update readme --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 50cfffcbc..35a7f2382 100644 --- a/README.md +++ b/README.md @@ -10,4 +10,11 @@ TlmCmdDBからC2Aのコードを生成するためのスクリプト ブランチのみ作成し,master pushは禁止する. - +## 要求 +- python 3.7 以上 +- 必要ライブラリは `./requirements.txt` に記載. + - なお,現在は標準ライブラリのみしか使っていない + - 以下で一括インストール可能 +``` +$ pip install -r requirements.txt +``` From 3911b5637e59ccab6ec8c0a6634e109eb9c269ac Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sun, 6 Dec 2020 16:41:41 +0900 Subject: [PATCH 014/141] add conv for gstos sib --- .gitignore | 15 +++ GenerateC2ACode.py | 258 ++++++++++++++++++++++++++++++++++++++++++++- settings.json | 2 +- 3 files changed, 273 insertions(+), 2 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..c0c122c08 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +# OSX +.DS_Store +.AppleDouble +.LSOverride +Icon + +# Thumbnails +._* + +# Files that might appear on external disk +.Spotlight-V100 +.Trashes + +# others +gstos_files/* diff --git a/GenerateC2ACode.py b/GenerateC2ACode.py index a6bb10e0a..60c9073cd 100644 --- a/GenerateC2ACode.py +++ b/GenerateC2ACode.py @@ -21,7 +21,7 @@ # 0 : Release # 1 : all SETTING_FILE_PATH = "settings.json" - +OUTPUT_DIR_GSTOS = "gstos_files" def main(): with open(SETTING_FILE_PATH, mode='r') as fh: @@ -37,6 +37,8 @@ def main(): GenerateCmdDef(settings, cmd_db['sgc']) GenerateBctDef(settings, cmd_db['bct']) GenerateTlmDef(settings, tlm_db) + if settings["is_generated_sib"]: + GenerateGstosFiles(settings, cmd_db['sgc'], tlm_db) print("Completed!") sys.exit(0) @@ -449,6 +451,260 @@ def OutputTlmDefH(file_path, body): fh.write(output) +def GenerateGstosFiles(settings, sgc_db, tlm_db): + if not os.path.exists(OUTPUT_DIR_GSTOS): + os.makedirs(OUTPUT_DIR_GSTOS) + + cmd_sib_file_path = r"./" + OUTPUT_DIR_GSTOS + r"/cmdfile.cmd.sib" + tlm_sib_file_path = r"./" + OUTPUT_DIR_GSTOS + r"/tlmfile.tlm.sib" + + output_cmd = "" + output_tlm = "" + + output_cmd += '\n' + output_cmd += '\n' + + DATA_SART_ROW = 3 + for i in range(DATA_SART_ROW, len(sgc_db)): + comment = sgc_db[i][0] + name = sgc_db[i][1] + if comment == "" and name == "": # CommentもNameも空白なら打ち切り + break + if comment != "": # Comment + continue + output_cmd += GetCmdSibDef(sgc_db[i]) + + output_cmd += '\n' + + with open(cmd_sib_file_path, mode='w', encoding='euc_jp') as fh: + fh.write(output_cmd) + + output_tlm += '\n' + output_tlm += '\n' + + DATA_SART_ROW = 7 + + for tlm in tlm_db: + for i in range(DATA_SART_ROW, len(tlm['data'])): + comment = tlm['data'][i][0] + name = tlm['data'][i][1] + var_type = tlm['data'][i][2] + # code = tlm['data'][i][3] + # pos = tlm['data'][i][4] + if comment == "" and name == "": # CommentもNameも空白なら打ち切り + break + if comment != "": + continue + if name == "": + continue + if var_type == "": + continue + # if code == "": + # continue + # if pos == "": + # continue + output_tlm += GetTlmSibDef(tlm['tlm_id'], tlm['data'][i]) + + output_tlm += '\n' + + with open(tlm_sib_file_path, mode='w', encoding='euc_jp') as fh: + fh.write(output_tlm) + + +def GetCmdSibDef(sgc_db_line): + cmd = sgc_db_line[1] + inf = sgc_db_line[18] + cmd_id = sgc_db_line[3] + param_num = int(sgc_db_line[4]) + START_PARAM_COL = 5 + is_danger = sgc_db_line[17] + + output = "" + + for cmd_type in range(0,3): + # 0,1,2 -> RT,TL,BL + output += ' \n' + if cmd_type == 0: + output += ' OBC_RT.' + cmd + ' \n' + elif cmd_type == 1: + output += ' OBC_BL.' + cmd + ' \n' + else: + output += ' OBC_TL.' + cmd + ' \n' + output += ' ' + inf + ' \n' + output += ' UNUSE\n' + output += ' 0x0210\n' + output += ' 432\n' + if is_danger: + output += ' K\n' + output += ' \n' + output += ' \n' + output += ' o0,b0@16=0x1a10 \n' + output += ' o2,b0@16=0xC000 \n' + output += ' \n' + output += ' o6,b0@8=0x01 \n' + output += ' \n' + output += ' o7,b0@8=0x02 \n' + output += ' o8,b0@16=' + cmd_id + '\n' + if cmd_type == 0: + output += ' o10,b0@8=0x00\n' + output += ' o11,b0@32=0x00000000 \n' + elif cmd_type == 1: + output += ' o10,b0@8=0x01\n' + output += ' \n' + output += ' \n' + output += ' o11,b0@32 \n' + output += ' Time(UINT,32BIT)\n' + output += ' UINT\n' + output += ' \n' + else: + output += ' o10,b0@8=0x02\n' + output += ' \n' + output += ' \n' + output += ' o11,b0@32 \n' + output += ' Time(UINT,32BIT)\n' + output += ' UINT\n' + output += ' \n' + + if param_num: + o = 0 + l = 0 + t = 0 + b = 0 + for s in range(0, param_num): # パラメーター数に制限はなし.シートで定義したぶんだけ生成可能 + str_info = "param" + str(s + 1); # いくつ目のパラメーターか表示 + var_type = sgc_db_line[START_PARAM_COL + s * 2] + var_note = "" + + if var_type == "int8_t": + var_note = "SINT" + o = 15 + t + l = 8 + t += 1 + elif var_type == "int16_t": + var_note = "SINT" + o = 15 + t + l = 16 + t += 2 + elif var_type == "int32_t": + var_note = "SINT" + o = 15 + t + l = 32 + t += 4 + elif var_type == "uint8_t": + var_note = "UINT" + o = 15 + t + l = 8 + t += 1 + elif var_type == "uint16_t": + var_note = "UINT" + o = 15 + t + l = 16 + t += 2 + elif var_type == "uint32_t": + var_note = "UINT" + o = 15 + t + l = 32 + t += 4 + elif var_type == "float": + var_note = "FLOAT" + o = 15 + t + l = 32 + t += 4 + elif var_type == "double": + var_note = "DOUBLE" + o = 15 + t + l = 64 + t += 8 + elif var_type == "raw": + var_note = "HEXBINARY" + o = 15 + t + l = (432 - o) * 8 + # t += 4 # コマンド長最後まで + else: + print("Error: Cmd DB Err at " + cmd, file=sys.stderr) + sys.exit(1) + + output += ' \n' + output += ' o' + str(o) + ',b' + str(b) + '@' + str(l) + '\n' + output += ' ' + str_info + ' (' + var_type + ',' + str(l) + 'BIT)\n' + output += ' ' + var_note + '\n' + output += ' \n' + + output += ' \n' + output += ' \n' + + return output + + +def GetTlmSibDef(tlm_id, tlm_db_line): + comment = tlm_db_line[0] + name = tlm_db_line[1] + var_type = tlm_db_line[2] + code = tlm_db_line[3] + pos = tlm_db_line[4] + ext_type = tlm_db_line[5] + oct_pos = tlm_db_line[6] + bit_pos = tlm_db_line[7] + bit_len = tlm_db_line[8] + cnv_type = tlm_db_line[9] + status = tlm_db_line[16] + var_note = "" + + tlm_id = tlm_id.replace("0x", "") + + if var_type == "int8_t": + var_note = "SINT" + elif var_type == "int16_t": + var_note = "SINT" + elif var_type == "int32_t": + var_note = "SINT" + elif var_type == "uint8_t": + var_note = "UINT" + elif var_type == "uint16_t": + var_note = "UINT" + elif var_type == "uint32_t": + var_note = "UINT" + elif var_type == "float": + var_note = "FLOAT" + elif var_type == "double": + var_note = "DOUBLE" + else: + print("Error: Tlm DB Err at " + name, file=sys.stderr) + sys.exit(1) + + # 今回はめんどいのでPACKETしかみない + if ext_type != "PACKET": + print("Error: Tlm DB Err at " + name, file=sys.stderr) + sys.exit(1) + + output = "" + + output += ' \n' + output += ' ' + name + ' \n' + output += ' ' + var_note + ' \n' + output += ' p510:s' + tlm_id + ',o' + oct_pos + ',b' + bit_pos + '@' + bit_len + ' \n' + + if cnv_type == "POLY": + coeffs = [] + for k in range(10,16): + coeff = tlm_db_line[k] + if coeff == "": + break + coeffs.append(coeff) + output += ' ' + ",".join(coeffs) + '\n' + elif cnv_type == "STATUS": + output += ' ' + status + '\n' + elif cnv_type == "NONE": + output += ' \n' + else: + print("Error: Tlm DB Err at " + name, file=sys.stderr) + sys.exit(1) + + output += ' \n' + + return output + + if __name__ == '__main__': main() diff --git a/settings.json b/settings.json index 29f027182..ca84d63bf 100644 --- a/settings.json +++ b/settings.json @@ -1,5 +1,5 @@ { "c2a_root_dir" : "../../c2a_user_oss/SH7254R_C2A/", "db_prefix" : "ISSL6U_MOBC", - "is_generated_sib" : 0 + "is_generated_sib" : 1 } From cb293f329a50e9b59182e07f6ccce60c6722ac11 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Thu, 7 Jan 2021 21:39:26 +0900 Subject: [PATCH 015/141] fix for coding rule --- GenerateC2ACode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GenerateC2ACode.py b/GenerateC2ACode.py index 60c9073cd..9a9644e13 100644 --- a/GenerateC2ACode.py +++ b/GenerateC2ACode.py @@ -230,7 +230,7 @@ def GenerateTlmDef(settings, tlm_db): body_c += "static int Tlm_" + tlm['tlm_name'] + "_(unsigned char* contents, int max_len)\n" body_c += "{\n" body_c += "\n" - body_c += " if( " + str(max_pos) + " > max_len) { return TLM_TOO_SHORT_LEN; }\n" + body_c += " if (" + str(max_pos) + " > max_len) { return TLM_TOO_SHORT_LEN; }\n" body_c += "\n" body_c += func_code body_c += "\n" From 336de6007d2f80063c0b3c1bde0ebc0315300929 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Thu, 21 Jan 2021 22:17:39 +0900 Subject: [PATCH 016/141] fix comment --- GenerateC2ACode.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GenerateC2ACode.py b/GenerateC2ACode.py index 9a9644e13..2e39159bd 100644 --- a/GenerateC2ACode.py +++ b/GenerateC2ACode.py @@ -356,7 +356,7 @@ def OutputBctDef(file_path, body): void BC_load_defaults(void); -#endif // BLOCK_COMMAND_DEFINISIONS_H_ +#endif '''[1:] # 最初の改行を除く with open(file_path, mode='w', encoding='shift_jis') as fh: @@ -444,7 +444,7 @@ def OutputTlmDefH(file_path, body): void TF_load_tlm_table(TlmInfo tlm_table_[TLM_MAX_TLMS]); -#endif // TLM_FRAME_INCLUDE +#endif '''[1:] # 最初の改行を除く with open(file_path, mode='w', encoding='shift_jis') as fh: From 33c628d96628bce40487ebf23056c6dffd73f288 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Fri, 5 Feb 2021 02:42:00 +0900 Subject: [PATCH 017/141] add def for fast build --- GenerateC2ACode.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/GenerateC2ACode.py b/GenerateC2ACode.py index 2e39159bd..2a8810c38 100644 --- a/GenerateC2ACode.py +++ b/GenerateC2ACode.py @@ -232,7 +232,9 @@ def GenerateTlmDef(settings, tlm_db): body_c += "\n" body_c += " if (" + str(max_pos) + " > max_len) { return TLM_TOO_SHORT_LEN; }\n" body_c += "\n" + body_c += "#ifndef FAST_BUILD\n" body_c += func_code + body_c += "#endif\n" body_c += "\n" body_c += " return " + str(max_pos) + ";\n" body_c += "}\n" @@ -376,6 +378,8 @@ def OutputTlmDefC(file_path, body): #include "TelemetryDefinitions.h" #include "TelemetrySource.h" +// #define FAST_BUILD + /* This pattern is a "separator". This should not be changed. From 7e50a4aef264033f346d0215e6bb8210ffb29aa1 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Fri, 5 Feb 2021 09:20:53 +0900 Subject: [PATCH 018/141] remove def --- GenerateC2ACode.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/GenerateC2ACode.py b/GenerateC2ACode.py index 2a8810c38..0c7d8b630 100644 --- a/GenerateC2ACode.py +++ b/GenerateC2ACode.py @@ -378,8 +378,6 @@ def OutputTlmDefC(file_path, body): #include "TelemetryDefinitions.h" #include "TelemetrySource.h" -// #define FAST_BUILD - /* This pattern is a "separator". This should not be changed. From 61d859841918cbb73caa1ba65ba4fd7a84fe6447 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sat, 13 Feb 2021 20:32:20 +0900 Subject: [PATCH 019/141] disable gstos option on default settings --- README.md | 22 ++++++++++++++++++++++ settings.json | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 35a7f2382..a611daff4 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,27 @@ ## これはなに? TlmCmdDBからC2Aのコードを生成するためのスクリプト +## 実行 +``` +$ python GenerateC2ACode.py +``` + +## 設定 +`settings.json` にて記述する. + +``` +{ + # C2A ROOTへ相対パス. + # C2A ROOTとは, `src_core`, `src_user` のあるディレクトリ + "c2a_root_dir" : "../../c2a_user_oss/SH7254R_C2A/", + # TlmCmdDBのファイル名の接頭辞 + "db_prefix" : "ISSL6U_MOBC", + # GSTOS用sibファイルを生成するか? 0/1 + "is_generated_sib" : 0 +} +``` + + ## 開発方針 そこまで込み入った開発はしないので, @@ -10,6 +31,7 @@ TlmCmdDBからC2Aのコードを生成するためのスクリプト ブランチのみ作成し,master pushは禁止する. + ## 要求 - python 3.7 以上 - 必要ライブラリは `./requirements.txt` に記載. diff --git a/settings.json b/settings.json index ca84d63bf..29f027182 100644 --- a/settings.json +++ b/settings.json @@ -1,5 +1,5 @@ { "c2a_root_dir" : "../../c2a_user_oss/SH7254R_C2A/", "db_prefix" : "ISSL6U_MOBC", - "is_generated_sib" : 1 + "is_generated_sib" : 0 } From 0cac5c92ae6ae26eabba6b9b8092d8bfd134b816 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sat, 13 Feb 2021 21:07:35 +0900 Subject: [PATCH 020/141] update for handle many obc --- README.md | 24 ++++++++++++++++++++++-- settings.json | 19 ++++++++++++++++++- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a611daff4..df8d35638 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,8 @@ $ python GenerateC2ACode.py ``` ## 設定 -`settings.json` にて記述する. +`settings.json` にて記述する. +現在m `is_main_obc` は,未だ仕様未確定なため, `0` とすること! ``` { @@ -18,7 +19,26 @@ $ python GenerateC2ACode.py # TlmCmdDBのファイル名の接頭辞 "db_prefix" : "ISSL6U_MOBC", # GSTOS用sibファイルを生成するか? 0/1 - "is_generated_sib" : 0 + "is_generated_sib" : 0, + # MOBCか?(他のOBCのtlm/cmdを取りまとめるか? 0/1 + # 0 の場合,以後のパラメタは無効 + "is_main_obc" : 0, + "other_obc_data" : [ + { + "name" : "AOBC", + "is_enable" : 0, + "db_prefix" : "ISSL6U_AOBC", + "db_path" : "../../aobc_tlmcmd/", + "tlm_id_range" : ["0x90", "0xc0"], + }, + { + "name" : "TOBC", + "is_enable" : 1, + "db_prefix" : "ISSL6U_TOBC", + "db_path" : "../../tobc_tlmcmd/", + "tlm_id_range" : ["0xc0", "0xf0"], + } + ] } ``` diff --git a/settings.json b/settings.json index 29f027182..85d3d99e2 100644 --- a/settings.json +++ b/settings.json @@ -1,5 +1,22 @@ { "c2a_root_dir" : "../../c2a_user_oss/SH7254R_C2A/", "db_prefix" : "ISSL6U_MOBC", - "is_generated_sib" : 0 + "is_generated_sib" : 0, + "is_main_obc" : 0, + "other_obc_data" : [ + { + "name" : "AOBC", + "is_enable" : 0, + "db_prefix" : "ISSL6U_AOBC", + "db_path" : "../../aobc_tlmcmd/", + "tlm_id_range" : ["0x90", "0xc0"], + }, + { + "name" : "TOBC", + "is_enable" : 1, + "db_prefix" : "ISSL6U_TOBC", + "db_path" : "../../tobc_tlmcmd/", + "tlm_id_range" : ["0xc0", "0xf0"], + } + ] } From 8dcafa3c256a2e82b8152aea7ab84cad3af182c2 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sat, 13 Feb 2021 21:12:20 +0900 Subject: [PATCH 021/141] fix --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index df8d35638..dbf9474d9 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ $ python GenerateC2ACode.py ## 設定 `settings.json` にて記述する. -現在m `is_main_obc` は,未だ仕様未確定なため, `0` とすること! +現在 `is_main_obc` は,未だ仕様未確定なため, `0` とすること! ``` { @@ -21,7 +21,7 @@ $ python GenerateC2ACode.py # GSTOS用sibファイルを生成するか? 0/1 "is_generated_sib" : 0, # MOBCか?(他のOBCのtlm/cmdを取りまとめるか? 0/1 - # 0 の場合,以後のパラメタは無効 + # 0 の場合,以後のパラメタは無効(現在仮おき) "is_main_obc" : 0, "other_obc_data" : [ { From 2fb369022b6334cbd30ad68f932f831e84c33533 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sat, 13 Feb 2021 21:27:10 +0900 Subject: [PATCH 022/141] extract gstos code --- .gitignore | 1 + GenerateC2ACode.py | 260 +------------------------------------------- my_mod/gstos.py | 261 +++++++++++++++++++++++++++++++++++++++++++++ settings.json | 4 +- 4 files changed, 268 insertions(+), 258 deletions(-) create mode 100644 my_mod/gstos.py diff --git a/.gitignore b/.gitignore index c0c122c08..abe7f23f5 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ Icon .Trashes # others +*.pyc gstos_files/* diff --git a/GenerateC2ACode.py b/GenerateC2ACode.py index 0c7d8b630..34e2ed952 100644 --- a/GenerateC2ACode.py +++ b/GenerateC2ACode.py @@ -10,7 +10,9 @@ import pprint import sys -# import os +import my_mod.gstos + + # import os.path # import msvcrt # Enter不要な入力用 # import subprocess @@ -21,7 +23,6 @@ # 0 : Release # 1 : all SETTING_FILE_PATH = "settings.json" -OUTPUT_DIR_GSTOS = "gstos_files" def main(): with open(SETTING_FILE_PATH, mode='r') as fh: @@ -38,7 +39,7 @@ def main(): GenerateBctDef(settings, cmd_db['bct']) GenerateTlmDef(settings, tlm_db) if settings["is_generated_sib"]: - GenerateGstosFiles(settings, cmd_db['sgc'], tlm_db) + my_mod.gstos.GenerateGstosFiles(settings, cmd_db['sgc'], tlm_db) print("Completed!") sys.exit(0) @@ -453,259 +454,6 @@ def OutputTlmDefH(file_path, body): fh.write(output) -def GenerateGstosFiles(settings, sgc_db, tlm_db): - if not os.path.exists(OUTPUT_DIR_GSTOS): - os.makedirs(OUTPUT_DIR_GSTOS) - - cmd_sib_file_path = r"./" + OUTPUT_DIR_GSTOS + r"/cmdfile.cmd.sib" - tlm_sib_file_path = r"./" + OUTPUT_DIR_GSTOS + r"/tlmfile.tlm.sib" - - output_cmd = "" - output_tlm = "" - - output_cmd += '\n' - output_cmd += '\n' - - DATA_SART_ROW = 3 - for i in range(DATA_SART_ROW, len(sgc_db)): - comment = sgc_db[i][0] - name = sgc_db[i][1] - if comment == "" and name == "": # CommentもNameも空白なら打ち切り - break - if comment != "": # Comment - continue - output_cmd += GetCmdSibDef(sgc_db[i]) - - output_cmd += '\n' - - with open(cmd_sib_file_path, mode='w', encoding='euc_jp') as fh: - fh.write(output_cmd) - - output_tlm += '\n' - output_tlm += '\n' - - DATA_SART_ROW = 7 - - for tlm in tlm_db: - for i in range(DATA_SART_ROW, len(tlm['data'])): - comment = tlm['data'][i][0] - name = tlm['data'][i][1] - var_type = tlm['data'][i][2] - # code = tlm['data'][i][3] - # pos = tlm['data'][i][4] - if comment == "" and name == "": # CommentもNameも空白なら打ち切り - break - if comment != "": - continue - if name == "": - continue - if var_type == "": - continue - # if code == "": - # continue - # if pos == "": - # continue - output_tlm += GetTlmSibDef(tlm['tlm_id'], tlm['data'][i]) - - output_tlm += '\n' - - with open(tlm_sib_file_path, mode='w', encoding='euc_jp') as fh: - fh.write(output_tlm) - - -def GetCmdSibDef(sgc_db_line): - cmd = sgc_db_line[1] - inf = sgc_db_line[18] - cmd_id = sgc_db_line[3] - param_num = int(sgc_db_line[4]) - START_PARAM_COL = 5 - is_danger = sgc_db_line[17] - - output = "" - - for cmd_type in range(0,3): - # 0,1,2 -> RT,TL,BL - output += ' \n' - if cmd_type == 0: - output += ' OBC_RT.' + cmd + ' \n' - elif cmd_type == 1: - output += ' OBC_BL.' + cmd + ' \n' - else: - output += ' OBC_TL.' + cmd + ' \n' - output += ' ' + inf + ' \n' - output += ' UNUSE\n' - output += ' 0x0210\n' - output += ' 432\n' - if is_danger: - output += ' K\n' - output += ' \n' - output += ' \n' - output += ' o0,b0@16=0x1a10 \n' - output += ' o2,b0@16=0xC000 \n' - output += ' \n' - output += ' o6,b0@8=0x01 \n' - output += ' \n' - output += ' o7,b0@8=0x02 \n' - output += ' o8,b0@16=' + cmd_id + '\n' - if cmd_type == 0: - output += ' o10,b0@8=0x00\n' - output += ' o11,b0@32=0x00000000 \n' - elif cmd_type == 1: - output += ' o10,b0@8=0x01\n' - output += ' \n' - output += ' \n' - output += ' o11,b0@32 \n' - output += ' Time(UINT,32BIT)\n' - output += ' UINT\n' - output += ' \n' - else: - output += ' o10,b0@8=0x02\n' - output += ' \n' - output += ' \n' - output += ' o11,b0@32 \n' - output += ' Time(UINT,32BIT)\n' - output += ' UINT\n' - output += ' \n' - - if param_num: - o = 0 - l = 0 - t = 0 - b = 0 - for s in range(0, param_num): # パラメーター数に制限はなし.シートで定義したぶんだけ生成可能 - str_info = "param" + str(s + 1); # いくつ目のパラメーターか表示 - var_type = sgc_db_line[START_PARAM_COL + s * 2] - var_note = "" - - if var_type == "int8_t": - var_note = "SINT" - o = 15 + t - l = 8 - t += 1 - elif var_type == "int16_t": - var_note = "SINT" - o = 15 + t - l = 16 - t += 2 - elif var_type == "int32_t": - var_note = "SINT" - o = 15 + t - l = 32 - t += 4 - elif var_type == "uint8_t": - var_note = "UINT" - o = 15 + t - l = 8 - t += 1 - elif var_type == "uint16_t": - var_note = "UINT" - o = 15 + t - l = 16 - t += 2 - elif var_type == "uint32_t": - var_note = "UINT" - o = 15 + t - l = 32 - t += 4 - elif var_type == "float": - var_note = "FLOAT" - o = 15 + t - l = 32 - t += 4 - elif var_type == "double": - var_note = "DOUBLE" - o = 15 + t - l = 64 - t += 8 - elif var_type == "raw": - var_note = "HEXBINARY" - o = 15 + t - l = (432 - o) * 8 - # t += 4 # コマンド長最後まで - else: - print("Error: Cmd DB Err at " + cmd, file=sys.stderr) - sys.exit(1) - - output += ' \n' - output += ' o' + str(o) + ',b' + str(b) + '@' + str(l) + '\n' - output += ' ' + str_info + ' (' + var_type + ',' + str(l) + 'BIT)\n' - output += ' ' + var_note + '\n' - output += ' \n' - - output += ' \n' - output += ' \n' - - return output - - -def GetTlmSibDef(tlm_id, tlm_db_line): - comment = tlm_db_line[0] - name = tlm_db_line[1] - var_type = tlm_db_line[2] - code = tlm_db_line[3] - pos = tlm_db_line[4] - ext_type = tlm_db_line[5] - oct_pos = tlm_db_line[6] - bit_pos = tlm_db_line[7] - bit_len = tlm_db_line[8] - cnv_type = tlm_db_line[9] - status = tlm_db_line[16] - var_note = "" - - tlm_id = tlm_id.replace("0x", "") - - if var_type == "int8_t": - var_note = "SINT" - elif var_type == "int16_t": - var_note = "SINT" - elif var_type == "int32_t": - var_note = "SINT" - elif var_type == "uint8_t": - var_note = "UINT" - elif var_type == "uint16_t": - var_note = "UINT" - elif var_type == "uint32_t": - var_note = "UINT" - elif var_type == "float": - var_note = "FLOAT" - elif var_type == "double": - var_note = "DOUBLE" - else: - print("Error: Tlm DB Err at " + name, file=sys.stderr) - sys.exit(1) - - # 今回はめんどいのでPACKETしかみない - if ext_type != "PACKET": - print("Error: Tlm DB Err at " + name, file=sys.stderr) - sys.exit(1) - - output = "" - - output += ' \n' - output += ' ' + name + ' \n' - output += ' ' + var_note + ' \n' - output += ' p510:s' + tlm_id + ',o' + oct_pos + ',b' + bit_pos + '@' + bit_len + ' \n' - - if cnv_type == "POLY": - coeffs = [] - for k in range(10,16): - coeff = tlm_db_line[k] - if coeff == "": - break - coeffs.append(coeff) - output += ' ' + ",".join(coeffs) + '\n' - elif cnv_type == "STATUS": - output += ' ' + status + '\n' - elif cnv_type == "NONE": - output += ' \n' - else: - print("Error: Tlm DB Err at " + name, file=sys.stderr) - sys.exit(1) - - output += ' \n' - - return output - if __name__ == '__main__': main() diff --git a/my_mod/gstos.py b/my_mod/gstos.py new file mode 100644 index 000000000..2f3c5cc1c --- /dev/null +++ b/my_mod/gstos.py @@ -0,0 +1,261 @@ +# coding: UTF-8 +""" +GSTOS関連処理 +""" + +import os + +OUTPUT_DIR_GSTOS = "gstos_files" + +def GenerateGstosFiles(settings, sgc_db, tlm_db): + if not os.path.exists(OUTPUT_DIR_GSTOS): + os.makedirs(OUTPUT_DIR_GSTOS) + + cmd_sib_file_path = r"./" + OUTPUT_DIR_GSTOS + r"/cmdfile.cmd.sib" + tlm_sib_file_path = r"./" + OUTPUT_DIR_GSTOS + r"/tlmfile.tlm.sib" + + output_cmd = "" + output_tlm = "" + + output_cmd += '\n' + output_cmd += '\n' + + DATA_SART_ROW = 3 + for i in range(DATA_SART_ROW, len(sgc_db)): + comment = sgc_db[i][0] + name = sgc_db[i][1] + if comment == "" and name == "": # CommentもNameも空白なら打ち切り + break + if comment != "": # Comment + continue + output_cmd += GetCmdSibDef(sgc_db[i]) + + output_cmd += '\n' + + with open(cmd_sib_file_path, mode='w', encoding='euc_jp') as fh: + fh.write(output_cmd) + + output_tlm += '\n' + output_tlm += '\n' + + DATA_SART_ROW = 7 + + for tlm in tlm_db: + for i in range(DATA_SART_ROW, len(tlm['data'])): + comment = tlm['data'][i][0] + name = tlm['data'][i][1] + var_type = tlm['data'][i][2] + # code = tlm['data'][i][3] + # pos = tlm['data'][i][4] + if comment == "" and name == "": # CommentもNameも空白なら打ち切り + break + if comment != "": + continue + if name == "": + continue + if var_type == "": + continue + # if code == "": + # continue + # if pos == "": + # continue + output_tlm += GetTlmSibDef(tlm['tlm_id'], tlm['data'][i]) + + output_tlm += '\n' + + with open(tlm_sib_file_path, mode='w', encoding='euc_jp') as fh: + fh.write(output_tlm) + + +def GetCmdSibDef(sgc_db_line): + cmd = sgc_db_line[1] + inf = sgc_db_line[18] + cmd_id = sgc_db_line[3] + param_num = int(sgc_db_line[4]) + START_PARAM_COL = 5 + is_danger = sgc_db_line[17] + + output = "" + + for cmd_type in range(0,3): + # 0,1,2 -> RT,TL,BL + output += ' \n' + if cmd_type == 0: + output += ' OBC_RT.' + cmd + ' \n' + elif cmd_type == 1: + output += ' OBC_BL.' + cmd + ' \n' + else: + output += ' OBC_TL.' + cmd + ' \n' + output += ' ' + inf + ' \n' + output += ' UNUSE\n' + output += ' 0x0210\n' + output += ' 432\n' + if is_danger: + output += ' K\n' + output += ' \n' + output += ' \n' + output += ' o0,b0@16=0x1a10 \n' + output += ' o2,b0@16=0xC000 \n' + output += ' \n' + output += ' o6,b0@8=0x01 \n' + output += ' \n' + output += ' o7,b0@8=0x02 \n' + output += ' o8,b0@16=' + cmd_id + '\n' + if cmd_type == 0: + output += ' o10,b0@8=0x00\n' + output += ' o11,b0@32=0x00000000 \n' + elif cmd_type == 1: + output += ' o10,b0@8=0x01\n' + output += ' \n' + output += ' \n' + output += ' o11,b0@32 \n' + output += ' Time(UINT,32BIT)\n' + output += ' UINT\n' + output += ' \n' + else: + output += ' o10,b0@8=0x02\n' + output += ' \n' + output += ' \n' + output += ' o11,b0@32 \n' + output += ' Time(UINT,32BIT)\n' + output += ' UINT\n' + output += ' \n' + + if param_num: + o = 0 + l = 0 + t = 0 + b = 0 + for s in range(0, param_num): # パラメーター数に制限はなし.シートで定義したぶんだけ生成可能 + str_info = "param" + str(s + 1); # いくつ目のパラメーターか表示 + var_type = sgc_db_line[START_PARAM_COL + s * 2] + var_note = "" + + if var_type == "int8_t": + var_note = "SINT" + o = 15 + t + l = 8 + t += 1 + elif var_type == "int16_t": + var_note = "SINT" + o = 15 + t + l = 16 + t += 2 + elif var_type == "int32_t": + var_note = "SINT" + o = 15 + t + l = 32 + t += 4 + elif var_type == "uint8_t": + var_note = "UINT" + o = 15 + t + l = 8 + t += 1 + elif var_type == "uint16_t": + var_note = "UINT" + o = 15 + t + l = 16 + t += 2 + elif var_type == "uint32_t": + var_note = "UINT" + o = 15 + t + l = 32 + t += 4 + elif var_type == "float": + var_note = "FLOAT" + o = 15 + t + l = 32 + t += 4 + elif var_type == "double": + var_note = "DOUBLE" + o = 15 + t + l = 64 + t += 8 + elif var_type == "raw": + var_note = "HEXBINARY" + o = 15 + t + l = (432 - o) * 8 + # t += 4 # コマンド長最後まで + else: + print("Error: Cmd DB Err at " + cmd, file=sys.stderr) + sys.exit(1) + + output += ' \n' + output += ' o' + str(o) + ',b' + str(b) + '@' + str(l) + '\n' + output += ' ' + str_info + ' (' + var_type + ',' + str(l) + 'BIT)\n' + output += ' ' + var_note + '\n' + output += ' \n' + + output += ' \n' + output += ' \n' + + return output + + +def GetTlmSibDef(tlm_id, tlm_db_line): + comment = tlm_db_line[0] + name = tlm_db_line[1] + var_type = tlm_db_line[2] + code = tlm_db_line[3] + pos = tlm_db_line[4] + ext_type = tlm_db_line[5] + oct_pos = tlm_db_line[6] + bit_pos = tlm_db_line[7] + bit_len = tlm_db_line[8] + cnv_type = tlm_db_line[9] + status = tlm_db_line[16] + var_note = "" + + tlm_id = tlm_id.replace("0x", "") + + if var_type == "int8_t": + var_note = "SINT" + elif var_type == "int16_t": + var_note = "SINT" + elif var_type == "int32_t": + var_note = "SINT" + elif var_type == "uint8_t": + var_note = "UINT" + elif var_type == "uint16_t": + var_note = "UINT" + elif var_type == "uint32_t": + var_note = "UINT" + elif var_type == "float": + var_note = "FLOAT" + elif var_type == "double": + var_note = "DOUBLE" + else: + print("Error: Tlm DB Err at " + name, file=sys.stderr) + sys.exit(1) + + # 今回はめんどいのでPACKETしかみない + if ext_type != "PACKET": + print("Error: Tlm DB Err at " + name, file=sys.stderr) + sys.exit(1) + + output = "" + + output += ' \n' + output += ' ' + name + ' \n' + output += ' ' + var_note + ' \n' + output += ' p510:s' + tlm_id + ',o' + oct_pos + ',b' + bit_pos + '@' + bit_len + ' \n' + + if cnv_type == "POLY": + coeffs = [] + for k in range(10,16): + coeff = tlm_db_line[k] + if coeff == "": + break + coeffs.append(coeff) + output += ' ' + ",".join(coeffs) + '\n' + elif cnv_type == "STATUS": + output += ' ' + status + '\n' + elif cnv_type == "NONE": + output += ' \n' + else: + print("Error: Tlm DB Err at " + name, file=sys.stderr) + sys.exit(1) + + output += ' \n' + + return output diff --git a/settings.json b/settings.json index 85d3d99e2..36b539c08 100644 --- a/settings.json +++ b/settings.json @@ -9,14 +9,14 @@ "is_enable" : 0, "db_prefix" : "ISSL6U_AOBC", "db_path" : "../../aobc_tlmcmd/", - "tlm_id_range" : ["0x90", "0xc0"], + "tlm_id_range" : ["0x90", "0xc0"] }, { "name" : "TOBC", "is_enable" : 1, "db_prefix" : "ISSL6U_TOBC", "db_path" : "../../tobc_tlmcmd/", - "tlm_id_range" : ["0xc0", "0xf0"], + "tlm_id_range" : ["0xc0", "0xf0"] } ] } From fad486123519c0eadf9da8d73848719fc7a0d2a8 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sat, 13 Feb 2021 21:40:51 +0900 Subject: [PATCH 023/141] divide src --- GenerateC2ACode.py | 426 +-------------------------------------------- my_mod/cmd_def.py | 190 ++++++++++++++++++++ my_mod/load_db.py | 55 ++++++ my_mod/tlm_def.py | 185 ++++++++++++++++++++ settings.json | 2 +- 5 files changed, 439 insertions(+), 419 deletions(-) create mode 100644 my_mod/cmd_def.py create mode 100644 my_mod/load_db.py create mode 100644 my_mod/tlm_def.py diff --git a/GenerateC2ACode.py b/GenerateC2ACode.py index 34e2ed952..fea59e62f 100644 --- a/GenerateC2ACode.py +++ b/GenerateC2ACode.py @@ -4,12 +4,12 @@ """ import json -import csv -import os -import re # 正規表現 import pprint import sys +import my_mod.load_db +import my_mod.cmd_def +import my_mod.tlm_def import my_mod.gstos @@ -29,15 +29,15 @@ def main(): settings = json.load(fh) # print(settings["c2a_root_dir"]); - cmd_db = LoadCmdCSV(settings) - tlm_db = LoadTlmCSV(settings) + cmd_db = my_mod.load_db.LoadCmdCSV(settings) + tlm_db = my_mod.load_db.LoadTlmCSV(settings) # pprint.pprint(cmd_db) # pprint.pprint(tlm_db) # print(tlm_db) - GenerateCmdDef(settings, cmd_db['sgc']) - GenerateBctDef(settings, cmd_db['bct']) - GenerateTlmDef(settings, tlm_db) + my_mod.cmd_def.GenerateCmdDef(settings, cmd_db['sgc']) + my_mod.cmd_def.GenerateBctDef(settings, cmd_db['bct']) + my_mod.tlm_def.GenerateTlmDef(settings, tlm_db) if settings["is_generated_sib"]: my_mod.gstos.GenerateGstosFiles(settings, cmd_db['sgc'], tlm_db) @@ -45,416 +45,6 @@ def main(): sys.exit(0) -def LoadCmdCSV(settings): - cmd_db_path = settings["c2a_root_dir"] + r"src_user/Settings/CmdTlm/DataBase/CMD_DB/" - sgc_db_path = cmd_db_path + settings["db_prefix"] + "_CMD_DB_CMD_DB.csv" # single cmd - bct_db_path = cmd_db_path + settings["db_prefix"] + "_CMD_DB_BCT.csv" # block cmd table - - with open(sgc_db_path, mode='r', encoding='shift_jis') 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: - reader = csv.reader(fh) - bct_db = [row for row in reader] - - # print(sgc_db) - # print(bct_db) - return {'sgc': sgc_db, 'bct': bct_db} - - -def LoadTlmCSV(settings): - tlm_db_path = settings["c2a_root_dir"] + r"src_user/Settings/CmdTlm/DataBase/TLM_DB/calced_data/" - - tlm_names = [file for file in os.listdir(tlm_db_path) if file.endswith(".csv")] - regex = r"^" + settings["db_prefix"] + "_TLM_DB_" - tlm_names = [re.sub(regex, "", file) for file in tlm_names] - tlm_names = [re.sub(".csv$", "", file) for file in tlm_names] - # pprint.pprint(tlm_names) - # print(len(tlm_names)) - - tlm_db = [] - - for tlm_name in tlm_names: - tlm_sheet_path = tlm_db_path + settings["db_prefix"] + "_TLM_DB_" + tlm_name + ".csv" - with open(tlm_sheet_path, mode='r', encoding='shift_jis') as fh: - reader = csv.reader(fh) - sheet = [row for row in reader] - # pprint.pprint(sheet) - # print(sheet) - tlm_id = sheet[1][2] # テレメIDを取得.マジックナンバーで指定してしまってる. - tlm_db.append({'tlm_id': tlm_id, 'tlm_name': tlm_name, 'data': sheet}) - # tlm_db.append({'tlm_id': tlm_id, 'tlm_name': tlm_name, 'data': 1}) - - tlm_db.sort(key=lambda x: x['tlm_id']) - return tlm_db; - - -def GenerateCmdDef(settings, sgc_db): - output_file_path = settings["c2a_root_dir"] + r"src_user/CmdTlm/" - output_file_name_base = "CommandDefinitions" - - DATA_SART_ROW = 3 - - body_c = "" - body_h = "" - # " cmd_table_[Cmd_CODE_NOP].cmd_func = Cmd_NOP;" - # " Cmd_CODE_NOP = 0x0000," - for i in range(DATA_SART_ROW, len(sgc_db)): - comment = sgc_db[i][0] - name = sgc_db[i][1] - cmd_id = sgc_db[i][3] - if comment == "" and name == "": # CommentもNameも空白なら打ち切り - break - if comment != "": # Comment - continue - # print(name) - cmd_name = name - cmd_code = cmd_name.replace("Cmd_", "Cmd_CODE_") - # print(cmd_name) - # print(cmd_code) - body_c += " cmd_table_[" + cmd_code + "].cmd_func = " + cmd_name + ";\n" - body_h += " " + cmd_code + " = " + cmd_id + ",\n" - - OutputCmdDefC(output_file_path + output_file_name_base + ".c", body_c) - OutputCmdDefH(output_file_path + output_file_name_base + ".h", body_h) - - -def GenerateBctDef(settings, bct_db): - output_file_path = settings["c2a_root_dir"] + r"src_user/CmdTlm/" - output_file_name = "BlockCommandDefinitions.h" - - DATA_SART_ROW = 2 - - body_h = "" - # " cmd_table_[Cmd_CODE_NOP].cmd_func = Cmd_NOP;" - # " Cmd_CODE_NOP = 0x0000," - for i in range(DATA_SART_ROW, len(bct_db)): - comment = bct_db[i][0] - name = bct_db[i][1] - bc_id = bct_db[i][3] - description = bct_db[i][10] - - if comment == "" and name == "": # CommentもNameも空白なら打ち切り - break - - if comment == "**": # New Line Comment - body_h += "\n // " + name + "\n" - elif comment != "": # Comment - body_h += " // " + name + "\n" - else: - # " BC_SL_INITIAL_TO_INITIAL = 0," - if description == "": - body_h += " " + name + " = " + bc_id +",\n" - else: - body_h += " " + name + " = " + bc_id +", // " + description + "\n" - - OutputBctDef(output_file_path + output_file_name, body_h) - - -def GenerateTlmDef(settings, tlm_db): - output_file_path = settings["c2a_root_dir"] + r"src_user/CmdTlm/" - output_file_name_base = "TelemetryDefinitions" - - DATA_SART_ROW = 7 - - body_c = "" - body_h = "" - - # "static int OBC_(unsigned char* contents, int max_len);" - # " OBC_ID = 0x00," - for tlm in tlm_db: - body_c += "static int Tlm_" + tlm['tlm_name'] + "_(unsigned char* contents, int max_len);\n" - body_h += " Tlm_CODE_" + tlm['tlm_name'] + " = " + tlm['tlm_id'] + ",\n" - - body_c += "\n" - body_c += "void TF_load_tlm_table(TlmInfo tlm_table_[TLM_MAX_TLMS])\n" - body_c += "{\n" - for tlm in tlm_db: - # " tlm_table_[OBC_ID].tlm_func = OBC_;" - body_c += " tlm_table_[Tlm_CODE_" + tlm['tlm_name'] + "].tlm_func = Tlm_" + tlm['tlm_name'] + "_;\n" - body_c += "}\n" - - for tlm in tlm_db: - func_code = "" - max_pos = "" - for i in range(DATA_SART_ROW, len(tlm['data'])): - comment = tlm['data'][i][0] - name = tlm['data'][i][1] - var_type = tlm['data'][i][2] - code = tlm['data'][i][3] - pos = tlm['data'][i][4] - if comment == "" and name == "": # CommentもNameも空白なら打ち切り - break - if comment != "": - continue - if name == "": - continue - if var_type == "": - continue - if code == "": - continue - if pos == "": - continue - - code = code.replace("@@", ",") - func_code += " " - if var_type == "int8_t": - func_code += "copy_i8_" - max_pos = int(pos) + 1 - elif var_type == "int16_t": - func_code += "copy_i16_" - max_pos = int(pos) + 2 - elif var_type == "int32_t": - func_code += "copy_i32_" - max_pos = int(pos) + 4 - elif var_type == "uint8_t": - func_code += "copy_u8_" - max_pos = int(pos) + 1 - elif var_type == "uint16_t": - func_code += "copy_u16_" - max_pos = int(pos) + 2 - elif var_type == "uint32_t": - func_code += "copy_u32_" - max_pos = int(pos) + 4 - elif var_type == "float": - func_code += "copy_float_" - max_pos = int(pos) + 4 - elif var_type == "double": - func_code += "copy_double_" - max_pos = int(pos) + 8 - else: - print("Error: Tlm DB Err at " + tlm['tlm_name'], file=sys.stderr) - sys.exit(1) - func_code += "(&contents[" + pos + "], " + code + ");\n" - - body_c += "\n" - body_c += "static int Tlm_" + tlm['tlm_name'] + "_(unsigned char* contents, int max_len)\n" - body_c += "{\n" - body_c += "\n" - body_c += " if (" + str(max_pos) + " > max_len) { return TLM_TOO_SHORT_LEN; }\n" - body_c += "\n" - body_c += "#ifndef FAST_BUILD\n" - body_c += func_code - body_c += "#endif\n" - body_c += "\n" - body_c += " return " + str(max_pos) + ";\n" - body_c += "}\n" - - OutputTlmDefC(output_file_path + output_file_name_base + ".c", body_c) - OutputTlmDefH(output_file_path + output_file_name_base + ".h", body_h) - - -def OutputCmdDefC(file_path, body): - output = "" - output += ''' -#pragma section REPRO -/** - * @file CommandDefinitions.c - * @brief コマンド定義 - * @author 鈴本 遼 - * @date 2020/08/23 - */ -#include "CommandDefinitions.h" -#include "CommandSource.h" - -/* -This pattern is a "separator". -This should not be changed. -This should not be used in other places. -*/ -//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## - -void CA_load_cmd_table(CmdInfo cmd_table_[CMD_MAX_CMDS]) -{ -'''[1:] # 最初の改行を除く - - output += body - - output += ''' -} - -//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## -/* -This pattern is a "separator". -This should not be changed. -This should not be used in other places. -*/ - -#pragma section -'''[1:] # 最初の改行を除く - - - with open(file_path, mode='w', encoding='shift_jis') as fh: - fh.write(output) - - -def OutputCmdDefH(file_path, body): - output = "" - output += ''' -/** - * @file CommandDefinitions.h - * @brief コマンド定義 - * @author 鈴本 遼 - * @date 2020/08/23 - */ -#ifndef COMMAND_DEFINITIONS_H_ -#define COMMAND_DEFINITIONS_H_ - -#include "../../src_core/CmdTlm/CommandAnalyze.h" - -typedef enum -{ -/* -This pattern is a "separator". -This should not be changed. -This should not be used in other places. -*/ -//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## - -'''[1:] # 最初の改行を除く - - output += body - - output += ''' - -//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## -/* -This pattern is a "separator". -This should not be changed. -This should not be used in other places. -*/ - Cmd_CODE_MAX -} CMD_CODE; - -void CA_load_cmd_table(CmdInfo cmd_table_[CMD_MAX_CMDS]); - -#endif -'''[1:] # 最初の改行を除く - - with open(file_path, mode='w', encoding='shift_jis') as fh: - fh.write(output) - - -def OutputBctDef(file_path, body): - output = "" - output += ''' -/** - * @file BlockCommandDefinitions.h - * @brief ブロックコマンド定義 - * @author 鈴本 遼 - * @date 2020/11/14 - */ -#ifndef BLOCK_COMMAND_DEFINITIONS_H_ -#define BLOCK_COMMAND_DEFINITIONS_H_ - -// 登録されるBlockCommandTableのblock番号を規定 -typedef enum -{ -'''[1:] # 最初の改行を除く - - output += body - - output += ''' -} BC_DEFAULT_ID; - -void BC_load_defaults(void); - -#endif -'''[1:] # 最初の改行を除く - - with open(file_path, mode='w', encoding='shift_jis') as fh: - fh.write(output) - - -def OutputTlmDefC(file_path, body): - output = "" - output += ''' -#pragma section REPRO -/** - * @file TelemetryDefinitions.c - * @brief テレメトリ定義 - * @author 鈴本 遼 - * @date 2020/08/23 - */ -#include "TelemetryDefinitions.h" -#include "TelemetrySource.h" - -/* -This pattern is a "separator". -This should not be changed. -This should not be used in other places. -*/ -//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## -'''[1:] # 最初の改行を除く - - output += body - - output += ''' - -//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## -/* -This pattern is a "separator". -This should not be changed. -This should not be used in other places. -*/ - -#pragma section -'''[1:] # 最初の改行を除く - - - with open(file_path, mode='w', encoding='shift_jis') as fh: - fh.write(output) - - -def OutputTlmDefH(file_path, body): - output = "" - output += ''' -/** - * @file TelemetryDefinitions.h - * @brief テレメトリ定義 - * @author 鈴本 遼 - * @date 2020/08/23 - */ -#ifndef TELEMETRY_DEFINITIONS_H_ -#define TELEMETRY_DEFINITIONS_H_ - -#include "../../src_core/CmdTlm/TelemetryFrame.h" - -typedef enum -{ -/* -This pattern is a "separator". -This should not be changed. -This should not be used in other places. -*/ -//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## - -'''[1:] # 最初の改行を除く - - output += body - - output += ''' - -//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## -/* -This pattern is a "separator". -This should not be changed. -This should not be used in other places. -*/ - TLM_CODE_MAX -} TLM_CODE; - -void TF_load_tlm_table(TlmInfo tlm_table_[TLM_MAX_TLMS]); - - -#endif -'''[1:] # 最初の改行を除く - - with open(file_path, mode='w', encoding='shift_jis') as fh: - fh.write(output) - - - if __name__ == '__main__': main() diff --git a/my_mod/cmd_def.py b/my_mod/cmd_def.py new file mode 100644 index 000000000..6e32da121 --- /dev/null +++ b/my_mod/cmd_def.py @@ -0,0 +1,190 @@ +# coding: UTF-8 +""" +cmd def +""" + +import os + +def GenerateCmdDef(settings, sgc_db): + output_file_path = settings["c2a_root_dir"] + r"src_user/CmdTlm/" + output_file_name_base = "CommandDefinitions" + + DATA_SART_ROW = 3 + + body_c = "" + body_h = "" + # " cmd_table_[Cmd_CODE_NOP].cmd_func = Cmd_NOP;" + # " Cmd_CODE_NOP = 0x0000," + for i in range(DATA_SART_ROW, len(sgc_db)): + comment = sgc_db[i][0] + name = sgc_db[i][1] + cmd_id = sgc_db[i][3] + if comment == "" and name == "": # CommentもNameも空白なら打ち切り + break + if comment != "": # Comment + continue + # print(name) + cmd_name = name + cmd_code = cmd_name.replace("Cmd_", "Cmd_CODE_") + # print(cmd_name) + # print(cmd_code) + body_c += " cmd_table_[" + cmd_code + "].cmd_func = " + cmd_name + ";\n" + body_h += " " + cmd_code + " = " + cmd_id + ",\n" + + OutputCmdDefC(output_file_path + output_file_name_base + ".c", body_c) + OutputCmdDefH(output_file_path + output_file_name_base + ".h", body_h) + + +def GenerateBctDef(settings, bct_db): + output_file_path = settings["c2a_root_dir"] + r"src_user/CmdTlm/" + output_file_name = "BlockCommandDefinitions.h" + + DATA_SART_ROW = 2 + + body_h = "" + # " cmd_table_[Cmd_CODE_NOP].cmd_func = Cmd_NOP;" + # " Cmd_CODE_NOP = 0x0000," + for i in range(DATA_SART_ROW, len(bct_db)): + comment = bct_db[i][0] + name = bct_db[i][1] + bc_id = bct_db[i][3] + description = bct_db[i][10] + + if comment == "" and name == "": # CommentもNameも空白なら打ち切り + break + + if comment == "**": # New Line Comment + body_h += "\n // " + name + "\n" + elif comment != "": # Comment + body_h += " // " + name + "\n" + else: + # " BC_SL_INITIAL_TO_INITIAL = 0," + if description == "": + body_h += " " + name + " = " + bc_id +",\n" + else: + body_h += " " + name + " = " + bc_id +", // " + description + "\n" + + OutputBctDef(output_file_path + output_file_name, body_h) + + +def OutputCmdDefC(file_path, body): + output = "" + output += ''' +#pragma section REPRO +/** + * @file CommandDefinitions.c + * @brief コマンド定義 + * @author 鈴本 遼 + * @date 2020/08/23 + */ +#include "CommandDefinitions.h" +#include "CommandSource.h" + +/* +This pattern is a "separator". +This should not be changed. +This should not be used in other places. +*/ +//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## + +void CA_load_cmd_table(CmdInfo cmd_table_[CMD_MAX_CMDS]) +{ +'''[1:] # 最初の改行を除く + + output += body + + output += ''' +} + +//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## +/* +This pattern is a "separator". +This should not be changed. +This should not be used in other places. +*/ + +#pragma section +'''[1:] # 最初の改行を除く + + + with open(file_path, mode='w', encoding='shift_jis') as fh: + fh.write(output) + + +def OutputCmdDefH(file_path, body): + output = "" + output += ''' +/** + * @file CommandDefinitions.h + * @brief コマンド定義 + * @author 鈴本 遼 + * @date 2020/08/23 + */ +#ifndef COMMAND_DEFINITIONS_H_ +#define COMMAND_DEFINITIONS_H_ + +#include "../../src_core/CmdTlm/CommandAnalyze.h" + +typedef enum +{ +/* +This pattern is a "separator". +This should not be changed. +This should not be used in other places. +*/ +//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## + +'''[1:] # 最初の改行を除く + + output += body + + output += ''' + +//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## +/* +This pattern is a "separator". +This should not be changed. +This should not be used in other places. +*/ + Cmd_CODE_MAX +} CMD_CODE; + +void CA_load_cmd_table(CmdInfo cmd_table_[CMD_MAX_CMDS]); + +#endif +'''[1:] # 最初の改行を除く + + with open(file_path, mode='w', encoding='shift_jis') as fh: + fh.write(output) + + +def OutputBctDef(file_path, body): + output = "" + output += ''' +/** + * @file BlockCommandDefinitions.h + * @brief ブロックコマンド定義 + * @author 鈴本 遼 + * @date 2020/11/14 + */ +#ifndef BLOCK_COMMAND_DEFINITIONS_H_ +#define BLOCK_COMMAND_DEFINITIONS_H_ + +// 登録されるBlockCommandTableのblock番号を規定 +typedef enum +{ +'''[1:] # 最初の改行を除く + + output += body + + output += ''' +} BC_DEFAULT_ID; + +void BC_load_defaults(void); + +#endif +'''[1:] # 最初の改行を除く + + with open(file_path, mode='w', encoding='shift_jis') as fh: + fh.write(output) + diff --git a/my_mod/load_db.py b/my_mod/load_db.py new file mode 100644 index 000000000..2874d7648 --- /dev/null +++ b/my_mod/load_db.py @@ -0,0 +1,55 @@ +# coding: UTF-8 +""" +DB読み込み +""" + +import os +import csv +import re # 正規表現 + +def LoadCmdCSV(settings): + cmd_db_path = settings["c2a_root_dir"] + r"src_user/Settings/CmdTlm/DataBase/CMD_DB/" + sgc_db_path = cmd_db_path + settings["db_prefix"] + "_CMD_DB_CMD_DB.csv" # single cmd + bct_db_path = cmd_db_path + settings["db_prefix"] + "_CMD_DB_BCT.csv" # block cmd table + + with open(sgc_db_path, mode='r', encoding='shift_jis') 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: + reader = csv.reader(fh) + bct_db = [row for row in reader] + + # print(sgc_db) + # print(bct_db) + return {'sgc': sgc_db, 'bct': bct_db} + + +def LoadTlmCSV(settings): + tlm_db_path = settings["c2a_root_dir"] + r"src_user/Settings/CmdTlm/DataBase/TLM_DB/calced_data/" + + tlm_names = [file for file in os.listdir(tlm_db_path) if file.endswith(".csv")] + regex = r"^" + settings["db_prefix"] + "_TLM_DB_" + tlm_names = [re.sub(regex, "", file) for file in tlm_names] + tlm_names = [re.sub(".csv$", "", file) for file in tlm_names] + # pprint.pprint(tlm_names) + # print(len(tlm_names)) + + tlm_db = [] + + for tlm_name in tlm_names: + tlm_sheet_path = tlm_db_path + settings["db_prefix"] + "_TLM_DB_" + tlm_name + ".csv" + with open(tlm_sheet_path, mode='r', encoding='shift_jis') as fh: + reader = csv.reader(fh) + sheet = [row for row in reader] + # pprint.pprint(sheet) + # print(sheet) + tlm_id = sheet[1][2] # テレメIDを取得.マジックナンバーで指定してしまってる. + tlm_db.append({'tlm_id': tlm_id, 'tlm_name': tlm_name, 'data': sheet}) + # tlm_db.append({'tlm_id': tlm_id, 'tlm_name': tlm_name, 'data': 1}) + + tlm_db.sort(key=lambda x: x['tlm_id']) + + # 重複チェックをする + + return tlm_db; + diff --git a/my_mod/tlm_def.py b/my_mod/tlm_def.py new file mode 100644 index 000000000..ab658a1cc --- /dev/null +++ b/my_mod/tlm_def.py @@ -0,0 +1,185 @@ +# coding: UTF-8 +""" +tlm def +""" + +import os + +def GenerateTlmDef(settings, tlm_db): + output_file_path = settings["c2a_root_dir"] + r"src_user/CmdTlm/" + output_file_name_base = "TelemetryDefinitions" + + DATA_SART_ROW = 7 + + body_c = "" + body_h = "" + + # "static int OBC_(unsigned char* contents, int max_len);" + # " OBC_ID = 0x00," + for tlm in tlm_db: + body_c += "static int Tlm_" + tlm['tlm_name'] + "_(unsigned char* contents, int max_len);\n" + body_h += " Tlm_CODE_" + tlm['tlm_name'] + " = " + tlm['tlm_id'] + ",\n" + + body_c += "\n" + body_c += "void TF_load_tlm_table(TlmInfo tlm_table_[TLM_MAX_TLMS])\n" + body_c += "{\n" + for tlm in tlm_db: + # " tlm_table_[OBC_ID].tlm_func = OBC_;" + body_c += " tlm_table_[Tlm_CODE_" + tlm['tlm_name'] + "].tlm_func = Tlm_" + tlm['tlm_name'] + "_;\n" + body_c += "}\n" + + for tlm in tlm_db: + func_code = "" + max_pos = "" + for i in range(DATA_SART_ROW, len(tlm['data'])): + comment = tlm['data'][i][0] + name = tlm['data'][i][1] + var_type = tlm['data'][i][2] + code = tlm['data'][i][3] + pos = tlm['data'][i][4] + if comment == "" and name == "": # CommentもNameも空白なら打ち切り + break + if comment != "": + continue + if name == "": + continue + if var_type == "": + continue + if code == "": + continue + if pos == "": + continue + + code = code.replace("@@", ",") + func_code += " " + if var_type == "int8_t": + func_code += "copy_i8_" + max_pos = int(pos) + 1 + elif var_type == "int16_t": + func_code += "copy_i16_" + max_pos = int(pos) + 2 + elif var_type == "int32_t": + func_code += "copy_i32_" + max_pos = int(pos) + 4 + elif var_type == "uint8_t": + func_code += "copy_u8_" + max_pos = int(pos) + 1 + elif var_type == "uint16_t": + func_code += "copy_u16_" + max_pos = int(pos) + 2 + elif var_type == "uint32_t": + func_code += "copy_u32_" + max_pos = int(pos) + 4 + elif var_type == "float": + func_code += "copy_float_" + max_pos = int(pos) + 4 + elif var_type == "double": + func_code += "copy_double_" + max_pos = int(pos) + 8 + else: + print("Error: Tlm DB Err at " + tlm['tlm_name'], file=sys.stderr) + sys.exit(1) + func_code += "(&contents[" + pos + "], " + code + ");\n" + + body_c += "\n" + body_c += "static int Tlm_" + tlm['tlm_name'] + "_(unsigned char* contents, int max_len)\n" + body_c += "{\n" + body_c += "\n" + body_c += " if (" + str(max_pos) + " > max_len) { return TLM_TOO_SHORT_LEN; }\n" + body_c += "\n" + body_c += "#ifndef FAST_BUILD\n" + body_c += func_code + body_c += "#endif\n" + body_c += "\n" + body_c += " return " + str(max_pos) + ";\n" + body_c += "}\n" + + OutputTlmDefC(output_file_path + output_file_name_base + ".c", body_c) + OutputTlmDefH(output_file_path + output_file_name_base + ".h", body_h) + + +def OutputTlmDefC(file_path, body): + output = "" + output += ''' +#pragma section REPRO +/** + * @file TelemetryDefinitions.c + * @brief テレメトリ定義 + * @author 鈴本 遼 + * @date 2020/08/23 + */ +#include "TelemetryDefinitions.h" +#include "TelemetrySource.h" + +/* +This pattern is a "separator". +This should not be changed. +This should not be used in other places. +*/ +//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## +'''[1:] # 最初の改行を除く + + output += body + + output += ''' + +//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## +/* +This pattern is a "separator". +This should not be changed. +This should not be used in other places. +*/ + +#pragma section +'''[1:] # 最初の改行を除く + + with open(file_path, mode='w', encoding='shift_jis') as fh: + fh.write(output) + + +def OutputTlmDefH(file_path, body): + output = "" + output += ''' +/** + * @file TelemetryDefinitions.h + * @brief テレメトリ定義 + * @author 鈴本 遼 + * @date 2020/08/23 + */ +#ifndef TELEMETRY_DEFINITIONS_H_ +#define TELEMETRY_DEFINITIONS_H_ + +#include "../../src_core/CmdTlm/TelemetryFrame.h" + +typedef enum +{ +/* +This pattern is a "separator". +This should not be changed. +This should not be used in other places. +*/ +//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## + +'''[1:] # 最初の改行を除く + + output += body + + output += ''' + +//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## +/* +This pattern is a "separator". +This should not be changed. +This should not be used in other places. +*/ + TLM_CODE_MAX +} TLM_CODE; + +void TF_load_tlm_table(TlmInfo tlm_table_[TLM_MAX_TLMS]); + +#endif +'''[1:] # 最初の改行を除く + + with open(file_path, mode='w', encoding='shift_jis') as fh: + fh.write(output) + diff --git a/settings.json b/settings.json index 36b539c08..0d8b19d48 100644 --- a/settings.json +++ b/settings.json @@ -2,7 +2,7 @@ "c2a_root_dir" : "../../c2a_user_oss/SH7254R_C2A/", "db_prefix" : "ISSL6U_MOBC", "is_generated_sib" : 0, - "is_main_obc" : 0, + "is_main_obc" : 1, "other_obc_data" : [ { "name" : "AOBC", From c13d2c86870c269d7b817ba5cb8d14e3e5b88201 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sat, 13 Feb 2021 23:35:01 +0900 Subject: [PATCH 024/141] update for tobc cmd code --- GenerateC2ACode.py | 8 +++- my_mod/cmd_def.py | 96 ++++++++++++++++++++++++++++++++++++++++++++++ my_mod/load_db.py | 57 +++++++++++++++++++++------ settings.json | 2 + 4 files changed, 150 insertions(+), 13 deletions(-) diff --git a/GenerateC2ACode.py b/GenerateC2ACode.py index fea59e62f..d270fa31d 100644 --- a/GenerateC2ACode.py +++ b/GenerateC2ACode.py @@ -29,8 +29,8 @@ def main(): settings = json.load(fh) # print(settings["c2a_root_dir"]); - cmd_db = my_mod.load_db.LoadCmdCSV(settings) - tlm_db = my_mod.load_db.LoadTlmCSV(settings) + cmd_db = my_mod.load_db.LoadCmdDb(settings) + tlm_db = my_mod.load_db.LoadTlmDb(settings) # pprint.pprint(cmd_db) # pprint.pprint(tlm_db) # print(tlm_db) @@ -38,6 +38,10 @@ def main(): my_mod.cmd_def.GenerateCmdDef(settings, cmd_db['sgc']) my_mod.cmd_def.GenerateBctDef(settings, cmd_db['bct']) my_mod.tlm_def.GenerateTlmDef(settings, tlm_db) + + if settings["is_main_obc"]: + my_mod.cmd_def.GenerateOtherObcCmdDef(settings, cmd_db['other_obc']) + if settings["is_generated_sib"]: my_mod.gstos.GenerateGstosFiles(settings, cmd_db['sgc'], tlm_db) diff --git a/my_mod/cmd_def.py b/my_mod/cmd_def.py index 6e32da121..7933fdabb 100644 --- a/my_mod/cmd_def.py +++ b/my_mod/cmd_def.py @@ -4,6 +4,7 @@ """ import os +import pprint def GenerateCmdDef(settings, sgc_db): output_file_path = settings["c2a_root_dir"] + r"src_user/CmdTlm/" @@ -67,6 +68,41 @@ def GenerateBctDef(settings, bct_db): OutputBctDef(output_file_path + output_file_name, body_h) +def GenerateOtherObcCmdDef(settings, other_obc_dbs): + # pprint.pprint(other_obc_dbs) + DATA_SART_ROW = 3 + for i in range(len(settings["other_obc_data"])): + if not settings["other_obc_data"][i]["is_enable"]: + continue + obc_name = settings["other_obc_data"][i]["name"] + name_upper = obc_name.upper() + name_lower = obc_name.lower() + name_capit = obc_name.capitalize() + # print(name_upper) + # print(name_lower) + # print(name_capit) + sgc_db = other_obc_dbs[obc_name] + # pprint.pprint(sgc_db) + + body_h = "" + # " TOBC_Cmd_CODE_NOP = 0x0000," + for j in range(DATA_SART_ROW, len(sgc_db)): + comment = sgc_db[j][0] + name = sgc_db[j][1] + cmd_id = sgc_db[j][3] + if comment == "" and name == "": # CommentもNameも空白なら打ち切り + break + if comment != "": # Comment + continue + # print(name) + cmd_name = name + cmd_code = cmd_name.replace("Cmd_", name_upper+"_Cmd_CODE_") + body_h += " " + cmd_code + " = " + cmd_id + ",\n" + # print(body_h) + output_file_path = settings["c2a_root_dir"] + r"src_user/Drivers/" + settings["other_obc_data"][i]["driver_path"] + name_capit + "CommandDefinitions.h" + OutputOtherObcCmdDefH(output_file_path, obc_name, body_h) + + def OutputCmdDefC(file_path, body): output = "" output += ''' @@ -188,3 +224,63 @@ def OutputBctDef(file_path, body): with open(file_path, mode='w', encoding='shift_jis') as fh: fh.write(output) + +def OutputOtherObcCmdDefH(file_path, name, body): + name_upper = name.upper() + name_lower = name.lower() + name_capit = name.capitalize() + + output = "" + output += ''' +/** +'''[1:] # 最初の改行を除く + + output += " * @file " + name_capit + "CommandDefinitions.h\n" + + output += ''' + * @brief コマンド定義 + * @author 鈴本 遼 + * @date 2020/08/23 + */ +/** +'''[1:] # 最初の改行を除く + + output += "#ifndef " + name_upper + "_COMMAND_DEFINITIONS_H_\n" + output += "#define " + name_upper + "_COMMAND_DEFINITIONS_H_\n" + + output += ''' + +typedef enum +{ +/* +This pattern is a "separator". +This should not be changed. +This should not be used in other places. +*/ +//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## + +'''[1:] # 最初の改行を除く + + output += body + + output += ''' + +//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## +/* +This pattern is a "separator". +This should not be changed. +This should not be used in other places. +*/ +'''[1:] # 最初の改行を除く + + output += " " + name_upper + "_Cmd_CODE_MAX\n" + output += "} " + name_upper + "_CMD_CODE;\n" + + output += ''' + +#endif +'''[1:] # 最初の改行を除く + + with open(file_path, mode='w', encoding='shift_jis') as fh: + fh.write(output) + diff --git a/my_mod/load_db.py b/my_mod/load_db.py index 2874d7648..db3906fb1 100644 --- a/my_mod/load_db.py +++ b/my_mod/load_db.py @@ -6,11 +6,25 @@ import os import csv import re # 正規表現 +import pprint -def LoadCmdCSV(settings): +def LoadCmdDb(settings): cmd_db_path = settings["c2a_root_dir"] + r"src_user/Settings/CmdTlm/DataBase/CMD_DB/" - sgc_db_path = cmd_db_path + settings["db_prefix"] + "_CMD_DB_CMD_DB.csv" # single cmd - bct_db_path = cmd_db_path + settings["db_prefix"] + "_CMD_DB_BCT.csv" # block cmd table + + sgc_db, bct_db = LoadCmdCSV(cmd_db_path, settings["db_prefix"]) + + other_obc_dbs = [] + if settings["is_main_obc"]: + other_obc_dbs = LoadOtherObcCmd(settings); + + # print(sgc_db) + # print(bct_db) + return {'sgc': sgc_db, 'bct': bct_db, 'other_obc': other_obc_dbs} + + +def LoadCmdCSV(cmd_db_path, db_prefix): + 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: reader = csv.reader(fh) @@ -19,16 +33,22 @@ def LoadCmdCSV(settings): reader = csv.reader(fh) bct_db = [row for row in reader] - # print(sgc_db) - # print(bct_db) - return {'sgc': sgc_db, 'bct': bct_db} + return sgc_db, bct_db -def LoadTlmCSV(settings): +def LoadTlmDb(settings): tlm_db_path = settings["c2a_root_dir"] + r"src_user/Settings/CmdTlm/DataBase/TLM_DB/calced_data/" + tlm_db = LoadTlmCSV(tlm_db_path, settings["db_prefix"]) + + # 重複チェックをする + + return tlm_db; + + +def LoadTlmCSV(tlm_db_path, db_prefix): tlm_names = [file for file in os.listdir(tlm_db_path) if file.endswith(".csv")] - regex = r"^" + settings["db_prefix"] + "_TLM_DB_" + regex = r"^" + db_prefix + "_TLM_DB_" tlm_names = [re.sub(regex, "", file) for file in tlm_names] tlm_names = [re.sub(".csv$", "", file) for file in tlm_names] # pprint.pprint(tlm_names) @@ -37,7 +57,7 @@ def LoadTlmCSV(settings): tlm_db = [] for tlm_name in tlm_names: - tlm_sheet_path = tlm_db_path + settings["db_prefix"] + "_TLM_DB_" + tlm_name + ".csv" + 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: reader = csv.reader(fh) sheet = [row for row in reader] @@ -49,7 +69,22 @@ def LoadTlmCSV(settings): tlm_db.sort(key=lambda x: x['tlm_id']) - # 重複チェックをする - return tlm_db; + +def LoadOtherObcCmd(settings): + other_obc_dbs = {} + + for i in range(len(settings["other_obc_data"])): + 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"]) + # other_obc_dbs.append(sgc_db) + other_obc_dbs[settings["other_obc_data"][i]["name"]] = sgc_db + # print(i) + + # pprint.pprint(settings["other_obc_data"]) + # pprint.pprint(other_obc_dbs) + return other_obc_dbs + diff --git a/settings.json b/settings.json index 0d8b19d48..c7a4afb41 100644 --- a/settings.json +++ b/settings.json @@ -9,6 +9,7 @@ "is_enable" : 0, "db_prefix" : "ISSL6U_AOBC", "db_path" : "../../aobc_tlmcmd/", + "driver_path" : "ADCS/", "tlm_id_range" : ["0x90", "0xc0"] }, { @@ -16,6 +17,7 @@ "is_enable" : 1, "db_prefix" : "ISSL6U_TOBC", "db_path" : "../../tobc_tlmcmd/", + "driver_path" : "THERMAL/", "tlm_id_range" : ["0xc0", "0xf0"] } ] From 85e0c8355b8e70e8a0c981405a911ec50d00b278 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sat, 13 Feb 2021 23:35:34 +0900 Subject: [PATCH 025/141] Update README.md --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dbf9474d9..e6b152cb8 100644 --- a/README.md +++ b/README.md @@ -29,14 +29,16 @@ $ python GenerateC2ACode.py "is_enable" : 0, "db_prefix" : "ISSL6U_AOBC", "db_path" : "../../aobc_tlmcmd/", - "tlm_id_range" : ["0x90", "0xc0"], + "driver_path" : "ADCS/", + "tlm_id_range" : ["0x90", "0xc0"] }, { "name" : "TOBC", "is_enable" : 1, "db_prefix" : "ISSL6U_TOBC", "db_path" : "../../tobc_tlmcmd/", - "tlm_id_range" : ["0xc0", "0xf0"], + "driver_path" : "THERMAL/", + "tlm_id_range" : ["0xc0", "0xf0"] } ] } From b10d73112998eb47ae8a7d5ae9c269b5a0f07bd9 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sat, 13 Feb 2021 23:37:23 +0900 Subject: [PATCH 026/141] fix --- my_mod/cmd_def.py | 1 - 1 file changed, 1 deletion(-) diff --git a/my_mod/cmd_def.py b/my_mod/cmd_def.py index 7933fdabb..8c0a30e71 100644 --- a/my_mod/cmd_def.py +++ b/my_mod/cmd_def.py @@ -242,7 +242,6 @@ def OutputOtherObcCmdDefH(file_path, name, body): * @author 鈴本 遼 * @date 2020/08/23 */ -/** '''[1:] # 最初の改行を除く output += "#ifndef " + name_upper + "_COMMAND_DEFINITIONS_H_\n" From db0e9007aa14e2c968021c331ef8045d28eee701 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sun, 14 Feb 2021 00:00:34 +0900 Subject: [PATCH 027/141] update for tobc tlm code --- GenerateC2ACode.py | 5 +-- my_mod/load_db.py | 25 +++++++++++++-- my_mod/tlm_def.py | 80 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 5 deletions(-) diff --git a/GenerateC2ACode.py b/GenerateC2ACode.py index d270fa31d..bd5499195 100644 --- a/GenerateC2ACode.py +++ b/GenerateC2ACode.py @@ -37,13 +37,14 @@ def main(): my_mod.cmd_def.GenerateCmdDef(settings, cmd_db['sgc']) my_mod.cmd_def.GenerateBctDef(settings, cmd_db['bct']) - my_mod.tlm_def.GenerateTlmDef(settings, tlm_db) + my_mod.tlm_def.GenerateTlmDef(settings, tlm_db['tlm']) if settings["is_main_obc"]: my_mod.cmd_def.GenerateOtherObcCmdDef(settings, cmd_db['other_obc']) + my_mod.tlm_def.GenerateOtherObcTlmDef(settings, tlm_db['other_obc']) if settings["is_generated_sib"]: - my_mod.gstos.GenerateGstosFiles(settings, cmd_db['sgc'], tlm_db) + my_mod.gstos.GenerateGstosFiles(settings, cmd_db['sgc'], tlm_db['tlm']) print("Completed!") sys.exit(0) diff --git a/my_mod/load_db.py b/my_mod/load_db.py index db3906fb1..db9491435 100644 --- a/my_mod/load_db.py +++ b/my_mod/load_db.py @@ -13,7 +13,7 @@ def LoadCmdDb(settings): sgc_db, bct_db = LoadCmdCSV(cmd_db_path, settings["db_prefix"]) - other_obc_dbs = [] + other_obc_dbs = {} if settings["is_main_obc"]: other_obc_dbs = LoadOtherObcCmd(settings); @@ -41,9 +41,13 @@ def LoadTlmDb(settings): tlm_db = LoadTlmCSV(tlm_db_path, settings["db_prefix"]) - # 重複チェックをする + other_obc_dbs = {} + if settings["is_main_obc"]: + other_obc_dbs = LoadOtherObcTlm(settings); - return tlm_db; + # TODO: 重複チェックをする + + return {'tlm': tlm_db, 'other_obc': other_obc_dbs} def LoadTlmCSV(tlm_db_path, db_prefix): @@ -88,3 +92,18 @@ def LoadOtherObcCmd(settings): # pprint.pprint(other_obc_dbs) return other_obc_dbs + +def LoadOtherObcTlm(settings): + other_obc_dbs = {} + + for i in range(len(settings["other_obc_data"])): + if not settings["other_obc_data"][i]["is_enable"]: + continue + tlm_db_path = settings["other_obc_data"][i]["db_path"] + r"TLM_DB/" + + tlm_db = LoadTlmCSV(tlm_db_path, settings["other_obc_data"][i]["db_prefix"]) + other_obc_dbs[settings["other_obc_data"][i]["name"]] = tlm_db + + # pprint.pprint(other_obc_dbs) + return other_obc_dbs + diff --git a/my_mod/tlm_def.py b/my_mod/tlm_def.py index ab658a1cc..017e945f4 100644 --- a/my_mod/tlm_def.py +++ b/my_mod/tlm_def.py @@ -98,6 +98,27 @@ def GenerateTlmDef(settings, tlm_db): OutputTlmDefH(output_file_path + output_file_name_base + ".h", body_h) +def GenerateOtherObcTlmDef(settings, other_obc_dbs): + DATA_SART_ROW = 7 + for i in range(len(settings["other_obc_data"])): + if not settings["other_obc_data"][i]["is_enable"]: + continue + obc_name = settings["other_obc_data"][i]["name"] + name_upper = obc_name.upper() + name_lower = obc_name.lower() + name_capit = obc_name.capitalize() + + tlm_db = other_obc_dbs[obc_name] + + body_h = "" + # " TOBC_Tlm_CODE_HK = 0xf0," + for tlm in tlm_db: + body_h += " " + name_upper + "_Tlm_CODE_" + tlm['tlm_name'] + " = " + tlm['tlm_id'] + ",\n" + output_file_path = settings["c2a_root_dir"] + r"src_user/Drivers/" + settings["other_obc_data"][i]["driver_path"] + name_capit + "TelemetryDefinitions.h" + OutputOtherObcTlmDefH(output_file_path, obc_name, body_h) + + + def OutputTlmDefC(file_path, body): output = "" output += ''' @@ -183,3 +204,62 @@ def OutputTlmDefH(file_path, body): with open(file_path, mode='w', encoding='shift_jis') as fh: fh.write(output) + +def OutputOtherObcTlmDefH(file_path, name, body): + name_upper = name.upper() + name_lower = name.lower() + name_capit = name.capitalize() + + output = "" + output += ''' +/** +'''[1:] # 最初の改行を除く + + output += " * @file " + name_capit + "TelemetryDefinitions.h\n" + + output += ''' + * @brief テレメトリ定義 + * @author 鈴本 遼 + * @date 2020/08/23 + */ +'''[1:] # 最初の改行を除く + + output += "#ifndef " + name_upper + "_TELEMETRY_DEFINITIONS_H_\n" + output += "#define " + name_upper + "_TELEMETRY_DEFINITIONS_H_\n" + + output += ''' + +typedef enum +{ +/* +This pattern is a "separator". +This should not be changed. +This should not be used in other places. +*/ +//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## + +'''[1:] # 最初の改行を除く + + output += body + + output += ''' + +//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## +/* +This pattern is a "separator". +This should not be changed. +This should not be used in other places. +*/ +'''[1:] # 最初の改行を除く + + output += " " + name_upper + "_TLM_CODE_MAX\n" + output += "} " + name_upper + "_TLM_CODE;\n" + + output += ''' + +#endif +'''[1:] # 最初の改行を除く + + with open(file_path, mode='w', encoding='shift_jis') as fh: + fh.write(output) + From f09f4d544359e9d4bcbaa42a2906814b0122f0c4 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sun, 14 Feb 2021 00:02:17 +0900 Subject: [PATCH 028/141] fix settings and readme --- README.md | 5 ++++- settings.json | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e6b152cb8..837016c18 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,10 @@ $ python GenerateC2ACode.py ## 設定 `settings.json` にて記述する. -現在 `is_main_obc` は,未だ仕様未確定なため, `0` とすること! +現在 `is_main_obc` は,未だ仕様未確定なため, `0` とすること! +`1` とした場合,現在は以下のみ生成される +- TobcCommandDefinitions.h +- TobcTelemetryDefinitions.h ``` { diff --git a/settings.json b/settings.json index c7a4afb41..d91a0987c 100644 --- a/settings.json +++ b/settings.json @@ -2,7 +2,7 @@ "c2a_root_dir" : "../../c2a_user_oss/SH7254R_C2A/", "db_prefix" : "ISSL6U_MOBC", "is_generated_sib" : 0, - "is_main_obc" : 1, + "is_main_obc" : 0, "other_obc_data" : [ { "name" : "AOBC", From 9900d38250d2774fac45f09c5330049b5f296a26 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sun, 14 Feb 2021 01:20:12 +0900 Subject: [PATCH 029/141] fix path --- README.md | 2 +- settings.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 837016c18..941ef8cdb 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ $ python GenerateC2ACode.py "name" : "AOBC", "is_enable" : 0, "db_prefix" : "ISSL6U_AOBC", - "db_path" : "../../aobc_tlmcmd/", + "db_path" : "../../c2a_issl6u_aobc//src/src_user/Settings/CmdTlm/DataBase/", "driver_path" : "ADCS/", "tlm_id_range" : ["0x90", "0xc0"] }, diff --git a/settings.json b/settings.json index d91a0987c..c6d020eb7 100644 --- a/settings.json +++ b/settings.json @@ -8,7 +8,7 @@ "name" : "AOBC", "is_enable" : 0, "db_prefix" : "ISSL6U_AOBC", - "db_path" : "../../aobc_tlmcmd/", + "db_path" : "../../c2a_issl6u_aobc//src/src_user/Settings/CmdTlm/DataBase/", "driver_path" : "ADCS/", "tlm_id_range" : ["0x90", "0xc0"] }, From 6ad875e00903e58e15d33682551f628434f7e3f4 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sun, 14 Feb 2021 09:03:51 +0900 Subject: [PATCH 030/141] add buffer template --- GenerateC2ACode.py | 2 + my_mod/tlm_buffer.py | 147 +++++++++++++++++++++++++++++++++++++++++++ my_mod/tlm_def.py | 1 - settings.json | 6 +- 4 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 my_mod/tlm_buffer.py diff --git a/GenerateC2ACode.py b/GenerateC2ACode.py index bd5499195..53a5afa25 100644 --- a/GenerateC2ACode.py +++ b/GenerateC2ACode.py @@ -10,6 +10,7 @@ import my_mod.load_db import my_mod.cmd_def import my_mod.tlm_def +import my_mod.tlm_buffer import my_mod.gstos @@ -42,6 +43,7 @@ def main(): if settings["is_main_obc"]: my_mod.cmd_def.GenerateOtherObcCmdDef(settings, cmd_db['other_obc']) my_mod.tlm_def.GenerateOtherObcTlmDef(settings, tlm_db['other_obc']) + my_mod.tlm_buffer.GenerateTlmBuffer(settings, tlm_db['other_obc']) if settings["is_generated_sib"]: my_mod.gstos.GenerateGstosFiles(settings, cmd_db['sgc'], tlm_db['tlm']) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py new file mode 100644 index 000000000..d358c243b --- /dev/null +++ b/my_mod/tlm_buffer.py @@ -0,0 +1,147 @@ +# coding: UTF-8 +""" +tlm buffer +""" + +import os + +def GenerateTlmBuffer(settings, other_obc_dbs): + DATA_SART_ROW = 7 + + for i in range(len(settings["other_obc_data"])): + if not settings["other_obc_data"][i]["is_enable"]: + continue + obc_name = settings["other_obc_data"][i]["name"] + name_upper = obc_name.upper() + name_lower = obc_name.lower() + name_capit = obc_name.capitalize() + driver_type = settings["other_obc_data"][i]["driver_type"] + driver_name = settings["other_obc_data"][i]["driver_name"] + contents_len = settings["other_obc_data"][i]["tlm_max_contents_len"] + + tlm_db = other_obc_dbs[obc_name] + + body_c = "" + body_h = "" + + body_h += "typedef struct {\n" + + for tlm in tlm_db: + tlm_name = tlm['tlm_name'] + tlm_name_upper = tlm_name.upper() + tlm_name_lower = tlm_name.lower() + body_h += " uint8_t " + tlm_name_lower + "[" + str(contents_len) + "];\n" + body_c += "static DRIVER_SUPER_ERR_CODE " + name_upper + "_analyze_tlm_" + tlm_name_lower + "_(DriverSuperStreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ");\n" + + body_h += "} " + name_upper + "_Buffer;\n" + body_h += "\n" + body_h += "extern const " + name_upper + "_Buffer* " + name_lower + "_buffer;\n" + body_h += "\n" + body_h += "DRIVER_SUPER_ERR_CODE " + name_upper + "_buffer_tlm_contents(DriverSuperStreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ");\n" + + + body_c += "\n" + body_c += "DRIVER_SUPER_ERR_CODE " + name_upper + "_buffer_tlm_contents(DriverSuperStreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ")\n" + body_c += "{\n" + body_c += " switch (tlm_id)\n" + body_c += " {\n" + for tlm in tlm_db: + tlm_name = tlm['tlm_name'] + tlm_name_upper = tlm_name.upper() + tlm_name_lower = tlm_name.lower() + body_c += " case " + name_upper + "_Tlm_CODE_" + tlm_name_upper + ":\n" + body_c += " return " + name_upper + "_analyze_tlm_" + tlm_name_lower + "_(p_stream_config, " + driver_name + ")\n" + body_c += " default:\n" + body_c += " " + settings["other_obc_data"][i]["code_when_tlm_not_found"] + "\n" + body_c += " return DRIVER_SUPER_ERR_CODE_OK;\n" + body_c += " }\n" + body_c += "}\n" + body_c += "\n" + for tlm in tlm_db: + tlm_name = tlm['tlm_name'] + tlm_name_upper = tlm_name.upper() + tlm_name_lower = tlm_name.lower() + body_c += "static DRIVER_SUPER_ERR_CODE " + name_upper + "_analyze_tlm_" + tlm_name_lower + "_(DriverSuperStreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ")\n" + body_c += "{\n" + body_c += " // [TODO] フレームの中身をパースしてMOBCでもろもろにアクセスするためのコード\n" + body_c += " return DRIVER_SUPER_ERR_CODE_OK;\n" + body_c += "}\n" + body_c += "\n" + + + output_file_path = settings["c2a_root_dir"] + r"src_user/Drivers/" + settings["other_obc_data"][i]["driver_path"]; + OutputTlmBufferC(output_file_path + name_capit + "TelemetryBuffer.c", obc_name, body_c) + OutputTlmBufferH(output_file_path + name_capit + "TelemetryBuffer.h", obc_name, body_h) + + +def OutputTlmBufferC(file_path, name, body): + name_upper = name.upper() + name_lower = name.lower() + name_capit = name.capitalize() + + output = "" + output += ''' +#pragma section REPRO +/** +'''[1:] # 最初の改行を除く + + output += " * @file " + name_capit + "TelemetryBuffer.c\n" + + output += ''' + * @brief テレメトリバッファー(テレメ中継) + * @author 鈴本 遼 + * @date 2021/02/14 + */ +'''[1:] # 最初の改行を除く + + output += "\n" + output += '#include "./' + name_capit + 'TelemetryDefinitions.h"\n' + output += '#include "./' + name_capit + 'TelemetryBuffer.h"\n' + output += "\n" + + output += body + + output += ''' + +#pragma section +'''[1:] # 最初の改行を除く + + with open(file_path, mode='w', encoding='shift_jis') as fh: + fh.write(output) + + +def OutputTlmBufferH(file_path, name, body): + name_upper = name.upper() + name_lower = name.lower() + name_capit = name.capitalize() + + output = "" + output += ''' +/** +'''[1:] # 最初の改行を除く + + output += " * @file " + name_capit + "TelemetryBuffer.h\n" + + output += ''' + * @brief テレメトリバッファー(テレメ中継) + * @author 鈴本 遼 + * @date 2021/02/14 + */ +'''[1:] # 最初の改行を除く + + output += "#ifndef " + name_upper + "_TELEMETRY_BUFFER_H_\n" + output += "#define " + name_upper + "_TELEMETRY_BUFFER_H_\n" + output += "\n" + output += '#include "./' + name_upper + '.h"\n' + + output += "\n" + + output += body + + output += ''' + +#endif +'''[1:] # 最初の改行を除く + + with open(file_path, mode='w', encoding='shift_jis') as fh: + fh.write(output) diff --git a/my_mod/tlm_def.py b/my_mod/tlm_def.py index 017e945f4..e52518f67 100644 --- a/my_mod/tlm_def.py +++ b/my_mod/tlm_def.py @@ -99,7 +99,6 @@ def GenerateTlmDef(settings, tlm_db): def GenerateOtherObcTlmDef(settings, other_obc_dbs): - DATA_SART_ROW = 7 for i in range(len(settings["other_obc_data"])): if not settings["other_obc_data"][i]["is_enable"]: continue diff --git a/settings.json b/settings.json index c6d020eb7..279b451a0 100644 --- a/settings.json +++ b/settings.json @@ -2,7 +2,7 @@ "c2a_root_dir" : "../../c2a_user_oss/SH7254R_C2A/", "db_prefix" : "ISSL6U_MOBC", "is_generated_sib" : 0, - "is_main_obc" : 0, + "is_main_obc" : 1, "other_obc_data" : [ { "name" : "AOBC", @@ -17,7 +17,11 @@ "is_enable" : 1, "db_prefix" : "ISSL6U_TOBC", "db_path" : "../../tobc_tlmcmd/", + "tlm_max_contents_len" : 512, "driver_path" : "THERMAL/", + "driver_type" : "TOBC_Driver", + "driver_name" : "tobc", + "code_when_tlm_not_found" : "tobc->info.comm.rx_err_code = TOBC_RX_ERR_CODE_TLM_NOT_FOUND;", "tlm_id_range" : ["0xc0", "0xf0"] } ] From 1ca3d831d16df1c34e804023d1ccb76bc140a657 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sun, 14 Feb 2021 18:16:12 +0900 Subject: [PATCH 031/141] first version of generate tlm buffer --- my_mod/cmd_def.py | 30 +++++-------- my_mod/tlm_buffer.py | 103 ++++++++++++++++++++++++------------------- my_mod/tlm_def.py | 29 +++++------- 3 files changed, 79 insertions(+), 83 deletions(-) diff --git a/my_mod/cmd_def.py b/my_mod/cmd_def.py index 8c0a30e71..0a32339f3 100644 --- a/my_mod/cmd_def.py +++ b/my_mod/cmd_def.py @@ -110,6 +110,7 @@ def OutputCmdDefC(file_path, body): /** * @file CommandDefinitions.c * @brief コマンド定義 + * @note このコードは自動生成されています! * @author 鈴本 遼 * @date 2020/08/23 */ @@ -153,6 +154,7 @@ def OutputCmdDefH(file_path, body): /** * @file CommandDefinitions.h * @brief コマンド定義 + * @note このコードは自動生成されています! * @author 鈴本 遼 * @date 2020/08/23 */ @@ -200,6 +202,7 @@ def OutputBctDef(file_path, body): /** * @file BlockCommandDefinitions.h * @brief ブロックコマンド定義 + * @note このコードは自動生成されています! * @author 鈴本 遼 * @date 2020/11/14 */ @@ -233,24 +236,17 @@ def OutputOtherObcCmdDefH(file_path, name, body): output = "" output += ''' /** -'''[1:] # 最初の改行を除く - - output += " * @file " + name_capit + "CommandDefinitions.h\n" - - output += ''' + * @file {_obc_name_capit}CommandDefinitions.h * @brief コマンド定義 + * @note このコードは自動生成されています! * @author 鈴本 遼 * @date 2020/08/23 */ -'''[1:] # 最初の改行を除く - - output += "#ifndef " + name_upper + "_COMMAND_DEFINITIONS_H_\n" - output += "#define " + name_upper + "_COMMAND_DEFINITIONS_H_\n" - - output += ''' +#ifndef {_obc_name_upper}_COMMAND_DEFINITIONS_H_ +#define {_obc_name_upper}_COMMAND_DEFINITIONS_H_ typedef enum -{ +{{ /* This pattern is a "separator". This should not be changed. @@ -270,16 +266,12 @@ def OutputOtherObcCmdDefH(file_path, name, body): This should not be changed. This should not be used in other places. */ -'''[1:] # 最初の改行を除く - - output += " " + name_upper + "_Cmd_CODE_MAX\n" - output += "} " + name_upper + "_CMD_CODE;\n" - - output += ''' + {_obc_name_upper}_Cmd_CODE_MAX +}} {_obc_name_upper}_CMD_CODE; #endif '''[1:] # 最初の改行を除く with open(file_path, mode='w', encoding='shift_jis') as fh: - fh.write(output) + fh.write(output.format(_obc_name_upper=name_upper, _obc_name_lower=name_lower, _obc_name_capit=name_capit)) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index d358c243b..a70a6e3a0 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -12,9 +12,6 @@ def GenerateTlmBuffer(settings, other_obc_dbs): if not settings["other_obc_data"][i]["is_enable"]: continue obc_name = settings["other_obc_data"][i]["name"] - name_upper = obc_name.upper() - name_lower = obc_name.lower() - name_capit = obc_name.capitalize() driver_type = settings["other_obc_data"][i]["driver_type"] driver_name = settings["other_obc_data"][i]["driver_name"] contents_len = settings["other_obc_data"][i]["tlm_max_contents_len"] @@ -24,54 +21,75 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c = "" body_h = "" - body_h += "typedef struct {\n" - + body_c += "static {_obc_name_upper}_Buffer {_obc_name_lower}_buffer_;\n" + body_c += "const {_obc_name_upper}_Buffer* {_obc_name_lower}_buffer;\n" + body_c += "\n" + body_h += "typedef struct {{\n" for tlm in tlm_db: tlm_name = tlm['tlm_name'] tlm_name_upper = tlm_name.upper() tlm_name_lower = tlm_name.lower() body_h += " uint8_t " + tlm_name_lower + "[" + str(contents_len) + "];\n" - body_c += "static DRIVER_SUPER_ERR_CODE " + name_upper + "_analyze_tlm_" + tlm_name_lower + "_(DriverSuperStreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ");\n" + body_c += "static DRIVER_SUPER_ERR_CODE {_obc_name_upper}_analyze_tlm_" + tlm_name_lower + "_(DriverSuperStreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ");\n" - body_h += "} " + name_upper + "_Buffer;\n" + body_h += "}} {_obc_name_upper}_Buffer;\n" body_h += "\n" - body_h += "extern const " + name_upper + "_Buffer* " + name_lower + "_buffer;\n" + body_h += "extern const {_obc_name_upper}_Buffer* {_obc_name_lower}_buffer;\n" body_h += "\n" - body_h += "DRIVER_SUPER_ERR_CODE " + name_upper + "_buffer_tlm_contents(DriverSuperStreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ");\n" + body_h += "DRIVER_SUPER_ERR_CODE {_obc_name_upper}_buffer_init(void);\n" + body_h += "DRIVER_SUPER_ERR_CODE {_obc_name_upper}_buffer_tlm_contents(DriverSuperStreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ");\n" body_c += "\n" - body_c += "DRIVER_SUPER_ERR_CODE " + name_upper + "_buffer_tlm_contents(DriverSuperStreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ")\n" - body_c += "{\n" + body_c += "DRIVER_SUPER_ERR_CODE {_obc_name_upper}_buffer_init(void)\n" + body_c += "{{\n" + body_c += " {_obc_name_lower}_buffer = &{_obc_name_lower}_buffer_;\n" + body_c += "}}\n" + body_c += "\n" + body_c += "DRIVER_SUPER_ERR_CODE {_obc_name_upper}_buffer_tlm_contents(DriverSuperStreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ")\n" + body_c += "{{\n" + + body_c += " uint8_t tlm_id = DRIVER_SUPER_C2AFMT_get_tlm_id(p_stream_config);\n" + body_c += "\n" + body_c += " switch (tlm_id)\n" - body_c += " {\n" + body_c += " {{\n" for tlm in tlm_db: tlm_name = tlm['tlm_name'] tlm_name_upper = tlm_name.upper() tlm_name_lower = tlm_name.lower() - body_c += " case " + name_upper + "_Tlm_CODE_" + tlm_name_upper + ":\n" - body_c += " return " + name_upper + "_analyze_tlm_" + tlm_name_lower + "_(p_stream_config, " + driver_name + ")\n" + body_c += " case {_obc_name_upper}_Tlm_CODE_" + tlm_name_upper + ":\n" + body_c += " return {_obc_name_upper}_analyze_tlm_" + tlm_name_lower + "_(p_stream_config, " + driver_name + ")\n" body_c += " default:\n" body_c += " " + settings["other_obc_data"][i]["code_when_tlm_not_found"] + "\n" body_c += " return DRIVER_SUPER_ERR_CODE_OK;\n" - body_c += " }\n" - body_c += "}\n" + body_c += " }}\n" + body_c += "}}\n" body_c += "\n" for tlm in tlm_db: tlm_name = tlm['tlm_name'] tlm_name_upper = tlm_name.upper() tlm_name_lower = tlm_name.lower() - body_c += "static DRIVER_SUPER_ERR_CODE " + name_upper + "_analyze_tlm_" + tlm_name_lower + "_(DriverSuperStreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ")\n" - body_c += "{\n" + body_c += "static DRIVER_SUPER_ERR_CODE {_obc_name_upper}_analyze_tlm_" + tlm_name_lower + "_(DriverSuperStreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ")\n" + body_c += "{{\n" + body_c += " uint32_t tlm_len = DRIVER_SUPER_ISSLFMT_get_tlm_length(p_stream_config);\n" + body_c += " uint32_t contents_len = tlm_len - DRIVER_SUPER_C2AFMT_TCP_TLM_SECONDARY_HEADER_SIZE - 1; // FIXME: CCSDSは1起算?\n" + body_c += " uint8_t* contents_pos = (p_stream_config->rx_frame) + DRIVER_SUPER_ISSLFMT_COMMON_HEADER_SIZE + DRIVER_SUPER_C2AFMT_TCP_TLM_PRIMARY_HEADER_SIZE + DRIVER_SUPER_C2AFMT_TCP_TLM_SECONDARY_HEADER_SIZE;\n" + body_c += "\n" + body_c += " if (contents_len > " + str(contents_len) + ") return DRIVER_SUPER_ERR_CODE_ERR;\n" + body_c += " memcpy(&({_obc_name_lower}_buffer_" + tlm_name_lower + "), contents_pos, (size_t)contents_len);\n" + body_c += "\n" body_c += " // [TODO] フレームの中身をパースしてMOBCでもろもろにアクセスするためのコード\n" + body_c += " // テレメDBと同じ構造の構造体を定義して代入する?\n" + body_c += " // 問題はビットフィールドを使ってるやつら\n" body_c += " return DRIVER_SUPER_ERR_CODE_OK;\n" - body_c += "}\n" + body_c += "}}\n" body_c += "\n" output_file_path = settings["c2a_root_dir"] + r"src_user/Drivers/" + settings["other_obc_data"][i]["driver_path"]; - OutputTlmBufferC(output_file_path + name_capit + "TelemetryBuffer.c", obc_name, body_c) - OutputTlmBufferH(output_file_path + name_capit + "TelemetryBuffer.h", obc_name, body_h) + OutputTlmBufferC(output_file_path + obc_name.capitalize() + "TelemetryBuffer.c", obc_name, body_c) + OutputTlmBufferH(output_file_path + obc_name.capitalize() + "TelemetryBuffer.h", obc_name, body_h) def OutputTlmBufferC(file_path, name, body): @@ -83,31 +101,29 @@ def OutputTlmBufferC(file_path, name, body): output += ''' #pragma section REPRO /** -'''[1:] # 最初の改行を除く - - output += " * @file " + name_capit + "TelemetryBuffer.c\n" - - output += ''' + * @file {_obc_name_capit}TelemetryBuffer.c * @brief テレメトリバッファー(テレメ中継) + * @note このコードは自動生成されています! * @author 鈴本 遼 * @date 2021/02/14 */ -'''[1:] # 最初の改行を除く - output += "\n" - output += '#include "./' + name_capit + 'TelemetryDefinitions.h"\n' - output += '#include "./' + name_capit + 'TelemetryBuffer.h"\n' - output += "\n" +#include "./{_obc_name_capit}TelemetryDefinitions.h" +#include "./{_obc_name_capit}TelemetryBuffer.h" + +'''[1:] # 最初の改行を除く output += body output += ''' - #pragma section '''[1:] # 最初の改行を除く with open(file_path, mode='w', encoding='shift_jis') as fh: - fh.write(output) + fh.write(output.format(_obc_name_upper=name_upper, _obc_name_lower=name_lower, _obc_name_capit=name_capit)) + + + def OutputTlmBufferH(file_path, name, body): @@ -118,23 +134,19 @@ def OutputTlmBufferH(file_path, name, body): output = "" output += ''' /** -'''[1:] # 最初の改行を除く - - output += " * @file " + name_capit + "TelemetryBuffer.h\n" - - output += ''' + * @file {_obc_name_capit}TelemetryBuffer.h * @brief テレメトリバッファー(テレメ中継) + * @note このコードは自動生成されています! * @author 鈴本 遼 * @date 2021/02/14 */ -'''[1:] # 最初の改行を除く +#ifndef {_obc_name_upper}_TELEMETRY_BUFFER_H_ +#define {_obc_name_upper}_TELEMETRY_BUFFER_H_ - output += "#ifndef " + name_upper + "_TELEMETRY_BUFFER_H_\n" - output += "#define " + name_upper + "_TELEMETRY_BUFFER_H_\n" - output += "\n" - output += '#include "./' + name_upper + '.h"\n' +#include "string.h" // for memcpy +#include "./{_obc_name_upper}.h" - output += "\n" +'''[1:] # 最初の改行を除く output += body @@ -144,4 +156,5 @@ def OutputTlmBufferH(file_path, name, body): '''[1:] # 最初の改行を除く with open(file_path, mode='w', encoding='shift_jis') as fh: - fh.write(output) + fh.write(output.format(_obc_name_upper=name_upper, _obc_name_lower=name_lower, _obc_name_capit=name_capit)) + diff --git a/my_mod/tlm_def.py b/my_mod/tlm_def.py index e52518f67..ddeaae29f 100644 --- a/my_mod/tlm_def.py +++ b/my_mod/tlm_def.py @@ -125,6 +125,7 @@ def OutputTlmDefC(file_path, body): /** * @file TelemetryDefinitions.c * @brief テレメトリ定義 + * @note このコードは自動生成されています! * @author 鈴本 遼 * @date 2020/08/23 */ @@ -163,6 +164,7 @@ def OutputTlmDefH(file_path, body): /** * @file TelemetryDefinitions.h * @brief テレメトリ定義 + * @note このコードは自動生成されています! * @author 鈴本 遼 * @date 2020/08/23 */ @@ -212,24 +214,17 @@ def OutputOtherObcTlmDefH(file_path, name, body): output = "" output += ''' /** -'''[1:] # 最初の改行を除く - - output += " * @file " + name_capit + "TelemetryDefinitions.h\n" - - output += ''' + * @file {_obc_name_capit}TelemetryDefinitions.h * @brief テレメトリ定義 + * @note このコードは自動生成されています! * @author 鈴本 遼 * @date 2020/08/23 */ -'''[1:] # 最初の改行を除く - - output += "#ifndef " + name_upper + "_TELEMETRY_DEFINITIONS_H_\n" - output += "#define " + name_upper + "_TELEMETRY_DEFINITIONS_H_\n" - - output += ''' +#ifndef {_obc_name_upper}_TELEMETRY_DEFINITIONS_H_ +#define {_obc_name_upper}_TELEMETRY_DEFINITIONS_H_ typedef enum -{ +{{ /* This pattern is a "separator". This should not be changed. @@ -249,16 +244,12 @@ def OutputOtherObcTlmDefH(file_path, name, body): This should not be changed. This should not be used in other places. */ -'''[1:] # 最初の改行を除く - - output += " " + name_upper + "_TLM_CODE_MAX\n" - output += "} " + name_upper + "_TLM_CODE;\n" - - output += ''' + {_obc_name_upper}_TLM_CODE_MAX +}} {_obc_name_upper}_TLM_CODE; #endif '''[1:] # 最初の改行を除く with open(file_path, mode='w', encoding='shift_jis') as fh: - fh.write(output) + fh.write(output.format(_obc_name_upper=name_upper, _obc_name_lower=name_lower, _obc_name_capit=name_capit)) From 9281c60b5afda8ae255afdaffcd9458bfa5b4b64 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sun, 14 Feb 2021 18:31:17 +0900 Subject: [PATCH 032/141] fix to be able to build for c2a --- my_mod/tlm_buffer.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index a70a6e3a0..c7c8afc4e 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -36,12 +36,12 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_h += "\n" body_h += "extern const {_obc_name_upper}_Buffer* {_obc_name_lower}_buffer;\n" body_h += "\n" - body_h += "DRIVER_SUPER_ERR_CODE {_obc_name_upper}_buffer_init(void);\n" + body_h += "void {_obc_name_upper}_buffer_init(void);\n" body_h += "DRIVER_SUPER_ERR_CODE {_obc_name_upper}_buffer_tlm_contents(DriverSuperStreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ");\n" body_c += "\n" - body_c += "DRIVER_SUPER_ERR_CODE {_obc_name_upper}_buffer_init(void)\n" + body_c += "void {_obc_name_upper}_buffer_init(void)\n" body_c += "{{\n" body_c += " {_obc_name_lower}_buffer = &{_obc_name_lower}_buffer_;\n" body_c += "}}\n" @@ -59,7 +59,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): tlm_name_upper = tlm_name.upper() tlm_name_lower = tlm_name.lower() body_c += " case {_obc_name_upper}_Tlm_CODE_" + tlm_name_upper + ":\n" - body_c += " return {_obc_name_upper}_analyze_tlm_" + tlm_name_lower + "_(p_stream_config, " + driver_name + ")\n" + body_c += " return {_obc_name_upper}_analyze_tlm_" + tlm_name_lower + "_(p_stream_config, " + driver_name + ");\n" body_c += " default:\n" body_c += " " + settings["other_obc_data"][i]["code_when_tlm_not_found"] + "\n" body_c += " return DRIVER_SUPER_ERR_CODE_OK;\n" @@ -77,11 +77,12 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += " uint8_t* contents_pos = (p_stream_config->rx_frame) + DRIVER_SUPER_ISSLFMT_COMMON_HEADER_SIZE + DRIVER_SUPER_C2AFMT_TCP_TLM_PRIMARY_HEADER_SIZE + DRIVER_SUPER_C2AFMT_TCP_TLM_SECONDARY_HEADER_SIZE;\n" body_c += "\n" body_c += " if (contents_len > " + str(contents_len) + ") return DRIVER_SUPER_ERR_CODE_ERR;\n" - body_c += " memcpy(&({_obc_name_lower}_buffer_" + tlm_name_lower + "), contents_pos, (size_t)contents_len);\n" + body_c += " memcpy({_obc_name_lower}_buffer_." + tlm_name_lower + ", contents_pos, (size_t)contents_len);\n" body_c += "\n" body_c += " // [TODO] フレームの中身をパースしてMOBCでもろもろにアクセスするためのコード\n" body_c += " // テレメDBと同じ構造の構造体を定義して代入する?\n" body_c += " // 問題はビットフィールドを使ってるやつら\n" + body_c += " (void)" + driver_name + "; // 仮\n" body_c += " return DRIVER_SUPER_ERR_CODE_OK;\n" body_c += "}}\n" body_c += "\n" @@ -110,6 +111,7 @@ def OutputTlmBufferC(file_path, name, body): #include "./{_obc_name_capit}TelemetryDefinitions.h" #include "./{_obc_name_capit}TelemetryBuffer.h" +#include "string.h" // for memcpy '''[1:] # 最初の改行を除く @@ -143,7 +145,6 @@ def OutputTlmBufferH(file_path, name, body): #ifndef {_obc_name_upper}_TELEMETRY_BUFFER_H_ #define {_obc_name_upper}_TELEMETRY_BUFFER_H_ -#include "string.h" // for memcpy #include "./{_obc_name_upper}.h" '''[1:] # 最初の改行を除く From d7a27eb1d29e20f0536c7fe8fee2d3c173be71aa Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sun, 14 Feb 2021 18:37:24 +0900 Subject: [PATCH 033/141] add size information to tlm buffer --- my_mod/tlm_buffer.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index c7c8afc4e..f503fdf65 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -29,7 +29,10 @@ def GenerateTlmBuffer(settings, other_obc_dbs): tlm_name = tlm['tlm_name'] tlm_name_upper = tlm_name.upper() tlm_name_lower = tlm_name.lower() - body_h += " uint8_t " + tlm_name_lower + "[" + str(contents_len) + "];\n" + body_h += " struct {{\n" + body_h += " int size;\n" + body_h += " uint8_t buffer[" + str(contents_len) + "];\n" + body_h += " }} " + tlm_name_lower + ";\n" body_c += "static DRIVER_SUPER_ERR_CODE {_obc_name_upper}_analyze_tlm_" + tlm_name_lower + "_(DriverSuperStreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ");\n" body_h += "}} {_obc_name_upper}_Buffer;\n" @@ -77,7 +80,8 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += " uint8_t* contents_pos = (p_stream_config->rx_frame) + DRIVER_SUPER_ISSLFMT_COMMON_HEADER_SIZE + DRIVER_SUPER_C2AFMT_TCP_TLM_PRIMARY_HEADER_SIZE + DRIVER_SUPER_C2AFMT_TCP_TLM_SECONDARY_HEADER_SIZE;\n" body_c += "\n" body_c += " if (contents_len > " + str(contents_len) + ") return DRIVER_SUPER_ERR_CODE_ERR;\n" - body_c += " memcpy({_obc_name_lower}_buffer_." + tlm_name_lower + ", contents_pos, (size_t)contents_len);\n" + body_c += " memcpy({_obc_name_lower}_buffer_." + tlm_name_lower + ".buffer, contents_pos, (size_t)contents_len);\n" + body_c += " {_obc_name_lower}_buffer_." + tlm_name_lower + ".size = (int)contents_len;\n" body_c += "\n" body_c += " // [TODO] フレームの中身をパースしてMOBCでもろもろにアクセスするためのコード\n" body_c += " // テレメDBと同じ構造の構造体を定義して代入する?\n" From d57d222a27f252743025b78cd3d7d957504d1c30 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sun, 14 Feb 2021 20:55:38 +0900 Subject: [PATCH 034/141] update for generating mobc tlm code --- GenerateC2ACode.py | 2 +- my_mod/cmd_def.py | 16 ++--- my_mod/gstos.py | 8 +-- my_mod/load_db.py | 18 +++--- my_mod/tlm_buffer.py | 14 ++-- my_mod/tlm_def.py | 151 ++++++++++++++++++++++++++++++++++++++----- settings.json | 3 + 7 files changed, 171 insertions(+), 41 deletions(-) diff --git a/GenerateC2ACode.py b/GenerateC2ACode.py index 53a5afa25..144a0eaeb 100644 --- a/GenerateC2ACode.py +++ b/GenerateC2ACode.py @@ -38,7 +38,7 @@ def main(): my_mod.cmd_def.GenerateCmdDef(settings, cmd_db['sgc']) my_mod.cmd_def.GenerateBctDef(settings, cmd_db['bct']) - my_mod.tlm_def.GenerateTlmDef(settings, tlm_db['tlm']) + my_mod.tlm_def.GenerateTlmDef(settings, tlm_db['tlm'], tlm_db['other_obc']) if settings["is_main_obc"]: my_mod.cmd_def.GenerateOtherObcCmdDef(settings, cmd_db['other_obc']) diff --git a/my_mod/cmd_def.py b/my_mod/cmd_def.py index 0a32339f3..3894f2b38 100644 --- a/my_mod/cmd_def.py +++ b/my_mod/cmd_def.py @@ -32,8 +32,8 @@ def GenerateCmdDef(settings, sgc_db): body_c += " cmd_table_[" + cmd_code + "].cmd_func = " + cmd_name + ";\n" body_h += " " + cmd_code + " = " + cmd_id + ",\n" - OutputCmdDefC(output_file_path + output_file_name_base + ".c", body_c) - OutputCmdDefH(output_file_path + output_file_name_base + ".h", body_h) + OutputCmdDefC_(output_file_path + output_file_name_base + ".c", body_c) + OutputCmdDefH_(output_file_path + output_file_name_base + ".h", body_h) def GenerateBctDef(settings, bct_db): @@ -65,7 +65,7 @@ def GenerateBctDef(settings, bct_db): else: body_h += " " + name + " = " + bc_id +", // " + description + "\n" - OutputBctDef(output_file_path + output_file_name, body_h) + OutputBctDef_(output_file_path + output_file_name, body_h) def GenerateOtherObcCmdDef(settings, other_obc_dbs): @@ -100,10 +100,10 @@ def GenerateOtherObcCmdDef(settings, other_obc_dbs): body_h += " " + cmd_code + " = " + cmd_id + ",\n" # print(body_h) output_file_path = settings["c2a_root_dir"] + r"src_user/Drivers/" + settings["other_obc_data"][i]["driver_path"] + name_capit + "CommandDefinitions.h" - OutputOtherObcCmdDefH(output_file_path, obc_name, body_h) + OutputOtherObcCmdDefH_(output_file_path, obc_name, body_h) -def OutputCmdDefC(file_path, body): +def OutputCmdDefC_(file_path, body): output = "" output += ''' #pragma section REPRO @@ -148,7 +148,7 @@ def OutputCmdDefC(file_path, body): fh.write(output) -def OutputCmdDefH(file_path, body): +def OutputCmdDefH_(file_path, body): output = "" output += ''' /** @@ -196,7 +196,7 @@ def OutputCmdDefH(file_path, body): fh.write(output) -def OutputBctDef(file_path, body): +def OutputBctDef_(file_path, body): output = "" output += ''' /** @@ -228,7 +228,7 @@ def OutputBctDef(file_path, body): fh.write(output) -def OutputOtherObcCmdDefH(file_path, name, body): +def OutputOtherObcCmdDefH_(file_path, name, body): name_upper = name.upper() name_lower = name.lower() name_capit = name.capitalize() diff --git a/my_mod/gstos.py b/my_mod/gstos.py index 2f3c5cc1c..9e665efe1 100644 --- a/my_mod/gstos.py +++ b/my_mod/gstos.py @@ -28,7 +28,7 @@ def GenerateGstosFiles(settings, sgc_db, tlm_db): break if comment != "": # Comment continue - output_cmd += GetCmdSibDef(sgc_db[i]) + output_cmd += GetCmdSibDef_(sgc_db[i]) output_cmd += '\n' @@ -59,7 +59,7 @@ def GenerateGstosFiles(settings, sgc_db, tlm_db): # continue # if pos == "": # continue - output_tlm += GetTlmSibDef(tlm['tlm_id'], tlm['data'][i]) + output_tlm += GetTlmSibDef_(tlm['tlm_id'], tlm['data'][i]) output_tlm += '\n' @@ -67,7 +67,7 @@ def GenerateGstosFiles(settings, sgc_db, tlm_db): fh.write(output_tlm) -def GetCmdSibDef(sgc_db_line): +def GetCmdSibDef_(sgc_db_line): cmd = sgc_db_line[1] inf = sgc_db_line[18] cmd_id = sgc_db_line[3] @@ -192,7 +192,7 @@ def GetCmdSibDef(sgc_db_line): return output -def GetTlmSibDef(tlm_id, tlm_db_line): +def GetTlmSibDef_(tlm_id, tlm_db_line): comment = tlm_db_line[0] name = tlm_db_line[1] var_type = tlm_db_line[2] diff --git a/my_mod/load_db.py b/my_mod/load_db.py index db9491435..09a6509c3 100644 --- a/my_mod/load_db.py +++ b/my_mod/load_db.py @@ -11,18 +11,20 @@ def LoadCmdDb(settings): cmd_db_path = settings["c2a_root_dir"] + r"src_user/Settings/CmdTlm/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"]) other_obc_dbs = {} if settings["is_main_obc"]: - other_obc_dbs = LoadOtherObcCmd(settings); + other_obc_dbs = LoadOtherObcCmd_(settings); + + # TODO: 重複チェックをする # print(sgc_db) # print(bct_db) 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): 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 @@ -39,7 +41,7 @@ def LoadCmdCSV(cmd_db_path, db_prefix): def LoadTlmDb(settings): tlm_db_path = settings["c2a_root_dir"] + r"src_user/Settings/CmdTlm/DataBase/TLM_DB/calced_data/" - tlm_db = LoadTlmCSV(tlm_db_path, settings["db_prefix"]) + tlm_db = LoadTlmCSV_(tlm_db_path, settings["db_prefix"]) other_obc_dbs = {} if settings["is_main_obc"]: @@ -50,7 +52,7 @@ def LoadTlmDb(settings): return {'tlm': tlm_db, 'other_obc': other_obc_dbs} -def LoadTlmCSV(tlm_db_path, db_prefix): +def LoadTlmCSV_(tlm_db_path, db_prefix): 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] @@ -76,14 +78,14 @@ def LoadTlmCSV(tlm_db_path, db_prefix): return tlm_db; -def LoadOtherObcCmd(settings): +def LoadOtherObcCmd_(settings): other_obc_dbs = {} for i in range(len(settings["other_obc_data"])): 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"]) # other_obc_dbs.append(sgc_db) other_obc_dbs[settings["other_obc_data"][i]["name"]] = sgc_db # print(i) @@ -101,7 +103,7 @@ def LoadOtherObcTlm(settings): continue tlm_db_path = settings["other_obc_data"][i]["db_path"] + r"TLM_DB/" - tlm_db = LoadTlmCSV(tlm_db_path, settings["other_obc_data"][i]["db_prefix"]) + tlm_db = LoadTlmCSV_(tlm_db_path, settings["other_obc_data"][i]["db_prefix"]) other_obc_dbs[settings["other_obc_data"][i]["name"]] = tlm_db # pprint.pprint(other_obc_dbs) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index f503fdf65..d98ed6321 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -27,7 +27,6 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_h += "typedef struct {{\n" for tlm in tlm_db: tlm_name = tlm['tlm_name'] - tlm_name_upper = tlm_name.upper() tlm_name_lower = tlm_name.lower() body_h += " struct {{\n" body_h += " int size;\n" @@ -47,6 +46,11 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += "void {_obc_name_upper}_buffer_init(void)\n" body_c += "{{\n" body_c += " {_obc_name_lower}_buffer = &{_obc_name_lower}_buffer_;\n" + body_c += "\n" + for tlm in tlm_db: + tlm_name = tlm['tlm_name'] + tlm_name_lower = tlm_name.lower() + body_c += " {_obc_name_lower}_buffer_." + tlm_name_lower + ".size = 0;\n" body_c += "}}\n" body_c += "\n" body_c += "DRIVER_SUPER_ERR_CODE {_obc_name_upper}_buffer_tlm_contents(DriverSuperStreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ")\n" @@ -93,11 +97,11 @@ def GenerateTlmBuffer(settings, other_obc_dbs): output_file_path = settings["c2a_root_dir"] + r"src_user/Drivers/" + settings["other_obc_data"][i]["driver_path"]; - OutputTlmBufferC(output_file_path + obc_name.capitalize() + "TelemetryBuffer.c", obc_name, body_c) - OutputTlmBufferH(output_file_path + obc_name.capitalize() + "TelemetryBuffer.h", obc_name, body_h) + OutputTlmBufferC_(output_file_path + obc_name.capitalize() + "TelemetryBuffer.c", obc_name, body_c) + OutputTlmBufferH_(output_file_path + obc_name.capitalize() + "TelemetryBuffer.h", obc_name, body_h) -def OutputTlmBufferC(file_path, name, body): +def OutputTlmBufferC_(file_path, name, body): name_upper = name.upper() name_lower = name.lower() name_capit = name.capitalize() @@ -132,7 +136,7 @@ def OutputTlmBufferC(file_path, name, body): -def OutputTlmBufferH(file_path, name, body): +def OutputTlmBufferH_(file_path, name, body): name_upper = name.upper() name_lower = name.lower() name_capit = name.capitalize() diff --git a/my_mod/tlm_def.py b/my_mod/tlm_def.py index ddeaae29f..ccd310ff2 100644 --- a/my_mod/tlm_def.py +++ b/my_mod/tlm_def.py @@ -4,8 +4,9 @@ """ import os +import sys -def GenerateTlmDef(settings, tlm_db): +def GenerateTlmDef(settings, tlm_db, other_obc_dbs): output_file_path = settings["c2a_root_dir"] + r"src_user/CmdTlm/" output_file_name_base = "TelemetryDefinitions" @@ -17,15 +18,20 @@ def GenerateTlmDef(settings, tlm_db): # "static int OBC_(unsigned char* contents, int max_len);" # " OBC_ID = 0x00," for tlm in tlm_db: - body_c += "static int Tlm_" + tlm['tlm_name'] + "_(unsigned char* contents, int max_len);\n" - body_h += " Tlm_CODE_" + tlm['tlm_name'] + " = " + tlm['tlm_id'] + ",\n" + body_c += "static int Tlm_" + tlm['tlm_name'].upper() + "_(unsigned char* contents, int max_len);\n" + body_h += " Tlm_CODE_" + tlm['tlm_name'].upper() + " = " + tlm['tlm_id'] + ",\n" + + if settings["is_main_obc"]: + body_c += GetTlmDefCOfOtherObcFunDef_(settings, tlm_db, other_obc_dbs) body_c += "\n" body_c += "void TF_load_tlm_table(TlmInfo tlm_table_[TLM_MAX_TLMS])\n" body_c += "{\n" for tlm in tlm_db: # " tlm_table_[OBC_ID].tlm_func = OBC_;" - body_c += " tlm_table_[Tlm_CODE_" + tlm['tlm_name'] + "].tlm_func = Tlm_" + tlm['tlm_name'] + "_;\n" + body_c += " tlm_table_[Tlm_CODE_" + tlm['tlm_name'].upper() + "].tlm_func = Tlm_" + tlm['tlm_name'].upper() + "_;\n" + if settings["is_main_obc"]: + body_c += GetTlmDefCOfOtherObcFunLoad_(settings, tlm_db, other_obc_dbs) body_c += "}\n" for tlm in tlm_db: @@ -77,12 +83,12 @@ def GenerateTlmDef(settings, tlm_db): func_code += "copy_double_" max_pos = int(pos) + 8 else: - print("Error: Tlm DB Err at " + tlm['tlm_name'], file=sys.stderr) + print("Error: Tlm DB Err at " + tlm['tlm_name'].upper(), file=sys.stderr) sys.exit(1) func_code += "(&contents[" + pos + "], " + code + ");\n" body_c += "\n" - body_c += "static int Tlm_" + tlm['tlm_name'] + "_(unsigned char* contents, int max_len)\n" + body_c += "static int Tlm_" + tlm['tlm_name'].upper() + "_(unsigned char* contents, int max_len)\n" body_c += "{\n" body_c += "\n" body_c += " if (" + str(max_pos) + " > max_len) { return TLM_TOO_SHORT_LEN; }\n" @@ -94,8 +100,126 @@ def GenerateTlmDef(settings, tlm_db): body_c += " return " + str(max_pos) + ";\n" body_c += "}\n" - OutputTlmDefC(output_file_path + output_file_name_base + ".c", body_c) - OutputTlmDefH(output_file_path + output_file_name_base + ".h", body_h) + if settings["is_main_obc"]: + body_c += GetTlmDefCOfOtherObcFunBody_(settings, tlm_db, other_obc_dbs) + body_h += GetTlmDefHOfOtherObc_(settings, tlm_db, other_obc_dbs) + + OutputTlmDefC_(output_file_path + output_file_name_base + ".c", body_c) + OutputTlmDefH_(output_file_path + output_file_name_base + ".h", body_h) + + +def GetTlmDefCOfOtherObcFunDef_(settings, tlm_db, other_obc_dbs): + body_c = "" + + for i in range(len(settings["other_obc_data"])): + if not settings["other_obc_data"][i]["is_enable"]: + continue + + obc_name = settings["other_obc_data"][i]["name"] + oter_obc_tlm_db = other_obc_dbs[obc_name] + + temp_c = "" + temp_c += "\n" + for tlm in oter_obc_tlm_db: + temp_c += "static int Tlm_{_obc_name_upper}_" + tlm['tlm_name'].upper() + "_(unsigned char* contents, int max_len);\n" + + body_c += temp_c.format(_obc_name_upper=obc_name.upper(), _obc_name_lower=obc_name.lower(), _obc_name_capit=obc_name.capitalize()) + + return body_c + + +def GetTlmDefCOfOtherObcFunLoad_(settings, tlm_db, other_obc_dbs): + body_c = "" + + for i in range(len(settings["other_obc_data"])): + if not settings["other_obc_data"][i]["is_enable"]: + continue + + obc_name = settings["other_obc_data"][i]["name"] + oter_obc_tlm_db = other_obc_dbs[obc_name] + + temp_c = "" + temp_c += "\n" + for tlm in oter_obc_tlm_db: + temp_c += " tlm_table_[Tlm_CODE_{_obc_name_upper}_" + tlm['tlm_name'].upper() + "].tlm_func = Tlm_{_obc_name_upper}_" + tlm['tlm_name'].upper() + "_;\n" + body_c += temp_c.format(_obc_name_upper=obc_name.upper(), _obc_name_lower=obc_name.lower(), _obc_name_capit=obc_name.capitalize()) + + return body_c + + +def GetTlmDefCOfOtherObcFunBody_(settings, tlm_db, other_obc_dbs): + body_c = "" + + for i in range(len(settings["other_obc_data"])): + if not settings["other_obc_data"][i]["is_enable"]: + continue + + obc_name = settings["other_obc_data"][i]["name"] + oter_obc_tlm_db = other_obc_dbs[obc_name] + + temp_c = "" + temp_c += "\n" + for tlm in oter_obc_tlm_db: + tlm_name = tlm['tlm_name'] + tlm_name_upper = tlm_name.upper() + tlm_name_lower = tlm_name.lower() + temp_c += "static int Tlm_{_obc_name_upper}_" + tlm_name_upper + "_(unsigned char* contents, int max_len)\n" + temp_c += "{{\n" + temp_c += " int buffer_size = {_obc_name_lower}_buffer->" + tlm_name_lower + ".size;\n" + temp_c += "\n" + temp_c += " if (buffer_size > max_len) {{ return TLM_TOO_SHORT_LEN; }}\n" + temp_c += "\n" + temp_c += " memcpy(contents, {_obc_name_lower}_buffer->" + tlm_name_lower + ".buffer, (size_t)buffer_size);\n" + temp_c += "\n" + temp_c += " return buffer_size;\n" + temp_c += "}}\n" + + body_c += temp_c.format(_obc_name_upper=obc_name.upper(), _obc_name_lower=obc_name.lower(), _obc_name_capit=obc_name.capitalize()) + + return body_c + + +def GetTlmDefHOfOtherObc_(settings, tlm_db, other_obc_dbs): + # ID重複チェックはここでやり,他のGet関数ではやらない(実装イマイチ...) + body_h = "" + + for i in range(len(settings["other_obc_data"])): + if not settings["other_obc_data"][i]["is_enable"]: + continue + obc_name = settings["other_obc_data"][i]["name"] + + temp_h = "" + + id_begin = int(settings["other_obc_data"][i]["tlm_id_range"][0], 0) + id_end = int(settings["other_obc_data"][i]["tlm_id_range"][1], 0) + + # MOBC Tlmが範囲外かチェック + for tlm in tlm_db: + tlm_id = int(tlm['tlm_id'], 0) + if id_begin <= tlm_id < id_end: + print("Error: MOBC TLM ID is invalid at " + tlm['tlm_name'].upper(), file=sys.stderr) + sys.exit(1) + + oter_obc_tlm_db = other_obc_dbs[obc_name] + # ID範囲内チェック + for tlm in oter_obc_tlm_db: + tlm_id = int(tlm['tlm_id'], 0) + if not id_begin <= tlm_id < id_end: + print("Error: " + obc_name + " TLM ID is invalid at " + tlm['tlm_name'].upper(), file=sys.stderr) + sys.exit(1) + + body_h += "\n" + for tlm in oter_obc_tlm_db: + temp_h += " Tlm_CODE_{_obc_name_upper}_" + tlm['tlm_name'].upper() + " = " + tlm['tlm_id'] + ",\n" + + body_h += temp_h.format(_obc_name_upper=obc_name.upper(), _obc_name_lower=obc_name.lower(), _obc_name_capit=obc_name.capitalize()) + + body_h += "\n" + body_h += " // FIXME:\n" + body_h += " // 他OBCのTLMをまとめたため,IDが昇順となっていない\n" + body_h += " // TLM_CODE_MAX が意味をなさなくなってしまうが,他で使われていないため,一旦このままにする(今後解決する実装)\n" + + return body_h def GenerateOtherObcTlmDef(settings, other_obc_dbs): @@ -103,22 +227,19 @@ def GenerateOtherObcTlmDef(settings, other_obc_dbs): if not settings["other_obc_data"][i]["is_enable"]: continue obc_name = settings["other_obc_data"][i]["name"] - name_upper = obc_name.upper() - name_lower = obc_name.lower() - name_capit = obc_name.capitalize() tlm_db = other_obc_dbs[obc_name] body_h = "" # " TOBC_Tlm_CODE_HK = 0xf0," for tlm in tlm_db: - body_h += " " + name_upper + "_Tlm_CODE_" + tlm['tlm_name'] + " = " + tlm['tlm_id'] + ",\n" - output_file_path = settings["c2a_root_dir"] + r"src_user/Drivers/" + settings["other_obc_data"][i]["driver_path"] + name_capit + "TelemetryDefinitions.h" + body_h += " {_obc_name_upper}_Tlm_CODE_" + tlm['tlm_name'].upper() + " = " + tlm['tlm_id'] + ",\n" + output_file_path = settings["c2a_root_dir"] + r"src_user/Drivers/" + settings["other_obc_data"][i]["driver_path"] + obc_name.capitalize() + "TelemetryDefinitions.h" OutputOtherObcTlmDefH(output_file_path, obc_name, body_h) -def OutputTlmDefC(file_path, body): +def OutputTlmDefC_(file_path, body): output = "" output += ''' #pragma section REPRO @@ -158,7 +279,7 @@ def OutputTlmDefC(file_path, body): fh.write(output) -def OutputTlmDefH(file_path, body): +def OutputTlmDefH_(file_path, body): output = "" output += ''' /** diff --git a/settings.json b/settings.json index 279b451a0..75c6498b2 100644 --- a/settings.json +++ b/settings.json @@ -10,6 +10,9 @@ "db_prefix" : "ISSL6U_AOBC", "db_path" : "../../c2a_issl6u_aobc//src/src_user/Settings/CmdTlm/DataBase/", "driver_path" : "ADCS/", + "driver_type" : "AOBC_Driver", + "driver_name" : "aobc", + "code_when_tlm_not_found" : "", "tlm_id_range" : ["0x90", "0xc0"] }, { From e32706b532a7fbb1f76e0b1fd2572c93b89de1b2 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sun, 14 Feb 2021 20:57:46 +0900 Subject: [PATCH 035/141] Update README.md --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 941ef8cdb..6528a9f59 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,9 @@ $ python GenerateC2ACode.py "db_prefix" : "ISSL6U_AOBC", "db_path" : "../../c2a_issl6u_aobc//src/src_user/Settings/CmdTlm/DataBase/", "driver_path" : "ADCS/", + "driver_type" : "AOBC_Driver", + "driver_name" : "aobc", + "code_when_tlm_not_found" : "", "tlm_id_range" : ["0x90", "0xc0"] }, { @@ -40,7 +43,11 @@ $ python GenerateC2ACode.py "is_enable" : 1, "db_prefix" : "ISSL6U_TOBC", "db_path" : "../../tobc_tlmcmd/", + "tlm_max_contents_len" : 512, "driver_path" : "THERMAL/", + "driver_type" : "TOBC_Driver", + "driver_name" : "tobc", + "code_when_tlm_not_found" : "tobc->info.comm.rx_err_code = TOBC_RX_ERR_CODE_TLM_NOT_FOUND;", "tlm_id_range" : ["0xc0", "0xf0"] } ] From 7ebb5c24a3bfd837a1b62874482158b936c39a84 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sun, 14 Feb 2021 21:00:48 +0900 Subject: [PATCH 036/141] Update README.md --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6528a9f59..c31acddfd 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,12 @@ ## これはなに? TlmCmdDBからC2Aのコードを生成するためのスクリプト +以下が自動生成させる. +- CommandDefinitions.c +- CommandDefinitions.h +- TelemetryDefinitions.c +- TelemetryDefinitions.h + ## 実行 ``` $ python GenerateC2ACode.py @@ -10,7 +16,9 @@ $ python GenerateC2ACode.py ## 設定 `settings.json` にて記述する. 現在 `is_main_obc` は,未だ仕様未確定なため, `0` とすること! -`1` とした場合,現在は以下のみ生成される +`1` とした場合,現在は以下のみ生成される. +- TobcTelemetryBuffer.c +- TobcTelemetryBuffer.h - TobcCommandDefinitions.h - TobcTelemetryDefinitions.h From a8268eb5257a871b2f73559ac0ec46eaa2bf2e37 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sun, 14 Feb 2021 21:17:38 +0900 Subject: [PATCH 037/141] fix --- my_mod/tlm_def.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/my_mod/tlm_def.py b/my_mod/tlm_def.py index ccd310ff2..4ce94b5ed 100644 --- a/my_mod/tlm_def.py +++ b/my_mod/tlm_def.py @@ -158,11 +158,11 @@ def GetTlmDefCOfOtherObcFunBody_(settings, tlm_db, other_obc_dbs): oter_obc_tlm_db = other_obc_dbs[obc_name] temp_c = "" - temp_c += "\n" for tlm in oter_obc_tlm_db: tlm_name = tlm['tlm_name'] tlm_name_upper = tlm_name.upper() tlm_name_lower = tlm_name.lower() + temp_c += "\n" temp_c += "static int Tlm_{_obc_name_upper}_" + tlm_name_upper + "_(unsigned char* contents, int max_len)\n" temp_c += "{{\n" temp_c += " int buffer_size = {_obc_name_lower}_buffer->" + tlm_name_lower + ".size;\n" From 6102cb24839afb7c67213d39f30a17fd708d08aa Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sun, 14 Feb 2021 21:26:32 +0900 Subject: [PATCH 038/141] fix typo --- my_mod/tlm_buffer.py | 2 +- my_mod/tlm_def.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index d98ed6321..2ecbae3fe 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -6,7 +6,7 @@ import os def GenerateTlmBuffer(settings, other_obc_dbs): - DATA_SART_ROW = 7 + # DATA_START_ROW = 7 for i in range(len(settings["other_obc_data"])): if not settings["other_obc_data"][i]["is_enable"]: diff --git a/my_mod/tlm_def.py b/my_mod/tlm_def.py index 4ce94b5ed..92112e22b 100644 --- a/my_mod/tlm_def.py +++ b/my_mod/tlm_def.py @@ -10,7 +10,7 @@ def GenerateTlmDef(settings, tlm_db, other_obc_dbs): output_file_path = settings["c2a_root_dir"] + r"src_user/CmdTlm/" output_file_name_base = "TelemetryDefinitions" - DATA_SART_ROW = 7 + DATA_START_ROW = 7 body_c = "" body_h = "" @@ -37,7 +37,7 @@ def GenerateTlmDef(settings, tlm_db, other_obc_dbs): for tlm in tlm_db: func_code = "" max_pos = "" - for i in range(DATA_SART_ROW, len(tlm['data'])): + for i in range(DATA_START_ROW, len(tlm['data'])): comment = tlm['data'][i][0] name = tlm['data'][i][1] var_type = tlm['data'][i][2] From 758a1ed1eb86eb058044dd95c45f8d5f0067207f Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Mon, 15 Feb 2021 05:18:23 +0000 Subject: [PATCH 039/141] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c31acddfd..dd3f6b465 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,12 @@ ## これはなに? TlmCmdDBからC2Aのコードを生成するためのスクリプト -以下が自動生成させる. +以下が自動生成される. - CommandDefinitions.c - CommandDefinitions.h - TelemetryDefinitions.c - TelemetryDefinitions.h +- BlockCommandDefinitions.h ## 実行 ``` From 6d71b3821ef7f00dc277975522d049eb073512a1 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 16 Feb 2021 19:07:10 +0900 Subject: [PATCH 040/141] fix style --- my_mod/tlm_buffer.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index 2ecbae3fe..564ad99f5 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -24,11 +24,13 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += "static {_obc_name_upper}_Buffer {_obc_name_lower}_buffer_;\n" body_c += "const {_obc_name_upper}_Buffer* {_obc_name_lower}_buffer;\n" body_c += "\n" - body_h += "typedef struct {{\n" + body_h += "typedef struct\n" + body_h += "{{\n" for tlm in tlm_db: tlm_name = tlm['tlm_name'] tlm_name_lower = tlm_name.lower() - body_h += " struct {{\n" + body_h += " struct\n" + body_h += " {{\n" body_h += " int size;\n" body_h += " uint8_t buffer[" + str(contents_len) + "];\n" body_h += " }} " + tlm_name_lower + ";\n" From f5d137a0a134e994d8183ea487f622658b5da7ab Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Mon, 22 Feb 2021 23:01:10 +0900 Subject: [PATCH 041/141] Update README.md --- README.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index dd3f6b465..f6f3756af 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,6 @@ $ python GenerateC2ACode.py ## 設定 `settings.json` にて記述する. -現在 `is_main_obc` は,未だ仕様未確定なため, `0` とすること! `1` とした場合,現在は以下のみ生成される. - TobcTelemetryBuffer.c - TobcTelemetryBuffer.h @@ -32,12 +31,15 @@ $ python GenerateC2ACode.py "db_prefix" : "ISSL6U_MOBC", # GSTOS用sibファイルを生成するか? 0/1 "is_generated_sib" : 0, - # MOBCか?(他のOBCのtlm/cmdを取りまとめるか? 0/1 - # 0 の場合,以後のパラメタは無効(現在仮おき) + # MOBCか?(他のOBCのtlm/cmdを取りまとめるか?) 0/1 + # (A|T)OBCのコードを生成するときなどは 0 にする + # 0 の場合,以後のパラメタは無効 "is_main_obc" : 0, "other_obc_data" : [ { + # OBC名 "name" : "AOBC", + # コードを生成するか? AOBCについては現時点でDBが存在しないため 0 "is_enable" : 0, "db_prefix" : "ISSL6U_AOBC", "db_path" : "../../c2a_issl6u_aobc//src/src_user/Settings/CmdTlm/DataBase/", @@ -48,9 +50,12 @@ $ python GenerateC2ACode.py "tlm_id_range" : ["0x90", "0xc0"] }, { + # OBC名 "name" : "TOBC", + # コードを生成するか? "is_enable" : 1, "db_prefix" : "ISSL6U_TOBC", + # 現在,TOBCのDBは https://gitlab.com/ut_issl/issl6u/thermal/tobc_tlmcmd にあるので,これを手元にcloneし,そこまでの相対パスを設定する. "db_path" : "../../tobc_tlmcmd/", "tlm_max_contents_len" : 512, "driver_path" : "THERMAL/", From ff8b009e8940f281590d33681ccce69b80a49a81 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Mon, 22 Feb 2021 23:01:55 +0900 Subject: [PATCH 042/141] fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f6f3756af..e091dd18f 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ $ python GenerateC2ACode.py # MOBCか?(他のOBCのtlm/cmdを取りまとめるか?) 0/1 # (A|T)OBCのコードを生成するときなどは 0 にする # 0 の場合,以後のパラメタは無効 - "is_main_obc" : 0, + "is_main_obc" : 1, "other_obc_data" : [ { # OBC名 From 43d08dd97a96dc08f05ee093d86aff01e3c6b00d Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Mon, 22 Feb 2021 23:28:01 +0900 Subject: [PATCH 043/141] del separator comment --- my_mod/cmd_def.py | 40 ---------------------------------------- my_mod/tlm_def.py | 39 --------------------------------------- 2 files changed, 79 deletions(-) diff --git a/my_mod/cmd_def.py b/my_mod/cmd_def.py index 3894f2b38..948fc7fc1 100644 --- a/my_mod/cmd_def.py +++ b/my_mod/cmd_def.py @@ -117,13 +117,6 @@ def OutputCmdDefC_(file_path, body): #include "CommandDefinitions.h" #include "CommandSource.h" -/* -This pattern is a "separator". -This should not be changed. -This should not be used in other places. -*/ -//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## - void CA_load_cmd_table(CmdInfo cmd_table_[CMD_MAX_CMDS]) { '''[1:] # 最初の改行を除く @@ -133,13 +126,6 @@ def OutputCmdDefC_(file_path, body): output += ''' } -//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## -/* -This pattern is a "separator". -This should not be changed. -This should not be used in other places. -*/ - #pragma section '''[1:] # 最初の改行を除く @@ -165,25 +151,12 @@ def OutputCmdDefH_(file_path, body): typedef enum { -/* -This pattern is a "separator". -This should not be changed. -This should not be used in other places. -*/ -//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## - '''[1:] # 最初の改行を除く output += body output += ''' -//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## -/* -This pattern is a "separator". -This should not be changed. -This should not be used in other places. -*/ Cmd_CODE_MAX } CMD_CODE; @@ -247,25 +220,12 @@ def OutputOtherObcCmdDefH_(file_path, name, body): typedef enum {{ -/* -This pattern is a "separator". -This should not be changed. -This should not be used in other places. -*/ -//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## - '''[1:] # 最初の改行を除く output += body output += ''' -//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## -/* -This pattern is a "separator". -This should not be changed. -This should not be used in other places. -*/ {_obc_name_upper}_Cmd_CODE_MAX }} {_obc_name_upper}_CMD_CODE; diff --git a/my_mod/tlm_def.py b/my_mod/tlm_def.py index 92112e22b..34b2ac22f 100644 --- a/my_mod/tlm_def.py +++ b/my_mod/tlm_def.py @@ -253,25 +253,12 @@ def OutputTlmDefC_(file_path, body): #include "TelemetryDefinitions.h" #include "TelemetrySource.h" -/* -This pattern is a "separator". -This should not be changed. -This should not be used in other places. -*/ -//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## '''[1:] # 最初の改行を除く output += body output += ''' -//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## -/* -This pattern is a "separator". -This should not be changed. -This should not be used in other places. -*/ - #pragma section '''[1:] # 最初の改行を除く @@ -296,25 +283,12 @@ def OutputTlmDefH_(file_path, body): typedef enum { -/* -This pattern is a "separator". -This should not be changed. -This should not be used in other places. -*/ -//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## - '''[1:] # 最初の改行を除く output += body output += ''' -//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## -/* -This pattern is a "separator". -This should not be changed. -This should not be used in other places. -*/ TLM_CODE_MAX } TLM_CODE; @@ -346,25 +320,12 @@ def OutputOtherObcTlmDefH(file_path, name, body): typedef enum {{ -/* -This pattern is a "separator". -This should not be changed. -This should not be used in other places. -*/ -//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## - '''[1:] # 最初の改行を除く output += body output += ''' -//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//## -/* -This pattern is a "separator". -This should not be changed. -This should not be used in other places. -*/ {_obc_name_upper}_TLM_CODE_MAX }} {_obc_name_upper}_TLM_CODE; From 1ee1906ba2d82bf0d7d03faef0c20df9858d1836 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 23 Feb 2021 01:37:21 +0900 Subject: [PATCH 044/141] add tlm data struct gen code --- my_mod/load_db.py | 2 +- my_mod/tlm_buffer.py | 96 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 93 insertions(+), 5 deletions(-) diff --git a/my_mod/load_db.py b/my_mod/load_db.py index 09a6509c3..162ec85e2 100644 --- a/my_mod/load_db.py +++ b/my_mod/load_db.py @@ -101,7 +101,7 @@ def LoadOtherObcTlm(settings): for i in range(len(settings["other_obc_data"])): if not settings["other_obc_data"][i]["is_enable"]: continue - tlm_db_path = settings["other_obc_data"][i]["db_path"] + r"TLM_DB/" + tlm_db_path = settings["other_obc_data"][i]["db_path"] + r"TLM_DB/calced_data/" tlm_db = LoadTlmCSV_(tlm_db_path, settings["other_obc_data"][i]["db_prefix"]) other_obc_dbs[settings["other_obc_data"][i]["name"]] = tlm_db diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index 564ad99f5..e27686d07 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -4,9 +4,12 @@ """ import os +import sys +# from collections import OrderedDict +import pprint def GenerateTlmBuffer(settings, other_obc_dbs): - # DATA_START_ROW = 7 + DATA_START_ROW = 7 for i in range(len(settings["other_obc_data"])): if not settings["other_obc_data"][i]["is_enable"]: @@ -38,6 +41,48 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_h += "}} {_obc_name_upper}_Buffer;\n" body_h += "\n" + body_h += "typedef struct\n" + body_h += "{{\n" + for tlm in tlm_db: + tlm_name = tlm['tlm_name'] + tlm_name_lower = tlm_name.lower() + + # pprint.pprint(tlm['data'][DATA_START_ROW:]) + last_var_type = "" + tlm_struct_tree = {} # python3.7以上を想定しているので,キーの順番は保存されていることが前提 + # tlm_struct_tree = collections.OrderedDict() # やっぱこっちで + for j in range(DATA_START_ROW, len(tlm['data'])): + comment = tlm['data'][j][0] + name = tlm['data'][j][1] + var_type = tlm['data'][j][2] + if comment == "" and name == "": # CommentもNameも空白なら打ち切り + break + if comment != "": + continue + if name == "": + continue + if var_type == "": + var_type = last_var_type + last_var_type = var_type + if last_var_type == "": + continue + + name_tree = name.lower().split(".")[2:] # OBC名.テレメ名.HOGE.FUGA を想定 + name_path = "/".join(name_tree) + if (SetStructTree_(tlm_struct_tree, name_path, var_type)): + print("Error: Tlm DB Struct Parse Err at " + name, file=sys.stderr) + sys.exit(1) + + # pprint.pprint(tlm_struct_tree) + # for k, v in tlm_struct_tree.items(): + # print(k) + # print(v) + # print("") + + body_h += GenerateStructDef_(tlm_struct_tree, tlm_name_lower) + + body_h += "}} {_obc_name_upper}_TlmData;\n" + body_h += "\n" body_h += "extern const {_obc_name_upper}_Buffer* {_obc_name_lower}_buffer;\n" body_h += "\n" body_h += "void {_obc_name_upper}_buffer_init(void);\n" @@ -135,9 +180,6 @@ def OutputTlmBufferC_(file_path, name, body): fh.write(output.format(_obc_name_upper=name_upper, _obc_name_lower=name_lower, _obc_name_capit=name_capit)) - - - def OutputTlmBufferH_(file_path, name, body): name_upper = name.upper() name_lower = name.lower() @@ -169,3 +211,49 @@ def OutputTlmBufferH_(file_path, name, body): with open(file_path, mode='w', encoding='shift_jis') as fh: fh.write(output.format(_obc_name_upper=name_upper, _obc_name_lower=name_lower, _obc_name_capit=name_capit)) + +def GetStructTree_(dict, path, sep="/", default=None): + path_list = path.split(sep) + def _(dict, path_list, sep, default): + if len(path_list) == 0: + return default + if len(path_list) == 1: + return dict.get(path_list[0], default) + else: + return _(dict.get(path_list[0], {}), path_list[1:], sep, default) + return _(dict, path_list, sep=sep, default=None) + + +def SetStructTree_(dict, path, val, sep="/"): + path_list = path.split(sep) + def _(dict, path_list, val, sep): + if len(path_list) == 0: + return 1 # err + if len(path_list) == 1: + key = path_list[0] + if key in dict: + return 1 # 上書きエラー + else: + dict[key] = val + return 0 + else: + key = path_list[0] + if not key in dict: + dict[key] = {} + return _(dict[key], path_list[1:], val, sep) + return _(dict, path_list, val, sep=sep) + + +def GenerateStructDef_(tree, name): + def _(tree, name, indent): + output = "" + output += " " * (indent) + "struct\n" + output += " " * (indent) + "{{\n" + for k, v in tree.items(): + if type(v) == dict: + output += _(v, k, indent+2) + continue + output += " " * (indent+2) + v + " " + k + ";\n" + output += " " * (indent) + "}} " + name + ";\n" + return output + return _(tree, name, 2) From 845ea55cdd7d3cfc602a2cbf4b63c606c7db1540 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 23 Feb 2021 02:00:02 +0900 Subject: [PATCH 045/141] change output file for tlm data struct --- my_mod/tlm_buffer.py | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index e27686d07..5245865d5 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -23,6 +23,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c = "" body_h = "" + tlmdef_body_h = "" body_c += "static {_obc_name_upper}_Buffer {_obc_name_lower}_buffer_;\n" body_c += "const {_obc_name_upper}_Buffer* {_obc_name_lower}_buffer;\n" @@ -41,8 +42,8 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_h += "}} {_obc_name_upper}_Buffer;\n" body_h += "\n" - body_h += "typedef struct\n" - body_h += "{{\n" + tlmdef_body_h += "typedef struct\n" + tlmdef_body_h += "{{\n" for tlm in tlm_db: tlm_name = tlm['tlm_name'] tlm_name_lower = tlm_name.lower() @@ -79,10 +80,10 @@ def GenerateTlmBuffer(settings, other_obc_dbs): # print(v) # print("") - body_h += GenerateStructDef_(tlm_struct_tree, tlm_name_lower) + tlmdef_body_h += GenerateStructDef_(tlm_struct_tree, tlm_name_lower) + + tlmdef_body_h += "}} {_obc_name_upper}_TlmData;\n" - body_h += "}} {_obc_name_upper}_TlmData;\n" - body_h += "\n" body_h += "extern const {_obc_name_upper}_Buffer* {_obc_name_lower}_buffer;\n" body_h += "\n" body_h += "void {_obc_name_upper}_buffer_init(void);\n" @@ -146,6 +147,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): output_file_path = settings["c2a_root_dir"] + r"src_user/Drivers/" + settings["other_obc_data"][i]["driver_path"]; OutputTlmBufferC_(output_file_path + obc_name.capitalize() + "TelemetryBuffer.c", obc_name, body_c) OutputTlmBufferH_(output_file_path + obc_name.capitalize() + "TelemetryBuffer.h", obc_name, body_h) + OutputTlmDataDefH_(output_file_path + obc_name.capitalize() + "TelemetryDataDefinitions.h", obc_name, tlmdef_body_h) def OutputTlmBufferC_(file_path, name, body): @@ -212,6 +214,36 @@ def OutputTlmBufferH_(file_path, name, body): fh.write(output.format(_obc_name_upper=name_upper, _obc_name_lower=name_lower, _obc_name_capit=name_capit)) +def OutputTlmDataDefH_(file_path, name, body): + name_upper = name.upper() + name_lower = name.lower() + name_capit = name.capitalize() + + output = "" + output += ''' +/** + * @file {_obc_name_capit}TelemetryDataDefinitions.h + * @brief バッファリングされているテレメをパースしてMOBC内でかんたんに利用できるようにするためのテレメデータ構造体定義 + * @note このコードは自動生成されています! + * @author 鈴本 遼 + * @date 2021/02/14 + */ +#ifndef {_obc_name_upper}_TELEMETRY_DATA_DEFINITIONS_H_ +#define {_obc_name_upper}_TELEMETRY_DATA_DEFINITIONS_H_ + +'''[1:] # 最初の改行を除く + + output += body + + output += ''' + +#endif +'''[1:] # 最初の改行を除く + + with open(file_path, mode='w', encoding='shift_jis') as fh: + fh.write(output.format(_obc_name_upper=name_upper, _obc_name_lower=name_lower, _obc_name_capit=name_capit)) + + def GetStructTree_(dict, path, sep="/", default=None): path_list = path.split(sep) def _(dict, path_list, sep, default): From db327a9835488fa8f59d97052d6cc68738d32d97 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 23 Feb 2021 02:04:33 +0900 Subject: [PATCH 046/141] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e091dd18f..55121ea8f 100644 --- a/README.md +++ b/README.md @@ -17,10 +17,11 @@ $ python GenerateC2ACode.py ## 設定 `settings.json` にて記述する. `1` とした場合,現在は以下のみ生成される. -- TobcTelemetryBuffer.c -- TobcTelemetryBuffer.h - TobcCommandDefinitions.h - TobcTelemetryDefinitions.h +- TobcTelemetryBuffer.c +- TobcTelemetryBuffer.h +- TobcTelemetryDataDefinitions.h ``` { From 8cea44974bc055c0be1c8699a0ba51b9cd306a17 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 23 Feb 2021 02:14:28 +0900 Subject: [PATCH 047/141] fix --- my_mod/tlm_buffer.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index 5245865d5..5705b6274 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -28,6 +28,8 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += "static {_obc_name_upper}_Buffer {_obc_name_lower}_buffer_;\n" body_c += "const {_obc_name_upper}_Buffer* {_obc_name_lower}_buffer;\n" body_c += "\n" + body_h += "#define {_obc_name_upper}_TELEMETRY_BUFFE_SIZE (" + str(contents_len) + ")\n" + body_h += "\n" body_h += "typedef struct\n" body_h += "{{\n" for tlm in tlm_db: @@ -36,7 +38,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_h += " struct\n" body_h += " {{\n" body_h += " int size;\n" - body_h += " uint8_t buffer[" + str(contents_len) + "];\n" + body_h += " uint8_t buffer[{_obc_name_upper}_TELEMETRY_BUFFE_SIZE];\n" body_h += " }} " + tlm_name_lower + ";\n" body_c += "static DRIVER_SUPER_ERR_CODE {_obc_name_upper}_analyze_tlm_" + tlm_name_lower + "_(DriverSuperStreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ");\n" @@ -131,12 +133,12 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += " uint32_t contents_len = tlm_len - DRIVER_SUPER_C2AFMT_TCP_TLM_SECONDARY_HEADER_SIZE - 1; // FIXME: CCSDSは1起算?\n" body_c += " uint8_t* contents_pos = (p_stream_config->rx_frame) + DRIVER_SUPER_ISSLFMT_COMMON_HEADER_SIZE + DRIVER_SUPER_C2AFMT_TCP_TLM_PRIMARY_HEADER_SIZE + DRIVER_SUPER_C2AFMT_TCP_TLM_SECONDARY_HEADER_SIZE;\n" body_c += "\n" - body_c += " if (contents_len > " + str(contents_len) + ") return DRIVER_SUPER_ERR_CODE_ERR;\n" + body_c += " if (contents_len > {_obc_name_upper}_TELEMETRY_BUFFE_SIZE) return DRIVER_SUPER_ERR_CODE_ERR;\n" body_c += " memcpy({_obc_name_lower}_buffer_." + tlm_name_lower + ".buffer, contents_pos, (size_t)contents_len);\n" body_c += " {_obc_name_lower}_buffer_." + tlm_name_lower + ".size = (int)contents_len;\n" body_c += "\n" body_c += " // [TODO] フレームの中身をパースしてMOBCでもろもろにアクセスするためのコード\n" - body_c += " // テレメDBと同じ構造の構造体を定義して代入する?\n" + body_c += " // 例えばTOBCであれば, TOBC_TlmData に代入していく\n" body_c += " // 問題はビットフィールドを使ってるやつら\n" body_c += " (void)" + driver_name + "; // 仮\n" body_c += " return DRIVER_SUPER_ERR_CODE_OK;\n" From f62c559ab27b04f0fa5e421e6bfbadb7b49fa44b Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 23 Feb 2021 03:36:18 +0900 Subject: [PATCH 048/141] add auto parse code --- my_mod/tlm_buffer.py | 77 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 72 insertions(+), 5 deletions(-) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index 5705b6274..9077e14e0 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -124,23 +124,90 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += "}}\n" body_c += "\n" for tlm in tlm_db: + conv_tpye_to_temp = { + 'int8_t' : 'temp_i8', + 'int16_t' : 'temp_i16', + 'int32_t' : 'temp_i32', + 'uint8_t' : 'temp_u8', + 'uint16_t' : 'temp_u16', + 'uint32_t' : 'temp_u32', + 'float' : 'temp_f', + 'double' : 'temp_d', + } + conv_tpye_to_size = { + 'int8_t' : 1, + 'int16_t' : 2, + 'int32_t' : 4, + 'uint8_t' : 1, + 'uint16_t' : 2, + 'uint32_t' : 4, + 'float' : 4, + 'double' : 8 + } tlm_name = tlm['tlm_name'] tlm_name_upper = tlm_name.upper() tlm_name_lower = tlm_name.lower() body_c += "static DRIVER_SUPER_ERR_CODE {_obc_name_upper}_analyze_tlm_" + tlm_name_lower + "_(DriverSuperStreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ")\n" body_c += "{{\n" body_c += " uint32_t tlm_len = DRIVER_SUPER_ISSLFMT_get_tlm_length(p_stream_config);\n" + body_c += " uint8_t* f = p_stream_config->rx_frame;\n" body_c += " uint32_t contents_len = tlm_len - DRIVER_SUPER_C2AFMT_TCP_TLM_SECONDARY_HEADER_SIZE - 1; // FIXME: CCSDSは1起算?\n" - body_c += " uint8_t* contents_pos = (p_stream_config->rx_frame) + DRIVER_SUPER_ISSLFMT_COMMON_HEADER_SIZE + DRIVER_SUPER_C2AFMT_TCP_TLM_PRIMARY_HEADER_SIZE + DRIVER_SUPER_C2AFMT_TCP_TLM_SECONDARY_HEADER_SIZE;\n" + body_c += " uint8_t* contents_pos = f + DRIVER_SUPER_ISSLFMT_COMMON_HEADER_SIZE + DRIVER_SUPER_C2AFMT_TCP_TLM_PRIMARY_HEADER_SIZE + DRIVER_SUPER_C2AFMT_TCP_TLM_SECONDARY_HEADER_SIZE;\n" + for k, v in conv_tpye_to_temp.items(): + if k == "float" or k == "double": + body_c += " " + k + " " + v + " = 0.0f;\n" + else: + body_c += " " + k + " " + v + " = 0;\n" body_c += "\n" + body_c += " // GSへのテレメ中継のためのバッファーへのコピー\n" body_c += " if (contents_len > {_obc_name_upper}_TELEMETRY_BUFFE_SIZE) return DRIVER_SUPER_ERR_CODE_ERR;\n" body_c += " memcpy({_obc_name_lower}_buffer_." + tlm_name_lower + ".buffer, contents_pos, (size_t)contents_len);\n" body_c += " {_obc_name_lower}_buffer_." + tlm_name_lower + ".size = (int)contents_len;\n" body_c += "\n" - body_c += " // [TODO] フレームの中身をパースしてMOBCでもろもろにアクセスするためのコード\n" - body_c += " // 例えばTOBCであれば, TOBC_TlmData に代入していく\n" - body_c += " // 問題はビットフィールドを使ってるやつら\n" - body_c += " (void)" + driver_name + "; // 仮\n" + body_c += " // MOBC内部でテレメデータへアクセスしやすいようにするための構造体へのパース\n" + last_var_type = "" + for j in range(DATA_START_ROW, len(tlm['data'])): + comment = tlm['data'][j][0] + name = tlm['data'][j][1] + var_type = tlm['data'][j][2] + if comment == "" and name == "": # CommentもNameも空白なら打ち切り + break + if comment != "": + continue + if name == "": + continue + if var_type == "": + var_type = last_var_type + last_var_type = var_type + if last_var_type == "": + continue + + oct_pos = int(tlm['data'][j][6]) + bit_pos = int(tlm['data'][j][7]) + bit_len = int(tlm['data'][j][8]) + is_compression = 0 # テレメ圧縮フラグ for ビットフィールドをつかってる奴ら + if tlm['data'][j][2] == "" or tlm['data'][j+1][2] == "": + is_compression = 1 + if (tlm['data'][j+1][0] == "" and tlm['data'][j+1][1] == "" and tlm['data'][j][2] != ""): # 最終行の除外 + is_compression = 0 + + name_tree = name.lower().split(".")[2:] # OBC名.テレメ名.HOGE.FUGA を想定 + name_path = ".".join(name_tree) + var_name = driver_name + "->tlm_data." + tlm_name_lower + "." + name_path + if (is_compression): + body_c += " endian_memcpy(&" + conv_tpye_to_temp[var_type] + ", &(f[" + str(oct_pos) + "]), " + str(conv_tpye_to_size[var_type]) + ");\n" + body_c += " " + conv_tpye_to_temp[var_type] + " >>= " + str(bit_pos) + ";\n" + body_c += " " + conv_tpye_to_temp[var_type] + " &= " + hex(int("0b" + "1" * bit_len, 2)) + ";\n" + body_c += " " + var_name + " = " + conv_tpye_to_temp[var_type] + ";\n" + else: + body_c += " endian_memcpy(&(" + var_name + "), &(f[" + str(oct_pos) + "]), " + str(conv_tpye_to_size[var_type]) + ");\n" + + body_c += " // TODO: ビットフィールドをつかっている系は,様々なパターンがあり得るので,今後,バグが出ないか注視する\n" + body_c += "\n" + body_c += " // ワーニング回避\n" + for k, v in conv_tpye_to_temp.items(): + body_c += " (void)" + v + ";\n" + body_c += "\n" body_c += " return DRIVER_SUPER_ERR_CODE_OK;\n" body_c += "}}\n" body_c += "\n" From 1c62372e944dd96460032e47b8084cfd68d9fac6 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Thu, 25 Feb 2021 09:35:16 +0900 Subject: [PATCH 049/141] fix float, double init value --- my_mod/tlm_buffer.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index 9077e14e0..f020c5cdb 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -154,8 +154,10 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += " uint32_t contents_len = tlm_len - DRIVER_SUPER_C2AFMT_TCP_TLM_SECONDARY_HEADER_SIZE - 1; // FIXME: CCSDSは1起算?\n" body_c += " uint8_t* contents_pos = f + DRIVER_SUPER_ISSLFMT_COMMON_HEADER_SIZE + DRIVER_SUPER_C2AFMT_TCP_TLM_PRIMARY_HEADER_SIZE + DRIVER_SUPER_C2AFMT_TCP_TLM_SECONDARY_HEADER_SIZE;\n" for k, v in conv_tpye_to_temp.items(): - if k == "float" or k == "double": + if k == "float": body_c += " " + k + " " + v + " = 0.0f;\n" + elif k == "double": + body_c += " " + k + " " + v + " = 0.0;\n" else: body_c += " " + k + " " + v + " = 0;\n" body_c += "\n" From 803c26b0d0f5c6f85b2c4791a0f3d615bf580f7c Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Thu, 25 Feb 2021 09:40:11 +0900 Subject: [PATCH 050/141] fix return code --- my_mod/tlm_buffer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index f020c5cdb..d93394b55 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -119,7 +119,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += " return {_obc_name_upper}_analyze_tlm_" + tlm_name_lower + "_(p_stream_config, " + driver_name + ");\n" body_c += " default:\n" body_c += " " + settings["other_obc_data"][i]["code_when_tlm_not_found"] + "\n" - body_c += " return DRIVER_SUPER_ERR_CODE_OK;\n" + body_c += " return DRIVER_SUPER_ERR_CODE_ERR;\n" body_c += " }}\n" body_c += "}}\n" body_c += "\n" From 7b67b2fecc0230e0c1b66a54b6bb6c437a19f76f Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Fri, 26 Feb 2021 11:13:34 +0900 Subject: [PATCH 051/141] Update README.md --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 55121ea8f..8db497165 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,10 @@ $ python GenerateC2ACode.py ``` ## 設定 -`settings.json` にて記述する. -`1` とした場合,現在は以下のみ生成される. +`settings.json` にて記述する. + +`is_main_obc` は,MOBCかそれ以外のOBCかを制御する. +`1` とした場合,MOBCを意図したコードが生成され,加えて以下が生成される. - TobcCommandDefinitions.h - TobcTelemetryDefinitions.h - TobcTelemetryBuffer.c From f145157dae3ca64f7b8ce27d2d3adeabae2a600a Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Fri, 26 Feb 2021 11:13:52 +0900 Subject: [PATCH 052/141] fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8db497165..78cc98422 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ $ python GenerateC2ACode.py ## 設定 `settings.json` にて記述する. -`is_main_obc` は,MOBCかそれ以外のOBCかを制御する. +`is_main_obc` は,MOBCかそれ以外のOBCかを制御する. `1` とした場合,MOBCを意図したコードが生成され,加えて以下が生成される. - TobcCommandDefinitions.h - TobcTelemetryDefinitions.h From 7a16f4e6f97276505ec3c823d997ad7e7b2df84c Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Mon, 22 Mar 2021 03:51:26 +0900 Subject: [PATCH 053/141] fix for ds --- my_mod/tlm_buffer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index d93394b55..1f00ffd7d 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -150,7 +150,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += "static DRIVER_SUPER_ERR_CODE {_obc_name_upper}_analyze_tlm_" + tlm_name_lower + "_(DriverSuperStreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ")\n" body_c += "{{\n" body_c += " uint32_t tlm_len = DRIVER_SUPER_ISSLFMT_get_tlm_length(p_stream_config);\n" - body_c += " uint8_t* f = p_stream_config->rx_frame;\n" + body_c += " uint8_t* f = DSSC_get_rx_frame(p_stream_config);\n" body_c += " uint32_t contents_len = tlm_len - DRIVER_SUPER_C2AFMT_TCP_TLM_SECONDARY_HEADER_SIZE - 1; // FIXME: CCSDSは1起算?\n" body_c += " uint8_t* contents_pos = f + DRIVER_SUPER_ISSLFMT_COMMON_HEADER_SIZE + DRIVER_SUPER_C2AFMT_TCP_TLM_PRIMARY_HEADER_SIZE + DRIVER_SUPER_C2AFMT_TCP_TLM_SECONDARY_HEADER_SIZE;\n" for k, v in conv_tpye_to_temp.items(): From ffeaf86b058644053fd6bc536a85e073ee79a33c Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Mon, 22 Mar 2021 03:56:15 +0900 Subject: [PATCH 054/141] add const --- my_mod/tlm_buffer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index 1f00ffd7d..2cb4c7557 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -150,9 +150,9 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += "static DRIVER_SUPER_ERR_CODE {_obc_name_upper}_analyze_tlm_" + tlm_name_lower + "_(DriverSuperStreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ")\n" body_c += "{{\n" body_c += " uint32_t tlm_len = DRIVER_SUPER_ISSLFMT_get_tlm_length(p_stream_config);\n" - body_c += " uint8_t* f = DSSC_get_rx_frame(p_stream_config);\n" + body_c += " const uint8_t* f = DSSC_get_rx_frame(p_stream_config);\n" body_c += " uint32_t contents_len = tlm_len - DRIVER_SUPER_C2AFMT_TCP_TLM_SECONDARY_HEADER_SIZE - 1; // FIXME: CCSDSは1起算?\n" - body_c += " uint8_t* contents_pos = f + DRIVER_SUPER_ISSLFMT_COMMON_HEADER_SIZE + DRIVER_SUPER_C2AFMT_TCP_TLM_PRIMARY_HEADER_SIZE + DRIVER_SUPER_C2AFMT_TCP_TLM_SECONDARY_HEADER_SIZE;\n" + body_c += " const uint8_t* contents_pos = f + DRIVER_SUPER_ISSLFMT_COMMON_HEADER_SIZE + DRIVER_SUPER_C2AFMT_TCP_TLM_PRIMARY_HEADER_SIZE + DRIVER_SUPER_C2AFMT_TCP_TLM_SECONDARY_HEADER_SIZE;\n" for k, v in conv_tpye_to_temp.items(): if k == "float": body_c += " " + k + " " + v + " = 0.0f;\n" From 606a1e7ba6b8acfd29af4441542a7fe471b9c2f4 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 13 Apr 2021 19:46:00 +0900 Subject: [PATCH 055/141] update --- my_mod/cmd_def.py | 5 +---- my_mod/tlm_def.py | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/my_mod/cmd_def.py b/my_mod/cmd_def.py index 948fc7fc1..874ef10e9 100644 --- a/my_mod/cmd_def.py +++ b/my_mod/cmd_def.py @@ -114,6 +114,7 @@ def OutputCmdDefC_(file_path, body): * @author 鈴本 遼 * @date 2020/08/23 */ +#include "../../src_core/CmdTlm/CommandAnalyze.h" #include "CommandDefinitions.h" #include "CommandSource.h" @@ -147,8 +148,6 @@ def OutputCmdDefH_(file_path, body): #ifndef COMMAND_DEFINITIONS_H_ #define COMMAND_DEFINITIONS_H_ -#include "../../src_core/CmdTlm/CommandAnalyze.h" - typedef enum { '''[1:] # 最初の改行を除く @@ -160,8 +159,6 @@ def OutputCmdDefH_(file_path, body): Cmd_CODE_MAX } CMD_CODE; -void CA_load_cmd_table(CmdInfo cmd_table_[CMD_MAX_CMDS]); - #endif '''[1:] # 最初の改行を除く diff --git a/my_mod/tlm_def.py b/my_mod/tlm_def.py index 34b2ac22f..16bbf37fd 100644 --- a/my_mod/tlm_def.py +++ b/my_mod/tlm_def.py @@ -250,6 +250,7 @@ def OutputTlmDefC_(file_path, body): * @author 鈴本 遼 * @date 2020/08/23 */ +#include "../../src_core/CmdTlm/TelemetryFrame.h" #include "TelemetryDefinitions.h" #include "TelemetrySource.h" @@ -279,8 +280,6 @@ def OutputTlmDefH_(file_path, body): #ifndef TELEMETRY_DEFINITIONS_H_ #define TELEMETRY_DEFINITIONS_H_ -#include "../../src_core/CmdTlm/TelemetryFrame.h" - typedef enum { '''[1:] # 最初の改行を除く @@ -292,8 +291,6 @@ def OutputTlmDefH_(file_path, body): TLM_CODE_MAX } TLM_CODE; -void TF_load_tlm_table(TlmInfo tlm_table_[TLM_MAX_TLMS]); - #endif '''[1:] # 最初の改行を除く From 8359d4c520fe5657bcc1f5adbbbc766675efeb51 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Thu, 3 Jun 2021 02:14:22 +0900 Subject: [PATCH 056/141] update for new naming rule --- my_mod/cmd_def.py | 26 +++++++++----------------- my_mod/tlm_buffer.py | 31 ++++++++++++------------------- my_mod/tlm_def.py | 31 ++++++++++++++----------------- settings.json | 19 ++++++++++--------- 4 files changed, 45 insertions(+), 62 deletions(-) diff --git a/my_mod/cmd_def.py b/my_mod/cmd_def.py index 874ef10e9..d880c8399 100644 --- a/my_mod/cmd_def.py +++ b/my_mod/cmd_def.py @@ -8,7 +8,7 @@ def GenerateCmdDef(settings, sgc_db): output_file_path = settings["c2a_root_dir"] + r"src_user/CmdTlm/" - output_file_name_base = "CommandDefinitions" + output_file_name_base = "command_definitions" DATA_SART_ROW = 3 @@ -38,7 +38,7 @@ def GenerateCmdDef(settings, sgc_db): def GenerateBctDef(settings, bct_db): output_file_path = settings["c2a_root_dir"] + r"src_user/CmdTlm/" - output_file_name = "BlockCommandDefinitions.h" + output_file_name = "block_command_definitions.h" DATA_SART_ROW = 2 @@ -99,7 +99,7 @@ def GenerateOtherObcCmdDef(settings, other_obc_dbs): cmd_code = cmd_name.replace("Cmd_", name_upper+"_Cmd_CODE_") body_h += " " + cmd_code + " = " + cmd_id + ",\n" # print(body_h) - output_file_path = settings["c2a_root_dir"] + r"src_user/Drivers/" + settings["other_obc_data"][i]["driver_path"] + name_capit + "CommandDefinitions.h" + output_file_path = settings["c2a_root_dir"] + r"src_user/Drivers/" + settings["other_obc_data"][i]["driver_path"] + name_lower + "_command_definitions.h" OutputOtherObcCmdDefH_(output_file_path, obc_name, body_h) @@ -108,15 +108,13 @@ def OutputCmdDefC_(file_path, body): output += ''' #pragma section REPRO /** - * @file CommandDefinitions.c + * @file command_definitions.c * @brief コマンド定義 * @note このコードは自動生成されています! - * @author 鈴本 遼 - * @date 2020/08/23 */ #include "../../src_core/CmdTlm/CommandAnalyze.h" -#include "CommandDefinitions.h" -#include "CommandSource.h" +#include "command_definitions.h" +#include "command_source.h" void CA_load_cmd_table(CmdInfo cmd_table_[CMD_MAX_CMDS]) { @@ -139,11 +137,9 @@ def OutputCmdDefH_(file_path, body): output = "" output += ''' /** - * @file CommandDefinitions.h + * @file command_definitions.h * @brief コマンド定義 * @note このコードは自動生成されています! - * @author 鈴本 遼 - * @date 2020/08/23 */ #ifndef COMMAND_DEFINITIONS_H_ #define COMMAND_DEFINITIONS_H_ @@ -170,11 +166,9 @@ def OutputBctDef_(file_path, body): output = "" output += ''' /** - * @file BlockCommandDefinitions.h + * @file block_command_definitions.h * @brief ブロックコマンド定義 * @note このコードは自動生成されています! - * @author 鈴本 遼 - * @date 2020/11/14 */ #ifndef BLOCK_COMMAND_DEFINITIONS_H_ #define BLOCK_COMMAND_DEFINITIONS_H_ @@ -206,11 +200,9 @@ def OutputOtherObcCmdDefH_(file_path, name, body): output = "" output += ''' /** - * @file {_obc_name_capit}CommandDefinitions.h + * @file {_obc_name_lower}_command_definitions.h * @brief コマンド定義 * @note このコードは自動生成されています! - * @author 鈴本 遼 - * @date 2020/08/23 */ #ifndef {_obc_name_upper}_COMMAND_DEFINITIONS_H_ #define {_obc_name_upper}_COMMAND_DEFINITIONS_H_ diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index 2cb4c7557..e70f99635 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -26,7 +26,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): tlmdef_body_h = "" body_c += "static {_obc_name_upper}_Buffer {_obc_name_lower}_buffer_;\n" - body_c += "const {_obc_name_upper}_Buffer* {_obc_name_lower}_buffer;\n" + body_c += "const {_obc_name_upper}_Buffer* const {_obc_name_lower}_buffer = &{_obc_name_lower}_buffer_;\n" body_c += "\n" body_h += "#define {_obc_name_upper}_TELEMETRY_BUFFE_SIZE (" + str(contents_len) + ")\n" body_h += "\n" @@ -86,17 +86,16 @@ def GenerateTlmBuffer(settings, other_obc_dbs): tlmdef_body_h += "}} {_obc_name_upper}_TlmData;\n" - body_h += "extern const {_obc_name_upper}_Buffer* {_obc_name_lower}_buffer;\n" + body_h += "extern const {_obc_name_upper}_Buffer* const {_obc_name_lower}_buffer;\n" body_h += "\n" body_h += "void {_obc_name_upper}_buffer_init(void);\n" + body_h += "\n" body_h += "DRIVER_SUPER_ERR_CODE {_obc_name_upper}_buffer_tlm_contents(DriverSuperStreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ");\n" body_c += "\n" body_c += "void {_obc_name_upper}_buffer_init(void)\n" body_c += "{{\n" - body_c += " {_obc_name_lower}_buffer = &{_obc_name_lower}_buffer_;\n" - body_c += "\n" for tlm in tlm_db: tlm_name = tlm['tlm_name'] tlm_name_lower = tlm_name.lower() @@ -216,9 +215,9 @@ def GenerateTlmBuffer(settings, other_obc_dbs): output_file_path = settings["c2a_root_dir"] + r"src_user/Drivers/" + settings["other_obc_data"][i]["driver_path"]; - OutputTlmBufferC_(output_file_path + obc_name.capitalize() + "TelemetryBuffer.c", obc_name, body_c) - OutputTlmBufferH_(output_file_path + obc_name.capitalize() + "TelemetryBuffer.h", obc_name, body_h) - OutputTlmDataDefH_(output_file_path + obc_name.capitalize() + "TelemetryDataDefinitions.h", obc_name, tlmdef_body_h) + OutputTlmBufferC_(output_file_path + obc_name.lower() + "_telemetry_buffer.c", obc_name, body_c) + OutputTlmBufferH_(output_file_path + obc_name.lower() + "_telemetry_buffer.h", obc_name, body_h) + OutputTlmDataDefH_(output_file_path + obc_name.lower() + "_telemetry_data_definitions.h", obc_name, tlmdef_body_h) def OutputTlmBufferC_(file_path, name, body): @@ -230,15 +229,13 @@ def OutputTlmBufferC_(file_path, name, body): output += ''' #pragma section REPRO /** - * @file {_obc_name_capit}TelemetryBuffer.c + * @file {_obc_name_lower}_telemetry_buffer.c * @brief テレメトリバッファー(テレメ中継) * @note このコードは自動生成されています! - * @author 鈴本 遼 - * @date 2021/02/14 */ -#include "./{_obc_name_capit}TelemetryDefinitions.h" -#include "./{_obc_name_capit}TelemetryBuffer.h" +#include "./{_obc_name_lower}_telemetry_definitions.h" +#include "./{_obc_name_lower}_telemetry_buffer.h" #include "string.h" // for memcpy '''[1:] # 最初の改行を除く @@ -261,16 +258,14 @@ def OutputTlmBufferH_(file_path, name, body): output = "" output += ''' /** - * @file {_obc_name_capit}TelemetryBuffer.h + * @file {_obc_name_lower}_telemetry_buffer.h * @brief テレメトリバッファー(テレメ中継) * @note このコードは自動生成されています! - * @author 鈴本 遼 - * @date 2021/02/14 */ #ifndef {_obc_name_upper}_TELEMETRY_BUFFER_H_ #define {_obc_name_upper}_TELEMETRY_BUFFER_H_ -#include "./{_obc_name_upper}.h" +#include "./{_obc_name_lower}.h" '''[1:] # 最初の改行を除く @@ -293,11 +288,9 @@ def OutputTlmDataDefH_(file_path, name, body): output = "" output += ''' /** - * @file {_obc_name_capit}TelemetryDataDefinitions.h + * @file {_obc_name_lower}_telemetry_data_definitions.h * @brief バッファリングされているテレメをパースしてMOBC内でかんたんに利用できるようにするためのテレメデータ構造体定義 * @note このコードは自動生成されています! - * @author 鈴本 遼 - * @date 2021/02/14 */ #ifndef {_obc_name_upper}_TELEMETRY_DATA_DEFINITIONS_H_ #define {_obc_name_upper}_TELEMETRY_DATA_DEFINITIONS_H_ diff --git a/my_mod/tlm_def.py b/my_mod/tlm_def.py index 16bbf37fd..e648b4e53 100644 --- a/my_mod/tlm_def.py +++ b/my_mod/tlm_def.py @@ -8,7 +8,7 @@ def GenerateTlmDef(settings, tlm_db, other_obc_dbs): output_file_path = settings["c2a_root_dir"] + r"src_user/CmdTlm/" - output_file_name_base = "TelemetryDefinitions" + output_file_name_base = "telemetry_definitions" DATA_START_ROW = 7 @@ -120,8 +120,9 @@ def GetTlmDefCOfOtherObcFunDef_(settings, tlm_db, other_obc_dbs): temp_c = "" temp_c += "\n" + temp_c += "// {_obc_name_upper} TLM\n" for tlm in oter_obc_tlm_db: - temp_c += "static int Tlm_{_obc_name_upper}_" + tlm['tlm_name'].upper() + "_(unsigned char* contents, int max_len);\n" + temp_c += "static int Tlm_" + tlm['tlm_name'].upper() + "_(unsigned char* contents, int max_len);\n" body_c += temp_c.format(_obc_name_upper=obc_name.upper(), _obc_name_lower=obc_name.lower(), _obc_name_capit=obc_name.capitalize()) @@ -140,8 +141,9 @@ def GetTlmDefCOfOtherObcFunLoad_(settings, tlm_db, other_obc_dbs): temp_c = "" temp_c += "\n" + temp_c += " // {_obc_name_upper} TLM\n" for tlm in oter_obc_tlm_db: - temp_c += " tlm_table_[Tlm_CODE_{_obc_name_upper}_" + tlm['tlm_name'].upper() + "].tlm_func = Tlm_{_obc_name_upper}_" + tlm['tlm_name'].upper() + "_;\n" + temp_c += " tlm_table_[Tlm_CODE_" + tlm['tlm_name'].upper() + "].tlm_func = Tlm_" + tlm['tlm_name'].upper() + "_;\n" body_c += temp_c.format(_obc_name_upper=obc_name.upper(), _obc_name_lower=obc_name.lower(), _obc_name_capit=obc_name.capitalize()) return body_c @@ -163,7 +165,7 @@ def GetTlmDefCOfOtherObcFunBody_(settings, tlm_db, other_obc_dbs): tlm_name_upper = tlm_name.upper() tlm_name_lower = tlm_name.lower() temp_c += "\n" - temp_c += "static int Tlm_{_obc_name_upper}_" + tlm_name_upper + "_(unsigned char* contents, int max_len)\n" + temp_c += "static int Tlm_" + tlm_name_upper + "_(unsigned char* contents, int max_len)\n" temp_c += "{{\n" temp_c += " int buffer_size = {_obc_name_lower}_buffer->" + tlm_name_lower + ".size;\n" temp_c += "\n" @@ -209,8 +211,9 @@ def GetTlmDefHOfOtherObc_(settings, tlm_db, other_obc_dbs): sys.exit(1) body_h += "\n" + temp_h += " // {_obc_name_upper} TLM\n" for tlm in oter_obc_tlm_db: - temp_h += " Tlm_CODE_{_obc_name_upper}_" + tlm['tlm_name'].upper() + " = " + tlm['tlm_id'] + ",\n" + temp_h += " Tlm_CODE_" + tlm['tlm_name'].upper() + " = " + tlm['tlm_id'] + ",\n" body_h += temp_h.format(_obc_name_upper=obc_name.upper(), _obc_name_lower=obc_name.lower(), _obc_name_capit=obc_name.capitalize()) @@ -234,7 +237,7 @@ def GenerateOtherObcTlmDef(settings, other_obc_dbs): # " TOBC_Tlm_CODE_HK = 0xf0," for tlm in tlm_db: body_h += " {_obc_name_upper}_Tlm_CODE_" + tlm['tlm_name'].upper() + " = " + tlm['tlm_id'] + ",\n" - output_file_path = settings["c2a_root_dir"] + r"src_user/Drivers/" + settings["other_obc_data"][i]["driver_path"] + obc_name.capitalize() + "TelemetryDefinitions.h" + output_file_path = settings["c2a_root_dir"] + r"src_user/Drivers/" + settings["other_obc_data"][i]["driver_path"] + obc_name.lower() + "_telemetry_definitions.h" OutputOtherObcTlmDefH(output_file_path, obc_name, body_h) @@ -244,15 +247,13 @@ def OutputTlmDefC_(file_path, body): output += ''' #pragma section REPRO /** - * @file TelemetryDefinitions.c + * @file telemetry_definitions.c * @brief テレメトリ定義 * @note このコードは自動生成されています! - * @author 鈴本 遼 - * @date 2020/08/23 */ #include "../../src_core/CmdTlm/TelemetryFrame.h" -#include "TelemetryDefinitions.h" -#include "TelemetrySource.h" +#include "telemetry_definitions.h" +#include "telemetry_source.h" '''[1:] # 最初の改行を除く @@ -271,11 +272,9 @@ def OutputTlmDefH_(file_path, body): output = "" output += ''' /** - * @file TelemetryDefinitions.h + * @file telemetry_definitions.h * @brief テレメトリ定義 * @note このコードは自動生成されています! - * @author 鈴本 遼 - * @date 2020/08/23 */ #ifndef TELEMETRY_DEFINITIONS_H_ #define TELEMETRY_DEFINITIONS_H_ @@ -306,11 +305,9 @@ def OutputOtherObcTlmDefH(file_path, name, body): output = "" output += ''' /** - * @file {_obc_name_capit}TelemetryDefinitions.h + * @file {_obc_name_lower}_telemetry_definitions.h * @brief テレメトリ定義 * @note このコードは自動生成されています! - * @author 鈴本 遼 - * @date 2020/08/23 */ #ifndef {_obc_name_upper}_TELEMETRY_DEFINITIONS_H_ #define {_obc_name_upper}_TELEMETRY_DEFINITIONS_H_ diff --git a/settings.json b/settings.json index 75c6498b2..54ddc0fe5 100644 --- a/settings.json +++ b/settings.json @@ -6,25 +6,26 @@ "other_obc_data" : [ { "name" : "AOBC", - "is_enable" : 0, + "is_enable" : 1, "db_prefix" : "ISSL6U_AOBC", - "db_path" : "../../c2a_issl6u_aobc//src/src_user/Settings/CmdTlm/DataBase/", - "driver_path" : "ADCS/", + "db_path" : "C:/Docs/ISSL_Git/S2E/FlightSW/c2a_issl6u_aobc/src/src_user/Settings/CmdTlm/DataBase/", + "tlm_max_contents_len" : 512, + "driver_path" : "Aocs/", "driver_type" : "AOBC_Driver", - "driver_name" : "aobc", - "code_when_tlm_not_found" : "", + "driver_name" : "aobc_driver", + "code_when_tlm_not_found" : "aobc_driver->info.comm.rx_err_code = AOBC_RX_ERR_CODE_TLM_NOT_FOUND;", "tlm_id_range" : ["0x90", "0xc0"] }, { "name" : "TOBC", "is_enable" : 1, "db_prefix" : "ISSL6U_TOBC", - "db_path" : "../../tobc_tlmcmd/", + "db_path" : "C:/Docs/ISSL_Git/S2E/FlightSW/c2a_issl6u_tobc/src/src_user/Settings/CmdTlm/DataBase/", "tlm_max_contents_len" : 512, - "driver_path" : "THERMAL/", + "driver_path" : "Thermal/", "driver_type" : "TOBC_Driver", - "driver_name" : "tobc", - "code_when_tlm_not_found" : "tobc->info.comm.rx_err_code = TOBC_RX_ERR_CODE_TLM_NOT_FOUND;", + "driver_name" : "tobc_driver", + "code_when_tlm_not_found" : "tobc_driver->info.comm.rx_err_code = TOBC_RX_ERR_CODE_TLM_NOT_FOUND;", "tlm_id_range" : ["0xc0", "0xf0"] } ] From 4d1f5bb45a3033a41a8664b492587c7a59e0c09e Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Thu, 3 Jun 2021 03:08:15 +0900 Subject: [PATCH 057/141] fix --- my_mod/tlm_buffer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index e70f99635..a0f2b2406 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -236,7 +236,7 @@ def OutputTlmBufferC_(file_path, name, body): #include "./{_obc_name_lower}_telemetry_definitions.h" #include "./{_obc_name_lower}_telemetry_buffer.h" -#include "string.h" // for memcpy +#include // for memcpy '''[1:] # 最初の改行を除く From 533d8289badeeb7e980625e1c5955cf2c393962b Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Wed, 16 Jun 2021 01:21:36 +0900 Subject: [PATCH 058/141] add cmd param len data --- my_mod/cmd_def.py | 53 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/my_mod/cmd_def.py b/my_mod/cmd_def.py index d880c8399..02199f2ba 100644 --- a/my_mod/cmd_def.py +++ b/my_mod/cmd_def.py @@ -4,6 +4,7 @@ """ import os +import sys import pprint def GenerateCmdDef(settings, sgc_db): @@ -24,7 +25,7 @@ def GenerateCmdDef(settings, sgc_db): break if comment != "": # Comment continue - # print(name) + cmd_name = name cmd_code = cmd_name.replace("Cmd_", "Cmd_CODE_") # print(cmd_name) @@ -32,6 +33,54 @@ def GenerateCmdDef(settings, sgc_db): body_c += " cmd_table_[" + cmd_code + "].cmd_func = " + cmd_name + ";\n" body_h += " " + cmd_code + " = " + cmd_id + ",\n" + body_c += "\n"; + for i in range(DATA_SART_ROW, len(sgc_db)): + comment = sgc_db[i][0] + name = sgc_db[i][1] + cmd_id = sgc_db[i][3] + if comment == "" and name == "": # CommentもNameも空白なら打ち切り + break + if comment != "": # Comment + continue + + param_num = int(sgc_db[i][4]) + type_list = [sgc_db[i][5], sgc_db[i][7], sgc_db[i][9], sgc_db[i][11], sgc_db[i][13], sgc_db[i][15]] + cmd_name = name + cmd_code = cmd_name.replace("Cmd_", "Cmd_CODE_") + + # パラメタ長の整合性チェック + for j in range(len(type_list)): + err_flag = 0; + if j < param_num and type_list[j] == "": + err_flag = 1 + if j >= param_num and type_list[j] != "": + err_flag = 1 + if (err_flag): + print("Error: Cmd DB Err at " + name, file=sys.stderr) + sys.exit(1) + + # パラメタ長のカウント + conv_tpye_to_size = { + 'int8_t' : 1, + 'int16_t' : 2, + 'int32_t' : 4, + 'uint8_t' : 1, + 'uint16_t' : 2, + 'uint32_t' : 4, + 'float' : 4, + 'double' : 8, + 'raw' : 0 + } + param_len_type = "CA_CMD_PARAM_LEN_TYPE_FIXED" + param_len = 0 + for j in range(param_num): + if type_list[j] == "raw": + param_len_type = "CA_CMD_PARAM_LEN_TYPE_LOWER_LIMIT" + param_len += conv_tpye_to_size[type_list[j]] + + body_c += " cmd_table_[" + cmd_code + "].param_len_type = " + param_len_type + ";\n" + body_c += " cmd_table_[" + cmd_code + "].param_len = " + str(param_len) + ";\n" + OutputCmdDefC_(output_file_path + output_file_name_base + ".c", body_c) OutputCmdDefH_(output_file_path + output_file_name_base + ".h", body_h) @@ -112,7 +161,7 @@ def OutputCmdDefC_(file_path, body): * @brief コマンド定義 * @note このコードは自動生成されています! */ -#include "../../src_core/CmdTlm/CommandAnalyze.h" +#include "../../src_core/CmdTlm/command_analyze.h" #include "command_definitions.h" #include "command_source.h" From 2459b434833271d3095d8a2e8887098f252d13db Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Thu, 24 Jun 2021 17:57:47 +0900 Subject: [PATCH 059/141] fix include --- my_mod/tlm_def.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/my_mod/tlm_def.py b/my_mod/tlm_def.py index e648b4e53..811dbb68a 100644 --- a/my_mod/tlm_def.py +++ b/my_mod/tlm_def.py @@ -251,7 +251,7 @@ def OutputTlmDefC_(file_path, body): * @brief テレメトリ定義 * @note このコードは自動生成されています! */ -#include "../../src_core/CmdTlm/TelemetryFrame.h" +#include "../../src_core/CmdTlm/telemetry_frame.h" #include "telemetry_definitions.h" #include "telemetry_source.h" From 1cc82e63ffe6855c356a9ad850a4569ba890d07d Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Thu, 24 Jun 2021 18:07:17 +0900 Subject: [PATCH 060/141] fix copy func name --- my_mod/tlm_def.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/my_mod/tlm_def.py b/my_mod/tlm_def.py index 811dbb68a..cbbd600d9 100644 --- a/my_mod/tlm_def.py +++ b/my_mod/tlm_def.py @@ -59,28 +59,28 @@ def GenerateTlmDef(settings, tlm_db, other_obc_dbs): code = code.replace("@@", ",") func_code += " " if var_type == "int8_t": - func_code += "copy_i8_" + func_code += "TF_copy_i8" max_pos = int(pos) + 1 elif var_type == "int16_t": - func_code += "copy_i16_" + func_code += "TF_copy_i16" max_pos = int(pos) + 2 elif var_type == "int32_t": - func_code += "copy_i32_" + func_code += "TF_copy_i32" max_pos = int(pos) + 4 elif var_type == "uint8_t": - func_code += "copy_u8_" + func_code += "TF_copy_u8" max_pos = int(pos) + 1 elif var_type == "uint16_t": - func_code += "copy_u16_" + func_code += "TF_copy_u16" max_pos = int(pos) + 2 elif var_type == "uint32_t": - func_code += "copy_u32_" + func_code += "TF_copy_u32" max_pos = int(pos) + 4 elif var_type == "float": - func_code += "copy_float_" + func_code += "TF_copy_float" max_pos = int(pos) + 4 elif var_type == "double": - func_code += "copy_double_" + func_code += "TF_copy_double" max_pos = int(pos) + 8 else: print("Error: Tlm DB Err at " + tlm['tlm_name'].upper(), file=sys.stderr) From 978359f2a1339483fe7771f7fb09fd39d494066b Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Thu, 24 Jun 2021 18:46:56 +0900 Subject: [PATCH 061/141] fix struct name --- my_mod/tlm_buffer.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index a0f2b2406..21c065d80 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -40,7 +40,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_h += " int size;\n" body_h += " uint8_t buffer[{_obc_name_upper}_TELEMETRY_BUFFE_SIZE];\n" body_h += " }} " + tlm_name_lower + ";\n" - body_c += "static DRIVER_SUPER_ERR_CODE {_obc_name_upper}_analyze_tlm_" + tlm_name_lower + "_(DriverSuperStreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ");\n" + body_c += "static DRIVER_SUPER_ERR_CODE {_obc_name_upper}_analyze_tlm_" + tlm_name_lower + "_(DS_StreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ");\n" body_h += "}} {_obc_name_upper}_Buffer;\n" body_h += "\n" @@ -90,7 +90,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_h += "\n" body_h += "void {_obc_name_upper}_buffer_init(void);\n" body_h += "\n" - body_h += "DRIVER_SUPER_ERR_CODE {_obc_name_upper}_buffer_tlm_contents(DriverSuperStreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ");\n" + body_h += "DRIVER_SUPER_ERR_CODE {_obc_name_upper}_buffer_tlm_contents(DS_StreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ");\n" body_c += "\n" @@ -102,7 +102,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += " {_obc_name_lower}_buffer_." + tlm_name_lower + ".size = 0;\n" body_c += "}}\n" body_c += "\n" - body_c += "DRIVER_SUPER_ERR_CODE {_obc_name_upper}_buffer_tlm_contents(DriverSuperStreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ")\n" + body_c += "DRIVER_SUPER_ERR_CODE {_obc_name_upper}_buffer_tlm_contents(DS_StreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ")\n" body_c += "{{\n" body_c += " uint8_t tlm_id = DRIVER_SUPER_C2AFMT_get_tlm_id(p_stream_config);\n" @@ -146,7 +146,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): tlm_name = tlm['tlm_name'] tlm_name_upper = tlm_name.upper() tlm_name_lower = tlm_name.lower() - body_c += "static DRIVER_SUPER_ERR_CODE {_obc_name_upper}_analyze_tlm_" + tlm_name_lower + "_(DriverSuperStreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ")\n" + body_c += "static DRIVER_SUPER_ERR_CODE {_obc_name_upper}_analyze_tlm_" + tlm_name_lower + "_(DS_StreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ")\n" body_c += "{{\n" body_c += " uint32_t tlm_len = DRIVER_SUPER_ISSLFMT_get_tlm_length(p_stream_config);\n" body_c += " const uint8_t* f = DSSC_get_rx_frame(p_stream_config);\n" From 58018b6afeff477e50a182563b574de15b08d76b Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Thu, 24 Jun 2021 19:13:10 +0900 Subject: [PATCH 062/141] fix prefix of DS --- my_mod/tlm_buffer.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index 21c065d80..18d9c2cbe 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -40,7 +40,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_h += " int size;\n" body_h += " uint8_t buffer[{_obc_name_upper}_TELEMETRY_BUFFE_SIZE];\n" body_h += " }} " + tlm_name_lower + ";\n" - body_c += "static DRIVER_SUPER_ERR_CODE {_obc_name_upper}_analyze_tlm_" + tlm_name_lower + "_(DS_StreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ");\n" + body_c += "static DS_ERR_CODE {_obc_name_upper}_analyze_tlm_" + tlm_name_lower + "_(DS_StreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ");\n" body_h += "}} {_obc_name_upper}_Buffer;\n" body_h += "\n" @@ -90,7 +90,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_h += "\n" body_h += "void {_obc_name_upper}_buffer_init(void);\n" body_h += "\n" - body_h += "DRIVER_SUPER_ERR_CODE {_obc_name_upper}_buffer_tlm_contents(DS_StreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ");\n" + body_h += "DS_ERR_CODE {_obc_name_upper}_buffer_tlm_contents(DS_StreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ");\n" body_c += "\n" @@ -102,10 +102,10 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += " {_obc_name_lower}_buffer_." + tlm_name_lower + ".size = 0;\n" body_c += "}}\n" body_c += "\n" - body_c += "DRIVER_SUPER_ERR_CODE {_obc_name_upper}_buffer_tlm_contents(DS_StreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ")\n" + body_c += "DS_ERR_CODE {_obc_name_upper}_buffer_tlm_contents(DS_StreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ")\n" body_c += "{{\n" - body_c += " uint8_t tlm_id = DRIVER_SUPER_C2AFMT_get_tlm_id(p_stream_config);\n" + body_c += " uint8_t tlm_id = DS_C2AFMT_get_tlm_id(p_stream_config);\n" body_c += "\n" body_c += " switch (tlm_id)\n" @@ -118,7 +118,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += " return {_obc_name_upper}_analyze_tlm_" + tlm_name_lower + "_(p_stream_config, " + driver_name + ");\n" body_c += " default:\n" body_c += " " + settings["other_obc_data"][i]["code_when_tlm_not_found"] + "\n" - body_c += " return DRIVER_SUPER_ERR_CODE_ERR;\n" + body_c += " return DS_ERR_CODE_ERR;\n" body_c += " }}\n" body_c += "}}\n" body_c += "\n" @@ -146,12 +146,12 @@ def GenerateTlmBuffer(settings, other_obc_dbs): tlm_name = tlm['tlm_name'] tlm_name_upper = tlm_name.upper() tlm_name_lower = tlm_name.lower() - body_c += "static DRIVER_SUPER_ERR_CODE {_obc_name_upper}_analyze_tlm_" + tlm_name_lower + "_(DS_StreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ")\n" + body_c += "static DS_ERR_CODE {_obc_name_upper}_analyze_tlm_" + tlm_name_lower + "_(DS_StreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ")\n" body_c += "{{\n" - body_c += " uint32_t tlm_len = DRIVER_SUPER_ISSLFMT_get_tlm_length(p_stream_config);\n" + body_c += " uint32_t tlm_len = DS_ISSLFMT_get_tlm_length(p_stream_config);\n" body_c += " const uint8_t* f = DSSC_get_rx_frame(p_stream_config);\n" - body_c += " uint32_t contents_len = tlm_len - DRIVER_SUPER_C2AFMT_TCP_TLM_SECONDARY_HEADER_SIZE - 1; // FIXME: CCSDSは1起算?\n" - body_c += " const uint8_t* contents_pos = f + DRIVER_SUPER_ISSLFMT_COMMON_HEADER_SIZE + DRIVER_SUPER_C2AFMT_TCP_TLM_PRIMARY_HEADER_SIZE + DRIVER_SUPER_C2AFMT_TCP_TLM_SECONDARY_HEADER_SIZE;\n" + body_c += " uint32_t contents_len = tlm_len - DS_C2AFMT_TCP_TLM_SECONDARY_HEADER_SIZE - 1; // FIXME: CCSDSは1起算?\n" + body_c += " const uint8_t* contents_pos = f + DS_ISSLFMT_COMMON_HEADER_SIZE + DS_C2AFMT_TCP_TLM_PRIMARY_HEADER_SIZE + DS_C2AFMT_TCP_TLM_SECONDARY_HEADER_SIZE;\n" for k, v in conv_tpye_to_temp.items(): if k == "float": body_c += " " + k + " " + v + " = 0.0f;\n" @@ -161,7 +161,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += " " + k + " " + v + " = 0;\n" body_c += "\n" body_c += " // GSへのテレメ中継のためのバッファーへのコピー\n" - body_c += " if (contents_len > {_obc_name_upper}_TELEMETRY_BUFFE_SIZE) return DRIVER_SUPER_ERR_CODE_ERR;\n" + body_c += " if (contents_len > {_obc_name_upper}_TELEMETRY_BUFFE_SIZE) return DS_ERR_CODE_ERR;\n" body_c += " memcpy({_obc_name_lower}_buffer_." + tlm_name_lower + ".buffer, contents_pos, (size_t)contents_len);\n" body_c += " {_obc_name_lower}_buffer_." + tlm_name_lower + ".size = (int)contents_len;\n" body_c += "\n" @@ -209,7 +209,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): for k, v in conv_tpye_to_temp.items(): body_c += " (void)" + v + ";\n" body_c += "\n" - body_c += " return DRIVER_SUPER_ERR_CODE_OK;\n" + body_c += " return DS_ERR_CODE_OK;\n" body_c += "}}\n" body_c += "\n" From 515102d8f86ff7ebd1f99143ac53ed308dbcb91d Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 13 Jul 2021 01:41:01 +0900 Subject: [PATCH 063/141] fix for coding rule --- my_mod/tlm_buffer.py | 8 ++++---- my_mod/tlm_def.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index 18d9c2cbe..398a46d91 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -40,7 +40,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_h += " int size;\n" body_h += " uint8_t buffer[{_obc_name_upper}_TELEMETRY_BUFFE_SIZE];\n" body_h += " }} " + tlm_name_lower + ";\n" - body_c += "static DS_ERR_CODE {_obc_name_upper}_analyze_tlm_" + tlm_name_lower + "_(DS_StreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ");\n" + body_c += "static DS_ERR_CODE {_obc_name_upper}_analyze_tlm_" + tlm_name_lower + "_(DS_StreamConfig* p_stream_config, " + driver_type + "* " + driver_name + ");\n" body_h += "}} {_obc_name_upper}_Buffer;\n" body_h += "\n" @@ -90,7 +90,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_h += "\n" body_h += "void {_obc_name_upper}_buffer_init(void);\n" body_h += "\n" - body_h += "DS_ERR_CODE {_obc_name_upper}_buffer_tlm_contents(DS_StreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ");\n" + body_h += "DS_ERR_CODE {_obc_name_upper}_buffer_tlm_contents(DS_StreamConfig* p_stream_config, " + driver_type + "* " + driver_name + ");\n" body_c += "\n" @@ -102,7 +102,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += " {_obc_name_lower}_buffer_." + tlm_name_lower + ".size = 0;\n" body_c += "}}\n" body_c += "\n" - body_c += "DS_ERR_CODE {_obc_name_upper}_buffer_tlm_contents(DS_StreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ")\n" + body_c += "DS_ERR_CODE {_obc_name_upper}_buffer_tlm_contents(DS_StreamConfig* p_stream_config, " + driver_type + "* " + driver_name + ")\n" body_c += "{{\n" body_c += " uint8_t tlm_id = DS_C2AFMT_get_tlm_id(p_stream_config);\n" @@ -146,7 +146,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): tlm_name = tlm['tlm_name'] tlm_name_upper = tlm_name.upper() tlm_name_lower = tlm_name.lower() - body_c += "static DS_ERR_CODE {_obc_name_upper}_analyze_tlm_" + tlm_name_lower + "_(DS_StreamConfig *p_stream_config, " + driver_type + " *" + driver_name + ")\n" + body_c += "static DS_ERR_CODE {_obc_name_upper}_analyze_tlm_" + tlm_name_lower + "_(DS_StreamConfig* p_stream_config, " + driver_type + "* " + driver_name + ")\n" body_c += "{{\n" body_c += " uint32_t tlm_len = DS_ISSLFMT_get_tlm_length(p_stream_config);\n" body_c += " const uint8_t* f = DSSC_get_rx_frame(p_stream_config);\n" diff --git a/my_mod/tlm_def.py b/my_mod/tlm_def.py index cbbd600d9..f4c671ec4 100644 --- a/my_mod/tlm_def.py +++ b/my_mod/tlm_def.py @@ -91,7 +91,7 @@ def GenerateTlmDef(settings, tlm_db, other_obc_dbs): body_c += "static int Tlm_" + tlm['tlm_name'].upper() + "_(unsigned char* contents, int max_len)\n" body_c += "{\n" body_c += "\n" - body_c += " if (" + str(max_pos) + " > max_len) { return TLM_TOO_SHORT_LEN; }\n" + body_c += " if (" + str(max_pos) + " > max_len) return TLM_TOO_SHORT_LEN;\n" body_c += "\n" body_c += "#ifndef FAST_BUILD\n" body_c += func_code From 77df3d7db6ddae3f6b09fae7a5418e9180e2f5a7 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Fri, 6 Aug 2021 19:21:30 +0900 Subject: [PATCH 064/141] escape tlm elem name --- my_mod/tlm_buffer.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index 398a46d91..74aeec597 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -56,7 +56,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): # tlm_struct_tree = collections.OrderedDict() # やっぱこっちで for j in range(DATA_START_ROW, len(tlm['data'])): comment = tlm['data'][j][0] - name = tlm['data'][j][1] + name = EscapeTlmElemName_(tlm['data'][j][1]) var_type = tlm['data'][j][2] if comment == "" and name == "": # CommentもNameも空白なら打ち切り break @@ -169,7 +169,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): last_var_type = "" for j in range(DATA_START_ROW, len(tlm['data'])): comment = tlm['data'][j][0] - name = tlm['data'][j][1] + name = EscapeTlmElemName_(tlm['data'][j][1]) var_type = tlm['data'][j][2] if comment == "" and name == "": # CommentもNameも空白なら打ち切り break @@ -353,3 +353,7 @@ def _(tree, name, indent): output += " " * (indent) + "}} " + name + ";\n" return output return _(tree, name, 2) + + +def EscapeTlmElemName_(name): + return name.replace("/", "_") \ No newline at end of file From c801fe13befcf2b4dabc866c9be625fb41d9d151 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Fri, 6 Aug 2021 19:23:28 +0900 Subject: [PATCH 065/141] fix --- my_mod/tlm_buffer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index 74aeec597..028dc8ef3 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -356,4 +356,4 @@ def _(tree, name, indent): def EscapeTlmElemName_(name): - return name.replace("/", "_") \ No newline at end of file + return name.replace("/", "_") From 9e47467c0bbd6d397902bdf5625c1829e330a8f8 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Thu, 19 Aug 2021 01:54:49 +0900 Subject: [PATCH 066/141] Update README.md --- README.md | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 78cc98422..de5d75f42 100644 --- a/README.md +++ b/README.md @@ -19,11 +19,11 @@ $ python GenerateC2ACode.py `is_main_obc` は,MOBCかそれ以外のOBCかを制御する. `1` とした場合,MOBCを意図したコードが生成され,加えて以下が生成される. -- TobcCommandDefinitions.h -- TobcTelemetryDefinitions.h -- TobcTelemetryBuffer.c -- TobcTelemetryBuffer.h -- TobcTelemetryDataDefinitions.h +- (a|t)obc_command_definitions.h +- (a|t)obc_telemetry_definitions.h +- (a|t)obc_telemetry_buffer.c +- (a|t)obc_telemetry_buffer.h +- (a|t)obc_telemetry_data_definitions.h ``` { @@ -42,14 +42,15 @@ $ python GenerateC2ACode.py { # OBC名 "name" : "AOBC", - # コードを生成するか? AOBCについては現時点でDBが存在しないため 0 - "is_enable" : 0, + # コードを生成するか? + "is_enable" : 1, "db_prefix" : "ISSL6U_AOBC", - "db_path" : "../../c2a_issl6u_aobc//src/src_user/Settings/CmdTlm/DataBase/", - "driver_path" : "ADCS/", + # DBがあるディレクトリへのパス(絶対でも相対でもOK) + "db_path" : "../../c2a_issl6u_aobc/src/src_user/Settings/CmdTlm/DataBase/", + "driver_path" : "Aocs/", "driver_type" : "AOBC_Driver", "driver_name" : "aobc", - "code_when_tlm_not_found" : "", + "code_when_tlm_not_found" : "aobc_driver->info.comm.rx_err_code = AOBC_RX_ERR_CODE_TLM_NOT_FOUND;", "tlm_id_range" : ["0x90", "0xc0"] }, { @@ -58,10 +59,10 @@ $ python GenerateC2ACode.py # コードを生成するか? "is_enable" : 1, "db_prefix" : "ISSL6U_TOBC", - # 現在,TOBCのDBは https://gitlab.com/ut_issl/issl6u/thermal/tobc_tlmcmd にあるので,これを手元にcloneし,そこまでの相対パスを設定する. - "db_path" : "../../tobc_tlmcmd/", + # DBがあるディレクトリへのパス(絶対でも相対でもOK) + "db_path" : ""../../c2a_issl6u_tobc/src/src_user/Settings/CmdTlm/DataBase/",", "tlm_max_contents_len" : 512, - "driver_path" : "THERMAL/", + "driver_path" : "Thermal/", "driver_type" : "TOBC_Driver", "driver_name" : "tobc", "code_when_tlm_not_found" : "tobc->info.comm.rx_err_code = TOBC_RX_ERR_CODE_TLM_NOT_FOUND;", From d0e241436d5918c92a8a43ed0bf95267fb5086d6 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Thu, 19 Aug 2021 01:56:47 +0900 Subject: [PATCH 067/141] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index de5d75f42..d04b1a639 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,11 @@ TlmCmdDBからC2Aのコードを生成するためのスクリプト 以下が自動生成される. -- CommandDefinitions.c -- CommandDefinitions.h -- TelemetryDefinitions.c -- TelemetryDefinitions.h -- BlockCommandDefinitions.h +- command_definitions.c +- command_definitions.h +- telemetry_definitions.c +- telemetry_definitions.h +- block_command_definitions.h ## 実行 ``` From e47301bcb048e432649a1fd8d51a45c4a09994f8 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Thu, 19 Aug 2021 01:59:34 +0900 Subject: [PATCH 068/141] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d04b1a639..24836e854 100644 --- a/README.md +++ b/README.md @@ -60,12 +60,12 @@ $ python GenerateC2ACode.py "is_enable" : 1, "db_prefix" : "ISSL6U_TOBC", # DBがあるディレクトリへのパス(絶対でも相対でもOK) - "db_path" : ""../../c2a_issl6u_tobc/src/src_user/Settings/CmdTlm/DataBase/",", + "db_path" : ""../../c2a_issl6u_tobc/src/src_user/Settings/CmdTlm/DataBase/", "tlm_max_contents_len" : 512, "driver_path" : "Thermal/", "driver_type" : "TOBC_Driver", "driver_name" : "tobc", - "code_when_tlm_not_found" : "tobc->info.comm.rx_err_code = TOBC_RX_ERR_CODE_TLM_NOT_FOUND;", + "code_when_tlm_not_found" : "tobc_driver->info.comm.rx_err_code = TOBC_RX_ERR_CODE_TLM_NOT_FOUND;", "tlm_id_range" : ["0xc0", "0xf0"] } ] From a59746bcdaea90193630a19795d7c06cbca05568 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 14 Sep 2021 22:02:24 +0900 Subject: [PATCH 069/141] fix frame offset --- my_mod/tlm_buffer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index 028dc8ef3..e1644be6b 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -149,9 +149,9 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += "static DS_ERR_CODE {_obc_name_upper}_analyze_tlm_" + tlm_name_lower + "_(DS_StreamConfig* p_stream_config, " + driver_type + "* " + driver_name + ")\n" body_c += "{{\n" body_c += " uint32_t tlm_len = DS_ISSLFMT_get_tlm_length(p_stream_config);\n" - body_c += " const uint8_t* f = DSSC_get_rx_frame(p_stream_config);\n" + body_c += " const uint8_t* f = DSSC_get_rx_frame(p_stream_config) + DS_ISSLFMT_COMMON_HEADER_SIZE;\n" body_c += " uint32_t contents_len = tlm_len - DS_C2AFMT_TCP_TLM_SECONDARY_HEADER_SIZE - 1; // FIXME: CCSDSは1起算?\n" - body_c += " const uint8_t* contents_pos = f + DS_ISSLFMT_COMMON_HEADER_SIZE + DS_C2AFMT_TCP_TLM_PRIMARY_HEADER_SIZE + DS_C2AFMT_TCP_TLM_SECONDARY_HEADER_SIZE;\n" + body_c += " const uint8_t* contents_pos = f + DS_C2AFMT_TCP_TLM_PRIMARY_HEADER_SIZE + DS_C2AFMT_TCP_TLM_SECONDARY_HEADER_SIZE;\n" for k, v in conv_tpye_to_temp.items(): if k == "float": body_c += " " + k + " " + v + " = 0.0f;\n" From 1154af0c81bb12065b6ef8d422c7896ce9500e8c Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Wed, 15 Sep 2021 22:40:05 +0900 Subject: [PATCH 070/141] fix bug --- my_mod/tlm_buffer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index e1644be6b..a7dc2d63a 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -197,7 +197,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): var_name = driver_name + "->tlm_data." + tlm_name_lower + "." + name_path if (is_compression): body_c += " endian_memcpy(&" + conv_tpye_to_temp[var_type] + ", &(f[" + str(oct_pos) + "]), " + str(conv_tpye_to_size[var_type]) + ");\n" - body_c += " " + conv_tpye_to_temp[var_type] + " >>= " + str(bit_pos) + ";\n" + body_c += " " + conv_tpye_to_temp[var_type] + " >>= " + str(7 - bit_pos) + ";\n" body_c += " " + conv_tpye_to_temp[var_type] + " &= " + hex(int("0b" + "1" * bit_len, 2)) + ";\n" body_c += " " + var_name + " = " + conv_tpye_to_temp[var_type] + ";\n" else: From 78494e37048782962d954db7d08e5382e9609327 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Wed, 3 Nov 2021 22:54:07 +0900 Subject: [PATCH 071/141] update --- my_mod/tlm_def.py | 23 ++++++++++++----------- settings.json | 1 + 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/my_mod/tlm_def.py b/my_mod/tlm_def.py index f4c671ec4..6f693480e 100644 --- a/my_mod/tlm_def.py +++ b/my_mod/tlm_def.py @@ -10,7 +10,7 @@ def GenerateTlmDef(settings, tlm_db, other_obc_dbs): output_file_path = settings["c2a_root_dir"] + r"src_user/CmdTlm/" output_file_name_base = "telemetry_definitions" - DATA_START_ROW = 7 + DATA_START_ROW = 8 body_c = "" body_h = "" @@ -42,7 +42,7 @@ def GenerateTlmDef(settings, tlm_db, other_obc_dbs): name = tlm['data'][i][1] var_type = tlm['data'][i][2] code = tlm['data'][i][3] - pos = tlm['data'][i][4] + pos = tlm['data'][i][5] if comment == "" and name == "": # CommentもNameも空白なら打ち切り break if comment != "": @@ -56,36 +56,37 @@ def GenerateTlmDef(settings, tlm_db, other_obc_dbs): if pos == "": continue + pos = int(pos) - settings['header_len'] code = code.replace("@@", ",") func_code += " " if var_type == "int8_t": func_code += "TF_copy_i8" - max_pos = int(pos) + 1 + max_pos = pos + 1 elif var_type == "int16_t": func_code += "TF_copy_i16" - max_pos = int(pos) + 2 + max_pos = pos + 2 elif var_type == "int32_t": func_code += "TF_copy_i32" - max_pos = int(pos) + 4 + max_pos = pos + 4 elif var_type == "uint8_t": func_code += "TF_copy_u8" - max_pos = int(pos) + 1 + max_pos = pos + 1 elif var_type == "uint16_t": func_code += "TF_copy_u16" - max_pos = int(pos) + 2 + max_pos = pos + 2 elif var_type == "uint32_t": func_code += "TF_copy_u32" - max_pos = int(pos) + 4 + max_pos = pos + 4 elif var_type == "float": func_code += "TF_copy_float" - max_pos = int(pos) + 4 + max_pos = pos + 4 elif var_type == "double": func_code += "TF_copy_double" - max_pos = int(pos) + 8 + max_pos = pos + 8 else: print("Error: Tlm DB Err at " + tlm['tlm_name'].upper(), file=sys.stderr) sys.exit(1) - func_code += "(&contents[" + pos + "], " + code + ");\n" + func_code += "(&contents[" + str(pos) + "], " + code + ");\n" body_c += "\n" body_c += "static int Tlm_" + tlm['tlm_name'].upper() + "_(unsigned char* contents, int max_len)\n" diff --git a/settings.json b/settings.json index 54ddc0fe5..a61d09c8f 100644 --- a/settings.json +++ b/settings.json @@ -2,6 +2,7 @@ "c2a_root_dir" : "../../c2a_user_oss/SH7254R_C2A/", "db_prefix" : "ISSL6U_MOBC", "is_generated_sib" : 0, + "header_len" : 13, "is_main_obc" : 1, "other_obc_data" : [ { From 8171ccb1ad32e4a723f52125a25af276bc1498fe Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Thu, 4 Nov 2021 00:01:48 +0900 Subject: [PATCH 072/141] fix for tlm --- my_mod/tlm_buffer.py | 14 ++++++++------ my_mod/tlm_def.py | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index a7dc2d63a..fa6c44c5b 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -9,7 +9,7 @@ import pprint def GenerateTlmBuffer(settings, other_obc_dbs): - DATA_START_ROW = 7 + DATA_START_ROW = 8 for i in range(len(settings["other_obc_data"])): if not settings["other_obc_data"][i]["is_enable"]: @@ -70,7 +70,8 @@ def GenerateTlmBuffer(settings, other_obc_dbs): if last_var_type == "": continue - name_tree = name.lower().split(".")[2:] # OBC名.テレメ名.HOGE.FUGA を想定 + # name_tree = name.lower().split(".")[2:] # OBC名.テレメ名.HOGE.FUGA を想定 + name_tree = name.lower().split(".") name_path = "/".join(name_tree) if (SetStructTree_(tlm_struct_tree, name_path, var_type)): print("Error: Tlm DB Struct Parse Err at " + name, file=sys.stderr) @@ -183,16 +184,17 @@ def GenerateTlmBuffer(settings, other_obc_dbs): if last_var_type == "": continue - oct_pos = int(tlm['data'][j][6]) - bit_pos = int(tlm['data'][j][7]) - bit_len = int(tlm['data'][j][8]) + oct_pos = int(tlm['data'][j][5]) + bit_pos = int(tlm['data'][j][6]) + bit_len = int(tlm['data'][j][7]) is_compression = 0 # テレメ圧縮フラグ for ビットフィールドをつかってる奴ら if tlm['data'][j][2] == "" or tlm['data'][j+1][2] == "": is_compression = 1 if (tlm['data'][j+1][0] == "" and tlm['data'][j+1][1] == "" and tlm['data'][j][2] != ""): # 最終行の除外 is_compression = 0 - name_tree = name.lower().split(".")[2:] # OBC名.テレメ名.HOGE.FUGA を想定 + # name_tree = name.lower().split(".")[2:] # OBC名.テレメ名.HOGE.FUGA を想定 + name_tree = name.lower().split(".") name_path = ".".join(name_tree) var_name = driver_name + "->tlm_data." + tlm_name_lower + "." + name_path if (is_compression): diff --git a/my_mod/tlm_def.py b/my_mod/tlm_def.py index 6f693480e..32d97ccef 100644 --- a/my_mod/tlm_def.py +++ b/my_mod/tlm_def.py @@ -94,7 +94,7 @@ def GenerateTlmDef(settings, tlm_db, other_obc_dbs): body_c += "\n" body_c += " if (" + str(max_pos) + " > max_len) return TLM_TOO_SHORT_LEN;\n" body_c += "\n" - body_c += "#ifndef FAST_BUILD\n" + body_c += "#ifndef BUILD_SETTINGS_FAST_BUILD\n" body_c += func_code body_c += "#endif\n" body_c += "\n" From c29f1a687ccfbb25e2861e083ba48ec45414c117 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Thu, 4 Nov 2021 00:03:29 +0900 Subject: [PATCH 073/141] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 24836e854..f37485670 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,8 @@ $ python GenerateC2ACode.py # MOBCか?(他のOBCのtlm/cmdを取りまとめるか?) 0/1 # (A|T)OBCのコードを生成するときなどは 0 にする # 0 の場合,以後のパラメタは無効 + "header_len" : 13, + # テレメパケットのヘッダ長.これをoffsetしたところから,C2A上のテレメのユーザー定義部 "is_main_obc" : 1, "other_obc_data" : [ { From 2788f8c207a41e1ee7f7b429d2f64cfafa4aeef3 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Fri, 26 Nov 2021 01:38:56 +0900 Subject: [PATCH 074/141] delete gitlab files --- .gitlab/merge_request_templates/template.md | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 .gitlab/merge_request_templates/template.md diff --git a/.gitlab/merge_request_templates/template.md b/.gitlab/merge_request_templates/template.md deleted file mode 100644 index 29f2dc21b..000000000 --- a/.gitlab/merge_request_templates/template.md +++ /dev/null @@ -1,17 +0,0 @@ -## Summary (概要) -ひとことで - -## Issue (イシュー) -Issueがすでに立っているならば,そのリンクを貼る - -## Detail (詳細) -詳しく - -## Impact (影響範囲) -大:推進系の動作がガラッと変わる,とか. - -## Priority (重要度) -大:◯◯までにはマージして欲しい!! - -## Note (補足) -何かあれば From c3c6f0e5fe92983ba10c98134906e279565707f2 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Fri, 26 Nov 2021 01:39:13 +0900 Subject: [PATCH 075/141] add repository template file --- .github/ISSUE_TEMPLATE/action_item.md | 26 +++++++++++++ .github/ISSUE_TEMPLATE/bug_report.md | 37 ++++++++++++++++++ .github/PULL_REQUEST_TEMPLATE.md | 23 +++++++++++ .github/labels.yml | 55 +++++++++++++++++++++++++++ .github/workflows/actionlint.yml | 17 +++++++++ .github/workflows/labeler.yml | 25 ++++++++++++ 6 files changed, 183 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/action_item.md create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/labels.yml create mode 100644 .github/workflows/actionlint.yml create mode 100644 .github/workflows/labeler.yml diff --git a/.github/ISSUE_TEMPLATE/action_item.md b/.github/ISSUE_TEMPLATE/action_item.md new file mode 100644 index 000000000..5c06b8b52 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/action_item.md @@ -0,0 +1,26 @@ +--- +name: Action Item +about: AI 管理用テンプレート +title: '' +labels: '' +assignees: '' + +--- + +## 概要 +ひとことで + +## 詳細 +詳しく + +## close条件 +どうなったらcloseできるか + +## 備考 +なにかあれば + +## 注意 +- 関連する Projects が存在する場合,それの紐付けを行うこと +- 可能ならば `priority` ラベルを付けること +- 可能ならば Assignees を設定すること +- close するときは結論を明記すること diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 000000000..7c03c968a --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,37 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +## 概要 +ひとことで + +## 詳細 +### 詳細症状 +どういうバグか + +### 発生条件 +発生した環境,症状,パラメタなど + +### 追加資料 +あればリンクなどを貼る + +## 必要な作業 +- [ ] あれして +- [ ] これする + +## 影響範囲 +tool類が全部死ぬ... みたいな + +## 補足 +何かれば + +## 注意 +- 関連する Projects が存在する場合,それの紐付けを行うこと +- 可能ならば `priority` ラベルを付けること +- 可能ならば Assignees を設定すること +- close するときは結論を明記すること diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 000000000..82728e779 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,23 @@ +## 概要 +ひとことで + +## Issue +- 関連する issue + +## 詳細 +詳しく + +## 検証結果 +test へのリンクや,検証結果へのリンク + +## 影響範囲 +XX系の動作がガラッと変わる,とか. + +## 補足 +何かあれば + +## 注意 +- 関連する Projects が存在する場合,それの紐付けを行うこと +- Assignees を設定すること +- 可能ならば Reviewers を設定すること +- 可能ならば `priority` ラベルを付けること diff --git a/.github/labels.yml b/.github/labels.yml new file mode 100644 index 000000000..60ca01d51 --- /dev/null +++ b/.github/labels.yml @@ -0,0 +1,55 @@ +- name: "bug" + color: "d73a4a" + description: "Something isn't working" + +- name: "documentation" + color: "0075ca" + description: "Improvements or additions to documentation" + +- name: "duplicate" + color: "cfd8d7" + description: "This issue or pull request already exists" + +- name: "enhancement" + description: "New feature or request" + color: "a2eeef" + +- name: "good first issue" + description: "Good for newcomers" + color: "7057ff" + +- name: "help wanted" + description: "Extra attention is needed" + color: "008672" + +- name: "invalid" + description: "This doesn't seem right" + color: "e4e669" + +- name: "question" + description: "Further information is requested" + color: "d876e3" + +- name: "wontfix" + description: "This will not be worked on" + color: "ffffff" + +- name: "icebox" + description: "icebox or pending" + color: "c5def5" + +- name: "priority::high" + description: "priorityg high" + color: "d93f0b" + +- name: "priority::low" + description: "priority low" + color: "9dcce0" + +- name: "priority::medium" + description: "priority medium" + color: "fbca04" + +- name: "tools" + description: "" + color: "510f70" diff --git a/.github/workflows/actionlint.yml b/.github/workflows/actionlint.yml new file mode 100644 index 000000000..274d11ec1 --- /dev/null +++ b/.github/workflows/actionlint.yml @@ -0,0 +1,17 @@ +name: reviewdog / actionlint + +on: + pull_request: + paths: + - '.github/workflows/**' + +jobs: + actionlint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: reviewdog/action-actionlint@v1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + reporter: github-pr-review + fail_on_error: true diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml new file mode 100644 index 000000000..e2f01a65f --- /dev/null +++ b/.github/workflows/labeler.yml @@ -0,0 +1,25 @@ +name: labeler + +on: + push: + branches: + - main + pull_request: + paths: + - .github/workflows/labeler.yml + - .github/labels.yml + +jobs: + labeler: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Run Labeler + uses: crazy-max/ghaction-github-labeler@v3 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + yaml-file: .github/labels.yml + skip-delete: false + dry-run: ${{ github.ref != 'refs/heads/main' }} From e44f5cda47ccd57708de76786de375cc829c5384 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Fri, 26 Nov 2021 01:39:59 +0900 Subject: [PATCH 076/141] Create LICENSE --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..89f748ff8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Intelligent Space Systems Laboratory, The University of Tokyo + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From bb067846c51d467ff9192ee76d4bc6b0a5e5475f Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Fri, 26 Nov 2021 01:48:45 +0900 Subject: [PATCH 077/141] update readme --- README.md | 40 ++++++++++++++++++++-------------------- settings.json | 12 ++++++------ 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index f37485670..9280e5ae4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ -# TlmCmdCodeGenerator -## これはなに? -TlmCmdDBからC2Aのコードを生成するためのスクリプト +# c2a-tlm-cmd-code-generator +[TlmCmd DB](https://github.com/ut-issl/tlm-cmd-db)からC2Aのコードを生成するためのスクリプト 以下が自動生成される. - command_definitions.c @@ -17,28 +16,28 @@ $ python GenerateC2ACode.py ## 設定 `settings.json` にて記述する. -`is_main_obc` は,MOBCかそれ以外のOBCかを制御する. +`is_main_obc` は,MOBC(地上局と通信するOBC.2nd OBCのtlm/cmdを取りまとめる)かそれ以外のOBC(2nd OBC.MOBCと通信するOBC)かを制御する. `1` とした場合,MOBCを意図したコードが生成され,加えて以下が生成される. -- (a|t)obc_command_definitions.h -- (a|t)obc_telemetry_definitions.h -- (a|t)obc_telemetry_buffer.c -- (a|t)obc_telemetry_buffer.h -- (a|t)obc_telemetry_data_definitions.h +- 2nd_obc_command_definitions.h +- 2nd_obc_telemetry_definitions.h +- 2nd_obc_telemetry_buffer.c +- 2nd_obc_telemetry_buffer.h +- 2nd_obc_telemetry_data_definitions.h ``` { # C2A ROOTへ相対パス. # C2A ROOTとは, `src_core`, `src_user` のあるディレクトリ - "c2a_root_dir" : "../../c2a_user_oss/SH7254R_C2A/", + "c2a_root_dir" : "../../c2a/src/", # TlmCmdDBのファイル名の接頭辞 - "db_prefix" : "ISSL6U_MOBC", + "db_prefix" : "SAMPLE_MOBC", # GSTOS用sibファイルを生成するか? 0/1 "is_generated_sib" : 0, + # テレメパケットのヘッダ長.これをoffsetしたところから,C2A上のテレメのユーザー定義部 + "header_len" : 13, # MOBCか?(他のOBCのtlm/cmdを取りまとめるか?) 0/1 - # (A|T)OBCのコードを生成するときなどは 0 にする + # 2nd OBCのコードを生成するときなどは 0 にする # 0 の場合,以後のパラメタは無効 - "header_len" : 13, - # テレメパケットのヘッダ長.これをoffsetしたところから,C2A上のテレメのユーザー定義部 "is_main_obc" : 1, "other_obc_data" : [ { @@ -46,9 +45,9 @@ $ python GenerateC2ACode.py "name" : "AOBC", # コードを生成するか? "is_enable" : 1, - "db_prefix" : "ISSL6U_AOBC", + "db_prefix" : "SAMPLE_AOBC", # DBがあるディレクトリへのパス(絶対でも相対でもOK) - "db_path" : "../../c2a_issl6u_aobc/src/src_user/Settings/CmdTlm/DataBase/", + "db_path" : "../../c2a_sample_aobc/src/src_user/Settings/CmdTlm/DataBase/", "driver_path" : "Aocs/", "driver_type" : "AOBC_Driver", "driver_name" : "aobc", @@ -60,9 +59,9 @@ $ python GenerateC2ACode.py "name" : "TOBC", # コードを生成するか? "is_enable" : 1, - "db_prefix" : "ISSL6U_TOBC", + "db_prefix" : "SAMPLE_TOBC", # DBがあるディレクトリへのパス(絶対でも相対でもOK) - "db_path" : ""../../c2a_issl6u_tobc/src/src_user/Settings/CmdTlm/DataBase/", + "db_path" : ""../../c2a_sample_tobc/src/src_user/Settings/CmdTlm/DataBase/", "tlm_max_contents_len" : 512, "driver_path" : "Thermal/", "driver_type" : "TOBC_Driver", @@ -74,7 +73,6 @@ $ python GenerateC2ACode.py } ``` - ## 開発方針 そこまで込み入った開発はしないので, @@ -83,7 +81,6 @@ $ python GenerateC2ACode.py ブランチのみ作成し,master pushは禁止する. - ## 要求 - python 3.7 以上 - 必要ライブラリは `./requirements.txt` に記載. @@ -92,3 +89,6 @@ $ python GenerateC2ACode.py ``` $ pip install -r requirements.txt ``` + +## その他 +- MOBCと2nd OBCのC2A間通信の例は (TBA). diff --git a/settings.json b/settings.json index a61d09c8f..8fe1371e7 100644 --- a/settings.json +++ b/settings.json @@ -1,6 +1,6 @@ { - "c2a_root_dir" : "../../c2a_user_oss/SH7254R_C2A/", - "db_prefix" : "ISSL6U_MOBC", + "c2a_root_dir" : "../../c2a/src/", + "db_prefix" : "SAMPLE_MOBC", "is_generated_sib" : 0, "header_len" : 13, "is_main_obc" : 1, @@ -8,8 +8,8 @@ { "name" : "AOBC", "is_enable" : 1, - "db_prefix" : "ISSL6U_AOBC", - "db_path" : "C:/Docs/ISSL_Git/S2E/FlightSW/c2a_issl6u_aobc/src/src_user/Settings/CmdTlm/DataBase/", + "db_prefix" : "SAMPLE_AOBC", + "db_path" : "C:/Docs/ISSL_Git/S2E/FlightSW/c2a_sample_aobc/src/src_user/Settings/CmdTlm/DataBase/", "tlm_max_contents_len" : 512, "driver_path" : "Aocs/", "driver_type" : "AOBC_Driver", @@ -20,8 +20,8 @@ { "name" : "TOBC", "is_enable" : 1, - "db_prefix" : "ISSL6U_TOBC", - "db_path" : "C:/Docs/ISSL_Git/S2E/FlightSW/c2a_issl6u_tobc/src/src_user/Settings/CmdTlm/DataBase/", + "db_prefix" : "SAMPLE_TOBC", + "db_path" : "C:/Docs/ISSL_Git/S2E/FlightSW/c2a_sample_tobc/src/src_user/Settings/CmdTlm/DataBase/", "tlm_max_contents_len" : 512, "driver_path" : "Thermal/", "driver_type" : "TOBC_Driver", From 7673755bdcff821bc82c4799327c9cfe7e0833ad Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Fri, 3 Dec 2021 03:59:49 +0900 Subject: [PATCH 078/141] update for c2a core update --- my_mod/cmd_def.py | 12 ++++++------ my_mod/tlm_def.py | 13 ++++++------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/my_mod/cmd_def.py b/my_mod/cmd_def.py index 02199f2ba..07473e17f 100644 --- a/my_mod/cmd_def.py +++ b/my_mod/cmd_def.py @@ -15,7 +15,7 @@ def GenerateCmdDef(settings, sgc_db): body_c = "" body_h = "" - # " cmd_table_[Cmd_CODE_NOP].cmd_func = Cmd_NOP;" + # " cmd_table[Cmd_CODE_NOP].cmd_func = Cmd_NOP;" # " Cmd_CODE_NOP = 0x0000," for i in range(DATA_SART_ROW, len(sgc_db)): comment = sgc_db[i][0] @@ -30,7 +30,7 @@ def GenerateCmdDef(settings, sgc_db): cmd_code = cmd_name.replace("Cmd_", "Cmd_CODE_") # print(cmd_name) # print(cmd_code) - body_c += " cmd_table_[" + cmd_code + "].cmd_func = " + cmd_name + ";\n" + body_c += " cmd_table[" + cmd_code + "].cmd_func = " + cmd_name + ";\n" body_h += " " + cmd_code + " = " + cmd_id + ",\n" body_c += "\n"; @@ -78,8 +78,8 @@ def GenerateCmdDef(settings, sgc_db): param_len_type = "CA_CMD_PARAM_LEN_TYPE_LOWER_LIMIT" param_len += conv_tpye_to_size[type_list[j]] - body_c += " cmd_table_[" + cmd_code + "].param_len_type = " + param_len_type + ";\n" - body_c += " cmd_table_[" + cmd_code + "].param_len = " + str(param_len) + ";\n" + body_c += " cmd_table[" + cmd_code + "].param_len_type = " + param_len_type + ";\n" + body_c += " cmd_table[" + cmd_code + "].param_len = " + str(param_len) + ";\n" OutputCmdDefC_(output_file_path + output_file_name_base + ".c", body_c) OutputCmdDefH_(output_file_path + output_file_name_base + ".h", body_h) @@ -92,7 +92,7 @@ def GenerateBctDef(settings, bct_db): DATA_SART_ROW = 2 body_h = "" - # " cmd_table_[Cmd_CODE_NOP].cmd_func = Cmd_NOP;" + # " cmd_table[Cmd_CODE_NOP].cmd_func = Cmd_NOP;" # " Cmd_CODE_NOP = 0x0000," for i in range(DATA_SART_ROW, len(bct_db)): comment = bct_db[i][0] @@ -165,7 +165,7 @@ def OutputCmdDefC_(file_path, body): #include "command_definitions.h" #include "command_source.h" -void CA_load_cmd_table(CmdInfo cmd_table_[CMD_MAX_CMDS]) +void CA_load_cmd_table(CA_CmdInfo cmd_table[CA_MAX_CMDS]) { '''[1:] # 最初の改行を除く diff --git a/my_mod/tlm_def.py b/my_mod/tlm_def.py index 32d97ccef..af93bc419 100644 --- a/my_mod/tlm_def.py +++ b/my_mod/tlm_def.py @@ -25,11 +25,11 @@ def GenerateTlmDef(settings, tlm_db, other_obc_dbs): body_c += GetTlmDefCOfOtherObcFunDef_(settings, tlm_db, other_obc_dbs) body_c += "\n" - body_c += "void TF_load_tlm_table(TlmInfo tlm_table_[TLM_MAX_TLMS])\n" + body_c += "void TF_load_tlm_table(TF_TlmInfo tlm_table[TF_MAX_TLMS])\n" body_c += "{\n" for tlm in tlm_db: - # " tlm_table_[OBC_ID].tlm_func = OBC_;" - body_c += " tlm_table_[Tlm_CODE_" + tlm['tlm_name'].upper() + "].tlm_func = Tlm_" + tlm['tlm_name'].upper() + "_;\n" + # " tlm_table[OBC_ID].tlm_func = OBC_;" + body_c += " tlm_table[Tlm_CODE_" + tlm['tlm_name'].upper() + "].tlm_func = Tlm_" + tlm['tlm_name'].upper() + "_;\n" if settings["is_main_obc"]: body_c += GetTlmDefCOfOtherObcFunLoad_(settings, tlm_db, other_obc_dbs) body_c += "}\n" @@ -91,8 +91,7 @@ def GenerateTlmDef(settings, tlm_db, other_obc_dbs): body_c += "\n" body_c += "static int Tlm_" + tlm['tlm_name'].upper() + "_(unsigned char* contents, int max_len)\n" body_c += "{\n" - body_c += "\n" - body_c += " if (" + str(max_pos) + " > max_len) return TLM_TOO_SHORT_LEN;\n" + body_c += " if (" + str(max_pos) + " > max_len) return TF_TOO_SHORT_LEN;\n" body_c += "\n" body_c += "#ifndef BUILD_SETTINGS_FAST_BUILD\n" body_c += func_code @@ -144,7 +143,7 @@ def GetTlmDefCOfOtherObcFunLoad_(settings, tlm_db, other_obc_dbs): temp_c += "\n" temp_c += " // {_obc_name_upper} TLM\n" for tlm in oter_obc_tlm_db: - temp_c += " tlm_table_[Tlm_CODE_" + tlm['tlm_name'].upper() + "].tlm_func = Tlm_" + tlm['tlm_name'].upper() + "_;\n" + temp_c += " tlm_table[Tlm_CODE_" + tlm['tlm_name'].upper() + "].tlm_func = Tlm_" + tlm['tlm_name'].upper() + "_;\n" body_c += temp_c.format(_obc_name_upper=obc_name.upper(), _obc_name_lower=obc_name.lower(), _obc_name_capit=obc_name.capitalize()) return body_c @@ -170,7 +169,7 @@ def GetTlmDefCOfOtherObcFunBody_(settings, tlm_db, other_obc_dbs): temp_c += "{{\n" temp_c += " int buffer_size = {_obc_name_lower}_buffer->" + tlm_name_lower + ".size;\n" temp_c += "\n" - temp_c += " if (buffer_size > max_len) {{ return TLM_TOO_SHORT_LEN; }}\n" + temp_c += " if (buffer_size > max_len) {{ return TF_TOO_SHORT_LEN; }}\n" temp_c += "\n" temp_c += " memcpy(contents, {_obc_name_lower}_buffer->" + tlm_name_lower + ".buffer, (size_t)buffer_size);\n" temp_c += "\n" From efeed70522e46d609be64d60812fb9c20f7c41b1 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sun, 5 Dec 2021 20:51:11 +0900 Subject: [PATCH 079/141] update cmd def for update ca --- my_mod/cmd_def.py | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/my_mod/cmd_def.py b/my_mod/cmd_def.py index 07473e17f..a3af58c50 100644 --- a/my_mod/cmd_def.py +++ b/my_mod/cmd_def.py @@ -61,25 +61,20 @@ def GenerateCmdDef(settings, sgc_db): # パラメタ長のカウント conv_tpye_to_size = { - 'int8_t' : 1, - 'int16_t' : 2, - 'int32_t' : 4, - 'uint8_t' : 1, - 'uint16_t' : 2, - 'uint32_t' : 4, - 'float' : 4, - 'double' : 8, - 'raw' : 0 + 'int8_t' : "CA_PARAM_SIZE_TYPE_1BYTE", + 'int16_t' : "CA_PARAM_SIZE_TYPE_2BYTE", + 'int32_t' : "CA_PARAM_SIZE_TYPE_4BYTE", + 'uint8_t' : "CA_PARAM_SIZE_TYPE_1BYTE", + 'uint16_t' : "CA_PARAM_SIZE_TYPE_2BYTE", + 'uint32_t' : "CA_PARAM_SIZE_TYPE_4BYTE", + 'float' : "CA_PARAM_SIZE_TYPE_4BYTE", + 'double' : "CA_PARAM_SIZE_TYPE_8BYTE", + 'raw' : "CA_PARAM_SIZE_TYPE_RAW" } - param_len_type = "CA_CMD_PARAM_LEN_TYPE_FIXED" - param_len = 0 for j in range(param_num): - if type_list[j] == "raw": - param_len_type = "CA_CMD_PARAM_LEN_TYPE_LOWER_LIMIT" - param_len += conv_tpye_to_size[type_list[j]] - - body_c += " cmd_table[" + cmd_code + "].param_len_type = " + param_len_type + ";\n" - body_c += " cmd_table[" + cmd_code + "].param_len = " + str(param_len) + ";\n" + index = j // 2 + subindex = "second" if j % 2 else "first" + body_c += " cmd_table[" + cmd_code + "].param_size_infos[" + str(index) + "].bit." + subindex + " = " + conv_tpye_to_size[type_list[j]] + ";\n" OutputCmdDefC_(output_file_path + output_file_name_base + ".c", body_c) OutputCmdDefH_(output_file_path + output_file_name_base + ".h", body_h) From 3a65dda417b120be9210b45a7b66f19af025cad6 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Fri, 10 Dec 2021 17:38:57 +0900 Subject: [PATCH 080/141] delete anonymous union --- my_mod/cmd_def.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/my_mod/cmd_def.py b/my_mod/cmd_def.py index a3af58c50..90a6e3f3c 100644 --- a/my_mod/cmd_def.py +++ b/my_mod/cmd_def.py @@ -74,7 +74,7 @@ def GenerateCmdDef(settings, sgc_db): for j in range(param_num): index = j // 2 subindex = "second" if j % 2 else "first" - body_c += " cmd_table[" + cmd_code + "].param_size_infos[" + str(index) + "].bit." + subindex + " = " + conv_tpye_to_size[type_list[j]] + ";\n" + body_c += " cmd_table[" + cmd_code + "].param_size_infos[" + str(index) + "].packed_info.bit." + subindex + " = " + conv_tpye_to_size[type_list[j]] + ";\n" OutputCmdDefC_(output_file_path + output_file_name_base + ".c", body_c) OutputCmdDefH_(output_file_path + output_file_name_base + ".h", body_h) From 57817fc8fcae83c77510347ed990733f1be69506 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 14 Dec 2021 11:32:02 +0900 Subject: [PATCH 081/141] support for c89 --- my_mod/cmd_def.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/my_mod/cmd_def.py b/my_mod/cmd_def.py index 90a6e3f3c..88d93c04c 100644 --- a/my_mod/cmd_def.py +++ b/my_mod/cmd_def.py @@ -225,6 +225,8 @@ def OutputBctDef_(file_path, body): output += body output += ''' + + BC_ID_MAX // BCT 自体のサイズは BCT_MAX_BLOCKS で規定 } BC_DEFAULT_ID; void BC_load_defaults(void); From e6676b75671bd3cea825af81fa8d62a4aa2f9781 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 28 Dec 2021 18:03:12 +0900 Subject: [PATCH 082/141] add local var for tlm def --- my_mod/load_db.py | 10 ++++++++-- my_mod/tlm_def.py | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/my_mod/load_db.py b/my_mod/load_db.py index 162ec85e2..e047d8e35 100644 --- a/my_mod/load_db.py +++ b/my_mod/load_db.py @@ -69,8 +69,14 @@ def LoadTlmCSV_(tlm_db_path, db_prefix): sheet = [row for row in reader] # pprint.pprint(sheet) # print(sheet) - tlm_id = sheet[1][2] # テレメIDを取得.マジックナンバーで指定してしまってる. - tlm_db.append({'tlm_id': tlm_id, 'tlm_name': tlm_name, 'data': sheet}) + tlm_id = sheet[1][2] # テレメIDを取得.マジックナンバーで指定してしまってる. + raw_local_vars = sheet[1][3].replace("%%", "").split("##") # ローカル変数を取得.マジックナンバーで指定してしまってる. + local_vars = [] + for raw_local_var in raw_local_vars: + local_var = raw_local_var.strip() + if len(local_var) > 0: + local_vars.append(local_var) + tlm_db.append({'tlm_id': tlm_id, 'tlm_name': tlm_name, 'local_vars': local_vars, 'data': sheet}) # tlm_db.append({'tlm_id': tlm_id, 'tlm_name': tlm_name, 'data': 1}) tlm_db.sort(key=lambda x: x['tlm_id']) diff --git a/my_mod/tlm_def.py b/my_mod/tlm_def.py index af93bc419..f4b23a8d3 100644 --- a/my_mod/tlm_def.py +++ b/my_mod/tlm_def.py @@ -91,6 +91,10 @@ def GenerateTlmDef(settings, tlm_db, other_obc_dbs): body_c += "\n" body_c += "static int Tlm_" + tlm['tlm_name'].upper() + "_(unsigned char* contents, int max_len)\n" body_c += "{\n" + for local_var in tlm['local_vars']: + body_c += " " + local_var + "\n" + if len(tlm['local_vars']) > 0: + body_c += "\n" body_c += " if (" + str(max_pos) + " > max_len) return TF_TOO_SHORT_LEN;\n" body_c += "\n" body_c += "#ifndef BUILD_SETTINGS_FAST_BUILD\n" From 5d6c46d4983ff6635849438ca3f6202864b46029 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Wed, 29 Dec 2021 00:16:56 +0900 Subject: [PATCH 083/141] add fixme --- my_mod/load_db.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/my_mod/load_db.py b/my_mod/load_db.py index e047d8e35..ab52aad7a 100644 --- a/my_mod/load_db.py +++ b/my_mod/load_db.py @@ -69,8 +69,8 @@ def LoadTlmCSV_(tlm_db_path, db_prefix): sheet = [row for row in reader] # pprint.pprint(sheet) # print(sheet) - tlm_id = sheet[1][2] # テレメIDを取得.マジックナンバーで指定してしまってる. - raw_local_vars = sheet[1][3].replace("%%", "").split("##") # ローカル変数を取得.マジックナンバーで指定してしまってる. + tlm_id = sheet[1][2] # FIXME: テレメIDを取得.マジックナンバーで指定してしまってる. + raw_local_vars = sheet[1][3].replace("%%", "").split("##") # FIXME: ローカル変数を取得.マジックナンバーで指定してしまってる. local_vars = [] for raw_local_var in raw_local_vars: local_var = raw_local_var.strip() From cf2535424adffd46c7b28285addfe3502964b1b5 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Mon, 3 Jan 2022 21:36:40 +0900 Subject: [PATCH 084/141] fix dogxgen --- my_mod/cmd_def.py | 8 ++++---- my_mod/tlm_buffer.py | 6 +++--- my_mod/tlm_def.py | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/my_mod/cmd_def.py b/my_mod/cmd_def.py index 88d93c04c..7e42cf8f5 100644 --- a/my_mod/cmd_def.py +++ b/my_mod/cmd_def.py @@ -152,7 +152,7 @@ def OutputCmdDefC_(file_path, body): output += ''' #pragma section REPRO /** - * @file command_definitions.c + * @file * @brief コマンド定義 * @note このコードは自動生成されています! */ @@ -181,7 +181,7 @@ def OutputCmdDefH_(file_path, body): output = "" output += ''' /** - * @file command_definitions.h + * @file * @brief コマンド定義 * @note このコードは自動生成されています! */ @@ -210,7 +210,7 @@ def OutputBctDef_(file_path, body): output = "" output += ''' /** - * @file block_command_definitions.h + * @file * @brief ブロックコマンド定義 * @note このコードは自動生成されています! */ @@ -246,7 +246,7 @@ def OutputOtherObcCmdDefH_(file_path, name, body): output = "" output += ''' /** - * @file {_obc_name_lower}_command_definitions.h + * @file * @brief コマンド定義 * @note このコードは自動生成されています! */ diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index fa6c44c5b..b1cd2a213 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -231,7 +231,7 @@ def OutputTlmBufferC_(file_path, name, body): output += ''' #pragma section REPRO /** - * @file {_obc_name_lower}_telemetry_buffer.c + * @file * @brief テレメトリバッファー(テレメ中継) * @note このコードは自動生成されています! */ @@ -260,7 +260,7 @@ def OutputTlmBufferH_(file_path, name, body): output = "" output += ''' /** - * @file {_obc_name_lower}_telemetry_buffer.h + * @file * @brief テレメトリバッファー(テレメ中継) * @note このコードは自動生成されています! */ @@ -290,7 +290,7 @@ def OutputTlmDataDefH_(file_path, name, body): output = "" output += ''' /** - * @file {_obc_name_lower}_telemetry_data_definitions.h + * @file * @brief バッファリングされているテレメをパースしてMOBC内でかんたんに利用できるようにするためのテレメデータ構造体定義 * @note このコードは自動生成されています! */ diff --git a/my_mod/tlm_def.py b/my_mod/tlm_def.py index f4b23a8d3..0738edb08 100644 --- a/my_mod/tlm_def.py +++ b/my_mod/tlm_def.py @@ -251,7 +251,7 @@ def OutputTlmDefC_(file_path, body): output += ''' #pragma section REPRO /** - * @file telemetry_definitions.c + * @file * @brief テレメトリ定義 * @note このコードは自動生成されています! */ @@ -276,7 +276,7 @@ def OutputTlmDefH_(file_path, body): output = "" output += ''' /** - * @file telemetry_definitions.h + * @file * @brief テレメトリ定義 * @note このコードは自動生成されています! */ @@ -309,7 +309,7 @@ def OutputOtherObcTlmDefH(file_path, name, body): output = "" output += ''' /** - * @file {_obc_name_lower}_telemetry_definitions.h + * @file * @brief テレメトリ定義 * @note このコードは自動生成されています! */ From d572374b23f0ee80e13a7914b7a65695faee99f5 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 4 Jan 2022 06:24:10 +0900 Subject: [PATCH 085/141] fix for cmd db update --- my_mod/cmd_def.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/my_mod/cmd_def.py b/my_mod/cmd_def.py index 7e42cf8f5..48a27a949 100644 --- a/my_mod/cmd_def.py +++ b/my_mod/cmd_def.py @@ -95,6 +95,10 @@ def GenerateBctDef(settings, bct_db): bc_id = bct_db[i][3] description = bct_db[i][10] + # エスケープ解除 + name = name.replace("@@", ",") + description = description.replace("@@", ",") + if comment == "" and name == "": # CommentもNameも空白なら打ち切り break From 402aadb1f76c96b338ee4dcc8a0e81a04d0f227d Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Thu, 13 Jan 2022 19:38:30 +0900 Subject: [PATCH 086/141] rename to TlmCmd from CmdTlm --- README.md | 4 ++-- my_mod/cmd_def.py | 6 +++--- my_mod/load_db.py | 4 ++-- my_mod/tlm_def.py | 4 ++-- settings.json | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 9280e5ae4..1b379ed46 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ $ python GenerateC2ACode.py "is_enable" : 1, "db_prefix" : "SAMPLE_AOBC", # DBがあるディレクトリへのパス(絶対でも相対でもOK) - "db_path" : "../../c2a_sample_aobc/src/src_user/Settings/CmdTlm/DataBase/", + "db_path" : "../../c2a_sample_aobc/src/src_user/Settings/TlmCmd/DataBase/", "driver_path" : "Aocs/", "driver_type" : "AOBC_Driver", "driver_name" : "aobc", @@ -61,7 +61,7 @@ $ python GenerateC2ACode.py "is_enable" : 1, "db_prefix" : "SAMPLE_TOBC", # DBがあるディレクトリへのパス(絶対でも相対でもOK) - "db_path" : ""../../c2a_sample_tobc/src/src_user/Settings/CmdTlm/DataBase/", + "db_path" : ""../../c2a_sample_tobc/src/src_user/Settings/TlmCmd/DataBase/", "tlm_max_contents_len" : 512, "driver_path" : "Thermal/", "driver_type" : "TOBC_Driver", diff --git a/my_mod/cmd_def.py b/my_mod/cmd_def.py index 48a27a949..efb0b6060 100644 --- a/my_mod/cmd_def.py +++ b/my_mod/cmd_def.py @@ -8,7 +8,7 @@ import pprint def GenerateCmdDef(settings, sgc_db): - output_file_path = settings["c2a_root_dir"] + r"src_user/CmdTlm/" + output_file_path = settings["c2a_root_dir"] + r"src_user/TlmCmd/" output_file_name_base = "command_definitions" DATA_SART_ROW = 3 @@ -81,7 +81,7 @@ def GenerateCmdDef(settings, sgc_db): def GenerateBctDef(settings, bct_db): - output_file_path = settings["c2a_root_dir"] + r"src_user/CmdTlm/" + output_file_path = settings["c2a_root_dir"] + r"src_user/TlmCmd/" output_file_name = "block_command_definitions.h" DATA_SART_ROW = 2 @@ -160,7 +160,7 @@ def OutputCmdDefC_(file_path, body): * @brief コマンド定義 * @note このコードは自動生成されています! */ -#include "../../src_core/CmdTlm/command_analyze.h" +#include "../../src_core/TlmCmd/command_analyze.h" #include "command_definitions.h" #include "command_source.h" diff --git a/my_mod/load_db.py b/my_mod/load_db.py index ab52aad7a..fbca274ba 100644 --- a/my_mod/load_db.py +++ b/my_mod/load_db.py @@ -9,7 +9,7 @@ import pprint def LoadCmdDb(settings): - cmd_db_path = settings["c2a_root_dir"] + r"src_user/Settings/CmdTlm/DataBase/CMD_DB/" + 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"]) @@ -39,7 +39,7 @@ def LoadCmdCSV_(cmd_db_path, db_prefix): def LoadTlmDb(settings): - tlm_db_path = settings["c2a_root_dir"] + r"src_user/Settings/CmdTlm/DataBase/TLM_DB/calced_data/" + tlm_db_path = settings["c2a_root_dir"] + r"src_user/Settings/TlmCmd/DataBase/TLM_DB/calced_data/" tlm_db = LoadTlmCSV_(tlm_db_path, settings["db_prefix"]) diff --git a/my_mod/tlm_def.py b/my_mod/tlm_def.py index 0738edb08..0773e5c61 100644 --- a/my_mod/tlm_def.py +++ b/my_mod/tlm_def.py @@ -7,7 +7,7 @@ import sys def GenerateTlmDef(settings, tlm_db, other_obc_dbs): - output_file_path = settings["c2a_root_dir"] + r"src_user/CmdTlm/" + output_file_path = settings["c2a_root_dir"] + r"src_user/TlmCmd/" output_file_name_base = "telemetry_definitions" DATA_START_ROW = 8 @@ -255,7 +255,7 @@ def OutputTlmDefC_(file_path, body): * @brief テレメトリ定義 * @note このコードは自動生成されています! */ -#include "../../src_core/CmdTlm/telemetry_frame.h" +#include "../../src_core/TlmCmd/telemetry_frame.h" #include "telemetry_definitions.h" #include "telemetry_source.h" diff --git a/settings.json b/settings.json index 8fe1371e7..9e13b8591 100644 --- a/settings.json +++ b/settings.json @@ -9,7 +9,7 @@ "name" : "AOBC", "is_enable" : 1, "db_prefix" : "SAMPLE_AOBC", - "db_path" : "C:/Docs/ISSL_Git/S2E/FlightSW/c2a_sample_aobc/src/src_user/Settings/CmdTlm/DataBase/", + "db_path" : "C:/Docs/ISSL_Git/S2E/FlightSW/c2a_sample_aobc/src/src_user/Settings/TlmCmd/DataBase/", "tlm_max_contents_len" : 512, "driver_path" : "Aocs/", "driver_type" : "AOBC_Driver", @@ -21,7 +21,7 @@ "name" : "TOBC", "is_enable" : 1, "db_prefix" : "SAMPLE_TOBC", - "db_path" : "C:/Docs/ISSL_Git/S2E/FlightSW/c2a_sample_tobc/src/src_user/Settings/CmdTlm/DataBase/", + "db_path" : "C:/Docs/ISSL_Git/S2E/FlightSW/c2a_sample_tobc/src/src_user/Settings/TlmCmd/DataBase/", "tlm_max_contents_len" : 512, "driver_path" : "Thermal/", "driver_type" : "TOBC_Driver", From da47f6ae016bfb6e5bdb24c9388f3b9230ab1eaf Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Thu, 13 Jan 2022 19:40:20 +0900 Subject: [PATCH 087/141] fix sample settings --- settings.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/settings.json b/settings.json index 9e13b8591..7540d60f2 100644 --- a/settings.json +++ b/settings.json @@ -9,7 +9,7 @@ "name" : "AOBC", "is_enable" : 1, "db_prefix" : "SAMPLE_AOBC", - "db_path" : "C:/Docs/ISSL_Git/S2E/FlightSW/c2a_sample_aobc/src/src_user/Settings/TlmCmd/DataBase/", + "db_path" : "C:/c2a_sample_aobc/src/src_user/Settings/TlmCmd/DataBase/", "tlm_max_contents_len" : 512, "driver_path" : "Aocs/", "driver_type" : "AOBC_Driver", @@ -21,7 +21,7 @@ "name" : "TOBC", "is_enable" : 1, "db_prefix" : "SAMPLE_TOBC", - "db_path" : "C:/Docs/ISSL_Git/S2E/FlightSW/c2a_sample_tobc/src/src_user/Settings/TlmCmd/DataBase/", + "db_path" : "C:/c2a_sample_tobc/src/src_user/Settings/TlmCmd/DataBase/", "tlm_max_contents_len" : 512, "driver_path" : "Thermal/", "driver_type" : "TOBC_Driver", From 75e1442cb49fd6aa5b277b922712cb9732de88a5 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sun, 16 Jan 2022 17:05:05 +0900 Subject: [PATCH 088/141] support utf-8 --- README.md | 2 ++ my_mod/cmd_def.py | 24 ++++++++++++------------ my_mod/tlm_buffer.py | 18 +++++++++--------- my_mod/tlm_def.py | 18 +++++++++--------- settings.json | 1 + 5 files changed, 33 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 1b379ed46..eebb112aa 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,8 @@ $ python GenerateC2ACode.py "c2a_root_dir" : "../../c2a/src/", # TlmCmdDBのファイル名の接頭辞 "db_prefix" : "SAMPLE_MOBC", + # 出力ファイルのエンコーディング + "output_file_encoding" : "utf-8", # GSTOS用sibファイルを生成するか? 0/1 "is_generated_sib" : 0, # テレメパケットのヘッダ長.これをoffsetしたところから,C2A上のテレメのユーザー定義部 diff --git a/my_mod/cmd_def.py b/my_mod/cmd_def.py index efb0b6060..bf6ac9113 100644 --- a/my_mod/cmd_def.py +++ b/my_mod/cmd_def.py @@ -76,8 +76,8 @@ def GenerateCmdDef(settings, sgc_db): subindex = "second" if j % 2 else "first" body_c += " cmd_table[" + cmd_code + "].param_size_infos[" + str(index) + "].packed_info.bit." + subindex + " = " + conv_tpye_to_size[type_list[j]] + ";\n" - OutputCmdDefC_(output_file_path + output_file_name_base + ".c", body_c) - OutputCmdDefH_(output_file_path + output_file_name_base + ".h", body_h) + OutputCmdDefC_(output_file_path + output_file_name_base + ".c", body_c, settings) + OutputCmdDefH_(output_file_path + output_file_name_base + ".h", body_h, settings) def GenerateBctDef(settings, bct_db): @@ -113,7 +113,7 @@ def GenerateBctDef(settings, bct_db): else: body_h += " " + name + " = " + bc_id +", // " + description + "\n" - OutputBctDef_(output_file_path + output_file_name, body_h) + OutputBctDef_(output_file_path + output_file_name, body_h, settings) def GenerateOtherObcCmdDef(settings, other_obc_dbs): @@ -148,10 +148,10 @@ def GenerateOtherObcCmdDef(settings, other_obc_dbs): body_h += " " + cmd_code + " = " + cmd_id + ",\n" # print(body_h) output_file_path = settings["c2a_root_dir"] + r"src_user/Drivers/" + settings["other_obc_data"][i]["driver_path"] + name_lower + "_command_definitions.h" - OutputOtherObcCmdDefH_(output_file_path, obc_name, body_h) + OutputOtherObcCmdDefH_(output_file_path, obc_name, body_h, settings) -def OutputCmdDefC_(file_path, body): +def OutputCmdDefC_(file_path, body, settings): output = "" output += ''' #pragma section REPRO @@ -177,11 +177,11 @@ def OutputCmdDefC_(file_path, body): '''[1:] # 最初の改行を除く - with open(file_path, mode='w', encoding='shift_jis') as fh: + with open(file_path, mode='w', encoding=settings['output_file_encoding']) as fh: fh.write(output) -def OutputCmdDefH_(file_path, body): +def OutputCmdDefH_(file_path, body, settings): output = "" output += ''' /** @@ -206,11 +206,11 @@ def OutputCmdDefH_(file_path, body): #endif '''[1:] # 最初の改行を除く - with open(file_path, mode='w', encoding='shift_jis') as fh: + with open(file_path, mode='w', encoding=settings['output_file_encoding']) as fh: fh.write(output) -def OutputBctDef_(file_path, body): +def OutputBctDef_(file_path, body, settings): output = "" output += ''' /** @@ -238,11 +238,11 @@ def OutputBctDef_(file_path, body): #endif '''[1:] # 最初の改行を除く - with open(file_path, mode='w', encoding='shift_jis') as fh: + with open(file_path, mode='w', encoding=settings['output_file_encoding']) as fh: fh.write(output) -def OutputOtherObcCmdDefH_(file_path, name, body): +def OutputOtherObcCmdDefH_(file_path, name, body, settings): name_upper = name.upper() name_lower = name.lower() name_capit = name.capitalize() @@ -271,6 +271,6 @@ def OutputOtherObcCmdDefH_(file_path, name, body): #endif '''[1:] # 最初の改行を除く - with open(file_path, mode='w', encoding='shift_jis') as fh: + with open(file_path, mode='w', encoding=settings['output_file_encoding']) as fh: fh.write(output.format(_obc_name_upper=name_upper, _obc_name_lower=name_lower, _obc_name_capit=name_capit)) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index b1cd2a213..4d9c4b5ff 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -217,12 +217,12 @@ def GenerateTlmBuffer(settings, other_obc_dbs): output_file_path = settings["c2a_root_dir"] + r"src_user/Drivers/" + settings["other_obc_data"][i]["driver_path"]; - OutputTlmBufferC_(output_file_path + obc_name.lower() + "_telemetry_buffer.c", obc_name, body_c) - OutputTlmBufferH_(output_file_path + obc_name.lower() + "_telemetry_buffer.h", obc_name, body_h) - OutputTlmDataDefH_(output_file_path + obc_name.lower() + "_telemetry_data_definitions.h", obc_name, tlmdef_body_h) + OutputTlmBufferC_(output_file_path + obc_name.lower() + "_telemetry_buffer.c", obc_name, body_c, settings) + OutputTlmBufferH_(output_file_path + obc_name.lower() + "_telemetry_buffer.h", obc_name, body_h, settings) + OutputTlmDataDefH_(output_file_path + obc_name.lower() + "_telemetry_data_definitions.h", obc_name, tlmdef_body_h, settings) -def OutputTlmBufferC_(file_path, name, body): +def OutputTlmBufferC_(file_path, name, body, settings): name_upper = name.upper() name_lower = name.lower() name_capit = name.capitalize() @@ -248,11 +248,11 @@ def OutputTlmBufferC_(file_path, name, body): #pragma section '''[1:] # 最初の改行を除く - with open(file_path, mode='w', encoding='shift_jis') as fh: + with open(file_path, mode='w', encoding=settings['output_file_encoding']) as fh: fh.write(output.format(_obc_name_upper=name_upper, _obc_name_lower=name_lower, _obc_name_capit=name_capit)) -def OutputTlmBufferH_(file_path, name, body): +def OutputTlmBufferH_(file_path, name, body, settings): name_upper = name.upper() name_lower = name.lower() name_capit = name.capitalize() @@ -278,11 +278,11 @@ def OutputTlmBufferH_(file_path, name, body): #endif '''[1:] # 最初の改行を除く - with open(file_path, mode='w', encoding='shift_jis') as fh: + with open(file_path, mode='w', encoding=settings['output_file_encoding']) as fh: fh.write(output.format(_obc_name_upper=name_upper, _obc_name_lower=name_lower, _obc_name_capit=name_capit)) -def OutputTlmDataDefH_(file_path, name, body): +def OutputTlmDataDefH_(file_path, name, body, settings): name_upper = name.upper() name_lower = name.lower() name_capit = name.capitalize() @@ -306,7 +306,7 @@ def OutputTlmDataDefH_(file_path, name, body): #endif '''[1:] # 最初の改行を除く - with open(file_path, mode='w', encoding='shift_jis') as fh: + with open(file_path, mode='w', encoding=settings['output_file_encoding']) as fh: fh.write(output.format(_obc_name_upper=name_upper, _obc_name_lower=name_lower, _obc_name_capit=name_capit)) diff --git a/my_mod/tlm_def.py b/my_mod/tlm_def.py index 0773e5c61..78f6ea610 100644 --- a/my_mod/tlm_def.py +++ b/my_mod/tlm_def.py @@ -108,8 +108,8 @@ def GenerateTlmDef(settings, tlm_db, other_obc_dbs): body_c += GetTlmDefCOfOtherObcFunBody_(settings, tlm_db, other_obc_dbs) body_h += GetTlmDefHOfOtherObc_(settings, tlm_db, other_obc_dbs) - OutputTlmDefC_(output_file_path + output_file_name_base + ".c", body_c) - OutputTlmDefH_(output_file_path + output_file_name_base + ".h", body_h) + OutputTlmDefC_(output_file_path + output_file_name_base + ".c", body_c, settings) + OutputTlmDefH_(output_file_path + output_file_name_base + ".h", body_h, settings) def GetTlmDefCOfOtherObcFunDef_(settings, tlm_db, other_obc_dbs): @@ -242,11 +242,11 @@ def GenerateOtherObcTlmDef(settings, other_obc_dbs): for tlm in tlm_db: body_h += " {_obc_name_upper}_Tlm_CODE_" + tlm['tlm_name'].upper() + " = " + tlm['tlm_id'] + ",\n" output_file_path = settings["c2a_root_dir"] + r"src_user/Drivers/" + settings["other_obc_data"][i]["driver_path"] + obc_name.lower() + "_telemetry_definitions.h" - OutputOtherObcTlmDefH(output_file_path, obc_name, body_h) + OutputOtherObcTlmDefH(output_file_path, obc_name, body_h, settings) -def OutputTlmDefC_(file_path, body): +def OutputTlmDefC_(file_path, body, settings): output = "" output += ''' #pragma section REPRO @@ -268,11 +268,11 @@ def OutputTlmDefC_(file_path, body): #pragma section '''[1:] # 最初の改行を除く - with open(file_path, mode='w', encoding='shift_jis') as fh: + with open(file_path, mode='w', encoding=settings['output_file_encoding']) as fh: fh.write(output) -def OutputTlmDefH_(file_path, body): +def OutputTlmDefH_(file_path, body, settings): output = "" output += ''' /** @@ -297,11 +297,11 @@ def OutputTlmDefH_(file_path, body): #endif '''[1:] # 最初の改行を除く - with open(file_path, mode='w', encoding='shift_jis') as fh: + with open(file_path, mode='w', encoding=settings['output_file_encoding']) as fh: fh.write(output) -def OutputOtherObcTlmDefH(file_path, name, body): +def OutputOtherObcTlmDefH(file_path, name, body, settings): name_upper = name.upper() name_lower = name.lower() name_capit = name.capitalize() @@ -330,6 +330,6 @@ def OutputOtherObcTlmDefH(file_path, name, body): #endif '''[1:] # 最初の改行を除く - with open(file_path, mode='w', encoding='shift_jis') as fh: + with open(file_path, mode='w', encoding=settings['output_file_encoding']) as fh: fh.write(output.format(_obc_name_upper=name_upper, _obc_name_lower=name_lower, _obc_name_capit=name_capit)) diff --git a/settings.json b/settings.json index 7540d60f2..df2f74723 100644 --- a/settings.json +++ b/settings.json @@ -1,6 +1,7 @@ { "c2a_root_dir" : "../../c2a/src/", "db_prefix" : "SAMPLE_MOBC", + "output_file_encoding" : "utf-8", "is_generated_sib" : 0, "header_len" : 13, "is_main_obc" : 1, From 9d92fc35cc93d0884ee624eaae8e504be17ae1b9 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Mon, 17 Jan 2022 12:21:23 +0900 Subject: [PATCH 089/141] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index eebb112aa..1371c5311 100644 --- a/README.md +++ b/README.md @@ -76,12 +76,12 @@ $ python GenerateC2ACode.py ``` ## 開発方針 -そこまで込み入った開発はしないので, +- `main`: リリース版 +- `feature/*` : 開発ブランチ -- master -- develop +というブランチを用いる. -ブランチのみ作成し,master pushは禁止する. +[C2A Core](https://github.com/ut-issl/c2a-core) との互換性などは,[Releases](https://github.com/ut-issl/c2a-tlm-cmd-code-generator/releases) を参照すること([詳細](https://github.com/ut-issl/c2a-core/tree/develop/Docs/.General/release.md)) ## 要求 - python 3.7 以上 From 8dc980fd01d3b3cc2b01478117f3e136fbb605ff Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Wed, 19 Jan 2022 16:25:05 +0900 Subject: [PATCH 090/141] check db range for single OBC --- README.md | 10 ++++++---- my_mod/load_db.py | 10 +++++++--- settings.json | 9 +++++---- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 1371c5311..b9e0337cd 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,8 @@ $ python GenerateC2ACode.py "c2a_root_dir" : "../../c2a/src/", # TlmCmdDBのファイル名の接頭辞 "db_prefix" : "SAMPLE_MOBC", + # TLM ID の定義域 + "tlm_id_range" : ["0x00", "0x100"], # 出力ファイルのエンコーディング "output_file_encoding" : "utf-8", # GSTOS用sibファイルを生成するか? 0/1 @@ -48,13 +50,13 @@ $ python GenerateC2ACode.py # コードを生成するか? "is_enable" : 1, "db_prefix" : "SAMPLE_AOBC", + "tlm_id_range" : ["0x90", "0xc0"], # DBがあるディレクトリへのパス(絶対でも相対でもOK) "db_path" : "../../c2a_sample_aobc/src/src_user/Settings/TlmCmd/DataBase/", "driver_path" : "Aocs/", "driver_type" : "AOBC_Driver", "driver_name" : "aobc", - "code_when_tlm_not_found" : "aobc_driver->info.comm.rx_err_code = AOBC_RX_ERR_CODE_TLM_NOT_FOUND;", - "tlm_id_range" : ["0x90", "0xc0"] + "code_when_tlm_not_found" : "aobc_driver->info.comm.rx_err_code = AOBC_RX_ERR_CODE_TLM_NOT_FOUND;" }, { # OBC名 @@ -63,13 +65,13 @@ $ python GenerateC2ACode.py "is_enable" : 1, "db_prefix" : "SAMPLE_TOBC", # DBがあるディレクトリへのパス(絶対でも相対でもOK) + "tlm_id_range" : ["0xc0", "0xf0"], "db_path" : ""../../c2a_sample_tobc/src/src_user/Settings/TlmCmd/DataBase/", "tlm_max_contents_len" : 512, "driver_path" : "Thermal/", "driver_type" : "TOBC_Driver", "driver_name" : "tobc", - "code_when_tlm_not_found" : "tobc_driver->info.comm.rx_err_code = TOBC_RX_ERR_CODE_TLM_NOT_FOUND;", - "tlm_id_range" : ["0xc0", "0xf0"] + "code_when_tlm_not_found" : "tobc_driver->info.comm.rx_err_code = TOBC_RX_ERR_CODE_TLM_NOT_FOUND;" } ] } diff --git a/my_mod/load_db.py b/my_mod/load_db.py index fbca274ba..aabc117cf 100644 --- a/my_mod/load_db.py +++ b/my_mod/load_db.py @@ -4,6 +4,7 @@ """ import os +import sys import csv import re # 正規表現 import pprint @@ -41,7 +42,7 @@ def LoadCmdCSV_(cmd_db_path, db_prefix): def LoadTlmDb(settings): tlm_db_path = settings["c2a_root_dir"] + r"src_user/Settings/TlmCmd/DataBase/TLM_DB/calced_data/" - tlm_db = LoadTlmCSV_(tlm_db_path, settings["db_prefix"]) + tlm_db = LoadTlmCSV_(tlm_db_path, settings["db_prefix"], settings["tlm_id_range"]) other_obc_dbs = {} if settings["is_main_obc"]: @@ -52,7 +53,7 @@ def LoadTlmDb(settings): return {'tlm': tlm_db, 'other_obc': other_obc_dbs} -def LoadTlmCSV_(tlm_db_path, db_prefix): +def LoadTlmCSV_(tlm_db_path, db_prefix, tlm_id_range): 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] @@ -70,6 +71,9 @@ def LoadTlmCSV_(tlm_db_path, db_prefix): # pprint.pprint(sheet) # print(sheet) tlm_id = sheet[1][2] # FIXME: テレメIDを取得.マジックナンバーで指定してしまってる. + if not int(tlm_id_range[0], 0) <= int(tlm_id, 0) < int(tlm_id_range[1], 0): + print("Error: TLM ID is invalid at " + db_prefix + "_TLM_DB_" + tlm_name + ".csv", file=sys.stderr) + sys.exit(1) raw_local_vars = sheet[1][3].replace("%%", "").split("##") # FIXME: ローカル変数を取得.マジックナンバーで指定してしまってる. local_vars = [] for raw_local_var in raw_local_vars: @@ -109,7 +113,7 @@ def LoadOtherObcTlm(settings): continue tlm_db_path = settings["other_obc_data"][i]["db_path"] + r"TLM_DB/calced_data/" - tlm_db = LoadTlmCSV_(tlm_db_path, settings["other_obc_data"][i]["db_prefix"]) + tlm_db = LoadTlmCSV_(tlm_db_path, settings["other_obc_data"][i]["db_prefix"], settings["other_obc_data"][i]["tlm_id_range"]) other_obc_dbs[settings["other_obc_data"][i]["name"]] = tlm_db # pprint.pprint(other_obc_dbs) diff --git a/settings.json b/settings.json index df2f74723..5672120cc 100644 --- a/settings.json +++ b/settings.json @@ -1,6 +1,7 @@ { "c2a_root_dir" : "../../c2a/src/", "db_prefix" : "SAMPLE_MOBC", + "tlm_id_range" : ["0x00", "0x100"], "output_file_encoding" : "utf-8", "is_generated_sib" : 0, "header_len" : 13, @@ -10,25 +11,25 @@ "name" : "AOBC", "is_enable" : 1, "db_prefix" : "SAMPLE_AOBC", + "tlm_id_range" : ["0x90", "0xc0"], "db_path" : "C:/c2a_sample_aobc/src/src_user/Settings/TlmCmd/DataBase/", "tlm_max_contents_len" : 512, "driver_path" : "Aocs/", "driver_type" : "AOBC_Driver", "driver_name" : "aobc_driver", - "code_when_tlm_not_found" : "aobc_driver->info.comm.rx_err_code = AOBC_RX_ERR_CODE_TLM_NOT_FOUND;", - "tlm_id_range" : ["0x90", "0xc0"] + "code_when_tlm_not_found" : "aobc_driver->info.comm.rx_err_code = AOBC_RX_ERR_CODE_TLM_NOT_FOUND;" }, { "name" : "TOBC", "is_enable" : 1, "db_prefix" : "SAMPLE_TOBC", + "tlm_id_range" : ["0xc0", "0xf0"], "db_path" : "C:/c2a_sample_tobc/src/src_user/Settings/TlmCmd/DataBase/", "tlm_max_contents_len" : 512, "driver_path" : "Thermal/", "driver_type" : "TOBC_Driver", "driver_name" : "tobc_driver", - "code_when_tlm_not_found" : "tobc_driver->info.comm.rx_err_code = TOBC_RX_ERR_CODE_TLM_NOT_FOUND;", - "tlm_id_range" : ["0xc0", "0xf0"] + "code_when_tlm_not_found" : "tobc_driver->info.comm.rx_err_code = TOBC_RX_ERR_CODE_TLM_NOT_FOUND;" } ] } From 3fb49ad466b45f3a95fddb658a7f12c1d2f4f935 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Wed, 19 Jan 2022 16:09:40 +0900 Subject: [PATCH 091/141] fix for check tlm enable flag --- my_mod/load_db.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/my_mod/load_db.py b/my_mod/load_db.py index aabc117cf..727b05df6 100644 --- a/my_mod/load_db.py +++ b/my_mod/load_db.py @@ -74,6 +74,9 @@ def LoadTlmCSV_(tlm_db_path, db_prefix, tlm_id_range): if not int(tlm_id_range[0], 0) <= int(tlm_id, 0) < int(tlm_id_range[1], 0): print("Error: TLM ID is invalid at " + db_prefix + "_TLM_DB_" + tlm_name + ".csv", file=sys.stderr) sys.exit(1) + enable_flag = sheet[2][2] # FIXME: Enable/Disable を取得.マジックナンバーで指定してしまってる. + if enable_flag != "ENABLE": + continue raw_local_vars = sheet[1][3].replace("%%", "").split("##") # FIXME: ローカル変数を取得.マジックナンバーで指定してしまってる. local_vars = [] for raw_local_var in raw_local_vars: From c6fd5eceb9247b53616a64c0e8f7873442e8ab88 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Thu, 20 Jan 2022 00:54:42 +0900 Subject: [PATCH 092/141] fix readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b9e0337cd..445739dad 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ $ python GenerateC2ACode.py "tlm_id_range" : ["0x90", "0xc0"], # DBがあるディレクトリへのパス(絶対でも相対でもOK) "db_path" : "../../c2a_sample_aobc/src/src_user/Settings/TlmCmd/DataBase/", + "tlm_max_contents_len" : 512, "driver_path" : "Aocs/", "driver_type" : "AOBC_Driver", "driver_name" : "aobc", @@ -64,8 +65,8 @@ $ python GenerateC2ACode.py # コードを生成するか? "is_enable" : 1, "db_prefix" : "SAMPLE_TOBC", - # DBがあるディレクトリへのパス(絶対でも相対でもOK) "tlm_id_range" : ["0xc0", "0xf0"], + # DBがあるディレクトリへのパス(絶対でも相対でもOK) "db_path" : ""../../c2a_sample_tobc/src/src_user/Settings/TlmCmd/DataBase/", "tlm_max_contents_len" : 512, "driver_path" : "Thermal/", From 290dd853f2b045f52d4866d038470fa2b5be8641 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Thu, 20 Jan 2022 12:21:35 +0900 Subject: [PATCH 093/141] del gstos --- GenerateC2ACode.py | 4 - my_mod/gstos.py | 261 --------------------------------------------- 2 files changed, 265 deletions(-) delete mode 100644 my_mod/gstos.py diff --git a/GenerateC2ACode.py b/GenerateC2ACode.py index 144a0eaeb..3cb660d41 100644 --- a/GenerateC2ACode.py +++ b/GenerateC2ACode.py @@ -11,7 +11,6 @@ import my_mod.cmd_def import my_mod.tlm_def import my_mod.tlm_buffer -import my_mod.gstos # import os.path @@ -45,9 +44,6 @@ def main(): my_mod.tlm_def.GenerateOtherObcTlmDef(settings, tlm_db['other_obc']) my_mod.tlm_buffer.GenerateTlmBuffer(settings, tlm_db['other_obc']) - if settings["is_generated_sib"]: - my_mod.gstos.GenerateGstosFiles(settings, cmd_db['sgc'], tlm_db['tlm']) - print("Completed!") sys.exit(0) diff --git a/my_mod/gstos.py b/my_mod/gstos.py deleted file mode 100644 index 9e665efe1..000000000 --- a/my_mod/gstos.py +++ /dev/null @@ -1,261 +0,0 @@ -# coding: UTF-8 -""" -GSTOS関連処理 -""" - -import os - -OUTPUT_DIR_GSTOS = "gstos_files" - -def GenerateGstosFiles(settings, sgc_db, tlm_db): - if not os.path.exists(OUTPUT_DIR_GSTOS): - os.makedirs(OUTPUT_DIR_GSTOS) - - cmd_sib_file_path = r"./" + OUTPUT_DIR_GSTOS + r"/cmdfile.cmd.sib" - tlm_sib_file_path = r"./" + OUTPUT_DIR_GSTOS + r"/tlmfile.tlm.sib" - - output_cmd = "" - output_tlm = "" - - output_cmd += '\n' - output_cmd += '\n' - - DATA_SART_ROW = 3 - for i in range(DATA_SART_ROW, len(sgc_db)): - comment = sgc_db[i][0] - name = sgc_db[i][1] - if comment == "" and name == "": # CommentもNameも空白なら打ち切り - break - if comment != "": # Comment - continue - output_cmd += GetCmdSibDef_(sgc_db[i]) - - output_cmd += '\n' - - with open(cmd_sib_file_path, mode='w', encoding='euc_jp') as fh: - fh.write(output_cmd) - - output_tlm += '\n' - output_tlm += '\n' - - DATA_SART_ROW = 7 - - for tlm in tlm_db: - for i in range(DATA_SART_ROW, len(tlm['data'])): - comment = tlm['data'][i][0] - name = tlm['data'][i][1] - var_type = tlm['data'][i][2] - # code = tlm['data'][i][3] - # pos = tlm['data'][i][4] - if comment == "" and name == "": # CommentもNameも空白なら打ち切り - break - if comment != "": - continue - if name == "": - continue - if var_type == "": - continue - # if code == "": - # continue - # if pos == "": - # continue - output_tlm += GetTlmSibDef_(tlm['tlm_id'], tlm['data'][i]) - - output_tlm += '\n' - - with open(tlm_sib_file_path, mode='w', encoding='euc_jp') as fh: - fh.write(output_tlm) - - -def GetCmdSibDef_(sgc_db_line): - cmd = sgc_db_line[1] - inf = sgc_db_line[18] - cmd_id = sgc_db_line[3] - param_num = int(sgc_db_line[4]) - START_PARAM_COL = 5 - is_danger = sgc_db_line[17] - - output = "" - - for cmd_type in range(0,3): - # 0,1,2 -> RT,TL,BL - output += ' \n' - if cmd_type == 0: - output += ' OBC_RT.' + cmd + ' \n' - elif cmd_type == 1: - output += ' OBC_BL.' + cmd + ' \n' - else: - output += ' OBC_TL.' + cmd + ' \n' - output += ' ' + inf + ' \n' - output += ' UNUSE\n' - output += ' 0x0210\n' - output += ' 432\n' - if is_danger: - output += ' K\n' - output += ' \n' - output += ' \n' - output += ' o0,b0@16=0x1a10 \n' - output += ' o2,b0@16=0xC000 \n' - output += ' \n' - output += ' o6,b0@8=0x01 \n' - output += ' \n' - output += ' o7,b0@8=0x02 \n' - output += ' o8,b0@16=' + cmd_id + '\n' - if cmd_type == 0: - output += ' o10,b0@8=0x00\n' - output += ' o11,b0@32=0x00000000 \n' - elif cmd_type == 1: - output += ' o10,b0@8=0x01\n' - output += ' \n' - output += ' \n' - output += ' o11,b0@32 \n' - output += ' Time(UINT,32BIT)\n' - output += ' UINT\n' - output += ' \n' - else: - output += ' o10,b0@8=0x02\n' - output += ' \n' - output += ' \n' - output += ' o11,b0@32 \n' - output += ' Time(UINT,32BIT)\n' - output += ' UINT\n' - output += ' \n' - - if param_num: - o = 0 - l = 0 - t = 0 - b = 0 - for s in range(0, param_num): # パラメーター数に制限はなし.シートで定義したぶんだけ生成可能 - str_info = "param" + str(s + 1); # いくつ目のパラメーターか表示 - var_type = sgc_db_line[START_PARAM_COL + s * 2] - var_note = "" - - if var_type == "int8_t": - var_note = "SINT" - o = 15 + t - l = 8 - t += 1 - elif var_type == "int16_t": - var_note = "SINT" - o = 15 + t - l = 16 - t += 2 - elif var_type == "int32_t": - var_note = "SINT" - o = 15 + t - l = 32 - t += 4 - elif var_type == "uint8_t": - var_note = "UINT" - o = 15 + t - l = 8 - t += 1 - elif var_type == "uint16_t": - var_note = "UINT" - o = 15 + t - l = 16 - t += 2 - elif var_type == "uint32_t": - var_note = "UINT" - o = 15 + t - l = 32 - t += 4 - elif var_type == "float": - var_note = "FLOAT" - o = 15 + t - l = 32 - t += 4 - elif var_type == "double": - var_note = "DOUBLE" - o = 15 + t - l = 64 - t += 8 - elif var_type == "raw": - var_note = "HEXBINARY" - o = 15 + t - l = (432 - o) * 8 - # t += 4 # コマンド長最後まで - else: - print("Error: Cmd DB Err at " + cmd, file=sys.stderr) - sys.exit(1) - - output += ' \n' - output += ' o' + str(o) + ',b' + str(b) + '@' + str(l) + '\n' - output += ' ' + str_info + ' (' + var_type + ',' + str(l) + 'BIT)\n' - output += ' ' + var_note + '\n' - output += ' \n' - - output += ' \n' - output += ' \n' - - return output - - -def GetTlmSibDef_(tlm_id, tlm_db_line): - comment = tlm_db_line[0] - name = tlm_db_line[1] - var_type = tlm_db_line[2] - code = tlm_db_line[3] - pos = tlm_db_line[4] - ext_type = tlm_db_line[5] - oct_pos = tlm_db_line[6] - bit_pos = tlm_db_line[7] - bit_len = tlm_db_line[8] - cnv_type = tlm_db_line[9] - status = tlm_db_line[16] - var_note = "" - - tlm_id = tlm_id.replace("0x", "") - - if var_type == "int8_t": - var_note = "SINT" - elif var_type == "int16_t": - var_note = "SINT" - elif var_type == "int32_t": - var_note = "SINT" - elif var_type == "uint8_t": - var_note = "UINT" - elif var_type == "uint16_t": - var_note = "UINT" - elif var_type == "uint32_t": - var_note = "UINT" - elif var_type == "float": - var_note = "FLOAT" - elif var_type == "double": - var_note = "DOUBLE" - else: - print("Error: Tlm DB Err at " + name, file=sys.stderr) - sys.exit(1) - - # 今回はめんどいのでPACKETしかみない - if ext_type != "PACKET": - print("Error: Tlm DB Err at " + name, file=sys.stderr) - sys.exit(1) - - output = "" - - output += ' \n' - output += ' ' + name + ' \n' - output += ' ' + var_note + ' \n' - output += ' p510:s' + tlm_id + ',o' + oct_pos + ',b' + bit_pos + '@' + bit_len + ' \n' - - if cnv_type == "POLY": - coeffs = [] - for k in range(10,16): - coeff = tlm_db_line[k] - if coeff == "": - break - coeffs.append(coeff) - output += ' ' + ",".join(coeffs) + '\n' - elif cnv_type == "STATUS": - output += ' ' + status + '\n' - elif cnv_type == "NONE": - output += ' \n' - else: - print("Error: Tlm DB Err at " + name, file=sys.stderr) - sys.exit(1) - - output += ' \n' - - return output From f0a107b146aeb335aa94bf29471b3f92ca38d513 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Thu, 20 Jan 2022 12:22:40 +0900 Subject: [PATCH 094/141] fix readme and settings --- README.md | 2 -- settings.json | 1 - 2 files changed, 3 deletions(-) diff --git a/README.md b/README.md index b9e0337cd..4338597ed 100644 --- a/README.md +++ b/README.md @@ -35,8 +35,6 @@ $ python GenerateC2ACode.py "tlm_id_range" : ["0x00", "0x100"], # 出力ファイルのエンコーディング "output_file_encoding" : "utf-8", - # GSTOS用sibファイルを生成するか? 0/1 - "is_generated_sib" : 0, # テレメパケットのヘッダ長.これをoffsetしたところから,C2A上のテレメのユーザー定義部 "header_len" : 13, # MOBCか?(他のOBCのtlm/cmdを取りまとめるか?) 0/1 diff --git a/settings.json b/settings.json index 5672120cc..6f7ab05f0 100644 --- a/settings.json +++ b/settings.json @@ -3,7 +3,6 @@ "db_prefix" : "SAMPLE_MOBC", "tlm_id_range" : ["0x00", "0x100"], "output_file_encoding" : "utf-8", - "is_generated_sib" : 0, "header_len" : 13, "is_main_obc" : 1, "other_obc_data" : [ From 61559fef6b1fb9ded30fa48a990474ce43660af7 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Thu, 20 Jan 2022 00:35:21 +0900 Subject: [PATCH 095/141] add flake8 and black --- .flake8 | 7 ++++++ .github/workflows/python_check_format.yml | 25 +++++++++++++++++++++ .github/workflows/python_lint.yml | 27 +++++++++++++++++++++++ pyproject.toml | 8 +++++++ 4 files changed, 67 insertions(+) create mode 100644 .flake8 create mode 100644 .github/workflows/python_check_format.yml create mode 100644 .github/workflows/python_lint.yml create mode 100644 pyproject.toml diff --git a/.flake8 b/.flake8 new file mode 100644 index 000000000..f12eee9c0 --- /dev/null +++ b/.flake8 @@ -0,0 +1,7 @@ +[flake8] +max-line-length = 100 +ignore = + # black と競合するので + E203, + W503, + W504 diff --git a/.github/workflows/python_check_format.yml b/.github/workflows/python_check_format.yml new file mode 100644 index 000000000..5122fd697 --- /dev/null +++ b/.github/workflows/python_check_format.yml @@ -0,0 +1,25 @@ +name: reviewdog / python format check + +on: + push: + branches: + - main + pull_request: + +jobs: + black_format: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + # - name: check python format with black + # uses: psf/black@stable + + - uses: reviewdog/action-black@v2 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + # reporter: github-pr-review # TODO: いい感じになったら直す + reporter: github-pr-check + filter_mode: nofilter + fail_on_error: true + level: warning diff --git a/.github/workflows/python_lint.yml b/.github/workflows/python_lint.yml new file mode 100644 index 000000000..cbef59827 --- /dev/null +++ b/.github/workflows/python_lint.yml @@ -0,0 +1,27 @@ +name: reviewdog / lint python + +on: + push: + branches: + - main + pull_request: + +jobs: + flake8_lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Set up python environment + uses: actions/setup-python@v2 + with: + python-version: "3.8" + + - name: flake8 Lint + uses: reviewdog/action-flake8@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + reporter: github-pr-review + filter_mode: nofilter + fail_on_error: true + level: warning diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..56ce77371 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,8 @@ +[tool.black] +target-version = ['py38'] +line-length = 100 +include = '\.pyi?$' + +# TODO: .flake8 を消してこちらに移植する +# [tool.flake8] +# max-line-length = 100 From 547aebd6642a86cfdc63ba222f53aba076168eae Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Thu, 20 Jan 2022 00:41:57 +0900 Subject: [PATCH 096/141] apply black --- GenerateC2ACode.py | 20 ++-- my_mod/cmd_def.py | 166 ++++++++++++++++---------- my_mod/load_db.py | 56 +++++---- my_mod/tlm_buffer.py | 275 ++++++++++++++++++++++++++++++------------- my_mod/tlm_def.py | 185 ++++++++++++++++++++--------- 5 files changed, 472 insertions(+), 230 deletions(-) diff --git a/GenerateC2ACode.py b/GenerateC2ACode.py index 3cb660d41..7a5a845c5 100644 --- a/GenerateC2ACode.py +++ b/GenerateC2ACode.py @@ -4,7 +4,6 @@ """ import json -import pprint import sys import my_mod.load_db @@ -13,6 +12,7 @@ import my_mod.tlm_buffer +# import pprint # import os.path # import msvcrt # Enter不要な入力用 # import subprocess @@ -24,8 +24,9 @@ # 1 : all SETTING_FILE_PATH = "settings.json" + def main(): - with open(SETTING_FILE_PATH, mode='r') as fh: + with open(SETTING_FILE_PATH, mode="r") as fh: settings = json.load(fh) # print(settings["c2a_root_dir"]); @@ -35,19 +36,18 @@ def main(): # pprint.pprint(tlm_db) # print(tlm_db) - my_mod.cmd_def.GenerateCmdDef(settings, cmd_db['sgc']) - my_mod.cmd_def.GenerateBctDef(settings, cmd_db['bct']) - my_mod.tlm_def.GenerateTlmDef(settings, tlm_db['tlm'], tlm_db['other_obc']) + my_mod.cmd_def.GenerateCmdDef(settings, cmd_db["sgc"]) + my_mod.cmd_def.GenerateBctDef(settings, cmd_db["bct"]) + my_mod.tlm_def.GenerateTlmDef(settings, tlm_db["tlm"], tlm_db["other_obc"]) if settings["is_main_obc"]: - my_mod.cmd_def.GenerateOtherObcCmdDef(settings, cmd_db['other_obc']) - my_mod.tlm_def.GenerateOtherObcTlmDef(settings, tlm_db['other_obc']) - my_mod.tlm_buffer.GenerateTlmBuffer(settings, tlm_db['other_obc']) + my_mod.cmd_def.GenerateOtherObcCmdDef(settings, cmd_db["other_obc"]) + my_mod.tlm_def.GenerateOtherObcTlmDef(settings, tlm_db["other_obc"]) + my_mod.tlm_buffer.GenerateTlmBuffer(settings, tlm_db["other_obc"]) print("Completed!") sys.exit(0) -if __name__ == '__main__': +if __name__ == "__main__": main() - diff --git a/my_mod/cmd_def.py b/my_mod/cmd_def.py index bf6ac9113..7c4a99767 100644 --- a/my_mod/cmd_def.py +++ b/my_mod/cmd_def.py @@ -3,9 +3,10 @@ cmd def """ -import os import sys -import pprint + +# import pprint + def GenerateCmdDef(settings, sgc_db): output_file_path = settings["c2a_root_dir"] + r"src_user/TlmCmd/" @@ -19,11 +20,11 @@ def GenerateCmdDef(settings, sgc_db): # " Cmd_CODE_NOP = 0x0000," for i in range(DATA_SART_ROW, len(sgc_db)): comment = sgc_db[i][0] - name = sgc_db[i][1] - cmd_id = sgc_db[i][3] - if comment == "" and name == "": # CommentもNameも空白なら打ち切り + name = sgc_db[i][1] + cmd_id = sgc_db[i][3] + if comment == "" and name == "": # CommentもNameも空白なら打ち切り break - if comment != "": # Comment + if comment != "": # Comment continue cmd_name = name @@ -33,48 +34,65 @@ def GenerateCmdDef(settings, sgc_db): body_c += " cmd_table[" + cmd_code + "].cmd_func = " + cmd_name + ";\n" body_h += " " + cmd_code + " = " + cmd_id + ",\n" - body_c += "\n"; + body_c += "\n" for i in range(DATA_SART_ROW, len(sgc_db)): comment = sgc_db[i][0] - name = sgc_db[i][1] - cmd_id = sgc_db[i][3] - if comment == "" and name == "": # CommentもNameも空白なら打ち切り + name = sgc_db[i][1] + cmd_id = sgc_db[i][3] + if comment == "" and name == "": # CommentもNameも空白なら打ち切り break - if comment != "": # Comment + if comment != "": # Comment continue param_num = int(sgc_db[i][4]) - type_list = [sgc_db[i][5], sgc_db[i][7], sgc_db[i][9], sgc_db[i][11], sgc_db[i][13], sgc_db[i][15]] + type_list = [ + sgc_db[i][5], + sgc_db[i][7], + sgc_db[i][9], + sgc_db[i][11], + sgc_db[i][13], + sgc_db[i][15], + ] cmd_name = name cmd_code = cmd_name.replace("Cmd_", "Cmd_CODE_") # パラメタ長の整合性チェック for j in range(len(type_list)): - err_flag = 0; + err_flag = 0 if j < param_num and type_list[j] == "": err_flag = 1 if j >= param_num and type_list[j] != "": err_flag = 1 - if (err_flag): + if err_flag: print("Error: Cmd DB Err at " + name, file=sys.stderr) sys.exit(1) # パラメタ長のカウント conv_tpye_to_size = { - 'int8_t' : "CA_PARAM_SIZE_TYPE_1BYTE", - 'int16_t' : "CA_PARAM_SIZE_TYPE_2BYTE", - 'int32_t' : "CA_PARAM_SIZE_TYPE_4BYTE", - 'uint8_t' : "CA_PARAM_SIZE_TYPE_1BYTE", - 'uint16_t' : "CA_PARAM_SIZE_TYPE_2BYTE", - 'uint32_t' : "CA_PARAM_SIZE_TYPE_4BYTE", - 'float' : "CA_PARAM_SIZE_TYPE_4BYTE", - 'double' : "CA_PARAM_SIZE_TYPE_8BYTE", - 'raw' : "CA_PARAM_SIZE_TYPE_RAW" - } + "int8_t": "CA_PARAM_SIZE_TYPE_1BYTE", + "int16_t": "CA_PARAM_SIZE_TYPE_2BYTE", + "int32_t": "CA_PARAM_SIZE_TYPE_4BYTE", + "uint8_t": "CA_PARAM_SIZE_TYPE_1BYTE", + "uint16_t": "CA_PARAM_SIZE_TYPE_2BYTE", + "uint32_t": "CA_PARAM_SIZE_TYPE_4BYTE", + "float": "CA_PARAM_SIZE_TYPE_4BYTE", + "double": "CA_PARAM_SIZE_TYPE_8BYTE", + "raw": "CA_PARAM_SIZE_TYPE_RAW", + } for j in range(param_num): index = j // 2 subindex = "second" if j % 2 else "first" - body_c += " cmd_table[" + cmd_code + "].param_size_infos[" + str(index) + "].packed_info.bit." + subindex + " = " + conv_tpye_to_size[type_list[j]] + ";\n" + body_c += ( + " cmd_table[" + + cmd_code + + "].param_size_infos[" + + str(index) + + "].packed_info.bit." + + subindex + + " = " + + conv_tpye_to_size[type_list[j]] + + ";\n" + ) OutputCmdDefC_(output_file_path + output_file_name_base + ".c", body_c, settings) OutputCmdDefH_(output_file_path + output_file_name_base + ".h", body_h, settings) @@ -91,27 +109,27 @@ def GenerateBctDef(settings, bct_db): # " Cmd_CODE_NOP = 0x0000," for i in range(DATA_SART_ROW, len(bct_db)): comment = bct_db[i][0] - name = bct_db[i][1] - bc_id = bct_db[i][3] + name = bct_db[i][1] + bc_id = bct_db[i][3] description = bct_db[i][10] # エスケープ解除 name = name.replace("@@", ",") description = description.replace("@@", ",") - if comment == "" and name == "": # CommentもNameも空白なら打ち切り + if comment == "" and name == "": # CommentもNameも空白なら打ち切り break - if comment == "**": # New Line Comment + if comment == "**": # New Line Comment body_h += "\n // " + name + "\n" - elif comment != "": # Comment + elif comment != "": # Comment body_h += " // " + name + "\n" else: # " BC_SL_INITIAL_TO_INITIAL = 0," if description == "": - body_h += " " + name + " = " + bc_id +",\n" + body_h += " " + name + " = " + bc_id + ",\n" else: - body_h += " " + name + " = " + bc_id +", // " + description + "\n" + body_h += " " + name + " = " + bc_id + ", // " + description + "\n" OutputBctDef_(output_file_path + output_file_name, body_h, settings) @@ -136,24 +154,30 @@ def GenerateOtherObcCmdDef(settings, other_obc_dbs): # " TOBC_Cmd_CODE_NOP = 0x0000," for j in range(DATA_SART_ROW, len(sgc_db)): comment = sgc_db[j][0] - name = sgc_db[j][1] - cmd_id = sgc_db[j][3] - if comment == "" and name == "": # CommentもNameも空白なら打ち切り + name = sgc_db[j][1] + cmd_id = sgc_db[j][3] + if comment == "" and name == "": # CommentもNameも空白なら打ち切り break - if comment != "": # Comment + if comment != "": # Comment continue # print(name) cmd_name = name - cmd_code = cmd_name.replace("Cmd_", name_upper+"_Cmd_CODE_") + cmd_code = cmd_name.replace("Cmd_", name_upper + "_Cmd_CODE_") body_h += " " + cmd_code + " = " + cmd_id + ",\n" # print(body_h) - output_file_path = settings["c2a_root_dir"] + r"src_user/Drivers/" + settings["other_obc_data"][i]["driver_path"] + name_lower + "_command_definitions.h" + output_file_path = ( + settings["c2a_root_dir"] + + r"src_user/Drivers/" + + settings["other_obc_data"][i]["driver_path"] + + name_lower + + "_command_definitions.h" + ) OutputOtherObcCmdDefH_(output_file_path, obc_name, body_h, settings) def OutputCmdDefC_(file_path, body, settings): output = "" - output += ''' + output += """ #pragma section REPRO /** * @file @@ -166,24 +190,27 @@ def OutputCmdDefC_(file_path, body, settings): void CA_load_cmd_table(CA_CmdInfo cmd_table[CA_MAX_CMDS]) { -'''[1:] # 最初の改行を除く +"""[ + 1: + ] # 最初の改行を除く output += body - output += ''' + output += """ } #pragma section -'''[1:] # 最初の改行を除く - +"""[ + 1: + ] # 最初の改行を除く - with open(file_path, mode='w', encoding=settings['output_file_encoding']) as fh: + with open(file_path, mode="w", encoding=settings["output_file_encoding"]) as fh: fh.write(output) def OutputCmdDefH_(file_path, body, settings): output = "" - output += ''' + output += """ /** * @file * @brief コマンド定義 @@ -194,25 +221,29 @@ def OutputCmdDefH_(file_path, body, settings): typedef enum { -'''[1:] # 最初の改行を除く +"""[ + 1: + ] # 最初の改行を除く output += body - output += ''' + output += """ Cmd_CODE_MAX } CMD_CODE; #endif -'''[1:] # 最初の改行を除く +"""[ + 1: + ] # 最初の改行を除く - with open(file_path, mode='w', encoding=settings['output_file_encoding']) as fh: + with open(file_path, mode="w", encoding=settings["output_file_encoding"]) as fh: fh.write(output) def OutputBctDef_(file_path, body, settings): output = "" - output += ''' + output += """ /** * @file * @brief ブロックコマンド定義 @@ -224,11 +255,13 @@ def OutputBctDef_(file_path, body, settings): // 登録されるBlockCommandTableのblock番号を規定 typedef enum { -'''[1:] # 最初の改行を除く +"""[ + 1: + ] # 最初の改行を除く output += body - output += ''' + output += """ BC_ID_MAX // BCT 自体のサイズは BCT_MAX_BLOCKS で規定 } BC_DEFAULT_ID; @@ -236,9 +269,11 @@ def OutputBctDef_(file_path, body, settings): void BC_load_defaults(void); #endif -'''[1:] # 最初の改行を除く +"""[ + 1: + ] # 最初の改行を除く - with open(file_path, mode='w', encoding=settings['output_file_encoding']) as fh: + with open(file_path, mode="w", encoding=settings["output_file_encoding"]) as fh: fh.write(output) @@ -248,7 +283,7 @@ def OutputOtherObcCmdDefH_(file_path, name, body, settings): name_capit = name.capitalize() output = "" - output += ''' + output += """ /** * @file * @brief コマンド定義 @@ -259,18 +294,25 @@ def OutputOtherObcCmdDefH_(file_path, name, body, settings): typedef enum {{ -'''[1:] # 最初の改行を除く +"""[ + 1: + ] # 最初の改行を除く output += body - output += ''' + output += """ {_obc_name_upper}_Cmd_CODE_MAX }} {_obc_name_upper}_CMD_CODE; #endif -'''[1:] # 最初の改行を除く - - with open(file_path, mode='w', encoding=settings['output_file_encoding']) as fh: - fh.write(output.format(_obc_name_upper=name_upper, _obc_name_lower=name_lower, _obc_name_capit=name_capit)) - +"""[ + 1: + ] # 最初の改行を除く + + with open(file_path, mode="w", encoding=settings["output_file_encoding"]) as fh: + fh.write( + output.format( + _obc_name_upper=name_upper, _obc_name_lower=name_lower, _obc_name_capit=name_capit + ) + ) diff --git a/my_mod/load_db.py b/my_mod/load_db.py index 727b05df6..0d3827f6a 100644 --- a/my_mod/load_db.py +++ b/my_mod/load_db.py @@ -6,8 +6,10 @@ import os import sys import csv -import re # 正規表現 -import pprint +import re # 正規表現 + +# import pprint + def LoadCmdDb(settings): cmd_db_path = settings["c2a_root_dir"] + r"src_user/Settings/TlmCmd/DataBase/CMD_DB/" @@ -16,23 +18,23 @@ def LoadCmdDb(settings): other_obc_dbs = {} if settings["is_main_obc"]: - other_obc_dbs = LoadOtherObcCmd_(settings); + other_obc_dbs = LoadOtherObcCmd_(settings) # TODO: 重複チェックをする # print(sgc_db) # print(bct_db) - return {'sgc': sgc_db, 'bct': bct_db, 'other_obc': other_obc_dbs} + return {"sgc": sgc_db, "bct": bct_db, "other_obc": other_obc_dbs} def LoadCmdCSV_(cmd_db_path, db_prefix): - 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 + 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="shift_jis") 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="shift_jis") as fh: reader = csv.reader(fh) bct_db = [row for row in reader] @@ -40,17 +42,19 @@ def LoadCmdCSV_(cmd_db_path, db_prefix): def LoadTlmDb(settings): - tlm_db_path = settings["c2a_root_dir"] + r"src_user/Settings/TlmCmd/DataBase/TLM_DB/calced_data/" + tlm_db_path = ( + 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"]) other_obc_dbs = {} if settings["is_main_obc"]: - other_obc_dbs = LoadOtherObcTlm(settings); + other_obc_dbs = LoadOtherObcTlm(settings) # TODO: 重複チェックをする - return {'tlm': tlm_db, 'other_obc': other_obc_dbs} + return {"tlm": tlm_db, "other_obc": other_obc_dbs} def LoadTlmCSV_(tlm_db_path, db_prefix, tlm_id_range): @@ -65,30 +69,37 @@ 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="shift_jis") as fh: reader = csv.reader(fh) sheet = [row for row in reader] # pprint.pprint(sheet) # print(sheet) - tlm_id = sheet[1][2] # FIXME: テレメIDを取得.マジックナンバーで指定してしまってる. + tlm_id = sheet[1][2] # FIXME: テレメIDを取得.マジックナンバーで指定してしまってる. if not int(tlm_id_range[0], 0) <= int(tlm_id, 0) < int(tlm_id_range[1], 0): - print("Error: TLM ID is invalid at " + db_prefix + "_TLM_DB_" + tlm_name + ".csv", file=sys.stderr) + print( + "Error: TLM ID is invalid at " + db_prefix + "_TLM_DB_" + tlm_name + ".csv", + file=sys.stderr, + ) sys.exit(1) - enable_flag = sheet[2][2] # FIXME: Enable/Disable を取得.マジックナンバーで指定してしまってる. + enable_flag = sheet[2][2] # FIXME: Enable/Disable を取得.マジックナンバーで指定してしまってる. if enable_flag != "ENABLE": continue - raw_local_vars = sheet[1][3].replace("%%", "").split("##") # FIXME: ローカル変数を取得.マジックナンバーで指定してしまってる. + raw_local_vars = ( + sheet[1][3].replace("%%", "").split("##") + ) # FIXME: ローカル変数を取得.マジックナンバーで指定してしまってる. local_vars = [] for raw_local_var in raw_local_vars: local_var = raw_local_var.strip() if len(local_var) > 0: local_vars.append(local_var) - tlm_db.append({'tlm_id': tlm_id, 'tlm_name': tlm_name, 'local_vars': local_vars, 'data': sheet}) + tlm_db.append( + {"tlm_id": tlm_id, "tlm_name": tlm_name, "local_vars": local_vars, "data": sheet} + ) # tlm_db.append({'tlm_id': tlm_id, 'tlm_name': tlm_name, 'data': 1}) - tlm_db.sort(key=lambda x: x['tlm_id']) + tlm_db.sort(key=lambda x: x["tlm_id"]) - return tlm_db; + return tlm_db def LoadOtherObcCmd_(settings): @@ -116,9 +127,12 @@ def LoadOtherObcTlm(settings): continue tlm_db_path = settings["other_obc_data"][i]["db_path"] + r"TLM_DB/calced_data/" - tlm_db = LoadTlmCSV_(tlm_db_path, settings["other_obc_data"][i]["db_prefix"], settings["other_obc_data"][i]["tlm_id_range"]) + tlm_db = LoadTlmCSV_( + tlm_db_path, + settings["other_obc_data"][i]["db_prefix"], + settings["other_obc_data"][i]["tlm_id_range"], + ) other_obc_dbs[settings["other_obc_data"][i]["name"]] = tlm_db # pprint.pprint(other_obc_dbs) return other_obc_dbs - diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index 4d9c4b5ff..502f32a48 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -3,10 +3,11 @@ tlm buffer """ -import os import sys + # from collections import OrderedDict -import pprint +# import pprint + def GenerateTlmBuffer(settings, other_obc_dbs): DATA_START_ROW = 8 @@ -33,32 +34,40 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_h += "typedef struct\n" body_h += "{{\n" for tlm in tlm_db: - tlm_name = tlm['tlm_name'] + tlm_name = tlm["tlm_name"] tlm_name_lower = tlm_name.lower() body_h += " struct\n" body_h += " {{\n" body_h += " int size;\n" body_h += " uint8_t buffer[{_obc_name_upper}_TELEMETRY_BUFFE_SIZE];\n" body_h += " }} " + tlm_name_lower + ";\n" - body_c += "static DS_ERR_CODE {_obc_name_upper}_analyze_tlm_" + tlm_name_lower + "_(DS_StreamConfig* p_stream_config, " + driver_type + "* " + driver_name + ");\n" + body_c += ( + "static DS_ERR_CODE {_obc_name_upper}_analyze_tlm_" + + tlm_name_lower + + "_(DS_StreamConfig* p_stream_config, " + + driver_type + + "* " + + driver_name + + ");\n" + ) body_h += "}} {_obc_name_upper}_Buffer;\n" body_h += "\n" tlmdef_body_h += "typedef struct\n" tlmdef_body_h += "{{\n" for tlm in tlm_db: - tlm_name = tlm['tlm_name'] + tlm_name = tlm["tlm_name"] tlm_name_lower = tlm_name.lower() # pprint.pprint(tlm['data'][DATA_START_ROW:]) last_var_type = "" - tlm_struct_tree = {} # python3.7以上を想定しているので,キーの順番は保存されていることが前提 + tlm_struct_tree = {} # python3.7以上を想定しているので,キーの順番は保存されていることが前提 # tlm_struct_tree = collections.OrderedDict() # やっぱこっちで - for j in range(DATA_START_ROW, len(tlm['data'])): - comment = tlm['data'][j][0] - name = EscapeTlmElemName_(tlm['data'][j][1]) - var_type = tlm['data'][j][2] - if comment == "" and name == "": # CommentもNameも空白なら打ち切り + for j in range(DATA_START_ROW, len(tlm["data"])): + comment = tlm["data"][j][0] + name = EscapeTlmElemName_(tlm["data"][j][1]) + var_type = tlm["data"][j][2] + if comment == "" and name == "": # CommentもNameも空白なら打ち切り break if comment != "": continue @@ -73,7 +82,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): # name_tree = name.lower().split(".")[2:] # OBC名.テレメ名.HOGE.FUGA を想定 name_tree = name.lower().split(".") name_path = "/".join(name_tree) - if (SetStructTree_(tlm_struct_tree, name_path, var_type)): + if SetStructTree_(tlm_struct_tree, name_path, var_type): print("Error: Tlm DB Struct Parse Err at " + name, file=sys.stderr) sys.exit(1) @@ -91,19 +100,30 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_h += "\n" body_h += "void {_obc_name_upper}_buffer_init(void);\n" body_h += "\n" - body_h += "DS_ERR_CODE {_obc_name_upper}_buffer_tlm_contents(DS_StreamConfig* p_stream_config, " + driver_type + "* " + driver_name + ");\n" - + body_h += ( + "DS_ERR_CODE {_obc_name_upper}_buffer_tlm_contents(DS_StreamConfig* p_stream_config, " + + driver_type + + "* " + + driver_name + + ");\n" + ) body_c += "\n" body_c += "void {_obc_name_upper}_buffer_init(void)\n" body_c += "{{\n" for tlm in tlm_db: - tlm_name = tlm['tlm_name'] + tlm_name = tlm["tlm_name"] tlm_name_lower = tlm_name.lower() body_c += " {_obc_name_lower}_buffer_." + tlm_name_lower + ".size = 0;\n" body_c += "}}\n" body_c += "\n" - body_c += "DS_ERR_CODE {_obc_name_upper}_buffer_tlm_contents(DS_StreamConfig* p_stream_config, " + driver_type + "* " + driver_name + ")\n" + body_c += ( + "DS_ERR_CODE {_obc_name_upper}_buffer_tlm_contents(DS_StreamConfig* p_stream_config, " + + driver_type + + "* " + + driver_name + + ")\n" + ) body_c += "{{\n" body_c += " uint8_t tlm_id = DS_C2AFMT_get_tlm_id(p_stream_config);\n" @@ -112,11 +132,17 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += " switch (tlm_id)\n" body_c += " {{\n" for tlm in tlm_db: - tlm_name = tlm['tlm_name'] + tlm_name = tlm["tlm_name"] tlm_name_upper = tlm_name.upper() tlm_name_lower = tlm_name.lower() body_c += " case {_obc_name_upper}_Tlm_CODE_" + tlm_name_upper + ":\n" - body_c += " return {_obc_name_upper}_analyze_tlm_" + tlm_name_lower + "_(p_stream_config, " + driver_name + ");\n" + body_c += ( + " return {_obc_name_upper}_analyze_tlm_" + + tlm_name_lower + + "_(p_stream_config, " + + driver_name + + ");\n" + ) body_c += " default:\n" body_c += " " + settings["other_obc_data"][i]["code_when_tlm_not_found"] + "\n" body_c += " return DS_ERR_CODE_ERR;\n" @@ -125,29 +151,37 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += "\n" for tlm in tlm_db: conv_tpye_to_temp = { - 'int8_t' : 'temp_i8', - 'int16_t' : 'temp_i16', - 'int32_t' : 'temp_i32', - 'uint8_t' : 'temp_u8', - 'uint16_t' : 'temp_u16', - 'uint32_t' : 'temp_u32', - 'float' : 'temp_f', - 'double' : 'temp_d', - } + "int8_t": "temp_i8", + "int16_t": "temp_i16", + "int32_t": "temp_i32", + "uint8_t": "temp_u8", + "uint16_t": "temp_u16", + "uint32_t": "temp_u32", + "float": "temp_f", + "double": "temp_d", + } conv_tpye_to_size = { - 'int8_t' : 1, - 'int16_t' : 2, - 'int32_t' : 4, - 'uint8_t' : 1, - 'uint16_t' : 2, - 'uint32_t' : 4, - 'float' : 4, - 'double' : 8 - } - tlm_name = tlm['tlm_name'] + "int8_t": 1, + "int16_t": 2, + "int32_t": 4, + "uint8_t": 1, + "uint16_t": 2, + "uint32_t": 4, + "float": 4, + "double": 8, + } + tlm_name = tlm["tlm_name"] tlm_name_upper = tlm_name.upper() tlm_name_lower = tlm_name.lower() - body_c += "static DS_ERR_CODE {_obc_name_upper}_analyze_tlm_" + tlm_name_lower + "_(DS_StreamConfig* p_stream_config, " + driver_type + "* " + driver_name + ")\n" + body_c += ( + "static DS_ERR_CODE {_obc_name_upper}_analyze_tlm_" + + tlm_name_lower + + "_(DS_StreamConfig* p_stream_config, " + + driver_type + + "* " + + driver_name + + ")\n" + ) body_c += "{{\n" body_c += " uint32_t tlm_len = DS_ISSLFMT_get_tlm_length(p_stream_config);\n" body_c += " const uint8_t* f = DSSC_get_rx_frame(p_stream_config) + DS_ISSLFMT_COMMON_HEADER_SIZE;\n" @@ -163,16 +197,22 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += "\n" body_c += " // GSへのテレメ中継のためのバッファーへのコピー\n" body_c += " if (contents_len > {_obc_name_upper}_TELEMETRY_BUFFE_SIZE) return DS_ERR_CODE_ERR;\n" - body_c += " memcpy({_obc_name_lower}_buffer_." + tlm_name_lower + ".buffer, contents_pos, (size_t)contents_len);\n" - body_c += " {_obc_name_lower}_buffer_." + tlm_name_lower + ".size = (int)contents_len;\n" + body_c += ( + " memcpy({_obc_name_lower}_buffer_." + + tlm_name_lower + + ".buffer, contents_pos, (size_t)contents_len);\n" + ) + body_c += ( + " {_obc_name_lower}_buffer_." + tlm_name_lower + ".size = (int)contents_len;\n" + ) body_c += "\n" body_c += " // MOBC内部でテレメデータへアクセスしやすいようにするための構造体へのパース\n" last_var_type = "" - for j in range(DATA_START_ROW, len(tlm['data'])): - comment = tlm['data'][j][0] - name = EscapeTlmElemName_(tlm['data'][j][1]) - var_type = tlm['data'][j][2] - if comment == "" and name == "": # CommentもNameも空白なら打ち切り + for j in range(DATA_START_ROW, len(tlm["data"])): + comment = tlm["data"][j][0] + name = EscapeTlmElemName_(tlm["data"][j][1]) + var_type = tlm["data"][j][2] + if comment == "" and name == "": # CommentもNameも空白なら打ち切り break if comment != "": continue @@ -184,26 +224,54 @@ def GenerateTlmBuffer(settings, other_obc_dbs): if last_var_type == "": continue - oct_pos = int(tlm['data'][j][5]) - bit_pos = int(tlm['data'][j][6]) - bit_len = int(tlm['data'][j][7]) - is_compression = 0 # テレメ圧縮フラグ for ビットフィールドをつかってる奴ら - if tlm['data'][j][2] == "" or tlm['data'][j+1][2] == "": + oct_pos = int(tlm["data"][j][5]) + bit_pos = int(tlm["data"][j][6]) + bit_len = int(tlm["data"][j][7]) + is_compression = 0 # テレメ圧縮フラグ for ビットフィールドをつかってる奴ら + if tlm["data"][j][2] == "" or tlm["data"][j + 1][2] == "": is_compression = 1 - if (tlm['data'][j+1][0] == "" and tlm['data'][j+1][1] == "" and tlm['data'][j][2] != ""): # 最終行の除外 + if ( + tlm["data"][j + 1][0] == "" + and tlm["data"][j + 1][1] == "" + and tlm["data"][j][2] != "" + ): # 最終行の除外 is_compression = 0 # name_tree = name.lower().split(".")[2:] # OBC名.テレメ名.HOGE.FUGA を想定 name_tree = name.lower().split(".") name_path = ".".join(name_tree) var_name = driver_name + "->tlm_data." + tlm_name_lower + "." + name_path - if (is_compression): - body_c += " endian_memcpy(&" + conv_tpye_to_temp[var_type] + ", &(f[" + str(oct_pos) + "]), " + str(conv_tpye_to_size[var_type]) + ");\n" - body_c += " " + conv_tpye_to_temp[var_type] + " >>= " + str(7 - bit_pos) + ";\n" - body_c += " " + conv_tpye_to_temp[var_type] + " &= " + hex(int("0b" + "1" * bit_len, 2)) + ";\n" + if is_compression: + body_c += ( + " endian_memcpy(&" + + conv_tpye_to_temp[var_type] + + ", &(f[" + + str(oct_pos) + + "]), " + + str(conv_tpye_to_size[var_type]) + + ");\n" + ) + body_c += ( + " " + conv_tpye_to_temp[var_type] + " >>= " + str(7 - bit_pos) + ";\n" + ) + body_c += ( + " " + + conv_tpye_to_temp[var_type] + + " &= " + + hex(int("0b" + "1" * bit_len, 2)) + + ";\n" + ) body_c += " " + var_name + " = " + conv_tpye_to_temp[var_type] + ";\n" else: - body_c += " endian_memcpy(&(" + var_name + "), &(f[" + str(oct_pos) + "]), " + str(conv_tpye_to_size[var_type]) + ");\n" + body_c += ( + " endian_memcpy(&(" + + var_name + + "), &(f[" + + str(oct_pos) + + "]), " + + str(conv_tpye_to_size[var_type]) + + ");\n" + ) body_c += " // TODO: ビットフィールドをつかっている系は,様々なパターンがあり得るので,今後,バグが出ないか注視する\n" body_c += "\n" @@ -215,11 +283,23 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += "}}\n" body_c += "\n" - - output_file_path = settings["c2a_root_dir"] + r"src_user/Drivers/" + settings["other_obc_data"][i]["driver_path"]; - OutputTlmBufferC_(output_file_path + obc_name.lower() + "_telemetry_buffer.c", obc_name, body_c, settings) - OutputTlmBufferH_(output_file_path + obc_name.lower() + "_telemetry_buffer.h", obc_name, body_h, settings) - OutputTlmDataDefH_(output_file_path + obc_name.lower() + "_telemetry_data_definitions.h", obc_name, tlmdef_body_h, settings) + output_file_path = ( + settings["c2a_root_dir"] + + r"src_user/Drivers/" + + settings["other_obc_data"][i]["driver_path"] + ) + OutputTlmBufferC_( + output_file_path + obc_name.lower() + "_telemetry_buffer.c", obc_name, body_c, settings + ) + OutputTlmBufferH_( + output_file_path + obc_name.lower() + "_telemetry_buffer.h", obc_name, body_h, settings + ) + OutputTlmDataDefH_( + output_file_path + obc_name.lower() + "_telemetry_data_definitions.h", + obc_name, + tlmdef_body_h, + settings, + ) def OutputTlmBufferC_(file_path, name, body, settings): @@ -228,7 +308,7 @@ def OutputTlmBufferC_(file_path, name, body, settings): name_capit = name.capitalize() output = "" - output += ''' + output += """ #pragma section REPRO /** * @file @@ -240,16 +320,24 @@ def OutputTlmBufferC_(file_path, name, body, settings): #include "./{_obc_name_lower}_telemetry_buffer.h" #include // for memcpy -'''[1:] # 最初の改行を除く +"""[ + 1: + ] # 最初の改行を除く output += body - output += ''' + output += """ #pragma section -'''[1:] # 最初の改行を除く +"""[ + 1: + ] # 最初の改行を除く - with open(file_path, mode='w', encoding=settings['output_file_encoding']) as fh: - fh.write(output.format(_obc_name_upper=name_upper, _obc_name_lower=name_lower, _obc_name_capit=name_capit)) + with open(file_path, mode="w", encoding=settings["output_file_encoding"]) as fh: + fh.write( + output.format( + _obc_name_upper=name_upper, _obc_name_lower=name_lower, _obc_name_capit=name_capit + ) + ) def OutputTlmBufferH_(file_path, name, body, settings): @@ -258,7 +346,7 @@ def OutputTlmBufferH_(file_path, name, body, settings): name_capit = name.capitalize() output = "" - output += ''' + output += """ /** * @file * @brief テレメトリバッファー(テレメ中継) @@ -269,17 +357,25 @@ def OutputTlmBufferH_(file_path, name, body, settings): #include "./{_obc_name_lower}.h" -'''[1:] # 最初の改行を除く +"""[ + 1: + ] # 最初の改行を除く output += body - output += ''' + output += """ #endif -'''[1:] # 最初の改行を除く +"""[ + 1: + ] # 最初の改行を除く - with open(file_path, mode='w', encoding=settings['output_file_encoding']) as fh: - fh.write(output.format(_obc_name_upper=name_upper, _obc_name_lower=name_lower, _obc_name_capit=name_capit)) + with open(file_path, mode="w", encoding=settings["output_file_encoding"]) as fh: + fh.write( + output.format( + _obc_name_upper=name_upper, _obc_name_lower=name_lower, _obc_name_capit=name_capit + ) + ) def OutputTlmDataDefH_(file_path, name, body, settings): @@ -288,7 +384,7 @@ def OutputTlmDataDefH_(file_path, name, body, settings): name_capit = name.capitalize() output = "" - output += ''' + output += """ /** * @file * @brief バッファリングされているテレメをパースしてMOBC内でかんたんに利用できるようにするためのテレメデータ構造体定義 @@ -297,21 +393,30 @@ def OutputTlmDataDefH_(file_path, name, body, settings): #ifndef {_obc_name_upper}_TELEMETRY_DATA_DEFINITIONS_H_ #define {_obc_name_upper}_TELEMETRY_DATA_DEFINITIONS_H_ -'''[1:] # 最初の改行を除く +"""[ + 1: + ] # 最初の改行を除く output += body - output += ''' + output += """ #endif -'''[1:] # 最初の改行を除く +"""[ + 1: + ] # 最初の改行を除く - with open(file_path, mode='w', encoding=settings['output_file_encoding']) as fh: - fh.write(output.format(_obc_name_upper=name_upper, _obc_name_lower=name_lower, _obc_name_capit=name_capit)) + with open(file_path, mode="w", encoding=settings["output_file_encoding"]) as fh: + fh.write( + output.format( + _obc_name_upper=name_upper, _obc_name_lower=name_lower, _obc_name_capit=name_capit + ) + ) def GetStructTree_(dict, path, sep="/", default=None): path_list = path.split(sep) + def _(dict, path_list, sep, default): if len(path_list) == 0: return default @@ -319,18 +424,20 @@ def _(dict, path_list, sep, default): return dict.get(path_list[0], default) else: return _(dict.get(path_list[0], {}), path_list[1:], sep, default) + return _(dict, path_list, sep=sep, default=None) def SetStructTree_(dict, path, val, sep="/"): path_list = path.split(sep) + def _(dict, path_list, val, sep): if len(path_list) == 0: - return 1 # err + return 1 # err if len(path_list) == 1: key = path_list[0] if key in dict: - return 1 # 上書きエラー + return 1 # 上書きエラー else: dict[key] = val return 0 @@ -339,6 +446,7 @@ def _(dict, path_list, val, sep): if not key in dict: dict[key] = {} return _(dict[key], path_list[1:], val, sep) + return _(dict, path_list, val, sep=sep) @@ -349,11 +457,12 @@ def _(tree, name, indent): output += " " * (indent) + "{{\n" for k, v in tree.items(): if type(v) == dict: - output += _(v, k, indent+2) + output += _(v, k, indent + 2) continue - output += " " * (indent+2) + v + " " + k + ";\n" + output += " " * (indent + 2) + v + " " + k + ";\n" output += " " * (indent) + "}} " + name + ";\n" return output + return _(tree, name, 2) diff --git a/my_mod/tlm_def.py b/my_mod/tlm_def.py index 78f6ea610..6bc459915 100644 --- a/my_mod/tlm_def.py +++ b/my_mod/tlm_def.py @@ -3,9 +3,9 @@ tlm def """ -import os import sys + def GenerateTlmDef(settings, tlm_db, other_obc_dbs): output_file_path = settings["c2a_root_dir"] + r"src_user/TlmCmd/" output_file_name_base = "telemetry_definitions" @@ -18,8 +18,12 @@ def GenerateTlmDef(settings, tlm_db, other_obc_dbs): # "static int OBC_(unsigned char* contents, int max_len);" # " OBC_ID = 0x00," for tlm in tlm_db: - body_c += "static int Tlm_" + tlm['tlm_name'].upper() + "_(unsigned char* contents, int max_len);\n" - body_h += " Tlm_CODE_" + tlm['tlm_name'].upper() + " = " + tlm['tlm_id'] + ",\n" + body_c += ( + "static int Tlm_" + + tlm["tlm_name"].upper() + + "_(unsigned char* contents, int max_len);\n" + ) + body_h += " Tlm_CODE_" + tlm["tlm_name"].upper() + " = " + tlm["tlm_id"] + ",\n" if settings["is_main_obc"]: body_c += GetTlmDefCOfOtherObcFunDef_(settings, tlm_db, other_obc_dbs) @@ -29,7 +33,13 @@ def GenerateTlmDef(settings, tlm_db, other_obc_dbs): body_c += "{\n" for tlm in tlm_db: # " tlm_table[OBC_ID].tlm_func = OBC_;" - body_c += " tlm_table[Tlm_CODE_" + tlm['tlm_name'].upper() + "].tlm_func = Tlm_" + tlm['tlm_name'].upper() + "_;\n" + body_c += ( + " tlm_table[Tlm_CODE_" + + tlm["tlm_name"].upper() + + "].tlm_func = Tlm_" + + tlm["tlm_name"].upper() + + "_;\n" + ) if settings["is_main_obc"]: body_c += GetTlmDefCOfOtherObcFunLoad_(settings, tlm_db, other_obc_dbs) body_c += "}\n" @@ -37,13 +47,13 @@ def GenerateTlmDef(settings, tlm_db, other_obc_dbs): for tlm in tlm_db: func_code = "" max_pos = "" - for i in range(DATA_START_ROW, len(tlm['data'])): - comment = tlm['data'][i][0] - name = tlm['data'][i][1] - var_type = tlm['data'][i][2] - code = tlm['data'][i][3] - pos = tlm['data'][i][5] - if comment == "" and name == "": # CommentもNameも空白なら打ち切り + for i in range(DATA_START_ROW, len(tlm["data"])): + comment = tlm["data"][i][0] + name = tlm["data"][i][1] + var_type = tlm["data"][i][2] + code = tlm["data"][i][3] + pos = tlm["data"][i][5] + if comment == "" and name == "": # CommentもNameも空白なら打ち切り break if comment != "": continue @@ -56,10 +66,10 @@ def GenerateTlmDef(settings, tlm_db, other_obc_dbs): if pos == "": continue - pos = int(pos) - settings['header_len'] + pos = int(pos) - settings["header_len"] code = code.replace("@@", ",") func_code += " " - if var_type == "int8_t": + if var_type == "int8_t": func_code += "TF_copy_i8" max_pos = pos + 1 elif var_type == "int16_t": @@ -84,16 +94,20 @@ def GenerateTlmDef(settings, tlm_db, other_obc_dbs): func_code += "TF_copy_double" max_pos = pos + 8 else: - print("Error: Tlm DB Err at " + tlm['tlm_name'].upper(), file=sys.stderr) + print("Error: Tlm DB Err at " + tlm["tlm_name"].upper(), file=sys.stderr) sys.exit(1) func_code += "(&contents[" + str(pos) + "], " + code + ");\n" body_c += "\n" - body_c += "static int Tlm_" + tlm['tlm_name'].upper() + "_(unsigned char* contents, int max_len)\n" + body_c += ( + "static int Tlm_" + + tlm["tlm_name"].upper() + + "_(unsigned char* contents, int max_len)\n" + ) body_c += "{\n" - for local_var in tlm['local_vars']: + for local_var in tlm["local_vars"]: body_c += " " + local_var + "\n" - if len(tlm['local_vars']) > 0: + if len(tlm["local_vars"]) > 0: body_c += "\n" body_c += " if (" + str(max_pos) + " > max_len) return TF_TOO_SHORT_LEN;\n" body_c += "\n" @@ -126,9 +140,17 @@ def GetTlmDefCOfOtherObcFunDef_(settings, tlm_db, other_obc_dbs): temp_c += "\n" temp_c += "// {_obc_name_upper} TLM\n" for tlm in oter_obc_tlm_db: - temp_c += "static int Tlm_" + tlm['tlm_name'].upper() + "_(unsigned char* contents, int max_len);\n" - - body_c += temp_c.format(_obc_name_upper=obc_name.upper(), _obc_name_lower=obc_name.lower(), _obc_name_capit=obc_name.capitalize()) + temp_c += ( + "static int Tlm_" + + tlm["tlm_name"].upper() + + "_(unsigned char* contents, int max_len);\n" + ) + + body_c += temp_c.format( + _obc_name_upper=obc_name.upper(), + _obc_name_lower=obc_name.lower(), + _obc_name_capit=obc_name.capitalize(), + ) return body_c @@ -147,8 +169,18 @@ def GetTlmDefCOfOtherObcFunLoad_(settings, tlm_db, other_obc_dbs): temp_c += "\n" temp_c += " // {_obc_name_upper} TLM\n" for tlm in oter_obc_tlm_db: - temp_c += " tlm_table[Tlm_CODE_" + tlm['tlm_name'].upper() + "].tlm_func = Tlm_" + tlm['tlm_name'].upper() + "_;\n" - body_c += temp_c.format(_obc_name_upper=obc_name.upper(), _obc_name_lower=obc_name.lower(), _obc_name_capit=obc_name.capitalize()) + temp_c += ( + " tlm_table[Tlm_CODE_" + + tlm["tlm_name"].upper() + + "].tlm_func = Tlm_" + + tlm["tlm_name"].upper() + + "_;\n" + ) + body_c += temp_c.format( + _obc_name_upper=obc_name.upper(), + _obc_name_lower=obc_name.lower(), + _obc_name_capit=obc_name.capitalize(), + ) return body_c @@ -165,22 +197,32 @@ def GetTlmDefCOfOtherObcFunBody_(settings, tlm_db, other_obc_dbs): temp_c = "" for tlm in oter_obc_tlm_db: - tlm_name = tlm['tlm_name'] + tlm_name = tlm["tlm_name"] tlm_name_upper = tlm_name.upper() tlm_name_lower = tlm_name.lower() temp_c += "\n" - temp_c += "static int Tlm_" + tlm_name_upper + "_(unsigned char* contents, int max_len)\n" + temp_c += ( + "static int Tlm_" + tlm_name_upper + "_(unsigned char* contents, int max_len)\n" + ) temp_c += "{{\n" temp_c += " int buffer_size = {_obc_name_lower}_buffer->" + tlm_name_lower + ".size;\n" temp_c += "\n" temp_c += " if (buffer_size > max_len) {{ return TF_TOO_SHORT_LEN; }}\n" temp_c += "\n" - temp_c += " memcpy(contents, {_obc_name_lower}_buffer->" + tlm_name_lower + ".buffer, (size_t)buffer_size);\n" + temp_c += ( + " memcpy(contents, {_obc_name_lower}_buffer->" + + tlm_name_lower + + ".buffer, (size_t)buffer_size);\n" + ) temp_c += "\n" temp_c += " return buffer_size;\n" temp_c += "}}\n" - body_c += temp_c.format(_obc_name_upper=obc_name.upper(), _obc_name_lower=obc_name.lower(), _obc_name_capit=obc_name.capitalize()) + body_c += temp_c.format( + _obc_name_upper=obc_name.upper(), + _obc_name_lower=obc_name.lower(), + _obc_name_capit=obc_name.capitalize(), + ) return body_c @@ -197,29 +239,38 @@ def GetTlmDefHOfOtherObc_(settings, tlm_db, other_obc_dbs): temp_h = "" id_begin = int(settings["other_obc_data"][i]["tlm_id_range"][0], 0) - id_end = int(settings["other_obc_data"][i]["tlm_id_range"][1], 0) + id_end = int(settings["other_obc_data"][i]["tlm_id_range"][1], 0) # MOBC Tlmが範囲外かチェック for tlm in tlm_db: - tlm_id = int(tlm['tlm_id'], 0) + tlm_id = int(tlm["tlm_id"], 0) if id_begin <= tlm_id < id_end: - print("Error: MOBC TLM ID is invalid at " + tlm['tlm_name'].upper(), file=sys.stderr) + print( + "Error: MOBC TLM ID is invalid at " + tlm["tlm_name"].upper(), file=sys.stderr + ) sys.exit(1) oter_obc_tlm_db = other_obc_dbs[obc_name] # ID範囲内チェック for tlm in oter_obc_tlm_db: - tlm_id = int(tlm['tlm_id'], 0) + tlm_id = int(tlm["tlm_id"], 0) if not id_begin <= tlm_id < id_end: - print("Error: " + obc_name + " TLM ID is invalid at " + tlm['tlm_name'].upper(), file=sys.stderr) + print( + "Error: " + obc_name + " TLM ID is invalid at " + tlm["tlm_name"].upper(), + file=sys.stderr, + ) sys.exit(1) body_h += "\n" temp_h += " // {_obc_name_upper} TLM\n" for tlm in oter_obc_tlm_db: - temp_h += " Tlm_CODE_" + tlm['tlm_name'].upper() + " = " + tlm['tlm_id'] + ",\n" + temp_h += " Tlm_CODE_" + tlm["tlm_name"].upper() + " = " + tlm["tlm_id"] + ",\n" - body_h += temp_h.format(_obc_name_upper=obc_name.upper(), _obc_name_lower=obc_name.lower(), _obc_name_capit=obc_name.capitalize()) + body_h += temp_h.format( + _obc_name_upper=obc_name.upper(), + _obc_name_lower=obc_name.lower(), + _obc_name_capit=obc_name.capitalize(), + ) body_h += "\n" body_h += " // FIXME:\n" @@ -240,15 +291,26 @@ def GenerateOtherObcTlmDef(settings, other_obc_dbs): body_h = "" # " TOBC_Tlm_CODE_HK = 0xf0," for tlm in tlm_db: - body_h += " {_obc_name_upper}_Tlm_CODE_" + tlm['tlm_name'].upper() + " = " + tlm['tlm_id'] + ",\n" - output_file_path = settings["c2a_root_dir"] + r"src_user/Drivers/" + settings["other_obc_data"][i]["driver_path"] + obc_name.lower() + "_telemetry_definitions.h" + body_h += ( + " {_obc_name_upper}_Tlm_CODE_" + + tlm["tlm_name"].upper() + + " = " + + tlm["tlm_id"] + + ",\n" + ) + output_file_path = ( + settings["c2a_root_dir"] + + r"src_user/Drivers/" + + settings["other_obc_data"][i]["driver_path"] + + obc_name.lower() + + "_telemetry_definitions.h" + ) OutputOtherObcTlmDefH(output_file_path, obc_name, body_h, settings) - def OutputTlmDefC_(file_path, body, settings): output = "" - output += ''' + output += """ #pragma section REPRO /** * @file @@ -259,22 +321,26 @@ def OutputTlmDefC_(file_path, body, settings): #include "telemetry_definitions.h" #include "telemetry_source.h" -'''[1:] # 最初の改行を除く +"""[ + 1: + ] # 最初の改行を除く output += body - output += ''' + output += """ #pragma section -'''[1:] # 最初の改行を除く +"""[ + 1: + ] # 最初の改行を除く - with open(file_path, mode='w', encoding=settings['output_file_encoding']) as fh: + with open(file_path, mode="w", encoding=settings["output_file_encoding"]) as fh: fh.write(output) def OutputTlmDefH_(file_path, body, settings): output = "" - output += ''' + output += """ /** * @file * @brief テレメトリ定義 @@ -285,19 +351,23 @@ def OutputTlmDefH_(file_path, body, settings): typedef enum { -'''[1:] # 最初の改行を除く +"""[ + 1: + ] # 最初の改行を除く output += body - output += ''' + output += """ TLM_CODE_MAX } TLM_CODE; #endif -'''[1:] # 最初の改行を除く +"""[ + 1: + ] # 最初の改行を除く - with open(file_path, mode='w', encoding=settings['output_file_encoding']) as fh: + with open(file_path, mode="w", encoding=settings["output_file_encoding"]) as fh: fh.write(output) @@ -307,7 +377,7 @@ def OutputOtherObcTlmDefH(file_path, name, body, settings): name_capit = name.capitalize() output = "" - output += ''' + output += """ /** * @file * @brief テレメトリ定義 @@ -318,18 +388,25 @@ def OutputOtherObcTlmDefH(file_path, name, body, settings): typedef enum {{ -'''[1:] # 最初の改行を除く +"""[ + 1: + ] # 最初の改行を除く output += body - output += ''' + output += """ {_obc_name_upper}_TLM_CODE_MAX }} {_obc_name_upper}_TLM_CODE; #endif -'''[1:] # 最初の改行を除く - - with open(file_path, mode='w', encoding=settings['output_file_encoding']) as fh: - fh.write(output.format(_obc_name_upper=name_upper, _obc_name_lower=name_lower, _obc_name_capit=name_capit)) - +"""[ + 1: + ] # 最初の改行を除く + + with open(file_path, mode="w", encoding=settings["output_file_encoding"]) as fh: + fh.write( + output.format( + _obc_name_upper=name_upper, _obc_name_lower=name_lower, _obc_name_capit=name_capit + ) + ) From a4cd9878306679c24d5010c4ef59b42471cb1c4e Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Thu, 20 Jan 2022 00:49:49 +0900 Subject: [PATCH 097/141] fix E713 --- my_mod/tlm_buffer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index 502f32a48..895549ddf 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -443,7 +443,7 @@ def _(dict, path_list, val, sep): return 0 else: key = path_list[0] - if not key in dict: + if key not in dict: dict[key] = {} return _(dict[key], path_list[1:], val, sep) From 5191b7c07fa7a6f1b628233fde77aa23e6b6dc88 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sat, 22 Jan 2022 00:34:36 +0900 Subject: [PATCH 098/141] add E501 to ignore for flake8 --- .flake8 | 1 + 1 file changed, 1 insertion(+) diff --git a/.flake8 b/.flake8 index f12eee9c0..1d1919b57 100644 --- a/.flake8 +++ b/.flake8 @@ -3,5 +3,6 @@ max-line-length = 100 ignore = # black と競合するので E203, + E501, W503, W504 From d0a874cd7cd29a63478cce2f57c9075071af0e67 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sat, 22 Jan 2022 00:38:01 +0900 Subject: [PATCH 099/141] fix F841 --- my_mod/cmd_def.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/my_mod/cmd_def.py b/my_mod/cmd_def.py index 7c4a99767..e3022ab4c 100644 --- a/my_mod/cmd_def.py +++ b/my_mod/cmd_def.py @@ -143,7 +143,7 @@ def GenerateOtherObcCmdDef(settings, other_obc_dbs): obc_name = settings["other_obc_data"][i]["name"] name_upper = obc_name.upper() name_lower = obc_name.lower() - name_capit = obc_name.capitalize() + # name_capit = obc_name.capitalize() # print(name_upper) # print(name_lower) # print(name_capit) From 7f5c63696f4ef066ee66355dc986281822af1556 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 1 Feb 2022 14:23:03 +0900 Subject: [PATCH 100/141] fix disable flag check --- my_mod/load_db.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/my_mod/load_db.py b/my_mod/load_db.py index 0d3827f6a..9b279595c 100644 --- a/my_mod/load_db.py +++ b/my_mod/load_db.py @@ -74,6 +74,9 @@ def LoadTlmCSV_(tlm_db_path, db_prefix, tlm_id_range): sheet = [row for row in reader] # pprint.pprint(sheet) # print(sheet) + enable_flag = sheet[2][2] # FIXME: Enable/Disable を取得.マジックナンバーで指定してしまってる. + if enable_flag != "ENABLE": + continue tlm_id = sheet[1][2] # FIXME: テレメIDを取得.マジックナンバーで指定してしまってる. if not int(tlm_id_range[0], 0) <= int(tlm_id, 0) < int(tlm_id_range[1], 0): print( @@ -81,9 +84,6 @@ def LoadTlmCSV_(tlm_db_path, db_prefix, tlm_id_range): file=sys.stderr, ) sys.exit(1) - enable_flag = sheet[2][2] # FIXME: Enable/Disable を取得.マジックナンバーで指定してしまってる. - if enable_flag != "ENABLE": - continue raw_local_vars = ( sheet[1][3].replace("%%", "").split("##") ) # FIXME: ローカル変数を取得.マジックナンバーで指定してしまってる. From da0c32894e1fdea7e17b3d5ea3647a6d14bbad34 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 1 Feb 2022 03:20:45 +0900 Subject: [PATCH 101/141] update for space packet and new c2a comm --- my_mod/tlm_buffer.py | 142 +++++++++++++++++++++++++++++-------------- my_mod/tlm_def.py | 17 +++--- 2 files changed, 103 insertions(+), 56 deletions(-) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index 895549ddf..e5a2ed1c6 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -18,7 +18,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): obc_name = settings["other_obc_data"][i]["name"] driver_type = settings["other_obc_data"][i]["driver_type"] driver_name = settings["other_obc_data"][i]["driver_name"] - contents_len = settings["other_obc_data"][i]["tlm_max_contents_len"] + max_tlms = settings["other_obc_data"][i]["max_tlms"] tlm_db = other_obc_dbs[obc_name] @@ -26,33 +26,39 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_h = "" tlmdef_body_h = "" - body_c += "static {_obc_name_upper}_Buffer {_obc_name_lower}_buffer_;\n" - body_c += "const {_obc_name_upper}_Buffer* const {_obc_name_lower}_buffer = &{_obc_name_lower}_buffer_;\n" - body_c += "\n" - body_h += "#define {_obc_name_upper}_TELEMETRY_BUFFE_SIZE (" + str(contents_len) + ")\n" - body_h += "\n" - body_h += "typedef struct\n" - body_h += "{{\n" for tlm in tlm_db: tlm_name = tlm["tlm_name"] tlm_name_lower = tlm_name.lower() - body_h += " struct\n" - body_h += " {{\n" - body_h += " int size;\n" - body_h += " uint8_t buffer[{_obc_name_upper}_TELEMETRY_BUFFE_SIZE];\n" - body_h += " }} " + tlm_name_lower + ";\n" body_c += ( "static DS_ERR_CODE {_obc_name_upper}_analyze_tlm_" + tlm_name_lower - + "_(DS_StreamConfig* p_stream_config, " + + "_(const CommonTlmPacket* packet, {_obc_name_upper}_TLM_CODE tlm_id, " + driver_type + "* " + driver_name + ");\n" ) - body_h += "}} {_obc_name_upper}_Buffer;\n" + body_c += "\n" + body_c += "static CommonTlmPacket {_obc_name_upper}_ctp_;\n" + body_c += "\n" + + body_h += "typedef struct " + driver_type + " " + driver_type + ";\n" + body_h += "\n" + body_h += "#define {_obc_name_upper}_MAX_TLMS (" + str(max_tlms) + ")\n" body_h += "\n" + body_h += "typedef struct\n" + body_h += "{{\n" + body_h += " CommonTlmPacket packet; //!< 最新のテレメパケットを保持\n" + body_h += " uint8_t is_null_packet; //!< 一度でもテレメを受信しているか?(空配列が読み出されるのを防ぐため)\n" + body_h += "}} {_obc_name_upper}_TlmBufferElem;\n" + body_h += "\n" + body_h += "typedef struct\n" + body_h += "{{\n" + body_h += " {_obc_name_upper}_TlmBufferElem tlm[{_obc_name_upper}_MAX_TLMS]; //!< TLM ID ごとに保持\n" + body_h += "}} {_obc_name_upper}_TlmBuffer;\n" + body_h += "\n" + tlmdef_body_h += "typedef struct\n" tlmdef_body_h += "{{\n" for tlm in tlm_db: @@ -96,29 +102,41 @@ def GenerateTlmBuffer(settings, other_obc_dbs): tlmdef_body_h += "}} {_obc_name_upper}_TlmData;\n" - body_h += "extern const {_obc_name_upper}_Buffer* const {_obc_name_lower}_buffer;\n" - body_h += "\n" - body_h += "void {_obc_name_upper}_buffer_init(void);\n" + body_h += ( + "void {_obc_name_upper}_init_tlm_buffer(" + driver_type + "* " + driver_name + ");\n" + ) body_h += "\n" body_h += ( - "DS_ERR_CODE {_obc_name_upper}_buffer_tlm_contents(DS_StreamConfig* p_stream_config, " + "DS_ERR_CODE {_obc_name_upper}_buffer_tlm_packet(DS_StreamConfig* p_stream_config, " + driver_type + "* " + driver_name + ");\n" ) + body_h += "\n" + body_h += "// FIXME: TF_ACK になおす!\n" + body_h += ( + "int {_obc_name_upper}_pick_up_tlm_buffer(const " + + driver_type + + "* " + + driver_name + + ", {_obc_name_upper}_TLM_CODE tlm_id, uint8_t* packet, int max_len);\n" + ) - body_c += "\n" - body_c += "void {_obc_name_upper}_buffer_init(void)\n" + body_c += ( + "void {_obc_name_upper}_init_tlm_buffer(" + driver_type + "* " + driver_name + ")\n" + ) body_c += "{{\n" - for tlm in tlm_db: - tlm_name = tlm["tlm_name"] - tlm_name_lower = tlm_name.lower() - body_c += " {_obc_name_lower}_buffer_." + tlm_name_lower + ".size = 0;\n" + body_c += " // packet などは,上位の driver の初期化で driver もろとも memset 0x00 されていると期待して,ここではしない\n" + body_c += " int i = 0;\n" + body_c += " for (i = 0; i < {_obc_name_upper}_MAX_TLMS; ++i)\n" + body_c += " {{\n" + body_c += " " + driver_name + "->tlm_buffer.tlm[i].is_null_packet = 1;\n" + body_c += " }}\n" body_c += "}}\n" body_c += "\n" body_c += ( - "DS_ERR_CODE {_obc_name_upper}_buffer_tlm_contents(DS_StreamConfig* p_stream_config, " + "DS_ERR_CODE {_obc_name_upper}_buffer_tlm_packet(DS_StreamConfig* p_stream_config, " + driver_type + "* " + driver_name @@ -126,7 +144,10 @@ def GenerateTlmBuffer(settings, other_obc_dbs): ) body_c += "{{\n" - body_c += " uint8_t tlm_id = DS_C2AFMT_get_tlm_id(p_stream_config);\n" + body_c += " {_obc_name_upper}_TLM_CODE tlm_id;\n" + body_c += "\n" + body_c += " DS_C2AFMT_get_ctp(p_stream_config, &{_obc_name_upper}_ctp_);\n" + body_c += " tlm_id = ({_obc_name_upper}_TLM_CODE)CTP_get_id(&{_obc_name_upper}_ctp_);\n" body_c += "\n" body_c += " switch (tlm_id)\n" @@ -139,7 +160,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += ( " return {_obc_name_upper}_analyze_tlm_" + tlm_name_lower - + "_(p_stream_config, " + + "_(&{_obc_name_upper}_ctp_, tlm_id, " + driver_name + ");\n" ) @@ -173,20 +194,18 @@ def GenerateTlmBuffer(settings, other_obc_dbs): tlm_name = tlm["tlm_name"] tlm_name_upper = tlm_name.upper() tlm_name_lower = tlm_name.lower() + body_c += ( "static DS_ERR_CODE {_obc_name_upper}_analyze_tlm_" + tlm_name_lower - + "_(DS_StreamConfig* p_stream_config, " + + "_(const CommonTlmPacket* packet, {_obc_name_upper}_TLM_CODE tlm_id, " + driver_type + "* " + driver_name + ")\n" ) body_c += "{{\n" - body_c += " uint32_t tlm_len = DS_ISSLFMT_get_tlm_length(p_stream_config);\n" - body_c += " const uint8_t* f = DSSC_get_rx_frame(p_stream_config) + DS_ISSLFMT_COMMON_HEADER_SIZE;\n" - body_c += " uint32_t contents_len = tlm_len - DS_C2AFMT_TCP_TLM_SECONDARY_HEADER_SIZE - 1; // FIXME: CCSDSは1起算?\n" - body_c += " const uint8_t* contents_pos = f + DS_C2AFMT_TCP_TLM_PRIMARY_HEADER_SIZE + DS_C2AFMT_TCP_TLM_SECONDARY_HEADER_SIZE;\n" + body_c += " const uint8_t* f = packet->packet;\n" for k, v in conv_tpye_to_temp.items(): if k == "float": body_c += " " + k + " " + v + " = 0.0f;\n" @@ -195,18 +214,17 @@ def GenerateTlmBuffer(settings, other_obc_dbs): else: body_c += " " + k + " " + v + " = 0;\n" body_c += "\n" - body_c += " // GSへのテレメ中継のためのバッファーへのコピー\n" - body_c += " if (contents_len > {_obc_name_upper}_TELEMETRY_BUFFE_SIZE) return DS_ERR_CODE_ERR;\n" - body_c += ( - " memcpy({_obc_name_lower}_buffer_." - + tlm_name_lower - + ".buffer, contents_pos, (size_t)contents_len);\n" - ) + body_c += " // GS へのテレメ中継のためのバッファーへのコピー\n" body_c += ( - " {_obc_name_lower}_buffer_." + tlm_name_lower + ".size = (int)contents_len;\n" + " CTP_copy_packet(&(" + + driver_name + + "->tlm_buffer.tlm[tlm_id].packet), packet);\n" ) + body_c += " " + driver_name + "->tlm_buffer.tlm[tlm_id].is_null_packet = 0;\n" + body_c += " // TODO: CRC チェック\n" body_c += "\n" - body_c += " // MOBC内部でテレメデータへアクセスしやすいようにするための構造体へのパース\n" + + body_c += " // MOBC 内部でテレメデータへアクセスしやすいようにするための構造体へのパース\n" last_var_type = "" for j in range(DATA_START_ROW, len(tlm["data"])): comment = tlm["data"][j][0] @@ -252,7 +270,11 @@ def GenerateTlmBuffer(settings, other_obc_dbs): + ");\n" ) body_c += ( - " " + conv_tpye_to_temp[var_type] + " >>= " + str(7 - bit_pos) + ";\n" + " " + + conv_tpye_to_temp[var_type] + + " >>= " + + str(conv_tpye_to_size[var_type] * 8 - bit_pos - bit_len) + + ";\n" ) body_c += ( " " @@ -283,6 +305,31 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += "}}\n" body_c += "\n" + body_c += ( + "int {_obc_name_upper}_pick_up_tlm_buffer(const " + + driver_type + + "* " + + driver_name + + ", {_obc_name_upper}_TLM_CODE tlm_id, uint8_t* packet, int max_len)\n" + ) + body_c += "{{\n" + body_c += " const CommonTlmPacket* buffered_packet;\n" + body_c += "\n" + body_c += " if (tlm_id >= {_obc_name_upper}_MAX_TLMS) return TF_NOT_DEFINED;\n" + body_c += ( + " if (" + + driver_name + + "->tlm_buffer.tlm[tlm_id].is_null_packet) return TF_NULL_PACKET;\n" + ) + body_c += "\n" + body_c += " buffered_packet = &(" + driver_name + "->tlm_buffer.tlm[tlm_id].packet);\n" + body_c += "\n" + body_c += " if (CTP_get_packet_len(buffered_packet) > max_len) return TF_TOO_SHORT_LEN;\n" + body_c += "\n" + body_c += " memcpy(packet, &buffered_packet->packet, (size_t)CTP_get_packet_len(buffered_packet));\n" + body_c += "}}\n" + body_c += "\n" + output_file_path = ( settings["c2a_root_dir"] + r"src_user/Drivers/" @@ -315,10 +362,10 @@ def OutputTlmBufferC_(file_path, name, body, settings): * @brief テレメトリバッファー(テレメ中継) * @note このコードは自動生成されています! */ - #include "./{_obc_name_lower}_telemetry_definitions.h" #include "./{_obc_name_lower}_telemetry_buffer.h" -#include // for memcpy +#include "./{_obc_name_lower}.h" +#include """[ 1: @@ -355,7 +402,10 @@ def OutputTlmBufferH_(file_path, name, body, settings): #ifndef {_obc_name_upper}_TELEMETRY_BUFFER_H_ #define {_obc_name_upper}_TELEMETRY_BUFFER_H_ -#include "./{_obc_name_lower}.h" +#include "./{_obc_name_lower}_telemetry_definitions.h" +#include +#include +#include """[ 1: diff --git a/my_mod/tlm_def.py b/my_mod/tlm_def.py index 6bc459915..7da66a686 100644 --- a/my_mod/tlm_def.py +++ b/my_mod/tlm_def.py @@ -194,28 +194,25 @@ def GetTlmDefCOfOtherObcFunBody_(settings, tlm_db, other_obc_dbs): obc_name = settings["other_obc_data"][i]["name"] oter_obc_tlm_db = other_obc_dbs[obc_name] + driver_name = settings["other_obc_data"][i]["driver_name"] temp_c = "" for tlm in oter_obc_tlm_db: tlm_name = tlm["tlm_name"] tlm_name_upper = tlm_name.upper() - tlm_name_lower = tlm_name.lower() + # tlm_name_lower = tlm_name.lower() temp_c += "\n" temp_c += ( "static int Tlm_" + tlm_name_upper + "_(unsigned char* contents, int max_len)\n" ) temp_c += "{{\n" - temp_c += " int buffer_size = {_obc_name_lower}_buffer->" + tlm_name_lower + ".size;\n" - temp_c += "\n" - temp_c += " if (buffer_size > max_len) {{ return TF_TOO_SHORT_LEN; }}\n" - temp_c += "\n" temp_c += ( - " memcpy(contents, {_obc_name_lower}_buffer->" - + tlm_name_lower - + ".buffer, (size_t)buffer_size);\n" + " return AOBC_pick_up_tlm_buffer(" + + driver_name + + ", {_obc_name_upper}_Tlm_CODE_" + + tlm_name_upper + + ", contents, max_len);\n" ) - temp_c += "\n" - temp_c += " return buffer_size;\n" temp_c += "}}\n" body_c += temp_c.format( From 914d6572b68742b3b3294f6ad7ed7b4d7f482daa Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 1 Feb 2022 03:22:37 +0900 Subject: [PATCH 102/141] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d842d85e2..039bf0698 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ $ python GenerateC2ACode.py # 出力ファイルのエンコーディング "output_file_encoding" : "utf-8", # テレメパケットのヘッダ長.これをoffsetしたところから,C2A上のテレメのユーザー定義部 - "header_len" : 13, + "header_len" : 26, # MOBCか?(他のOBCのtlm/cmdを取りまとめるか?) 0/1 # 2nd OBCのコードを生成するときなどは 0 にする # 0 の場合,以後のパラメタは無効 @@ -51,7 +51,7 @@ $ python GenerateC2ACode.py "tlm_id_range" : ["0x90", "0xc0"], # DBがあるディレクトリへのパス(絶対でも相対でもOK) "db_path" : "../../c2a_sample_aobc/src/src_user/Settings/TlmCmd/DataBase/", - "tlm_max_contents_len" : 512, + "max_tlms" : 256, "driver_path" : "Aocs/", "driver_type" : "AOBC_Driver", "driver_name" : "aobc", @@ -66,7 +66,7 @@ $ python GenerateC2ACode.py "tlm_id_range" : ["0xc0", "0xf0"], # DBがあるディレクトリへのパス(絶対でも相対でもOK) "db_path" : ""../../c2a_sample_tobc/src/src_user/Settings/TlmCmd/DataBase/", - "tlm_max_contents_len" : 512, + "max_tlms" : 256, "driver_path" : "Thermal/", "driver_type" : "TOBC_Driver", "driver_name" : "tobc", From f4541332edef395d65c70ae70a86e09196cd224d Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 1 Feb 2022 03:47:29 +0900 Subject: [PATCH 103/141] fix small --- my_mod/tlm_buffer.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index e5a2ed1c6..7d65ebdda 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -314,6 +314,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): ) body_c += "{{\n" body_c += " const CommonTlmPacket* buffered_packet;\n" + body_c += " uint16_t packet_len;\n" body_c += "\n" body_c += " if (tlm_id >= {_obc_name_upper}_MAX_TLMS) return TF_NOT_DEFINED;\n" body_c += ( @@ -323,10 +324,12 @@ def GenerateTlmBuffer(settings, other_obc_dbs): ) body_c += "\n" body_c += " buffered_packet = &(" + driver_name + "->tlm_buffer.tlm[tlm_id].packet);\n" + body_c += " packet_len = CTP_get_packet_len(buffered_packet);\n" body_c += "\n" - body_c += " if (CTP_get_packet_len(buffered_packet) > max_len) return TF_TOO_SHORT_LEN;\n" + body_c += " if (packet_len > max_len) return TF_TOO_SHORT_LEN;\n" body_c += "\n" - body_c += " memcpy(packet, &buffered_packet->packet, (size_t)CTP_get_packet_len(buffered_packet));\n" + body_c += " memcpy(packet, &buffered_packet->packet, (size_t)packet_len);\n" + body_c += " return packet_len;\n" body_c += "}}\n" body_c += "\n" From 39737242d4b31cb814a214bd76a5ecf4b2286c44 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 1 Feb 2022 04:02:22 +0900 Subject: [PATCH 104/141] update for include header to tlm contents --- my_mod/tlm_def.py | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/my_mod/tlm_def.py b/my_mod/tlm_def.py index 7da66a686..105d76ec8 100644 --- a/my_mod/tlm_def.py +++ b/my_mod/tlm_def.py @@ -15,14 +15,10 @@ def GenerateTlmDef(settings, tlm_db, other_obc_dbs): body_c = "" body_h = "" - # "static int OBC_(unsigned char* contents, int max_len);" + # "static int OBC_(uint8_t* packet, int max_len);" # " OBC_ID = 0x00," for tlm in tlm_db: - body_c += ( - "static int Tlm_" - + tlm["tlm_name"].upper() - + "_(unsigned char* contents, int max_len);\n" - ) + body_c += "static int Tlm_" + tlm["tlm_name"].upper() + "_(uint8_t* packet, int max_len);\n" body_h += " Tlm_CODE_" + tlm["tlm_name"].upper() + " = " + tlm["tlm_id"] + ",\n" if settings["is_main_obc"]: @@ -66,7 +62,7 @@ def GenerateTlmDef(settings, tlm_db, other_obc_dbs): if pos == "": continue - pos = int(pos) - settings["header_len"] + pos = int(pos) code = code.replace("@@", ",") func_code += " " if var_type == "int8_t": @@ -96,14 +92,10 @@ def GenerateTlmDef(settings, tlm_db, other_obc_dbs): else: print("Error: Tlm DB Err at " + tlm["tlm_name"].upper(), file=sys.stderr) sys.exit(1) - func_code += "(&contents[" + str(pos) + "], " + code + ");\n" + func_code += "(&packet[" + str(pos) + "], " + code + ");\n" body_c += "\n" - body_c += ( - "static int Tlm_" - + tlm["tlm_name"].upper() - + "_(unsigned char* contents, int max_len)\n" - ) + body_c += "static int Tlm_" + tlm["tlm_name"].upper() + "_(uint8_t* packet, int max_len)\n" body_c += "{\n" for local_var in tlm["local_vars"]: body_c += " " + local_var + "\n" @@ -141,9 +133,7 @@ def GetTlmDefCOfOtherObcFunDef_(settings, tlm_db, other_obc_dbs): temp_c += "// {_obc_name_upper} TLM\n" for tlm in oter_obc_tlm_db: temp_c += ( - "static int Tlm_" - + tlm["tlm_name"].upper() - + "_(unsigned char* contents, int max_len);\n" + "static int Tlm_" + tlm["tlm_name"].upper() + "_(uint8_t* packet, int max_len);\n" ) body_c += temp_c.format( @@ -202,16 +192,14 @@ def GetTlmDefCOfOtherObcFunBody_(settings, tlm_db, other_obc_dbs): tlm_name_upper = tlm_name.upper() # tlm_name_lower = tlm_name.lower() temp_c += "\n" - temp_c += ( - "static int Tlm_" + tlm_name_upper + "_(unsigned char* contents, int max_len)\n" - ) + temp_c += "static int Tlm_" + tlm_name_upper + "_(uint8_t* packet, int max_len)\n" temp_c += "{{\n" temp_c += ( - " return AOBC_pick_up_tlm_buffer(" + " return {_obc_name_upper}_pick_up_tlm_buffer(" + driver_name + ", {_obc_name_upper}_Tlm_CODE_" + tlm_name_upper - + ", contents, max_len);\n" + + ", packet, max_len);\n" ) temp_c += "}}\n" From 9794478ba1c797a2b3d4cd101882f9d7c3a45afc Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 1 Feb 2022 04:02:38 +0900 Subject: [PATCH 105/141] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 039bf0698..8ca102e8f 100644 --- a/README.md +++ b/README.md @@ -35,8 +35,6 @@ $ python GenerateC2ACode.py "tlm_id_range" : ["0x00", "0x100"], # 出力ファイルのエンコーディング "output_file_encoding" : "utf-8", - # テレメパケットのヘッダ長.これをoffsetしたところから,C2A上のテレメのユーザー定義部 - "header_len" : 26, # MOBCか?(他のOBCのtlm/cmdを取りまとめるか?) 0/1 # 2nd OBCのコードを生成するときなどは 0 にする # 0 の場合,以後のパラメタは無効 From 644ae284f3bd62596a9a10e482685237a33cd1f9 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 1 Feb 2022 04:05:32 +0900 Subject: [PATCH 106/141] Update settings.json --- settings.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/settings.json b/settings.json index 6f7ab05f0..3e83da0b9 100644 --- a/settings.json +++ b/settings.json @@ -3,7 +3,6 @@ "db_prefix" : "SAMPLE_MOBC", "tlm_id_range" : ["0x00", "0x100"], "output_file_encoding" : "utf-8", - "header_len" : 13, "is_main_obc" : 1, "other_obc_data" : [ { @@ -12,7 +11,7 @@ "db_prefix" : "SAMPLE_AOBC", "tlm_id_range" : ["0x90", "0xc0"], "db_path" : "C:/c2a_sample_aobc/src/src_user/Settings/TlmCmd/DataBase/", - "tlm_max_contents_len" : 512, + "max_tlms" : 256, "driver_path" : "Aocs/", "driver_type" : "AOBC_Driver", "driver_name" : "aobc_driver", @@ -24,7 +23,7 @@ "db_prefix" : "SAMPLE_TOBC", "tlm_id_range" : ["0xc0", "0xf0"], "db_path" : "C:/c2a_sample_tobc/src/src_user/Settings/TlmCmd/DataBase/", - "tlm_max_contents_len" : 512, + "max_tlms" : 256, "driver_path" : "Thermal/", "driver_type" : "TOBC_Driver", "driver_name" : "tobc_driver", From b2cb882186812141e78dd232b38eb7754844ef12 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Wed, 2 Feb 2022 01:35:42 +0900 Subject: [PATCH 107/141] add validation --- my_mod/tlm_buffer.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index 7d65ebdda..d852e11bc 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -145,8 +145,11 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += "{{\n" body_c += " {_obc_name_upper}_TLM_CODE tlm_id;\n" + body_c += " DS_ERR_CODE ret;\n" + body_c += "\n" + body_c += " ret = DS_C2AFMT_get_ctp(p_stream_config, &{_obc_name_upper}_ctp_);\n" + body_c += " if (ret != DS_ERR_CODE_OK) return ret;\n" body_c += "\n" - body_c += " DS_C2AFMT_get_ctp(p_stream_config, &{_obc_name_upper}_ctp_);\n" body_c += " tlm_id = ({_obc_name_upper}_TLM_CODE)CTP_get_id(&{_obc_name_upper}_ctp_);\n" body_c += "\n" From 51abdb27aa30ca0eb653947d88e143e8eda73f86 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Wed, 2 Feb 2022 01:40:25 +0900 Subject: [PATCH 108/141] fix define name --- README.md | 6 ++++-- my_mod/tlm_buffer.py | 10 +++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 8ca102e8f..a0b6dd1da 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,8 @@ $ python GenerateC2ACode.py "tlm_id_range" : ["0x90", "0xc0"], # DBがあるディレクトリへのパス(絶対でも相対でもOK) "db_path" : "../../c2a_sample_aobc/src/src_user/Settings/TlmCmd/DataBase/", - "max_tlms" : 256, + # MOBC で保持するテレメの TLM ID の最大値(=テレメ種類数) + "max_tlm_num" : 256, "driver_path" : "Aocs/", "driver_type" : "AOBC_Driver", "driver_name" : "aobc", @@ -64,7 +65,8 @@ $ python GenerateC2ACode.py "tlm_id_range" : ["0xc0", "0xf0"], # DBがあるディレクトリへのパス(絶対でも相対でもOK) "db_path" : ""../../c2a_sample_tobc/src/src_user/Settings/TlmCmd/DataBase/", - "max_tlms" : 256, + # MOBC で保持するテレメの TLM ID の最大値(=テレメ種類数) + "max_tlm_num" : 256, "driver_path" : "Thermal/", "driver_type" : "TOBC_Driver", "driver_name" : "tobc", diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index d852e11bc..855424474 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -18,7 +18,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): obc_name = settings["other_obc_data"][i]["name"] driver_type = settings["other_obc_data"][i]["driver_type"] driver_name = settings["other_obc_data"][i]["driver_name"] - max_tlms = settings["other_obc_data"][i]["max_tlms"] + max_tlm_num = settings["other_obc_data"][i]["max_tlm_num"] tlm_db = other_obc_dbs[obc_name] @@ -45,7 +45,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_h += "typedef struct " + driver_type + " " + driver_type + ";\n" body_h += "\n" - body_h += "#define {_obc_name_upper}_MAX_TLMS (" + str(max_tlms) + ")\n" + body_h += "#define {_obc_name_upper}_MAX_TLM_NUM (" + str(max_tlm_num) + ")\n" body_h += "\n" body_h += "typedef struct\n" body_h += "{{\n" @@ -55,7 +55,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_h += "\n" body_h += "typedef struct\n" body_h += "{{\n" - body_h += " {_obc_name_upper}_TlmBufferElem tlm[{_obc_name_upper}_MAX_TLMS]; //!< TLM ID ごとに保持\n" + body_h += " {_obc_name_upper}_TlmBufferElem tlm[{_obc_name_upper}_MAX_TLM_NUM]; //!< TLM ID ごとに保持\n" body_h += "}} {_obc_name_upper}_TlmBuffer;\n" body_h += "\n" @@ -129,7 +129,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += "{{\n" body_c += " // packet などは,上位の driver の初期化で driver もろとも memset 0x00 されていると期待して,ここではしない\n" body_c += " int i = 0;\n" - body_c += " for (i = 0; i < {_obc_name_upper}_MAX_TLMS; ++i)\n" + body_c += " for (i = 0; i < {_obc_name_upper}_MAX_TLM_NUM; ++i)\n" body_c += " {{\n" body_c += " " + driver_name + "->tlm_buffer.tlm[i].is_null_packet = 1;\n" body_c += " }}\n" @@ -319,7 +319,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += " const CommonTlmPacket* buffered_packet;\n" body_c += " uint16_t packet_len;\n" body_c += "\n" - body_c += " if (tlm_id >= {_obc_name_upper}_MAX_TLMS) return TF_NOT_DEFINED;\n" + body_c += " if (tlm_id >= {_obc_name_upper}_MAX_TLM_NUM) return TF_NOT_DEFINED;\n" body_c += ( " if (" + driver_name From 60cf66b9a4964ff6e0c824eeea5ad156b09b1daf Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Wed, 2 Feb 2022 01:41:04 +0900 Subject: [PATCH 109/141] Update settings.json --- settings.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/settings.json b/settings.json index 3e83da0b9..60c825b47 100644 --- a/settings.json +++ b/settings.json @@ -11,7 +11,7 @@ "db_prefix" : "SAMPLE_AOBC", "tlm_id_range" : ["0x90", "0xc0"], "db_path" : "C:/c2a_sample_aobc/src/src_user/Settings/TlmCmd/DataBase/", - "max_tlms" : 256, + "max_tlm_num" : 256, "driver_path" : "Aocs/", "driver_type" : "AOBC_Driver", "driver_name" : "aobc_driver", @@ -23,7 +23,7 @@ "db_prefix" : "SAMPLE_TOBC", "tlm_id_range" : ["0xc0", "0xf0"], "db_path" : "C:/c2a_sample_tobc/src/src_user/Settings/TlmCmd/DataBase/", - "max_tlms" : 256, + "max_tlm_num" : 256, "driver_path" : "Thermal/", "driver_type" : "TOBC_Driver", "driver_name" : "tobc_driver", From 6cc7dabae17f0d3c8a1031174e521d79fe896b75 Mon Sep 17 00:00:00 2001 From: Yoshinari Gyu <50069930+yngyu@users.noreply.github.com> Date: Wed, 16 Feb 2022 15:08:17 +0900 Subject: [PATCH 110/141] add replace @@ to , --- my_mod/load_db.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/my_mod/load_db.py b/my_mod/load_db.py index 9b279595c..6cd09fc4a 100644 --- a/my_mod/load_db.py +++ b/my_mod/load_db.py @@ -89,7 +89,7 @@ def LoadTlmCSV_(tlm_db_path, db_prefix, tlm_id_range): ) # FIXME: ローカル変数を取得.マジックナンバーで指定してしまってる. local_vars = [] for raw_local_var in raw_local_vars: - local_var = raw_local_var.strip() + local_var = raw_local_var.strip().replace("@@", ",") if len(local_var) > 0: local_vars.append(local_var) tlm_db.append( From 21e37a1fb7507ec4e98d99642b198ff0031ed729 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Fri, 18 Feb 2022 06:34:12 +0000 Subject: [PATCH 111/141] Add renovate.json --- renovate.json | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 renovate.json diff --git a/renovate.json b/renovate.json new file mode 100644 index 000000000..f45d8f110 --- /dev/null +++ b/renovate.json @@ -0,0 +1,5 @@ +{ + "extends": [ + "config:base" + ] +} From 80190a78a4e084b6444b2ffd629e60be9689fc97 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Tue, 1 Mar 2022 19:29:53 +0000 Subject: [PATCH 112/141] Update actions/checkout action to v3 --- .github/workflows/actionlint.yml | 2 +- .github/workflows/labeler.yml | 2 +- .github/workflows/python_check_format.yml | 2 +- .github/workflows/python_lint.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/actionlint.yml b/.github/workflows/actionlint.yml index 274d11ec1..4ef847aaf 100644 --- a/.github/workflows/actionlint.yml +++ b/.github/workflows/actionlint.yml @@ -9,7 +9,7 @@ jobs: actionlint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: reviewdog/action-actionlint@v1 with: github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml index e2f01a65f..da65f939a 100644 --- a/.github/workflows/labeler.yml +++ b/.github/workflows/labeler.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Run Labeler uses: crazy-max/ghaction-github-labeler@v3 diff --git a/.github/workflows/python_check_format.yml b/.github/workflows/python_check_format.yml index 5122fd697..be8c870e9 100644 --- a/.github/workflows/python_check_format.yml +++ b/.github/workflows/python_check_format.yml @@ -10,7 +10,7 @@ jobs: black_format: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 # - name: check python format with black # uses: psf/black@stable diff --git a/.github/workflows/python_lint.yml b/.github/workflows/python_lint.yml index cbef59827..6d85e59c9 100644 --- a/.github/workflows/python_lint.yml +++ b/.github/workflows/python_lint.yml @@ -10,7 +10,7 @@ jobs: flake8_lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up python environment uses: actions/setup-python@v2 From 82faee610cd40cc6e3043ab3da236afec0a0c669 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Tue, 1 Mar 2022 19:29:56 +0000 Subject: [PATCH 113/141] Update actions/setup-python action to v3 --- .github/workflows/python_lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python_lint.yml b/.github/workflows/python_lint.yml index cbef59827..e0a2a9ead 100644 --- a/.github/workflows/python_lint.yml +++ b/.github/workflows/python_lint.yml @@ -13,7 +13,7 @@ jobs: - uses: actions/checkout@v2 - name: Set up python environment - uses: actions/setup-python@v2 + uses: actions/setup-python@v3 with: python-version: "3.8" From fd606151a2daed52ff1b3ab903baad918f42534b Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Tue, 1 Mar 2022 22:50:09 +0000 Subject: [PATCH 114/141] Update reviewdog/action-black action to v3 --- .github/workflows/python_check_format.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python_check_format.yml b/.github/workflows/python_check_format.yml index 5122fd697..38282686d 100644 --- a/.github/workflows/python_check_format.yml +++ b/.github/workflows/python_check_format.yml @@ -15,7 +15,7 @@ jobs: # - name: check python format with black # uses: psf/black@stable - - uses: reviewdog/action-black@v2 + - uses: reviewdog/action-black@v3 with: github_token: ${{ secrets.GITHUB_TOKEN }} # reporter: github-pr-review # TODO: いい感じになったら直す From 3c2f3ba246950d088f463310ad66a99cf96b59d4 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Wed, 9 Mar 2022 02:15:27 +0900 Subject: [PATCH 115/141] fix TF_ACK and tlm func --- my_mod/tlm_buffer.py | 22 ++++++++++------------ my_mod/tlm_def.py | 17 +++++++++-------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index 855424474..a043d8178 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -114,13 +114,12 @@ def GenerateTlmBuffer(settings, other_obc_dbs): + ");\n" ) body_h += "\n" - body_h += "// FIXME: TF_ACK になおす!\n" body_h += ( - "int {_obc_name_upper}_pick_up_tlm_buffer(const " + "TF_TLM_FUNC_ACK {_obc_name_upper}_pick_up_tlm_buffer(const " + driver_type + "* " + driver_name - + ", {_obc_name_upper}_TLM_CODE tlm_id, uint8_t* packet, int max_len);\n" + + ", {_obc_name_upper}_TLM_CODE tlm_id, uint8_t* packet, uint16_t* len, uint16_t max_len);\n" ) body_c += ( @@ -309,30 +308,29 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += "\n" body_c += ( - "int {_obc_name_upper}_pick_up_tlm_buffer(const " + "TF_TLM_FUNC_ACK {_obc_name_upper}_pick_up_tlm_buffer(const " + driver_type + "* " + driver_name - + ", {_obc_name_upper}_TLM_CODE tlm_id, uint8_t* packet, int max_len)\n" + + ", {_obc_name_upper}_TLM_CODE tlm_id, uint8_t* packet, uint16_t* len, uint16_t max_len)\n" ) body_c += "{{\n" body_c += " const CommonTlmPacket* buffered_packet;\n" - body_c += " uint16_t packet_len;\n" body_c += "\n" - body_c += " if (tlm_id >= {_obc_name_upper}_MAX_TLM_NUM) return TF_NOT_DEFINED;\n" + body_c += " if (tlm_id >= {_obc_name_upper}_MAX_TLM_NUM) return TF_TLM_FUNC_ACK_NOT_DEFINED;\n" body_c += ( " if (" + driver_name - + "->tlm_buffer.tlm[tlm_id].is_null_packet) return TF_NULL_PACKET;\n" + + "->tlm_buffer.tlm[tlm_id].is_null_packet) return TF_TLM_FUNC_ACK_NULL_PACKET;\n" ) body_c += "\n" body_c += " buffered_packet = &(" + driver_name + "->tlm_buffer.tlm[tlm_id].packet);\n" - body_c += " packet_len = CTP_get_packet_len(buffered_packet);\n" + body_c += " *len = CTP_get_packet_len(buffered_packet);\n" body_c += "\n" - body_c += " if (packet_len > max_len) return TF_TOO_SHORT_LEN;\n" + body_c += " if (*len > max_len) return TF_TLM_FUNC_ACK_TOO_SHORT_LEN;\n" body_c += "\n" - body_c += " memcpy(packet, &buffered_packet->packet, (size_t)packet_len);\n" - body_c += " return packet_len;\n" + body_c += " memcpy(packet, &buffered_packet->packet, (size_t)(*len));\n" + body_c += " return TF_TLM_FUNC_ACK_SUCCESS;\n" body_c += "}}\n" body_c += "\n" diff --git a/my_mod/tlm_def.py b/my_mod/tlm_def.py index 105d76ec8..5350f6801 100644 --- a/my_mod/tlm_def.py +++ b/my_mod/tlm_def.py @@ -15,10 +15,10 @@ def GenerateTlmDef(settings, tlm_db, other_obc_dbs): body_c = "" body_h = "" - # "static int OBC_(uint8_t* packet, int max_len);" + # "static TF_TLM_FUNC_ACK OBC_(uint8_t* packet, uint16_t* len, uint16_t max_len);" # " OBC_ID = 0x00," for tlm in tlm_db: - body_c += "static int Tlm_" + tlm["tlm_name"].upper() + "_(uint8_t* packet, int max_len);\n" + body_c += "static TF_TLM_FUNC_ACK Tlm_" + tlm["tlm_name"].upper() + "_(uint8_t* packet, uint16_t* len, uint16_t max_len);\n" body_h += " Tlm_CODE_" + tlm["tlm_name"].upper() + " = " + tlm["tlm_id"] + ",\n" if settings["is_main_obc"]: @@ -95,19 +95,20 @@ def GenerateTlmDef(settings, tlm_db, other_obc_dbs): func_code += "(&packet[" + str(pos) + "], " + code + ");\n" body_c += "\n" - body_c += "static int Tlm_" + tlm["tlm_name"].upper() + "_(uint8_t* packet, int max_len)\n" + body_c += "static TF_TLM_FUNC_ACK Tlm_" + tlm["tlm_name"].upper() + "_(uint8_t* packet, uint16_t* len, uint16_t max_len)\n" body_c += "{\n" for local_var in tlm["local_vars"]: body_c += " " + local_var + "\n" if len(tlm["local_vars"]) > 0: body_c += "\n" - body_c += " if (" + str(max_pos) + " > max_len) return TF_TOO_SHORT_LEN;\n" + body_c += " if (" + str(max_pos) + " > max_len) return TF_TLM_FUNC_ACK_TOO_SHORT_LEN;\n" body_c += "\n" body_c += "#ifndef BUILD_SETTINGS_FAST_BUILD\n" body_c += func_code body_c += "#endif\n" body_c += "\n" - body_c += " return " + str(max_pos) + ";\n" + body_c += " *len = " + str(max_pos) + ";\n" + body_c += " return TF_TLM_FUNC_ACK_SUCCESS;\n" body_c += "}\n" if settings["is_main_obc"]: @@ -133,7 +134,7 @@ def GetTlmDefCOfOtherObcFunDef_(settings, tlm_db, other_obc_dbs): temp_c += "// {_obc_name_upper} TLM\n" for tlm in oter_obc_tlm_db: temp_c += ( - "static int Tlm_" + tlm["tlm_name"].upper() + "_(uint8_t* packet, int max_len);\n" + "static TF_TLM_FUNC_ACK Tlm_" + tlm["tlm_name"].upper() + "_(uint8_t* packet, uint16_t* len, uint16_t max_len);\n" ) body_c += temp_c.format( @@ -192,14 +193,14 @@ def GetTlmDefCOfOtherObcFunBody_(settings, tlm_db, other_obc_dbs): tlm_name_upper = tlm_name.upper() # tlm_name_lower = tlm_name.lower() temp_c += "\n" - temp_c += "static int Tlm_" + tlm_name_upper + "_(uint8_t* packet, int max_len)\n" + temp_c += "static TF_TLM_FUNC_ACK Tlm_" + tlm_name_upper + "_(uint8_t* packet, uint16_t* len, uint16_t max_len)\n" temp_c += "{{\n" temp_c += ( " return {_obc_name_upper}_pick_up_tlm_buffer(" + driver_name + ", {_obc_name_upper}_Tlm_CODE_" + tlm_name_upper - + ", packet, max_len);\n" + + ", packet, len, max_len);\n" ) temp_c += "}}\n" From 3e7888180276401b0848f22572232dff3aa1540a Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Wed, 9 Mar 2022 02:16:42 +0900 Subject: [PATCH 116/141] apply black --- my_mod/tlm_buffer.py | 4 +++- my_mod/tlm_def.py | 22 ++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index a043d8178..653724bb0 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -317,7 +317,9 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += "{{\n" body_c += " const CommonTlmPacket* buffered_packet;\n" body_c += "\n" - body_c += " if (tlm_id >= {_obc_name_upper}_MAX_TLM_NUM) return TF_TLM_FUNC_ACK_NOT_DEFINED;\n" + body_c += ( + " if (tlm_id >= {_obc_name_upper}_MAX_TLM_NUM) return TF_TLM_FUNC_ACK_NOT_DEFINED;\n" + ) body_c += ( " if (" + driver_name diff --git a/my_mod/tlm_def.py b/my_mod/tlm_def.py index 5350f6801..3c52255ae 100644 --- a/my_mod/tlm_def.py +++ b/my_mod/tlm_def.py @@ -18,7 +18,11 @@ def GenerateTlmDef(settings, tlm_db, other_obc_dbs): # "static TF_TLM_FUNC_ACK OBC_(uint8_t* packet, uint16_t* len, uint16_t max_len);" # " OBC_ID = 0x00," for tlm in tlm_db: - body_c += "static TF_TLM_FUNC_ACK Tlm_" + tlm["tlm_name"].upper() + "_(uint8_t* packet, uint16_t* len, uint16_t max_len);\n" + body_c += ( + "static TF_TLM_FUNC_ACK Tlm_" + + tlm["tlm_name"].upper() + + "_(uint8_t* packet, uint16_t* len, uint16_t max_len);\n" + ) body_h += " Tlm_CODE_" + tlm["tlm_name"].upper() + " = " + tlm["tlm_id"] + ",\n" if settings["is_main_obc"]: @@ -95,7 +99,11 @@ def GenerateTlmDef(settings, tlm_db, other_obc_dbs): func_code += "(&packet[" + str(pos) + "], " + code + ");\n" body_c += "\n" - body_c += "static TF_TLM_FUNC_ACK Tlm_" + tlm["tlm_name"].upper() + "_(uint8_t* packet, uint16_t* len, uint16_t max_len)\n" + body_c += ( + "static TF_TLM_FUNC_ACK Tlm_" + + tlm["tlm_name"].upper() + + "_(uint8_t* packet, uint16_t* len, uint16_t max_len)\n" + ) body_c += "{\n" for local_var in tlm["local_vars"]: body_c += " " + local_var + "\n" @@ -134,7 +142,9 @@ def GetTlmDefCOfOtherObcFunDef_(settings, tlm_db, other_obc_dbs): temp_c += "// {_obc_name_upper} TLM\n" for tlm in oter_obc_tlm_db: temp_c += ( - "static TF_TLM_FUNC_ACK Tlm_" + tlm["tlm_name"].upper() + "_(uint8_t* packet, uint16_t* len, uint16_t max_len);\n" + "static TF_TLM_FUNC_ACK Tlm_" + + tlm["tlm_name"].upper() + + "_(uint8_t* packet, uint16_t* len, uint16_t max_len);\n" ) body_c += temp_c.format( @@ -193,7 +203,11 @@ def GetTlmDefCOfOtherObcFunBody_(settings, tlm_db, other_obc_dbs): tlm_name_upper = tlm_name.upper() # tlm_name_lower = tlm_name.lower() temp_c += "\n" - temp_c += "static TF_TLM_FUNC_ACK Tlm_" + tlm_name_upper + "_(uint8_t* packet, uint16_t* len, uint16_t max_len)\n" + temp_c += ( + "static TF_TLM_FUNC_ACK Tlm_" + + tlm_name_upper + + "_(uint8_t* packet, uint16_t* len, uint16_t max_len)\n" + ) temp_c += "{{\n" temp_c += ( " return {_obc_name_upper}_pick_up_tlm_buffer(" From c5f65c335a3fadefbd4b56dfff45f3c89fb9485d Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 22 Mar 2022 02:10:52 +0900 Subject: [PATCH 117/141] update renovate settings --- .github/workflows/validate-renovate.yml | 22 ++++++++++++++++++++++ renovate.json | 5 ++++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/validate-renovate.yml diff --git a/.github/workflows/validate-renovate.yml b/.github/workflows/validate-renovate.yml new file mode 100644 index 000000000..84b52217e --- /dev/null +++ b/.github/workflows/validate-renovate.yml @@ -0,0 +1,22 @@ +name: validate / renovate.json + +on: + pull_request: + paths: + - 'renovate.json' + - '.github/workflows/validate-renovate.yml' + +jobs: + validate-renovate: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + + - name: install + run: | + npm install -g renovate + - name: validate + run: | + renovate-config-validator diff --git a/renovate.json b/renovate.json index f45d8f110..9b053cf94 100644 --- a/renovate.json +++ b/renovate.json @@ -1,5 +1,8 @@ { "extends": [ "config:base" - ] + ], + "labels": ["priority::medium", "tools"], + "additionalReviewers": ["meltingrabbit", "sksat"], + "assignees": ["meltingrabbit", "sksat"] } From c8ed4c16772b4470e81b62dbc04d36efb3608ea4 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 18 Jun 2022 18:42:01 +0000 Subject: [PATCH 118/141] Update actions/setup-python action to v4 --- .github/workflows/python_lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python_lint.yml b/.github/workflows/python_lint.yml index b6b7f7a69..e2c78d63a 100644 --- a/.github/workflows/python_lint.yml +++ b/.github/workflows/python_lint.yml @@ -13,7 +13,7 @@ jobs: - uses: actions/checkout@v3 - name: Set up python environment - uses: actions/setup-python@v3 + uses: actions/setup-python@v4 with: python-version: "3.8" From a48484ca2bfe7249a29126dff0ca5cd38dd89f98 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 18 Jun 2022 18:42:08 +0000 Subject: [PATCH 119/141] Update crazy-max/ghaction-github-labeler action to v4 --- .github/workflows/labeler.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml index da65f939a..82cb5d166 100644 --- a/.github/workflows/labeler.yml +++ b/.github/workflows/labeler.yml @@ -17,7 +17,7 @@ jobs: - uses: actions/checkout@v3 - name: Run Labeler - uses: crazy-max/ghaction-github-labeler@v3 + uses: crazy-max/ghaction-github-labeler@v4 with: github-token: ${{ secrets.GITHUB_TOKEN }} yaml-file: .github/labels.yml From 5f197053e2e652c186f8be93b3eb06dd6fdffa9e Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 23 Aug 2022 19:17:31 +0900 Subject: [PATCH 120/141] fix for eb90 frame --- my_mod/tlm_buffer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index 653724bb0..11ecb0e03 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -146,7 +146,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += " {_obc_name_upper}_TLM_CODE tlm_id;\n" body_c += " DS_ERR_CODE ret;\n" body_c += "\n" - body_c += " ret = DS_C2AFMT_get_ctp(p_stream_config, &{_obc_name_upper}_ctp_);\n" + body_c += " ret = CTP_get_ctp_from_dssc(p_stream_config, &{_obc_name_upper}_ctp_);\n" body_c += " if (ret != DS_ERR_CODE_OK) return ret;\n" body_c += "\n" body_c += " tlm_id = ({_obc_name_upper}_TLM_CODE)CTP_get_id(&{_obc_name_upper}_ctp_);\n" @@ -368,6 +368,7 @@ def OutputTlmBufferC_(file_path, name, body, settings): * @brief テレメトリバッファー(テレメ中継) * @note このコードは自動生成されています! */ +#include #include "./{_obc_name_lower}_telemetry_definitions.h" #include "./{_obc_name_lower}_telemetry_buffer.h" #include "./{_obc_name_lower}.h" From bb1e3103f72ea1ec94acfd98b1d1d801a4f692ff Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 30 Aug 2022 02:06:38 +0900 Subject: [PATCH 121/141] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index a0b6dd1da..764c9f5d9 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 の最大値(=テレメ種類数) @@ -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 の最大値(=テレメ種類数) From a906656f29ac8d1f927c5f04bd321124b49bf096 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 30 Aug 2022 02:18:28 +0900 Subject: [PATCH 122/141] add option for input encoding --- my_mod/load_db.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/my_mod/load_db.py b/my_mod/load_db.py index 6cd09fc4a..7139b9984 100644 --- a/my_mod/load_db.py +++ b/my_mod/load_db.py @@ -14,7 +14,7 @@ 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"]: @@ -27,14 +27,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] @@ -46,7 +46,7 @@ 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"]: @@ -57,7 +57,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] @@ -69,7 +69,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) @@ -109,7 +109,7 @@ 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) @@ -131,6 +131,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 From 57df373424b06a237d55aad36e6b93754ea2a378 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 30 Aug 2022 02:18:58 +0900 Subject: [PATCH 123/141] apply black --- my_mod/load_db.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/my_mod/load_db.py b/my_mod/load_db.py index 7139b9984..39a74afad 100644 --- a/my_mod/load_db.py +++ b/my_mod/load_db.py @@ -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"], settings["input_file_encoding"]) + sgc_db, bct_db = LoadCmdCSV_( + cmd_db_path, settings["db_prefix"], settings["input_file_encoding"] + ) other_obc_dbs = {} if settings["is_main_obc"]: @@ -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"], settings["input_file_encoding"]) + 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"]: @@ -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"], settings["other_obc_data"][i]["input_file_encoding"]) + 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) @@ -131,7 +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"] + settings["other_obc_data"][i]["input_file_encoding"], ) other_obc_dbs[settings["other_obc_data"][i]["name"]] = tlm_db From 210a66528abbcf5d5b601d68ae26ed705bb5dc0d Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 30 Aug 2022 14:16:52 +0900 Subject: [PATCH 124/141] Update settings.json --- settings.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/settings.json b/settings.json index 60c825b47..45e3c1c21 100644 --- a/settings.json +++ b/settings.json @@ -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" : [ @@ -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/", @@ -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/", From 29aae8bcee6e57f4699846787c54204832607304 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Thu, 29 Sep 2022 22:58:50 +0900 Subject: [PATCH 125/141] fix endian func --- my_mod/tlm_buffer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index 11ecb0e03..0dad7b286 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -263,7 +263,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): var_name = driver_name + "->tlm_data." + tlm_name_lower + "." + name_path if is_compression: body_c += ( - " endian_memcpy(&" + " ENDIAN_memcpy(&" + conv_tpye_to_temp[var_type] + ", &(f[" + str(oct_pos) @@ -288,7 +288,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += " " + var_name + " = " + conv_tpye_to_temp[var_type] + ";\n" else: body_c += ( - " endian_memcpy(&(" + " ENDIAN_memcpy(&(" + var_name + "), &(f[" + str(oct_pos) From 4067e34a63e97b08391a87d23ea73aef9a1eaf3c Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 4 Apr 2023 02:58:48 +0900 Subject: [PATCH 126/141] del unnecessary comment --- my_mod/cmd_def.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/my_mod/cmd_def.py b/my_mod/cmd_def.py index e3022ab4c..0df387360 100644 --- a/my_mod/cmd_def.py +++ b/my_mod/cmd_def.py @@ -105,8 +105,6 @@ def GenerateBctDef(settings, bct_db): DATA_SART_ROW = 2 body_h = "" - # " cmd_table[Cmd_CODE_NOP].cmd_func = Cmd_NOP;" - # " Cmd_CODE_NOP = 0x0000," for i in range(DATA_SART_ROW, len(bct_db)): comment = bct_db[i][0] name = bct_db[i][1] From 63588256c6b595330761d7ca2e11d078cd0cebee Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 4 Apr 2023 03:13:43 +0900 Subject: [PATCH 127/141] add option is_cmd_prefix_in_db --- my_mod/cmd_def.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/my_mod/cmd_def.py b/my_mod/cmd_def.py index 0df387360..7d9b3798e 100644 --- a/my_mod/cmd_def.py +++ b/my_mod/cmd_def.py @@ -27,8 +27,7 @@ def GenerateCmdDef(settings, sgc_db): if comment != "": # Comment continue - cmd_name = name - cmd_code = cmd_name.replace("Cmd_", "Cmd_CODE_") + cmd_name, cmd_code = GetCmdNameAndCmdCode_(name, settings["is_cmd_prefix_in_db"]) # print(cmd_name) # print(cmd_code) body_c += " cmd_table[" + cmd_code + "].cmd_func = " + cmd_name + ";\n" @@ -53,8 +52,7 @@ def GenerateCmdDef(settings, sgc_db): sgc_db[i][13], sgc_db[i][15], ] - cmd_name = name - cmd_code = cmd_name.replace("Cmd_", "Cmd_CODE_") + cmd_name, cmd_code = GetCmdNameAndCmdCode_(name, settings["is_cmd_prefix_in_db"]) # パラメタ長の整合性チェック for j in range(len(type_list)): @@ -159,8 +157,8 @@ def GenerateOtherObcCmdDef(settings, other_obc_dbs): if comment != "": # Comment continue # print(name) - cmd_name = name - cmd_code = cmd_name.replace("Cmd_", name_upper + "_Cmd_CODE_") + _, cmd_code = GetCmdNameAndCmdCode_(name, settings["other_obc_data"][i]["is_cmd_prefix_in_db"]) + cmd_code = name_upper + cmd_code body_h += " " + cmd_code + " = " + cmd_id + ",\n" # print(body_h) output_file_path = ( @@ -173,6 +171,15 @@ def GenerateOtherObcCmdDef(settings, other_obc_dbs): OutputOtherObcCmdDefH_(output_file_path, obc_name, body_h, settings) +def GetCmdNameAndCmdCode_(name, is_cmd_prefix_in_db): + if is_cmd_prefix_in_db: + cmd_name = name + else: + cmd_name = "Cmd_" + name + cmd_code = cmd_name.replace("Cmd_", "Cmd_CODE_") + return cmd_name, cmd_code + + def OutputCmdDefC_(file_path, body, settings): output = "" output += """ From 433b21318819927b1881351f66aad6eaa8c40c74 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 4 Apr 2023 03:16:26 +0900 Subject: [PATCH 128/141] apply black --- my_mod/cmd_def.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/my_mod/cmd_def.py b/my_mod/cmd_def.py index 7d9b3798e..039efd2f1 100644 --- a/my_mod/cmd_def.py +++ b/my_mod/cmd_def.py @@ -157,7 +157,9 @@ def GenerateOtherObcCmdDef(settings, other_obc_dbs): if comment != "": # Comment continue # print(name) - _, cmd_code = GetCmdNameAndCmdCode_(name, settings["other_obc_data"][i]["is_cmd_prefix_in_db"]) + _, cmd_code = GetCmdNameAndCmdCode_( + name, settings["other_obc_data"][i]["is_cmd_prefix_in_db"] + ) cmd_code = name_upper + cmd_code body_h += " " + cmd_code + " = " + cmd_id + ",\n" # print(body_h) From 610f81f6cd11f404a030b1dd7293522bb7db6eb7 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 4 Apr 2023 03:18:30 +0900 Subject: [PATCH 129/141] update readme --- README.md | 4 ++++ settings.json | 3 +++ 2 files changed, 7 insertions(+) diff --git a/README.md b/README.md index 764c9f5d9..d53648b46 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,8 @@ $ python GenerateC2ACode.py "db_prefix" : "SAMPLE_MOBC", # TLM ID の定義域 "tlm_id_range" : ["0x00", "0x100"], + # Cmd DB の Name に "Cmd_" の接頭辞が含まれるか?(今後は含まれないのが基本とする) + "is_cmd_prefix_in_db" : 0, # 入力 Tlm Cmd DB のエンコーディング "input_file_encoding" : "utf-8", # 出力ファイルのエンコーディング @@ -49,6 +51,7 @@ $ python GenerateC2ACode.py "is_enable" : 1, "db_prefix" : "SAMPLE_AOBC", "tlm_id_range" : ["0x90", "0xc0"], + "is_cmd_prefix_in_db" : 0, "input_file_encoding" : "utf-8", # DBがあるディレクトリへのパス(絶対でも相対でもOK) "db_path" : "../../c2a_sample_aobc/src/src_user/Settings/TlmCmd/DataBase/", @@ -66,6 +69,7 @@ $ python GenerateC2ACode.py "is_enable" : 1, "db_prefix" : "SAMPLE_TOBC", "tlm_id_range" : ["0xc0", "0xf0"], + "is_cmd_prefix_in_db" : 0, "input_file_encoding" : "utf-8", # DBがあるディレクトリへのパス(絶対でも相対でもOK) "db_path" : ""../../c2a_sample_tobc/src/src_user/Settings/TlmCmd/DataBase/", diff --git a/settings.json b/settings.json index 45e3c1c21..0414f7ddf 100644 --- a/settings.json +++ b/settings.json @@ -2,6 +2,7 @@ "c2a_root_dir" : "../../c2a/src/", "db_prefix" : "SAMPLE_MOBC", "tlm_id_range" : ["0x00", "0x100"], + "is_cmd_prefix_in_db" : 0, "input_file_encoding" : "utf-8", "output_file_encoding" : "utf-8", "is_main_obc" : 1, @@ -11,6 +12,7 @@ "is_enable" : 1, "db_prefix" : "SAMPLE_AOBC", "tlm_id_range" : ["0x90", "0xc0"], + "is_cmd_prefix_in_db" : 0, "input_file_encoding" : "utf-8", "db_path" : "C:/c2a_sample_aobc/src/src_user/Settings/TlmCmd/DataBase/", "max_tlm_num" : 256, @@ -24,6 +26,7 @@ "is_enable" : 1, "db_prefix" : "SAMPLE_TOBC", "tlm_id_range" : ["0xc0", "0xf0"], + "is_cmd_prefix_in_db" : 0, "input_file_encoding" : "utf-8", "db_path" : "C:/c2a_sample_tobc/src/src_user/Settings/TlmCmd/DataBase/", "max_tlm_num" : 256, From eee2d3732c6c5a54f40a4dc17d520ca09860fb9e Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Tue, 4 Apr 2023 03:26:54 +0900 Subject: [PATCH 130/141] fix bug --- my_mod/cmd_def.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/my_mod/cmd_def.py b/my_mod/cmd_def.py index 039efd2f1..dd12b8227 100644 --- a/my_mod/cmd_def.py +++ b/my_mod/cmd_def.py @@ -160,7 +160,7 @@ def GenerateOtherObcCmdDef(settings, other_obc_dbs): _, cmd_code = GetCmdNameAndCmdCode_( name, settings["other_obc_data"][i]["is_cmd_prefix_in_db"] ) - cmd_code = name_upper + cmd_code + cmd_code = name_upper + "_" + cmd_code body_h += " " + cmd_code + " = " + cmd_id + ",\n" # print(body_h) output_file_path = ( From e0da8f6668ed5e6d9f040297a3a9838386526dfe Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Sun, 9 Apr 2023 22:40:55 +0900 Subject: [PATCH 131/141] sed is_cmd_prefixed_in_db --- README.md | 6 +++--- my_mod/cmd_def.py | 10 +++++----- settings.json | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index d53648b46..004c6bc26 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ $ python GenerateC2ACode.py # TLM ID の定義域 "tlm_id_range" : ["0x00", "0x100"], # Cmd DB の Name に "Cmd_" の接頭辞が含まれるか?(今後は含まれないのが基本とする) - "is_cmd_prefix_in_db" : 0, + "is_cmd_prefixed_in_db" : 0, # 入力 Tlm Cmd DB のエンコーディング "input_file_encoding" : "utf-8", # 出力ファイルのエンコーディング @@ -51,7 +51,7 @@ $ python GenerateC2ACode.py "is_enable" : 1, "db_prefix" : "SAMPLE_AOBC", "tlm_id_range" : ["0x90", "0xc0"], - "is_cmd_prefix_in_db" : 0, + "is_cmd_prefixed_in_db" : 0, "input_file_encoding" : "utf-8", # DBがあるディレクトリへのパス(絶対でも相対でもOK) "db_path" : "../../c2a_sample_aobc/src/src_user/Settings/TlmCmd/DataBase/", @@ -69,7 +69,7 @@ $ python GenerateC2ACode.py "is_enable" : 1, "db_prefix" : "SAMPLE_TOBC", "tlm_id_range" : ["0xc0", "0xf0"], - "is_cmd_prefix_in_db" : 0, + "is_cmd_prefixed_in_db" : 0, "input_file_encoding" : "utf-8", # DBがあるディレクトリへのパス(絶対でも相対でもOK) "db_path" : ""../../c2a_sample_tobc/src/src_user/Settings/TlmCmd/DataBase/", diff --git a/my_mod/cmd_def.py b/my_mod/cmd_def.py index dd12b8227..1782f5172 100644 --- a/my_mod/cmd_def.py +++ b/my_mod/cmd_def.py @@ -27,7 +27,7 @@ def GenerateCmdDef(settings, sgc_db): if comment != "": # Comment continue - cmd_name, cmd_code = GetCmdNameAndCmdCode_(name, settings["is_cmd_prefix_in_db"]) + cmd_name, cmd_code = GetCmdNameAndCmdCode_(name, settings["is_cmd_prefixed_in_db"]) # print(cmd_name) # print(cmd_code) body_c += " cmd_table[" + cmd_code + "].cmd_func = " + cmd_name + ";\n" @@ -52,7 +52,7 @@ def GenerateCmdDef(settings, sgc_db): sgc_db[i][13], sgc_db[i][15], ] - cmd_name, cmd_code = GetCmdNameAndCmdCode_(name, settings["is_cmd_prefix_in_db"]) + cmd_name, cmd_code = GetCmdNameAndCmdCode_(name, settings["is_cmd_prefixed_in_db"]) # パラメタ長の整合性チェック for j in range(len(type_list)): @@ -158,7 +158,7 @@ def GenerateOtherObcCmdDef(settings, other_obc_dbs): continue # print(name) _, cmd_code = GetCmdNameAndCmdCode_( - name, settings["other_obc_data"][i]["is_cmd_prefix_in_db"] + name, settings["other_obc_data"][i]["is_cmd_prefixed_in_db"] ) cmd_code = name_upper + "_" + cmd_code body_h += " " + cmd_code + " = " + cmd_id + ",\n" @@ -173,8 +173,8 @@ def GenerateOtherObcCmdDef(settings, other_obc_dbs): OutputOtherObcCmdDefH_(output_file_path, obc_name, body_h, settings) -def GetCmdNameAndCmdCode_(name, is_cmd_prefix_in_db): - if is_cmd_prefix_in_db: +def GetCmdNameAndCmdCode_(name, is_cmd_prefixed_in_db): + if is_cmd_prefixed_in_db: cmd_name = name else: cmd_name = "Cmd_" + name diff --git a/settings.json b/settings.json index 0414f7ddf..bd8454d46 100644 --- a/settings.json +++ b/settings.json @@ -2,7 +2,7 @@ "c2a_root_dir" : "../../c2a/src/", "db_prefix" : "SAMPLE_MOBC", "tlm_id_range" : ["0x00", "0x100"], - "is_cmd_prefix_in_db" : 0, + "is_cmd_prefixed_in_db" : 0, "input_file_encoding" : "utf-8", "output_file_encoding" : "utf-8", "is_main_obc" : 1, @@ -12,7 +12,7 @@ "is_enable" : 1, "db_prefix" : "SAMPLE_AOBC", "tlm_id_range" : ["0x90", "0xc0"], - "is_cmd_prefix_in_db" : 0, + "is_cmd_prefixed_in_db" : 0, "input_file_encoding" : "utf-8", "db_path" : "C:/c2a_sample_aobc/src/src_user/Settings/TlmCmd/DataBase/", "max_tlm_num" : 256, @@ -26,7 +26,7 @@ "is_enable" : 1, "db_prefix" : "SAMPLE_TOBC", "tlm_id_range" : ["0xc0", "0xf0"], - "is_cmd_prefix_in_db" : 0, + "is_cmd_prefixed_in_db" : 0, "input_file_encoding" : "utf-8", "db_path" : "C:/c2a_sample_tobc/src/src_user/Settings/TlmCmd/DataBase/", "max_tlm_num" : 256, From 6cb95d285a8ebaaeaf1d80dab0672391d37f8192 Mon Sep 17 00:00:00 2001 From: Ryo Suzumoto Date: Mon, 17 Apr 2023 07:30:54 +0900 Subject: [PATCH 132/141] del 2nd obc tlm in mobc tlm def for foward tlm --- GenerateC2ACode.py | 2 +- my_mod/tlm_def.py | 164 +-------------------------------------------- 2 files changed, 2 insertions(+), 164 deletions(-) diff --git a/GenerateC2ACode.py b/GenerateC2ACode.py index 7a5a845c5..00f272255 100644 --- a/GenerateC2ACode.py +++ b/GenerateC2ACode.py @@ -38,7 +38,7 @@ def main(): my_mod.cmd_def.GenerateCmdDef(settings, cmd_db["sgc"]) my_mod.cmd_def.GenerateBctDef(settings, cmd_db["bct"]) - my_mod.tlm_def.GenerateTlmDef(settings, tlm_db["tlm"], tlm_db["other_obc"]) + my_mod.tlm_def.GenerateTlmDef(settings, tlm_db["tlm"]) if settings["is_main_obc"]: my_mod.cmd_def.GenerateOtherObcCmdDef(settings, cmd_db["other_obc"]) diff --git a/my_mod/tlm_def.py b/my_mod/tlm_def.py index 3c52255ae..ecaef8c6f 100644 --- a/my_mod/tlm_def.py +++ b/my_mod/tlm_def.py @@ -6,7 +6,7 @@ import sys -def GenerateTlmDef(settings, tlm_db, other_obc_dbs): +def GenerateTlmDef(settings, tlm_db): output_file_path = settings["c2a_root_dir"] + r"src_user/TlmCmd/" output_file_name_base = "telemetry_definitions" @@ -25,9 +25,6 @@ def GenerateTlmDef(settings, tlm_db, other_obc_dbs): ) body_h += " Tlm_CODE_" + tlm["tlm_name"].upper() + " = " + tlm["tlm_id"] + ",\n" - if settings["is_main_obc"]: - body_c += GetTlmDefCOfOtherObcFunDef_(settings, tlm_db, other_obc_dbs) - body_c += "\n" body_c += "void TF_load_tlm_table(TF_TlmInfo tlm_table[TF_MAX_TLMS])\n" body_c += "{\n" @@ -40,8 +37,6 @@ def GenerateTlmDef(settings, tlm_db, other_obc_dbs): + tlm["tlm_name"].upper() + "_;\n" ) - if settings["is_main_obc"]: - body_c += GetTlmDefCOfOtherObcFunLoad_(settings, tlm_db, other_obc_dbs) body_c += "}\n" for tlm in tlm_db: @@ -119,167 +114,10 @@ def GenerateTlmDef(settings, tlm_db, other_obc_dbs): body_c += " return TF_TLM_FUNC_ACK_SUCCESS;\n" body_c += "}\n" - if settings["is_main_obc"]: - body_c += GetTlmDefCOfOtherObcFunBody_(settings, tlm_db, other_obc_dbs) - body_h += GetTlmDefHOfOtherObc_(settings, tlm_db, other_obc_dbs) - OutputTlmDefC_(output_file_path + output_file_name_base + ".c", body_c, settings) OutputTlmDefH_(output_file_path + output_file_name_base + ".h", body_h, settings) -def GetTlmDefCOfOtherObcFunDef_(settings, tlm_db, other_obc_dbs): - body_c = "" - - for i in range(len(settings["other_obc_data"])): - if not settings["other_obc_data"][i]["is_enable"]: - continue - - obc_name = settings["other_obc_data"][i]["name"] - oter_obc_tlm_db = other_obc_dbs[obc_name] - - temp_c = "" - temp_c += "\n" - temp_c += "// {_obc_name_upper} TLM\n" - for tlm in oter_obc_tlm_db: - temp_c += ( - "static TF_TLM_FUNC_ACK Tlm_" - + tlm["tlm_name"].upper() - + "_(uint8_t* packet, uint16_t* len, uint16_t max_len);\n" - ) - - body_c += temp_c.format( - _obc_name_upper=obc_name.upper(), - _obc_name_lower=obc_name.lower(), - _obc_name_capit=obc_name.capitalize(), - ) - - return body_c - - -def GetTlmDefCOfOtherObcFunLoad_(settings, tlm_db, other_obc_dbs): - body_c = "" - - for i in range(len(settings["other_obc_data"])): - if not settings["other_obc_data"][i]["is_enable"]: - continue - - obc_name = settings["other_obc_data"][i]["name"] - oter_obc_tlm_db = other_obc_dbs[obc_name] - - temp_c = "" - temp_c += "\n" - temp_c += " // {_obc_name_upper} TLM\n" - for tlm in oter_obc_tlm_db: - temp_c += ( - " tlm_table[Tlm_CODE_" - + tlm["tlm_name"].upper() - + "].tlm_func = Tlm_" - + tlm["tlm_name"].upper() - + "_;\n" - ) - body_c += temp_c.format( - _obc_name_upper=obc_name.upper(), - _obc_name_lower=obc_name.lower(), - _obc_name_capit=obc_name.capitalize(), - ) - - return body_c - - -def GetTlmDefCOfOtherObcFunBody_(settings, tlm_db, other_obc_dbs): - body_c = "" - - for i in range(len(settings["other_obc_data"])): - if not settings["other_obc_data"][i]["is_enable"]: - continue - - obc_name = settings["other_obc_data"][i]["name"] - oter_obc_tlm_db = other_obc_dbs[obc_name] - driver_name = settings["other_obc_data"][i]["driver_name"] - - temp_c = "" - for tlm in oter_obc_tlm_db: - tlm_name = tlm["tlm_name"] - tlm_name_upper = tlm_name.upper() - # tlm_name_lower = tlm_name.lower() - temp_c += "\n" - temp_c += ( - "static TF_TLM_FUNC_ACK Tlm_" - + tlm_name_upper - + "_(uint8_t* packet, uint16_t* len, uint16_t max_len)\n" - ) - temp_c += "{{\n" - temp_c += ( - " return {_obc_name_upper}_pick_up_tlm_buffer(" - + driver_name - + ", {_obc_name_upper}_Tlm_CODE_" - + tlm_name_upper - + ", packet, len, max_len);\n" - ) - temp_c += "}}\n" - - body_c += temp_c.format( - _obc_name_upper=obc_name.upper(), - _obc_name_lower=obc_name.lower(), - _obc_name_capit=obc_name.capitalize(), - ) - - return body_c - - -def GetTlmDefHOfOtherObc_(settings, tlm_db, other_obc_dbs): - # ID重複チェックはここでやり,他のGet関数ではやらない(実装イマイチ...) - body_h = "" - - for i in range(len(settings["other_obc_data"])): - if not settings["other_obc_data"][i]["is_enable"]: - continue - obc_name = settings["other_obc_data"][i]["name"] - - temp_h = "" - - id_begin = int(settings["other_obc_data"][i]["tlm_id_range"][0], 0) - id_end = int(settings["other_obc_data"][i]["tlm_id_range"][1], 0) - - # MOBC Tlmが範囲外かチェック - for tlm in tlm_db: - tlm_id = int(tlm["tlm_id"], 0) - if id_begin <= tlm_id < id_end: - print( - "Error: MOBC TLM ID is invalid at " + tlm["tlm_name"].upper(), file=sys.stderr - ) - sys.exit(1) - - oter_obc_tlm_db = other_obc_dbs[obc_name] - # ID範囲内チェック - for tlm in oter_obc_tlm_db: - tlm_id = int(tlm["tlm_id"], 0) - if not id_begin <= tlm_id < id_end: - print( - "Error: " + obc_name + " TLM ID is invalid at " + tlm["tlm_name"].upper(), - file=sys.stderr, - ) - sys.exit(1) - - body_h += "\n" - temp_h += " // {_obc_name_upper} TLM\n" - for tlm in oter_obc_tlm_db: - temp_h += " Tlm_CODE_" + tlm["tlm_name"].upper() + " = " + tlm["tlm_id"] + ",\n" - - body_h += temp_h.format( - _obc_name_upper=obc_name.upper(), - _obc_name_lower=obc_name.lower(), - _obc_name_capit=obc_name.capitalize(), - ) - - body_h += "\n" - body_h += " // FIXME:\n" - body_h += " // 他OBCのTLMをまとめたため,IDが昇順となっていない\n" - body_h += " // TLM_CODE_MAX が意味をなさなくなってしまうが,他で使われていないため,一旦このままにする(今後解決する実装)\n" - - return body_h - - def GenerateOtherObcTlmDef(settings, other_obc_dbs): for i in range(len(settings["other_obc_data"])): if not settings["other_obc_data"][i]["is_enable"]: From b1756b67d034e55fe7490b438b52fac9ee5c96f8 Mon Sep 17 00:00:00 2001 From: sksat Date: Thu, 20 Apr 2023 02:31:38 +0900 Subject: [PATCH 133/141] fix relative c2a-core header include --- my_mod/cmd_def.py | 2 +- my_mod/tlm_def.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/my_mod/cmd_def.py b/my_mod/cmd_def.py index 1782f5172..961a66823 100644 --- a/my_mod/cmd_def.py +++ b/my_mod/cmd_def.py @@ -191,7 +191,7 @@ def OutputCmdDefC_(file_path, body, settings): * @brief コマンド定義 * @note このコードは自動生成されています! */ -#include "../../src_core/TlmCmd/command_analyze.h" +#include #include "command_definitions.h" #include "command_source.h" diff --git a/my_mod/tlm_def.py b/my_mod/tlm_def.py index ecaef8c6f..abaac707e 100644 --- a/my_mod/tlm_def.py +++ b/my_mod/tlm_def.py @@ -155,7 +155,7 @@ def OutputTlmDefC_(file_path, body, settings): * @brief テレメトリ定義 * @note このコードは自動生成されています! */ -#include "../../src_core/TlmCmd/telemetry_frame.h" +#include #include "telemetry_definitions.h" #include "telemetry_source.h" From f0b8263d44700c3db222742949704836eac6a840 Mon Sep 17 00:00:00 2001 From: chutaro <35984595+chutaro@users.noreply.github.com> Date: Mon, 24 Jul 2023 15:33:39 +0900 Subject: [PATCH 134/141] add path to db settings --- GenerateC2ACode.py | 2 +- README.md | 2 +- my_mod/cmd_def.py | 6 +++--- my_mod/load_db.py | 6 ++---- my_mod/tlm_buffer.py | 2 +- my_mod/tlm_def.py | 4 ++-- settings.json | 7 ++++--- 7 files changed, 14 insertions(+), 15 deletions(-) diff --git a/GenerateC2ACode.py b/GenerateC2ACode.py index 00f272255..8ec163d10 100644 --- a/GenerateC2ACode.py +++ b/GenerateC2ACode.py @@ -28,7 +28,7 @@ def main(): with open(SETTING_FILE_PATH, mode="r") as fh: settings = json.load(fh) - # print(settings["c2a_root_dir"]); + # print(settings["path_to_src"]); cmd_db = my_mod.load_db.LoadCmdDb(settings) tlm_db = my_mod.load_db.LoadTlmDb(settings) diff --git a/README.md b/README.md index 004c6bc26..cc62ab0d3 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ $ python GenerateC2ACode.py { # C2A ROOTへ相対パス. # C2A ROOTとは, `src_core`, `src_user` のあるディレクトリ - "c2a_root_dir" : "../../c2a/src/", + "path_to_src" : "../../c2a/src/", # TlmCmdDBのファイル名の接頭辞 "db_prefix" : "SAMPLE_MOBC", # TLM ID の定義域 diff --git a/my_mod/cmd_def.py b/my_mod/cmd_def.py index 961a66823..50a98ed76 100644 --- a/my_mod/cmd_def.py +++ b/my_mod/cmd_def.py @@ -9,7 +9,7 @@ def GenerateCmdDef(settings, sgc_db): - output_file_path = settings["c2a_root_dir"] + r"src_user/TlmCmd/" + output_file_path = settings["path_to_src"] + r"src_user/TlmCmd/" output_file_name_base = "command_definitions" DATA_SART_ROW = 3 @@ -97,7 +97,7 @@ def GenerateCmdDef(settings, sgc_db): def GenerateBctDef(settings, bct_db): - output_file_path = settings["c2a_root_dir"] + r"src_user/TlmCmd/" + output_file_path = settings["path_to_src"] + r"src_user/TlmCmd/" output_file_name = "block_command_definitions.h" DATA_SART_ROW = 2 @@ -164,7 +164,7 @@ def GenerateOtherObcCmdDef(settings, other_obc_dbs): body_h += " " + cmd_code + " = " + cmd_id + ",\n" # print(body_h) output_file_path = ( - settings["c2a_root_dir"] + settings["path_to_src"] + r"src_user/Drivers/" + settings["other_obc_data"][i]["driver_path"] + name_lower diff --git a/my_mod/load_db.py b/my_mod/load_db.py index 39a74afad..66c2e859d 100644 --- a/my_mod/load_db.py +++ b/my_mod/load_db.py @@ -12,7 +12,7 @@ def LoadCmdDb(settings): - cmd_db_path = settings["c2a_root_dir"] + r"src_user/Settings/TlmCmd/DataBase/CMD_DB/" + cmd_db_path = settings["db_path"] + r"CMD_DB/" sgc_db, bct_db = LoadCmdCSV_( cmd_db_path, settings["db_prefix"], settings["input_file_encoding"] @@ -44,9 +44,7 @@ def LoadCmdCSV_(cmd_db_path, db_prefix, encoding): def LoadTlmDb(settings): - tlm_db_path = ( - settings["c2a_root_dir"] + r"src_user/Settings/TlmCmd/DataBase/TLM_DB/calced_data/" - ) + tlm_db_path = settings["db_path"] + r"TLM_DB/calced_data/" tlm_db = LoadTlmCSV_( tlm_db_path, diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index 0dad7b286..4eb06b714 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -337,7 +337,7 @@ def GenerateTlmBuffer(settings, other_obc_dbs): body_c += "\n" output_file_path = ( - settings["c2a_root_dir"] + settings["path_to_src"] + r"src_user/Drivers/" + settings["other_obc_data"][i]["driver_path"] ) diff --git a/my_mod/tlm_def.py b/my_mod/tlm_def.py index abaac707e..e8ba39969 100644 --- a/my_mod/tlm_def.py +++ b/my_mod/tlm_def.py @@ -7,7 +7,7 @@ def GenerateTlmDef(settings, tlm_db): - output_file_path = settings["c2a_root_dir"] + r"src_user/TlmCmd/" + output_file_path = settings["path_to_src"] + r"src_user/TlmCmd/" output_file_name_base = "telemetry_definitions" DATA_START_ROW = 8 @@ -137,7 +137,7 @@ def GenerateOtherObcTlmDef(settings, other_obc_dbs): + ",\n" ) output_file_path = ( - settings["c2a_root_dir"] + settings["path_to_src"] + r"src_user/Drivers/" + settings["other_obc_data"][i]["driver_path"] + obc_name.lower() diff --git a/settings.json b/settings.json index bd8454d46..6ef5e13bf 100644 --- a/settings.json +++ b/settings.json @@ -1,5 +1,6 @@ { - "c2a_root_dir" : "../../c2a/src/", + "path_to_src" : "../../c2a/src/", + "path_to_db" : "../../c2a/database/", "db_prefix" : "SAMPLE_MOBC", "tlm_id_range" : ["0x00", "0x100"], "is_cmd_prefixed_in_db" : 0, @@ -14,7 +15,7 @@ "tlm_id_range" : ["0x90", "0xc0"], "is_cmd_prefixed_in_db" : 0, "input_file_encoding" : "utf-8", - "db_path" : "C:/c2a_sample_aobc/src/src_user/Settings/TlmCmd/DataBase/", + "path_to_db" : "C:/c2a_sample_aobc/database/", "max_tlm_num" : 256, "driver_path" : "Aocs/", "driver_type" : "AOBC_Driver", @@ -28,7 +29,7 @@ "tlm_id_range" : ["0xc0", "0xf0"], "is_cmd_prefixed_in_db" : 0, "input_file_encoding" : "utf-8", - "db_path" : "C:/c2a_sample_tobc/src/src_user/Settings/TlmCmd/DataBase/", + "path_to_db" : "C:/c2a_sample_tobc/database/", "max_tlm_num" : 256, "driver_path" : "Thermal/", "driver_type" : "TOBC_Driver", From dad7078ce145df34226463aa1ca5ddaf2f273e03 Mon Sep 17 00:00:00 2001 From: chutaro <35984595+chutaro@users.noreply.github.com> Date: Mon, 24 Jul 2023 15:39:46 +0900 Subject: [PATCH 135/141] =?UTF-8?q?=E5=BE=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 11 ++++++----- my_mod/load_db.py | 8 ++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index cc62ab0d3..f6c0365f3 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ $ python GenerateC2ACode.py ## 設定 `settings.json` にて記述する. -`is_main_obc` は,MOBC(地上局と通信するOBC.2nd OBCのtlm/cmdを取りまとめる)かそれ以外のOBC(2nd OBC.MOBCと通信するOBC)かを制御する. +`is_main_obc` は,MOBC(地上局と通信するOBC.2nd OBCのtlm/cmdを取りまとめる)かそれ以外のOBC(2nd OBC.MOBCと通信するOBC)かを制御する. `1` とした場合,MOBCを意図したコードが生成され,加えて以下が生成される. - 2nd_obc_command_definitions.h - 2nd_obc_telemetry_definitions.h @@ -26,9 +26,10 @@ $ python GenerateC2ACode.py ``` { - # C2A ROOTへ相対パス. - # C2A ROOTとは, `src_core`, `src_user` のあるディレクトリ + # `src_core`, `src_user` のあるディレクトリへのパス "path_to_src" : "../../c2a/src/", + # テレコマ DB のあるディレクトリへのパス + "path_to_db" : "../../c2a/database/", # TlmCmdDBのファイル名の接頭辞 "db_prefix" : "SAMPLE_MOBC", # TLM ID の定義域 @@ -54,7 +55,7 @@ $ python GenerateC2ACode.py "is_cmd_prefixed_in_db" : 0, "input_file_encoding" : "utf-8", # DBがあるディレクトリへのパス(絶対でも相対でもOK) - "db_path" : "../../c2a_sample_aobc/src/src_user/Settings/TlmCmd/DataBase/", + "path_to_db" : "../../c2a_sample_aobc/database/", # MOBC で保持するテレメの TLM ID の最大値(=テレメ種類数) "max_tlm_num" : 256, "driver_path" : "Aocs/", @@ -72,7 +73,7 @@ $ python GenerateC2ACode.py "is_cmd_prefixed_in_db" : 0, "input_file_encoding" : "utf-8", # DBがあるディレクトリへのパス(絶対でも相対でもOK) - "db_path" : ""../../c2a_sample_tobc/src/src_user/Settings/TlmCmd/DataBase/", + "path_to_db" : ""../../c2a_sample_tobc/database/", # MOBC で保持するテレメの TLM ID の最大値(=テレメ種類数) "max_tlm_num" : 256, "driver_path" : "Thermal/", diff --git a/my_mod/load_db.py b/my_mod/load_db.py index 66c2e859d..b5fb3f8de 100644 --- a/my_mod/load_db.py +++ b/my_mod/load_db.py @@ -12,7 +12,7 @@ def LoadCmdDb(settings): - cmd_db_path = settings["db_path"] + r"CMD_DB/" + cmd_db_path = settings["path_to_db"] + r"CMD_DB/" sgc_db, bct_db = LoadCmdCSV_( cmd_db_path, settings["db_prefix"], settings["input_file_encoding"] @@ -44,7 +44,7 @@ def LoadCmdCSV_(cmd_db_path, db_prefix, encoding): def LoadTlmDb(settings): - tlm_db_path = settings["db_path"] + r"TLM_DB/calced_data/" + tlm_db_path = settings["path_to_db"] + r"TLM_DB/calced_data/" tlm_db = LoadTlmCSV_( tlm_db_path, @@ -113,7 +113,7 @@ def LoadOtherObcCmd_(settings): for i in range(len(settings["other_obc_data"])): if not settings["other_obc_data"][i]["is_enable"]: continue - cmd_db_path = settings["other_obc_data"][i]["db_path"] + r"CMD_DB/" + cmd_db_path = settings["other_obc_data"][i]["path_to_db"] + r"CMD_DB/" sgc_db, bct_db = LoadCmdCSV_( cmd_db_path, settings["other_obc_data"][i]["db_prefix"], @@ -134,7 +134,7 @@ def LoadOtherObcTlm(settings): for i in range(len(settings["other_obc_data"])): if not settings["other_obc_data"][i]["is_enable"]: continue - tlm_db_path = settings["other_obc_data"][i]["db_path"] + r"TLM_DB/calced_data/" + tlm_db_path = settings["other_obc_data"][i]["path_to_db"] + r"TLM_DB/calced_data/" tlm_db = LoadTlmCSV_( tlm_db_path, From 5e8b52520c983b5c66415bfb46a74b922eaba77e Mon Sep 17 00:00:00 2001 From: yutaro_ito <4793651-yutaro_ito@users.noreply.gitlab.com> Date: Tue, 25 Jul 2023 10:37:24 +0900 Subject: [PATCH 136/141] =?UTF-8?q?=E6=94=B9=E8=A1=8C=E6=88=BB=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f6c0365f3..e1fc2452e 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ $ python GenerateC2ACode.py ## 設定 `settings.json` にて記述する. -`is_main_obc` は,MOBC(地上局と通信するOBC.2nd OBCのtlm/cmdを取りまとめる)かそれ以外のOBC(2nd OBC.MOBCと通信するOBC)かを制御する. +`is_main_obc` は,MOBC(地上局と通信するOBC.2nd OBCのtlm/cmdを取りまとめる)かそれ以外のOBC(2nd OBC.MOBCと通信するOBC)かを制御する. `1` とした場合,MOBCを意図したコードが生成され,加えて以下が生成される. - 2nd_obc_command_definitions.h - 2nd_obc_telemetry_definitions.h From 98388c81827b3d0ea74a7413e081309c7c620ed4 Mon Sep 17 00:00:00 2001 From: sksat Date: Tue, 5 Sep 2023 13:13:27 +0900 Subject: [PATCH 137/141] apply arkedge/c2a-core v4 rename TlmCmd -> tlm_cmd --- my_mod/cmd_def.py | 6 +++--- my_mod/tlm_buffer.py | 4 ++-- my_mod/tlm_def.py | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/my_mod/cmd_def.py b/my_mod/cmd_def.py index 50a98ed76..1b2f24b93 100644 --- a/my_mod/cmd_def.py +++ b/my_mod/cmd_def.py @@ -9,7 +9,7 @@ def GenerateCmdDef(settings, sgc_db): - output_file_path = settings["path_to_src"] + r"src_user/TlmCmd/" + output_file_path = settings["path_to_src"] + r"src_user/tlm_cmd/" output_file_name_base = "command_definitions" DATA_SART_ROW = 3 @@ -97,7 +97,7 @@ def GenerateCmdDef(settings, sgc_db): def GenerateBctDef(settings, bct_db): - output_file_path = settings["path_to_src"] + r"src_user/TlmCmd/" + output_file_path = settings["path_to_src"] + r"src_user/tlm_cmd/" output_file_name = "block_command_definitions.h" DATA_SART_ROW = 2 @@ -191,7 +191,7 @@ def OutputCmdDefC_(file_path, body, settings): * @brief コマンド定義 * @note このコードは自動生成されています! */ -#include +#include #include "command_definitions.h" #include "command_source.h" diff --git a/my_mod/tlm_buffer.py b/my_mod/tlm_buffer.py index 4eb06b714..c151770bf 100644 --- a/my_mod/tlm_buffer.py +++ b/my_mod/tlm_buffer.py @@ -411,8 +411,8 @@ def OutputTlmBufferH_(file_path, name, body, settings): #include "./{_obc_name_lower}_telemetry_definitions.h" #include -#include -#include +#include +#include """[ 1: diff --git a/my_mod/tlm_def.py b/my_mod/tlm_def.py index e8ba39969..4fa64719d 100644 --- a/my_mod/tlm_def.py +++ b/my_mod/tlm_def.py @@ -7,7 +7,7 @@ def GenerateTlmDef(settings, tlm_db): - output_file_path = settings["path_to_src"] + r"src_user/TlmCmd/" + output_file_path = settings["path_to_src"] + r"src_user/tlm_cmd/" output_file_name_base = "telemetry_definitions" DATA_START_ROW = 8 @@ -155,7 +155,7 @@ def OutputTlmDefC_(file_path, body, settings): * @brief テレメトリ定義 * @note このコードは自動生成されています! */ -#include +#include #include "telemetry_definitions.h" #include "telemetry_source.h" From 55466966ccbad4c9efc6ae4b53888067adbb0fdb Mon Sep 17 00:00:00 2001 From: sksat Date: Tue, 3 Oct 2023 02:08:39 +0900 Subject: [PATCH 138/141] import ut-issl/c2a-tlm-cmd-code-generator ae-v2.0.0 --- tlm-cmd-code-generator/.flake8 | 8 + .../.github/ISSUE_TEMPLATE/action_item.md | 26 + .../.github/ISSUE_TEMPLATE/bug_report.md | 37 ++ .../.github/PULL_REQUEST_TEMPLATE.md | 23 + tlm-cmd-code-generator/.github/labels.yml | 55 ++ .../.github/workflows/actionlint.yml | 17 + .../.github/workflows/labeler.yml | 25 + .../.github/workflows/python_check_format.yml | 25 + .../.github/workflows/python_lint.yml | 27 + .../.github/workflows/validate-renovate.yml | 22 + tlm-cmd-code-generator/.gitignore | 16 + tlm-cmd-code-generator/GenerateC2ACode.py | 53 ++ tlm-cmd-code-generator/LICENSE | 21 + tlm-cmd-code-generator/README.md | 106 ++++ tlm-cmd-code-generator/my_mod/cmd_def.py | 325 +++++++++++ tlm-cmd-code-generator/my_mod/load_db.py | 148 +++++ tlm-cmd-code-generator/my_mod/tlm_buffer.py | 527 ++++++++++++++++++ tlm-cmd-code-generator/my_mod/tlm_def.py | 250 +++++++++ tlm-cmd-code-generator/pyproject.toml | 8 + tlm-cmd-code-generator/renovate.json | 8 + tlm-cmd-code-generator/requirements.txt | 0 tlm-cmd-code-generator/settings.json | 40 ++ 22 files changed, 1767 insertions(+) create mode 100644 tlm-cmd-code-generator/.flake8 create mode 100644 tlm-cmd-code-generator/.github/ISSUE_TEMPLATE/action_item.md create mode 100644 tlm-cmd-code-generator/.github/ISSUE_TEMPLATE/bug_report.md create mode 100644 tlm-cmd-code-generator/.github/PULL_REQUEST_TEMPLATE.md create mode 100644 tlm-cmd-code-generator/.github/labels.yml create mode 100644 tlm-cmd-code-generator/.github/workflows/actionlint.yml create mode 100644 tlm-cmd-code-generator/.github/workflows/labeler.yml create mode 100644 tlm-cmd-code-generator/.github/workflows/python_check_format.yml create mode 100644 tlm-cmd-code-generator/.github/workflows/python_lint.yml create mode 100644 tlm-cmd-code-generator/.github/workflows/validate-renovate.yml create mode 100644 tlm-cmd-code-generator/.gitignore create mode 100644 tlm-cmd-code-generator/GenerateC2ACode.py create mode 100644 tlm-cmd-code-generator/LICENSE create mode 100644 tlm-cmd-code-generator/README.md create mode 100644 tlm-cmd-code-generator/my_mod/cmd_def.py create mode 100644 tlm-cmd-code-generator/my_mod/load_db.py create mode 100644 tlm-cmd-code-generator/my_mod/tlm_buffer.py create mode 100644 tlm-cmd-code-generator/my_mod/tlm_def.py create mode 100644 tlm-cmd-code-generator/pyproject.toml create mode 100644 tlm-cmd-code-generator/renovate.json create mode 100644 tlm-cmd-code-generator/requirements.txt create mode 100644 tlm-cmd-code-generator/settings.json diff --git a/tlm-cmd-code-generator/.flake8 b/tlm-cmd-code-generator/.flake8 new file mode 100644 index 000000000..1d1919b57 --- /dev/null +++ b/tlm-cmd-code-generator/.flake8 @@ -0,0 +1,8 @@ +[flake8] +max-line-length = 100 +ignore = + # black と競合するので + E203, + E501, + W503, + W504 diff --git a/tlm-cmd-code-generator/.github/ISSUE_TEMPLATE/action_item.md b/tlm-cmd-code-generator/.github/ISSUE_TEMPLATE/action_item.md new file mode 100644 index 000000000..5c06b8b52 --- /dev/null +++ b/tlm-cmd-code-generator/.github/ISSUE_TEMPLATE/action_item.md @@ -0,0 +1,26 @@ +--- +name: Action Item +about: AI 管理用テンプレート +title: '' +labels: '' +assignees: '' + +--- + +## 概要 +ひとことで + +## 詳細 +詳しく + +## close条件 +どうなったらcloseできるか + +## 備考 +なにかあれば + +## 注意 +- 関連する Projects が存在する場合,それの紐付けを行うこと +- 可能ならば `priority` ラベルを付けること +- 可能ならば Assignees を設定すること +- close するときは結論を明記すること diff --git a/tlm-cmd-code-generator/.github/ISSUE_TEMPLATE/bug_report.md b/tlm-cmd-code-generator/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 000000000..7c03c968a --- /dev/null +++ b/tlm-cmd-code-generator/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,37 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +## 概要 +ひとことで + +## 詳細 +### 詳細症状 +どういうバグか + +### 発生条件 +発生した環境,症状,パラメタなど + +### 追加資料 +あればリンクなどを貼る + +## 必要な作業 +- [ ] あれして +- [ ] これする + +## 影響範囲 +tool類が全部死ぬ... みたいな + +## 補足 +何かれば + +## 注意 +- 関連する Projects が存在する場合,それの紐付けを行うこと +- 可能ならば `priority` ラベルを付けること +- 可能ならば Assignees を設定すること +- close するときは結論を明記すること diff --git a/tlm-cmd-code-generator/.github/PULL_REQUEST_TEMPLATE.md b/tlm-cmd-code-generator/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 000000000..82728e779 --- /dev/null +++ b/tlm-cmd-code-generator/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,23 @@ +## 概要 +ひとことで + +## Issue +- 関連する issue + +## 詳細 +詳しく + +## 検証結果 +test へのリンクや,検証結果へのリンク + +## 影響範囲 +XX系の動作がガラッと変わる,とか. + +## 補足 +何かあれば + +## 注意 +- 関連する Projects が存在する場合,それの紐付けを行うこと +- Assignees を設定すること +- 可能ならば Reviewers を設定すること +- 可能ならば `priority` ラベルを付けること diff --git a/tlm-cmd-code-generator/.github/labels.yml b/tlm-cmd-code-generator/.github/labels.yml new file mode 100644 index 000000000..60ca01d51 --- /dev/null +++ b/tlm-cmd-code-generator/.github/labels.yml @@ -0,0 +1,55 @@ +- name: "bug" + color: "d73a4a" + description: "Something isn't working" + +- name: "documentation" + color: "0075ca" + description: "Improvements or additions to documentation" + +- name: "duplicate" + color: "cfd8d7" + description: "This issue or pull request already exists" + +- name: "enhancement" + description: "New feature or request" + color: "a2eeef" + +- name: "good first issue" + description: "Good for newcomers" + color: "7057ff" + +- name: "help wanted" + description: "Extra attention is needed" + color: "008672" + +- name: "invalid" + description: "This doesn't seem right" + color: "e4e669" + +- name: "question" + description: "Further information is requested" + color: "d876e3" + +- name: "wontfix" + description: "This will not be worked on" + color: "ffffff" + +- name: "icebox" + description: "icebox or pending" + color: "c5def5" + +- name: "priority::high" + description: "priorityg high" + color: "d93f0b" + +- name: "priority::low" + description: "priority low" + color: "9dcce0" + +- name: "priority::medium" + description: "priority medium" + color: "fbca04" + +- name: "tools" + description: "" + color: "510f70" diff --git a/tlm-cmd-code-generator/.github/workflows/actionlint.yml b/tlm-cmd-code-generator/.github/workflows/actionlint.yml new file mode 100644 index 000000000..4ef847aaf --- /dev/null +++ b/tlm-cmd-code-generator/.github/workflows/actionlint.yml @@ -0,0 +1,17 @@ +name: reviewdog / actionlint + +on: + pull_request: + paths: + - '.github/workflows/**' + +jobs: + actionlint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: reviewdog/action-actionlint@v1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + reporter: github-pr-review + fail_on_error: true diff --git a/tlm-cmd-code-generator/.github/workflows/labeler.yml b/tlm-cmd-code-generator/.github/workflows/labeler.yml new file mode 100644 index 000000000..82cb5d166 --- /dev/null +++ b/tlm-cmd-code-generator/.github/workflows/labeler.yml @@ -0,0 +1,25 @@ +name: labeler + +on: + push: + branches: + - main + pull_request: + paths: + - .github/workflows/labeler.yml + - .github/labels.yml + +jobs: + labeler: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Run Labeler + uses: crazy-max/ghaction-github-labeler@v4 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + yaml-file: .github/labels.yml + skip-delete: false + dry-run: ${{ github.ref != 'refs/heads/main' }} diff --git a/tlm-cmd-code-generator/.github/workflows/python_check_format.yml b/tlm-cmd-code-generator/.github/workflows/python_check_format.yml new file mode 100644 index 000000000..ca77e90f5 --- /dev/null +++ b/tlm-cmd-code-generator/.github/workflows/python_check_format.yml @@ -0,0 +1,25 @@ +name: reviewdog / python format check + +on: + push: + branches: + - main + pull_request: + +jobs: + black_format: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + # - name: check python format with black + # uses: psf/black@stable + + - uses: reviewdog/action-black@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + # reporter: github-pr-review # TODO: いい感じになったら直す + reporter: github-pr-check + filter_mode: nofilter + fail_on_error: true + level: warning diff --git a/tlm-cmd-code-generator/.github/workflows/python_lint.yml b/tlm-cmd-code-generator/.github/workflows/python_lint.yml new file mode 100644 index 000000000..e2c78d63a --- /dev/null +++ b/tlm-cmd-code-generator/.github/workflows/python_lint.yml @@ -0,0 +1,27 @@ +name: reviewdog / lint python + +on: + push: + branches: + - main + pull_request: + +jobs: + flake8_lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up python environment + uses: actions/setup-python@v4 + with: + python-version: "3.8" + + - name: flake8 Lint + uses: reviewdog/action-flake8@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + reporter: github-pr-review + filter_mode: nofilter + fail_on_error: true + level: warning diff --git a/tlm-cmd-code-generator/.github/workflows/validate-renovate.yml b/tlm-cmd-code-generator/.github/workflows/validate-renovate.yml new file mode 100644 index 000000000..84b52217e --- /dev/null +++ b/tlm-cmd-code-generator/.github/workflows/validate-renovate.yml @@ -0,0 +1,22 @@ +name: validate / renovate.json + +on: + pull_request: + paths: + - 'renovate.json' + - '.github/workflows/validate-renovate.yml' + +jobs: + validate-renovate: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + + - name: install + run: | + npm install -g renovate + - name: validate + run: | + renovate-config-validator diff --git a/tlm-cmd-code-generator/.gitignore b/tlm-cmd-code-generator/.gitignore new file mode 100644 index 000000000..abe7f23f5 --- /dev/null +++ b/tlm-cmd-code-generator/.gitignore @@ -0,0 +1,16 @@ +# OSX +.DS_Store +.AppleDouble +.LSOverride +Icon + +# Thumbnails +._* + +# Files that might appear on external disk +.Spotlight-V100 +.Trashes + +# others +*.pyc +gstos_files/* diff --git a/tlm-cmd-code-generator/GenerateC2ACode.py b/tlm-cmd-code-generator/GenerateC2ACode.py new file mode 100644 index 000000000..8ec163d10 --- /dev/null +++ b/tlm-cmd-code-generator/GenerateC2ACode.py @@ -0,0 +1,53 @@ +# coding: UTF-8 +""" +python 3.7以上を要求 +""" + +import json +import sys + +import my_mod.load_db +import my_mod.cmd_def +import my_mod.tlm_def +import my_mod.tlm_buffer + + +# import pprint +# import os.path +# import msvcrt # Enter不要な入力用 +# import subprocess + + +# 環境変数 +DEBUG = 0 +# 0 : Release +# 1 : all +SETTING_FILE_PATH = "settings.json" + + +def main(): + with open(SETTING_FILE_PATH, mode="r") as fh: + settings = json.load(fh) + # print(settings["path_to_src"]); + + cmd_db = my_mod.load_db.LoadCmdDb(settings) + tlm_db = my_mod.load_db.LoadTlmDb(settings) + # pprint.pprint(cmd_db) + # pprint.pprint(tlm_db) + # print(tlm_db) + + my_mod.cmd_def.GenerateCmdDef(settings, cmd_db["sgc"]) + my_mod.cmd_def.GenerateBctDef(settings, cmd_db["bct"]) + my_mod.tlm_def.GenerateTlmDef(settings, tlm_db["tlm"]) + + if settings["is_main_obc"]: + my_mod.cmd_def.GenerateOtherObcCmdDef(settings, cmd_db["other_obc"]) + my_mod.tlm_def.GenerateOtherObcTlmDef(settings, tlm_db["other_obc"]) + my_mod.tlm_buffer.GenerateTlmBuffer(settings, tlm_db["other_obc"]) + + print("Completed!") + sys.exit(0) + + +if __name__ == "__main__": + main() diff --git a/tlm-cmd-code-generator/LICENSE b/tlm-cmd-code-generator/LICENSE new file mode 100644 index 000000000..89f748ff8 --- /dev/null +++ b/tlm-cmd-code-generator/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Intelligent Space Systems Laboratory, The University of Tokyo + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/tlm-cmd-code-generator/README.md b/tlm-cmd-code-generator/README.md new file mode 100644 index 000000000..e1fc2452e --- /dev/null +++ b/tlm-cmd-code-generator/README.md @@ -0,0 +1,106 @@ +# c2a-tlm-cmd-code-generator +[TlmCmd DB](https://github.com/ut-issl/tlm-cmd-db)からC2Aのコードを生成するためのスクリプト + +以下が自動生成される. +- command_definitions.c +- command_definitions.h +- telemetry_definitions.c +- telemetry_definitions.h +- block_command_definitions.h + +## 実行 +``` +$ python GenerateC2ACode.py +``` + +## 設定 +`settings.json` にて記述する. + +`is_main_obc` は,MOBC(地上局と通信するOBC.2nd OBCのtlm/cmdを取りまとめる)かそれ以外のOBC(2nd OBC.MOBCと通信するOBC)かを制御する. +`1` とした場合,MOBCを意図したコードが生成され,加えて以下が生成される. +- 2nd_obc_command_definitions.h +- 2nd_obc_telemetry_definitions.h +- 2nd_obc_telemetry_buffer.c +- 2nd_obc_telemetry_buffer.h +- 2nd_obc_telemetry_data_definitions.h + +``` +{ + # `src_core`, `src_user` のあるディレクトリへのパス + "path_to_src" : "../../c2a/src/", + # テレコマ DB のあるディレクトリへのパス + "path_to_db" : "../../c2a/database/", + # TlmCmdDBのファイル名の接頭辞 + "db_prefix" : "SAMPLE_MOBC", + # TLM ID の定義域 + "tlm_id_range" : ["0x00", "0x100"], + # Cmd DB の Name に "Cmd_" の接頭辞が含まれるか?(今後は含まれないのが基本とする) + "is_cmd_prefixed_in_db" : 0, + # 入力 Tlm Cmd DB のエンコーディング + "input_file_encoding" : "utf-8", + # 出力ファイルのエンコーディング + "output_file_encoding" : "utf-8", + # MOBCか?(他のOBCのtlm/cmdを取りまとめるか?) 0/1 + # 2nd OBCのコードを生成するときなどは 0 にする + # 0 の場合,以後のパラメタは無効 + "is_main_obc" : 1, + "other_obc_data" : [ + { + # OBC名 + "name" : "AOBC", + # コードを生成するか? + "is_enable" : 1, + "db_prefix" : "SAMPLE_AOBC", + "tlm_id_range" : ["0x90", "0xc0"], + "is_cmd_prefixed_in_db" : 0, + "input_file_encoding" : "utf-8", + # DBがあるディレクトリへのパス(絶対でも相対でもOK) + "path_to_db" : "../../c2a_sample_aobc/database/", + # MOBC で保持するテレメの TLM ID の最大値(=テレメ種類数) + "max_tlm_num" : 256, + "driver_path" : "Aocs/", + "driver_type" : "AOBC_Driver", + "driver_name" : "aobc", + "code_when_tlm_not_found" : "aobc_driver->info.comm.rx_err_code = AOBC_RX_ERR_CODE_TLM_NOT_FOUND;" + }, + { + # OBC名 + "name" : "TOBC", + # コードを生成するか? + "is_enable" : 1, + "db_prefix" : "SAMPLE_TOBC", + "tlm_id_range" : ["0xc0", "0xf0"], + "is_cmd_prefixed_in_db" : 0, + "input_file_encoding" : "utf-8", + # DBがあるディレクトリへのパス(絶対でも相対でもOK) + "path_to_db" : ""../../c2a_sample_tobc/database/", + # MOBC で保持するテレメの TLM ID の最大値(=テレメ種類数) + "max_tlm_num" : 256, + "driver_path" : "Thermal/", + "driver_type" : "TOBC_Driver", + "driver_name" : "tobc", + "code_when_tlm_not_found" : "tobc_driver->info.comm.rx_err_code = TOBC_RX_ERR_CODE_TLM_NOT_FOUND;" + } + ] +} +``` + +## 開発方針 +- `main`: リリース版 +- `feature/*` : 開発ブランチ + +というブランチを用いる. + +[C2A Core](https://github.com/ut-issl/c2a-core) との互換性などは,[Releases](https://github.com/ut-issl/c2a-tlm-cmd-code-generator/releases) を参照すること([詳細](https://github.com/ut-issl/c2a-core/tree/develop/Docs/.General/release.md)) + +## 要求 +- python 3.7 以上 +- 必要ライブラリは `./requirements.txt` に記載. + - なお,現在は標準ライブラリのみしか使っていない + - 以下で一括インストール可能 +``` +$ pip install -r requirements.txt +``` + +## その他 +- MOBCと2nd OBCのC2A間通信の例は (TBA). diff --git a/tlm-cmd-code-generator/my_mod/cmd_def.py b/tlm-cmd-code-generator/my_mod/cmd_def.py new file mode 100644 index 000000000..1b2f24b93 --- /dev/null +++ b/tlm-cmd-code-generator/my_mod/cmd_def.py @@ -0,0 +1,325 @@ +# coding: UTF-8 +""" +cmd def +""" + +import sys + +# import pprint + + +def GenerateCmdDef(settings, sgc_db): + output_file_path = settings["path_to_src"] + r"src_user/tlm_cmd/" + output_file_name_base = "command_definitions" + + DATA_SART_ROW = 3 + + body_c = "" + body_h = "" + # " cmd_table[Cmd_CODE_NOP].cmd_func = Cmd_NOP;" + # " Cmd_CODE_NOP = 0x0000," + for i in range(DATA_SART_ROW, len(sgc_db)): + comment = sgc_db[i][0] + name = sgc_db[i][1] + cmd_id = sgc_db[i][3] + if comment == "" and name == "": # CommentもNameも空白なら打ち切り + break + if comment != "": # Comment + continue + + cmd_name, cmd_code = GetCmdNameAndCmdCode_(name, settings["is_cmd_prefixed_in_db"]) + # print(cmd_name) + # print(cmd_code) + body_c += " cmd_table[" + cmd_code + "].cmd_func = " + cmd_name + ";\n" + body_h += " " + cmd_code + " = " + cmd_id + ",\n" + + body_c += "\n" + for i in range(DATA_SART_ROW, len(sgc_db)): + comment = sgc_db[i][0] + name = sgc_db[i][1] + cmd_id = sgc_db[i][3] + if comment == "" and name == "": # CommentもNameも空白なら打ち切り + break + if comment != "": # Comment + continue + + param_num = int(sgc_db[i][4]) + type_list = [ + sgc_db[i][5], + sgc_db[i][7], + sgc_db[i][9], + sgc_db[i][11], + sgc_db[i][13], + sgc_db[i][15], + ] + cmd_name, cmd_code = GetCmdNameAndCmdCode_(name, settings["is_cmd_prefixed_in_db"]) + + # パラメタ長の整合性チェック + for j in range(len(type_list)): + err_flag = 0 + if j < param_num and type_list[j] == "": + err_flag = 1 + if j >= param_num and type_list[j] != "": + err_flag = 1 + if err_flag: + print("Error: Cmd DB Err at " + name, file=sys.stderr) + sys.exit(1) + + # パラメタ長のカウント + conv_tpye_to_size = { + "int8_t": "CA_PARAM_SIZE_TYPE_1BYTE", + "int16_t": "CA_PARAM_SIZE_TYPE_2BYTE", + "int32_t": "CA_PARAM_SIZE_TYPE_4BYTE", + "uint8_t": "CA_PARAM_SIZE_TYPE_1BYTE", + "uint16_t": "CA_PARAM_SIZE_TYPE_2BYTE", + "uint32_t": "CA_PARAM_SIZE_TYPE_4BYTE", + "float": "CA_PARAM_SIZE_TYPE_4BYTE", + "double": "CA_PARAM_SIZE_TYPE_8BYTE", + "raw": "CA_PARAM_SIZE_TYPE_RAW", + } + for j in range(param_num): + index = j // 2 + subindex = "second" if j % 2 else "first" + body_c += ( + " cmd_table[" + + cmd_code + + "].param_size_infos[" + + str(index) + + "].packed_info.bit." + + subindex + + " = " + + conv_tpye_to_size[type_list[j]] + + ";\n" + ) + + OutputCmdDefC_(output_file_path + output_file_name_base + ".c", body_c, settings) + OutputCmdDefH_(output_file_path + output_file_name_base + ".h", body_h, settings) + + +def GenerateBctDef(settings, bct_db): + output_file_path = settings["path_to_src"] + r"src_user/tlm_cmd/" + output_file_name = "block_command_definitions.h" + + DATA_SART_ROW = 2 + + body_h = "" + for i in range(DATA_SART_ROW, len(bct_db)): + comment = bct_db[i][0] + name = bct_db[i][1] + bc_id = bct_db[i][3] + description = bct_db[i][10] + + # エスケープ解除 + name = name.replace("@@", ",") + description = description.replace("@@", ",") + + if comment == "" and name == "": # CommentもNameも空白なら打ち切り + break + + if comment == "**": # New Line Comment + body_h += "\n // " + name + "\n" + elif comment != "": # Comment + body_h += " // " + name + "\n" + else: + # " BC_SL_INITIAL_TO_INITIAL = 0," + if description == "": + body_h += " " + name + " = " + bc_id + ",\n" + else: + body_h += " " + name + " = " + bc_id + ", // " + description + "\n" + + OutputBctDef_(output_file_path + output_file_name, body_h, settings) + + +def GenerateOtherObcCmdDef(settings, other_obc_dbs): + # pprint.pprint(other_obc_dbs) + DATA_SART_ROW = 3 + for i in range(len(settings["other_obc_data"])): + if not settings["other_obc_data"][i]["is_enable"]: + continue + obc_name = settings["other_obc_data"][i]["name"] + name_upper = obc_name.upper() + name_lower = obc_name.lower() + # name_capit = obc_name.capitalize() + # print(name_upper) + # print(name_lower) + # print(name_capit) + sgc_db = other_obc_dbs[obc_name] + # pprint.pprint(sgc_db) + + body_h = "" + # " TOBC_Cmd_CODE_NOP = 0x0000," + for j in range(DATA_SART_ROW, len(sgc_db)): + comment = sgc_db[j][0] + name = sgc_db[j][1] + cmd_id = sgc_db[j][3] + if comment == "" and name == "": # CommentもNameも空白なら打ち切り + break + if comment != "": # Comment + continue + # print(name) + _, cmd_code = GetCmdNameAndCmdCode_( + name, settings["other_obc_data"][i]["is_cmd_prefixed_in_db"] + ) + cmd_code = name_upper + "_" + cmd_code + body_h += " " + cmd_code + " = " + cmd_id + ",\n" + # print(body_h) + output_file_path = ( + settings["path_to_src"] + + r"src_user/Drivers/" + + settings["other_obc_data"][i]["driver_path"] + + name_lower + + "_command_definitions.h" + ) + OutputOtherObcCmdDefH_(output_file_path, obc_name, body_h, settings) + + +def GetCmdNameAndCmdCode_(name, is_cmd_prefixed_in_db): + if is_cmd_prefixed_in_db: + cmd_name = name + else: + cmd_name = "Cmd_" + name + cmd_code = cmd_name.replace("Cmd_", "Cmd_CODE_") + return cmd_name, cmd_code + + +def OutputCmdDefC_(file_path, body, settings): + output = "" + output += """ +#pragma section REPRO +/** + * @file + * @brief コマンド定義 + * @note このコードは自動生成されています! + */ +#include +#include "command_definitions.h" +#include "command_source.h" + +void CA_load_cmd_table(CA_CmdInfo cmd_table[CA_MAX_CMDS]) +{ +"""[ + 1: + ] # 最初の改行を除く + + output += body + + output += """ +} + +#pragma section +"""[ + 1: + ] # 最初の改行を除く + + with open(file_path, mode="w", encoding=settings["output_file_encoding"]) as fh: + fh.write(output) + + +def OutputCmdDefH_(file_path, body, settings): + output = "" + output += """ +/** + * @file + * @brief コマンド定義 + * @note このコードは自動生成されています! + */ +#ifndef COMMAND_DEFINITIONS_H_ +#define COMMAND_DEFINITIONS_H_ + +typedef enum +{ +"""[ + 1: + ] # 最初の改行を除く + + output += body + + output += """ + + Cmd_CODE_MAX +} CMD_CODE; + +#endif +"""[ + 1: + ] # 最初の改行を除く + + with open(file_path, mode="w", encoding=settings["output_file_encoding"]) as fh: + fh.write(output) + + +def OutputBctDef_(file_path, body, settings): + output = "" + output += """ +/** + * @file + * @brief ブロックコマンド定義 + * @note このコードは自動生成されています! + */ +#ifndef BLOCK_COMMAND_DEFINITIONS_H_ +#define BLOCK_COMMAND_DEFINITIONS_H_ + +// 登録されるBlockCommandTableのblock番号を規定 +typedef enum +{ +"""[ + 1: + ] # 最初の改行を除く + + output += body + + output += """ + + BC_ID_MAX // BCT 自体のサイズは BCT_MAX_BLOCKS で規定 +} BC_DEFAULT_ID; + +void BC_load_defaults(void); + +#endif +"""[ + 1: + ] # 最初の改行を除く + + with open(file_path, mode="w", encoding=settings["output_file_encoding"]) as fh: + fh.write(output) + + +def OutputOtherObcCmdDefH_(file_path, name, body, settings): + name_upper = name.upper() + name_lower = name.lower() + name_capit = name.capitalize() + + output = "" + output += """ +/** + * @file + * @brief コマンド定義 + * @note このコードは自動生成されています! + */ +#ifndef {_obc_name_upper}_COMMAND_DEFINITIONS_H_ +#define {_obc_name_upper}_COMMAND_DEFINITIONS_H_ + +typedef enum +{{ +"""[ + 1: + ] # 最初の改行を除く + + output += body + + output += """ + + {_obc_name_upper}_Cmd_CODE_MAX +}} {_obc_name_upper}_CMD_CODE; + +#endif +"""[ + 1: + ] # 最初の改行を除く + + with open(file_path, mode="w", encoding=settings["output_file_encoding"]) as fh: + fh.write( + output.format( + _obc_name_upper=name_upper, _obc_name_lower=name_lower, _obc_name_capit=name_capit + ) + ) diff --git a/tlm-cmd-code-generator/my_mod/load_db.py b/tlm-cmd-code-generator/my_mod/load_db.py new file mode 100644 index 000000000..b5fb3f8de --- /dev/null +++ b/tlm-cmd-code-generator/my_mod/load_db.py @@ -0,0 +1,148 @@ +# coding: UTF-8 +""" +DB読み込み +""" + +import os +import sys +import csv +import re # 正規表現 + +# import pprint + + +def LoadCmdDb(settings): + cmd_db_path = settings["path_to_db"] + r"CMD_DB/" + + sgc_db, bct_db = LoadCmdCSV_( + cmd_db_path, settings["db_prefix"], settings["input_file_encoding"] + ) + + other_obc_dbs = {} + if settings["is_main_obc"]: + other_obc_dbs = LoadOtherObcCmd_(settings) + + # TODO: 重複チェックをする + + # print(sgc_db) + # print(bct_db) + return {"sgc": sgc_db, "bct": bct_db, "other_obc": other_obc_dbs} + + +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=encoding) as fh: + reader = csv.reader(fh) + sgc_db = [row for row in reader] + with open(bct_db_path, mode="r", encoding=encoding) as fh: + reader = csv.reader(fh) + bct_db = [row for row in reader] + + return sgc_db, bct_db + + +def LoadTlmDb(settings): + tlm_db_path = settings["path_to_db"] + r"TLM_DB/calced_data/" + + 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"]: + other_obc_dbs = LoadOtherObcTlm(settings) + + # TODO: 重複チェックをする + + return {"tlm": tlm_db, "other_obc": other_obc_dbs} + + +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] + tlm_names = [re.sub(".csv$", "", file) for file in tlm_names] + # pprint.pprint(tlm_names) + # print(len(tlm_names)) + + tlm_db = [] + + 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=encoding) as fh: + reader = csv.reader(fh) + sheet = [row for row in reader] + # pprint.pprint(sheet) + # print(sheet) + enable_flag = sheet[2][2] # FIXME: Enable/Disable を取得.マジックナンバーで指定してしまってる. + if enable_flag != "ENABLE": + continue + tlm_id = sheet[1][2] # FIXME: テレメIDを取得.マジックナンバーで指定してしまってる. + if not int(tlm_id_range[0], 0) <= int(tlm_id, 0) < int(tlm_id_range[1], 0): + print( + "Error: TLM ID is invalid at " + db_prefix + "_TLM_DB_" + tlm_name + ".csv", + file=sys.stderr, + ) + sys.exit(1) + raw_local_vars = ( + sheet[1][3].replace("%%", "").split("##") + ) # FIXME: ローカル変数を取得.マジックナンバーで指定してしまってる. + local_vars = [] + for raw_local_var in raw_local_vars: + local_var = raw_local_var.strip().replace("@@", ",") + if len(local_var) > 0: + local_vars.append(local_var) + tlm_db.append( + {"tlm_id": tlm_id, "tlm_name": tlm_name, "local_vars": local_vars, "data": sheet} + ) + # tlm_db.append({'tlm_id': tlm_id, 'tlm_name': tlm_name, 'data': 1}) + + tlm_db.sort(key=lambda x: x["tlm_id"]) + + return tlm_db + + +def LoadOtherObcCmd_(settings): + other_obc_dbs = {} + + for i in range(len(settings["other_obc_data"])): + if not settings["other_obc_data"][i]["is_enable"]: + continue + cmd_db_path = settings["other_obc_data"][i]["path_to_db"] + r"CMD_DB/" + 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) + + # pprint.pprint(settings["other_obc_data"]) + # pprint.pprint(other_obc_dbs) + return other_obc_dbs + + +def LoadOtherObcTlm(settings): + other_obc_dbs = {} + + for i in range(len(settings["other_obc_data"])): + if not settings["other_obc_data"][i]["is_enable"]: + continue + tlm_db_path = settings["other_obc_data"][i]["path_to_db"] + r"TLM_DB/calced_data/" + + tlm_db = LoadTlmCSV_( + 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 + + # pprint.pprint(other_obc_dbs) + return other_obc_dbs diff --git a/tlm-cmd-code-generator/my_mod/tlm_buffer.py b/tlm-cmd-code-generator/my_mod/tlm_buffer.py new file mode 100644 index 000000000..c151770bf --- /dev/null +++ b/tlm-cmd-code-generator/my_mod/tlm_buffer.py @@ -0,0 +1,527 @@ +# coding: UTF-8 +""" +tlm buffer +""" + +import sys + +# from collections import OrderedDict +# import pprint + + +def GenerateTlmBuffer(settings, other_obc_dbs): + DATA_START_ROW = 8 + + for i in range(len(settings["other_obc_data"])): + if not settings["other_obc_data"][i]["is_enable"]: + continue + obc_name = settings["other_obc_data"][i]["name"] + driver_type = settings["other_obc_data"][i]["driver_type"] + driver_name = settings["other_obc_data"][i]["driver_name"] + max_tlm_num = settings["other_obc_data"][i]["max_tlm_num"] + + tlm_db = other_obc_dbs[obc_name] + + body_c = "" + body_h = "" + tlmdef_body_h = "" + + for tlm in tlm_db: + tlm_name = tlm["tlm_name"] + tlm_name_lower = tlm_name.lower() + body_c += ( + "static DS_ERR_CODE {_obc_name_upper}_analyze_tlm_" + + tlm_name_lower + + "_(const CommonTlmPacket* packet, {_obc_name_upper}_TLM_CODE tlm_id, " + + driver_type + + "* " + + driver_name + + ");\n" + ) + + body_c += "\n" + body_c += "static CommonTlmPacket {_obc_name_upper}_ctp_;\n" + body_c += "\n" + + body_h += "typedef struct " + driver_type + " " + driver_type + ";\n" + body_h += "\n" + body_h += "#define {_obc_name_upper}_MAX_TLM_NUM (" + str(max_tlm_num) + ")\n" + body_h += "\n" + body_h += "typedef struct\n" + body_h += "{{\n" + body_h += " CommonTlmPacket packet; //!< 最新のテレメパケットを保持\n" + body_h += " uint8_t is_null_packet; //!< 一度でもテレメを受信しているか?(空配列が読み出されるのを防ぐため)\n" + body_h += "}} {_obc_name_upper}_TlmBufferElem;\n" + body_h += "\n" + body_h += "typedef struct\n" + body_h += "{{\n" + body_h += " {_obc_name_upper}_TlmBufferElem tlm[{_obc_name_upper}_MAX_TLM_NUM]; //!< TLM ID ごとに保持\n" + body_h += "}} {_obc_name_upper}_TlmBuffer;\n" + body_h += "\n" + + tlmdef_body_h += "typedef struct\n" + tlmdef_body_h += "{{\n" + for tlm in tlm_db: + tlm_name = tlm["tlm_name"] + tlm_name_lower = tlm_name.lower() + + # pprint.pprint(tlm['data'][DATA_START_ROW:]) + last_var_type = "" + tlm_struct_tree = {} # python3.7以上を想定しているので,キーの順番は保存されていることが前提 + # tlm_struct_tree = collections.OrderedDict() # やっぱこっちで + for j in range(DATA_START_ROW, len(tlm["data"])): + comment = tlm["data"][j][0] + name = EscapeTlmElemName_(tlm["data"][j][1]) + var_type = tlm["data"][j][2] + if comment == "" and name == "": # CommentもNameも空白なら打ち切り + break + if comment != "": + continue + if name == "": + continue + if var_type == "": + var_type = last_var_type + last_var_type = var_type + if last_var_type == "": + continue + + # name_tree = name.lower().split(".")[2:] # OBC名.テレメ名.HOGE.FUGA を想定 + name_tree = name.lower().split(".") + name_path = "/".join(name_tree) + if SetStructTree_(tlm_struct_tree, name_path, var_type): + print("Error: Tlm DB Struct Parse Err at " + name, file=sys.stderr) + sys.exit(1) + + # pprint.pprint(tlm_struct_tree) + # for k, v in tlm_struct_tree.items(): + # print(k) + # print(v) + # print("") + + tlmdef_body_h += GenerateStructDef_(tlm_struct_tree, tlm_name_lower) + + tlmdef_body_h += "}} {_obc_name_upper}_TlmData;\n" + + body_h += ( + "void {_obc_name_upper}_init_tlm_buffer(" + driver_type + "* " + driver_name + ");\n" + ) + body_h += "\n" + body_h += ( + "DS_ERR_CODE {_obc_name_upper}_buffer_tlm_packet(DS_StreamConfig* p_stream_config, " + + driver_type + + "* " + + driver_name + + ");\n" + ) + body_h += "\n" + body_h += ( + "TF_TLM_FUNC_ACK {_obc_name_upper}_pick_up_tlm_buffer(const " + + driver_type + + "* " + + driver_name + + ", {_obc_name_upper}_TLM_CODE tlm_id, uint8_t* packet, uint16_t* len, uint16_t max_len);\n" + ) + + body_c += ( + "void {_obc_name_upper}_init_tlm_buffer(" + driver_type + "* " + driver_name + ")\n" + ) + body_c += "{{\n" + body_c += " // packet などは,上位の driver の初期化で driver もろとも memset 0x00 されていると期待して,ここではしない\n" + body_c += " int i = 0;\n" + body_c += " for (i = 0; i < {_obc_name_upper}_MAX_TLM_NUM; ++i)\n" + body_c += " {{\n" + body_c += " " + driver_name + "->tlm_buffer.tlm[i].is_null_packet = 1;\n" + body_c += " }}\n" + body_c += "}}\n" + body_c += "\n" + body_c += ( + "DS_ERR_CODE {_obc_name_upper}_buffer_tlm_packet(DS_StreamConfig* p_stream_config, " + + driver_type + + "* " + + driver_name + + ")\n" + ) + body_c += "{{\n" + + body_c += " {_obc_name_upper}_TLM_CODE tlm_id;\n" + body_c += " DS_ERR_CODE ret;\n" + body_c += "\n" + body_c += " ret = CTP_get_ctp_from_dssc(p_stream_config, &{_obc_name_upper}_ctp_);\n" + body_c += " if (ret != DS_ERR_CODE_OK) return ret;\n" + body_c += "\n" + body_c += " tlm_id = ({_obc_name_upper}_TLM_CODE)CTP_get_id(&{_obc_name_upper}_ctp_);\n" + body_c += "\n" + + body_c += " switch (tlm_id)\n" + body_c += " {{\n" + for tlm in tlm_db: + tlm_name = tlm["tlm_name"] + tlm_name_upper = tlm_name.upper() + tlm_name_lower = tlm_name.lower() + body_c += " case {_obc_name_upper}_Tlm_CODE_" + tlm_name_upper + ":\n" + body_c += ( + " return {_obc_name_upper}_analyze_tlm_" + + tlm_name_lower + + "_(&{_obc_name_upper}_ctp_, tlm_id, " + + driver_name + + ");\n" + ) + body_c += " default:\n" + body_c += " " + settings["other_obc_data"][i]["code_when_tlm_not_found"] + "\n" + body_c += " return DS_ERR_CODE_ERR;\n" + body_c += " }}\n" + body_c += "}}\n" + body_c += "\n" + for tlm in tlm_db: + conv_tpye_to_temp = { + "int8_t": "temp_i8", + "int16_t": "temp_i16", + "int32_t": "temp_i32", + "uint8_t": "temp_u8", + "uint16_t": "temp_u16", + "uint32_t": "temp_u32", + "float": "temp_f", + "double": "temp_d", + } + conv_tpye_to_size = { + "int8_t": 1, + "int16_t": 2, + "int32_t": 4, + "uint8_t": 1, + "uint16_t": 2, + "uint32_t": 4, + "float": 4, + "double": 8, + } + tlm_name = tlm["tlm_name"] + tlm_name_upper = tlm_name.upper() + tlm_name_lower = tlm_name.lower() + + body_c += ( + "static DS_ERR_CODE {_obc_name_upper}_analyze_tlm_" + + tlm_name_lower + + "_(const CommonTlmPacket* packet, {_obc_name_upper}_TLM_CODE tlm_id, " + + driver_type + + "* " + + driver_name + + ")\n" + ) + body_c += "{{\n" + body_c += " const uint8_t* f = packet->packet;\n" + for k, v in conv_tpye_to_temp.items(): + if k == "float": + body_c += " " + k + " " + v + " = 0.0f;\n" + elif k == "double": + body_c += " " + k + " " + v + " = 0.0;\n" + else: + body_c += " " + k + " " + v + " = 0;\n" + body_c += "\n" + body_c += " // GS へのテレメ中継のためのバッファーへのコピー\n" + body_c += ( + " CTP_copy_packet(&(" + + driver_name + + "->tlm_buffer.tlm[tlm_id].packet), packet);\n" + ) + body_c += " " + driver_name + "->tlm_buffer.tlm[tlm_id].is_null_packet = 0;\n" + body_c += " // TODO: CRC チェック\n" + body_c += "\n" + + body_c += " // MOBC 内部でテレメデータへアクセスしやすいようにするための構造体へのパース\n" + last_var_type = "" + for j in range(DATA_START_ROW, len(tlm["data"])): + comment = tlm["data"][j][0] + name = EscapeTlmElemName_(tlm["data"][j][1]) + var_type = tlm["data"][j][2] + if comment == "" and name == "": # CommentもNameも空白なら打ち切り + break + if comment != "": + continue + if name == "": + continue + if var_type == "": + var_type = last_var_type + last_var_type = var_type + if last_var_type == "": + continue + + oct_pos = int(tlm["data"][j][5]) + bit_pos = int(tlm["data"][j][6]) + bit_len = int(tlm["data"][j][7]) + is_compression = 0 # テレメ圧縮フラグ for ビットフィールドをつかってる奴ら + if tlm["data"][j][2] == "" or tlm["data"][j + 1][2] == "": + is_compression = 1 + if ( + tlm["data"][j + 1][0] == "" + and tlm["data"][j + 1][1] == "" + and tlm["data"][j][2] != "" + ): # 最終行の除外 + is_compression = 0 + + # name_tree = name.lower().split(".")[2:] # OBC名.テレメ名.HOGE.FUGA を想定 + name_tree = name.lower().split(".") + name_path = ".".join(name_tree) + var_name = driver_name + "->tlm_data." + tlm_name_lower + "." + name_path + if is_compression: + body_c += ( + " ENDIAN_memcpy(&" + + conv_tpye_to_temp[var_type] + + ", &(f[" + + str(oct_pos) + + "]), " + + str(conv_tpye_to_size[var_type]) + + ");\n" + ) + body_c += ( + " " + + conv_tpye_to_temp[var_type] + + " >>= " + + str(conv_tpye_to_size[var_type] * 8 - bit_pos - bit_len) + + ";\n" + ) + body_c += ( + " " + + conv_tpye_to_temp[var_type] + + " &= " + + hex(int("0b" + "1" * bit_len, 2)) + + ";\n" + ) + body_c += " " + var_name + " = " + conv_tpye_to_temp[var_type] + ";\n" + else: + body_c += ( + " ENDIAN_memcpy(&(" + + var_name + + "), &(f[" + + str(oct_pos) + + "]), " + + str(conv_tpye_to_size[var_type]) + + ");\n" + ) + + body_c += " // TODO: ビットフィールドをつかっている系は,様々なパターンがあり得るので,今後,バグが出ないか注視する\n" + body_c += "\n" + body_c += " // ワーニング回避\n" + for k, v in conv_tpye_to_temp.items(): + body_c += " (void)" + v + ";\n" + body_c += "\n" + body_c += " return DS_ERR_CODE_OK;\n" + body_c += "}}\n" + body_c += "\n" + + body_c += ( + "TF_TLM_FUNC_ACK {_obc_name_upper}_pick_up_tlm_buffer(const " + + driver_type + + "* " + + driver_name + + ", {_obc_name_upper}_TLM_CODE tlm_id, uint8_t* packet, uint16_t* len, uint16_t max_len)\n" + ) + body_c += "{{\n" + body_c += " const CommonTlmPacket* buffered_packet;\n" + body_c += "\n" + body_c += ( + " if (tlm_id >= {_obc_name_upper}_MAX_TLM_NUM) return TF_TLM_FUNC_ACK_NOT_DEFINED;\n" + ) + body_c += ( + " if (" + + driver_name + + "->tlm_buffer.tlm[tlm_id].is_null_packet) return TF_TLM_FUNC_ACK_NULL_PACKET;\n" + ) + body_c += "\n" + body_c += " buffered_packet = &(" + driver_name + "->tlm_buffer.tlm[tlm_id].packet);\n" + body_c += " *len = CTP_get_packet_len(buffered_packet);\n" + body_c += "\n" + body_c += " if (*len > max_len) return TF_TLM_FUNC_ACK_TOO_SHORT_LEN;\n" + body_c += "\n" + body_c += " memcpy(packet, &buffered_packet->packet, (size_t)(*len));\n" + body_c += " return TF_TLM_FUNC_ACK_SUCCESS;\n" + body_c += "}}\n" + body_c += "\n" + + output_file_path = ( + settings["path_to_src"] + + r"src_user/Drivers/" + + settings["other_obc_data"][i]["driver_path"] + ) + OutputTlmBufferC_( + output_file_path + obc_name.lower() + "_telemetry_buffer.c", obc_name, body_c, settings + ) + OutputTlmBufferH_( + output_file_path + obc_name.lower() + "_telemetry_buffer.h", obc_name, body_h, settings + ) + OutputTlmDataDefH_( + output_file_path + obc_name.lower() + "_telemetry_data_definitions.h", + obc_name, + tlmdef_body_h, + settings, + ) + + +def OutputTlmBufferC_(file_path, name, body, settings): + name_upper = name.upper() + name_lower = name.lower() + name_capit = name.capitalize() + + output = "" + output += """ +#pragma section REPRO +/** + * @file + * @brief テレメトリバッファー(テレメ中継) + * @note このコードは自動生成されています! + */ +#include +#include "./{_obc_name_lower}_telemetry_definitions.h" +#include "./{_obc_name_lower}_telemetry_buffer.h" +#include "./{_obc_name_lower}.h" +#include + +"""[ + 1: + ] # 最初の改行を除く + + output += body + + output += """ +#pragma section +"""[ + 1: + ] # 最初の改行を除く + + with open(file_path, mode="w", encoding=settings["output_file_encoding"]) as fh: + fh.write( + output.format( + _obc_name_upper=name_upper, _obc_name_lower=name_lower, _obc_name_capit=name_capit + ) + ) + + +def OutputTlmBufferH_(file_path, name, body, settings): + name_upper = name.upper() + name_lower = name.lower() + name_capit = name.capitalize() + + output = "" + output += """ +/** + * @file + * @brief テレメトリバッファー(テレメ中継) + * @note このコードは自動生成されています! + */ +#ifndef {_obc_name_upper}_TELEMETRY_BUFFER_H_ +#define {_obc_name_upper}_TELEMETRY_BUFFER_H_ + +#include "./{_obc_name_lower}_telemetry_definitions.h" +#include +#include +#include + +"""[ + 1: + ] # 最初の改行を除く + + output += body + + output += """ + +#endif +"""[ + 1: + ] # 最初の改行を除く + + with open(file_path, mode="w", encoding=settings["output_file_encoding"]) as fh: + fh.write( + output.format( + _obc_name_upper=name_upper, _obc_name_lower=name_lower, _obc_name_capit=name_capit + ) + ) + + +def OutputTlmDataDefH_(file_path, name, body, settings): + name_upper = name.upper() + name_lower = name.lower() + name_capit = name.capitalize() + + output = "" + output += """ +/** + * @file + * @brief バッファリングされているテレメをパースしてMOBC内でかんたんに利用できるようにするためのテレメデータ構造体定義 + * @note このコードは自動生成されています! + */ +#ifndef {_obc_name_upper}_TELEMETRY_DATA_DEFINITIONS_H_ +#define {_obc_name_upper}_TELEMETRY_DATA_DEFINITIONS_H_ + +"""[ + 1: + ] # 最初の改行を除く + + output += body + + output += """ + +#endif +"""[ + 1: + ] # 最初の改行を除く + + with open(file_path, mode="w", encoding=settings["output_file_encoding"]) as fh: + fh.write( + output.format( + _obc_name_upper=name_upper, _obc_name_lower=name_lower, _obc_name_capit=name_capit + ) + ) + + +def GetStructTree_(dict, path, sep="/", default=None): + path_list = path.split(sep) + + def _(dict, path_list, sep, default): + if len(path_list) == 0: + return default + if len(path_list) == 1: + return dict.get(path_list[0], default) + else: + return _(dict.get(path_list[0], {}), path_list[1:], sep, default) + + return _(dict, path_list, sep=sep, default=None) + + +def SetStructTree_(dict, path, val, sep="/"): + path_list = path.split(sep) + + def _(dict, path_list, val, sep): + if len(path_list) == 0: + return 1 # err + if len(path_list) == 1: + key = path_list[0] + if key in dict: + return 1 # 上書きエラー + else: + dict[key] = val + return 0 + else: + key = path_list[0] + if key not in dict: + dict[key] = {} + return _(dict[key], path_list[1:], val, sep) + + return _(dict, path_list, val, sep=sep) + + +def GenerateStructDef_(tree, name): + def _(tree, name, indent): + output = "" + output += " " * (indent) + "struct\n" + output += " " * (indent) + "{{\n" + for k, v in tree.items(): + if type(v) == dict: + output += _(v, k, indent + 2) + continue + output += " " * (indent + 2) + v + " " + k + ";\n" + output += " " * (indent) + "}} " + name + ";\n" + return output + + return _(tree, name, 2) + + +def EscapeTlmElemName_(name): + return name.replace("/", "_") diff --git a/tlm-cmd-code-generator/my_mod/tlm_def.py b/tlm-cmd-code-generator/my_mod/tlm_def.py new file mode 100644 index 000000000..4fa64719d --- /dev/null +++ b/tlm-cmd-code-generator/my_mod/tlm_def.py @@ -0,0 +1,250 @@ +# coding: UTF-8 +""" +tlm def +""" + +import sys + + +def GenerateTlmDef(settings, tlm_db): + output_file_path = settings["path_to_src"] + r"src_user/tlm_cmd/" + output_file_name_base = "telemetry_definitions" + + DATA_START_ROW = 8 + + body_c = "" + body_h = "" + + # "static TF_TLM_FUNC_ACK OBC_(uint8_t* packet, uint16_t* len, uint16_t max_len);" + # " OBC_ID = 0x00," + for tlm in tlm_db: + body_c += ( + "static TF_TLM_FUNC_ACK Tlm_" + + tlm["tlm_name"].upper() + + "_(uint8_t* packet, uint16_t* len, uint16_t max_len);\n" + ) + body_h += " Tlm_CODE_" + tlm["tlm_name"].upper() + " = " + tlm["tlm_id"] + ",\n" + + body_c += "\n" + body_c += "void TF_load_tlm_table(TF_TlmInfo tlm_table[TF_MAX_TLMS])\n" + body_c += "{\n" + for tlm in tlm_db: + # " tlm_table[OBC_ID].tlm_func = OBC_;" + body_c += ( + " tlm_table[Tlm_CODE_" + + tlm["tlm_name"].upper() + + "].tlm_func = Tlm_" + + tlm["tlm_name"].upper() + + "_;\n" + ) + body_c += "}\n" + + for tlm in tlm_db: + func_code = "" + max_pos = "" + for i in range(DATA_START_ROW, len(tlm["data"])): + comment = tlm["data"][i][0] + name = tlm["data"][i][1] + var_type = tlm["data"][i][2] + code = tlm["data"][i][3] + pos = tlm["data"][i][5] + if comment == "" and name == "": # CommentもNameも空白なら打ち切り + break + if comment != "": + continue + if name == "": + continue + if var_type == "": + continue + if code == "": + continue + if pos == "": + continue + + pos = int(pos) + code = code.replace("@@", ",") + func_code += " " + if var_type == "int8_t": + func_code += "TF_copy_i8" + max_pos = pos + 1 + elif var_type == "int16_t": + func_code += "TF_copy_i16" + max_pos = pos + 2 + elif var_type == "int32_t": + func_code += "TF_copy_i32" + max_pos = pos + 4 + elif var_type == "uint8_t": + func_code += "TF_copy_u8" + max_pos = pos + 1 + elif var_type == "uint16_t": + func_code += "TF_copy_u16" + max_pos = pos + 2 + elif var_type == "uint32_t": + func_code += "TF_copy_u32" + max_pos = pos + 4 + elif var_type == "float": + func_code += "TF_copy_float" + max_pos = pos + 4 + elif var_type == "double": + func_code += "TF_copy_double" + max_pos = pos + 8 + else: + print("Error: Tlm DB Err at " + tlm["tlm_name"].upper(), file=sys.stderr) + sys.exit(1) + func_code += "(&packet[" + str(pos) + "], " + code + ");\n" + + body_c += "\n" + body_c += ( + "static TF_TLM_FUNC_ACK Tlm_" + + tlm["tlm_name"].upper() + + "_(uint8_t* packet, uint16_t* len, uint16_t max_len)\n" + ) + body_c += "{\n" + for local_var in tlm["local_vars"]: + body_c += " " + local_var + "\n" + if len(tlm["local_vars"]) > 0: + body_c += "\n" + body_c += " if (" + str(max_pos) + " > max_len) return TF_TLM_FUNC_ACK_TOO_SHORT_LEN;\n" + body_c += "\n" + body_c += "#ifndef BUILD_SETTINGS_FAST_BUILD\n" + body_c += func_code + body_c += "#endif\n" + body_c += "\n" + body_c += " *len = " + str(max_pos) + ";\n" + body_c += " return TF_TLM_FUNC_ACK_SUCCESS;\n" + body_c += "}\n" + + OutputTlmDefC_(output_file_path + output_file_name_base + ".c", body_c, settings) + OutputTlmDefH_(output_file_path + output_file_name_base + ".h", body_h, settings) + + +def GenerateOtherObcTlmDef(settings, other_obc_dbs): + for i in range(len(settings["other_obc_data"])): + if not settings["other_obc_data"][i]["is_enable"]: + continue + obc_name = settings["other_obc_data"][i]["name"] + + tlm_db = other_obc_dbs[obc_name] + + body_h = "" + # " TOBC_Tlm_CODE_HK = 0xf0," + for tlm in tlm_db: + body_h += ( + " {_obc_name_upper}_Tlm_CODE_" + + tlm["tlm_name"].upper() + + " = " + + tlm["tlm_id"] + + ",\n" + ) + output_file_path = ( + settings["path_to_src"] + + r"src_user/Drivers/" + + settings["other_obc_data"][i]["driver_path"] + + obc_name.lower() + + "_telemetry_definitions.h" + ) + OutputOtherObcTlmDefH(output_file_path, obc_name, body_h, settings) + + +def OutputTlmDefC_(file_path, body, settings): + output = "" + output += """ +#pragma section REPRO +/** + * @file + * @brief テレメトリ定義 + * @note このコードは自動生成されています! + */ +#include +#include "telemetry_definitions.h" +#include "telemetry_source.h" + +"""[ + 1: + ] # 最初の改行を除く + + output += body + + output += """ + +#pragma section +"""[ + 1: + ] # 最初の改行を除く + + with open(file_path, mode="w", encoding=settings["output_file_encoding"]) as fh: + fh.write(output) + + +def OutputTlmDefH_(file_path, body, settings): + output = "" + output += """ +/** + * @file + * @brief テレメトリ定義 + * @note このコードは自動生成されています! + */ +#ifndef TELEMETRY_DEFINITIONS_H_ +#define TELEMETRY_DEFINITIONS_H_ + +typedef enum +{ +"""[ + 1: + ] # 最初の改行を除く + + output += body + + output += """ + + TLM_CODE_MAX +} TLM_CODE; + +#endif +"""[ + 1: + ] # 最初の改行を除く + + with open(file_path, mode="w", encoding=settings["output_file_encoding"]) as fh: + fh.write(output) + + +def OutputOtherObcTlmDefH(file_path, name, body, settings): + name_upper = name.upper() + name_lower = name.lower() + name_capit = name.capitalize() + + output = "" + output += """ +/** + * @file + * @brief テレメトリ定義 + * @note このコードは自動生成されています! + */ +#ifndef {_obc_name_upper}_TELEMETRY_DEFINITIONS_H_ +#define {_obc_name_upper}_TELEMETRY_DEFINITIONS_H_ + +typedef enum +{{ +"""[ + 1: + ] # 最初の改行を除く + + output += body + + output += """ + + {_obc_name_upper}_TLM_CODE_MAX +}} {_obc_name_upper}_TLM_CODE; + +#endif +"""[ + 1: + ] # 最初の改行を除く + + with open(file_path, mode="w", encoding=settings["output_file_encoding"]) as fh: + fh.write( + output.format( + _obc_name_upper=name_upper, _obc_name_lower=name_lower, _obc_name_capit=name_capit + ) + ) diff --git a/tlm-cmd-code-generator/pyproject.toml b/tlm-cmd-code-generator/pyproject.toml new file mode 100644 index 000000000..56ce77371 --- /dev/null +++ b/tlm-cmd-code-generator/pyproject.toml @@ -0,0 +1,8 @@ +[tool.black] +target-version = ['py38'] +line-length = 100 +include = '\.pyi?$' + +# TODO: .flake8 を消してこちらに移植する +# [tool.flake8] +# max-line-length = 100 diff --git a/tlm-cmd-code-generator/renovate.json b/tlm-cmd-code-generator/renovate.json new file mode 100644 index 000000000..9b053cf94 --- /dev/null +++ b/tlm-cmd-code-generator/renovate.json @@ -0,0 +1,8 @@ +{ + "extends": [ + "config:base" + ], + "labels": ["priority::medium", "tools"], + "additionalReviewers": ["meltingrabbit", "sksat"], + "assignees": ["meltingrabbit", "sksat"] +} diff --git a/tlm-cmd-code-generator/requirements.txt b/tlm-cmd-code-generator/requirements.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tlm-cmd-code-generator/settings.json b/tlm-cmd-code-generator/settings.json new file mode 100644 index 000000000..6ef5e13bf --- /dev/null +++ b/tlm-cmd-code-generator/settings.json @@ -0,0 +1,40 @@ +{ + "path_to_src" : "../../c2a/src/", + "path_to_db" : "../../c2a/database/", + "db_prefix" : "SAMPLE_MOBC", + "tlm_id_range" : ["0x00", "0x100"], + "is_cmd_prefixed_in_db" : 0, + "input_file_encoding" : "utf-8", + "output_file_encoding" : "utf-8", + "is_main_obc" : 1, + "other_obc_data" : [ + { + "name" : "AOBC", + "is_enable" : 1, + "db_prefix" : "SAMPLE_AOBC", + "tlm_id_range" : ["0x90", "0xc0"], + "is_cmd_prefixed_in_db" : 0, + "input_file_encoding" : "utf-8", + "path_to_db" : "C:/c2a_sample_aobc/database/", + "max_tlm_num" : 256, + "driver_path" : "Aocs/", + "driver_type" : "AOBC_Driver", + "driver_name" : "aobc_driver", + "code_when_tlm_not_found" : "aobc_driver->info.comm.rx_err_code = AOBC_RX_ERR_CODE_TLM_NOT_FOUND;" + }, + { + "name" : "TOBC", + "is_enable" : 1, + "db_prefix" : "SAMPLE_TOBC", + "tlm_id_range" : ["0xc0", "0xf0"], + "is_cmd_prefixed_in_db" : 0, + "input_file_encoding" : "utf-8", + "path_to_db" : "C:/c2a_sample_tobc/database/", + "max_tlm_num" : 256, + "driver_path" : "Thermal/", + "driver_type" : "TOBC_Driver", + "driver_name" : "tobc_driver", + "code_when_tlm_not_found" : "tobc_driver->info.comm.rx_err_code = TOBC_RX_ERR_CODE_TLM_NOT_FOUND;" + } + ] +} From 4a46efb254e09fba4c9a9afc05adc32570d6fc48 Mon Sep 17 00:00:00 2001 From: sksat Date: Tue, 3 Oct 2023 02:22:30 +0900 Subject: [PATCH 139/141] update docs from import ut-issl/c2a-tlm-cmd-code-generator --- CHANGELOG.md | 3 ++- README.md | 1 - docs/driver/communication_with_components.md | 2 +- docs/general/release.md | 1 - 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32665673a..cadf52e8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,8 @@ - 設定ファイル中のディレクトリの設定を C2A user のトップディレクトリからの相対パスに変更 - [ut-issl/c2a-enum-loader](https://github.com/ut-issl/c2a-enum-loader) を c2a-core リポジトリで管理するように変更: [#99](https://github.com/arkedge/c2a-core/pull/99) - import したバージョン: [ut-issl/c2a-enum-loader ae-v2.0.0](https://github.com/ut-issl/c2a-enum-loader/releases/tag/ae-v2.0.0) +- [ut-issl/c2a-tlm-cmd-code-generator](https://github.com/ut-issl/c2a-tlm-cmd-code-generator) を c2a-core リポジトリで管理するように変更: [#111](https://github.com/arkedge/c2a-core/pull/111) + - import したバージョン: [ut-issl/c2a-tlm-cmd-code-generator ae-v2.0.0](https://github.com/ut-issl/c2a-tlm-cmd-code-generator/releases/tag/ae-v2.0.0) ### Enhancements @@ -56,7 +58,6 @@ - [ut-issl/tlm-cmd-db v2.4.0](https://github.com/ut-issl/tlm-cmd-db/releases/tag/v2.4.0) - [ut-issl/python-wings-interface v1.5.1](https://github.com/ut-issl/python-wings-interface/releases/tag/v1.5.1) -- [ut-issl/c2a-tlm-cmd-code-generator ae-v2.0.0](https://github.com/ut-issl/c2a-tlm-cmd-code-generator/releases/tag/ae-v2.0.0) - [arkedge/gaia v0.5.0](https://github.com/arkedge/gaia/releases/tag/v0.5.0) - [tlmcmddb-cli 0.2.0](https://crates.io/crates/tlmcmddb-cli/0.2.0) - [kble 0.2.0](https://crates.io/crates/kble/0.2.0) diff --git a/README.md b/README.md index 523935866..ce677dd5c 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,6 @@ C2A Core の採用実績のある衛星 OBC や動作実績のあるボードの ## 関連リンク ### C2A 関連ツール - https://github.com/ut-issl/tlm-cmd-db -- https://github.com/ut-issl/c2a-tlm-cmd-code-generator - https://github.com/ut-issl/python-wings-interface - https://github.com/ut-issl/s2e-user-for-c2a-core - https://github.com/arkedge/c2a-tlmcmddb diff --git a/docs/driver/communication_with_components.md b/docs/driver/communication_with_components.md index 219ed6338..d62c4bff5 100644 --- a/docs/driver/communication_with_components.md +++ b/docs/driver/communication_with_components.md @@ -95,7 +95,7 @@ https://github.com/arkedge/c2a-core/blob/45d78a05c339c285b5aa0c2fcbf57c1b105137e C2A 間通信によって,以下のような機能が提供される. - OBC 間の簡易な Driver 実装と自動コード生成 - - [c2a-tlm-cmd-code-generator](https://github.com/ut-issl/c2a-tlm-cmd-code-generator) 参照. + - [c2a-tlm-cmd-code-generator](../../tlm-cmd-code-generator/) 参照. - [`examples/mobc/src/src_user/Drivers/Aocs`](/examples/mobc/src/src_user/Drivers/Aocs/) などの多くのコードが自動生成される. - OBC と地上局でネットワークを形成. - 地上局から MOBC をルーターとして, sub OBC へコマンド配送. diff --git a/docs/general/release.md b/docs/general/release.md index 35d9bfbfa..716724930 100644 --- a/docs/general/release.md +++ b/docs/general/release.md @@ -81,6 +81,5 @@ Tool のリリースには,以下に注意する. 例: -- https://github.com/ut-issl/c2a-tlm-cmd-code-generator/releases - https://github.com/ut-issl/python-wings-interface/releases - https://github.com/ut-issl/tlm-cmd-db/releases From a2794434f383069598369e4a1bc382ae65166125 Mon Sep 17 00:00:00 2001 From: sksat Date: Tue, 3 Oct 2023 02:28:21 +0900 Subject: [PATCH 140/141] remove unneeded ut-issl/c2a-tlm-cmd-code-generator repo files --- .../.github/ISSUE_TEMPLATE/action_item.md | 26 --------- .../.github/ISSUE_TEMPLATE/bug_report.md | 37 ------------- .../.github/PULL_REQUEST_TEMPLATE.md | 23 -------- tlm-cmd-code-generator/.github/labels.yml | 55 ------------------- .../.github/workflows/actionlint.yml | 17 ------ .../.github/workflows/labeler.yml | 25 --------- .../.github/workflows/python_check_format.yml | 25 --------- .../.github/workflows/python_lint.yml | 27 --------- .../.github/workflows/validate-renovate.yml | 22 -------- tlm-cmd-code-generator/renovate.json | 8 --- 10 files changed, 265 deletions(-) delete mode 100644 tlm-cmd-code-generator/.github/ISSUE_TEMPLATE/action_item.md delete mode 100644 tlm-cmd-code-generator/.github/ISSUE_TEMPLATE/bug_report.md delete mode 100644 tlm-cmd-code-generator/.github/PULL_REQUEST_TEMPLATE.md delete mode 100644 tlm-cmd-code-generator/.github/labels.yml delete mode 100644 tlm-cmd-code-generator/.github/workflows/actionlint.yml delete mode 100644 tlm-cmd-code-generator/.github/workflows/labeler.yml delete mode 100644 tlm-cmd-code-generator/.github/workflows/python_check_format.yml delete mode 100644 tlm-cmd-code-generator/.github/workflows/python_lint.yml delete mode 100644 tlm-cmd-code-generator/.github/workflows/validate-renovate.yml delete mode 100644 tlm-cmd-code-generator/renovate.json diff --git a/tlm-cmd-code-generator/.github/ISSUE_TEMPLATE/action_item.md b/tlm-cmd-code-generator/.github/ISSUE_TEMPLATE/action_item.md deleted file mode 100644 index 5c06b8b52..000000000 --- a/tlm-cmd-code-generator/.github/ISSUE_TEMPLATE/action_item.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -name: Action Item -about: AI 管理用テンプレート -title: '' -labels: '' -assignees: '' - ---- - -## 概要 -ひとことで - -## 詳細 -詳しく - -## close条件 -どうなったらcloseできるか - -## 備考 -なにかあれば - -## 注意 -- 関連する Projects が存在する場合,それの紐付けを行うこと -- 可能ならば `priority` ラベルを付けること -- 可能ならば Assignees を設定すること -- close するときは結論を明記すること diff --git a/tlm-cmd-code-generator/.github/ISSUE_TEMPLATE/bug_report.md b/tlm-cmd-code-generator/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index 7c03c968a..000000000 --- a/tlm-cmd-code-generator/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,37 +0,0 @@ ---- -name: Bug report -about: Create a report to help us improve -title: '' -labels: '' -assignees: '' - ---- - -## 概要 -ひとことで - -## 詳細 -### 詳細症状 -どういうバグか - -### 発生条件 -発生した環境,症状,パラメタなど - -### 追加資料 -あればリンクなどを貼る - -## 必要な作業 -- [ ] あれして -- [ ] これする - -## 影響範囲 -tool類が全部死ぬ... みたいな - -## 補足 -何かれば - -## 注意 -- 関連する Projects が存在する場合,それの紐付けを行うこと -- 可能ならば `priority` ラベルを付けること -- 可能ならば Assignees を設定すること -- close するときは結論を明記すること diff --git a/tlm-cmd-code-generator/.github/PULL_REQUEST_TEMPLATE.md b/tlm-cmd-code-generator/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 82728e779..000000000 --- a/tlm-cmd-code-generator/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,23 +0,0 @@ -## 概要 -ひとことで - -## Issue -- 関連する issue - -## 詳細 -詳しく - -## 検証結果 -test へのリンクや,検証結果へのリンク - -## 影響範囲 -XX系の動作がガラッと変わる,とか. - -## 補足 -何かあれば - -## 注意 -- 関連する Projects が存在する場合,それの紐付けを行うこと -- Assignees を設定すること -- 可能ならば Reviewers を設定すること -- 可能ならば `priority` ラベルを付けること diff --git a/tlm-cmd-code-generator/.github/labels.yml b/tlm-cmd-code-generator/.github/labels.yml deleted file mode 100644 index 60ca01d51..000000000 --- a/tlm-cmd-code-generator/.github/labels.yml +++ /dev/null @@ -1,55 +0,0 @@ -- name: "bug" - color: "d73a4a" - description: "Something isn't working" - -- name: "documentation" - color: "0075ca" - description: "Improvements or additions to documentation" - -- name: "duplicate" - color: "cfd8d7" - description: "This issue or pull request already exists" - -- name: "enhancement" - description: "New feature or request" - color: "a2eeef" - -- name: "good first issue" - description: "Good for newcomers" - color: "7057ff" - -- name: "help wanted" - description: "Extra attention is needed" - color: "008672" - -- name: "invalid" - description: "This doesn't seem right" - color: "e4e669" - -- name: "question" - description: "Further information is requested" - color: "d876e3" - -- name: "wontfix" - description: "This will not be worked on" - color: "ffffff" - -- name: "icebox" - description: "icebox or pending" - color: "c5def5" - -- name: "priority::high" - description: "priorityg high" - color: "d93f0b" - -- name: "priority::low" - description: "priority low" - color: "9dcce0" - -- name: "priority::medium" - description: "priority medium" - color: "fbca04" - -- name: "tools" - description: "" - color: "510f70" diff --git a/tlm-cmd-code-generator/.github/workflows/actionlint.yml b/tlm-cmd-code-generator/.github/workflows/actionlint.yml deleted file mode 100644 index 4ef847aaf..000000000 --- a/tlm-cmd-code-generator/.github/workflows/actionlint.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: reviewdog / actionlint - -on: - pull_request: - paths: - - '.github/workflows/**' - -jobs: - actionlint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: reviewdog/action-actionlint@v1 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - reporter: github-pr-review - fail_on_error: true diff --git a/tlm-cmd-code-generator/.github/workflows/labeler.yml b/tlm-cmd-code-generator/.github/workflows/labeler.yml deleted file mode 100644 index 82cb5d166..000000000 --- a/tlm-cmd-code-generator/.github/workflows/labeler.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: labeler - -on: - push: - branches: - - main - pull_request: - paths: - - .github/workflows/labeler.yml - - .github/labels.yml - -jobs: - labeler: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Run Labeler - uses: crazy-max/ghaction-github-labeler@v4 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - yaml-file: .github/labels.yml - skip-delete: false - dry-run: ${{ github.ref != 'refs/heads/main' }} diff --git a/tlm-cmd-code-generator/.github/workflows/python_check_format.yml b/tlm-cmd-code-generator/.github/workflows/python_check_format.yml deleted file mode 100644 index ca77e90f5..000000000 --- a/tlm-cmd-code-generator/.github/workflows/python_check_format.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: reviewdog / python format check - -on: - push: - branches: - - main - pull_request: - -jobs: - black_format: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - # - name: check python format with black - # uses: psf/black@stable - - - uses: reviewdog/action-black@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - # reporter: github-pr-review # TODO: いい感じになったら直す - reporter: github-pr-check - filter_mode: nofilter - fail_on_error: true - level: warning diff --git a/tlm-cmd-code-generator/.github/workflows/python_lint.yml b/tlm-cmd-code-generator/.github/workflows/python_lint.yml deleted file mode 100644 index e2c78d63a..000000000 --- a/tlm-cmd-code-generator/.github/workflows/python_lint.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: reviewdog / lint python - -on: - push: - branches: - - main - pull_request: - -jobs: - flake8_lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Set up python environment - uses: actions/setup-python@v4 - with: - python-version: "3.8" - - - name: flake8 Lint - uses: reviewdog/action-flake8@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - reporter: github-pr-review - filter_mode: nofilter - fail_on_error: true - level: warning diff --git a/tlm-cmd-code-generator/.github/workflows/validate-renovate.yml b/tlm-cmd-code-generator/.github/workflows/validate-renovate.yml deleted file mode 100644 index 84b52217e..000000000 --- a/tlm-cmd-code-generator/.github/workflows/validate-renovate.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: validate / renovate.json - -on: - pull_request: - paths: - - 'renovate.json' - - '.github/workflows/validate-renovate.yml' - -jobs: - validate-renovate: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - - - name: install - run: | - npm install -g renovate - - name: validate - run: | - renovate-config-validator diff --git a/tlm-cmd-code-generator/renovate.json b/tlm-cmd-code-generator/renovate.json deleted file mode 100644 index 9b053cf94..000000000 --- a/tlm-cmd-code-generator/renovate.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": [ - "config:base" - ], - "labels": ["priority::medium", "tools"], - "additionalReviewers": ["meltingrabbit", "sksat"], - "assignees": ["meltingrabbit", "sksat"] -} From 503e775724c6e61853889e2a80064a640e9d554e Mon Sep 17 00:00:00 2001 From: sksat Date: Tue, 3 Oct 2023 02:30:02 +0900 Subject: [PATCH 141/141] remove duplicated license file Both c2a-core and c2a-tlm-cmd-code-generator are forked from ut-issl and will be maintained together in arkedge/c2a-core. The license displayed in this license file will be completely the same as the license at the top of arkedge/c2a-core. --- tlm-cmd-code-generator/LICENSE | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 tlm-cmd-code-generator/LICENSE diff --git a/tlm-cmd-code-generator/LICENSE b/tlm-cmd-code-generator/LICENSE deleted file mode 100644 index 89f748ff8..000000000 --- a/tlm-cmd-code-generator/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2021 Intelligent Space Systems Laboratory, The University of Tokyo - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE.