diff --git a/src/utils/logger.c b/src/utils/logger.c deleted file mode 100644 index 69cd856..0000000 --- a/src/utils/logger.c +++ /dev/null @@ -1,84 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -static int log_socket __attribute__((section(".data"))) = -1; -static struct sockaddr_in connect_addr __attribute__((section(".data"))); -static volatile int log_lock __attribute__((section(".data"))) = 0; - -void log_init_() { - int broadcastEnable = 1; - log_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - if (log_socket < 0) { - return; - } - - setsockopt(log_socket, SOL_SOCKET, SO_BROADCAST, &broadcastEnable, sizeof(broadcastEnable)); - - memset(&connect_addr, 0, sizeof(struct sockaddr_in)); - connect_addr.sin_family = AF_INET; - connect_addr.sin_port = 4405; - connect_addr.sin_addr.s_addr = htonl(INADDR_BROADCAST); -} - -void log_print_(const char *str) { - // socket is always 0 initially as it is in the BSS - if (log_socket < 0) { - return; - } - - while (log_lock) - OSSleepTicks(OSMicrosecondsToTicks(1000)); - log_lock = 1; - - int len = strlen(str); - int ret; - while (len > 0) { - int block = len < 1400 ? len : 1400; // take max 1400 bytes per UDP packet - ret = sendto(log_socket, str, block, 0, (struct sockaddr *) &connect_addr, sizeof(struct sockaddr_in)); - if (ret < 0) { - break; - } - - len -= ret; - str += ret; - } - - log_lock = 0; -} - -void OSFatal_printf(const char *format, ...) { - char tmp[512]; - tmp[0] = 0; - va_list va; - va_start(va, format); - if ((vsprintf(tmp, format, va) >= 0)) { - OSFatal(tmp); - } - va_end(va); -} - -void log_printf_(const char *format, ...) { - if (log_socket < 0) { - return; - } - - char tmp[512]; - tmp[0] = 0; - - va_list va; - va_start(va, format); - if ((vsprintf(tmp, format, va) >= 0)) { - log_print_(tmp); - } - va_end(va); -} - diff --git a/src/utils/logger.h b/src/utils/logger.h index 0fadbd9..bc85221 100644 --- a/src/utils/logger.h +++ b/src/utils/logger.h @@ -1,34 +1,15 @@ #pragma once +#include +#include + #ifdef __cplusplus extern "C" { #endif -#include -#include - -void log_init_(); - -//void log_deinit_(void); -void log_print_(const char *str); - -void log_printf_(const char *format, ...); - -void OSFatal_printf(const char *format, ...); - #define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__) -#define OSFATAL_FUNCTION_LINE(FMT, ARGS...)do { \ - OSFatal_printf("[%s]%s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ - } while (0) - - -#define log_init() log_init_() -//#define log_deinit() log_deinit_() -#define log_print(str) log_print_(str) -#define log_printf(FMT, ARGS...) log_printf_(FMT, ## ARGS); - #define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \ WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ } while (0) diff --git a/src/utils/utils.c b/src/utils/utils.c index d02af35..f09244c 100644 --- a/src/utils/utils.c +++ b/src/utils/utils.c @@ -1,9 +1,6 @@ #include #include -#include #include -#include -#include #include "utils/logger.h" // https://gist.github.com/ccbrown/9722406 @@ -13,28 +10,28 @@ void dumpHex(const void *data, size_t size) { ascii[16] = '\0'; DEBUG_FUNCTION_LINE("0x%08X (0x0000): ", data); for (i = 0; i < size; ++i) { - log_printf("%02X ", ((unsigned char *) data)[i]); + WHBLogPrintf("%02X ", ((unsigned char *) data)[i]); if (((unsigned char *) data)[i] >= ' ' && ((unsigned char *) data)[i] <= '~') { ascii[i % 16] = ((unsigned char *) data)[i]; } else { ascii[i % 16] = '.'; } if ((i + 1) % 8 == 0 || i + 1 == size) { - log_print(" "); + WHBLogPrintf(" "); if ((i + 1) % 16 == 0) { - log_printf("| %s \n", ascii); + WHBLogPrintf("| %s \n", ascii); if (i + 1 < size) { DEBUG_FUNCTION_LINE("0x%08X (0x%04X); ", data + i + 1, i + 1); } } else if (i + 1 == size) { ascii[(i + 1) % 16] = '\0'; if ((i + 1) % 16 <= 8) { - log_print(" "); + WHBLogPrintf(" "); } for (j = (i + 1) % 16; j < 16; ++j) { - log_print(" "); + WHBLogPrintf(" "); } - log_printf("| %s \n", ascii); + WHBLogPrintf("| %s \n", ascii); } } }