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
Header¶
For informations, a header field inside LoggerFrame is giving mavlink messages Names and ID. The completion of this
header is done by MAVLINK_UTILS::initiateLogging()
. It is given just as a indication as the log decoding tools will extract
the informations directly from generated code and ID encoded inside the mavlink frame payload.
{
"mavlinkHeader": "ATTITUDE_QUATERNION,LOCAL_POSITION_NED,GLOBAL_POSITION_INT,HIGHRES_IMU,SYSROX_INS_GENERIC_CALIBRATION_BARO_SENSOR_CORRECTION,SYSROX_INS_GENERIC_CALIBRATION_IMU_SENSOR_CORRECTION_ACC,SYSROX_INS_GENERIC_CALIBRATION_IMU_SENSOR_CORRECTION_GYRO,SYSROX_INS_GENERIC_CALIBRATION_IMU_SENSOR_CORRECTION_MAG,SYSROX_INS_GENERIC_CALIBRATION_MAG_SENSOR_CORRECTION",
"timestamp": 5811387
},
{
"mavlinkID": "31,32,33,105,50005,50001,50002,50003,50004",
"timestamp": 5811387
},
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.
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
},