#include <DataLinkSerialProtocol.h>
template<uint8_t NMaxMessage = 10>
struct proto::Bicoder< NMaxMessage >
The main (and only) class containing the whole functionality. This class holds both the encoder and decoder. It stores the encoded or decoded message in the internal buffer. A typical workflow looks like this:
{
uint8_t* pBuffer = bicoder.
buff();
for(uint8_t i = 0; i < bicoder.
size(); ++i)
{
print(pBuffer[i]);
}
}
{
}
Definition DataLinkSerialProtocol.h:76
uint8_t size() const
Definition DataLinkSerialProtocol.h:172
bool decodeMessage(const uint8_t *data, uint8_t size)
Definition DataLinkSerialProtocol.h:234
bool encodeMessage(const uint8_t *data, uint8_t size)
Definition DataLinkSerialProtocol.h:266
const uint8_t * buff() const
Definition DataLinkSerialProtocol.h:179
- Note
- The buffer is shared between the encoder and decoder so don't try to encode a message while you haven't finished decoding, and vice versa. It doesn't mean you have to create 2 instances of this class: one for the encoder and one for the decoder (though you can if you want). It just means once you've started, f.e. the encoding process any data in the buffer (if any) is lost, and vice versa. Once you've read the encoded (decoded) message and you don't need it anymore you can start a new operation.
- Template Parameters
-
| NMaxMessage | The maximum length of a (raw) message, i.e. the maximum number of bytes that the data may consist of. |
◆ buff()
template<uint8_t NMaxMessage = 10>
Use this member-function in conjunction with the size member-function to read the encoded/decoded message.
- See also
size()
◆ decodeByte()
Decode a single byte. An auxiliary function. Used by the decodeMessage member-function.
- Parameters
-
- Returns
true if succeedded, false - otherwise
- Important
- Before this function is called on the first byte of the message it is necessary to call the reset() member-function first:
...
for(uint8_t i = 0; i < messageLength; ++i)
{
}
void reset()
Definition DataLinkSerialProtocol.h:220
bool decodeByte(const uint8_t data)
Definition DataLinkSerialProtocol.h:228
- See also
isCompleted()
◆ decodeMessage()
template<uint8_t N>
| bool proto::Bicoder< N >::decodeMessage |
( |
const uint8_t * | data, |
|
|
uint8_t | size ) |
Decode an encoded message.
- Note
- This function overwrites the internal buffer, so be sure you don't need its content anymore before call this member-function.
-
This member-function calls the reset() member-function.
- Parameters
-
| data | the encoded message |
| size | the length of the encoded message (the number of bytes in data) |
- Returns
true if succeedded, false - otherwise
- See also
size(), buff()
◆ encodeMessage()
template<uint8_t N>
| bool proto::Bicoder< N >::encodeMessage |
( |
const uint8_t * | data, |
|
|
uint8_t | size ) |
Encode a raw message.
- Note
- This function rewrites the internal buffer, so be sure you don't need its content anymore before call this member-function.
-
This member-function calls the reset() member-function.
- Parameters
-
| data | the raw message |
| size | the length of the message (the number of bytes in data) |
- Returns
true if succeedded, false - otherwise
- See also
size(), buff()
◆ isCompleted()
template<uint8_t NMaxMessage = 10>
Indicates whether a frame has been received (decoded) completely. Call it to check if the buffer contains a complete frame, i.e. the message has been decoded. Usually used in conjunction with the decodeByte() member function.
- Returns
true if the internal buffer contains a complete frame and can be read using the size and buff member functions. false - otherwise.
- See also
decodeByte()
◆ reset()
Resets the internal state of the instance. After this member function has been called the state is the following:
- the
isCompleted member function will return false
- the decoder is in the
waitHeader state awaiting for the start of the frame
- the current index of the internal buffer is set to 0
- Note
- It doesn't clear the buffer - just sets the current index to 0
◆ size()
template<uint8_t NMaxMessage = 10>
Returns the size of the internal buffer. Use this member-function in conjunction with the buff member-function to read the encoded/decoded message.
- See also
buff()
◆ maxEncodedSize
template<uint8_t NMaxMessage = 10>
| uint8_t proto::Bicoder< NMaxMessage >::maxEncodedSize = 2U * NMaxMessage + 2U |
|
staticconstexpr |
Maximum possible length of the encoded message. This is the capacity of the internal buffer.
The documentation for this struct was generated from the following file: