Messages logging

Introduction

The methods used to send and received messages (MAVLINK_UTILS::sendMessage(), MAVLINK_UTILS::sendMessages(), MAVLINK_UTILS::updateMonitoredMessages()) include logging mecanism that can be used to log the mavlink sent or received messages.

Activation

The only method that has to be called is MAVLINK_UTILS::initiateLogging() :

MAVLINK_UTILS mavlink(&streamObj);
mavlink.initiateLogging();

Warning

As mentionned in the API documentation, this function should be called after all messages to monitor and send have been added! So it should be called after all MAVLINK_UTILS::addMsgToMonitor() and MAVLINK_UTILS::addMsgToSendingList().

The use of libDM_msg_center does call this method automatically.

Location and structure of the logging file

From June 2024, the protobuf events are logged inside the unique protobuf encoded binary file. The file is located in the SD card in local_folder/log.binDM.

  • The logging binary file is located in the SD card in local_folder/log.binDM.

More information about the general logging mechanism at libDM_stream_logger

Body

Inside the LoggerFrame structure, a field containing the mavlink events exists and is populated when a mavlink event is sent or received.

  • The logged mavlink frame follows mavlink structure with the addition of direction.

Message structure

Direction

Mavlink message

With direction being 0 for messages received and 1 for messages sent.

Decoding

A general logging file handle the decoding of all the enclosed information, including protobuf events. The script is located in the protobuf repo, inside the folder tools/decode_protobuf.py.

The script can be used as follow:

  • Install the requirements:

pip install -r requirements.txt
  • Run the script:

python decode_protobuf.py log.binDM

The script will read and extract the data from the logging file and create a new file mavlinkEventsLog_decoded.json inside the output folder, with the messages sent or received presented with json format, for example:

{
    "mavlinkData": {
    "mavpackettype": "ATTITUDE_QUATERNION",
    "time_boot_ms": 11770,
    "q1": 0.8999999761581421,
    "q2": 0.10000000149011612,
    "q3": 0.20000000298023224,
    "q4": 0.30000001192092896,
    "rollspeed": 0.0,
    "pitchspeed": 0.0,
    "yawspeed": 0.0,
    "repr_offset_q": [
        0.0,
        0.0,
        0.0,
        0.0
    ]
    },
    "mavlinkDirection": "TX",
    "mavlinkID": 31,
    "timestamp": 11770214
},