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

mavlink / MAVSDK / 12364462666

17 Dec 2024 01:20AM UTC coverage: 43.583% (+4.9%) from 38.708%
12364462666

Pull #2386

github

web-flow
Merge 2e0e12179 into 5f2f56d25
Pull Request #2386: camera: support multiple cameras within one instance

1407 of 2127 new or added lines in 47 files covered. (66.15%)

48 existing lines in 8 files now uncovered.

13970 of 32054 relevant lines covered (43.58%)

289.29 hits per line

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

66.98
/src/mavsdk/plugins/param_server/param_server_impl.cpp
1
#include "param_server_impl.h"
2
#include "callback_list.tpp"
3

4
namespace mavsdk {
5

6
template class CallbackList<ParamServer::IntParam>;
7
template class CallbackList<ParamServer::FloatParam>;
8
template class CallbackList<ParamServer::CustomParam>;
9

10
ParamServerImpl::ParamServerImpl(std::shared_ptr<ServerComponent> server_component) :
8✔
11
    ServerPluginImplBase(server_component)
8✔
12
{
13
    // FIXME: this plugin should support various component IDs
14
    _server_component_impl->register_plugin(this);
8✔
15
}
8✔
16

17
ParamServerImpl::~ParamServerImpl()
16✔
18
{
19
    _server_component_impl->unregister_plugin(this);
8✔
20
}
16✔
21

22
void ParamServerImpl::init() {}
8✔
23

24
void ParamServerImpl::deinit()
8✔
25
{
26
    _server_component_impl->mavlink_parameter_server().unsubscribe_all_params_changed(this);
8✔
27
}
8✔
28

NEW
29
ParamServer::Result ParamServerImpl::set_protocol(bool extended_protocol)
×
30
{
NEW
31
    _server_component_impl->mavlink_parameter_server().set_extended_protocol(extended_protocol);
×
NEW
32
    return ParamServer::Result::Success;
×
33
}
34

35
std::pair<ParamServer::Result, int32_t> ParamServerImpl::retrieve_param_int(std::string name) const
2✔
36
{
37
    auto result =
2✔
38
        _server_component_impl->mavlink_parameter_server().retrieve_server_param_int(name);
2✔
39

40
    if (result.first == MavlinkParameterServer::Result::Ok) {
2✔
41
        return {ParamServer::Result::Success, result.second};
2✔
42
    } else {
43
        return {ParamServer::Result::NotFound, -1};
×
44
    }
45
}
46

47
ParamServer::Result ParamServerImpl::provide_param_int(std::string name, int32_t value)
49✔
48
{
49
    if (name.size() > 16) {
49✔
50
        return ParamServer::Result::ParamNameTooLong;
×
51
    }
52
    const auto ret =
53
        _server_component_impl->mavlink_parameter_server().provide_server_param_int(name, value);
49✔
54
    if (ret == MavlinkParameterServer::Result::Ok) {
49✔
55
        _server_component_impl->mavlink_parameter_server().subscribe_param_int_changed(
34✔
56
            name,
57
            [name, this](int32_t new_value) { _changed_param_int_callbacks({name, new_value}); },
20✔
58
            this);
59
    }
60
    return result_from_mavlink_parameter_server_result(ret);
49✔
61
}
62

63
std::pair<ParamServer::Result, float> ParamServerImpl::retrieve_param_float(std::string name) const
2✔
64
{
65
    const auto result =
2✔
66
        _server_component_impl->mavlink_parameter_server().retrieve_server_param_float(name);
2✔
67

68
    if (result.first == MavlinkParameterServer::Result::Ok) {
2✔
69
        return {ParamServer::Result::Success, result.second};
2✔
70
    } else {
71
        return {ParamServer::Result::NotFound, NAN};
×
72
    }
73
}
74

75
ParamServer::Result ParamServerImpl::provide_param_float(std::string name, float value)
8✔
76
{
77
    if (name.size() > 16) {
8✔
78
        return ParamServer::Result::ParamNameTooLong;
×
79
    }
80
    const auto ret =
81
        _server_component_impl->mavlink_parameter_server().provide_server_param_float(name, value);
8✔
82
    if (ret == MavlinkParameterServer::Result::Ok) {
8✔
83
        _server_component_impl->mavlink_parameter_server().subscribe_param_float_changed(
8✔
84
            name,
85
            [name, this](float new_value) { _changed_param_float_callbacks({name, new_value}); },
2✔
86
            this);
87
    }
88
    return result_from_mavlink_parameter_server_result(ret);
8✔
89
}
90

91
std::pair<ParamServer::Result, std::string>
92
ParamServerImpl::retrieve_param_custom(std::string name) const
2✔
93
{
94
    const auto result =
2✔
95
        _server_component_impl->mavlink_parameter_server().retrieve_server_param_custom(name);
2✔
96

97
    if (result.first == MavlinkParameterServer::Result::Ok) {
2✔
98
        return {ParamServer::Result::Success, result.second};
2✔
99
    } else {
100
        return {ParamServer::Result::NotFound, {}};
×
101
    }
102
}
2✔
103

104
ParamServer::Result
105
ParamServerImpl::provide_param_custom(std::string name, const std::string& value)
8✔
106
{
107
    if (name.size() > 16) {
8✔
108
        return ParamServer::Result::ParamNameTooLong;
×
109
    }
110

111
    const auto ret =
112
        _server_component_impl->mavlink_parameter_server().provide_server_param_custom(name, value);
8✔
113
    if (ret == MavlinkParameterServer::Result::Ok) {
8✔
114
        _server_component_impl->mavlink_parameter_server().subscribe_param_custom_changed(
8✔
115
            name,
116
            [name, this](const std::string& new_value) {
2✔
117
                _changed_param_custom_callbacks({name, new_value});
2✔
118
            },
2✔
119
            this);
120
    }
121
    return result_from_mavlink_parameter_server_result(ret);
8✔
122
}
123

124
ParamServer::AllParams ParamServerImpl::retrieve_all_params() const
2✔
125
{
126
    auto tmp = _server_component_impl->mavlink_parameter_server().retrieve_all_server_params();
2✔
127

128
    ParamServer::AllParams res{};
2✔
129

130
    for (auto const& param_pair : tmp) {
6✔
131
        if (param_pair.second.is<float>()) {
4✔
132
            ParamServer::FloatParam tmp_param;
2✔
133
            tmp_param.name = param_pair.first;
2✔
134
            tmp_param.value = param_pair.second.get<float>();
2✔
135
            res.float_params.push_back(tmp_param);
2✔
136
        } else if (param_pair.second.is<int32_t>()) {
4✔
137
            ParamServer::IntParam tmp_param;
2✔
138
            tmp_param.name = param_pair.first;
2✔
139
            tmp_param.value = param_pair.second.get<int32_t>();
2✔
140
            res.int_params.push_back(tmp_param);
2✔
141
        }
2✔
142
    }
143

144
    return res;
2✔
145
}
2✔
146

147
ParamServer::ChangedParamIntHandle
148
ParamServerImpl::subscribe_changed_param_int(const ParamServer::ChangedParamIntCallback& callback)
×
149
{
150
    return _changed_param_int_callbacks.subscribe(callback);
×
151
}
152

153
void ParamServerImpl::unsubscribe_changed_param_int(ParamServer::ChangedParamIntHandle handle)
×
154
{
155
    _changed_param_int_callbacks.unsubscribe(handle);
×
156
}
×
157

158
ParamServer::ChangedParamFloatHandle ParamServerImpl::subscribe_changed_param_float(
×
159
    const ParamServer::ChangedParamFloatCallback& callback)
160
{
161
    return _changed_param_float_callbacks.subscribe(callback);
×
162
}
163

164
void ParamServerImpl::unsubscribe_changed_param_float(ParamServer::ChangedParamFloatHandle handle)
×
165
{
166
    _changed_param_float_callbacks.unsubscribe(handle);
×
167
}
×
168

169
ParamServer::ChangedParamCustomHandle ParamServerImpl::subscribe_changed_param_custom(
×
170
    const ParamServer::ChangedParamCustomCallback& callback)
171
{
172
    return _changed_param_custom_callbacks.subscribe(callback);
×
173
}
174

175
void ParamServerImpl::unsubscribe_changed_param_custom(ParamServer::ChangedParamCustomHandle handle)
×
176
{
177
    _changed_param_custom_callbacks.unsubscribe(handle);
×
178
}
×
179

180
ParamServer::Result
181
ParamServerImpl::result_from_mavlink_parameter_server_result(MavlinkParameterServer::Result result)
65✔
182
{
183
    switch (result) {
65✔
184
        case MavlinkParameterServer::Result::Ok:
65✔
185
        case MavlinkParameterServer::Result::OkExistsAlready:
186
            return ParamServer::Result::Success;
65✔
187
        case MavlinkParameterServer::Result::NotFound:
×
188
            return ParamServer::Result::NotFound;
×
189
        case MavlinkParameterServer::Result::ParamNameTooLong:
×
190
            return ParamServer::Result::ParamNameTooLong;
×
191
        case MavlinkParameterServer::Result::WrongType:
×
192
            return ParamServer::Result::WrongType;
×
193
        case MavlinkParameterServer::Result::ParamValueTooLong:
×
194
            return ParamServer::Result::ParamValueTooLong;
×
195
        default:
×
196
            LogErr() << "Unknown param error";
×
197
            return ParamServer::Result::Unknown;
×
198
    }
199
}
200

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