Skip to content

Commit

Permalink
Merge pull request #263 from arkedge/feature/ccp-dump-tlm
Browse files Browse the repository at this point in the history
CDIS や BCT に保存された CCP をダンプする App を追加
  • Loading branch information
meltingrabbit authored Jan 4, 2024
2 parents 9151eff + 18b3bbe commit 413caa1
Show file tree
Hide file tree
Showing 21 changed files with 1,654 additions and 13 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [#240](https://github.com/arkedge/c2a-core/pull/240): code-generator の出力コードに,設定情報を残すようにする
- [#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 を追加

### Breaking Changes

Expand Down Expand Up @@ -44,6 +45,12 @@
- 以下の tlm id を変更したため,これらを user 側の tlm db に上書きし,tlm db を再度読み込み,再出力することで更新する.
- `examples/mobc/tlm-cmd-db/TLM_DB/SAMPLE_MOBC_TLM_DB_CDIS.csv`
- `examples/mobc/tlm-cmd-db/TLM_DB/SAMPLE_MOBC_TLM_DB_CA.csv`
- [#263](https://github.com/arkedge/c2a-core/pull/263): user 側でのコードレベルでの対応は不要
- CcpDump App を追加したため,この App を利用する user は,`applications/ccp_dump.c` をビルド対象に加え,App 登録する.
- `examples/mobc/tlm-cmd-db/TLM_DB/SAMPLE_MOBC_TLM_DB_CCP_DUMP.csv` を user 側の tlm db に追加し,コード生成をする.
- `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 にも加える.


## 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 @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.13)
project(C2A_CORE_APPS)

set(C2A_SRCS
ccp_dump.c
divided_cmd_utility.c
gs_command_dispatcher.c
event_utility.c
Expand Down
149 changes: 149 additions & 0 deletions applications/ccp_dump.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
#pragma section REPRO
/**
* @file
* @brief TL や CDIS などの PacketList や BCT の CCP をダンプする (GS から内容を確認できるようにする) ための App
*/
#include "ccp_dump.h"
#include <stddef.h>
#include <string.h>
#include "../tlm_cmd/command_dispatcher_manager.h"
#include "../system/time_manager/time_manager.h"

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

static RESULT CCP_DUMP_cdis_(const CommandDispatcher* cdis);
static RESULT CCP_DUMP_bct_(void);


static CcpDump ccp_dump_;
const CcpDump* const ccp_dump = &ccp_dump_;


AppInfo CCP_DUMP_create_app(void)
{
return AI_create_app_info("ccpdump", CCP_DUMP_init_, NULL);
}


static RESULT CCP_DUMP_init_(void)
{
memset(&ccp_dump_, 0x00, sizeof(CcpDump));

// 初回はなにもダンプしてないので
ccp_dump_.dump.status = CCP_DUMP_STATUS_NOT_FOUND;
return RESULT_OK;
}


CCP_CmdRet Cmd_CCP_DUMP_CDIS(const CommonCmdPacket* packet)
{
CCP_DUMP_CdisDump* cdis_dump = &ccp_dump_.info.cdis;
const CommandDispatcher* cdis;
cdis_dump->cdis_idx = CCP_get_param_from_packet(packet, 0, uint8_t);
cdis_dump->queue_idx = CCP_get_param_from_packet(packet, 1, uint16_t);

cdis = CDIS_MGR_get_cdis(cdis_dump->cdis_idx);

ccp_dump_.dump.target = CCP_DUMP_TARGET_CDIS;

if (cdis == NULL)
{
ccp_dump_.dump.status = CCP_DUMP_STATUS_NOT_FOUND;
return CCP_make_cmd_ret(CCP_EXEC_ILLEGAL_PARAMETER, 1);
}
if (PL_count_active_nodes(cdis->pl) <= cdis_dump->queue_idx)
{
ccp_dump_.dump.status = CCP_DUMP_STATUS_NOT_FOUND;
return CCP_make_cmd_ret(CCP_EXEC_ILLEGAL_PARAMETER, 2);
}

if (CCP_DUMP_cdis_(cdis) == RESULT_OK)
{
ccp_dump_.dump.status = CCP_DUMP_STATUS_OK;
ccp_dump_.dump.dump_time = TMGR_get_master_clock();
return CCP_make_cmd_ret_without_err_code(CCP_EXEC_SUCCESS);
}
else
{
ccp_dump_.dump.status = CCP_DUMP_STATUS_NOT_FOUND;
return CCP_make_cmd_ret(CCP_EXEC_ILLEGAL_PARAMETER, 3);
}
}


static RESULT CCP_DUMP_cdis_(const CommandDispatcher* cdis)
{
const CCP_DUMP_CdisDump* cdis_dump = &ccp_dump_.info.cdis;
const PacketList* pl = cdis->pl;
const PL_Node* node = PL_get_head(pl);
const CommonCmdPacket* ccp;
uint16_t i;

for (i = 0; i < cdis_dump->queue_idx; ++i)
{
node = PL_get_next(node);
}
if (node == NULL)
{
return RESULT_ERR;
}

ccp = (const CommonCmdPacket*)PL_get_packet(node);

// CCP_copy_packet はパケット長しかコピーしない.ここではダンプなので,末端の不定もふくめてコピーする
memcpy(ccp_dump_.dump.ccp.packet, ccp->packet, CSP_MAX_LEN);
return RESULT_OK;
}


CCP_CmdRet Cmd_CCP_DUMP_BCT(const CommonCmdPacket* packet)
{
CCP_DUMP_BctDump* bct_dump = &ccp_dump_.info.bct;
bct_dump->pos.block = (bct_id_t)CCP_get_param_from_packet(packet, 0, uint16_t);
bct_dump->pos.cmd = CCP_get_param_from_packet(packet, 1, uint8_t);

ccp_dump_.dump.target = CCP_DUMP_TARGET_BCT;

if (BCT_check_position(&bct_dump->pos) != BCT_SUCCESS)
{
ccp_dump_.dump.status = CCP_DUMP_STATUS_NOT_FOUND;
return CCP_make_cmd_ret(CCP_EXEC_ILLEGAL_PARAMETER, 1);
}

if (CCP_DUMP_bct_() == RESULT_OK)
{
ccp_dump_.dump.status = CCP_DUMP_STATUS_OK;
ccp_dump_.dump.dump_time = TMGR_get_master_clock();
return CCP_make_cmd_ret_without_err_code(CCP_EXEC_SUCCESS);
}
else
{
ccp_dump_.dump.status = CCP_DUMP_STATUS_NOT_FOUND;
return CCP_make_cmd_ret(CCP_EXEC_ILLEGAL_PARAMETER, 2);
}
}


static RESULT CCP_DUMP_bct_(void)
{
CCP_DUMP_BctDump* bct_dump = &ccp_dump_.info.bct;

// BCT は CCP 長さが短いので,末尾を 0 埋めしておく
memset(&ccp_dump_.dump.ccp, 0x00, sizeof(CommonCmdPacket));

if (BCT_load_cmd(&bct_dump->pos, &ccp_dump_.dump.ccp) == BCT_SUCCESS)
{
return RESULT_OK;
}
else
{
return RESULT_ERR;
}
}

#pragma section
81 changes: 81 additions & 0 deletions applications/ccp_dump.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* @file
* @brief CDIS などの PacketList や BCT の CCP をダンプする (GS から内容を確認できるようにする) ための App
*/
#ifndef CCP_DUMP_H_
#define CCP_DUMP_H_

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

/**
* @enum CCP_DUMP_TARGET
* @note uint8_t を想定
* @brief ダンプした CCP のダンプ元
*/
typedef enum
{
CCP_DUMP_TARGET_CDIS, //!< CDIS
CCP_DUMP_TARGET_BCT //!< BCT
} CCP_DUMP_TARGET;

/**
* @enum CCP_DUMP_STATUS
* @note uint8_t を想定
* @brief ダンプ結果
*/
typedef enum
{
CCP_DUMP_STATUS_OK, //!< ダンプ成功
CCP_DUMP_STATUS_NOT_FOUND //!< CCP が存在せず
} CCP_DUMP_STATUS;

/**
* @struct CCP_DUMP_CdisDump
* @brief CDIS のダンプ
*/
typedef struct
{
uint8_t cdis_idx; //!< CommandDispatcher.idx
uint16_t queue_idx; //!< CDIS の queue の何番目の CCP か
} CCP_DUMP_CdisDump;

/**
* @struct CCP_DUMP_BctDump
* @brief BCT のダンプ
*/
typedef struct
{
BCT_Pos pos; //!< ダンプする BCT の位置
} CCP_DUMP_BctDump;

/**
* @struct CcpDump
* @brief CcpDump の AppInfo 構造体
*/
typedef struct
{
struct
{
CCP_DUMP_CdisDump cdis;
CCP_DUMP_BctDump bct;
} info; //!< ダンブ情報(ダンプするパラメタ)
struct
{
CommonCmdPacket ccp; //!< ダンプした CCP
CCP_DUMP_TARGET target; //!< ダンプ元
CCP_DUMP_STATUS status; //!< ダンプ結果
ObcTime dump_time; //!< ダンプした時刻
} dump;
} CcpDump;

extern const CcpDump* const ccp_dump;

AppInfo CCP_DUMP_create_app(void);

CCP_CmdRet Cmd_CCP_DUMP_CDIS(const CommonCmdPacket* packet);
CCP_CmdRet Cmd_CCP_DUMP_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 @@ -12,6 +12,7 @@
#include <src_core/applications/timeline_command_dispatcher.h>
#include <src_core/applications/event_utility.h>
#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/utility_command.h>
#include <src_core/applications/utility_counter.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 @@ -27,6 +27,7 @@ void AR_load_initial_settings(void)
add_application_(AR_CSRV_AOBC_CDIS, CSRV_AOBC_cmd_dispatcher);
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_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 @@ -22,6 +22,7 @@ typedef enum
#endif
AR_EVENT_UTILITY,
AR_MEM_DUMP,
AR_CCP_DUMP,
AR_TELEMETRY_MANAGER,
AR_DIVIDED_CMD_UTILITY,
AR_UTILITY_CMD,
Expand Down
Loading

0 comments on commit 413caa1

Please sign in to comment.