Skip to content

Commit

Permalink
rtk: encode RTCM data in base64
Browse files Browse the repository at this point in the history
This makes it possible to use this in language wrappers such as Python.
  • Loading branch information
julianoes committed Jun 4, 2024
1 parent 99ef45a commit 5b96d93
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 88 deletions.
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

0 comments on commit 5b96d93

Please sign in to comment.