1. Introduction
This project establishes the foundational architecture for the MAVLink communication system, enabling the seamless encoding and decoding of MAVLink messages from raw data inputs.
2. Features & Functionalities
Encoding of Data: Convert raw data inputs into MAVLink formatted messages.
Buffer Storage: Store the MAVLink formatted messages into a buffer for transmission or further processing.
Decoding of MAVLink Bytestreams: Parse buffer to retrieve MAVLink message.
3. Classes & Methods
MavlinkEncoder
This class serves as the core component responsible for encoding MAVLink messages from raw data inputs contained within the IncomingData
struct. It provides functionalities for encoding different MAVLink messages and packing them into a single buffer array.
Constructor: MavlinkEncoder::MavlinkEncoder()
Purpose: Initializes the
MavlinkEncoder
object.
Method: packIntoMavlinkByteArray
Purpose: Encodes incoming data into MAVLink formatted messages and packs these messages into an output buffer.
Parameters:
IncomingData &data
: Reference to the raw data that needs to be encoded.uint8_t outputBuffer[]
: Target buffer where the MAVLink messages will be stored.size_t maxBufferSize
: Maximum allowable size of the target buffer to prevent overflow.
Return Value:
Returns the actual size of the data packed into the output buffer. Note that the output buffer provided in the parameter will be filled with the encoded MAVLink messages.
Notes:
Uses a temporary buffer (
tempBuffer
) to first store the MAVLink message before copying it to the output buffer.Checks for the initialization of various data fields (like latitude, longitude, altitude) and encodes the corresponding MAVLink message.
Does not contain an error handling like overwriting the outputBuffer.
MavlinkDecoder
This class acts as the principal mechanism for decoding MAVLink messages into their respective structured representations. The decoded data can then be utilized for further application-specific processing. The decoder leverages callback-based techniques, registering specific decoder functions for each MAVLink message type. When a message is detected, the appropriate decoder function is triggered.
Constructor: MavlinkDecoder::MavlinkDecoder()
Purpose: Sets up the registered decoders for the MAVLink message types, mapping each message type to its corresponding decoding function.
Method: parseBytesToMavlinkMsgs
Purpose: Iterates through a provided byte buffer, attempts to construct valid MAVLink messages, and subsequently decodes them.
Parameters:
*u_int8_t buffer: Pointer to the source buffer containing raw bytes.
std::size_t bufferSize: The size of the provided buffer, denoting how many bytes to process.
Notes:
Relies on the
mavlink_parse_char
function to recognize and create MAVLink messages.Uses the constructed MAVLink message and tries to decode it employing the registered decoder functions.
Macro: REGISTER_DECODER()
IncomingData
The IncomingData
structure represents incoming data for the drone. However, this struct is just a starting point. It's designed to hold various parameters such as latitude, longitude, velocities in different axes, altitude, and the pitch, roll, and yaw angles. A dedicated boolean flag accompanies each data point to signify if that data point has been initialized, ensuring data validity before processing.
Member Variables:
Variable Name | Data Type | Description | Initialization Flag |
---|---|---|---|
latitude | float | Latitude of the drone in degrees. | isLatitudeInitialized |
longitude | float | Longitude of the drone in degrees. | isLongitudeInitialized |
vx | float | Velocity in the X-axis (m/s). | isVxInitialized |
vy | float | Velocity in the Y-axis (m/s). | isVyInitialized |
vz | float | Velocity in the Z-axis (m/s). | isVzInitialized |
altitude | int | Altitude of the drone in meters. | isAltitudeInitialized |
pitch | float | Pitch angle of the drone in degrees. | isPitchInitialized |
roll | float | Roll angle of the drone in degrees. | isRollInitialized |
yaw | float | Yaw angle of the drone in degrees. | isYawInitialized |
Note: This structure MUST be modified as needed to align with the project's requirements (the required fields for the project). The current structure serves as a starting point.
4. Usage Example
Initialize the
IncomingData
object with data values.Use
findPackingFunction
fromMavlinkEncoder
to encode data into a buffer.Demonstrate decoding using the placeholder
MavlinkDecoder
class.
5. Testing
Manual Testing
Sample data initialized and encoding verified by observing the buffer output.
Placeholder decoding demonstrated with the sample buffer to ensure data integrity.
Unit Testing
None
6. Future Improvements
Implement error-handling for buffer overflow scenarios.
0 Comments