CTS-SAT-1-OBC-Firmware
Loading...
Searching...
No Matches
log.c File Reference
#include "log/log.h"
#include "log/log_sinks.h"
#include "debug_tools/debug_uart.h"
#include "timekeeping/timekeeping.h"
#include <complex.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
Include dependency graph for log.c:

Classes

struct  LOG_sink_t
 
struct  LOG_system_t
 
struct  LOG_memory_entry_t
 

Macros

#define LOG_TIMESTAMP_MAX_LENGTH   30
 
#define LOG_SINK_NAME_MAX_LENGTH   20
 
#define LOG_SYSTEM_NAME_MAX_LENGTH   20
 
#define LOG_FULL_MESSAGE_MAX_LENGTH   ( LOG_FORMATTED_MESSAGE_MAX_LENGTH + LOG_TIMESTAMP_MAX_LENGTH + LOG_SINK_NAME_MAX_LENGTH + LOG_SYSTEM_NAME_MAX_LENGTH + 1 )
 
#define LOG_MEMORY_NUMBER_OF_ENTRIES   128
 

Functions

static char LOG_context_enum_to_char (LOG_context_enum_t context)
 
void LOG_message (LOG_system_enum_t system, LOG_severity_enum_t severity, uint32_t sink_mask, const char fmt[],...)
 Log a message to several destinations (sinks)
 
uint32_t LOG_all_sinks_except (uint32_t sink_exceptions_mask)
 Returns all sinks, except the specified exceptions.
 
uint8_t LOG_is_sink_enabled (LOG_sink_enum_t sink)
 Check logging sink status.
 
void LOG_set_sink_debugging_messages_enabled_state (LOG_sink_enum_t sink, uint8_t state)
 Turn debugging messages on or off for the specified sink.
 
void LOG_set_system_debugging_messages_enabled_state (LOG_system_enum_t system, uint8_t state)
 Turn debugging messages on or off for the specified system.
 
uint8_t LOG_is_system_file_logging_enabled (LOG_system_enum_t system)
 Check whether file logging is enabled for a subsystem.
 
void LOG_set_system_severity_mask (LOG_system_enum_t system, uint32_t severity_mask)
 Set the logging severity bitfield mask for a subsystem.
 
void LOG_set_sink_enabled_state (LOG_sink_enum_t sink, uint8_t state)
 Enable or disable logging to a sink.
 
void LOG_set_system_file_logging_enabled_state (LOG_system_enum_t system, uint8_t state)
 Enable or disable logging to file for a subsystem.
 
void LOG_report_sink_enabled_state (LOG_sink_enum_t sink)
 Report a sink's enabled state.
 
void LOG_report_system_file_logging_state (LOG_system_enum_t system)
 Report a subsystem's file-logging state.
 
uint16_t LOG_number_of_logging_sinks (void)
 
uint16_t LOG_number_of_logging_systems (void)
 
const char * LOG_get_severity_name (LOG_severity_enum_t severity)
 Get the name of a severity enum.
 
uint8_t LOG_memory_table_max_entries (void)
 Get the size in entries of the in-memory log table.
 
uint8_t LOG_get_memory_table_index_of_most_recent_log_entry (void)
 Get the index of the most recent in-memory log message.
 
const char * LOG_get_memory_table_full_message_at_index (uint8_t index)
 Get a pointer to the full text of the in-memory log message at the specified index.
 

Variables

LOG_context_enum_t LOG_current_log_context = LOG_CONTEXT_AUTONOMOUS
 
static char LOG_timestamp_string [LOG_TIMESTAMP_MAX_LENGTH] = {0}
 
static char LOG_formatted_log_message [LOG_FORMATTED_MESSAGE_MAX_LENGTH] = {0}
 
static LOG_memory_entry_t LOG_memory_table [LOG_MEMORY_NUMBER_OF_ENTRIES] = {0}
 
static uint8_t LOG_memory_index_of_current_log_entry = LOG_MEMORY_NUMBER_OF_ENTRIES - 1
 
static const uint8_t LOG_SEVERITY_MASK_ALL = 0xFF
 
static const uint8_t LOG_SEVERITY_MASK_DEFAULT = LOG_SEVERITY_MASK_ALL
 
static LOG_sink_t LOG_sinks []
 
static const uint16_t LOG_NUMBER_OF_SINKS = sizeof(LOG_sinks) / sizeof(LOG_sink_t)
 
static LOG_system_t LOG_systems []
 
static const uint16_t LOG_NUMBER_OF_SYSTEMS = sizeof(LOG_systems) / sizeof(LOG_system_t)
 

Macro Definition Documentation

◆ LOG_FULL_MESSAGE_MAX_LENGTH

◆ LOG_MEMORY_NUMBER_OF_ENTRIES

#define LOG_MEMORY_NUMBER_OF_ENTRIES   128

◆ LOG_SINK_NAME_MAX_LENGTH

#define LOG_SINK_NAME_MAX_LENGTH   20

◆ LOG_SYSTEM_NAME_MAX_LENGTH

#define LOG_SYSTEM_NAME_MAX_LENGTH   20

◆ LOG_TIMESTAMP_MAX_LENGTH

#define LOG_TIMESTAMP_MAX_LENGTH   30

Function Documentation

◆ LOG_all_sinks_except()

uint32_t LOG_all_sinks_except ( uint32_t sink_exceptions_mask)

Returns all sinks, except the specified exceptions.

Parameters
exceptionsBitfield represent log sinks to exclude
Returns
Bitfield representing all log sinks, except those passed as an arg
Note
Especially useful in calls to LOG_message(), to report a failure of a specific logging sink.
Here is the caller graph for this function:

◆ LOG_context_enum_to_char()

static char LOG_context_enum_to_char ( LOG_context_enum_t context)
static
Here is the caller graph for this function:

◆ LOG_get_memory_table_full_message_at_index()

const char * LOG_get_memory_table_full_message_at_index ( uint8_t index)

Get a pointer to the full text of the in-memory log message at the specified index.

Parameters
indexrequested in-memory log message
Returns
pointer to the full text of the log message
Here is the caller graph for this function:

◆ LOG_get_memory_table_index_of_most_recent_log_entry()

uint8_t LOG_get_memory_table_index_of_most_recent_log_entry ( void )

Get the index of the most recent in-memory log message.

Returns
index of the most recent log message
Here is the caller graph for this function:

◆ LOG_get_severity_name()

const char * LOG_get_severity_name ( LOG_severity_enum_t severity)

Get the name of a severity enum.

Parameters
severitythe specified severity
Returns
pointer to the statically allocated name
Here is the caller graph for this function:

◆ LOG_is_sink_enabled()

uint8_t LOG_is_sink_enabled ( LOG_sink_enum_t sink)

Check logging sink status.

Parameters
sinkthe sink to check
Returns
0: disabled (or invalid sink); 1: enabled
Here is the call graph for this function:
Here is the caller graph for this function:

◆ LOG_is_system_file_logging_enabled()

uint8_t LOG_is_system_file_logging_enabled ( LOG_system_enum_t system)

Check whether file logging is enabled for a subsystem.

Parameters
system
Returns
returns 1 if logging to file is enabled, 0 otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ LOG_memory_table_max_entries()

uint8_t LOG_memory_table_max_entries ( void )

Get the size in entries of the in-memory log table.

Returns
size of the in-memory log table
Here is the caller graph for this function:

◆ LOG_message()

void LOG_message ( LOG_system_enum_t system,
LOG_severity_enum_t severity,
uint32_t sink_mask,
const char fmt[],
... )

Log a message to several destinations (sinks)

Parameters
systemthe system sending the log message (i.e., satellite subsystem)
severitymessage severity
sink_maskbitfield representing desired log sinks
fmtprintf-link format
...additional printf-like message arguments
Returns
void

Normally the message should not end with a newline (
). Exclude one or more sinks using LOG_all_sinks_except(...)

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LOG_number_of_logging_sinks()

uint16_t LOG_number_of_logging_sinks ( void )
Here is the caller graph for this function:

◆ LOG_number_of_logging_systems()

uint16_t LOG_number_of_logging_systems ( void )
Here is the caller graph for this function:

◆ LOG_report_sink_enabled_state()

void LOG_report_sink_enabled_state ( LOG_sink_enum_t sink)

Report a sink's enabled state.

Parameters
sinkspecified sink
Here is the call graph for this function:
Here is the caller graph for this function:

◆ LOG_report_system_file_logging_state()

void LOG_report_system_file_logging_state ( LOG_system_enum_t system)

Report a subsystem's file-logging state.

Parameters
sinkspecified sink
Note
includes the subsystem's log filename
Here is the call graph for this function:
Here is the caller graph for this function:

◆ LOG_set_sink_debugging_messages_enabled_state()

void LOG_set_sink_debugging_messages_enabled_state ( LOG_sink_enum_t sink,
uint8_t state )

Turn debugging messages on or off for the specified sink.

Parameters
sinkspecified sink
state0: debugging messages off; 1: debugging messages on

Turning off a sink's debugging messages overrides a system's debugging messages state

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LOG_set_sink_enabled_state()

void LOG_set_sink_enabled_state ( LOG_sink_enum_t sink,
uint8_t state )

Enable or disable logging to a sink.

Parameters
sinkspecified sink @state 0: disable 1: enable
Here is the call graph for this function:
Here is the caller graph for this function:

◆ LOG_set_system_debugging_messages_enabled_state()

void LOG_set_system_debugging_messages_enabled_state ( LOG_system_enum_t system,
uint8_t state )

Turn debugging messages on or off for the specified system.

Parameters
systemspecified system
state0: debugging messages off; 1: debugging messages on

Debugging messages will be disabled if turned off for a given sink

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LOG_set_system_file_logging_enabled_state()

void LOG_set_system_file_logging_enabled_state ( LOG_system_enum_t system,
uint8_t state )

Enable or disable logging to file for a subsystem.

Parameters
systemspecified subsystem @state 0: disable 1: enable
Here is the call graph for this function:
Here is the caller graph for this function:

◆ LOG_set_system_severity_mask()

void LOG_set_system_severity_mask ( LOG_system_enum_t system,
uint32_t severity_mask )

Set the logging severity bitfield mask for a subsystem.

Parameters
systemspecified system
severity_maskbitfield representing the severities to be logged
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ LOG_current_log_context

LOG_context_enum_t LOG_current_log_context = LOG_CONTEXT_AUTONOMOUS

◆ LOG_formatted_log_message

char LOG_formatted_log_message[LOG_FORMATTED_MESSAGE_MAX_LENGTH] = {0}
static

◆ LOG_memory_index_of_current_log_entry

uint8_t LOG_memory_index_of_current_log_entry = LOG_MEMORY_NUMBER_OF_ENTRIES - 1
static

◆ LOG_memory_table

LOG_memory_entry_t LOG_memory_table[LOG_MEMORY_NUMBER_OF_ENTRIES] = {0}
static

◆ LOG_NUMBER_OF_SINKS

const uint16_t LOG_NUMBER_OF_SINKS = sizeof(LOG_sinks) / sizeof(LOG_sink_t)
static

◆ LOG_NUMBER_OF_SYSTEMS

const uint16_t LOG_NUMBER_OF_SYSTEMS = sizeof(LOG_systems) / sizeof(LOG_system_t)
static

◆ LOG_SEVERITY_MASK_ALL

const uint8_t LOG_SEVERITY_MASK_ALL = 0xFF
static

◆ LOG_SEVERITY_MASK_DEFAULT

const uint8_t LOG_SEVERITY_MASK_DEFAULT = LOG_SEVERITY_MASK_ALL
static

◆ LOG_sinks

LOG_sink_t LOG_sinks[]
static
Initial value:
= {
}
static const uint8_t LOG_SEVERITY_MASK_DEFAULT
Definition log.c:65
@ LOG_SINK_ON
Definition log.h:28
@ LOG_SINK_OFF
Definition log.h:27
@ LOG_SINK_UMBILICAL_UART
Definition log.h:21
@ LOG_SINK_UHF_RADIO
Definition log.h:19
@ LOG_SINK_FILE
Definition log.h:20

◆ LOG_systems

LOG_system_t LOG_systems[]
static
Initial value:
= {
{LOG_SYSTEM_OBC, "OBC", "/logs/obc_system.log", LOG_SYSTEM_ON, LOG_SEVERITY_MASK_DEFAULT},
{LOG_SYSTEM_UHF_RADIO, "UHF_RADIO", "/logs/uhf_radio_system.log", LOG_SYSTEM_ON, LOG_SEVERITY_MASK_DEFAULT},
{LOG_SYSTEM_UMBILICAL_UART, "UMBILICAL_UART", "/logs/umbilical_uart_system.log", LOG_SYSTEM_ON, LOG_SEVERITY_MASK_DEFAULT},
{LOG_SYSTEM_GNSS, "GNSS", "/logs/gnss_system.log", LOG_SYSTEM_ON, LOG_SEVERITY_MASK_DEFAULT},
{LOG_SYSTEM_MPI, "MPI", "/logs/mpi_system.log", LOG_SYSTEM_ON, LOG_SEVERITY_MASK_DEFAULT},
{LOG_SYSTEM_EPS, "EPS", "/logs/eps_system.log", LOG_SYSTEM_ON, LOG_SEVERITY_MASK_DEFAULT},
{LOG_SYSTEM_BOOM, "BOOM", "/logs/boom_system.log", LOG_SYSTEM_ON, LOG_SEVERITY_MASK_DEFAULT},
{LOG_SYSTEM_ADCS, "ADCS", "/logs/adcs_system.log", LOG_SYSTEM_ON, LOG_SEVERITY_MASK_DEFAULT},
{LOG_SYSTEM_LFS, "LFS", "/logs/lfs_system.log", LOG_SYSTEM_ON, LOG_SEVERITY_MASK_DEFAULT},
{LOG_SYSTEM_FLASH, "FLASH", "/logs/flash_system.log", LOG_SYSTEM_ON, LOG_SEVERITY_MASK_DEFAULT},
{LOG_SYSTEM_ANTENNA_DEPLOY, "ANTENNA_DEPLOY", "/logs/antenna_deploy_system.log", LOG_SYSTEM_ON, LOG_SEVERITY_MASK_DEFAULT},
{LOG_SYSTEM_LOG, "LOG", "/logs/log_system.log", LOG_SYSTEM_ON, LOG_SEVERITY_MASK_DEFAULT},
{LOG_SYSTEM_TELECOMMAND, "TELECOMMAND", "/logs/telecommand_system.log", LOG_SYSTEM_ON, LOG_SEVERITY_MASK_DEFAULT},
{LOG_SYSTEM_UNIT_TEST, "UNIT_TEST", "/logs/unit_test_system.log", LOG_SYSTEM_ON, LOG_SEVERITY_MASK_DEFAULT},
{LOG_SYSTEM_UNKNOWN, "UNKNOWN", "/logs/unknown_system.log", LOG_SYSTEM_ON, LOG_SEVERITY_MASK_DEFAULT},
}
@ LOG_SYSTEM_ON
Definition log.h:61
@ LOG_SYSTEM_LOG
Definition log.h:43
@ LOG_SYSTEM_UMBILICAL_UART
Definition log.h:34
@ LOG_SYSTEM_ANTENNA_DEPLOY
Definition log.h:42
@ LOG_SYSTEM_UHF_RADIO
Definition log.h:33
@ LOG_SYSTEM_ADCS
Definition log.h:39
@ LOG_SYSTEM_UNIT_TEST
Definition log.h:45
@ LOG_SYSTEM_LFS
Definition log.h:40
@ LOG_SYSTEM_GNSS
Definition log.h:35
@ LOG_SYSTEM_OBC
Definition log.h:32
@ LOG_SYSTEM_UNKNOWN
Definition log.h:46
@ LOG_SYSTEM_FLASH
Definition log.h:41
@ LOG_SYSTEM_MPI
Definition log.h:36
@ LOG_SYSTEM_EPS
Definition log.h:37
@ LOG_SYSTEM_TELECOMMAND
Definition log.h:44
@ LOG_SYSTEM_BOOM
Definition log.h:38

◆ LOG_timestamp_string

char LOG_timestamp_string[LOG_TIMESTAMP_MAX_LENGTH] = {0}
static