Serialize Monitor_Pvt data with Protocol Buffers

This commit is contained in:
Carles Fernandez 2019-04-20 18:50:22 +02:00
parent 96ebeb922d
commit 347d212d6c
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
6 changed files with 210 additions and 9 deletions

View File

@ -0,0 +1,40 @@
syntax = "proto3";
package gnss_sdr;
message MonitorPvt {
uint32 tow_at_current_symbol_ms = 1;
uint32 week = 2;
double rx_time = 3;
double user_clk_offset = 4;
double pos_x = 5;
double pos_y = 6;
double pos_z = 7;
double vel_x = 8;
double vel_y = 9;
double vel_z = 10;
double cov_xx = 11;
double cov_yy = 12;
double cov_zz = 13;
double cov_xy = 14;
double cov_yz = 15;
double cov_zx = 16;
double latitude = 17;
double longitude = 18;
double height = 19;
uint32 valid_sats = 20;
uint32 solution_status = 21;
uint32 solution_type = 22;
float ar_ratio_factor = 23;
float ar_ratio_threshold = 24;
double gdop = 25;
double pdop = 26;
double hdop = 27;
double vdop = 28;
}

View File

@ -16,6 +16,7 @@
# along with GNSS-SDR. If not, see <https://www.gnu.org/licenses/>.
#
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${CMAKE_SOURCE_DIR}/docs/protobuf/monitor_pvt.proto)
set(PVT_LIB_SOURCES
pvt_solution.cc
@ -31,6 +32,7 @@ set(PVT_LIB_SOURCES
rtklib_solver.cc
pvt_conf.cc
monitor_pvt_udp_sink.cc
${PROTO_SRCS}
)
set(PVT_LIB_HEADERS
@ -48,6 +50,8 @@ set(PVT_LIB_HEADERS
pvt_conf.h
monitor_pvt_udp_sink.h
monitor_pvt.h
serdes_monitor_pvt.h
${PROTO_HDRS}
)
list(SORT PVT_LIB_HEADERS)
@ -61,6 +65,7 @@ target_link_libraries(pvt_libs
PUBLIC
Armadillo::armadillo
Boost::date_time
protobuf::libprotobuf
algorithms_libs_rtklib
core_system_parameters
PRIVATE
@ -72,9 +77,12 @@ target_link_libraries(pvt_libs
Matio::matio
)
get_filename_component(PROTO_INCLUDE_HEADERS ${PROTO_HDRS} DIRECTORY)
target_include_directories(pvt_libs
PUBLIC
${CMAKE_SOURCE_DIR}/src/core/receiver
${PROTO_INCLUDE_HEADERS}
)
target_compile_definitions(pvt_libs PRIVATE -DGNSS_SDR_VERSION="${VERSION}")

View File

@ -70,15 +70,25 @@ Monitor_Pvt_Udp_Sink::Monitor_Pvt_Udp_Sink(std::vector<std::string> addresses, c
monitor_pvt.pdop = 0.0;
monitor_pvt.hdop = 0.0;
monitor_pvt.vdop = 0.0;
serdes = Serdes_Monitor_Pvt();
}
bool Monitor_Pvt_Udp_Sink::write_monitor_pvt(const Monitor_Pvt& monitor_pvt)
bool Monitor_Pvt_Udp_Sink::write_monitor_pvt(const Monitor_Pvt& monitor_pvt, bool protobuf)
{
std::ostringstream archive_stream;
boost::archive::binary_oarchive oa{archive_stream};
oa << monitor_pvt;
std::string outbound_data = archive_stream.str();
std::string outbound_data;
if (protobuf == false)
{
std::ostringstream archive_stream;
boost::archive::binary_oarchive oa{archive_stream};
oa << monitor_pvt;
outbound_data = archive_stream.str();
}
else
{
outbound_data = serdes.createProtobuffer(monitor_pvt);
}
for (const auto& endpoint : endpoints)
{

View File

@ -33,13 +33,14 @@
#define GNSS_SDR_MONITOR_PVT_UDP_SINK_H_
#include "monitor_pvt.h"
#include "serdes_monitor_pvt.h"
#include <boost/asio.hpp>
class Monitor_Pvt_Udp_Sink
{
public:
Monitor_Pvt_Udp_Sink(std::vector<std::string> addresses, const uint16_t &port);
bool write_monitor_pvt(const Monitor_Pvt &monitor_pvt);
bool write_monitor_pvt(const Monitor_Pvt &monitor_pvt, bool protobuf = false);
private:
boost::asio::io_service io_service;
@ -47,6 +48,7 @@ private:
boost::system::error_code error;
std::vector<boost::asio::ip::udp::endpoint> endpoints;
Monitor_Pvt monitor_pvt;
Serdes_Monitor_Pvt serdes;
};

View File

@ -0,0 +1,138 @@
/*!
* \file serdes_monitor_pvt.h
* \brief Serialization / Deserialization of Monitor_Pvt objects using
* Protocol Buffers
* \author Carles Fernandez-Prades, 2019. cfernandez(at)cttc.es
*
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2019 (see AUTHORS file for a list of contributors)
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
*
* This file is part of GNSS-SDR.
*
* GNSS-SDR is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GNSS-SDR is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNSS-SDR. If not, see <https://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/
#ifndef GNSS_SDR_SERDES_MONITOR_PVT_H_
#define GNSS_SDR_SERDES_MONITOR_PVT_H_
#include "monitor_pvt.h"
#include "monitor_pvt.pb.h" // file created by Protocol Buffers at compile time
/*!
* \brief This class implements serialization and deserialization of
* Monitor_Pvt objects using Protocol Buffers.
*/
class Serdes_Monitor_Pvt
{
public:
Serdes_Monitor_Pvt()
{
// Verify that the version of the library that we linked against is
// compatible with the version of the headers we compiled against.
GOOGLE_PROTOBUF_VERIFY_VERSION;
monitor_.New();
}
~Serdes_Monitor_Pvt()
{
// google::protobuf::ShutdownProtobufLibrary();
}
inline std::string createProtobuffer(const Monitor_Pvt& monitor) //!< Serialization into a string
{
monitor_.Clear();
std::string data;
monitor_.set_tow_at_current_symbol_ms(monitor.TOW_at_current_symbol_ms);
monitor_.set_week(monitor.week);
monitor_.set_rx_time(monitor.RX_time);
monitor_.set_user_clk_offset(monitor.user_clk_offset);
monitor_.set_pos_x(monitor.pos_x);
monitor_.set_pos_y(monitor.pos_y);
monitor_.set_pos_z(monitor.pos_z);
monitor_.set_vel_x(monitor.vel_x);
monitor_.set_vel_y(monitor.vel_y);
monitor_.set_vel_z(monitor.vel_z);
monitor_.set_cov_xx(monitor.cov_xx);
monitor_.set_cov_yy(monitor.cov_yy);
monitor_.set_cov_zz(monitor.cov_zz);
monitor_.set_cov_xy(monitor.cov_xy);
monitor_.set_cov_yz(monitor.cov_yz);
monitor_.set_cov_yz(monitor.cov_yz);
monitor_.set_latitude(monitor.latitude);
monitor_.set_longitude(monitor.longitude);
monitor_.set_height(monitor.height);
monitor_.set_valid_sats(monitor.valid_sats);
monitor_.set_solution_status(monitor.solution_status);
monitor_.set_solution_type(monitor.solution_type);
monitor_.set_ar_ratio_factor(monitor.AR_ratio_factor);
monitor_.set_ar_ratio_threshold(monitor.AR_ratio_threshold);
monitor_.set_gdop(monitor.gdop);
monitor_.set_pdop(monitor.pdop);
monitor_.set_hdop(monitor.hdop);
monitor_.set_vdop(monitor.vdop);
monitor_.SerializeToString(&data);
return data;
}
inline Monitor_Pvt readProtobuffer(const gnss_sdr::MonitorPvt& mon) //!< Deserialization
{
Monitor_Pvt monitor;
monitor.TOW_at_current_symbol_ms = mon.tow_at_current_symbol_ms();
monitor.week = mon.week();
monitor.RX_time = mon.rx_time();
monitor.user_clk_offset = mon.user_clk_offset();
monitor.pos_x = mon.pos_x();
monitor.pos_y = mon.pos_y();
monitor.pos_z = mon.pos_z();
monitor.vel_x = mon.vel_x();
monitor.vel_y = mon.vel_y();
monitor.vel_z = mon.vel_z();
monitor.cov_xx = mon.cov_xx();
monitor.cov_yy = mon.cov_yy();
monitor.cov_zz = mon.cov_zz();
monitor.cov_xy = mon.cov_xy();
monitor.cov_yz = mon.cov_yz();
monitor.cov_zx = mon.cov_zx();
monitor.latitude = mon.latitude();
monitor.longitude = mon.longitude();
monitor.height = mon.height();
monitor.valid_sats = static_cast<uint8_t>(mon.valid_sats());
monitor.solution_status = static_cast<uint8_t>(mon.solution_status());
monitor.solution_type = static_cast<uint8_t>(mon.solution_type());
monitor.AR_ratio_factor = mon.ar_ratio_factor();
monitor.AR_ratio_threshold = mon.ar_ratio_threshold();
monitor.gdop = mon.gdop();
monitor.pdop = mon.pdop();
monitor.hdop = mon.hdop();
monitor.vdop = mon.vdop();
return monitor;
}
private:
gnss_sdr::MonitorPvt monitor_;
};
#endif // GNSS_SDR_SERDES_MONITOR_PVT_H_

View File

@ -50,6 +50,7 @@ public:
// Verify that the version of the library that we linked against is
// compatible with the version of the headers we compiled against.
GOOGLE_PROTOBUF_VERIFY_VERSION;
observables.New();
}
~Serdes_Gnss_Synchro()
{
@ -58,10 +59,10 @@ public:
inline std::string createProtobuffer(const std::vector<Gnss_Synchro>& vgs) //!< Serialization into a string
{
gnss_sdr::Observables observables;
observables.Clear();
std::string data;
for (int i = 0; i < vgs.size(); ++i)
for (uint32_t i = 0; i < vgs.size(); ++i)
{
gnss_sdr::GnssSynchro* obs = observables.add_observable();
Gnss_Synchro gs = vgs[i];
@ -115,7 +116,7 @@ public:
std::vector<Gnss_Synchro> vgs;
vgs.reserve(obs.observable_size());
for (int i = 0; i < obs.observable_size(); ++i)
for (uint32_t i = 0; i < obs.observable_size(); ++i)
{
const gnss_sdr::GnssSynchro& gs_read = obs.observable(i);
Gnss_Synchro gs = Gnss_Synchro();
@ -153,6 +154,8 @@ public:
}
return vgs;
}
private:
gnss_sdr::Observables observables;
};
#endif // GNSS_SDR_SERDES_GNSS_SYNCHRO_H_