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

CommandDispatcher の統一的なテレメの提供 #18

Merged
merged 11 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from 10 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
1 change: 1 addition & 0 deletions Applications/divided_cmd_utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#define DCU_LOG_MAX (16) //!< 保存するログの最大数

// DCU_LOG_MAX の user オーバーライド
#include <src_user/Settings/Applications/divided_cmd_utility_params.h>

// key が uint8_t なので,それ以下を要請する
Expand Down
3 changes: 1 addition & 2 deletions Applications/gs_command_dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ AppInfo GSCD_create_app(void)

static RESULT GSCD_init_(void)
{
gs_command_dispatcher_ = CDIS_init(&PH_gs_cmd_list);
return RESULT_OK;
return CDIS_init(&gs_command_dispatcher_, &PH_gs_cmd_list);
}

static RESULT GSCD_dispatch_(void)
Expand Down
3 changes: 1 addition & 2 deletions Applications/realtime_command_dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ AppInfo RTCD_create_app(void)

static RESULT RTCD_init_(void)
{
realtime_command_dispatcher_ = CDIS_init(&PH_rt_cmd_list);
return RESULT_OK;
return CDIS_init(&realtime_command_dispatcher_, &PH_rt_cmd_list);
}

static RESULT RTCD_dispatch_(void)
Expand Down
13 changes: 5 additions & 8 deletions Applications/timeline_command_dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ AppInfo TLCD_gs_create_app(void)

static RESULT TLCD_gs_init_(void)
{
timeline_command_dispatcher_.dispatcher[TLCD_ID_FROM_GS] = CDIS_init(&(PH_tl_cmd_list[TLCD_ID_FROM_GS]));
RESULT ret = CDIS_init(&timeline_command_dispatcher_.dispatcher[TLCD_ID_FROM_GS], &(PH_tl_cmd_list[TLCD_ID_FROM_GS]));

// タイムラインコマンドのテレメトリ変数初期設定
// すべてのタイムラインで共用なので TLCD_gs で代表して初期化
Expand All @@ -56,7 +56,7 @@ static RESULT TLCD_gs_init_(void)

memset(&TLCD_null_packet_, 0, sizeof(TLCD_null_packet_));
TLCD_update_tl_list_for_tlm(TLCD_ID_FROM_GS);
return RESULT_OK;
return ret;
}

static RESULT TLCD_gs_dispatch_(void)
Expand All @@ -72,8 +72,7 @@ AppInfo TLCD_bc_create_app(void)

static RESULT TLCD_bc_init_(void)
{
timeline_command_dispatcher_.dispatcher[TLCD_ID_DEPLOY_BC] = CDIS_init(&(PH_tl_cmd_list[TLCD_ID_DEPLOY_BC]));
return RESULT_OK;
return CDIS_init(&timeline_command_dispatcher_.dispatcher[TLCD_ID_DEPLOY_BC], &(PH_tl_cmd_list[TLCD_ID_DEPLOY_BC]));
}

static RESULT TLCD_bc_dispatch_(void)
Expand All @@ -89,8 +88,7 @@ AppInfo TLCD_tlm_create_app(void)

static RESULT TLCD_tlm_init_(void)
{
timeline_command_dispatcher_.dispatcher[TLCD_ID_DEPLOY_TLM] = CDIS_init(&(PH_tl_cmd_list[TLCD_ID_DEPLOY_TLM]));
return RESULT_OK;
return CDIS_init(&timeline_command_dispatcher_.dispatcher[TLCD_ID_DEPLOY_TLM], &(PH_tl_cmd_list[TLCD_ID_DEPLOY_TLM]));
}

static RESULT TLCD_tlm_dispatch_(void)
Expand All @@ -107,8 +105,7 @@ AppInfo TLCD_mis_create_app(void)

static RESULT TLCD_mis_init_(void)
{
timeline_command_dispatcher_.dispatcher[TLCD_ID_FROM_GS_FOR_MISSION] = CDIS_init(&(PH_tl_cmd_list[TLCD_ID_FROM_GS_FOR_MISSION]));
return RESULT_OK;
return CDIS_init(&timeline_command_dispatcher_.dispatcher[TLCD_ID_FROM_GS_FOR_MISSION], &(PH_tl_cmd_list[TLCD_ID_FROM_GS_FOR_MISSION]));
}

static RESULT TLCD_mis_dispatch_(void)
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ set(C2A_SRCS
TlmCmd/block_command_executor.c
TlmCmd/command_analyze.c
TlmCmd/command_dispatcher.c
TlmCmd/command_dispatcher_manager.c
TlmCmd/common_cmd_packet_util.c
TlmCmd/packet_handler.c
TlmCmd/packet_list_util.c
Expand Down
2 changes: 1 addition & 1 deletion System/TaskManager/task_dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void TDSP_initialize(void)
PL_initialize_with_ccp(task_stock_, packet_stock_, TDSP_TASK_MAX, &TDSP_task_list_);

// タスクリストを初期化し、INITIALモードのブロックコマンドを展開する
task_dispatcher_.tskd = CDIS_init(&TDSP_task_list_);
CDIS_init(&task_dispatcher_.tskd, &TDSP_task_list_);
task_dispatcher_.task_list_id = MM_get_tasklist_id_of_mode(MD_MODEID_START_UP);
TDSP_deploy_block_as_task_list_();
task_dispatcher_.activated_at = 0;
Expand Down
57 changes: 40 additions & 17 deletions TlmCmd/command_dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
* @brief 各種コマンドの実行管理
*/
#include "command_dispatcher.h"
#include <src_user/TlmCmd/command_definitions.h>
#include "command_dispatcher_manager.h"
#include <string.h>
#include "../System/TimeManager/time_manager.h"
#include "../System/EventManager/event_logger.h"
#include "packet_handler.h"
#include <src_user/TlmCmd/command_definitions.h>

// TODO: 本当は,不正な CDISは pl == NULL などにしておくのが良さそうだが,
// 現状 PL が NULL チェックをしてないので,できない
Expand All @@ -21,6 +23,7 @@ typedef enum
{
CDIS_EL_LOCAL_ID_NULL_PARAM, //!< NULL 引数
CDIS_EL_LOCAL_ID_INVALID_PL, //!< 不正な PL
CDIS_EL_LOCAL_ID_CDIS_MGR_ERR, //!< CDIS MGR キャパオーバー
CDIS_EL_LOCAL_ID_UNKNOWN
} CDIS_EL_LOCAL_ID;

Expand All @@ -32,26 +35,32 @@ typedef enum
static void CDIS_clear_exec_info_(CDIS_ExecInfo* exec_info);


CommandDispatcher CDIS_init(PacketList* pl)
RESULT CDIS_init(CommandDispatcher* cdis, PacketList* pl)
{
CommandDispatcher cdis;
static uint8_t init_counter = 0;
static uint8_t is_first_call_ = 1;
static uint8_t cdis_overflow_counter_ = 0;
RESULT ret;

if (is_first_call_)
{
CDIS_MGR_initialize();
}
is_first_call_ = 0;

cdis.idx = init_counter;
init_counter++;
// 初期化
memset(cdis, 0x00, sizeof(CommandDispatcher));

// コマンド実行情報を初期化
CDIS_clear_exec_info_(&cdis.prev);
CDIS_clear_exec_info_(&cdis.prev_err);
CDIS_clear_exec_info_(&cdis->prev);
CDIS_clear_exec_info_(&cdis->prev_err);

// 実行エラーカウンタを0に初期化
cdis.error_counter = 0;
// 実行エラーカウンタを初期化
CDIS_clear_error_status(cdis);

// 実行中断フラグを無効に設定
cdis.lockout = 0;

cdis->lockout = 0;
// 異常時実行中断フラグを無効に設定
cdis.stop_on_error = 0;
cdis->stop_on_error = 0;

// 処理対象とするPacketListをクリアして登録
if (pl == NULL)
Expand All @@ -61,7 +70,7 @@ CommandDispatcher CDIS_init(PacketList* pl)
CDIS_EL_LOCAL_ID_NULL_PARAM,
EL_ERROR_LEVEL_HIGH,
0);
return cdis;
return RESULT_ERR;
}
if (PL_get_packet_type(pl) != PL_PACKET_TYPE_CCP)
{
Expand All @@ -70,12 +79,26 @@ CommandDispatcher CDIS_init(PacketList* pl)
CDIS_EL_LOCAL_ID_INVALID_PL,
EL_ERROR_LEVEL_HIGH,
(uint32_t)pl);
return cdis;
return RESULT_ERR;
}
PL_clear_list(pl);
cdis.pl = pl;
cdis->pl = pl;

