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

mavlink / MAVSDK / 4899817366

pending completion
4899817366

Pull #1772

github

GitHub
Merge c0bb90862 into e4e9c71dd
Pull Request #1772: Refactor MAVLinkParameters into client and server classes

2192 of 2192 new or added lines in 34 files covered. (100.0%)

7708 of 24812 relevant lines covered (31.07%)

19.96 hits per line

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

0.0
/src/mavsdk/plugins/mavlink_passthrough/mavlink_passthrough_impl.cpp
1
#include <functional>
2
#include "mavlink_passthrough_impl.h"
3
#include "system.h"
4
#include "callback_list.tpp"
5

6
namespace mavsdk {
7

8
template class CallbackList<const mavlink_message_t&>;
9

10
MavlinkPassthroughImpl::MavlinkPassthroughImpl(System& system) : PluginImplBase(system)
×
11
{
12
    _system_impl->register_plugin(this);
×
13
}
×
14

15
MavlinkPassthroughImpl::MavlinkPassthroughImpl(std::shared_ptr<System> system) :
×
16
    PluginImplBase(std::move(system))
×
17
{
18
    _system_impl->register_plugin(this);
×
19
}
×
20

21
MavlinkPassthroughImpl::~MavlinkPassthroughImpl()
×
22
{
23
    _system_impl->unregister_plugin(this);
×
24
}
×
25

26
void MavlinkPassthroughImpl::init() {}
×
27

28
void MavlinkPassthroughImpl::deinit()
×
29
{
30
    _system_impl->unregister_all_mavlink_message_handlers(this);
×
31
    _message_subscriptions.clear();
×
32
}
×
33

34
void MavlinkPassthroughImpl::enable() {}
×
35

36
void MavlinkPassthroughImpl::disable() {}
×
37

38
MavlinkPassthrough::Result MavlinkPassthroughImpl::send_message(mavlink_message_t& message)
×
39
{
40
    if (!_system_impl->send_message(message)) {
×
41
        return MavlinkPassthrough::Result::ConnectionError;
×
42
    }
43
    return MavlinkPassthrough::Result::Success;
×
44
}
45

46
MavlinkPassthrough::Result
47
MavlinkPassthroughImpl::send_command_long(const MavlinkPassthrough::CommandLong& command)
×
48
{
49
    MavlinkCommandSender::CommandLong command_internal{};
×
50
    command_internal.target_system_id = command.target_sysid;
×
51
    command_internal.target_component_id = command.target_compid;
×
52
    command_internal.command = command.command;
×
53
    command_internal.params.maybe_param1 = command.param1;
×
54
    command_internal.params.maybe_param2 = command.param2;
×
55
    command_internal.params.maybe_param3 = command.param3;
×
56
    command_internal.params.maybe_param4 = command.param4;
×
57
    command_internal.params.maybe_param5 = command.param5;
×
58
    command_internal.params.maybe_param6 = command.param6;
×
59
    command_internal.params.maybe_param7 = command.param7;
×
60

61
    return to_mavlink_passthrough_result_from_mavlink_commands_result(
×
62
        _system_impl->send_command(command_internal));
×
63
}
64

65
MavlinkPassthrough::Result
66
MavlinkPassthroughImpl::send_command_int(const MavlinkPassthrough::CommandInt& command)
×
67
{
68
    MavlinkCommandSender::CommandInt command_internal{};
×
69
    command_internal.target_system_id = command.target_sysid;
×
70
    command_internal.target_component_id = command.target_compid;
×
71
    command_internal.frame = command.frame;
×
72
    command_internal.command = command.command;
×
73
    command_internal.params.maybe_param1 = command.param1;
×
74
    command_internal.params.maybe_param2 = command.param2;
×
75
    command_internal.params.maybe_param3 = command.param3;
×
76
    command_internal.params.maybe_param4 = command.param4;
×
77
    command_internal.params.x = command.x;
×
78
    command_internal.params.y = command.y;
×
79
    command_internal.params.maybe_z = command.z;
×
80

81
    return to_mavlink_passthrough_result_from_mavlink_commands_result(
×
82
        _system_impl->send_command(command_internal));
×
83
}
84

85
mavlink_message_t MavlinkPassthroughImpl::make_command_ack_message(
×
86
    const uint8_t target_sysid,
87
    const uint8_t target_compid,
88
    const uint16_t command,
89
    MAV_RESULT result)
90
{
91
    /* copied over from system impl */
92
    const uint8_t progress = std::numeric_limits<uint8_t>::max();
×
93
    const uint8_t result_param2 = 0;
×
94

95
    mavlink_message_t msg{};
×
96
    mavlink_msg_command_ack_pack(
×
97
        get_our_sysid(),
×
98
        get_our_compid(),
×
99
        &msg,
100
        command,
101
        result,
102
        progress,
103
        result_param2,
104
        target_sysid,
105
        target_compid);
106
    return msg;
×
107
}
108

109
std::pair<MavlinkPassthrough::Result, int32_t> MavlinkPassthroughImpl::get_param_int(
×
110
    const std::string& name, std::optional<uint8_t> maybe_component_id, bool extended)
111
{
112
    auto result = _system_impl->get_param_int(name, maybe_component_id, extended);
×
113
    auto translated_result = to_mavlink_passthrough_result_from_mavlink_params_result(result.first);
×
114

115
    return std::make_pair(translated_result, result.second);
×
116
}
117

118
std::pair<MavlinkPassthrough::Result, float> MavlinkPassthroughImpl::get_param_float(
×
119
    const std::string& name, std::optional<uint8_t> maybe_component_id, bool extended)
120
{
121
    auto result = _system_impl->get_param_float(name, maybe_component_id, extended);
×
122
    auto translated_result = to_mavlink_passthrough_result_from_mavlink_params_result(result.first);
×
123

124
    return std::make_pair(translated_result, result.second);
×
125
}
126

127
MavlinkPassthrough::Result
128
MavlinkPassthroughImpl::to_mavlink_passthrough_result_from_mavlink_commands_result(
×
129
    MavlinkCommandSender::Result result)
130
{
131
    switch (result) {
×
132
        case MavlinkCommandSender::Result::Success:
×
133
            return MavlinkPassthrough::Result::Success;
×
134
        case MavlinkCommandSender::Result::NoSystem:
×
135
            return MavlinkPassthrough::Result::CommandNoSystem;
×
136
        case MavlinkCommandSender::Result::ConnectionError:
×
137
            return MavlinkPassthrough::Result::ConnectionError;
×
138
        case MavlinkCommandSender::Result::Busy:
×
139
            return MavlinkPassthrough::Result::CommandBusy;
×
140
        case MavlinkCommandSender::Result::Denied:
×
141
            return MavlinkPassthrough::Result::CommandDenied;
×
142
        case MavlinkCommandSender::Result::TemporarilyRejected:
×
143
            return MavlinkPassthrough::Result::CommandTemporarilyRejected;
×
144
        case MavlinkCommandSender::Result::Unsupported:
×
145
            return MavlinkPassthrough::Result::CommandUnsupported;
×
146
        case MavlinkCommandSender::Result::Failed:
×
147
            return MavlinkPassthrough::Result::CommandFailed;
×
148
        case MavlinkCommandSender::Result::Timeout:
×
149
            return MavlinkPassthrough::Result::CommandTimeout;
×
150
        default:
×
151
            // FALLTHROUGH
152
        case MavlinkCommandSender::Result::InProgress: // FIXME: currently not expected
153
                                                       // FALLTHROUGH
154
        case MavlinkCommandSender::Result::UnknownError:
155
            return MavlinkPassthrough::Result::Unknown;
×
156
    }
157
}
158

159
MavlinkPassthrough::Result
160
MavlinkPassthroughImpl::to_mavlink_passthrough_result_from_mavlink_params_result(
×
161
    MavlinkParameterSender::Result result)
162
{
163
    switch (result) {
×
164
        case MavlinkParameterSender::Result::Success:
×
165
            return MavlinkPassthrough::Result::Success;
×
166
        case MavlinkParameterSender::Result::Timeout:
×
167
            return MavlinkPassthrough::Result::CommandTimeout;
×
168
        case MavlinkParameterSender::Result::ConnectionError:
×
169
            return MavlinkPassthrough::Result::ConnectionError;
×
170
        case MavlinkParameterSender::Result::WrongType:
×
171
            return MavlinkPassthrough::Result::ParamWrongType;
×
172
        case MavlinkParameterSender::Result::ParamNameTooLong:
×
173
            return MavlinkPassthrough::Result::ParamNameTooLong;
×
174
        case MavlinkParameterSender::Result::ParamValueTooLong:
×
175
            return MavlinkPassthrough::Result::ParamValueTooLong;
×
176
        case MavlinkParameterSender::Result::NotFound:
×
177
            return MavlinkPassthrough::Result::ParamNotFound;
×
178
        case MavlinkParameterSender::Result::ValueUnsupported:
×
179
            return MavlinkPassthrough::Result::ParamValueUnsupported;
×
180
        case MavlinkParameterSender::Result::Failed:
×
181
            return MavlinkPassthrough::Result::CommandFailed;
×
182
        default:
×
183
            // FALLTHROUGH
184
        case MavlinkParameterSender::Result::UnknownError:
185
            return MavlinkPassthrough::Result::Unknown;
×
186
    }
187
}
188

189
MavlinkPassthrough::MessageHandle MavlinkPassthroughImpl::subscribe_message(
×
190
    uint16_t message_id, const MavlinkPassthrough::MessageCallback& callback)
191
{
192
    if (_message_subscriptions.find(message_id) == _message_subscriptions.end()) {
×
193
        _system_impl->register_mavlink_message_handler(
×
194
            message_id,
195
            [this](const mavlink_message_t& message) { receive_mavlink_message(message); },
×
196
            this);
197
    }
198

199
    return _message_subscriptions[message_id].subscribe(callback);
×
200
}
201

202
void MavlinkPassthroughImpl::unsubscribe_message(MavlinkPassthrough::MessageHandle handle)
×
203
{
204
    // We don't know which subscription holds the handle, so we have to go
205
    // through all of them.
206
    for (auto& subscription : _message_subscriptions) {
×
207
        subscription.second.unsubscribe(handle);
×
208
    }
209
}
×
210

211
void MavlinkPassthroughImpl::receive_mavlink_message(const mavlink_message_t& message)
×
212
{
213
    _message_subscriptions[message.msgid].queue(
×
214
        message, [this](const auto& func) { _system_impl->call_user_callback(func); });
×
215
}
×
216

217
uint8_t MavlinkPassthroughImpl::get_our_sysid() const
×
218
{
219
    return _system_impl->get_own_system_id();
×
220
}
221

222
uint8_t MavlinkPassthroughImpl::get_our_compid() const
×
223
{
224
    return _system_impl->get_own_component_id();
×
225
}
226

227
uint8_t MavlinkPassthroughImpl::get_target_sysid() const
×
228
{
229
    return _system_impl->get_system_id();
×
230
}
231

232
uint8_t MavlinkPassthroughImpl::get_target_compid() const
×
233
{
234
    return _system_impl->get_autopilot_id();
×
235
}
236

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