Design a protocol
A protocol is used for communicating between master and slave device.
A suggested minium protocol structure is: HEAD + LENGTH + MSG_TYPE + DATA + TAIL
.
You can add SEQUENCE
if the lower tranmission layer can't guarantee correct data sequence.
You can add CHECKSUM
if the lower tranmission layer can't guarantee correct data content.
HEAD
is to determine where a package starts from.
LENGTH
and TAIL
can work together to determine if a package is received completely. A large package could be splited into several small packages and sent seperately. For example, BLE mtu is 20 byte by default, which is very small to send big data.