Skip to content
Open
Show file tree
Hide file tree
Changes from 17 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
13 changes: 12 additions & 1 deletion interfaces/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ set(INCLUDE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}/obc_gs_interface/fec

${CMAKE_CURRENT_SOURCE_DIR}/data_pack_unpack

${CMAKE_CURRENT_SOURCE_DIR}/../obc/app/sys/logging
${CMAKE_CURRENT_SOURCE_DIR}/../obc/app/sys
Comment on lines +15 to +16
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove these. See the comments below

)

set(SOURCES
Expand All @@ -35,7 +38,15 @@ set(SOURCES
add_library(${OBC_GS_INTERFACE_LIB_NAME} STATIC ${SOURCES})
target_include_directories(${OBC_GS_INTERFACE_LIB_NAME} PUBLIC ${INCLUDE_DIRS})

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()
Comment on lines +41 to +47
Copy link
Contributor

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


target_link_libraries(${OBC_GS_INTERFACE_LIB_NAME} PRIVATE
tiny-aes
lib-correct
)
)
1 change: 1 addition & 0 deletions interfaces/obc_gs_interface/aes128/obc_gs_aes128.c
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"
Copy link
Contributor

Choose a reason for hiding this comment

The 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>

Expand Down
1 change: 1 addition & 0 deletions interfaces/obc_gs_interface/ax25/obc_gs_ax25.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "obc_gs_ax25.h"
#include "obc_gs_crc.h"
#include "obc_logging.h"

#include <stdint.h>
#include <string.h>
Expand Down
1 change: 1 addition & 0 deletions interfaces/obc_gs_interface/commands/obc_gs_command_pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "obc_gs_command_id.h"
#include "data_pack_utils.h"
#include "obc_gs_errors.h"
#include "obc_logging.h"

#include <stdbool.h>
#include <stdint.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "obc_gs_command_id.h"
#include "data_unpack_utils.h"
#include "obc_gs_errors.h"
#include "obc_logging.h"

#include <stdbool.h>
#include <stdint.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

#include "data_pack_utils.h"
#include "obc_gs_commands_response_pack.h"
#include "obc_logging.h"

#include <stdint.h>
#include <string.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "data_unpack_utils.h"
#include "obc_gs_commands_response_unpack.h"
#include "obc_gs_command_id.h"
#include "obc_logging.h"

#include <stdint.h>
#include <string.h>
Expand Down
1 change: 1 addition & 0 deletions interfaces/obc_gs_interface/fec/obc_gs_fec.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "obc_gs_fec.h"
#include "obc_gs_aes128.h"
#include "obc_gs_errors.h"
#include "obc_logging.h"

#include <correct.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "obc_gs_telemetry_id.h"
#include "data_pack_utils.h"
#include "obc_gs_errors.h"
#include "obc_logging.h"

#include <stddef.h>
#include <stdint.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "obc_gs_telemetry_id.h"
#include "data_unpack_utils.h"
#include "obc_gs_errors.h"
#include "obc_logging.h"

#include <stddef.h>
#include <stdint.h>
Expand Down
101 changes: 101 additions & 0 deletions obc/app/sys/logging/obc_logging.h
Copy link
Contributor

Choose a reason for hiding this comment

The 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>
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

  • Move the lines 48-53 and 62 and 65-103 below to a new logging.h file located in the interfaces/common directory. You will need to change the OBC_ERR_CODE_SUCCESS to 0 as success should always be 0. You should add a static assert for this in the obc_logging.c file. Also move the lines 10-11 and 25-44 to that new interfaces logging.h file.
  • Make the current file include that new logging.h file.
  • You will also need to update the CmakeLists.txt to have the point to that this logging.h header file in the interfaces/common directory
  • Add new logging error codes that are will be put inside of the logging.h file
  • Update the logging implementation files on the obc to return the new logging error codes


#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)
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Loading