-
Notifications
You must be signed in to change notification settings - Fork 31
Logging for Interface #328
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
base: main
Are you sure you want to change the base?
Changes from 14 commits
09c9484
5396716
f2025c5
c6bf9a5
99eb19d
4837841
1385040
b51dca5
36dad41
0a7f05f
e856f63
13ef2b1
252f2d8
bd744ad
6d03258
839b417
376d8ba
ef50fe2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| #include "obc_gs_aes128.h" | ||
| #include "obc_gs_errors.h" | ||
| #include "obc_logging.h" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interfaces can't depend on obc. It should be the other way around |
||
|
|
||
| #include <aes.h> | ||
|
|
||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You will need to generalize this file and move most of it to interfaces |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| #pragma once | ||
|
|
||
| #include "obc_errors.h" | ||
| #include "obc_gs_errors.h" | ||
|
|
||
| #include <stdint.h> | ||
| #include <stdarg.h> | ||
|
|
@@ -42,6 +43,8 @@ typedef enum { LOG_TYPE_ERROR_CODE = 0, LOG_TYPE_MSG = 1 } log_type_t; | |
| #define LOG_DEFAULT_LEVEL LOG_TRACE | ||
| #endif | ||
|
|
||
| #ifdef BUILD_TYPE_OBC_FW | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| #define LOG_TRACE(msg) logMsg(LOG_TRACE, __FILE_FROM_REPO_ROOT__, __LINE__, msg) | ||
| #define LOG_DEBUG(msg) logMsg(LOG_DEBUG, __FILE_FROM_REPO_ROOT__, __LINE__, msg) | ||
| #define LOG_INFO(msg) logMsg(LOG_INFO, __FILE_FROM_REPO_ROOT__, __LINE__, msg) | ||
|
|
@@ -146,3 +149,101 @@ obc_error_code_t logErrorCodeFromISR(log_level_t msgLevel, const char *file, uin | |
| * | ||
| */ | ||
| obc_error_code_t logMsgFromISR(log_level_t msgLevel, const char *file, uint32_t line, const char *msg); | ||
|
|
||
| #else | ||
|
|
||
| #ifdef BUILD_TYPE_OBC_GS | ||
|
|
||
| #define LOG_TRACE(msg) gsLogMsg(LOG_TRACE, __FILE_FROM_REPO_ROOT__, __LINE__, msg) | ||
| #define LOG_DEBUG(msg) gsLogMsg(LOG_DEBUG, __FILE_FROM_REPO_ROOT__, __LINE__, msg) | ||
| #define LOG_INFO(msg) gsLogMsg(LOG_INFO, __FILE_FROM_REPO_ROOT__, __LINE__, msg) | ||
| #define LOG_WARN(msg) gsLogMsg(LOG_WARN, __FILE_FROM_REPO_ROOT__, __LINE__, msg) | ||
| #define LOG_ERROR(msg) gsLogMsg(LOG_ERROR, __FILE_FROM_REPO_ROOT__, __LINE__, msg) | ||
| #define LOG_FATAL(msg) gsLogMsg(LOG_FATAL, __FILE_FROM_REPO_ROOT__, __LINE__, msg) | ||
|
|
||
| #define LOG_TRACE_FROM_ISR(msg) LOG_TRACE(msg) | ||
| #define LOG_DEBUG_FROM_ISR(msg) LOG_DEBUG(msg) | ||
| #define LOG_INFO_FROM_ISR(msg) LOG_INFO(msg) | ||
| #define LOG_WARN_FROM_ISR(msg) LOG_WARN(msg) | ||
| #define LOG_ERROR_FROM_ISR(msg) LOG_ERROR(msg) | ||
| #define LOG_FATAL_FROM_ISR(msg) LOG_FATAL(msg) | ||
|
|
||
| #define LOG_ERROR_CODE(errCode) gsLogErrorCode(LOG_ERROR, __FILE_FROM_REPO_ROOT__, __LINE__, errCode) | ||
| #define LOG_ERROR_CODE_FROM_ISR(errCode) gsLogErrorCode(LOG_ERROR, __FILE_FROM_REPO_ROOT__, __LINE__, errCode) | ||
|
|
||
| #define RETURN_IF_ERROR_CODE(_ret) \ | ||
| do { \ | ||
| errCode = _ret; \ | ||
| if (errCode != OBC_GS_ERR_CODE_SUCCESS) { \ | ||
| LOG_ERROR_CODE(errCode); \ | ||
| return errCode; \ | ||
| } \ | ||
| } while (0) | ||
|
|
||
| #define LOG_IF_ERROR_CODE(_ret) \ | ||
| do { \ | ||
| errCode = _ret; \ | ||
| if (errCode != OBC_GS_ERR_CODE_SUCCESS) { \ | ||
| LOG_ERROR_CODE(errCode); \ | ||
| } \ | ||
| } while (0) | ||
|
|
||
| /** | ||
| * @brief Log an error code | ||
| * | ||
| * @param msgLevel Level of the message | ||
| * @param file File of message | ||
| * @param line Line of message | ||
| * @param errCode the error code that needs to be logged | ||
| * @return obc_gs_error_code_t OBC_GS_ERR_CODE_LOG_MSG_SILENCED if msgLevel is lower than logging level | ||
| * OBC_GS_ERR_CODE_BUFF_TOO_SMALL if logged message is too long | ||
| * OBC_GS_ERR_CODE_INVALID_ARG if file or s are null or if there is an encoding error | ||
| * OBC_GS_ERR_CODE_SUCCESS if message is successfully logged | ||
| * OBC_GS_ERR_CODE_UNKNOWN otherwise | ||
| */ | ||
| obc_gs_error_code_t gsLogErrorCode(gs_log_level_t msgLevel, const char *file, uint32_t line, uint32_t errCode); | ||
|
|
||
| /** | ||
| * @brief Log a message | ||
| * | ||
| * @param msgLevel Level of the message | ||
| * @param file File of message | ||
| * @param line Line of message | ||
| * @param msg the message that should be logged (MUST BE STATIC) | ||
| * @return obc_gs_error_code_t OBC_GS_ERR_CODE_LOG_MSG_SILENCED if msgLevel is lower than logging level | ||
| * OBC_GS_ERR_CODE_BUFF_TOO_SMALL if logged message is too long | ||
| * OBC_GS_ERR_CODE_INVALID_ARG if file or s are null or if there is an encoding error | ||
| * OBC_GS_ERR_CODE_SUCCESS if message is successfully logged | ||
| * OBC_GS_ERR_CODE_UNKNOWN otherwise | ||
| */ | ||
| obc_gs_error_code_t gsLogMsg(gs_log_level_t msgLevel, const char *file, uint32_t line, const char *msg); | ||
|
|
||
| #else | ||
|
|
||
| #define LOG_DEBUG(msg) ((void)0) | ||
| #define LOG_INFO(msg) ((void)0) | ||
| #define LOG_WARN(msg) ((void)0) | ||
| #define LOG_ERROR(msg) ((void)0) | ||
| #define LOG_FATAL(msg) ((void)0) | ||
| #define LOG_TRACE_FROM_ISR(msg) ((void)0) | ||
| #define LOG_DEBUG_FROM_ISR(msg) ((void)0) | ||
| #define LOG_INFO_FROM_ISR(msg) ((void)0) | ||
| #define LOG_WARN_FROM_ISR(msg) ((void)0) | ||
| #define LOG_ERROR_FROM_ISR(msg) ((void)0) | ||
| #define LOG_FATAL_FROM_ISR(msg) ((void)0) | ||
| #define LOG_ERROR_CODE(errCode) ((void)0) | ||
| #define LOG_ERROR_CODE_FROM_ISR(errCode) ((void)0) | ||
|
|
||
| #define RETURN_IF_ERROR_CODE(_ret) \ | ||
| do { \ | ||
| (void)(_ret); \ | ||
| return _ret; \ | ||
| } while (0) | ||
|
|
||
| #define LOG_IF_ERROR_CODE(_ret) \ | ||
| do { \ | ||
| (void)(_ret); \ | ||
| } while (0) | ||
| #endif | ||
|
|
||
| #endif | ||
|
Comment on lines
+152
to
+249
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code isn't needed as we are going to be changing the implementation (.c file) in the cmakelist.txt file to handle the different logging environments |
||
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.
You dont need this code. You will need to conditionally add the source (.c) file that implements logMsg and logErrorCode. If the build type is obc, it will use the obc implementation at also implements the isr versions.
If its gs, it will add the source file that you will add in the interfaces/common directory.
Otherwise, you will add the source file that implements stubs for these 2 functions. Basically it return success in this last case and ignore all arguments