logging: don't ask...
This commit is contained in:
@@ -1,88 +0,0 @@
|
||||
#ifndef __THREAD_COMMON_LOG_H_
|
||||
#define __THREAD_COMMON_LOG_H_
|
||||
|
||||
#include "chip.h"
|
||||
#include "board.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/*
|
||||
This simlpe logging framework is dependant
|
||||
on std lib's multithread support, thus
|
||||
if needed on different platforms, please
|
||||
wrap it with mutexes.
|
||||
*/
|
||||
|
||||
/* ================= Settings ================== */
|
||||
#define LOG_COLORED_OUTPUT
|
||||
#define HIGH_PRIORITY_DEBUG
|
||||
#define LOG_DEBUG_MESSAGES 1
|
||||
/* ================= Settings ================== */
|
||||
|
||||
// internal debug defines
|
||||
#ifdef HIGH_PRIORITY_DEBUG
|
||||
#include <assert.h>
|
||||
#define INT_ASSERT(statement) assert(statement)
|
||||
#else
|
||||
#define INT_ASSERT(statement)
|
||||
#endif
|
||||
|
||||
#ifdef LOG_COLORED_OUTPUT
|
||||
#define C_INFO "\x1b[34mINFO\x1b[0m"
|
||||
#define C_DEBUG "\x1b[35mDEBUG\x1b[0m"
|
||||
#define C_WARN "\x1b[33mWARNING\x1b[0m"
|
||||
#define C_ERROR "\x1b[31mERROR\x1b[0m"
|
||||
#else
|
||||
#define C_INFO "INFO"
|
||||
#define C_DEBUG "DEBUG"
|
||||
#define C_WARN "WARNING"
|
||||
#define C_ERROR "ERROR"
|
||||
#endif
|
||||
|
||||
#define LOG_BUFFER_MAX_CAP 500
|
||||
#define LOG_MESSAGE_MAX_CAP 150
|
||||
|
||||
#define _LOG_STREAMOUT(message, message_length) \
|
||||
INT_ASSERT(message_length > 0); \
|
||||
printf("%.*s\n", message_length, message); \
|
||||
|
||||
static void create_log_line(const char * _status,
|
||||
const char * _location,
|
||||
const size_t _line,
|
||||
const char * _fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, _fmt);
|
||||
char message [LOG_BUFFER_MAX_CAP] = {0};
|
||||
int message_len = vsnprintf(message, LOG_BUFFER_MAX_CAP, _fmt, args);
|
||||
va_end(args);
|
||||
char buffer [LOG_BUFFER_MAX_CAP] = {0};
|
||||
int buffer_len = snprintf(buffer, LOG_BUFFER_MAX_CAP,
|
||||
"[%s] [File: %s] [Line: %ld] %.*s",
|
||||
_status,
|
||||
_location,
|
||||
_line,
|
||||
message_len,
|
||||
message);
|
||||
_LOG_STREAMOUT(buffer, buffer_len)
|
||||
|
||||
}
|
||||
|
||||
#define LOG_INFO(fmt, ...) \
|
||||
create_log_line(C_INFO, __FILE__, __LINE__, fmt, ##__VA_ARGS__); \
|
||||
|
||||
#define LOG_WARNING(fmt, ...) \
|
||||
create_log_line(C_WARN, __FILE__, __LINE__, fmt, ##__VA_ARGS__); \
|
||||
|
||||
#define LOG_ERROR(fmt, ...) \
|
||||
create_log_line(C_ERROR, __FILE__, __LINE__, fmt, ##__VA_ARGS__); \
|
||||
|
||||
#if LOG_DEBUG_MESSAGES
|
||||
#define LOG_DEBUG(fmt, ...) \
|
||||
create_log_line(C_INFO, __FILE__, __LINE__, fmt, ##__VA_ARGS__); \
|
||||
#else
|
||||
#define LOG_DEBUG(fmt, ...)
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* __THREAD_COMMON_LOG_H_ */
|
||||
@@ -13,14 +13,11 @@ ThreadCommon::QueueManager::QueueManager() {}
|
||||
bool ThreadCommon::QueueManager::createQueue(size_t queue_length, size_t item_size, Queue_id qid)
|
||||
{
|
||||
QueueHandle_t queue_to_create;
|
||||
LOG_DEBUG("Creating queue with id %d", qid);
|
||||
if ((queue_to_create = xQueueCreate(queue_length, item_size)))
|
||||
{
|
||||
LOG_DEBUG("Queue with id %d has been created", qid);
|
||||
queues.insert({qid, queue_to_create});
|
||||
return true;
|
||||
}
|
||||
LOG_ERROR("Failed to cerate queue with id %d", qid);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
namespace ThreadCommon
|
||||
{
|
||||
|
||||
enum RotaryAction
|
||||
{
|
||||
Right,
|
||||
@@ -45,7 +46,8 @@ namespace ThreadCommon
|
||||
master_event_all,
|
||||
relay_event_master,
|
||||
manager_event_master,
|
||||
ui_event_manager
|
||||
ui_event_manager,
|
||||
logging_message_all
|
||||
};
|
||||
QueueManager();
|
||||
~QueueManager() = default;
|
||||
@@ -70,6 +72,12 @@ namespace ThreadCommon
|
||||
std::map <Queue_id, QueueHandle_t> queues;
|
||||
};
|
||||
|
||||
typedef struct _CommonManagers
|
||||
{
|
||||
ThreadManager * tm;
|
||||
QueueManager * qm;
|
||||
} CommonManagers;
|
||||
|
||||
/* global variables */
|
||||
/* 'receiver'_'what'_'sender'_q */
|
||||
/*
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "ThreadCommon.h"
|
||||
#include "Log.h"
|
||||
|
||||
|
||||
ThreadCommon::ThreadManager::ThreadManager(){}
|
||||
@@ -11,18 +10,12 @@ bool ThreadCommon::ThreadManager::createTask(void (*task_func)(void*),
|
||||
void* parameters)
|
||||
{
|
||||
const char * t_name = name.c_str();
|
||||
LOG_DEBUG("Creating task [name: %s, priority: %ld, stack: %ld]",
|
||||
t_name, priority, stack_size);
|
||||
BaseType_t taskCreated = xTaskCreate(task_func,
|
||||
t_name,
|
||||
stack_size,
|
||||
parameters,
|
||||
priority,
|
||||
NULL);
|
||||
if (!(taskCreated == pdPASS))
|
||||
{
|
||||
LOG_ERROR("Failed to create a task [name: %s, priority: %ld, stack: %ld]",
|
||||
t_name, priority, stack_size)
|
||||
}
|
||||
assert(taskCreated == pdPASS);
|
||||
return (taskCreated == pdPASS);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user