ret = CDIS_MGR_register_cdis(cdis, &cdis->idx);
if (ret != RESULT_OK)
{
// CDIS MGR のキャパオーバー
EL_record_event((EL_GROUP)EL_CORE_GROUP_CDIS_INTERNAL_ERR,
CDIS_EL_LOCAL_ID_CDIS_MGR_ERR,
EL_ERROR_LEVEL_LOW,
(uint32_t)cdis);
cdis_overflow_counter_++;
// 仕方がないのでユニークな idx を割り振る(同一 CDIS でも初期化のたびに異なる idx になってしまう)
cdis->idx = cdis_overflow_counter_ + CDIS_MGR_MAX_NUM_OF_CDIS;
return RESULT_ERR;
}

return cdis;
return RESULT_OK;
}


Expand Down
15 changes: 9 additions & 6 deletions TlmCmd/command_dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "common_cmd_packet.h"
#include "packet_list.h"
#include "../System/TimeManager/obc_time.h"
#include "../Library/result.h"
#include <src_user/TlmCmd/command_definitions.h>

/**
Expand All @@ -28,23 +29,25 @@ typedef struct
*/
typedef struct
{
uint8_t idx; //!< CDIS のインデックス. EL で用いる
uint8_t idx; //!< CDIS のインデックス. EL, command_dispatcher_manager で用いる
CDIS_ExecInfo prev; //!< 前回のコマンド実行情報
CDIS_ExecInfo prev_err; //!< 最後にエラーが出たコマンド実行情報
uint32_t error_counter; //!< エラーカウンタ
int lockout; //!< 実行中断フラグ
int stop_on_error; //!< 異常時実行中断フラグ
int stop_on_error; //!< 異常時実行中断フラグ // FIXME: きちんと実装する
PacketList* pl; //!< コマンドキュー
} CommandDispatcher;


/**
* @brief CDIS の初期化と取得
* @brief CDIS の初期化
* @note 各種 CommandDispatcher App (Realtime Command Dispatcher とか) でこれを呼び,使う
* @param[in] pl: この CDIS と紐付けるコマンドキューの PacketList
* @return 初期化された CommandDispatcher
* @param[out] cdis: 初期化する CDIS
* @param[in] pl: この CDIS と紐付けるコマンドキューの PacketList
* @retval RESULT_OK: 正常終了
* @retval RESULT_ERR: 不正入力 or CDIS の初期化はしたが, CDIS_MGR への登録に失敗した(キャパオーバー)
*/
CommandDispatcher CDIS_init(PacketList* pl);
RESULT CDIS_init(CommandDispatcher* cdis, PacketList* pl);

/**
* @brief CDIS に登録されているコマンドキューからコマンドを実行
Expand Down
85 changes: 85 additions & 0 deletions TlmCmd/command_dispatcher_manager.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#pragma section REPRO
/**
* @file
* @brief Command Dispatcher Manager
* @note 様々な CDIS を一括管理する
* @note 例えば,様々な CDIS のテレメトリをいちいち作るのはめんどくさい(とくに MOBC にある sub OBC 用の CDIS)ため,それを一括で提供する
*/
#include "command_dispatcher_manager.h"
#include <stddef.h>
#include <string.h>
#include "./common_cmd_packet_util.h"

/**
* @brief cdis を cdis mgr に登録されているか探し,見つかった場合は idx を返す
* @note CDIS_init から呼ばれることを想定
* @param[in] cdis: 探す cdis のポインタ
* @param[out] cdis: 見つかった idx
* @retval RESULT_OK: 見つかった(登録されている)
* @retval RESULT_ERR: 見つからず(登録されていない)
*/
static RESULT CDIS_MGR_find_cdis_(const CommandDispatcher* cdis, uint8_t* idx);

static CommandDispatcherManager command_dispatcher_manager_;
const CommandDispatcherManager* const command_dispatcher_manager = &command_dispatcher_manager_;


void CDIS_MGR_initialize(void)
{
uint8_t idx;
memset(&command_dispatcher_manager_, 0x00, sizeof(command_dispatcher_manager_));
for (idx = 0; idx < CDIS_MGR_MAX_NUM_OF_CDIS; ++idx)
{
command_dispatcher_manager_.cdises[idx] = NULL;
}
}


