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

mavlink / MAVSDK / 19124558934

06 Nov 2025 04:13AM UTC coverage: 48.329% (+0.2%) from 48.156%
19124558934

push

github

web-flow
Merge pull request #2682 from mavlink/pr-raw-bytes

core: add raw connection

154 of 169 new or added lines in 6 files covered. (91.12%)

381 existing lines in 8 files now uncovered.

17643 of 36506 relevant lines covered (48.33%)

469.45 hits per line

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

80.65
/src/mavsdk/core/raw_connection.cpp
1
#include "raw_connection.h"
2
#include "mavsdk_impl.h"
3
#include "log.h"
4

5
namespace mavsdk {
6

7
RawConnection::RawConnection(
2✔
8
    ReceiverCallback receiver_callback,
9
    LibmavReceiverCallback libmav_receiver_callback,
10
    MavsdkImpl& mavsdk_impl,
11
    ForwardingOption forwarding_option) :
2✔
12
    Connection(receiver_callback, libmav_receiver_callback, mavsdk_impl, forwarding_option)
2✔
13
{}
2✔
14

15
RawConnection::~RawConnection() = default;
4✔
16

17
ConnectionResult RawConnection::start()
2✔
18
{
19
    if (!start_mavlink_receiver()) {
2✔
NEW
20
        return ConnectionResult::ConnectionError;
×
21
    }
22

23
    if (!start_libmav_receiver()) {
2✔
NEW
24
        return ConnectionResult::ConnectionError;
×
25
    }
26

27
    return ConnectionResult::Success;
2✔
28
}
29

NEW
30
ConnectionResult RawConnection::stop()
×
31
{
NEW
32
    stop_mavlink_receiver();
×
NEW
33
    stop_libmav_receiver();
×
NEW
34
    return ConnectionResult::Success;
×
35
}
36

37
std::pair<bool, std::string> RawConnection::send_message(const mavlink_message_t& message)
3✔
38
{
39
    // Convert message to raw bytes and use common send path
40
    uint8_t buffer[MAVLINK_MAX_PACKET_LEN];
41
    uint16_t buffer_len = mavlink_msg_to_send_buffer(buffer, &message);
3✔
42
    return send_raw_bytes(reinterpret_cast<const char*>(buffer), buffer_len);
3✔
43
}
44

45
std::pair<bool, std::string> RawConnection::send_raw_bytes(const char* bytes, size_t length)
3✔
46
{
47
    if (_mavsdk_impl.notify_raw_bytes_sent(bytes, length)) {
3✔
48
        return {true, ""};
1✔
49
    } else {
50
        return {false, "no raw_bytes sender"};
2✔
51
    }
52
}
53

54
void RawConnection::receive(const char* bytes, size_t length)
1✔
55
{
56
    // set_new_datagram expects char*, not const char*, so we need to cast
57
    // This is safe because the receivers only read from the buffer
58
    _mavlink_receiver->set_new_datagram(const_cast<char*>(bytes), static_cast<int>(length));
1✔
59

60
    // Parse all mavlink messages in one datagram. Once exhausted, we'll exit while.
61
    while (_mavlink_receiver->parse_message()) {
2✔
62
        // Handle parsed message
63
        receive_message(_mavlink_receiver->get_last_message(), this);
1✔
64
    }
65

66
    // Also parse with libmav if available
67
    if (_libmav_receiver) {
1✔
68
        _libmav_receiver->set_new_datagram(const_cast<char*>(bytes), static_cast<int>(length));
1✔
69

70
        while (_libmav_receiver->parse_message()) {
2✔
71
            receive_libmav_message(_libmav_receiver->get_last_message(), this);
1✔
72
        }
73
    }
74
}
1✔
75

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