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

デモ用のアプリ #411

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions examples/mobc/src/src_user/applications/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(C2A_SRCS
component_service/csrv_aobc.c
component_service/csrv_gs.c
component_service/csrv_uart_test.c
user_defined/etc/demo_calculator.c
user_defined/debug_apps.c
)

Expand Down
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 @@ -29,6 +29,7 @@
#include "component_service/csrv_gs.h"

// UserDefined
#include "user_defined/etc/demo_calculator.h"
#include "user_defined/debug_apps.h"

#endif
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 @@ -34,6 +34,7 @@ void AR_load_initial_settings(void)
add_application_(AR_CDRV_UTIL, CDRV_UTIL_create_app);
add_application_(AR_UTILITY_CMD, UTIL_CMD_create_app);
// add_application_(AR_UTILITY_COUNTER, UTIL_COUNTER_create_app);
add_application_(AR_APP_DEMO_CALCULATOR, APP_CALC_create_app);
add_application_(AR_APP_DBG_FLUSH_SCREEN, APP_DBG_flush_screen);
add_application_(AR_APP_DBG_PRINT_TIMESTAMP, APP_DBG_print_time_stamp);
add_application_(AR_APP_DBG_PRINT_CMD_STATUS, APP_DBG_print_cmd_status);
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 @@ -29,6 +29,7 @@ typedef enum
AR_CDRV_UTIL,
AR_UTILITY_CMD,
AR_UTILITY_COUNTER,
AR_APP_DEMO_CALCULATOR,
AR_APP_DBG_FLUSH_SCREEN,
AR_APP_DBG_PRINT_TIMESTAMP,
AR_APP_DBG_PRINT_CMD_STATUS,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#pragma section REPRO
/**
* @file
* @brief Application の雛形や,アトミック操作のデモのための,実利用価値はないデモアプリ
*/
#include "demo_calculator.h"
#include <stddef.h>
#include <string.h>
#include <src_core/system/time_manager/time_manager.h>
#include <src_core/tlm_cmd/common_packet/common_cmd_packet_util.h>

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

static DemoCalculator demo_calculator_;
const DemoCalculator* const demo_calculator = &demo_calculator_;


AppInfo APP_CALC_create_app(void)
{
return AI_create_app_info("demo_calc", APP_CALC_init_, APP_CALC_exec_);
}


static RESULT APP_CALC_init_(void)
{
memset(&demo_calculator_, 0x00, sizeof(DemoCalculator));
return RESULT_OK;
}


static RESULT APP_CALC_exec_(void)
{
demo_calculator_.info.exec_count++;
demo_calculator_.info.last_exec_time = TMGR_get_master_clock();
demo_calculator_.info.status = APP_CALC_STATUS_OK;

switch (demo_calculator_.calc.operator)
{
case APP_CALC_OPERATOR_ADD:
demo_calculator_.calc.result = demo_calculator_.calc.a + demo_calculator_.calc.b;
break;
case APP_CALC_OPERATOR_SUB:
demo_calculator_.calc.result = demo_calculator_.calc.a - demo_calculator_.calc.b;
break;
case APP_CALC_OPERATOR_MUL:
demo_calculator_.calc.result = demo_calculator_.calc.a * demo_calculator_.calc.b;
break;
case APP_CALC_OPERATOR_DIV:
if (demo_calculator_.calc.b == 0)
{
demo_calculator_.info.status = APP_CALC_STATUS_ERR_DIV_BY_ZERO;
demo_calculator_.info.err_count++;
return RESULT_ERR;
}
demo_calculator_.calc.result = demo_calculator_.calc.a / demo_calculator_.calc.b;
break;
case APP_CALC_OPERATOR_MOD:
if (demo_calculator_.calc.b == 0)
{
demo_calculator_.info.status = APP_CALC_STATUS_ERR_DIV_BY_ZERO;
demo_calculator_.info.err_count++;
return RESULT_ERR;
}
demo_calculator_.calc.result = demo_calculator_.calc.a % demo_calculator_.calc.b;
break;
default:
demo_calculator_.info.status = APP_CALC_STATUS_ERR_UNKNOWN;
demo_calculator_.info.err_count++;
return RESULT_ERR;
}

return RESULT_OK;
}


CCP_CmdRet Cmd_APP_CALC_EXEC(const CommonCmdPacket* packet)
{
(void)packet;

if (APP_CALC_exec_() == RESULT_ERR)
{
return CCP_make_cmd_ret(CCP_EXEC_ILLEGAL_CONTEXT, demo_calculator_.info.status);
}

return CCP_make_cmd_ret_without_err_code(CCP_EXEC_SUCCESS);
}


CCP_CmdRet Cmd_APP_CALC_SET_A(const CommonCmdPacket* packet)
{
demo_calculator_.calc.a = CCP_get_param_from_packet(packet, 0, int32_t);
return CCP_make_cmd_ret_without_err_code(CCP_EXEC_SUCCESS);
}


CCP_CmdRet Cmd_APP_CALC_SET_B(const CommonCmdPacket* packet)
{
demo_calculator_.calc.b = CCP_get_param_from_packet(packet, 0, int32_t);
return CCP_make_cmd_ret_without_err_code(CCP_EXEC_SUCCESS);
}


CCP_CmdRet Cmd_APP_CALC_SET_OP(const CommonCmdPacket* packet){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [check_coding_rule] reported by reviewdog 🐶
PROHIBITED PATTERNS:'){' (SPACE IS REQUIRED)

APP_CALC_OPERATOR op = (APP_CALC_OPERATOR)CCP_get_param_from_packet(packet, 0, uint8_t);

if (op >= APP_CALC_OPERATOR_MAX)
{
return CCP_make_cmd_ret(CCP_EXEC_ILLEGAL_PARAMETER, op);
}

demo_calculator_.calc.operator = op;
return CCP_make_cmd_ret_without_err_code(CCP_EXEC_SUCCESS);
}


CCP_CmdRet Cmd_APP_CALC_RESET(const CommonCmdPacket* packet)
{
(void)packet;
APP_CALC_init_();
return CCP_make_cmd_ret_without_err_code(CCP_EXEC_SUCCESS);
}

#pragma section
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* @file
* @brief Application の雛形や,アトミック操作のデモのための,実利用価値はないデモアプリ
*/
#ifndef DEMO_CALCULATOR_H_
#define DEMO_CALCULATOR_H_

#include <src_core/system/application_manager/app_info.h>
#include <src_core/tlm_cmd/common_packet/common_cmd_packet.h>
#include <src_core/system/time_manager/obc_time.h>

/**
* @enum APP_CALC_OPERATOR
* @note uint8_t を想定
* @brief 演算子
*/
typedef enum
{
APP_CALC_OPERATOR_ADD, //!< addition
APP_CALC_OPERATOR_SUB, //!< subtraction
APP_CALC_OPERATOR_MUL, //!< multiply
APP_CALC_OPERATOR_DIV, //!< division
APP_CALC_OPERATOR_MOD, //!< modulo
APP_CALC_OPERATOR_MAX
} APP_CALC_OPERATOR;

/**
* @enum APP_CALC_STATUS
* @note uint8_t を想定
* @brief 演算結果
*/
typedef enum
{
APP_CALC_STATUS_OK, //!< OK
APP_CALC_STATUS_ERR_DIV_BY_ZERO, //!< 0 割エラー
APP_CALC_STATUS_ERR_UNKNOWN //!< 不明なエラー
} APP_CALC_STATUS;

/**
* @struct DemoCalculator
* @brief DemoCalculator の AppInfo 構造体
*/
typedef struct
{
struct
{
uint32_t exec_count; //!< 実行回数
uint32_t err_count; //!< エラーカウント
ObcTime last_exec_time; //!< 最終実行時刻
APP_CALC_STATUS status; //!< 最終実行結果
} info; //!< 実行状況
struct
{
int32_t a; //!< 第 1 引数
int32_t b; //!< 第 2 引数
int32_t result; //!< 結果
APP_CALC_OPERATOR operator; //!< 演算子
} calc; //!< 計算
} DemoCalculator;

extern const DemoCalculator* const demo_calculator;

AppInfo APP_CALC_create_app(void);

