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

mavlink / MAVSDK / 7233481265

16 Dec 2023 06:06PM UTC coverage: 37.088% (+0.09%) from 36.997%
7233481265

push

github

web-flow
Merge pull request #2192 from mavlink/pr-fix-sysid-filter

core: fix incoming messages by sysid

32 of 52 new or added lines in 4 files covered. (61.54%)

1 existing line in 1 file now uncovered.

10002 of 26968 relevant lines covered (37.09%)

113.62 hits per line

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

58.93
/src/mavsdk/core/mavlink_message_handler.cpp
1
#include <mutex>
2
#include "mavlink_message_handler.h"
3
#include "log.h"
4

5
namespace mavsdk {
6

7
MavlinkMessageHandler::MavlinkMessageHandler()
197✔
8
{
9
    if (const char* env_p = std::getenv("MAVSDK_MESSAGE_HANDLER_DEBUGGING")) {
197✔
NEW
10
        if (std::string(env_p) == "1") {
×
NEW
11
            LogDebug() << "Mavlink message handler debugging is on.";
×
NEW
12
            _debugging = true;
×
13
        }
14
    }
15
}
197✔
16

17
void MavlinkMessageHandler::register_one(
1,214✔
18
    uint16_t msg_id, const Callback& callback, const void* cookie)
19
{
20
    std::lock_guard<std::mutex> lock(_mutex);
2,428✔
21

22
    Entry entry = {msg_id, {}, callback, cookie};
2,428✔
23
    _table.push_back(entry);
1,214✔
24
}
1,214✔
25

26
void MavlinkMessageHandler::register_one_with_component_id(
7✔
27
    uint16_t msg_id, uint8_t component_id, const Callback& callback, const void* cookie)
28
{
29
    std::lock_guard<std::mutex> lock(_mutex);
14✔
30

31
    Entry entry = {msg_id, component_id, callback, cookie};
14✔
32
    _table.push_back(entry);
7✔
33
}
7✔
34

35
void MavlinkMessageHandler::unregister_one(uint16_t msg_id, const void* cookie)
×
36
{
37
    std::lock_guard<std::mutex> lock(_mutex);
×
38

39
    for (auto it = _table.begin(); it != _table.end();
×
40
         /* no ++it */) {
41
        if (it->msg_id == msg_id && it->cookie == cookie) {
×
42
            it = _table.erase(it);
×
43
        } else {
44
            ++it;
×
45
        }
46
    }
47
}
×
48

49
void MavlinkMessageHandler::unregister_all(const void* cookie)
687✔
50
{
51
    std::lock_guard<std::mutex> lock(_mutex);
1,374✔
52

53
    for (auto it = _table.begin(); it != _table.end();
3,720✔
54
         /* no ++it */) {
55
        if (it->cookie == cookie) {
3,033✔
56
            it = _table.erase(it);
1,221✔
57
        } else {
58
            ++it;
1,812✔
59
        }
60
    }
61
}
687✔
62

63
void MavlinkMessageHandler::process_message(const mavlink_message_t& message)
2,903✔
64
{
65
    std::lock_guard<std::mutex> lock(_mutex);
5,806✔
66

67
    bool forwarded = false;
2,902✔
68

69
    if (_debugging) {
2,902✔
NEW
70
        LogDebug() << "Table entries: ";
×
71
    }
72

73
    for (auto& entry : _table) {
24,481✔
74
        if (_debugging) {
21,576✔
NEW
75
            LogDebug() << "Msg id: " << entry.msg_id << ", component id: "
×
NEW
76
                       << (entry.component_id.has_value() ?
×
NEW
77
                               std::to_string(entry.component_id.value()) :
×
NEW
78
                               "none");
×
79
        }
80

81
        if (entry.msg_id == message.msgid &&
24,175✔
82
            (!entry.component_id.has_value() || entry.component_id.value() == message.compid)) {
2,596✔
83
            if (_debugging) {
2,596✔
NEW
84
                LogDebug() << "Using msg " << int(message.msgid) << " to " << size_t(entry.cookie);
×
85
            }
86

87
            forwarded = true;
2,596✔
88
            entry.callback(message);
2,596✔
89
        }
90
    }
91

92
    if (_debugging && !forwarded) {
2,903✔
UNCOV
93
        LogDebug() << "Ignoring msg " << int(message.msgid);
×
94
    }
95
}
2,903✔
96

97
void MavlinkMessageHandler::update_component_id(
×
98
    uint16_t msg_id, uint8_t component_id, const void* cookie)
99
{
100
    std::lock_guard<std::mutex> lock(_mutex);
×
101

102
    for (auto& entry : _table) {
×
103
        if (entry.msg_id == msg_id && entry.cookie == cookie) {
×
NEW
104
            entry.component_id = component_id;
×
105
        }
106
    }
107
}
×
108

109
} // 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