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

GS と FSW 側での同期のために,BCT, TL のダイジェスト (CRC) を下ろせるようにする App の追加 #268

Merged
merged 21 commits into from
Jan 5, 2024
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- [#243](https://github.com/arkedge/c2a-core/pull/243): code-generator に max_tlm_num のアサーションを追加
- [#256](https://github.com/arkedge/c2a-core/pull/256): code-generator: MOBC が定義を持っていない Sub OBC の tlm でも GS に Forward できるようにする
- [#263](https://github.com/arkedge/c2a-core/pull/263): CDIS や BCT に保存された CCP をダンプする App を追加
- [#268](https://github.com/arkedge/c2a-core/pull/268): GS と FSW 側での同期のために,BCT, TL のダイジェスト (CRC) を下ろせるようにする App の追加

### Breaking Changes

Expand Down Expand Up @@ -51,6 +52,12 @@
- `examples/mobc/tlm-cmd-db/CMD_DB/SAMPLE_MOBC_CMD_DB_CMD_DB.csv` の `CCP_DUMP_*` コマンドを user 側の cmd db に追加し,コード生成をする.
- `examples/mobc/src/src_user/test/src_core/applications/test_ccp_dump.py` を user 側の test にも加える.
- もし,汎用テスト用 BCT `BC_TEST_USE_PYTEST` が user 側に存在しない場合, user 側の BCT ID にも加える.
- [#268](https://github.com/arkedge/c2a-core/pull/268): user 側でのコードレベルでの対応は不要
- TL BCT Digest App を追加したため,この App を利用する user は,`applications/tl_bct_digest.c` をビルド対象に加え,App 登録する.
- `examples/mobc/tlm-cmd-db/TLM_DB/{SAMPLE_MOBC_TLM_DB_TL_DIGEST.csv,SAMPLE_MOBC_TLM_DB_BCT_DIGEST.csv}` を user 側の tlm db に追加し,コード生成をする.
- `examples/mobc/tlm-cmd-db/CMD_DB/SAMPLE_MOBC_CMD_DB_CMD_DB.csv` の `TL_BCT_DIGEST_*` コマンドを user 側の cmd db に追加し,コード生成をする.
- `examples/mobc/src/src_user/test/src_core/applications/test_tl_bct_digest.py` を user 側の test にも加える.
- もし,汎用テスト用 BCT `BC_TEST_USE_PYTEST` が user 側に存在しない場合, user 側の BCT ID にも加える.


## v4.1.0 (2023-12-11)
Expand Down
1 change: 1 addition & 0 deletions applications/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ set(C2A_SRCS
nop.c
realtime_command_dispatcher.c
timeline_command_dispatcher.c
tl_bct_digest.c
utility_command.c
utility_counter.c
telemetry_manager.c
Expand Down
167 changes: 167 additions & 0 deletions applications/tl_bct_digest.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
#pragma section REPRO
/**
* @file
* @brief TL や BCT のコマンド列の digest を計算し, GS と FSW での整合性を確認するための App
*/
#include "tl_bct_digest.h"
#include <stddef.h>
#include <string.h>
#include "../tlm_cmd/command_dispatcher_manager.h"
#include "../system/time_manager/time_manager.h"
#include "../library/crc.h"

/**
* @brief App 初期化関数
* @param void
* @return RESULT
*/
static RESULT TL_BCT_DIGEST_init_(void);

/**
* @brief CCP の digest を計算
* @param ccp: digest を計算する CCP
* @return digest
*/
static uint16_t TL_BCT_DIGEST_calc_digest_(const CommonCmdPacket* ccp);

static TlBctDigest tl_bct_digest_;
const TlBctDigest* const tl_bct_digest = &tl_bct_digest_;


AppInfo TL_BCT_DIGEST_create_app(void)
{
return AI_create_app_info("tl_bct_digest", TL_BCT_DIGEST_init_, NULL);
}


static RESULT TL_BCT_DIGEST_init_(void)
{
memset(&tl_bct_digest_, 0x00, sizeof(TlBctDigest));
return RESULT_OK;
}


static uint16_t TL_BCT_DIGEST_calc_digest_(const CommonCmdPacket* ccp)
{
// 念のため(外部の CCP を扱うので)
if (!(CCP_is_valid_packet(ccp)))
{
return 0;
}
return CRC_calc_crc_16_ccitt_left(0xffff, ccp->packet, CCP_get_packet_len(ccp), 0);
}


CCP_CmdRet Cmd_TL_BCT_DIGEST_TL(const CommonCmdPacket* packet)
{
const PL_Node* node;
const PacketList* pl;
uint16_t i;
TL_BCT_DIGEST_TlDigest* tl_digest = &tl_bct_digest_.tl;
tl_digest->info.tl_id = (TLCD_ID)CCP_get_param_from_packet(packet, 0, uint8_t);
tl_digest->info.page_no = CCP_get_param_from_packet(packet, 1, uint8_t);

// 計算結果をクリア
memset(tl_digest->digests, 0x00, TL_BCT_DIGEST_TL_DIGEST_PAGE_SIZE * sizeof(uint16_t));
tl_digest->info.digests_num = 0;

if (tl_digest->info.tl_id >= TLCD_ID_MAX)
{
tl_digest->info.status = TL_BCT_DIGEST_STATUS_PARAM_ERR;
return CCP_make_cmd_ret(CCP_EXEC_ILLEGAL_PARAMETER, 1);
hender14 marked this conversation as resolved.
Show resolved Hide resolved
}

pl = &(PH_tl_cmd_list[tl_digest->info.tl_id]);
tl_digest->info.queued = PL_count_active_nodes(pl);

if (tl_digest->info.queued <= tl_digest->info.page_no * TL_BCT_DIGEST_TL_DIGEST_PAGE_SIZE)
{
tl_digest->info.status = TL_BCT_DIGEST_STATUS_NO_CCP;
tl_digest->info.time_stamp = TMGR_get_master_clock();
// たまたま計算するものがないだけなので, CCP_EXEC_SUCCESS を返す
return CCP_make_cmd_ret_without_err_code(CCP_EXEC_SUCCESS);
}

// 計算開始する node まで linked list をすすめる
node = PL_get_head(pl);
for (i = 0; i < tl_digest->info.page_no * TL_BCT_DIGEST_TL_DIGEST_PAGE_SIZE; ++i)
{
node = PL_get_next(node);
}
if (node == NULL)
{
// ありえないエラー
tl_digest->info.status = TL_BCT_DIGEST_STATUS_UNKNOWN;
return CCP_make_cmd_ret(CCP_EXEC_ILLEGAL_PARAMETER, 2);
}

// 計算する CCP 数を計算
tl_digest->info.digests_num = tl_digest->info.queued % TL_BCT_DIGEST_TL_DIGEST_PAGE_SIZE;
if (tl_digest->info.queued >= TL_BCT_DIGEST_TL_DIGEST_PAGE_SIZE * (tl_digest->info.page_no + 1))
{
tl_digest->info.digests_num = TL_BCT_DIGEST_TL_DIGEST_PAGE_SIZE;
}

for (i = 0; i < tl_digest->info.digests_num; i++)
{
if (node == NULL)
{
// ありえないエラー
tl_digest->info.status = TL_BCT_DIGEST_STATUS_UNKNOWN;
return CCP_make_cmd_ret(CCP_EXEC_ILLEGAL_PARAMETER, 3);
}

// digest 計算
tl_digest->digests[i] = TL_BCT_DIGEST_calc_digest_((const CommonCmdPacket*)PL_get_packet(node));

node = PL_get_next(node);
}

tl_digest->info.status = TL_BCT_DIGEST_STATUS_OK;
tl_digest->info.time_stamp = TMGR_get_master_clock();
return CCP_make_cmd_ret_without_err_code(CCP_EXEC_SUCCESS);
}


CCP_CmdRet Cmd_TL_BCT_DIGEST_BCT(const CommonCmdPacket* packet)
{
uint8_t i;
TL_BCT_DIGEST_BctDigest* bct_digest = &tl_bct_digest_.bct;
bct_digest->info.block = (bct_id_t)CCP_get_param_from_packet(packet, 0, uint16_t);

// 計算結果をクリア
memset(bct_digest->digests, 0x00, BCT_MAX_CMD_NUM * sizeof(uint16_t));
bct_digest->info.digests_num = 0;

if (bct_digest->info.block >= BCT_MAX_BLOCKS)
{
bct_digest->info.status = TL_BCT_DIGEST_STATUS_PARAM_ERR;
return CCP_make_cmd_ret(CCP_EXEC_ILLEGAL_PARAMETER, 1);
}

bct_digest->info.digests_num = BCT_get_bc_length(bct_digest->info.block);
for (i = 0; i < bct_digest->info.digests_num; i++)
{
const CommonCmdPacket* ccp;
BCT_Pos pos;
if (BCT_make_pos(&pos, bct_digest->info.block, i) != BCT_SUCCESS)
{
// ありえないエラー
bct_digest->info.status = TL_BCT_DIGEST_STATUS_UNKNOWN;
return CCP_make_cmd_ret(CCP_EXEC_ILLEGAL_PARAMETER, 2);
}

// BCT cmd 取得
// NOTE: const BCT_CmdData → const CommonCmdPacket* への cast
ccp = (const CommonCmdPacket*)BCT_get_bc_cmd_data(&pos);

// digest 計算
bct_digest->digests[i] = TL_BCT_DIGEST_calc_digest_(ccp);
}

bct_digest->info.status = TL_BCT_DIGEST_STATUS_OK;
bct_digest->info.time_stamp = TMGR_get_master_clock();
return CCP_make_cmd_ret_without_err_code(CCP_EXEC_SUCCESS);
}

#pragma section
85 changes: 85 additions & 0 deletions applications/tl_bct_digest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* @file
* @brief TL や BCT のコマンド列の digest を計算し, GS と FSW での整合性を確認するための App
*/
#ifndef TL_BCT_DIGEST_H_
#define TL_BCT_DIGEST_H_

#include "../system/application_manager/app_info.h"
#include "../tlm_cmd/common_cmd_packet.h"
#include "../tlm_cmd/block_command_table.h"
#include "../tlm_cmd/packet_handler.h"
#include "../system/time_manager/obc_time.h"
#include "./timeline_command_dispatcher_id_define.h"

#define TL_BCT_DIGEST_TL_DIGEST_PAGE_SIZE (TL_TLM_PAGE_SIZE * 2) /*!< TL の digest のページサイズ.
計算にはそれなりの時間がかかるので,テレメサイズだけでなく OBC の計算リソースと相談して決める. */
// TL_BCT_DIGEST_TL_DIGEST_PAGE_SIZE の user オーバーライド(設定)
#include <src_user/settings/applications/tl_bct_digest_params.h>


/**
* @enum TL_BCT_DIGEST_STATUS
* @note uint8_t を想定
* @brief digest 計算結果
*/
typedef enum
{
TL_BCT_DIGEST_STATUS_OK, //!< 計算成功
TL_BCT_DIGEST_STATUS_PARAM_ERR, //!< パラメタエラー
TL_BCT_DIGEST_STATUS_NO_CCP, //!< digest を計算すべき CCP はなし
TL_BCT_DIGEST_STATUS_UNKNOWN //!< 不明なエラー
} TL_BCT_DIGEST_STATUS;

/**
* @struct TL_BCT_DIGEST_TlDigest
* @brief TL の digest
*/
typedef struct
{
struct
{
TLCD_ID tl_id; //!< TL の ID
uint8_t page_no; //!< TL_BCT_DIGEST_TL_DIGEST_PAGE_SIZE のページネーション
TL_BCT_DIGEST_STATUS status; //!< digest 計算結果
uint16_t queued; //!< 該当の TL に保存されたコマンド数
ObcTime time_stamp; //!< digest 計算時刻
uint8_t digests_num; //!< 計算した digests の数
} info;
uint16_t digests[TL_BCT_DIGEST_TL_DIGEST_PAGE_SIZE]; //!< TL の digest
} TL_BCT_DIGEST_TlDigest;

/**
* @struct TL_BCT_DIGEST_BctDigest
* @brief BCT の digest
*/
typedef struct
{
struct
{
bct_id_t block; //!< BCT block
TL_BCT_DIGEST_STATUS status; //!< digest 計算結果
ObcTime time_stamp; //!< digest 計算時刻
uint8_t digests_num; //!< 計算した digests の数(= BCT に登録されたコマンド数)
} info;
uint16_t digests[BCT_MAX_CMD_NUM]; //!< BCT の digest
} TL_BCT_DIGEST_BctDigest;

/**
* @struct CcpDump
* @brief CcpDump の AppInfo 構造体
*/
typedef struct
{
TL_BCT_DIGEST_TlDigest tl; //!< TL の digest
TL_BCT_DIGEST_BctDigest bct; //!< BCT の digest
} TlBctDigest;

extern const TlBctDigest* const tl_bct_digest;

AppInfo TL_BCT_DIGEST_create_app(void);

CCP_CmdRet Cmd_TL_BCT_DIGEST_TL(const CommonCmdPacket* packet);
CCP_CmdRet Cmd_TL_BCT_DIGEST_BCT(const CommonCmdPacket* packet);

#endif
1 change: 1 addition & 0 deletions examples/mobc/src/src_user/applications/app_headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <src_core/applications/memory_dump.h>
#include <src_core/applications/ccp_dump.h>
#include <src_core/applications/telemetry_manager.h>
#include <src_core/applications/tl_bct_digest.h>
#include <src_core/applications/utility_command.h>
#include <src_core/applications/utility_counter.h>
#include <src_core/applications/divided_cmd_utility.h>
Expand Down
1 change: 1 addition & 0 deletions examples/mobc/src/src_user/applications/app_registry.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ void AR_load_initial_settings(void)
add_application_(AR_EVENT_UTILITY, EVENT_UTIL_create_app);
add_application_(AR_MEM_DUMP, MEM_create_app);
add_application_(AR_CCP_DUMP, CCP_DUMP_create_app);
add_application_(AR_TL_BCT_DIGEST, TL_BCT_DIGEST_create_app);
add_application_(AR_TELEMETRY_MANAGER, TLM_MGR_create_app);
add_application_(AR_DIVIDED_CMD_UTILITY, DCU_create_app);
add_application_(AR_UTILITY_CMD, UTIL_CMD_create_app);
Expand Down
1 change: 1 addition & 0 deletions examples/mobc/src/src_user/applications/app_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ typedef enum
AR_EVENT_UTILITY,
AR_MEM_DUMP,
AR_CCP_DUMP,
AR_TL_BCT_DIGEST,
AR_TELEMETRY_MANAGER,
AR_DIVIDED_CMD_UTILITY,
AR_UTILITY_CMD,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @file
* @brief TL_BCT_DIGEST の CoreApp パラメタのオーバーライド用ヘッダー
*/
#ifndef TL_BCT_DIGEST_PARAMS_H_
#define TL_BCT_DIGEST_PARAMS_H_

#include <src_core/tlm_cmd/packet_handler.h>

#undef TL_BCT_DIGSET_TL_DIGEST_PAGE_SIZE

#define TL_BCT_DIGSET_TL_DIGEST_PAGE_SIZE (TL_TLM_PAGE_SIZE * 2)

#endif
Loading
Loading