CCP_CmdRet Cmd_APP_CALC_EXEC(const CommonCmdPacket* packet);
CCP_CmdRet Cmd_APP_CALC_SET_A(const CommonCmdPacket* packet);
CCP_CmdRet Cmd_APP_CALC_SET_B(const CommonCmdPacket* packet);
CCP_CmdRet Cmd_APP_CALC_SET_OP(const CommonCmdPacket* packet);
CCP_CmdRet Cmd_APP_CALC_RESET(const CommonCmdPacket* packet);

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @note コード生成元 tlm-cmd-db:
* repository: github.com/arkedge/c2a-core.git
* CSV files MD5: 0e38aad788fca6fba1d44684152ac1a2
* db commit hash: e1e6b79acd85523f04266f1c08b7a3b89e5b6e05
* db commit hash: 488124bf75deb7fe29d0509b111b208630d310b1
* @note コード生成パラメータ:
* name: AOBC
* db_prefix: SAMPLE_AOBC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @note コード生成元 tlm-cmd-db:
* repository: github.com/arkedge/c2a-core.git
* CSV files MD5: 0e38aad788fca6fba1d44684152ac1a2
* db commit hash: e1e6b79acd85523f04266f1c08b7a3b89e5b6e05
* db commit hash: 488124bf75deb7fe29d0509b111b208630d310b1
* @note コード生成パラメータ:
* name: AOBC
* db_prefix: SAMPLE_AOBC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @note コード生成元 tlm-cmd-db:
* repository: github.com/arkedge/c2a-core.git
* CSV files MD5: 0e38aad788fca6fba1d44684152ac1a2
* db commit hash: e1e6b79acd85523f04266f1c08b7a3b89e5b6e05
* db commit hash: 488124bf75deb7fe29d0509b111b208630d310b1
* @note コード生成パラメータ:
* name: AOBC
* db_prefix: SAMPLE_AOBC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @note コード生成元 tlm-cmd-db:
* repository: github.com/arkedge/c2a-core.git
* CSV files MD5: 0e38aad788fca6fba1d44684152ac1a2
* db commit hash: e1e6b79acd85523f04266f1c08b7a3b89e5b6e05
* db commit hash: 488124bf75deb7fe29d0509b111b208630d310b1
* @note コード生成パラメータ:
* name: AOBC
* db_prefix: SAMPLE_AOBC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @note コード生成元 tlm-cmd-db:
* repository: github.com/arkedge/c2a-core.git
* CSV files MD5: 0e38aad788fca6fba1d44684152ac1a2
* db commit hash: e1e6b79acd85523f04266f1c08b7a3b89e5b6e05
* db commit hash: 488124bf75deb7fe29d0509b111b208630d310b1
* @note コード生成パラメータ:
* name: AOBC
* db_prefix: SAMPLE_AOBC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @note このコードは自動生成されています!
* @note コード生成元 tlm-cmd-db:
* repository: github.com/arkedge/c2a-core.git
* CSV files MD5: a6ac3f58e1422615904c43d389e64877
* CSV files MD5: cdfb84318ccef71e1e893aa4e68d0efa
* @note コード生成パラメータ:
* db_prefix: SAMPLE_MOBC
* tlm_id_range: [0x00, 0x100]
Expand Down
10 changes: 9 additions & 1 deletion examples/mobc/src/src_user/tlm_cmd/command_definitions.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @note このコードは自動生成されています!
* @note コード生成元 tlm-cmd-db:
* repository: github.com/arkedge/c2a-core.git
* CSV files MD5: a6ac3f58e1422615904c43d389e64877
* CSV files MD5: cdfb84318ccef71e1e893aa4e68d0efa
* @note コード生成パラメータ:
* db_prefix: SAMPLE_MOBC
* tlm_id_range: [0x00, 0x100]
Expand Down Expand Up @@ -196,6 +196,11 @@ void CA_load_cmd_table(CA_CmdInfo cmd_table[CA_MAX_CMDS])
cmd_table[Cmd_CODE_UART_TEST_INIT_CSRV].cmd_func = Cmd_UART_TEST_INIT_CSRV;
cmd_table[Cmd_CODE_UART_TEST_UPDATE].cmd_func = Cmd_UART_TEST_UPDATE;
cmd_table[Cmd_CODE_UART_TEST_SEND_TEST].cmd_func = Cmd_UART_TEST_SEND_TEST;
cmd_table[Cmd_CODE_APP_CALC_EXEC].cmd_func = Cmd_APP_CALC_EXEC;
cmd_table[Cmd_CODE_APP_CALC_SET_A].cmd_func = Cmd_APP_CALC_SET_A;
cmd_table[Cmd_CODE_APP_CALC_SET_B].cmd_func = Cmd_APP_CALC_SET_B;
cmd_table[Cmd_CODE_APP_CALC_SET_OP].cmd_func = Cmd_APP_CALC_SET_OP;
cmd_table[Cmd_CODE_APP_CALC_RESET].cmd_func = Cmd_APP_CALC_RESET;
cmd_table[Cmd_CODE_UTIL_CMD_ADD].cmd_func = Cmd_UTIL_CMD_ADD;
cmd_table[Cmd_CODE_UTIL_CMD_SEND].cmd_func = Cmd_UTIL_CMD_SEND;
cmd_table[Cmd_CODE_UTIL_CMD_RESET].cmd_func = Cmd_UTIL_CMD_RESET;
Expand Down Expand Up @@ -421,6 +426,9 @@ void CA_load_cmd_table(CA_CmdInfo cmd_table[CA_MAX_CMDS])
cmd_table[Cmd_CODE_CSRV_GS_SET_INFO].param_size_infos[0].packed_info.bit.first = CA_PARAM_SIZE_TYPE_1BYTE;
cmd_table[Cmd_CODE_CSRV_GS_CCSDS_SET_RATE].param_size_infos[0].packed_info.bit.first = CA_PARAM_SIZE_TYPE_1BYTE;
cmd_table[Cmd_CODE_UART_TEST_SEND_TEST].param_size_infos[0].packed_info.bit.first = CA_PARAM_SIZE_TYPE_1BYTE;
cmd_table[Cmd_CODE_APP_CALC_SET_A].param_size_infos[0].packed_info.bit.first = CA_PARAM_SIZE_TYPE_4BYTE;
cmd_table[Cmd_CODE_APP_CALC_SET_B].param_size_infos[0].packed_info.bit.first = CA_PARAM_SIZE_TYPE_4BYTE;
cmd_table[Cmd_CODE_APP_CALC_SET_OP].param_size_infos[0].packed_info.bit.first = CA_PARAM_SIZE_TYPE_1BYTE;
cmd_table[Cmd_CODE_UTIL_CMD_ADD].param_size_infos[0].packed_info.bit.first = CA_PARAM_SIZE_TYPE_1BYTE;
cmd_table[Cmd_CODE_UTIL_CMD_ADD].param_size_infos[0].packed_info.bit.second = CA_PARAM_SIZE_TYPE_4BYTE;
cmd_table[Cmd_CODE_UTIL_CMD_ADD].param_size_infos[1].packed_info.bit.first = CA_PARAM_SIZE_TYPE_4BYTE;
Expand Down
7 changes: 6 additions & 1 deletion examples/mobc/src/src_user/tlm_cmd/command_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @note このコードは自動生成されています!
* @note コード生成元 tlm-cmd-db:
* repository: github.com/arkedge/c2a-core.git
* CSV files MD5: a6ac3f58e1422615904c43d389e64877
* CSV files MD5: cdfb84318ccef71e1e893aa4e68d0efa
* @note コード生成パラメータ:
* db_prefix: SAMPLE_MOBC
* tlm_id_range: [0x00, 0x100]
Expand Down Expand Up @@ -194,6 +194,11 @@ typedef enum
Cmd_CODE_UART_TEST_INIT_CSRV = 0x010E, //!< CSRV 初期化
Cmd_CODE_UART_TEST_UPDATE = 0x010F, //!< Driver update
Cmd_CODE_UART_TEST_SEND_TEST = 0x0110, //!< Driver send test
Cmd_CODE_APP_CALC_EXEC = 0x0111, //!< 計算を実行
Cmd_CODE_APP_CALC_SET_A = 0x0112, //!< 被演算子 a をセット
Cmd_CODE_APP_CALC_SET_B = 0x0113, //!< 被演算子 b をセット
Cmd_CODE_APP_CALC_SET_OP = 0x0114, //!< 演算子をセット
Cmd_CODE_APP_CALC_RESET = 0x0115, //!< クリア
Cmd_CODE_UTIL_CMD_ADD = 0x03E0, //!< 汎用コマンドのバッファに指定サイズのデータを入れる
Cmd_CODE_UTIL_CMD_SEND = 0x03E1, //!< 引数のCHに汎用コマンドのバッファにあるデータを送信する
Cmd_CODE_UTIL_CMD_RESET = 0x03E2, //!< 汎用コマンドのバッファをクリアする
Expand Down
24 changes: 23 additions & 1 deletion examples/mobc/src/src_user/tlm_cmd/telemetry_definitions.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @note このコードは自動生成されています!
* @note コード生成元 tlm-cmd-db:
* repository: github.com/arkedge/c2a-core.git
* CSV files MD5: a6ac3f58e1422615904c43d389e64877
* CSV files MD5: cdfb84318ccef71e1e893aa4e68d0efa
* @note コード生成パラメータ:
* db_prefix: SAMPLE_MOBC
* tlm_id_range: [0x00, 0x100]
Expand Down Expand Up @@ -43,6 +43,7 @@ static TF_TLM_FUNC_ACK Tlm_EH_RULE_(uint8_t* packet, uint16_t* len, uint16_t max
static TF_TLM_FUNC_ACK Tlm_EH_LOG_(uint8_t* packet, uint16_t* len, uint16_t max_len);
static TF_TLM_FUNC_ACK Tlm_EH_INDEX_(uint8_t* packet, uint16_t* len, uint16_t max_len);
static TF_TLM_FUNC_ACK Tlm_GS_(uint8_t* packet, uint16_t* len, uint16_t max_len);
static TF_TLM_FUNC_ACK Tlm_DEMO_CALC_(uint8_t* packet, uint16_t* len, uint16_t max_len);
static TF_TLM_FUNC_ACK Tlm_HK_(uint8_t* packet, uint16_t* len, uint16_t max_len);
static TF_TLM_FUNC_ACK Tlm_GIT_REV_(uint8_t* packet, uint16_t* len, uint16_t max_len);
static TF_TLM_FUNC_ACK Tlm_UART_TEST_(uint8_t* packet, uint16_t* len, uint16_t max_len);
Expand Down Expand Up @@ -75,6 +76,7 @@ void TF_load_tlm_table(TF_TlmInfo tlm_table[TF_MAX_TLMS])
tlm_table[Tlm_CODE_EH_LOG].tlm_func = Tlm_EH_LOG_;
tlm_table[Tlm_CODE_EH_INDEX].tlm_func = Tlm_EH_INDEX_;
tlm_table[Tlm_CODE_GS].tlm_func = Tlm_GS_;
tlm_table[Tlm_CODE_DEMO_CALC].tlm_func = Tlm_DEMO_CALC_;
tlm_table[Tlm_CODE_HK].tlm_func = Tlm_HK_;
tlm_table[Tlm_CODE_GIT_REV].tlm_func = Tlm_GIT_REV_;
tlm_table[Tlm_CODE_UART_TEST].tlm_func = Tlm_UART_TEST_;
Expand Down Expand Up @@ -4134,6 +4136,26 @@ static TF_TLM_FUNC_ACK Tlm_GS_(uint8_t* packet, uint16_t* len, uint16_t max_len)
return TF_TLM_FUNC_ACK_SUCCESS;
}

