I am developing a UART protocol based on ASCII encoding. Communication is between a PC and an STM32 board. Packet format is like this:
Packet: {STX,DATA,ETX} Where STX and ETX are 0x02
and Ox03
in ASCII.
Example:
STXHELLOETX in Hex would be: 0x02 0x48 0x45 0x4c 0x4c 0x4f 0x03
My question is where exactly is the position of \0
character in my packet? is it after ETX like this: STXHELLOETX\0 or after HELLO like this: STXHELLO\0ETX ?
Best Answer
You specify your packet format as {STX,DATA,ETX}.
The entire DATA content of the packet is contained within the DATA field, between the STX and ETX.
If you decide to send NUL-terminated strings in your packets then the NUL is part of the string - part of your DATA field.
So you would send: STXHELLO\0ETX