I'm trying to write a custom logger that takes messages from a queue and transmits them over a BLE connection. Overall, I've got it working, but I have some strange behavior that I can't explain.
I want to prepend a short string ("# ") before transmitting the message. Here is a slightly adjusted version of my code:
Code: Select all
void log_queue_processing_task(void *pdParameters) {
char msg[CONFIG_NORDIC_UART_MAX_LINE_LENGTH];
static const char pre[] = "# ";
while (true) {
if(ble_connected) {
if (xQueueReceive(xLogQueue, &msg, portMAX_DELAY) == pdTRUE) {
char mbuf[CONFIG_NORDIC_UART_MAX_LINE_LENGTH];
//strncat(mbuf, msg, sizeof(mbuf)-2); // original method. Results the same as using the snprintf on the next line.
snprintf(mbuf, CONFIG_NORDIC_UART_MAX_LINE_LENGTH, "%.3s%.252s", pre, msg);
nordic_uart_send(mbuf);
}
} else {
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
vTaskDelete(NULL);
}
Here is an example of the output I'm getting:
Code: Select all
// Console output:
"I (5968) MAIN: This is a log message"
// Expected processed output:
"# I (5968) MAIN: This is a log message"
// Actual output
"# I (5968) main_task: # Returned from app_main()# "
Can anyone explain why I'm getting the extra "# "s inserted into the output? I get the same thing whether I'm using strcpy() or snprintf().
Thanks for any help you can give!
