GPS Device
Loading...
Searching...
No Matches
Log Internal Helpers

Functions

static ERR_te log_print_prologue (MODULES_te subsys, LOG_LEVEL_te log_level)
 Prints the log message prologue: timestamp, severity, and subsystem name.

Detailed Description

Function Documentation

◆ log_print_prologue()

ERR_te log_print_prologue ( MODULES_te subsys,
LOG_LEVEL_te log_level )
inlinestatic

Prints the log message prologue: timestamp, severity, and subsystem name.

Reads the current time from the RTC and formats it as (HH:MM:SS), zero-padding single-digit values. Follows with the severity level in parentheses and the subsystem name, then "-> " to precede the message body.

Output format: (HH:MM:SS)(level)SUBSYSTEM_NAME->

Parameters
[in]subsysThe subsystem emitting the message.
[in]log_levelThe severity level of the message.
Returns
  • ERR_OK always

Definition at line 248 of file log.c.

248 {
249 TIME_ts rtc_time = { 0 };
250 rtc_get_time(&rtc_time);
251
252 char seconds[2];
253 int_to_str(rtc_time.seconds, seconds);
254 if(get_str_len(seconds) == 1) {
255 char temp = seconds[0];
256 seconds[0] = '0';
257 seconds[1] = temp;
258 }
259
260 char minutes[2];
261 int_to_str(rtc_time.minutes, minutes);
262 if(get_str_len(minutes) == 1) {
263 char temp = minutes[0];
264 minutes[0] = '0';
265 minutes[1] = temp;
266 }
267
268 char hours[2];
269 int_to_str(rtc_time.hours, hours);
270 if(get_str_len(hours) == 1) {
271 char temp = hours[0];
272 hours[0] = '0';
273 hours[1] = temp;
274 }
275
276 char time_format[] = "(__:__:__)";
277
278 str_set(time_format, seconds, 2, 7);
279 str_set(time_format, minutes, 2, 4);
280 str_set(time_format, hours, 2, 1);
281
282 usart_send(internal_state.usart_instance, (uint8_t*)time_format, 10);
283
284 char log_level_str[16];
285 uint8_t log_level_len = 0;
286 log_level_str[0] = '(';
287 log_get_level_name(log_level, log_level_str + 1);
288 log_level_len = get_str_len(log_level_str);
289 log_level_str[log_level_len] = ')';
290 log_level_str[log_level_len + 1] = '\0';
291
293 internal_state.usart_instance,
294 (uint8_t*)log_level_str,
295 get_str_len(log_level_str) + 1
296 );
297
299 internal_state.usart_instance,
300 (uint8_t*)modules_names[subsys],
301 get_str_len((char*)modules_names[subsys])
302 );
303
305 internal_state.usart_instance,
306 (uint8_t*)"-> ",
307 3
308 );
309
310 return ERR_OK;
311}
static struct internal_state_s internal_state
Singleton instance of the SysTick driver internal state.
void str_set(char *target_str, char const *host_str, uint32_t host_str_len, uint32_t pos)
Overwrites a region of a target string with the contents of a source string.
Definition common.c:195
uint32_t get_str_len(char const *str)
Returns the length of a string, excluding the null terminator.
Definition common.c:22
void int_to_str(int num, char *str)
Converts an integer to its decimal string representation.
Definition common.c:33
@ ERR_OK
Definition err.h:36
ERR_te log_get_level_name(LOG_LEVEL_te log_level, char *str)
Converts a LOG_LEVEL_te value to its lowercase string name.
Definition log.c:153
void rtc_get_time(TIME_ts *time)
Reads the current time from the RTC.
void usart_send(USART_REGDEF_ts *usart_instance, uint8_t *tx_buffer, uint32_t len)
Blocking USART transmit. Sends len bytes from tx_buffer.
const char * modules_names[]
External array mapping MODULES_te values to their name strings.
Definition modules.c:24
Holds a time-of-day value (hours, minutes, seconds).
uint8_t seconds
uint8_t hours
uint8_t minutes
Here is the call graph for this function:
Here is the caller graph for this function: