mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2025-01-17 20:53:02 +00:00
fixing binary format in RTCM messages
This commit is contained in:
parent
ad16c5ab35
commit
ed8d647935
@ -183,7 +183,7 @@ bool Rtcm::check_CRC(const std::string & message) const
|
|||||||
std::string Rtcm::bin_to_binary_data(const std::string& s) const
|
std::string Rtcm::bin_to_binary_data(const std::string& s) const
|
||||||
{
|
{
|
||||||
std::string s_aux;
|
std::string s_aux;
|
||||||
int remainder = static_cast<int>(std::fmod(s.length(), 4));
|
int remainder = static_cast<int>(std::fmod(s.length(), 8));
|
||||||
unsigned char c[s.length()];
|
unsigned char c[s.length()];
|
||||||
unsigned int k = 0;
|
unsigned int k = 0;
|
||||||
if (remainder != 0)
|
if (remainder != 0)
|
||||||
@ -191,17 +191,20 @@ std::string Rtcm::bin_to_binary_data(const std::string& s) const
|
|||||||
s_aux.assign(s, 0 , remainder);
|
s_aux.assign(s, 0 , remainder);
|
||||||
boost::dynamic_bitset<> rembits(s_aux);
|
boost::dynamic_bitset<> rembits(s_aux);
|
||||||
unsigned long int n = rembits.to_ulong();
|
unsigned long int n = rembits.to_ulong();
|
||||||
c[0] = (unsigned char)n;
|
c[0] = static_cast<unsigned char>(n);
|
||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int start = std::max(remainder, 0);
|
unsigned int start = std::max(remainder, 0);
|
||||||
for(unsigned int i = start; i < s.length() - 1; i = i + 4)
|
for(unsigned int i = start; i < s.length() - 1; i = i + 8)
|
||||||
{
|
{
|
||||||
s_aux.assign(s, i, 4);
|
s_aux.assign(s, i, 4);
|
||||||
std::bitset<4> bs(s_aux);
|
std::bitset<4> bs(s_aux);
|
||||||
unsigned n = bs.to_ulong();
|
unsigned n = bs.to_ulong();
|
||||||
c[k] = (unsigned char)n;
|
s_aux.assign(s, i + 4 , 4);
|
||||||
|
std::bitset<4> bs2(s_aux);
|
||||||
|
unsigned n2 = bs2.to_ulong();
|
||||||
|
c[k] = static_cast<unsigned char>(n * 16) + static_cast<unsigned char>(n2);
|
||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,7 +221,7 @@ std::string Rtcm::binary_data_to_bin(const std::string& s) const
|
|||||||
for(unsigned int i = 0; i < s.length(); i++)
|
for(unsigned int i = 0; i < s.length(); i++)
|
||||||
{
|
{
|
||||||
unsigned char val = static_cast<unsigned char>(s.at(i));
|
unsigned char val = static_cast<unsigned char>(s.at(i));
|
||||||
std::bitset<4> bs(val);
|
std::bitset<8> bs(val);
|
||||||
ss << bs;
|
ss << bs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,13 +158,13 @@ TEST(Rtcm_Test, Bin_to_int)
|
|||||||
TEST(Rtcm_Test, Bin_to_binary_data)
|
TEST(Rtcm_Test, Bin_to_binary_data)
|
||||||
{
|
{
|
||||||
auto rtcm = std::make_shared<Rtcm>();
|
auto rtcm = std::make_shared<Rtcm>();
|
||||||
std::string bin_str("11011010");
|
std::string bin_str("1101101011010110");
|
||||||
std::string data_str = rtcm->bin_to_binary_data(bin_str);
|
std::string data_str = rtcm->bin_to_binary_data(bin_str);
|
||||||
|
|
||||||
std::string test_binary = data_str.substr(0,1);
|
std::string test_binary = data_str.substr(0,1);
|
||||||
std::string test_bin = rtcm->binary_data_to_bin(test_binary);
|
std::string test_bin = rtcm->binary_data_to_bin(test_binary);
|
||||||
std::string test_hex = rtcm->bin_to_hex(test_bin);
|
std::string test_hex = rtcm->bin_to_hex(test_bin);
|
||||||
EXPECT_EQ(0, test_hex.compare("D"));
|
EXPECT_EQ(0, test_hex.compare("DA"));
|
||||||
|
|
||||||
std::string recovered_str = rtcm->binary_data_to_bin(data_str);
|
std::string recovered_str = rtcm->binary_data_to_bin(data_str);
|
||||||
EXPECT_EQ(0, recovered_str.compare(bin_str));
|
EXPECT_EQ(0, recovered_str.compare(bin_str));
|
||||||
@ -283,12 +283,12 @@ TEST(Rtcm_Test, MT1029)
|
|||||||
unsigned int ref_id = 23;
|
unsigned int ref_id = 23;
|
||||||
double obs_time = 0;
|
double obs_time = 0;
|
||||||
Gps_Ephemeris gps_eph = Gps_Ephemeris();
|
Gps_Ephemeris gps_eph = Gps_Ephemeris();
|
||||||
std::string m1029 = rtcm->print_MT1029(ref_id, gps_eph, obs_time, s_test);
|
std::string m1029 = rtcm->bin_to_hex(rtcm->binary_data_to_bin(rtcm->print_MT1029(ref_id, gps_eph, obs_time, s_test)));
|
||||||
std::string encoded_text = m1029.substr(24, 60);
|
std::string encoded_text = m1029.substr(24, 60);
|
||||||
std::string expected_encoded_text(rtcm->bin_to_binary_data(rtcm->hex_to_bin("5554462D3820D0BFD180D0BED0B2D0B5D180D0BAD0B02077C3B672746572")));
|
std::string expected_encoded_text("5554462D3820D0BFD180D0BED0B2D0B5D180D0BAD0B02077C3B672746572");
|
||||||
EXPECT_EQ(0, expected_encoded_text.compare(encoded_text));
|
EXPECT_EQ(0, expected_encoded_text.compare(encoded_text));
|
||||||
|
|
||||||
std::string characters_to_follow = rtcm->bin_to_hex(rtcm->binary_data_to_bin(m1029.substr(22, 2)));
|
std::string characters_to_follow = m1029.substr(22, 2);
|
||||||
std::string expected_characters_to_follow("1E");
|
std::string expected_characters_to_follow("1E");
|
||||||
EXPECT_EQ(0, expected_characters_to_follow.compare(characters_to_follow));
|
EXPECT_EQ(0, expected_characters_to_follow.compare(characters_to_follow));
|
||||||
}
|
}
|
||||||
|
@ -77,11 +77,12 @@ TEST(Rtcm_Printer_Test, Run)
|
|||||||
/* Convert the reference message to binary data */
|
/* Convert the reference message to binary data */
|
||||||
std::string reference_msg_binary;
|
std::string reference_msg_binary;
|
||||||
unsigned char c[1];
|
unsigned char c[1];
|
||||||
for(unsigned int i = 0; i < reference_msg.length(); i++)
|
for(unsigned int i = 0; i < reference_msg.length(); i = i + 2)
|
||||||
{
|
{
|
||||||
unsigned long int n;
|
unsigned long int n, n2;
|
||||||
std::istringstream(reference_msg.substr(i,1)) >> std::hex >> n;
|
std::istringstream(reference_msg.substr(i,1)) >> std::hex >> n;
|
||||||
c[0] = (unsigned char)n;
|
std::istringstream(reference_msg.substr(i + 1, 1)) >> std::hex >> n2;
|
||||||
|
c[0] = static_cast<unsigned char>(n * 16) + static_cast<unsigned char>(n2);
|
||||||
std::string ret(c, c+1);
|
std::string ret(c, c+1);
|
||||||
reference_msg_binary += ret;
|
reference_msg_binary += ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user