Reputation: 1622
I am implementing a very simple communication system based in serial transmission and message frames, small, roughly and loosely adapted from Modbus, with 0x3A
as starting byte, 0x0D 0x0A
sequence as ending bytes.
Most of the action happens when the serial bus detects the 0x3A
byte, and stops until the 0x0D 0x0A
sequence is found.
I would wish a little advice about:
0x0A
and 0x0D
inside a frame? for example, if one of the data in a frame happens to be equal to 0x0A
(an address?). I noted ASCII represents digits symbols with the 0x30
offset, should I do something like that in order to represent raw data, at the obvious expense of losing bytes? Do this have a possible real advantage in here?
Summarizing: Should I stop interpreting the ending bytes as ending bytes and treat all frames as given (predefined or header defined) length?
Upvotes: 1
Views: 771
Reputation: 389
As an 'escaping scheme' a special escape character (ESC
) can be inserted before each control character (start-byte, end-byte) that is part of the data. When a reciever receives an ESC
the next byte is not an control character but part of the data instead. When ESC
itself is part of the data ESC
is also inserted before it.
For example with ESC
0x10
and data 0x00 0x10 0x3A 0x00 0x0D
the transmitted message should become: 0x3A 0x00 0x10 0x10 0x10 0x3A 0x00 0x10 0x0D 0x0D 0x0A
.
Upvotes: 1