-
Notifications
You must be signed in to change notification settings - Fork 2
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
meltingrabbit
wants to merge
2
commits into
main
Choose a base branch
from
demo-calc-app
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
デモ用のアプリ #411
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
examples/mobc/src/src_user/applications/user_defined/etc/demo_calculator.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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){ | ||
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 |
71 changes: 71 additions & 0 deletions
71
examples/mobc/src/src_user/applications/user_defined/etc/demo_calculator.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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)