#ifndef TEST #include #include #include #include #endif #include #include #include #include #include #include #include #ifdef TEST #define LOGBUFFER_SIZE 32 #define MSGBUFFER_SIZE 16 #else #define LOGBUFFER_SIZE 1024 #define MSGBUFFER_SIZE 64 #endif // TEST static ringbuffer_t logBuffer; void logInit() { ringbufferInit(&logBuffer, LOGBUFFER_SIZE); } void logFree() { ringbufferFree(&logBuffer); } int logExec() { int c = -1; #ifndef TEST if (__HAL_UART_GET_FLAG(&debugUart, UART_FLAG_TXE)) { // is the TX channel free #endif // TEST c = ringbufferGetOne(&logBuffer); if (c > 0) { #ifndef TEST // transfer to TX channel uint8_t cc = (uint8_t) c; HAL_UART_Transmit(&debugUart, &cc, 1, HAL_MAX_DELAY); #endif // TEST } #ifndef TEST } #endif // TEST return c; } #ifndef TEST static void flashGreenLed(void *handle) { show(LED_GREEN, TOGGLE); } #endif // TEST int logMsg(const char *format, ...) { int res = -1; char msgBuffer[MSGBUFFER_SIZE]; va_list vl; va_start(vl, format); int vcnt = vsnprintf(msgBuffer, MSGBUFFER_SIZE-2, format, vl); va_end(vl); if (vcnt < MSGBUFFER_SIZE) { strcat(msgBuffer, "\r\n"); if (-1 == (res = ringbufferPut(&logBuffer, (uint8_t*) msgBuffer, strlen(msgBuffer)))) { #ifndef TEST // blink the green light or so flashGreenLed(NULL); schAdd(flashGreenLed, NULL, 100, 0); #else printf("\n*** green blink ***\n"); #endif // TEST } } return res; }