Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rtk: encode RTCM data in base64 #2332

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion proto
Submodule proto updated 1 files
+1 −1 protos/rtk/rtk.proto
2 changes: 1 addition & 1 deletion src/mavsdk/plugins/rtk/include/plugins/rtk/rtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Rtk : public PluginBase {
* @brief RTCM data type
*/
struct RtcmData {
std::string data{}; /**< @brief The data encoded as a string */
std::string data_base64{}; /**< @brief The data encoded as a base64 string */
};

/**
Expand Down
4 changes: 2 additions & 2 deletions src/mavsdk/plugins/rtk/rtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ Rtk::Result Rtk::send_rtcm_data(RtcmData rtcm_data) const

bool operator==(const Rtk::RtcmData& lhs, const Rtk::RtcmData& rhs)
{
return (rhs.data == lhs.data);
return (rhs.data_base64 == lhs.data_base64);
}

std::ostream& operator<<(std::ostream& str, Rtk::RtcmData const& rtcm_data)
{
str << std::setprecision(15);
str << "rtcm_data:" << '\n' << "{\n";
str << " data: " << rtcm_data.data << '\n';
str << " data_base64: " << rtcm_data.data_base64 << '\n';
str << '}';
return str;
}
Expand Down
12 changes: 7 additions & 5 deletions src/mavsdk/plugins/rtk/rtk_impl.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "rtk_impl.h"
#include "unused.h"
#include "base64.h"

namespace mavsdk {

Expand Down Expand Up @@ -30,8 +30,10 @@ Rtk::Result RtkImpl::send_rtcm_data(Rtk::RtcmData rtcm_data)
{
constexpr size_t field_len = MAVLINK_MSG_GPS_RTCM_DATA_FIELD_DATA_LEN;

std::vector<uint8_t> decoded = base64_decode(rtcm_data.data_base64);

const size_t num_packets_required =
rtcm_data.data.size() / field_len + (rtcm_data.data.size() % field_len == 0 ? 0 : 1);
decoded.size() / field_len + (decoded.size() % field_len == 0 ? 0 : 1);

// The maximum is 4 times the 180 bytes because we only have two bits to
// denote the fragment ID.
Expand All @@ -40,11 +42,11 @@ Rtk::Result RtkImpl::send_rtcm_data(Rtk::RtcmData rtcm_data)
}

// Copy length before we change it.
size_t bytes_to_send = rtcm_data.data.size();
size_t bytes_to_send = decoded.size();

// The mavlink helpers memcpy, so we need to make sure we're not
// copying from where we shouldn't.
rtcm_data.data.resize(num_packets_required * field_len);
decoded.resize(num_packets_required * field_len);

for (size_t i = 0; i < num_packets_required; ++i) {
const uint8_t flags =
Expand All @@ -59,7 +61,7 @@ Rtk::Result RtkImpl::send_rtcm_data(Rtk::RtcmData rtcm_data)
&message,
flags,
static_cast<uint8_t>(std::min(field_len, bytes_to_send)),
reinterpret_cast<const uint8_t*>(rtcm_data.data.c_str() + (i * field_len)));
(decoded.data() + (i * field_len)));
return message;
})) {
++_sequence;
Expand Down
76 changes: 38 additions & 38 deletions src/mavsdk_server/src/generated/rtk/rtk.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 39 additions & 39 deletions src/mavsdk_server/src/generated/rtk/rtk.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading