Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[code-generator] 自動生成コードの @note に,生成元DBのコミットハッシュと生成パラメータを出力する #240

Merged
merged 21 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/check_code_generation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
working-directory: ./code-generator
run: |
cp "./settings_${{ matrix.user }}.json" ./settings.json
# sub obc の tlm cmd db は見ない
sed -i 's/ "is_main_obc" : 1,/ "is_main_obc" : 0,/g' ./settings.json
python GenerateC2ACode.py

- name: check diff
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

注意: これは既存の C2A core update の「リリースの間の Pull Request を眺めてなんとなく察する」という曖昧な操作を緩和していくための試みであり,C2A user に対するお知らせを行う場として使っていくことを意図しています.初めから c2a-core の全変更を取り扱うと不必要に煩雑になるだけになってしまうため,完全な変更内容の一覧についてはこれまで通り [GitHub Releases](https://github.com/arkedge/c2a-core/releases) などから参照してください.

## v4.2.0 (Unreleased-12-11)

### Enhancements
- [#240](https://github.com/arkedge/c2a-core/pull/240): code-generator の出力コードに,設定情報を残すようにする

### Migration Guide
- [#240](https://github.com/arkedge/c2a-core/pull/240): user 側でのコードレベルでの対応は不要
- 新しい code-generator で生成したコードは,既存のものと diff が発生するため,改めてコード生成し直すとよい.


## v4.1.0 (2023-12-11)

### Breaking Changes
Expand Down
21 changes: 12 additions & 9 deletions code-generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ $ 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
`is_main_obc` は,MOBC(地上局と通信するOBC.sub OBCのtlm/cmdを取りまとめる)かそれ以外のOBC(sub OBC.MOBCと通信するOBC)かを制御する.
`1` とした場合,MOBC用のコードに加えて以下が生成される.
- sub_obc_command_definitions.h
- sub_obc_telemetry_definitions.h
- sub_obc_telemetry_buffer.c
- sub_obc_telemetry_buffer.h
- sub_obc_telemetry_data_definitions.h

なお,MOBC の場合でも, `0` にすることで, sub OBC のコードを生成せず, MOBC のコードのみを生成することができる

設定の記述例(JSON としては invalid だがコメント付き)
```
Expand All @@ -42,7 +44,8 @@ $ python GenerateC2ACode.py
# 出力ファイルのエンコーディング
"output_file_encoding" : "utf-8",
# MOBCか?(他のOBCのtlm/cmdを取りまとめるか?) 0/1
# 2nd OBCのコードを生成するときなどは 0 にする
# sub OBCのコードを生成するときなどは 0 にする
# MOBC の場合でも, 0 にすることで, sub OBC のコードを生成せず, MOBC のコードのみを生成することができる
# 0 の場合,以後のパラメタは無効
"is_main_obc" : 1,
"other_obc_data" : [
Expand Down Expand Up @@ -97,4 +100,4 @@ $ pip install -r requirements.txt

## その他
- [settings_mobc.json](./settings_mobc.json), [settings_subobc.json](./settings_subobc.json) は c2a-core example user での設定
- MOBCと2nd OBCのC2A間通信の例は (TBA).
- MOBCとsub OBCのC2A間通信の例は (TBA).
45 changes: 35 additions & 10 deletions code-generator/my_mod/cmd_def.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

import sys
import my_mod.util

# import pprint

Expand Down Expand Up @@ -170,7 +171,7 @@ def GenerateOtherObcCmdDef(settings, other_obc_dbs):
+ name_lower
+ "_command_definitions.h"
)
OutputOtherObcCmdDefH_(output_file_path, obc_name, body_h, settings)
OutputOtherObcCmdDefH_(output_file_path, obc_name, body_h, settings, i)


def GetCmdNameAndCmdCode_(name, is_cmd_prefixed_in_db):
Expand All @@ -188,8 +189,14 @@ def OutputCmdDefC_(file_path, body, settings):
#pragma section REPRO
/**
* @file
* @brief コマンド定義
* @note このコードは自動生成されています!
* @brief コマンド定義
"""[
1:
] # 最初の改行を除く

output += my_mod.util.GenerateSettingNote(settings)

output += """
*/
#include <src_core/tlm_cmd/command_analyze.h>
#include "command_definitions.h"
Expand Down Expand Up @@ -220,8 +227,14 @@ def OutputCmdDefH_(file_path, body, settings):
output += """
/**
* @file
* @brief コマンド定義
* @note このコードは自動生成されています!
* @brief コマンド定義
"""[
1:
] # 最初の改行を除く

output += my_mod.util.GenerateSettingNote(settings)

output += """
*/
#ifndef COMMAND_DEFINITIONS_H_
#define COMMAND_DEFINITIONS_H_
Expand Down Expand Up @@ -253,8 +266,14 @@ def OutputBctDef_(file_path, body, settings):
output += """
/**
* @file
* @brief ブロックコマンド定義
* @note このコードは自動生成されています!
* @brief ブロックコマンド定義
"""[
1:
] # 最初の改行を除く

output += my_mod.util.GenerateSettingNote(settings)

output += """
*/
#ifndef BLOCK_COMMAND_DEFINITIONS_H_
#define BLOCK_COMMAND_DEFINITIONS_H_
Expand Down Expand Up @@ -284,7 +303,7 @@ def OutputBctDef_(file_path, body, settings):
fh.write(output)


def OutputOtherObcCmdDefH_(file_path, name, body, settings):
def OutputOtherObcCmdDefH_(file_path, name, body, settings, obc_idx):
name_upper = name.upper()
name_lower = name.lower()
name_capit = name.capitalize()
Expand All @@ -293,8 +312,14 @@ def OutputOtherObcCmdDefH_(file_path, name, body, settings):
output += """
/**
* @file
* @brief コマンド定義
* @note このコードは自動生成されています!
* @brief コマンド定義
"""[
1:
] # 最初の改行を除く

output += my_mod.util.GenerateSubObcSettingNote(settings, obc_idx)

output += """
*/
#ifndef {_obc_name_upper}_COMMAND_DEFINITIONS_H_
#define {_obc_name_upper}_COMMAND_DEFINITIONS_H_
Expand Down
50 changes: 39 additions & 11 deletions code-generator/my_mod/tlm_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

import sys
import my_mod.util

# from collections import OrderedDict
# import pprint
Expand Down Expand Up @@ -342,20 +343,29 @@ def GenerateTlmBuffer(settings, other_obc_dbs):
+ settings["other_obc_data"][i]["driver_path"]
)
OutputTlmBufferC_(
output_file_path + obc_name.lower() + "_telemetry_buffer.c", obc_name, body_c, settings
output_file_path + obc_name.lower() + "_telemetry_buffer.c",
obc_name,
body_c,
settings,
i,
)
OutputTlmBufferH_(
output_file_path + obc_name.lower() + "_telemetry_buffer.h", obc_name, body_h, settings
output_file_path + obc_name.lower() + "_telemetry_buffer.h",
obc_name,
body_h,
settings,
i,
)
OutputTlmDataDefH_(
output_file_path + obc_name.lower() + "_telemetry_data_definitions.h",
obc_name,
tlmdef_body_h,
settings,
i,
)


def OutputTlmBufferC_(file_path, name, body, settings):
def OutputTlmBufferC_(file_path, name, body, settings, obc_idx):
name_upper = name.upper()
name_lower = name.lower()
name_capit = name.capitalize()
Expand All @@ -365,8 +375,14 @@ def OutputTlmBufferC_(file_path, name, body, settings):
#pragma section REPRO
/**
* @file
* @brief テレメトリバッファー(テレメ中継)
* @note このコードは自動生成されています!
* @brief テレメトリバッファー(テレメ中継)
"""[
1:
] # 最初の改行を除く

output += my_mod.util.GenerateSubObcSettingNote(settings, obc_idx)

output += """
*/
#include <src_core/component_driver/cdrv_common_tlm_cmd_packet.h>
#include "./{_obc_name_lower}_telemetry_definitions.h"
Expand Down Expand Up @@ -394,7 +410,7 @@ def OutputTlmBufferC_(file_path, name, body, settings):
)


def OutputTlmBufferH_(file_path, name, body, settings):
def OutputTlmBufferH_(file_path, name, body, settings, obc_idx):
name_upper = name.upper()
name_lower = name.lower()
name_capit = name.capitalize()
Expand All @@ -403,8 +419,14 @@ def OutputTlmBufferH_(file_path, name, body, settings):
output += """
/**
* @file
* @brief テレメトリバッファー(テレメ中継)
* @note このコードは自動生成されています!
* @brief テレメトリバッファー(テレメ中継)
"""[
1:
] # 最初の改行を除く

output += my_mod.util.GenerateSubObcSettingNote(settings, obc_idx)

output += """
*/
#ifndef {_obc_name_upper}_TELEMETRY_BUFFER_H_
#define {_obc_name_upper}_TELEMETRY_BUFFER_H_
Expand Down Expand Up @@ -435,7 +457,7 @@ def OutputTlmBufferH_(file_path, name, body, settings):
)


def OutputTlmDataDefH_(file_path, name, body, settings):
def OutputTlmDataDefH_(file_path, name, body, settings, obc_idx):
name_upper = name.upper()
name_lower = name.lower()
name_capit = name.capitalize()
Expand All @@ -444,8 +466,14 @@ def OutputTlmDataDefH_(file_path, name, body, settings):
output += """
/**
* @file
* @brief バッファリングされているテレメをパースしてMOBC内でかんたんに利用できるようにするためのテレメデータ構造体定義
* @note このコードは自動生成されています!
* @brief バッファリングされているテレメをパースしてMOBC内でかんたんに利用できるようにするためのテレメデータ構造体定義
"""[
1:
] # 最初の改行を除く

output += my_mod.util.GenerateSubObcSettingNote(settings, obc_idx)

output += """
*/
#ifndef {_obc_name_upper}_TELEMETRY_DATA_DEFINITIONS_H_
#define {_obc_name_upper}_TELEMETRY_DATA_DEFINITIONS_H_
Expand Down
35 changes: 27 additions & 8 deletions code-generator/my_mod/tlm_def.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

import sys
import my_mod.util


def GenerateTlmDef(settings, tlm_db):
Expand Down Expand Up @@ -143,7 +144,7 @@ def GenerateOtherObcTlmDef(settings, other_obc_dbs):
+ obc_name.lower()
+ "_telemetry_definitions.h"
)
OutputOtherObcTlmDefH(output_file_path, obc_name, body_h, settings)
OutputOtherObcTlmDefH(output_file_path, obc_name, body_h, settings, i)


def OutputTlmDefC_(file_path, body, settings):
Expand All @@ -152,8 +153,14 @@ def OutputTlmDefC_(file_path, body, settings):
#pragma section REPRO
/**
* @file
* @brief テレメトリ定義
* @note このコードは自動生成されています!
* @brief テレメトリ定義
"""[
1:
] # 最初の改行を除く

output += my_mod.util.GenerateSettingNote(settings)

output += """
*/
#include <src_core/tlm_cmd/telemetry_frame.h>
#include "telemetry_definitions.h"
Expand Down Expand Up @@ -181,8 +188,14 @@ def OutputTlmDefH_(file_path, body, settings):
output += """
/**
* @file
* @brief テレメトリ定義
* @note このコードは自動生成されています!
* @brief テレメトリ定義
"""[
1:
] # 最初の改行を除く

output += my_mod.util.GenerateSettingNote(settings)

output += """
*/
#ifndef TELEMETRY_DEFINITIONS_H_
#define TELEMETRY_DEFINITIONS_H_
Expand All @@ -209,7 +222,7 @@ def OutputTlmDefH_(file_path, body, settings):
fh.write(output)


def OutputOtherObcTlmDefH(file_path, name, body, settings):
def OutputOtherObcTlmDefH(file_path, name, body, settings, obc_idx):
name_upper = name.upper()
name_lower = name.lower()
name_capit = name.capitalize()
Expand All @@ -218,8 +231,14 @@ def OutputOtherObcTlmDefH(file_path, name, body, settings):
output += """
/**
* @file
* @brief テレメトリ定義
* @note このコードは自動生成されています!
* @brief テレメトリ定義
"""[
1:
] # 最初の改行を除く

output += my_mod.util.GenerateSubObcSettingNote(settings, obc_idx)

output += """
*/
#ifndef {_obc_name_upper}_TELEMETRY_DEFINITIONS_H_
#define {_obc_name_upper}_TELEMETRY_DEFINITIONS_H_
Expand Down
Loading
Loading