I’m working on with an embedded device that is connected to PC using rs232 (rs232 over USB).
I’m thinking about developing my own protocol:
<MAGIC><LENGTH><BINARY DATA><CRC>
but I don’t want to reinvent the wheel.
Please note that: I'm thinking about quite restricted device: 4kb of RAM, no kernel, nor standard C lib.
Can you think about a standard way to do this (maybe open source library)?
If you code your own solution do have any best practices?
UPDATE: Please re read the question. I shouldn't ask for library but for good practices.
Deserializing (converting byte array into Object)
TCP is a byte-oriented protocol, which means that the sender writes bytes into a TCP connection and the receiver reads bytes out of the TCP connection. Although “byte stream” describes the service TCP offers to application processes, TCP does not, itself, transmit individual bytes over the Internet.
It is a full duplex protocol meaning that each TCP connection supports a pair of byte streams, one flowing each direction. It also includes a flow control mechanism for each of these byte streams that allow the receiver to limit how much data the sender can transmit at a given time.
A reliable byte stream is a common service paradigm in computer networking; it refers to a byte stream in which the bytes which emerge from the communication channel at the recipient are exactly the same, and in exactly the same order, as they were when the sender inserted them into the channel.
See this answer I gave to a very similar question regarding details of a simple protocol.
To respond to your specific points:
For something like this by the time you get an existing solution to work on your device, it would have been easier just to reinvent the wheel.
void buffer_packet(unsigned char rx_byte)
{
static unsigned char byte_count = 0;
static unsigned char packet[8];
packet[byte_count++] = rx_byte;
if (byte_count == 8)
{
unsigned char crc = calculate_crc(packet, 8);
write_uart(0x55);
write_uart(8);
while (byte_count--)
{
write_uart(packet[7 - byte_count]);
}
write_uart(crc);
}
}
Or maybe I am underestimating your problem. If you're looking for how to generate the RS232 bits look in your microcontrollers datasheet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With