• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mavlink / MAVSDK / 16699901624

03 Aug 2025 01:51AM UTC coverage: 46.517% (+0.4%) from 46.108%
16699901624

Pull #2637

github

web-flow
Merge eb84636d5 into 501170eb2
Pull Request #2637: Enable forwarding unknown messages

140 of 178 new or added lines in 6 files covered. (78.65%)

43 existing lines in 6 files now uncovered.

16300 of 35041 relevant lines covered (46.52%)

368.27 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

41.1
/src/mavsdk/core/mavlink_receiver.cpp
1
#include "mavlink_receiver.h"
2
#include "log.h"
3
#include <iomanip>
4

5
namespace mavsdk {
6

7
MavlinkReceiver::MavlinkReceiver()
108✔
8
{
9
    if (const char* env_p = std::getenv("MAVSDK_DROP_DEBUGGING")) {
108✔
10
        if (std::string(env_p) == "1") {
×
11
            LogDebug() << "Drop debugging is on.";
×
12
            _drop_debugging_on = true;
×
13
        }
14
    }
15
}
108✔
16

17
void MavlinkReceiver::set_new_datagram(char* datagram, unsigned datagram_len)
2,255✔
18
{
19
    _datagram = datagram;
2,255✔
20
    _datagram_len = datagram_len;
2,255✔
21

22
    if (_drop_debugging_on) {
2,255✔
23
        _drop_stats.bytes_received += _datagram_len;
×
24
    }
25
}
2,255✔
26

27
bool MavlinkReceiver::parse_message()
4,514✔
28
{
29
    // Note that one datagram can contain multiple mavlink messages.
30
    for (unsigned i = 0; i < _datagram_len; ++i) {
237,497✔
31
        uint8_t parse_result = mavlink_frame_char_buffer(
235,233✔
32
            &_mavlink_message_buffer, &_mavlink_status, _datagram[i], &_last_message, &_status);
235,233✔
33

34
        if (parse_result == MAVLINK_FRAMING_OK) {
235,234✔
35
            // Successfully parsed message
36
            // Move the pointer to the datagram forward by the amount parsed.
37
            _datagram += (i + 1);
2,247✔
38
            // And decrease the length, so we don't overshoot in the next round.
39
            _datagram_len -= (i + 1);
2,247✔
40

41
            if (_drop_debugging_on) {
2,247✔
42
                debug_drop_rate();
×
43
            }
44

45
            // We have parsed one message, let's return, so it can be handled.
46
            return true;
2,255✔
47
        } else if (parse_result == MAVLINK_FRAMING_BAD_CRC) {
232,987✔
48
            // Complete message with bad CRC - store raw bytes for forwarding
49
            // Calculate the message length based on header info
50
            size_t message_length = 0;
4✔
51
            if (_last_message.magic == MAVLINK_STX_MAVLINK1) {
4✔
52
                // MAVLink v1: STX + header + payload + CRC
NEW
53
                message_length = 1 + MAVLINK_CORE_HEADER_MAVLINK1_LEN + _last_message.len +
×
54
                                 MAVLINK_NUM_CHECKSUM_BYTES;
55
            } else {
56
                // MAVLink v2: STX + header + payload + CRC + optional signature
57
                message_length =
4✔
58
                    1 + MAVLINK_CORE_HEADER_LEN + _last_message.len + MAVLINK_NUM_CHECKSUM_BYTES;
4✔
59
                if (_last_message.incompat_flags & MAVLINK_IFLAG_SIGNED) {
4✔
NEW
60
                    message_length += MAVLINK_SIGNATURE_BLOCK_LEN;
×
61
                }
62
            }
63

64
            // Calculate start position (current position minus what we've consumed)
65
            if (i + 1 >= message_length) {
4✔
66
                // Note: Raw message detected but storage removed since retrieval methods were
67
                // unused
68

69
                // Move the pointer to the datagram forward by the amount parsed.
70
                _datagram += (i + 1);
4✔
71
                // And decrease the length, so we don't overshoot in the next round.
72
                _datagram_len -= (i + 1);
4✔
73

74
                // Return true to indicate we have something to process (raw message)
75
                return true;
4✔
76
            }
77
        }
78
    }
79

80
    // No (more) messages, let's give up.
81
    _datagram = nullptr;
2,264✔
82
    _datagram_len = 0;
2,264✔
83
    return false;
2,264✔
84
}
85

86
void MavlinkReceiver::debug_drop_rate()
×
87
{
88
    if (_last_message.msgid == MAVLINK_MSG_ID_SYS_STATUS) {
×
89
        const unsigned msg_len = (_last_message.len + MAVLINK_NUM_NON_PAYLOAD_BYTES);
×
90

91
        _drop_stats.bytes_received -= msg_len;
×
92

93
        mavlink_sys_status_t sys_status;
94
        mavlink_msg_sys_status_decode(&_last_message, &sys_status);
×
95

96
        if (!_drop_stats.first) {
×
97
            LogDebug() << "-------------------------------------------------------------------"
×
98
                       << "-----------";
×
99

100
            if (_drop_stats.bytes_received <= sys_status.errors_comm &&
×
101
                sys_status.errors_count2 <= sys_status.errors_comm) {
×
102
                _drop_stats.bytes_sent_overall += sys_status.errors_comm;
×
103
                //_bytes_at_gimbal_overall += sys_status.errors_count1;
104
                _drop_stats.bytes_at_camera_overall += sys_status.errors_count2;
×
105
                _drop_stats.bytes_at_sdk_overall += _drop_stats.bytes_received;
×
106

107
                _drop_stats.time_elapsed += _time.elapsed_since_s(_drop_stats.last_time);
×
108

109
                print_line(
×
110
                    "FMU   ",
111
                    sys_status.errors_comm,
×
112
                    sys_status.errors_comm,
×
113
                    _drop_stats.bytes_sent_overall,
114
                    _drop_stats.bytes_sent_overall);
115

116
                print_line(
×
117
                    "Camera",
118
                    sys_status.errors_count2,
×
119
                    sys_status.errors_comm,
×
120
                    _drop_stats.bytes_at_camera_overall,
121
                    _drop_stats.bytes_sent_overall);
122

123
                print_line(
×
124
                    "SDK   ",
125
                    _drop_stats.bytes_received,
126
                    sys_status.errors_comm,
×
127
                    _drop_stats.bytes_at_sdk_overall,
128
                    _drop_stats.bytes_sent_overall);
129

130
            } else {
131
                LogDebug() << "Missed SYS_STATUS";
×
132
            }
133
        }
134
        _drop_stats.first = false;
×
135

136
        _drop_stats.last_time = _time.steady_time();
×
137

138
        // Reset afterwards:
139
        _drop_stats.bytes_received = msg_len;
×
140
    }
141
}
×
142

143
void MavlinkReceiver::print_line(
×
144
    const char* index,
145
    uint64_t count,
146
    uint64_t count_total,
147
    uint64_t overall_bytes,
148
    uint64_t overall_bytes_total)
149
{
150
    LogDebug() << "count " << index << ": " << std::setw(6) << count << ", loss: " << std::setw(6)
×
151
               << count_total - count << ",  " << std::setw(6) << std::setprecision(2) << std::fixed
×
152
               << 100.0f * float(count) / float(count_total) << " %, overall: " << std::setw(6)
×
153
               << std::setprecision(2) << std::fixed
×
154
               << (100.0f * float(overall_bytes) / float(overall_bytes_total)) << " %, "
×
155
               << std::setw(6) << std::setprecision(2) << std::fixed
×
156
               << (float(overall_bytes) / float(_drop_stats.time_elapsed) / 1024.0f) << " KiB/s";
×
157
}
×
158

159
} // namespace mavsdk
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc