Skip to content

Commit

Permalink
fixed all bugs so that the system would build. Added cmake as well. T…
Browse files Browse the repository at this point in the history
…he system seems to be building now
  • Loading branch information
aerokiwi committed Jul 31, 2018
1 parent fcee003 commit 7d91792
Show file tree
Hide file tree
Showing 12 changed files with 489 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ set(TELEMETRY_DECODER_GR_BLOCKS_SOURCES
galileo_e5a_telemetry_decoder_cc.cc
glonass_l1_ca_telemetry_decoder_cc.cc
glonass_l2_ca_telemetry_decoder_cc.cc
beidou_b2a_telemetry_decoder_cc.cc
)

include_directories(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ void beidou_b2a_telemetry_decoder_cc::decode_string(double *frame_symbols, int f
if (d_nav.flag_update_slot_number == true)
{
LOG(INFO) << "BEIDOU CNAV2 Slot Number Identified in channel " << d_channel;
d_satellite.update_PRN(d_nav.cnav2_ephemeris.d_n);
d_satellite.what_block(d_satellite.get_system(), d_nav.cnav2_ephemeris.d_n);
d_satellite.update_PRN(d_nav.cnav2_ephemeris.SatType);
d_satellite.what_block(d_satellite.get_system(), d_nav.cnav2_ephemeris.SatType);
d_nav.flag_update_slot_number = false;
}
}
Expand Down Expand Up @@ -361,7 +361,7 @@ int beidou_b2a_telemetry_decoder_cc::general_work(int noutput_items __attribute_
if (this->d_flag_preamble == true and d_nav.flag_TOW_new == true)
//update TOW at the preamble instant
{
d_TOW_at_current_symbol = floor((d_nav.cnav2_ephemeris.d_TOW - BEIDOU_CNAV2_PREAMBLE_DURATION_S) * 1000) / 1000;
d_TOW_at_current_symbol = floor((d_nav.cnav2_ephemeris.SOW - BEIDOU_CNAV2_PREAMBLE_DURATION_S) * 1000) / 1000;
d_nav.flag_TOW_new = false;
}
else //if there is not a new preamble, we define the TOW of the current symbol
Expand Down
1 change: 1 addition & 0 deletions src/algorithms/telemetry_decoder/libs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ add_subdirectory(libswiftcnav)
set(TELEMETRY_DECODER_LIB_SOURCES
gps_l1_ca_subframe_fsm.cc
viterbi_decoder.cc
crc24q.c
)

include_directories(
Expand Down
2 changes: 1 addition & 1 deletion src/algorithms/telemetry_decoder/libs/crc24q.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

#include "crc24q.h"

#ifdef REBUILD_CRC_TABLE
//#ifdef REBUILD_CRC_TABLE
/*
* The crc24q code table below can be regenerated with the following code:
*/
Expand Down
4 changes: 2 additions & 2 deletions src/core/system_parameters/BEIDOU_B2a.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ const double BEIDOU_LEAP_SECONDS = -33; // uniform scale and 33 seconds behind T
// NAVIGATION MESSAGE DEMODULATION AND DECODING
#define BEIDOU_CNAV2_PREAMBLE \
{ \
1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0 \
}

const double BEIDOU_CNAV2_PREAMBLE_DURATION_S = 0.120; //[s]
const int BEIDOU_CNAV2_PREAMBLE_LENGTH_BITS = 12; //[bits]
const int BEIDOU_CNAV2_PREAMBLE_LENGTH_SYMBOLS = 24; //[symbols]

//const int BEIDOU_CNAV2_PREAMBLE_PERIOD_SYMBOLS = 2000;
const int BEIDOU_CNAV2_PREAMBLE_PERIOD_SYMBOLS = 600;
const int BEIDOU_CNAV2_TELEMETRY_RATE_BITS_SECOND = 100; //bps
const int BEIDOU_CNAV2_TELEMETRY_SYMBOLS_PER_BIT = 2; //spb
const int BEIDOU_CNAV2_TELEMETRY_SYMBOLS_PER_PREAMBLE_BIT = 2; //spb
Expand Down
12 changes: 8 additions & 4 deletions src/core/system_parameters/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ set(SYSTEM_PARAMETERS_SOURCES
gps_cnav_iono.cc
gps_cnav_utc_model.cc
rtcm.cc
glonass_gnav_ephemeris.cc
glonass_gnav_almanac.cc
glonass_gnav_utc_model.cc
glonass_gnav_navigation_message.cc
glonass_gnav_ephemeris.cc
glonass_gnav_almanac.cc
glonass_gnav_utc_model.cc
glonass_gnav_navigation_message.cc
beidou_cnav2_navigation_message.cc
beidou_cnav2_ephemeris.cc
beidou_cnav2_almanac.cc
beidou_cnav2_utc_model.cc
)


Expand Down
15 changes: 8 additions & 7 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.h"
#include "../../algorithms/telemetry_decoder/libs/crc24q.h"

void Beidou_Cnav2_Navigation_Message::reset()
{
Expand Down Expand Up @@ -63,8 +63,7 @@ void Beidou_Cnav2_Navigation_Message::reset()
flag_TOW_new = false;

flag_CRC_test = false;
d_frame_ID = 0;
d_string_ID = 0;
i_string_MesType = 0;
i_channel_ID = 0;

// Clock terms
Expand Down Expand Up @@ -174,8 +173,6 @@ bool Beidou_Cnav2_Navigation_Message::CRC_test(std::bitset<BEIDOU_CNAV2_STRING_B

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

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

Expand Down Expand Up @@ -221,6 +218,8 @@ int Beidou_Cnav2_Navigation_Message::string_decoder(std::string const &frame_str

flag_ephemeris_str_10 = true;

//cnav2_utc_model.beidt_to_utc(cnav2_ephemeris, 0, 1142341);

break;

case 11:
Expand Down Expand Up @@ -550,13 +549,13 @@ int Beidou_Cnav2_Navigation_Message::string_decoder(std::string const &frame_str


default:
LOG(INFO) << "BEIDOU CNAV2: Invalid String ID of received. Received " << d_string_ID
LOG(INFO) << "BEIDOU CNAV2: Invalid String ID of received. Received " << i_string_MesType
<< ", but acceptable range is from 10 11 30 31 32 33 34 40";

break;
} // switch string ID

return d_string_ID;
return i_string_MesType;
}


Expand Down Expand Up @@ -642,4 +641,6 @@ bool Beidou_Cnav2_Navigation_Message::have_new_almanac() //Check if we have a n
}
}

// todo fix
return false;
}
43 changes: 26 additions & 17 deletions src/core/system_parameters/beidou_cnav2_utc_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
*/

#include "beidou_cnav2_utc_model.h"
#include <cmath>

Beidou_Cnav2_Utc_Model::Beidou_Cnav2_Utc_Model()
{
Expand Down Expand Up @@ -67,35 +68,43 @@ double Beidou_Cnav2_Utc_Model::utc_time(double beidou_time)
{
double t_utc;

// BEIDOU Time is relative to UTC Moscow, so we simply add its time difference
t_utc = beidou_time + dt_LS; // Adds the leap seconds that is broadcasted

return t_utc;
}

boost::posix_time::ptime Beidou_Cnav2_Utc_Model::beidt_to_utc(const double offset_time, const double beidt2utc_corr) const
double Beidou_Cnav2_Utc_Model::beidt_to_utc(Beidou_Cnav2_Ephemeris const&eph)
{
/*
* 1) DN is not in the past
* t_UTC = (t_E - dt_UTC)mod86400
* dt_UTC = dt_LS + A_0UTC + A_1UTC * (t_E - t_ot + 604800 * (WN - WN_ot)) + A_2UTC * (t_E - t_ot + 604800 * (WN - WN_ot))^2
*
* 2) user's present time falls within the time span which starts six hours prior to the leap second time and ends six hours after the leap second time
* t_UTC = W mod(86400 + dt_LSF - dt_LS)
* W = ((t_E - dt_UTC - 43200) mod86400) + 43200
*
* 3) DN is in the past
* t_UTC = (t_E - dt_UTC)mod86400
* dt_UTC = dt_LSF + A_0UTC + A_1UTC * (t_E - t_ot + 604800 * (WN - WN_ot)) + A_2UTC * (t_E - t_ot + 604800 * (WN - WN_ot))^2
*/
double t_UTC;
double dt_UTC;
double W;

// 1) DN is not in the past
dt_UTC = dt_LS + A_0UTC + A_1UTC * (eph.t_oe - t_ot + 604800 * (eph.WN - WN_ot)) + A_2UTC * (eph.t_oe - t_ot + 604800 * (eph.WN - WN_ot)) * (eph.t_oe - t_ot + 604800 * (eph.WN - WN_ot));
t_UTC = fmod((eph.t_oe - dt_UTC),86400);

// 2) user's present time falls within the time span which starts six hours prior to the leap second time and ends six hours after the leap second time
W = fmod((eph.t_oe - dt_UTC - 43200),86400) + 43200;
t_UTC = fmod(W,(86400 + dt_LSF - dt_LS));

// 3) DN is in the past
dt_UTC = dt_LSF + A_0UTC + A_1UTC * (eph.t_oe - t_ot + 604800 * (eph.WN - WN_ot)) + A_2UTC * (eph.t_oe - t_ot + 604800 * (eph.WN - WN_ot)) * (eph.t_oe - t_ot + 604800 * (eph.WN - WN_ot));
t_UTC = fmod((eph.t_oe - dt_UTC),86400);

return t_UTC;
}

/*
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
double Beidou_Cnav2_Utc_Model::beidt_to_gpst(Beidou_Cnav2_Ephemeris const&eph, double beidou_time)
{
double t_GNSS;

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))
//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));
t_GNSS = beidou_time - (A_0BGTO + A_1BGTO*(beidou_time - t_0BGTO + 604800*(eph.WN - WN_0BGTO)) + A_2BGTO*(beidou_time - t_0BGTO +604800*(eph.WN - WN_0BGTO)))*(beidou_time - t_0BGTO +604800*(eph.WN - WN_0BGTO));

return t_GNSS;
}
37 changes: 14 additions & 23 deletions src/core/system_parameters/beidou_cnav2_utc_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#include <boost/assign.hpp>
#include <boost/serialization/nvp.hpp>
#include "beidou_cnav2_ephemeris.h"

//!!! Check
/*!
Expand Down Expand Up @@ -112,26 +113,19 @@ class Beidou_Cnav2_Utc_Model
archive& make_nvp("a_2", a_2);
}

/*!
* \brief Sets (\a d_satClkDrift)and returns the clock drift in seconds according to the User Algorithm for SV Clock Correction
* (IS-GPS-200E, 20.3.3.3.3.1)
*/
double sv_clock_drift(double transmitTime, double timeCorrUTC);

/*!
* \brief Computes the BEIDOU System Time and returns a boost::posix_time::ptime object
* \ param offset_time Is the start of day offset to compute the time
*/
boost::posix_time::ptime compute_BEIDOU_time(const double offset_time) const;
double beidt_to_gpst(const double offset_time, const double glot2utc_corr);

/*!
* \brief Converts from BEIDOUT to UTC
* \details The function simply adjust for the 6 hrs offset between BEIDOUT and UTC
* \param[in] offset_time Is the start of day offset
* \brief Converts from BEIDOUT to GPST
* \details Converts from BEIDOUT to GPST in time of week (TOW) and week number (WN) format
* \param[in] tod_offset Is the start of day offset
* \param[in] beidt2utc_corr Correction from BEIDOUT to UTC
* \returns UTC time as a boost::posix_time::ptime object
* \param[in] beidt2gpst_corr Correction from BEIDOUT to GPST
* \param[out] WN Week Number, not in mod(1024) format
* \param[out] TOW Time of Week in seconds of week
*/
boost::posix_time::ptime beidt_to_utc(const double offset_time, const double glot2utc_corr) const;
double beidt_to_utc(Beidou_Cnav2_Ephemeris const&eph);


/*!
* \brief Converts from BEIDOUT to GPST
Expand All @@ -142,24 +136,21 @@ class Beidou_Cnav2_Utc_Model
* \param[out] WN Week Number, not in mod(1024) format
* \param[out] TOW Time of Week in seconds of week
*/
void beidt_to_gpst(double tod_offset, double beidt2utc_corr, double beidt2gpst_corr, double* WN, double* TOW) const;

double beidt_to_gpst(const Beidou_Cnav2_Ephemeris &eph, double beid_time);

/*!
* Default constructor
*/


double utc_time(double beidou_time);

/*!
* Default constructor
*/

Beidou_Cnav2_Utc_Model();

/*!
* \brief Computes the Coordinated Universal Time (UTC) and
* returns it in [s]
*/
double utc_time(double beidou_time);
};

#endif
12 changes: 12 additions & 0 deletions src/core/system_parameters/gnss_satellite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,18 @@ void Gnss_Satellite::set_PRN(unsigned int PRN_)
PRN = PRN_;
}
}
else if (system.compare("Beidou") == 0)
{
if (PRN_ < 1 or PRN_ > 63)
{
DLOG(INFO) << "This PRN is not defined";
PRN = 0;
}
else
{
PRN = PRN_;
}
}
else
{
DLOG(INFO) << "System " << system << " is not defined";
Expand Down
Loading

0 comments on commit 7d91792

Please sign in to comment.