Skip to content

Commit 5b96d93

Browse files
committed
rtk: encode RTCM data in base64
This makes it possible to use this in language wrappers such as Python.
1 parent 99ef45a commit 5b96d93

File tree

7 files changed

+90
-88
lines changed

7 files changed

+90
-88
lines changed

proto

src/mavsdk/plugins/rtk/include/plugins/rtk/rtk.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class Rtk : public PluginBase {
6262
* @brief RTCM data type
6363
*/
6464
struct RtcmData {
65-
std::string data{}; /**< @brief The data encoded as a string */
65+
std::string data_base64{}; /**< @brief The data encoded as a base64 string */
6666
};
6767

6868
/**

src/mavsdk/plugins/rtk/rtk.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ Rtk::Result Rtk::send_rtcm_data(RtcmData rtcm_data) const
2424

2525
bool operator==(const Rtk::RtcmData& lhs, const Rtk::RtcmData& rhs)
2626
{
27-
return (rhs.data == lhs.data);
27+
return (rhs.data_base64 == lhs.data_base64);
2828
}
2929

3030
std::ostream& operator<<(std::ostream& str, Rtk::RtcmData const& rtcm_data)
3131
{
3232
str << std::setprecision(15);
3333
str << "rtcm_data:" << '\n' << "{\n";
34-
str << " data: " << rtcm_data.data << '\n';
34+
str << " data_base64: " << rtcm_data.data_base64 << '\n';
3535
str << '}';
3636
return str;
3737
}

src/mavsdk/plugins/rtk/rtk_impl.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "rtk_impl.h"
2-
#include "unused.h"
2+
#include "base64.h"
33

44
namespace mavsdk {
55

@@ -30,8 +30,10 @@ Rtk::Result RtkImpl::send_rtcm_data(Rtk::RtcmData rtcm_data)
3030
{
3131
constexpr size_t field_len = MAVLINK_MSG_GPS_RTCM_DATA_FIELD_DATA_LEN;
3232

33+
std::vector<uint8_t> decoded = base64_decode(rtcm_data.data_base64);
34+
3335
const size_t num_packets_required =
34-
rtcm_data.data.size() / field_len + (rtcm_data.data.size() % field_len == 0 ? 0 : 1);
36+
decoded.size() / field_len + (decoded.size() % field_len == 0 ? 0 : 1);
3537

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

4244
// Copy length before we change it.
43-
size_t bytes_to_send = rtcm_data.data.size();
45+
size_t bytes_to_send = decoded.size();
4446

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

4951
for (size_t i = 0; i < num_packets_required; ++i) {
5052
const uint8_t flags =
@@ -59,7 +61,7 @@ Rtk::Result RtkImpl::send_rtcm_data(Rtk::RtcmData rtcm_data)
5961
&message,
6062
flags,
6163
static_cast<uint8_t>(std::min(field_len, bytes_to_send)),
62-
reinterpret_cast<const uint8_t*>(rtcm_data.data.c_str() + (i * field_len)));
64+
(decoded.data() + (i * field_len)));
6365
return message;
6466
})) {
6567
++_sequence;

src/mavsdk_server/src/generated/rtk/rtk.pb.cc

+38-38
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/mavsdk_server/src/generated/rtk/rtk.pb.h

+39-39
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)