1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-06-25 06:23:18 +00:00

More work on the Rtcm class

Added message type 1029, added automatic sending of messages when
printing, removing unnecessary reset of data fields, reordering of
tests, new tests added, the TCP server shuts down in the class
destructor if running
This commit is contained in:
Carles Fernandez 2015-12-23 22:18:43 +01:00
parent dd22536c9b
commit ad228cb500
3 changed files with 257 additions and 168 deletions

View File

@ -37,6 +37,7 @@
#include <thread>
#include <boost/algorithm/string.hpp> // for to_upper_copy
#include <boost/crc.hpp>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/dynamic_bitset.hpp>
#include <gflags/gflags.h>
#include <glog/logging.h>
@ -51,11 +52,9 @@ DEFINE_int32(RTCM_Port, 2101 , "TCP port of the RTCM message server");
Rtcm::Rtcm()
{
Rtcm::reset_data_fields();
preamble = std::bitset<8>("11010011");
reserved_field = std::bitset<6>("000000");
rtcm_message_queue = std::make_shared< concurrent_queue<std::string> >();
// for each server, do:
boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), FLAGS_RTCM_Port);
servers.emplace_back(io_service, endpoint);
server_is_running = false;
@ -63,7 +62,12 @@ Rtcm::Rtcm()
Rtcm::~Rtcm()
{}
{
if(server_is_running)
{
stop_server();
}
}
@ -424,7 +428,12 @@ std::string Rtcm::print_MT1001(const Gps_Ephemeris & gps_eph, double obs_time, c
data += content.to_string();
}
return Rtcm::build_message(data);
std::string msg = build_message(data);
if(server_is_running)
{
rtcm_message_queue->push(msg);
}
return msg;
}
@ -469,7 +478,12 @@ std::string Rtcm::print_MT1002(const Gps_Ephemeris & gps_eph, double obs_time, c
data += content.to_string();
}
return Rtcm::build_message(data);
std::string msg = build_message(data);
if(server_is_running)
{
rtcm_message_queue->push(msg);
}
return msg;
}
@ -568,7 +582,12 @@ std::string Rtcm::print_MT1003(const Gps_Ephemeris & ephL1, const Gps_CNAV_Ephem
data += content.to_string();
}
return Rtcm::build_message(data);
std::string msg = build_message(data);
if(server_is_running)
{
rtcm_message_queue->push(msg);
}
return msg;
}
@ -673,7 +692,12 @@ std::string Rtcm::print_MT1004(const Gps_Ephemeris & ephL1, const Gps_CNAV_Ephem
data += content.to_string();
}
return Rtcm::build_message(data);
std::string msg = build_message(data);
if(server_is_running)
{
rtcm_message_queue->push(msg);
}
return msg;
}
@ -804,8 +828,12 @@ std::string Rtcm::print_MT1005( unsigned int ref_id, double ecef_x, double ecef_
DF364.to_string() +
DF027.to_string() ;
std::string message = build_message(data);
return message;
std::string msg = build_message(data);
if(server_is_running)
{
rtcm_message_queue->push(msg);
}
return msg;
}
@ -888,7 +916,7 @@ std::string Rtcm::print_MT1005_test()
//
// ********************************************************
std::string Rtcm::print_MT1006( unsigned int ref_id, double ecef_x, double ecef_y, double ecef_z, bool gps, bool glonass, bool galileo, bool non_physical, bool single_oscillator, unsigned int quarter_cycle_indicator, double height)
std::string Rtcm::print_MT1006(unsigned int ref_id, double ecef_x, double ecef_y, double ecef_z, bool gps, bool glonass, bool galileo, bool non_physical, bool single_oscillator, unsigned int quarter_cycle_indicator, double height)
{
unsigned int msg_number = 1006;
std::bitset<1> DF001_;
@ -923,8 +951,12 @@ std::string Rtcm::print_MT1006( unsigned int ref_id, double ecef_x, double ecef_
DF027.to_string() +
DF028.to_string();
std::string message = build_message(data);
return message;
std::string msg = build_message(data);
if(server_is_running)
{
rtcm_message_queue->push(msg);
}
return msg;
}
@ -982,8 +1014,12 @@ std::string Rtcm::print_MT1008(unsigned int ref_id, const std::string & antenna_
DF032.to_string() +
DF033_str_;
std::string message = build_message(data);
return message;
std::string msg = build_message(data);
if(server_is_running)
{
rtcm_message_queue->push(msg);
}
return msg;
}
@ -1068,8 +1104,12 @@ std::string Rtcm::print_MT1019(const Gps_Ephemeris & gps_eph)
LOG(WARNING) << "Bad-formatted RTCM MT1019 (488 bits expected, found " << data.length() << ")";
}
std::string message = build_message(data);
return message;
std::string msg = build_message(data);
if(server_is_running)
{
rtcm_message_queue->push(msg);
}
return msg;
}
@ -1202,6 +1242,72 @@ int Rtcm::read_MT1019(const std::string & message, Gps_Ephemeris & gps_eph)
}
// ********************************************************
//
// MESSAGE TYPE 1029 (UNICODE TEXT STRING)
//
// ********************************************************
std::string Rtcm::print_MT1029(unsigned int ref_id, const Gps_Ephemeris & gps_eph, double obs_time, const std::string & message)
{
unsigned int msg_number = 1029;
Rtcm::set_DF002(msg_number);
Rtcm::set_DF003(ref_id);
Rtcm::set_DF051(gps_eph, obs_time);
Rtcm::set_DF052(gps_eph, obs_time);
unsigned int i = 0;
bool first = true;
std::string text_binary;
for(auto it = message.begin(); it != message.end(); it++)
{
char c = *it;
if(isgraph(c))
{
i++;
first = true;
}
else if(c == ' ')
{
i++;
first = true;
}
else
{
if(!first)
{
i++;
first = true;
}
else
{
first = false;
}
}
std::bitset<8> character = std::bitset<8>(c);
text_binary += character.to_string();
}
std::bitset<7> DF138_ = std::bitset<7>(i);
std::bitset<8> DF139_ = std::bitset<8>(message.length());
std::string data = DF002.to_string() +
DF003.to_string() +
DF051.to_string() +
DF052.to_string() +
DF138_.to_string() +
DF139_.to_string() +
text_binary;
std::string msg = build_message(data);
if(server_is_running)
{
rtcm_message_queue->push(msg);
}
return msg;
}
// ********************************************************
//
@ -1280,8 +1386,12 @@ std::string Rtcm::print_MT1045(const Galileo_Ephemeris & gal_eph)
LOG(WARNING) << "Bad-formatted RTCM MT1045 (496 bits expected, found " << data.length() << ")";
}
std::string message = build_message(data);
return message;
std::string msg = build_message(data);
if(server_is_running)
{
rtcm_message_queue->push(msg);
}
return msg;
}
@ -1455,6 +1565,12 @@ std::string Rtcm::print_MSM_1( const Gps_Ephemeris & gps_eph,
std::string signal_data = Rtcm::get_MSM_1_content_signal_data(pseudoranges);
std::string message = build_message(header + sat_data + signal_data);
if(server_is_running)
{
rtcm_message_queue->push(message);
}
return message;
}
@ -1636,6 +1752,11 @@ std::string Rtcm::print_MSM_2( const Gps_Ephemeris & gps_eph,
std::string signal_data = Rtcm::get_MSM_2_content_signal_data(gps_eph, gps_cnav_eph, gal_eph, obs_time, pseudoranges);
std::string message = build_message(header + sat_data + signal_data);
if(server_is_running)
{
rtcm_message_queue->push(message);
}
return message;
}
@ -1728,6 +1849,11 @@ std::string Rtcm::print_MSM_3( const Gps_Ephemeris & gps_eph,
std::string signal_data = Rtcm::get_MSM_3_content_signal_data(gps_eph, gps_cnav_eph, gal_eph, obs_time, pseudoranges);
std::string message = build_message(header + sat_data + signal_data);
if(server_is_running)
{
rtcm_message_queue->push(message);
}
return message;
}
@ -1822,6 +1948,11 @@ std::string Rtcm::print_MSM_4( const Gps_Ephemeris & gps_eph,
std::string signal_data = Rtcm::get_MSM_4_content_signal_data(gps_eph, gps_cnav_eph, gal_eph, obs_time, pseudoranges);
std::string message = build_message(header + sat_data + signal_data);
if(server_is_running)
{
rtcm_message_queue->push(message);
}
return message;
}
@ -1959,6 +2090,11 @@ std::string Rtcm::print_MSM_5( const Gps_Ephemeris & gps_eph,
std::string signal_data = Rtcm::get_MSM_5_content_signal_data(gps_eph, gps_cnav_eph, gal_eph, obs_time, pseudoranges);
std::string message = build_message(header + sat_data + signal_data);
if(server_is_running)
{
rtcm_message_queue->push(message);
}
return message;
}
@ -2106,6 +2242,11 @@ std::string Rtcm::print_MSM_6( const Gps_Ephemeris & gps_eph,
std::string signal_data = Rtcm::get_MSM_6_content_signal_data(gps_eph, gps_cnav_eph, gal_eph, obs_time, pseudoranges);
std::string message = build_message(header + sat_data + signal_data);
if(server_is_running)
{
rtcm_message_queue->push(message);
}
return message;
}
@ -2204,6 +2345,11 @@ std::string Rtcm::print_MSM_7( const Gps_Ephemeris & gps_eph,
std::string signal_data = Rtcm::get_MSM_7_content_signal_data(gps_eph, gps_cnav_eph, gal_eph, obs_time, pseudoranges);
std::string message = build_message(header + sat_data + signal_data);
if(server_is_running)
{
rtcm_message_queue->push(message);
}
return message;
}
@ -2562,120 +2708,6 @@ unsigned int Rtcm::msm_extended_lock_time_indicator(unsigned int lock_time_perio
//
// *****************************************************************************************************
int Rtcm::reset_data_fields()
{
//DF001.reset();
DF002.reset();
DF003.reset();
DF004.reset();
DF005.reset();
DF006.reset();
DF007.reset();
DF008.reset();
DF009.reset();
DF010.reset();
DF011.reset();
DF012.reset();
DF013.reset();
DF014.reset();
DF015.reset();
DF017.reset();
DF018.reset();
DF019.reset();
DF020.reset();
// Contents of GPS Satellite Ephemeris Data, Message Type 1019
DF071.reset();
DF076.reset();
DF077.reset();
DF078.reset();
DF079.reset();
DF081.reset();
DF082.reset();
DF083.reset();
DF084.reset();
DF085.reset();
DF086.reset();
DF087.reset();
DF088.reset();
DF089.reset();
DF090.reset();
DF091.reset();
DF092.reset();
DF093.reset();
DF094.reset();
DF095.reset();
DF096.reset();
DF097.reset();
DF098.reset();
DF099.reset();
DF100.reset();
DF101.reset();
DF102.reset();
DF103.reset();
DF137.reset();
DF248.reset();
// Contents of Galileo F/NAV Satellite Ephemeris Data, Message Type 1045
DF252.reset();
DF289.reset();
DF290.reset();
DF291.reset();
DF292.reset();
DF293.reset();
DF294.reset();
DF295.reset();
DF296.reset();
DF297.reset();
DF298.reset();
DF299.reset();
DF300.reset();
DF301.reset();
DF302.reset();
DF303.reset();
DF304.reset();
DF305.reset();
DF306.reset();
DF307.reset();
DF308.reset();
DF309.reset();
DF310.reset();
DF311.reset();
DF312.reset();
DF314.reset();
DF315.reset();
DF364.reset();
DF393.reset();
DF394.reset();
DF395.reset();
DF397.reset();
DF398.reset();
DF399.reset();
DF400.reset();
DF401.reset();
DF402.reset();
DF403.reset();
DF404.reset();
DF405.reset();
DF406.reset();
DF407.reset();
DF408.reset();
DF409.reset();
DF411.reset();
DF412.reset();
DF417.reset();
DF418.reset();
DF420.reset();
return 0;
}
int Rtcm::set_DF002(unsigned int message_number)
{
if (message_number > 4095)
@ -2984,6 +3016,37 @@ int Rtcm::set_DF031(unsigned int antenna_setup_id)
return 0;
}
int Rtcm::set_DF051(const Gps_Ephemeris & gps_eph, double obs_time)
{
const double gps_t = obs_time;
boost::posix_time::time_duration t = boost::posix_time::millisec((gps_t + 604800 * static_cast<double>(gps_eph.i_GPS_week % 1024)) * 1000);
boost::posix_time::ptime p_time(boost::gregorian::date(1999, 8, 22), t);
std::string now_ptime = to_iso_string(p_time);
std::string today_ptime = now_ptime.substr(0, 8);
boost::gregorian::date d(boost::gregorian::from_undelimited_string(today_ptime));
unsigned int mjd = d.modjulian_day();
DF051 = std::bitset<16>(mjd);
return 0;
}
int Rtcm::set_DF052(const Gps_Ephemeris & gps_eph, double obs_time)
{
const double gps_t = obs_time;
boost::posix_time::time_duration t = boost::posix_time::millisec((gps_t + 604800 * static_cast<double>(gps_eph.i_GPS_week % 1024)) * 1000);
boost::posix_time::ptime p_time(boost::gregorian::date(1999, 8, 22), t);
std::string now_ptime = to_iso_string(p_time);
std::string hours = now_ptime.substr(9, 2);
std::string minutes = now_ptime.substr(11, 2);
std::string seconds = now_ptime.substr(13, 8);
//boost::gregorian::date d(boost::gregorian::from_undelimited_string(today_ptime));
long unsigned int seconds_of_day = boost::lexical_cast<unsigned int>(hours) * 60 * 60 + boost::lexical_cast<unsigned int>(minutes) * 60 + boost::lexical_cast<unsigned int>(seconds);
DF052 = std::bitset<17>(seconds_of_day);
return 0;
}
int Rtcm::set_DF071(const Gps_Ephemeris & gps_eph)
{
unsigned int iode = static_cast<unsigned int>(gps_eph.d_IODE_SF2);

View File

@ -56,7 +56,7 @@
* defined in the RTCM 3.2 Standard, plus some utilities to handle messages.
*
* Generation of the following Message Types:
* 1001, 1002, 1003, 1004, 1005, 1006, 1008, 1019, 1045
* 1001, 1002, 1003, 1004, 1005, 1006, 1008, 1019, 1029, 1045
*
* Decoding of the following Message Types:
* 1019, 1045
@ -139,6 +139,11 @@ public:
*/
int read_MT1019(const std::string & message, Gps_Ephemeris & gps_eph);
/*!
* \brief Prints message type 1029 (Unicode Text String)
*/
std::string print_MT1029(unsigned int ref_id, const Gps_Ephemeris & gps_eph, double obs_time, const std::string & message);
/*!
* \brief Prints message type 1045 (Galileo Ephemeris), should be broadcast every 2 minutes
*/
@ -769,8 +774,6 @@ private:
//
// Data Fields
//
int reset_data_fields();
std::bitset<12> DF002;
int set_DF002(unsigned int message_number);
@ -858,6 +861,12 @@ private:
std::bitset<8> DF032;
std::bitset<16> DF051;
int set_DF051(const Gps_Ephemeris & gps_eph, double obs_time);
std::bitset<17> DF052;
int set_DF052(const Gps_Ephemeris & gps_eph, double obs_time);
// Contents of GPS Satellite Ephemeris Data, Message Type 1019
std::bitset<8> DF071;
int set_DF071(const Gps_Ephemeris & gps_eph);

View File

@ -165,7 +165,28 @@ TEST(Rtcm_Test, Check_CRC)
}
TEST(Rtcm_Test, Test_MT1005)
TEST(Rtcm_Test, MT1001)
{
auto rtcm = std::make_shared<Rtcm>();
Gps_Ephemeris gps_eph = Gps_Ephemeris();
Gnss_Synchro gnss_synchro;
gnss_synchro.PRN = 2;
std::string sys = "G";
std::string sig = "1C";
gnss_synchro.System = *sys.c_str();
std::memcpy((void*)gnss_synchro.Signal, sig.c_str(), 3);
gnss_synchro.Pseudorange_m = 20000000.0;
double obs_time = 25.0;
std::map<int, Gnss_Synchro> pseudoranges;
pseudoranges.insert(std::pair<int, Gnss_Synchro>(1, gnss_synchro));
std::string MT1001 = rtcm->print_MT1001(gps_eph, obs_time, pseudoranges);
EXPECT_EQ(true, rtcm->check_CRC(MT1001));
}
TEST(Rtcm_Test, MT1005)
{
auto rtcm = std::make_shared<Rtcm>();
std::string reference_msg = rtcm->print_MT1005_test();
@ -205,7 +226,7 @@ TEST(Rtcm_Test, Test_MT1005)
TEST(Rtcm_Test, Test_MT1019)
TEST(Rtcm_Test, MT1019)
{
auto rtcm = std::make_shared<Rtcm>();
@ -227,8 +248,25 @@ TEST(Rtcm_Test, Test_MT1019)
}
TEST(Rtcm_Test, MT1029)
{
auto rtcm = std::make_shared<Rtcm>();
std::string s_test("UTF-8 проверка wörter");
unsigned int ref_id = 23;
double obs_time = 0;
Gps_Ephemeris gps_eph = Gps_Ephemeris();
std::string m1029 = rtcm->print_MT1029(ref_id, gps_eph, obs_time, s_test);
std::string encoded_text = m1029.substr(24, 60);
std::string expected_encoded_text("5554462D3820D0BFD180D0BED0B2D0B5D180D0BAD0B02077C3B672746572");
EXPECT_EQ(0, expected_encoded_text.compare(encoded_text));
TEST(Rtcm_Test, Test_MT1045)
std::string characters_to_follow = m1029.substr(22, 2);
std::string expected_characters_to_follow("1E");
EXPECT_EQ(0, expected_characters_to_follow.compare(characters_to_follow));
}
TEST(Rtcm_Test, MT1045)
{
auto rtcm = std::make_shared<Rtcm>();
@ -249,27 +287,6 @@ TEST(Rtcm_Test, Test_MT1045)
}
TEST(Rtcm_Test, MT1001)
{
auto rtcm = std::make_shared<Rtcm>();
Gps_Ephemeris gps_eph = Gps_Ephemeris();
Gnss_Synchro gnss_synchro;
gnss_synchro.PRN = 2;
std::string sys = "G";
std::string sig = "1C";
gnss_synchro.System = *sys.c_str();
std::memcpy((void*)gnss_synchro.Signal, sig.c_str(), 3);
gnss_synchro.Pseudorange_m = 20000000.0;
double obs_time = 25.0;
std::map<int, Gnss_Synchro> pseudoranges;
pseudoranges.insert(std::pair<int, Gnss_Synchro>(1, gnss_synchro));
std::string MT1001 = rtcm->print_MT1001(gps_eph, obs_time, pseudoranges);
EXPECT_EQ(true, rtcm->check_CRC(MT1001));
}
TEST(Rtcm_Test, MSMCell)
{
auto rtcm = std::make_shared<Rtcm>();
@ -498,7 +515,6 @@ TEST(Rtcm_Test, MSM1)
int read_psrng4_s = rtcm->bin_to_int( MSM1_bin.substr(size_header + size_msg_length + 169 + (Nsat * Nsig) + 30 + 15 * 3, 15));
EXPECT_EQ(psrng4_s, read_psrng4_s);
std::map<int, Gnss_Synchro> pseudoranges2;
pseudoranges2.insert(std::pair<int, Gnss_Synchro>(1, gnss_synchro4));
pseudoranges2.insert(std::pair<int, Gnss_Synchro>(2, gnss_synchro3));
@ -516,7 +532,7 @@ TEST(Rtcm_Test, MSM1)
divergence_free,
more_messages);
std::string MSM1_bin2 = rtcm->hex_to_bin(MSM1_2);
int read_psrng4_s_2 = rtcm->bin_to_int( MSM1_bin2.substr(size_header + size_msg_length + 169 + (Nsat * Nsig) + 30 + 15 * 3, 15));
int read_psrng4_s_2 = rtcm->bin_to_int( MSM1_bin2.substr(size_header + size_msg_length + 169 + (Nsat * Nsig) + 30 + 15 * 3, 15));
EXPECT_EQ(psrng4_s, read_psrng4_s_2);
}
@ -544,17 +560,18 @@ TEST(Rtcm_Test, InstantiateServer)
EXPECT_EQ(0, test4_bin.compare("11111111"));
}
/*
TEST(Rtcm_Test, InstantiateClient)
TEST(Rtcm_Test, InstantiateServerWithoutClosing)
{
auto rtcm = std::make_shared<Rtcm>();
rtcm->run_client();
rtcm->run_server();
std::string msg("Hello");
rtcm->send_message(msg);
std::string test3 = "ff";
std::string test3_bin = rtcm->hex_to_bin(test3);
EXPECT_EQ(0, test3_bin.compare("11111111"));
rtcm->stop_client();
std::string test3_bin2 = rtcm->hex_to_bin(test3);
EXPECT_EQ(0, test3_bin2.compare("11111111"));
} */
}