static TF_TLM_FUNC_ACK Tlm_DEMO_CALC_(uint8_t* packet, uint16_t* len, uint16_t max_len)
{
if (53 > max_len) return TF_TLM_FUNC_ACK_TOO_SHORT_LEN;

#ifndef BUILD_SETTINGS_FAST_BUILD
TF_copy_u32(&packet[26], demo_calculator->info.exec_count);
TF_copy_u32(&packet[30], demo_calculator->info.err_count);
TF_copy_u32(&packet[34], demo_calculator->info.last_exec_time.total_cycle);
TF_copy_u32(&packet[38], demo_calculator->info.last_exec_time.step);
TF_copy_u8(&packet[42], demo_calculator->info.status);
TF_copy_i32(&packet[43], demo_calculator->calc.a);
TF_copy_i32(&packet[47], demo_calculator->calc.b);
TF_copy_u8(&packet[51], demo_calculator->calc.result);
TF_copy_u8(&packet[52], demo_calculator->calc.operator);
#endif

*len = 53;
return TF_TLM_FUNC_ACK_SUCCESS;
}

static TF_TLM_FUNC_ACK Tlm_HK_(uint8_t* packet, uint16_t* len, uint16_t max_len)
{
if (428 > max_len) return TF_TLM_FUNC_ACK_TOO_SHORT_LEN;
Expand Down
Loading
Loading