08-23-2021 07:31 AM
Hello, I would join this auhtor's question with my escape character issue.
I need parse serial communication, where some characters are used for control the communication. But thay may occur also in payload data, so escape character is used as prefix. (ESC)(restricted_characted). In this protocol escape is value 0x1F. control values are 0x1A to 0x1E
How I can easily "cleanup" recieved string, from ESC characters (thay may occur 0 to N-occurences) ?
Example
0x1A 0x03 0x02 0x1F 0x1B 0x1A 0x1B
here escape character tells that ending character 0x1B is earlier, so physically datagram is 0x1A 0x03 0x02 0x1B 0x1B (bold are controls)
Thanks you
LPR
Solved! Go to Solution.
08-23-2021 10:46 AM
08-31-2021 02:42 AM
Finally I solved problem by right sorting and logic of packet processing.
I hope, it can help somebody else with processing, parsing packets.
KP
08-31-2021 11:34 AM
Holy cow, I hate parsing serial strings of this nature. It's never nice and clean.
09-01-2021 08:24 AM
@KPr_HW wrote:
Finally I solved problem by right sorting and logic of packet processing.
- Firstly I detect end of packet, that should contain END character, but not ESC character before. For that I use "Match pattern" wtih REGEX [^\xDA][\xB0].
- Then I parse begining of packet (START character)
- And last thing I remove ESCape character by "Search and Replace String".
I hope, it can help somebody else with processing, parsing packets.
KP
That's a good way. Or convert the string to an array of chars/U8 and flag if 1F is found. If so, the next character should be included 'as is' (and all standard ones, ofc). If End character is found, break loop and send out the resulting string.