RESULT CDIS_MGR_register_cdis(const CommandDispatcher* cdis, uint8_t* idx)
{
if (CDIS_MGR_find_cdis_(cdis, idx) == RESULT_OK)
{
return RESULT_OK;
}

if (command_dispatcher_manager_.num_of_cdis >= CDIS_MGR_MAX_NUM_OF_CDIS)
{
return RESULT_ERR;
}

*idx = command_dispatcher_manager_.num_of_cdis;
command_dispatcher_manager_.cdises[command_dispatcher_manager_.num_of_cdis] = cdis;
command_dispatcher_manager_.num_of_cdis++;

return RESULT_OK;
}


static RESULT CDIS_MGR_find_cdis_(const CommandDispatcher* cdis, uint8_t* idx)
{
uint8_t i;
for (i = 0; i < command_dispatcher_manager_.num_of_cdis; ++i)
{
if (command_dispatcher_manager_.cdises[i] == cdis)
{
*idx = i;
return RESULT_OK;
}
}
return RESULT_ERR;
}


CCP_CmdRet Cmd_CDIS_MGR_SET_IDX_FOR_TLM(const CommonCmdPacket* packet)
{
uint8_t idx_for_tlm = CCP_get_param_from_packet(packet, 0, uint8_t);
if (idx_for_tlm >= command_dispatcher_manager_.num_of_cdis)
{
return CCP_make_cmd_ret(CCP_EXEC_ILLEGAL_PARAMETER, idx_for_tlm);
}

command_dispatcher_manager_.idx_for_tlm = idx_for_tlm;
return CCP_make_cmd_ret_without_err_code(CCP_EXEC_SUCCESS);
}

#pragma section
54 changes: 54 additions & 0 deletions TlmCmd/command_dispatcher_manager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* @file
* @brief Command Dispatcher Manager
* @note 様々な CDIS を一括管理する
* @note 例えば,様々な CDIS のテレメトリをいちいち作るのはめんどくさい(とくに MOBC にある sub OBC 用の CDIS)ため,それを一括で提供する
*/
#ifndef COMMAND_DISPATCHER_MANAGER_H_
#define COMMAND_DISPATCHER_MANAGER_H_

#include "./common_cmd_packet.h"
#include "./command_dispatcher.h"
#include "../Library/result.h"

#define CDIS_MGR_MAX_NUM_OF_CDIS (7) /*!< 保持する CDIS の最大数
RT, TL * 4, GS, TDSP */

// CDIS_MGR_MAX_NUM_OF_CDIS の user オーバーライド
#include <src_user/Settings/TlmCmd/command_dispatcher_manager_params.h>

/**
* @struct CommandDispatcherManager
* @brief CommandDispatcherManager の AppInfo 構造体
*/
typedef struct
{
const CommandDispatcher* cdises[CDIS_MGR_MAX_NUM_OF_CDIS];
uint8_t num_of_cdis;
uint8_t idx_for_tlm;
} CommandDispatcherManager;

extern const CommandDispatcherManager* const command_dispatcher_manager;


/**
* @brief Command Dispatcher Manager の初期化
* @param void
* @return void
*/
void CDIS_MGR_initialize(void);

/**
* @brief cdis を cdis mgr に登録すし,登録した idx を返す
* @note CDIS_init から呼ばれることを想定
* @note 同じアプリ内でも CDIS_init は複数回呼ばれる可能性があるので,重複登録はケアされる
* @param[in] cdis: 登録する cdis のポインタ
* @param[out] cdis: 登録した idx
* @retval RESULT_OK: 登録に成功 or すでに登録されている
* @retval RESULT_ERR: 登録に失敗(サイズオーバー)
*/
RESULT CDIS_MGR_register_cdis(const CommandDispatcher* cdis, uint8_t* idx);

CCP_CmdRet Cmd_CDIS_MGR_SET_IDX_FOR_TLM(const CommonCmdPacket* packet);

#endif
3 changes: 3 additions & 0 deletions TlmCmd/packet_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ void PL_clear_list(PacketList* pl)
pl->inactive_list_head_ = pl->pl_node_stock_;
pl->active_list_head_ = NULL;
pl->active_list_tail_ = NULL;

// カウンタリセット
pl->executed_nodes_ = 0;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ AppInfo DI_AOBC_cmd_dispatcher(void)

static RESULT DI_AOBC_cmd_dispatcher_init_(void)
{
DI_AOBC_cdis_ = CDIS_init(&PH_aobc_cmd_list);
return RESULT_OK;
return CDIS_init(&DI_AOBC_cdis_, &PH_aobc_cmd_list);
}


Expand Down
Loading
Loading