Conversation
…to add-logging-task
Yarik-Popov
left a comment
There was a problem hiding this comment.
There's a few issues with the PR:
- You should be generalizing obc_logging.h, not creating a new set of macros for logging in obc gs. Have a look at #277 for a starting point
- The obc_gs_logging.h isnt used anywhere and as such the build succeed even if there are functions that arent implemented. You will need to update all the .c files in the interfaces directory to point to your new logging.h file once u generalize it. Possibly updating all .c filrs that use obc_logging.h to point to the new generalize solution
Yarik-Popov
left a comment
There was a problem hiding this comment.
I've added some comments to help clarify how to implement this.
There was a problem hiding this comment.
You will need to generalize this file and move most of it to interfaces
| if(CMAKE_BUILD_TYPE MATCHES OBC) | ||
| target_compile_definitions(${OBC_GS_INTERFACE_LIB_NAME} PUBLIC BUILD_TYPE_OBC_FW) | ||
|
|
||
| elseif(CMAKE_BUILD_TYPE MATCHES GS) | ||
| target_compile_definitions(${OBC_GS_INTERFACE_LIB_NAME} PUBLIC BUILD_TYPE_OBC_GS) | ||
|
|
||
| endif() |
There was a problem hiding this comment.
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
| #define LOG_DEFAULT_LEVEL LOG_TRACE | ||
| #endif | ||
|
|
||
| #ifdef BUILD_TYPE_OBC_FW |
There was a problem hiding this comment.
- Move the lines 48-53 and 62 and 65-103 below to a new
logging.hfile located in theinterfaces/commondirectory. You will need to change theOBC_ERR_CODE_SUCCESSto 0 as success should always be 0. You should add a static assert for this in theobc_logging.cfile. Also move the lines 10-11 and 25-44 to that new interfaces logging.h file. - Make the current file include that new
logging.hfile. - You will also need to update the CmakeLists.txt to have the point to that this
logging.hheader file in the interfaces/common directory - Add new logging error codes that are will be put inside of the
logging.hfile - Update the logging implementation files on the obc to return the new logging error codes
|
|
||
| #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 No newline at end of file |
There was a problem hiding this comment.
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
| @@ -1,5 +1,6 @@ | |||
| #include "obc_gs_aes128.h" | |||
| #include "obc_gs_errors.h" | |||
| #include "obc_logging.h" | |||
There was a problem hiding this comment.
Interfaces can't depend on obc. It should be the other way around
| ${CMAKE_CURRENT_SOURCE_DIR}/../obc/app/sys/logging | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/../obc/app/sys |
There was a problem hiding this comment.
Remove these. See the comments below
Purpose
Implemented Logging for Interface.
New Changes
Testing
Outstanding Changes