MightyPork / TinyFrame

A simple library for building and parsing data frames for serial interfaces (like UART / RS232)
MIT License
344 stars 111 forks source link

if TF_CKSUM_NONE is used, we can use memcpy instead of single byte copy loop #28

Open asmwarrior opened 2 years ago

asmwarrior commented 2 years ago

The patch something like this:

#if TF_CKSUM_TYPE == TF_CKSUM_NONE
    memcpy(outbuff, data, data_len);
#else
    for (i = 0; i < data_len; i++) {
        b = data[i];
        outbuff[pos++] = b;
        CKSUM_ADD(*cksum, b);
    }
#endif // TF_CKSUM_TYPE

In our test, it looks like using memcpy is much faster, and in one test, it reduced to 1/40 of the manually loop byte copy time.

I have use this library in several projects.

For example, I use it in UDP data sending, I think we don't need CRC check here, because the UDP protocol already does some data check. While the UDP package is not sending in a synchronized way, so I use the ID filed of the TinyFrame to resort the messages. It works really nice! Thanks for this great project!