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

mavlink / MAVSDK / 6568658631

19 Oct 2023 01:31AM UTC coverage: 31.23% (+0.02%) from 31.215%
6568658631

push

github

web-flow
Merge pull request #2155 from mavlink/pr-static-fixes

Threading fixes, MAVLink sequence number cleanup

1386 of 1386 new or added lines in 46 files covered. (100.0%)

7906 of 25315 relevant lines covered (31.23%)

23.54 hits per line

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

0.0
/src/mavsdk/plugins/server_utility/server_utility_impl.cpp
1
#include "server_utility_impl.h"
2
#include <limits>
3

4
namespace mavsdk {
5

6
ServerUtilityImpl::ServerUtilityImpl(System& system) : PluginImplBase(system)
×
7
{
8
    _system_impl->register_plugin(this);
×
9
}
×
10

11
ServerUtilityImpl::ServerUtilityImpl(std::shared_ptr<System> system) :
×
12
    PluginImplBase(std::move(system))
×
13
{
14
    _system_impl->register_plugin(this);
×
15
}
×
16

17
ServerUtilityImpl::~ServerUtilityImpl()
×
18
{
19
    _system_impl->unregister_plugin(this);
×
20
}
×
21

22
void ServerUtilityImpl::init() {}
×
23

24
void ServerUtilityImpl::deinit() {}
×
25

26
void ServerUtilityImpl::enable() {}
×
27

28
void ServerUtilityImpl::disable() {}
×
29

30
std::optional<MAV_SEVERITY>
31
ServerUtilityImpl::mav_severity_from_status_text_type(ServerUtility::StatusTextType type)
×
32
{
33
    switch (type) {
×
34
        case ServerUtility::StatusTextType::Debug:
×
35
            return {MAV_SEVERITY_DEBUG};
×
36
        case ServerUtility::StatusTextType::Info:
×
37
            return {MAV_SEVERITY_INFO};
×
38
        case ServerUtility::StatusTextType::Notice:
×
39
            return {MAV_SEVERITY_NOTICE};
×
40
        case ServerUtility::StatusTextType::Warning:
×
41
            return {MAV_SEVERITY_WARNING};
×
42
        case ServerUtility::StatusTextType::Error:
×
43
            return {MAV_SEVERITY_ERROR};
×
44
        case ServerUtility::StatusTextType::Critical:
×
45
            return {MAV_SEVERITY_CRITICAL};
×
46
        case ServerUtility::StatusTextType::Alert:
×
47
            return {MAV_SEVERITY_ALERT};
×
48
        case ServerUtility::StatusTextType::Emergency:
×
49
            return {MAV_SEVERITY_EMERGENCY};
×
50
    }
51

52
    return {};
×
53
}
54

55
ServerUtility::Result
56
ServerUtilityImpl::send_status_text(ServerUtility::StatusTextType type, std::string text)
×
57
{
58
    constexpr unsigned chunk_size =
×
59
        sizeof(mavlink_statustext_t::text) / sizeof(mavlink_statustext_t::text[0]);
60
    constexpr unsigned max_len = chunk_size * std::numeric_limits<uint8_t>::max();
×
61

62
    // -1 for 0 termination.
63
    if (text.size() > max_len - 1) {
×
64
        return ServerUtility::Result::InvalidArgument;
×
65
    }
66

67
    const auto maybe_mav_severity = mav_severity_from_status_text_type(type);
×
68
    if (!maybe_mav_severity.has_value()) {
×
69
        return ServerUtility::Result::InvalidArgument;
×
70
    }
71

72
    // If the text size is a multiple of the chunk_size, we still need to add
73
    // one chunk for the 0 termination.
74
    const auto chunks_required = text.size() / chunk_size + 1;
×
75

76
    // The id starts from 1 if there are multiple chunks, it's 0 otherwise.
77
    uint16_t id = 0;
×
78
    if (chunks_required > 1) {
×
79
        id = _unique_send_id++;
×
80
    }
81

82
    for (unsigned chunk_seq = 0; chunk_seq < chunks_required; ++chunk_seq) {
×
83
        const char* pos = &text.c_str()[chunk_seq * chunk_size];
×
84
        char tmp_buf[chunk_size]{};
×
85
        const unsigned copy_len = std::min(chunk_size, static_cast<unsigned>(strlen(pos)));
×
86
        memcpy(tmp_buf, pos, copy_len);
×
87

88
        if (!_system_impl->queue_message([&](MavlinkAddress mavlink_address, uint8_t channel) {
×
89
                mavlink_message_t message;
90
                mavlink_msg_statustext_pack_chan(
×
91
                    mavlink_address.system_id,
×
92
                    mavlink_address.component_id,
×
93
                    channel,
94
                    &message,
95
                    maybe_mav_severity.value(),
×
96
                    tmp_buf,
×
97
                    id,
×
98
                    chunk_seq);
×
99
                return message;
×
100
            })) {
101
            return ServerUtility::Result::ConnectionError;
×
102
        }
103
    }
104

105
    return ServerUtility::Result::Success;
×
106
}
107

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

© 2025 Coveralls, Inc