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

mavlink / MAVSDK / 11452150858

22 Oct 2024 02:32AM CUT coverage: 37.403% (+0.02%) from 37.381%
11452150858

push

github

web-flow
camera_server: prevent double ack+message (#2430)

It turns out we were sending the ack and message for storage information
as well as capture status twice, once directly in the request handler
callback, and once the MAVSDK user would call the respond function.

We should only call it in the respond function, not in the callback.

11105 of 29690 relevant lines covered (37.4%)

255.6 hits per line

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

0.0
/src/mavsdk/plugins/arm_authorizer_server/arm_authorizer_server_impl.cpp
1
#include "arm_authorizer_server_impl.h"
2

3
#include <utility>
4
#include "log.h"
5

6
namespace mavsdk {
7

8
ArmAuthorizerServerImpl::ArmAuthorizerServerImpl(
×
9
    std::shared_ptr<ServerComponent> server_component) :
×
10
    ServerPluginImplBase(std::move(server_component))
×
11
{
12
    _server_component_impl->register_plugin(this);
×
13
}
×
14

15
ArmAuthorizerServerImpl::~ArmAuthorizerServerImpl()
×
16
{
17
    _server_component_impl->unregister_plugin(this);
×
18
}
×
19

20
void ArmAuthorizerServerImpl::init()
×
21
{
22
    _server_component_impl->register_mavlink_command_handler(
×
23
        MAV_CMD_ARM_AUTHORIZATION_REQUEST,
24
        [this](const MavlinkCommandReceiver::CommandLong& command) {
×
25
            return process_arm_authorization_request(command);
×
26
        },
27
        this);
28
}
×
29

30
void ArmAuthorizerServerImpl::deinit() {}
×
31

32
ArmAuthorizerServer::ArmAuthorizationHandle ArmAuthorizerServerImpl::subscribe_arm_authorization(
×
33
    const ArmAuthorizerServer::ArmAuthorizationCallback& callback)
34
{
35
    return _arm_authorization_callbacks.subscribe(callback);
×
36
}
37

38
void ArmAuthorizerServerImpl::unsubscribe_arm_authorization(
×
39
    ArmAuthorizerServer::ArmAuthorizationHandle handle)
40
{
41
    _arm_authorization_callbacks.unsubscribe(handle);
×
42
}
×
43

44
std::optional<mavlink_command_ack_t> ArmAuthorizerServerImpl::process_arm_authorization_request(
×
45
    const MavlinkCommandReceiver::CommandLong& command)
46
{
47
    if (_arm_authorization_callbacks.empty()) {
×
48
        LogDebug() << "Set mode requested with no user callback";
×
49
        return _server_component_impl->make_command_ack_message(
×
50
            command, MAV_RESULT::MAV_RESULT_UNSUPPORTED);
×
51
    }
52
    auto const system_id = static_cast<uint32_t>(command.params.param1);
×
53

54
    _last_arm_authorization_request_command = command;
×
55
    _arm_authorization_callbacks(system_id);
×
56

57
    return std::nullopt;
×
58
}
59

60
ArmAuthorizerServer::Result
61
ArmAuthorizerServerImpl::accept_arm_authorization(int32_t valid_time_s) const
×
62
{
63
    auto command_ack = _server_component_impl->make_command_ack_message(
×
64
        _last_arm_authorization_request_command, MAV_RESULT_ACCEPTED);
×
65

66
    // If the arm is authorized, param2 is set to the time in seconds through which the
67
    // authorization is valid
68
    command_ack.result_param2 = valid_time_s;
×
69

70
    if (!_server_component_impl->send_command_ack(command_ack)) {
×
71
        return ArmAuthorizerServer::Result::Failed;
×
72
    }
73
    return ArmAuthorizerServer::Result::Success;
×
74
}
75

76
ArmAuthorizerServer::Result ArmAuthorizerServerImpl::reject_arm_authorization(
×
77
    bool temporarily, ArmAuthorizerServer::RejectionReason reason, int32_t extra_info) const
78
{
79
    MAV_RESULT result = temporarily ? MAV_RESULT_TEMPORARILY_REJECTED : MAV_RESULT_DENIED;
×
80
    auto command_ack = _server_component_impl->make_command_ack_message(
×
81
        _last_arm_authorization_request_command, result);
×
82

83
    // Fill in progress, which is the reason for arm rejected or 0 if arm was allowed
84
    switch (reason) {
×
85
        case ArmAuthorizerServer::RejectionReason::Generic:
×
86
            command_ack.progress = static_cast<uint8_t>(MAV_ARM_AUTH_DENIED_REASON_GENERIC);
×
87
            break;
×
88
        case ArmAuthorizerServer::RejectionReason::Timeout:
×
89
            command_ack.progress = static_cast<uint8_t>(MAV_ARM_AUTH_DENIED_REASON_TIMEOUT);
×
90
            break;
×
91
        case ArmAuthorizerServer::RejectionReason::BadWeather:
×
92
            command_ack.progress = static_cast<uint8_t>(MAV_ARM_AUTH_DENIED_REASON_BAD_WEATHER);
×
93
            break;
×
94
        case ArmAuthorizerServer::RejectionReason::InvalidWaypoint:
×
95
            command_ack.progress =
×
96
                static_cast<uint8_t>(MAV_ARM_AUTH_DENIED_REASON_INVALID_WAYPOINT);
97
            break;
×
98
        case ArmAuthorizerServer::RejectionReason::AirspaceInUse:
×
99
            command_ack.progress = static_cast<uint8_t>(MAV_ARM_AUTH_DENIED_REASON_AIRSPACE_IN_USE);
×
100
            break;
×
101
        case ArmAuthorizerServer::RejectionReason::None:
×
102
            [[fallthrough]];
103
        default:
104
            command_ack.progress = static_cast<uint8_t>(MAV_ARM_AUTH_DENIED_REASON_NONE);
×
105
            break;
×
106
    }
107

108
    // Fill in the extra information. It is dependent on the decision, and and reason
109
    command_ack.result_param2 = extra_info;
×
110

111
    if (!_server_component_impl->send_command_ack(command_ack)) {
×
112
        return ArmAuthorizerServer::Result::Failed;
×
113
    }
114

115
    return ArmAuthorizerServer::Result::Success;
×
116
}
117

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