Log format enhanced, match LVGL log level to INFO.
This commit is contained in:
parent
d1ad67dde3
commit
99914fe090
|
@ -25,6 +25,7 @@ set(C_SOURCES
|
|||
"src/tasks/user_base_task.c"
|
||||
"src/tasks/user_mqtt_task.c"
|
||||
"src/utils/user_log_util.c"
|
||||
"src/utils/user_system_util.c"
|
||||
"src/assets/encode_sans_sc_light_24.c"
|
||||
"src/assets/encode_sans_sc_regular_32.c"
|
||||
"src/assets/encode_sans_sc_bold_48.c"
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include "mqtt_influx.h"
|
||||
|
||||
typedef struct {
|
||||
struct mosquito *mosq;
|
||||
struct mosquitto *mosq;
|
||||
} user_mqtt_impl_t;
|
||||
|
||||
int user_mqtt_impl_init(user_mqtt_impl_t *handle);
|
||||
|
|
|
@ -4,15 +4,15 @@
|
|||
#include <string.h>
|
||||
|
||||
typedef enum {
|
||||
USER_LOG_DEBUG = 1,
|
||||
USER_LOG_INFO,
|
||||
USER_LOG_WARN,
|
||||
USER_LOG_FATAL = 1,
|
||||
USER_LOG_ERROR,
|
||||
USER_LOG_FATAL
|
||||
USER_LOG_WARN,
|
||||
USER_LOG_INFO,
|
||||
USER_LOG_DEBUG,
|
||||
} user_log_level_t;
|
||||
|
||||
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
|
||||
#define USER_LOG(level, fmt, ...) user_log_print(level, "[%s:%d] " fmt, __FILENAME__, __LINE__, ##__VA_ARGS__)
|
||||
#define USER_LOG(level, fmt, ...) user_log_print(level, "[% 24s:%04d] " fmt, __FILENAME__, __LINE__, ##__VA_ARGS__)
|
||||
|
||||
void user_log_set_level(user_log_level_t level);
|
||||
void user_log_print(user_log_level_t level, char *fmt, ...);
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef USER_SYSTEM_UTIL_H
|
||||
#define USER_SYSTEM_UTIL_H
|
||||
|
||||
int user_system_get_systemd_unique_id(char *uuid);
|
||||
|
||||
#endif
|
|
@ -69,7 +69,21 @@ agent: {
|
|||
|
||||
libraries: {
|
||||
lvgl: {
|
||||
fs_base = "";
|
||||
fs_base = ""; # This will be used as LVGL base file system and will be mounted at drive A:
|
||||
};
|
||||
mqtt: {
|
||||
client: {
|
||||
id_prefix = "";
|
||||
server_host = "127.0.0.1";
|
||||
server_port = 1883;
|
||||
};
|
||||
tls: {
|
||||
enabled = false;
|
||||
psk = "";
|
||||
ca_file = "";
|
||||
client_cert_file = "";
|
||||
client_key_file = "";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ void user_lvgl_impl_indev_read_cb(lv_indev_drv_t *drv, lv_indev_data_t *data) {
|
|||
}
|
||||
|
||||
void user_lvgl_impl_log_cb(const char *buf) {
|
||||
USER_LOG(USER_LOG_DEBUG, "LVGL: %s", buf);
|
||||
USER_LOG(USER_LOG_INFO, "LVGL: %s", buf);
|
||||
}
|
||||
|
||||
void *user_lvgl_impl_fs_open_cb(lv_fs_drv_t *drv, const char *path,
|
||||
|
|
|
@ -6,12 +6,17 @@
|
|||
|
||||
#include "utils/user_log_util.h"
|
||||
|
||||
// TODO: Add callbacks here as static functions.
|
||||
|
||||
int user_mqtt_impl_init(user_mqtt_impl_t *handle) {
|
||||
int mosq_major, mosq_minor, mosq_revision;
|
||||
mosquitto_lib_init();
|
||||
|
||||
mosquitto_lib_version(&mosq_major, &mosq_minor, &mosq_revision);
|
||||
USER_LOG(USER_LOG_INFO, "libmosquitto version %d.%d rev. %d.", mosq_major, mosq_minor, mosq_revision);
|
||||
USER_LOG(USER_LOG_INFO, "libmosquitto library version %d.%d rev. %d.", mosq_major, mosq_minor, mosq_revision);
|
||||
|
||||
// Init mosquitto instance.
|
||||
//handle->mosq = mosquitto_new();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,6 +27,10 @@ int user_mqtt_impl_deinit(user_mqtt_impl_t *handle) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int user_mqtt_network_loop(user_mqtt_impl_t *handle) {
|
||||
return mosquitto_loop(handle->mosq, 1000, 1);
|
||||
}
|
||||
|
||||
mqtt_influx_ret_t user_mqtt_get_nsec_timestamp_cb(user_mqtt_impl_t *handle, char *timestamp_string) {
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "drivers/user_config_driver.h"
|
||||
#include "drivers/user_spi_driver.h"
|
||||
#include "utils/user_log_util.h"
|
||||
#include "utils/user_system_util.h"
|
||||
#include "tasks/user_tasks.h"
|
||||
|
||||
uint8_t g_running = 1;
|
||||
|
@ -43,6 +44,10 @@ int main(int argc, const char *argv[]) {
|
|||
user_config_lookup_int(&g_config, "agent.common.log_level", (int *)&log_level);
|
||||
user_log_set_level(log_level);
|
||||
|
||||
char system_uuid[33] = { 0x00 };
|
||||
user_system_get_systemd_unique_id(system_uuid);
|
||||
USER_LOG(USER_LOG_INFO, "System UUID: %s", system_uuid);
|
||||
|
||||
user_mqtt_task_init();
|
||||
user_lvgl_task_init();
|
||||
user_base_task_init();
|
||||
|
|
|
@ -17,7 +17,7 @@ void user_log_set_level(user_log_level_t level) {
|
|||
|
||||
void user_log_print(user_log_level_t level, char *fmt, ...) {
|
||||
|
||||
if(level < s_current_level) return;
|
||||
if(level > s_current_level) return;
|
||||
|
||||
while(s_lock) {
|
||||
usleep(1000);
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
// For systemd-based system, we can use an uuid generated by systemd during first boot.
|
||||
int user_system_get_systemd_unique_id(char *uuid) {
|
||||
int machid_fd = open("/etc/machine-id", O_RDONLY);
|
||||
if(machid_fd < 0) return -1;
|
||||
|
||||
if(read(machid_fd, uuid, 32) < 32) {
|
||||
close(machid_fd);
|
||||
return -2;
|
||||
}
|
||||
|
||||
close(machid_fd);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue