Skip to content

Commit

Permalink
added CRC check and also added the LDPC decoder. It does not do error…
Browse files Browse the repository at this point in the history
… correction
  • Loading branch information
aerokiwi committed Jul 26, 2018
1 parent 337fdb1 commit fcee003
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 45 deletions.
1 change: 1 addition & 0 deletions src/algorithms/PVT/libs/rinex_printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "gps_cnav_navigation_message.h"
#include "galileo_navigation_message.h"
#include "glonass_gnav_navigation_message.h"
#include "beidou_cnav2_navigation_message.h"
#include "GPS_L1_CA.h"
#include "Galileo_E1.h"
#include "GLONASS_L1_L2_CA.h"
Expand Down
2 changes: 1 addition & 1 deletion src/algorithms/PVT/libs/rtklib_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class rtklib_solver : public Pvt_Solution
std::map<int, Galileo_Ephemeris> galileo_ephemeris_map; //!< Map storing new Galileo_Ephemeris
std::map<int, Gps_Ephemeris> gps_ephemeris_map; //!< Map storing new GPS_Ephemeris
std::map<int, Gps_CNAV_Ephemeris> gps_cnav_ephemeris_map; //!< Map storing new GPS_CNAV_Ephemeris
std::map<int, Glonass_Gnav_Ephemeris> glonass_gnav_ephemeris_map; //!< Map storing new BEIDOU_CNAV2_Ephemeris
std::map<int, Glonass_Gnav_Ephemeris> glonass_gnav_ephemeris_map; //!< Map storing new GLONASS_GNAV_Ephemeris
std::map<int, Beidou_Cnav2_Ephemeris> beidou_cnav2_ephemeris_map; //!< Map storing new BEIDOU_CNAV2_Ephemeris

Galileo_Utc_Model galileo_utc_model;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include <boost/lexical_cast.hpp>
#include <gnuradio/io_signature.h>
#include <glog/logging.h>

//#include <memory>

#define CRC_ERROR_LIMIT 8

Expand Down Expand Up @@ -132,7 +132,22 @@ void beidou_b2a_telemetry_decoder_cc::decode_string(double *frame_symbols, int f
// 1. Transform from symbols to bits
std::string data_bits;

data_bits = frame_symbols[1:288];
// we want data_bits = frame_symbols[24:311]
assert(frame_length >= 24+288); // or whatever error checking mechanism exists in this cb
for (unsigned ii = 24; ii < (24+288); ++ii) {
char bit_value;

if (frame_symbols[ii] > 0)
bit_value = '1';
else
bit_value = '0';

data_bits.push_back(bit_value);

// "ternary" operator
//data_bits.push_back( (frame_symbols[ii] > 0) ? ('1') : ('0') );
}


// 2. Call the BEIDOU CNAV2 string decoder
d_nav.string_decoder(data_bits);
Expand Down
4 changes: 2 additions & 2 deletions src/algorithms/telemetry_decoder/libs/crc24q.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static void crc_init(unsigned table[256])
table[i + j] = table[j] ^ h;
}
}

/*
int main(int argc, char *argv[])
{
int i;
Expand All @@ -83,7 +83,7 @@ int main(int argc, char *argv[])
exit(0);
}
#endif

*/
static const unsigned crc24q[256] = {
0x00000000, 0x01864CFB, 0x028AD50D, 0x030C99F6,
0x0493E6E1, 0x0515AA1A, 0x061933EC, 0x079F7F17,
Expand Down
2 changes: 1 addition & 1 deletion src/core/system_parameters/beidou_cnav2_almanac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ Beidou_Cnav2_Almanac::Beidou_Cnav2_Almanac()

delta_A = 0.0; //!< Correction of semi-major axis relative to reference value at reference time
Phi_0 = 0.0; //!< Argument of latitude at reference time
Health = 0.0; //!< Satellite health information
//Health = 0.0; //!< Satellite health information
}
4 changes: 0 additions & 4 deletions src/core/system_parameters/beidou_cnav2_almanac.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,8 @@ class Beidou_Cnav2_Almanac

// Reduced Almanac Parameters

unsigned int PRN_a; //!< PRN number of the corresponding almanac data
double SatType; //!< Satellite orbit type
double delta_A; //!< Correction of semi-major axis relative to reference value at reference time
double Omega_0; //!< Longitude of ascending node of orbital plane at weekly epoch
double Phi_0; //!< Argument of latitude at reference time
double Health; //!< Satellite health information

template <class Archive>
/*!
Expand Down
48 changes: 23 additions & 25 deletions src/core/system_parameters/beidou_cnav2_navigation_message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "beidou_cnav2_navigation_message.h"
#include "gnss_satellite.h"
#include <glog/logging.h>
#include "crc24q.c"
#include "crc24q.h"

void Beidou_Cnav2_Navigation_Message::reset()
{
Expand Down Expand Up @@ -90,10 +90,12 @@ Beidou_Cnav2_Navigation_Message::Beidou_Cnav2_Navigation_Message()
}


bool Beidou_Cnav2_Navigation_Message::read_navigation_bool(std::bitset<BEIDOU_CNAV2_STRING_BITS> bits, const std::vector<std::pair<int, int>> parameter)
bool Beidou_Cnav2_Navigation_Message::read_navigation_bool(std::bitset<BEIDOU_CNAV2_STRING_BITS> const &bits, const std::vector<std::pair<int, int>> &parameter)
{
bool value;

// bitset::any() (bits.any())

if (bits[BEIDOU_CNAV2_STRING_BITS - parameter[0].first] == 1)
{
value = true;
Expand All @@ -106,7 +108,7 @@ bool Beidou_Cnav2_Navigation_Message::read_navigation_bool(std::bitset<BEIDOU_CN
}


unsigned long int Beidou_Cnav2_Navigation_Message::read_navigation_unsigned(std::bitset<BEIDOU_CNAV2_STRING_BITS> bits, const std::vector<std::pair<int, int>> parameter)
unsigned long int Beidou_Cnav2_Navigation_Message::read_navigation_unsigned(std::bitset<BEIDOU_CNAV2_STRING_BITS> const &bits, const std::vector<std::pair<int, int>> &parameter)
{
unsigned long int value = 0;
int num_of_slices = parameter.size();
Expand All @@ -117,15 +119,15 @@ unsigned long int Beidou_Cnav2_Navigation_Message::read_navigation_unsigned(std:
value <<= 1; //shift left
if (bits[BEIDOU_CNAV2_STRING_BITS - parameter[i].first - j] == 1)
{
value += 1; // insert the bit
value |= 1; // insert the bit
}
}
}
return value;
}


signed long int Beidou_Cnav2_Navigation_Message::read_navigation_signed(std::bitset<BEIDOU_CNAV2_STRING_BITS> bits, const std::vector<std::pair<int, int>> parameter)
signed long int Beidou_Cnav2_Navigation_Message::read_navigation_signed(std::bitset<BEIDOU_CNAV2_STRING_BITS> const &bits, const std::vector<std::pair<int, int>> &parameter)
{
signed long int value = 0;
signed long int sign = 0;
Expand All @@ -146,52 +148,48 @@ signed long int Beidou_Cnav2_Navigation_Message::read_navigation_signed(std::bit
value <<= 1; //shift left
if (bits[BEIDOU_CNAV2_STRING_BITS - parameter[i].first - j] == 1)
{
value += 1; // insert the bit
value |= 1; // insert the bit
}
}
}
return (sign * value);
}


bool Beidou_Cnav2_Navigation_Message::CRC_test(std::bitset<BEIDOU_CNAV2_STRING_BITS> string_bits)
bool Beidou_Cnav2_Navigation_Message::CRC_test(std::bitset<BEIDOU_CNAV2_STRING_BITS> const &string_bits)
{
crc_compute = crc24q_check(string_bits({1,264});
std::vector<unsigned char> rawBits(0, string_bits.size() / 8);

if (crc_compute == static_cast<double>(read_navigation_unsigned(string_bits, CRC)))
{
return true;
}
else
// All other conditions are assumed errors.
{
return false;
}
return true;
for (unsigned i = 0; i < rawBits.size(); ++i) {
for (int j = 0; j < 8; ++j) {
rawBits[i] |= (string_bits[8*i + j] << (7 - j));
}
}

crc_compute = crc24q_check(rawBits.data(), rawBits.size());

return crc_compute;
}


int Beidou_Cnav2_Navigation_Message::string_decoder(std::string frame_string)
int Beidou_Cnav2_Navigation_Message::string_decoder(std::string const &frame_string)
{
int J = 0;
d_string_ID = 0;
d_frame_ID = 0;

// Unpack bytes to bits
std::bitset<BEIDOU_CNAV2_STRING_BITS> string_bits(frame_string);


d_string_ID = static_cast<unsigned int>(read_navigation_unsigned(string_bits, MesType));

// Perform data verification and exit code if error in bit sequence
flag_CRC_test = CRC_test(string_bits);


if (flag_CRC_test == false)
return 0;

i_string_MesType = static_cast<unsigned int>(read_navigation_unsigned(string_bits, MesType));

// Decode all 8 string messages
switch (d_string_ID)
switch (i_string_MesType)
{
case 10:
//--- It is Type 10 -----------------------------------------------
Expand Down
13 changes: 6 additions & 7 deletions src/core/system_parameters/beidou_cnav2_navigation_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,13 @@
class Beidou_Cnav2_Navigation_Message
{
private:
unsigned long int read_navigation_unsigned(std::bitset<BEIDOU_CNAV2_STRING_BITS> bits, const std::vector<std::pair<int, int>> parameter);
signed long int read_navigation_signed(std::bitset<BEIDOU_CNAV2_STRING_BITS> bits, const std::vector<std::pair<int, int>> parameter);
bool read_navigation_bool(std::bitset<BEIDOU_CNAV2_STRING_BITS> bits, const std::vector<std::pair<int, int>> parameter);
unsigned long int read_navigation_unsigned(std::bitset<BEIDOU_CNAV2_STRING_BITS> const &bits, const std::vector<std::pair<int, int>> &parameter);
signed long int read_navigation_signed(std::bitset<BEIDOU_CNAV2_STRING_BITS> const &bits, const std::vector<std::pair<int, int>> &parameter);
bool read_navigation_bool(std::bitset<BEIDOU_CNAV2_STRING_BITS> const &bits, const std::vector<std::pair<int, int>> &parameter);

public:
bool flag_CRC_test;
unsigned int d_frame_ID;
unsigned int d_string_ID;
unsigned int i_string_MesType;
bool flag_update_slot_number;

int i_channel_ID;
Expand Down Expand Up @@ -110,7 +109,7 @@ class Beidou_Cnav2_Navigation_Message
* \brief Compute CRC for BEIDOU CNAV2 strings
* \param bits Bits of the string message where to compute CRC
*/
bool CRC_test(std::bitset<BEIDOU_CNAV2_STRING_BITS> bits);
bool CRC_test(std::bitset<BEIDOU_CNAV2_STRING_BITS> const &bits);

/*!
* \brief Computes the frame number being decoded given the satellite slot number
Expand Down Expand Up @@ -161,7 +160,7 @@ class Beidou_Cnav2_Navigation_Message
* \param frame_string [in] is the string message within the parsed frame
* \returns Returns the ID of the decoded string
*/
int string_decoder(std::string frame_string);
int string_decoder(std::string const &frame_string);

/*!
* Default constructor
Expand Down
8 changes: 5 additions & 3 deletions src/core/system_parameters/beidou_cnav2_utc_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,12 @@ boost::posix_time::ptime Beidou_Cnav2_Utc_Model::beidt_to_utc(const double offse
*/
}

template < typename t >
t square(t x) { return x * x; }

void Beidou_Cnav2_Utc_Model::beidt_to_gpst(double tod_offset, double beidt2utc_corr, double beidt2gpst_corr, double* wn, double* tow) const
{
/*
* dT_systems = t_BD - t_GNSS = A_0BGTO + A_1BGTO*[t_BD - t_0BGTO + 604800*(WN - WN_BGTO)] + A_2BGTO*[t_BD - t_0BGTO +604800*(WN - WN_BGTO)]^2
*/

dT_systems = t_BD - t_GNSS = A_0BGTO + A_1BGTO*[t_BD - t_0BGTO + 604800*(WN - WN_BGTO)] + A_2BGTO*square(t_BD - t_0BGTO +604800*(WN - WN_BGTO))

}

0 comments on commit fcee003

Please sign in to comment.