add uart log flag
This commit is contained in:
1 parent
df305437f7
commit
ff084e2f31
2 files changed
+39
-19
No files matched your search
@@ -45,21 +45,26 @@ namespace fileUtils {
|
|||||||
LockableMutex g_csv_mutex;
|
LockableMutex g_csv_mutex;
|
||||||
std::atomic_bool g_has_initialized = false;
|
std::atomic_bool g_has_initialized = false;
|
||||||
bool g_log_enabled = false;
|
bool g_log_enabled = false;
|
||||||
|
bool g_uart_enabled = false;
|
||||||
std::uint64_t g_last_flag_check = 0;
|
std::uint64_t g_last_flag_check = 0;
|
||||||
|
|
||||||
|
bool FlagExists(const char *path) {
|
||||||
|
FILE *file = fopen(path, "r");
|
||||||
|
if (file) {
|
||||||
|
fclose(file);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void RefreshFlags(bool force) {
|
void RefreshFlags(bool force) {
|
||||||
std::uint64_t now = armTicksToNs(armGetSystemTick());
|
std::uint64_t now = armTicksToNs(armGetSystemTick());
|
||||||
if (!force && (now - g_last_flag_check) < FILE_FLAG_CHECK_INTERVAL_NS) {
|
if (!force && (now - g_last_flag_check) < FILE_FLAG_CHECK_INTERVAL_NS) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *file = fopen(FILE_LOG_FLAG_PATH, "r");
|
g_log_enabled = FlagExists(FILE_LOG_FLAG_PATH);
|
||||||
if (file) {
|
g_uart_enabled = FlagExists(FILE_UART_FLAG_PATH);
|
||||||
g_log_enabled = true;
|
|
||||||
fclose(file);
|
|
||||||
} else {
|
|
||||||
g_log_enabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_last_flag_check = now;
|
g_last_flag_check = now;
|
||||||
}
|
}
|
||||||
@@ -78,9 +83,23 @@ namespace fileUtils {
|
|||||||
return g_log_enabled;
|
return g_log_enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsUartEnabled() {
|
||||||
|
return g_uart_enabled;
|
||||||
|
}
|
||||||
|
|
||||||
void LogLine(const char *format, ...) {
|
void LogLine(const char *format, ...) {
|
||||||
std::scoped_lock lock{ g_log_mutex };
|
std::scoped_lock lock{ g_log_mutex };
|
||||||
|
|
||||||
|
if (!g_has_initialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RefreshFlags(false);
|
||||||
|
|
||||||
|
if (!g_log_enabled && !g_uart_enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
|
|
||||||
@@ -99,21 +118,19 @@ namespace fileUtils {
|
|||||||
buff[len] = '\0';
|
buff[len] = '\0';
|
||||||
|
|
||||||
// Debug UART log
|
// Debug UART log
|
||||||
svcOutputDebugString(buff, len);
|
if (g_uart_enabled) {
|
||||||
|
svcOutputDebugString(buff, len);
|
||||||
|
}
|
||||||
|
|
||||||
if (g_has_initialized) {
|
if (g_log_enabled) {
|
||||||
RefreshFlags(false);
|
FILE *file = fopen(FILE_LOG_FILE_PATH, "a");
|
||||||
|
|
||||||
if (g_log_enabled) {
|
if (file) {
|
||||||
FILE *file = fopen(FILE_LOG_FILE_PATH, "a");
|
timespec now = {};
|
||||||
|
clock_gettime(CLOCK_REALTIME, &now);
|
||||||
|
|
||||||
if (file) {
|
fprintf(file, "[%luls] %s", now.tv_sec - bootTimeS, buff);
|
||||||
timespec now = {};
|
fclose(file);
|
||||||
clock_gettime(CLOCK_REALTIME, &now);
|
|
||||||
|
|
||||||
fprintf(file, "[%luls] %s", now.tv_sec - bootTimeS, buff);
|
|
||||||
fclose(file);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -222,6 +239,7 @@ namespace fileUtils {
|
|||||||
|
|
||||||
g_has_initialized = false;
|
g_has_initialized = false;
|
||||||
g_log_enabled = false;
|
g_log_enabled = false;
|
||||||
|
g_uart_enabled = false;
|
||||||
|
|
||||||
fsdevUnmountAll();
|
fsdevUnmountAll();
|
||||||
fsExit();
|
fsExit();
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
#define FILE_FLAG_CHECK_INTERVAL_NS (10000ULL * 1000000000ULL)
|
#define FILE_FLAG_CHECK_INTERVAL_NS (10000ULL * 1000000000ULL)
|
||||||
#define FILE_CONTEXT_CSV_PATH FILE_CONFIG_DIR "/context.csv"
|
#define FILE_CONTEXT_CSV_PATH FILE_CONFIG_DIR "/context.csv"
|
||||||
#define FILE_LOG_FLAG_PATH FILE_CONFIG_DIR "/log.flag"
|
#define FILE_LOG_FLAG_PATH FILE_CONFIG_DIR "/log.flag"
|
||||||
|
#define FILE_UART_FLAG_PATH FILE_CONFIG_DIR "/uart.flag"
|
||||||
#define FILE_LOG_FILE_PATH FILE_CONFIG_DIR "/log.txt"
|
#define FILE_LOG_FILE_PATH FILE_CONFIG_DIR "/log.txt"
|
||||||
|
|
||||||
namespace fileUtils {
|
namespace fileUtils {
|
||||||
@@ -46,6 +47,7 @@ namespace fileUtils {
|
|||||||
Result Initialize();
|
Result Initialize();
|
||||||
bool IsInitialized();
|
bool IsInitialized();
|
||||||
bool IsLogEnabled();
|
bool IsLogEnabled();
|
||||||
|
bool IsUartEnabled();
|
||||||
void InitializeAsync();
|
void InitializeAsync();
|
||||||
void LogLine(const char *format, ...);
|
void LogLine(const char *format, ...);
|
||||||
void WriteContextToCsv(const HocClkContext *context);
|
void WriteContextToCsv(const HocClkContext *context);
|
||||||
|
|||||||
Reference in new issue
Block a user