I have a small c program to copy input from an algorithm into a final char array that is then sent over serial (UART) to a raspberry pi. The problem is the last character in the char array is always a latin-1 character of the ÿ (\xff).
The sprintf formatting works great but when i create a new char buffer to limit the size of the array and only copy the contents it seems to strip off the \n and append the \xff or ÿ depending upon what encoding you are using in the pi for the serial reader.
char accel_string[50] = "";
sprintf(accel_string, "B:%d|A:%d\n", dataB, dataA)
// I can see "B:123|A:123\n\0" in the char array now
int str_length = strlen(accel_string);
char trunc_str[str_length];
strncpy(trunc_str, accel_string, str_length);
// Now it sets trunc_str to "B:123|A:123\xff
// Blocking TX right now - write over serial
eResult = adi_uart_Write(ghUART, trunc_str, sizeof(trunc_str));
trunc_str keeps ending with the ÿ when I would expect it to end in the "\n"
Help me where I went wrong.
Update based on comments with putty results
Update #2 I have verified that a '\n' anywhere in the char array gets removed and replace with the ÿ. I looked at the watch variable on the char array and when its sent to the uart_write the \n exists. After the buffer is coverted to a unit8_t in the uart code it seems to strip off the \n. I have even tried a unit8_t with a '\n' and it strips out after calling the uart_write code. I have reached out to analog.com and will update this post once there is a resolution.