2011-10-01 18:45:20 +00:00
|
|
|
/*!
|
2019-03-02 01:21:03 +00:00
|
|
|
* \file gps_l1_ca_telemetry_decoder_gs.cc
|
2011-12-28 21:36:45 +00:00
|
|
|
* \brief Implementation of a NAV message demodulator block based on
|
|
|
|
* Kay Borre book MATLAB-based GPS receiver
|
- Major changes:
- The executable file and the default configuration file is now changed from "./install/mercurio" and "./conf/mercurio.conf" to "./install/gnss-sdr" and "./conf/gnss-sdr.conf", respectively.
- Configuration file structure changed to define in a single entry the internal sampling frequency (after the signal conditioner). NOTICE that this change affects the all the adapters (acquisition, tracking, telemetry_decoder, observables, and PVT). All the adapters are now modified to work with this feature.
- Moved several in-line GPS L1 CA parameters (a.k.a magic numbers..) to ./src/core/system_parameters/GPS_L1_CA.h definition file.
- Tracking blocks now uses DOUBLE values in their outputs.
- Observables and PVT now are separated. PVT and their associated libraries are moved to ./src/algorithms/PVT
- Temporarily disabled the RINEX output (I am working on that!)
- GNSS-SDR screen output now gives extended debug information of the receiver status and events. In the future, this output will be redirected to a log file.
- Bug fixes:
- FILE_SIGNAL_SOURCE now works correctly when the user configures GNSS-SDR to process the entire file.
- GPS_L1_CA_DLL_PLL now computes correctly the PRN start values.
- GPS_L1_CA_DLL_FLL_PLL now computes correctly the PRN start values.
- Several modifications in GPS_L1_CA_Telemetry_Decoder, GPS_L1_CA_Observables, and GPS_L1_CA_PVT modules to fix the GPS position computation.
- New features
- Tracking blocks perform a signal integrity check against NaN outliers before the correlation process.
- Tracking and PVT binary dump options are now documented and we provide MATLAB libraries and sample files to read it. Available in ./utils/matlab" and "./utils/matlab/libs"
- Observables output rate can be configured. This option enables the GPS L1 CA PVT computation at a maximum rate of 1ms.
- GPS_L1_CA_PVT now can perform a moving average Latitude, Longitude, and Altitude output for each of the Observables output. It is configurable using the configuration file.
- Added Google Earth compatible Keyhole Markup Language (KML) output writer class (./src/algorithms/PVT/libs/kml_printer.h and ./src/algorithms/PVT/libs/kml_printer.cc ). You can see the receiver position directly using Google Earth.
- We provide a master configuration file which includes an in-line documentation with all the new (and old) options. It can be found in ./conf/master.conf
git-svn-id: https://svn.code.sf.net/p/gnss-sdr/code/trunk@84 64b25241-fba3-4117-9849-534c7e92360d
2011-12-07 17:59:34 +00:00
|
|
|
* \author Javier Arribas, 2011. jarribas(at)cttc.es
|
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*
|
2019-07-26 10:38:20 +00:00
|
|
|
* Copyright (C) 2010-2019 (see AUTHORS file for a list of contributors)
|
- Major changes:
- The executable file and the default configuration file is now changed from "./install/mercurio" and "./conf/mercurio.conf" to "./install/gnss-sdr" and "./conf/gnss-sdr.conf", respectively.
- Configuration file structure changed to define in a single entry the internal sampling frequency (after the signal conditioner). NOTICE that this change affects the all the adapters (acquisition, tracking, telemetry_decoder, observables, and PVT). All the adapters are now modified to work with this feature.
- Moved several in-line GPS L1 CA parameters (a.k.a magic numbers..) to ./src/core/system_parameters/GPS_L1_CA.h definition file.
- Tracking blocks now uses DOUBLE values in their outputs.
- Observables and PVT now are separated. PVT and their associated libraries are moved to ./src/algorithms/PVT
- Temporarily disabled the RINEX output (I am working on that!)
- GNSS-SDR screen output now gives extended debug information of the receiver status and events. In the future, this output will be redirected to a log file.
- Bug fixes:
- FILE_SIGNAL_SOURCE now works correctly when the user configures GNSS-SDR to process the entire file.
- GPS_L1_CA_DLL_PLL now computes correctly the PRN start values.
- GPS_L1_CA_DLL_FLL_PLL now computes correctly the PRN start values.
- Several modifications in GPS_L1_CA_Telemetry_Decoder, GPS_L1_CA_Observables, and GPS_L1_CA_PVT modules to fix the GPS position computation.
- New features
- Tracking blocks perform a signal integrity check against NaN outliers before the correlation process.
- Tracking and PVT binary dump options are now documented and we provide MATLAB libraries and sample files to read it. Available in ./utils/matlab" and "./utils/matlab/libs"
- Observables output rate can be configured. This option enables the GPS L1 CA PVT computation at a maximum rate of 1ms.
- GPS_L1_CA_PVT now can perform a moving average Latitude, Longitude, and Altitude output for each of the Observables output. It is configurable using the configuration file.
- Added Google Earth compatible Keyhole Markup Language (KML) output writer class (./src/algorithms/PVT/libs/kml_printer.h and ./src/algorithms/PVT/libs/kml_printer.cc ). You can see the receiver position directly using Google Earth.
- We provide a master configuration file which includes an in-line documentation with all the new (and old) options. It can be found in ./conf/master.conf
git-svn-id: https://svn.code.sf.net/p/gnss-sdr/code/trunk@84 64b25241-fba3-4117-9849-534c7e92360d
2011-12-07 17:59:34 +00:00
|
|
|
*
|
|
|
|
* GNSS-SDR is a software defined Global Navigation
|
|
|
|
* Satellite Systems receiver
|
|
|
|
*
|
|
|
|
* This file is part of GNSS-SDR.
|
|
|
|
*
|
2020-02-08 00:20:02 +00:00
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
- Major changes:
- The executable file and the default configuration file is now changed from "./install/mercurio" and "./conf/mercurio.conf" to "./install/gnss-sdr" and "./conf/gnss-sdr.conf", respectively.
- Configuration file structure changed to define in a single entry the internal sampling frequency (after the signal conditioner). NOTICE that this change affects the all the adapters (acquisition, tracking, telemetry_decoder, observables, and PVT). All the adapters are now modified to work with this feature.
- Moved several in-line GPS L1 CA parameters (a.k.a magic numbers..) to ./src/core/system_parameters/GPS_L1_CA.h definition file.
- Tracking blocks now uses DOUBLE values in their outputs.
- Observables and PVT now are separated. PVT and their associated libraries are moved to ./src/algorithms/PVT
- Temporarily disabled the RINEX output (I am working on that!)
- GNSS-SDR screen output now gives extended debug information of the receiver status and events. In the future, this output will be redirected to a log file.
- Bug fixes:
- FILE_SIGNAL_SOURCE now works correctly when the user configures GNSS-SDR to process the entire file.
- GPS_L1_CA_DLL_PLL now computes correctly the PRN start values.
- GPS_L1_CA_DLL_FLL_PLL now computes correctly the PRN start values.
- Several modifications in GPS_L1_CA_Telemetry_Decoder, GPS_L1_CA_Observables, and GPS_L1_CA_PVT modules to fix the GPS position computation.
- New features
- Tracking blocks perform a signal integrity check against NaN outliers before the correlation process.
- Tracking and PVT binary dump options are now documented and we provide MATLAB libraries and sample files to read it. Available in ./utils/matlab" and "./utils/matlab/libs"
- Observables output rate can be configured. This option enables the GPS L1 CA PVT computation at a maximum rate of 1ms.
- GPS_L1_CA_PVT now can perform a moving average Latitude, Longitude, and Altitude output for each of the Observables output. It is configurable using the configuration file.
- Added Google Earth compatible Keyhole Markup Language (KML) output writer class (./src/algorithms/PVT/libs/kml_printer.h and ./src/algorithms/PVT/libs/kml_printer.cc ). You can see the receiver position directly using Google Earth.
- We provide a master configuration file which includes an in-line documentation with all the new (and old) options. It can be found in ./conf/master.conf
git-svn-id: https://svn.code.sf.net/p/gnss-sdr/code/trunk@84 64b25241-fba3-4117-9849-534c7e92360d
2011-12-07 17:59:34 +00:00
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
2011-10-01 18:45:20 +00:00
|
|
|
*/
|
|
|
|
|
2019-03-02 01:21:03 +00:00
|
|
|
#include "gps_l1_ca_telemetry_decoder_gs.h"
|
2019-03-05 21:17:09 +00:00
|
|
|
#include "gps_ephemeris.h" // for Gps_Ephemeris
|
|
|
|
#include "gps_iono.h" // for Gps_Iono
|
|
|
|
#include "gps_utc_model.h" // for Gps_Utc_Model
|
2011-10-01 18:45:20 +00:00
|
|
|
#include <glog/logging.h>
|
2018-04-22 20:51:02 +00:00
|
|
|
#include <gnuradio/io_signature.h>
|
2019-03-05 21:17:09 +00:00
|
|
|
#include <pmt/pmt.h> // for make_any
|
|
|
|
#include <pmt/pmt_sugar.h> // for mp
|
2019-07-19 16:23:36 +00:00
|
|
|
#include <cmath> // for round
|
|
|
|
#include <cstring> // for memcpy
|
|
|
|
#include <exception> // for exception
|
|
|
|
#include <iostream> // for cout
|
|
|
|
#include <memory> // for shared_ptr
|
2018-02-26 02:15:53 +00:00
|
|
|
|
2012-02-03 11:50:51 +00:00
|
|
|
|
2020-06-16 10:22:37 +00:00
|
|
|
#ifdef COMPILER_HAS_ROTL
|
|
|
|
#include <bit>
|
|
|
|
namespace my_rotl = std;
|
|
|
|
#else
|
|
|
|
namespace my_rotl
|
|
|
|
{
|
2020-06-16 11:04:02 +00:00
|
|
|
#if HAS_GENERIC_LAMBDA
|
|
|
|
auto rotl = [](auto x, auto n) { return (((x) << (n)) ^ ((x) >> (32 - (n)))); };
|
|
|
|
#else
|
2020-06-16 12:00:12 +00:00
|
|
|
auto rotl = [](uint32_t x, uint32_t n) { return (((x) << (n)) ^ ((x) >> (32 - (n)))); };
|
2020-06-16 11:04:02 +00:00
|
|
|
#endif
|
|
|
|
} // namespace my_rotl
|
2013-10-18 18:26:06 +00:00
|
|
|
#endif
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2016-03-22 17:07:12 +00:00
|
|
|
|
2019-03-02 01:21:03 +00:00
|
|
|
gps_l1_ca_telemetry_decoder_gs_sptr
|
|
|
|
gps_l1_ca_make_telemetry_decoder_gs(const Gnss_Satellite &satellite, bool dump)
|
2012-01-10 08:43:58 +00:00
|
|
|
{
|
2019-03-02 01:21:03 +00:00
|
|
|
return gps_l1_ca_telemetry_decoder_gs_sptr(new gps_l1_ca_telemetry_decoder_gs(satellite, dump));
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
2017-08-19 00:33:54 +00:00
|
|
|
|
2019-03-02 01:21:03 +00:00
|
|
|
gps_l1_ca_telemetry_decoder_gs::gps_l1_ca_telemetry_decoder_gs(
|
2018-03-03 01:03:39 +00:00
|
|
|
const Gnss_Satellite &satellite,
|
2019-03-02 01:21:03 +00:00
|
|
|
bool dump) : gr::block("gps_navigation_gs", gr::io_signature::make(1, 1, sizeof(Gnss_Synchro)),
|
2018-03-03 01:03:39 +00:00
|
|
|
gr::io_signature::make(1, 1, sizeof(Gnss_Synchro)))
|
2012-01-10 08:43:58 +00:00
|
|
|
{
|
2019-07-19 16:23:36 +00:00
|
|
|
// prevent telemetry symbols accumulation in output buffers
|
2019-07-04 10:54:45 +00:00
|
|
|
this->set_max_noutput_items(1);
|
2019-07-04 10:16:37 +00:00
|
|
|
|
2016-04-12 13:28:58 +00:00
|
|
|
// Ephemeris data port out
|
|
|
|
this->message_port_register_out(pmt::mp("telemetry"));
|
2019-03-18 15:28:49 +00:00
|
|
|
// Control messages to tracking block
|
|
|
|
this->message_port_register_out(pmt::mp("telemetry_to_trk"));
|
|
|
|
d_last_valid_preamble = 0;
|
|
|
|
d_sent_tlm_failed_msg = false;
|
2019-04-16 07:47:26 +00:00
|
|
|
|
2012-01-10 08:43:58 +00:00
|
|
|
// initialize internal vars
|
|
|
|
d_dump = dump;
|
2012-01-20 23:28:11 +00:00
|
|
|
d_satellite = Gnss_Satellite(satellite.get_system(), satellite.get_PRN());
|
2019-04-16 07:47:26 +00:00
|
|
|
DLOG(INFO) << "Initializing GPS L1 TELEMETRY DECODER";
|
2016-03-22 17:07:12 +00:00
|
|
|
|
2019-04-16 07:47:26 +00:00
|
|
|
d_bits_per_preamble = GPS_CA_PREAMBLE_LENGTH_BITS;
|
2019-07-01 09:00:38 +00:00
|
|
|
d_samples_per_preamble = d_bits_per_preamble;
|
2019-07-03 16:57:26 +00:00
|
|
|
d_preamble_period_symbols = GPS_SUBFRAME_BITS;
|
2012-01-10 08:43:58 +00:00
|
|
|
// set the preamble
|
2019-07-03 16:57:26 +00:00
|
|
|
d_required_symbols = GPS_SUBFRAME_BITS;
|
2012-01-10 08:43:58 +00:00
|
|
|
// preamble bits to sampled symbols
|
2019-04-16 07:47:26 +00:00
|
|
|
d_frame_length_symbols = GPS_SUBFRAME_BITS * GPS_CA_TELEMETRY_SYMBOLS_PER_BIT;
|
2019-07-03 16:57:26 +00:00
|
|
|
d_max_symbols_without_valid_frame = d_required_symbols * 20; // rise alarm 120 segs without valid tlm
|
2018-08-13 11:03:01 +00:00
|
|
|
int32_t n = 0;
|
2019-04-16 07:47:26 +00:00
|
|
|
for (int32_t i = 0; i < d_bits_per_preamble; i++)
|
2011-10-01 18:45:20 +00:00
|
|
|
{
|
2019-09-09 14:00:17 +00:00
|
|
|
if (GPS_CA_PREAMBLE[i] == '1')
|
2012-01-10 08:43:58 +00:00
|
|
|
{
|
2019-07-01 09:00:38 +00:00
|
|
|
d_preamble_samples[n] = 1;
|
|
|
|
n++;
|
2019-04-16 07:47:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-01 09:00:38 +00:00
|
|
|
d_preamble_samples[n] = -1;
|
|
|
|
n++;
|
2012-01-10 08:43:58 +00:00
|
|
|
}
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
2019-04-16 07:47:26 +00:00
|
|
|
d_sample_counter = 0ULL;
|
|
|
|
d_stat = 0;
|
|
|
|
d_preamble_index = 0ULL;
|
|
|
|
|
2012-01-11 09:01:24 +00:00
|
|
|
d_flag_frame_sync = false;
|
2019-04-16 07:47:26 +00:00
|
|
|
|
|
|
|
d_flag_parity = false;
|
|
|
|
d_TOW_at_current_symbol_ms = 0;
|
2018-06-05 16:21:51 +00:00
|
|
|
d_TOW_at_Preamble_ms = 0;
|
2019-04-16 07:47:26 +00:00
|
|
|
d_CRC_error_counter = 0;
|
2015-05-19 20:45:16 +00:00
|
|
|
d_flag_preamble = false;
|
|
|
|
d_channel = 0;
|
2020-06-19 00:15:56 +00:00
|
|
|
d_flag_TOW_set = false;
|
|
|
|
d_flag_PLL_180_deg_phase_locked = false;
|
2019-04-16 07:47:26 +00:00
|
|
|
d_prev_GPS_frame_4bytes = 0;
|
|
|
|
d_symbol_history.set_capacity(d_required_symbols);
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
2012-01-11 09:01:24 +00:00
|
|
|
|
2019-03-02 01:21:03 +00:00
|
|
|
gps_l1_ca_telemetry_decoder_gs::~gps_l1_ca_telemetry_decoder_gs()
|
2012-01-10 08:43:58 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
if (d_dump_file.is_open() == true)
|
2017-07-28 22:25:43 +00:00
|
|
|
{
|
|
|
|
try
|
2018-03-03 01:03:39 +00:00
|
|
|
{
|
2017-07-28 22:25:43 +00:00
|
|
|
d_dump_file.close();
|
2018-03-03 01:03:39 +00:00
|
|
|
}
|
|
|
|
catch (const std::exception &ex)
|
|
|
|
{
|
2017-07-28 22:25:43 +00:00
|
|
|
LOG(WARNING) << "Exception in destructor closing the dump file " << ex.what();
|
2018-03-03 01:03:39 +00:00
|
|
|
}
|
2017-07-28 22:25:43 +00:00
|
|
|
}
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
2017-07-28 22:25:43 +00:00
|
|
|
|
2019-03-02 01:21:03 +00:00
|
|
|
bool gps_l1_ca_telemetry_decoder_gs::gps_word_parityCheck(uint32_t gpsword)
|
2012-01-03 09:27:24 +00:00
|
|
|
{
|
2019-08-12 22:19:31 +00:00
|
|
|
uint32_t d1;
|
|
|
|
uint32_t d2;
|
|
|
|
uint32_t d3;
|
|
|
|
uint32_t d4;
|
|
|
|
uint32_t d5;
|
|
|
|
uint32_t d6;
|
|
|
|
uint32_t d7;
|
|
|
|
uint32_t t;
|
|
|
|
uint32_t parity;
|
2018-08-13 11:03:01 +00:00
|
|
|
// XOR as many bits in parallel as possible. The magic constants pick
|
|
|
|
// up bits which are to be XOR'ed together to implement the GPS parity
|
2020-01-25 12:07:03 +00:00
|
|
|
// check algorithm described in IS-GPS-200K. This avoids lengthy shift-
|
2018-08-13 11:03:01 +00:00
|
|
|
// and-xor loops.
|
2019-07-15 10:14:39 +00:00
|
|
|
d1 = gpsword & 0xFBFFBF00U;
|
2020-06-16 10:22:37 +00:00
|
|
|
d2 = my_rotl::rotl(gpsword, 1U) & 0x07FFBF01U;
|
|
|
|
d3 = my_rotl::rotl(gpsword, 2U) & 0xFC0F8100U;
|
|
|
|
d4 = my_rotl::rotl(gpsword, 3U) & 0xF81FFE02U;
|
|
|
|
d5 = my_rotl::rotl(gpsword, 4U) & 0xFC00000EU;
|
|
|
|
d6 = my_rotl::rotl(gpsword, 5U) & 0x07F00001U;
|
|
|
|
d7 = my_rotl::rotl(gpsword, 6U) & 0x00003000U;
|
2012-01-10 08:43:58 +00:00
|
|
|
t = d1 ^ d2 ^ d3 ^ d4 ^ d5 ^ d6 ^ d7;
|
|
|
|
// Now XOR the 5 6-bit fields together to produce the 6-bit final result.
|
2020-06-16 10:22:37 +00:00
|
|
|
parity = t ^ my_rotl::rotl(t, 6U) ^ my_rotl::rotl(t, 12U) ^ my_rotl::rotl(t, 18U) ^ my_rotl::rotl(t, 24U);
|
2019-07-15 10:14:39 +00:00
|
|
|
parity = parity & 0x3FU;
|
|
|
|
if (parity == (gpsword & 0x3FU))
|
2018-12-03 21:08:19 +00:00
|
|
|
{
|
2019-05-15 15:35:10 +00:00
|
|
|
return true;
|
2018-12-03 21:08:19 +00:00
|
|
|
}
|
|
|
|
|
2019-05-15 15:35:10 +00:00
|
|
|
return false;
|
2012-01-03 09:27:24 +00:00
|
|
|
}
|
|
|
|
|
2012-01-11 09:01:24 +00:00
|
|
|
|
2019-03-02 01:21:03 +00:00
|
|
|
void gps_l1_ca_telemetry_decoder_gs::set_satellite(const Gnss_Satellite &satellite)
|
2018-04-13 09:07:58 +00:00
|
|
|
{
|
2020-06-10 08:15:59 +00:00
|
|
|
d_nav = Gps_Navigation_Message();
|
2018-04-13 09:07:58 +00:00
|
|
|
d_satellite = Gnss_Satellite(satellite.get_system(), satellite.get_PRN());
|
|
|
|
DLOG(INFO) << "Setting decoder Finite State Machine to satellite " << d_satellite;
|
2020-06-23 07:47:58 +00:00
|
|
|
d_nav.set_satellite_PRN(d_satellite.get_PRN());
|
2018-04-13 09:07:58 +00:00
|
|
|
DLOG(INFO) << "Navigation Satellite set to " << d_satellite;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-02 01:21:03 +00:00
|
|
|
void gps_l1_ca_telemetry_decoder_gs::set_channel(int32_t channel)
|
2018-04-13 09:07:58 +00:00
|
|
|
{
|
|
|
|
d_channel = channel;
|
2020-06-23 07:47:58 +00:00
|
|
|
d_nav.set_channel(channel);
|
2018-04-13 09:07:58 +00:00
|
|
|
DLOG(INFO) << "Navigation channel set to " << channel;
|
|
|
|
// ############# ENABLE DATA FILE LOG #################
|
|
|
|
if (d_dump == true)
|
|
|
|
{
|
|
|
|
if (d_dump_file.is_open() == false)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
d_dump_filename = "telemetry";
|
2018-12-03 22:34:29 +00:00
|
|
|
d_dump_filename.append(std::to_string(d_channel));
|
2018-04-13 09:07:58 +00:00
|
|
|
d_dump_filename.append(".dat");
|
|
|
|
d_dump_file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
|
|
|
d_dump_file.open(d_dump_filename.c_str(), std::ios::out | std::ios::binary);
|
|
|
|
LOG(INFO) << "Telemetry decoder dump enabled on channel " << d_channel
|
|
|
|
<< " Log file: " << d_dump_filename.c_str();
|
|
|
|
}
|
|
|
|
catch (const std::ifstream::failure &e)
|
|
|
|
{
|
|
|
|
LOG(WARNING) << "channel " << d_channel << " Exception opening trk dump file " << e.what();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-02 01:21:03 +00:00
|
|
|
bool gps_l1_ca_telemetry_decoder_gs::decode_subframe()
|
2018-07-11 17:38:08 +00:00
|
|
|
{
|
2019-07-14 12:09:12 +00:00
|
|
|
std::array<char, GPS_SUBFRAME_LENGTH> subframe{};
|
2018-08-13 11:03:01 +00:00
|
|
|
int32_t frame_bit_index = 0;
|
|
|
|
int32_t word_index = 0;
|
2018-07-11 17:38:08 +00:00
|
|
|
uint32_t GPS_frame_4bytes = 0;
|
2019-05-15 15:35:10 +00:00
|
|
|
bool subframe_synchro_confirmation = true;
|
2019-04-16 07:47:26 +00:00
|
|
|
for (float subframe_symbol : d_symbol_history)
|
2018-07-11 17:38:08 +00:00
|
|
|
{
|
2018-08-13 11:03:01 +00:00
|
|
|
// ******* SYMBOL TO BIT *******
|
2019-07-01 09:00:38 +00:00
|
|
|
// symbol to bit
|
|
|
|
if (subframe_symbol > 0)
|
2018-07-11 17:38:08 +00:00
|
|
|
{
|
2019-07-01 09:00:38 +00:00
|
|
|
GPS_frame_4bytes += 1; // insert the telemetry bit in LSB
|
|
|
|
}
|
|
|
|
|
|
|
|
// ******* bits to words ******
|
|
|
|
frame_bit_index++;
|
|
|
|
if (frame_bit_index == 30)
|
|
|
|
{
|
|
|
|
frame_bit_index = 0;
|
|
|
|
// parity check
|
|
|
|
// Each word in wordbuff is composed of:
|
|
|
|
// Bits 0 to 29 = the GPS data word
|
|
|
|
// Bits 30 to 31 = 2 LSBs of the GPS word ahead.
|
|
|
|
// prepare the extended frame [-2 -1 0 ... 30]
|
2019-07-15 10:14:39 +00:00
|
|
|
if (d_prev_GPS_frame_4bytes & 0x00000001U)
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
2019-07-15 10:14:39 +00:00
|
|
|
GPS_frame_4bytes = GPS_frame_4bytes | 0x40000000U;
|
2019-04-16 07:47:26 +00:00
|
|
|
}
|
2019-07-15 10:14:39 +00:00
|
|
|
if (d_prev_GPS_frame_4bytes & 0x00000002U)
|
2019-04-16 07:47:26 +00:00
|
|
|
{
|
2019-07-15 10:14:39 +00:00
|
|
|
GPS_frame_4bytes = GPS_frame_4bytes | 0x80000000U;
|
2019-02-11 20:13:02 +00:00
|
|
|
}
|
2019-07-01 09:00:38 +00:00
|
|
|
// Check that the 2 most recently logged words pass parity. Have to first
|
|
|
|
// invert the data bits according to bit 30 of the previous word.
|
2019-07-15 10:14:39 +00:00
|
|
|
if (GPS_frame_4bytes & 0x40000000U)
|
2018-07-11 17:38:08 +00:00
|
|
|
{
|
2019-07-15 10:14:39 +00:00
|
|
|
GPS_frame_4bytes ^= 0x3FFFFFC0U; // invert the data bits (using XOR)
|
2018-07-11 17:38:08 +00:00
|
|
|
}
|
2019-07-01 09:00:38 +00:00
|
|
|
// check parity. If ANY word inside the subframe fails the parity, set subframe_synchro_confirmation = false
|
|
|
|
if (not gps_l1_ca_telemetry_decoder_gs::gps_word_parityCheck(GPS_frame_4bytes))
|
2018-07-11 17:38:08 +00:00
|
|
|
{
|
2019-07-01 09:00:38 +00:00
|
|
|
subframe_synchro_confirmation = false;
|
2018-07-11 17:38:08 +00:00
|
|
|
}
|
2019-07-01 09:00:38 +00:00
|
|
|
// add word to subframe
|
|
|
|
// insert the word in the correct position of the subframe
|
|
|
|
std::memcpy(&subframe[word_index * GPS_WORD_LENGTH], &GPS_frame_4bytes, sizeof(uint32_t));
|
|
|
|
word_index++;
|
|
|
|
d_prev_GPS_frame_4bytes = GPS_frame_4bytes; // save the actual frame
|
|
|
|
GPS_frame_4bytes = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-15 10:14:39 +00:00
|
|
|
GPS_frame_4bytes <<= 1U; // shift 1 bit left the telemetry word
|
2018-07-11 17:38:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-13 11:03:01 +00:00
|
|
|
// decode subframe
|
2018-07-11 17:38:08 +00:00
|
|
|
// NEW GPS SUBFRAME HAS ARRIVED!
|
2019-04-23 10:27:18 +00:00
|
|
|
if (subframe_synchro_confirmation)
|
2018-07-11 17:38:08 +00:00
|
|
|
{
|
2019-07-14 12:09:12 +00:00
|
|
|
int32_t subframe_ID = d_nav.subframe_decoder(subframe.data()); // decode the subframe
|
2018-07-26 17:56:10 +00:00
|
|
|
if (subframe_ID > 0 and subframe_ID < 6)
|
2018-07-11 17:38:08 +00:00
|
|
|
{
|
2018-07-26 17:56:10 +00:00
|
|
|
std::cout << "New GPS NAV message received in channel " << this->d_channel << ": "
|
|
|
|
<< "subframe "
|
|
|
|
<< subframe_ID << " from satellite "
|
2020-06-23 07:47:58 +00:00
|
|
|
<< Gnss_Satellite(std::string("GPS"), d_nav.get_satellite_PRN()) << std::endl;
|
2018-07-26 17:56:10 +00:00
|
|
|
|
|
|
|
switch (subframe_ID)
|
2018-07-11 17:38:08 +00:00
|
|
|
{
|
2018-08-13 11:03:01 +00:00
|
|
|
case 3: // we have a new set of ephemeris data for the current SV
|
2018-07-26 17:56:10 +00:00
|
|
|
if (d_nav.satellite_validation() == true)
|
|
|
|
{
|
|
|
|
// get ephemeris object for this SV (mandatory)
|
|
|
|
std::shared_ptr<Gps_Ephemeris> tmp_obj = std::make_shared<Gps_Ephemeris>(d_nav.get_ephemeris());
|
|
|
|
this->message_port_pub(pmt::mp("telemetry"), pmt::make_any(tmp_obj));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4: // Possible IONOSPHERE and UTC model update (page 18)
|
2020-06-23 07:47:58 +00:00
|
|
|
if (d_nav.get_flag_iono_valid() == true)
|
2018-07-26 17:56:10 +00:00
|
|
|
{
|
|
|
|
std::shared_ptr<Gps_Iono> tmp_obj = std::make_shared<Gps_Iono>(d_nav.get_iono());
|
|
|
|
this->message_port_pub(pmt::mp("telemetry"), pmt::make_any(tmp_obj));
|
|
|
|
}
|
2020-06-23 07:47:58 +00:00
|
|
|
if (d_nav.get_flag_utc_model_valid() == true)
|
2018-07-26 17:56:10 +00:00
|
|
|
{
|
|
|
|
std::shared_ptr<Gps_Utc_Model> tmp_obj = std::make_shared<Gps_Utc_Model>(d_nav.get_utc_model());
|
|
|
|
this->message_port_pub(pmt::mp("telemetry"), pmt::make_any(tmp_obj));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
// get almanac (if available)
|
2019-08-18 20:16:13 +00:00
|
|
|
// TODO: implement almanac reader in navigation_message
|
2018-07-26 17:56:10 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2018-07-11 17:38:08 +00:00
|
|
|
}
|
2019-04-23 10:27:18 +00:00
|
|
|
return true;
|
2018-07-26 17:56:10 +00:00
|
|
|
}
|
2019-04-23 10:32:12 +00:00
|
|
|
}
|
2019-08-04 11:15:03 +00:00
|
|
|
return false;
|
2018-07-11 17:38:08 +00:00
|
|
|
}
|
|
|
|
|
2019-03-18 18:41:41 +00:00
|
|
|
|
2019-03-18 15:28:49 +00:00
|
|
|
void gps_l1_ca_telemetry_decoder_gs::reset()
|
|
|
|
{
|
2019-04-23 10:27:18 +00:00
|
|
|
gr::thread::scoped_lock lock(d_setlock); // require mutex with work function called by the scheduler
|
2019-03-18 15:28:49 +00:00
|
|
|
d_last_valid_preamble = d_sample_counter;
|
|
|
|
d_sent_tlm_failed_msg = false;
|
2020-06-19 00:15:56 +00:00
|
|
|
d_flag_TOW_set = false;
|
2019-04-23 10:27:18 +00:00
|
|
|
d_symbol_history.clear();
|
|
|
|
d_stat = 0;
|
2019-03-18 15:28:49 +00:00
|
|
|
DLOG(INFO) << "Telemetry decoder reset for satellite " << d_satellite;
|
|
|
|
}
|
2018-08-13 11:03:01 +00:00
|
|
|
|
2019-03-18 18:41:41 +00:00
|
|
|
|
2019-03-02 01:21:03 +00:00
|
|
|
int gps_l1_ca_telemetry_decoder_gs::general_work(int noutput_items __attribute__((unused)), gr_vector_int &ninput_items __attribute__((unused)),
|
2018-03-03 01:03:39 +00:00
|
|
|
gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
|
2012-01-11 09:01:24 +00:00
|
|
|
{
|
2018-12-03 15:25:11 +00:00
|
|
|
auto **out = reinterpret_cast<Gnss_Synchro **>(&output_items[0]); // Get the output buffer pointer
|
|
|
|
const auto **in = reinterpret_cast<const Gnss_Synchro **>(&input_items[0]); // Get the input buffer pointer
|
2012-01-10 08:43:58 +00:00
|
|
|
|
2020-05-29 22:44:37 +00:00
|
|
|
Gnss_Synchro current_symbol{};
|
2018-08-13 11:03:01 +00:00
|
|
|
// 1. Copy the current tracking output
|
2020-05-29 22:44:37 +00:00
|
|
|
current_symbol = in[0][0];
|
2019-04-16 07:47:26 +00:00
|
|
|
// add new symbol to the symbol queue
|
|
|
|
d_symbol_history.push_back(current_symbol.Prompt_I);
|
|
|
|
d_sample_counter++; // count for the processed symbols
|
2017-05-17 10:48:57 +00:00
|
|
|
consume_each(1);
|
2012-11-25 11:15:11 +00:00
|
|
|
d_flag_preamble = false;
|
2019-03-18 15:28:49 +00:00
|
|
|
// check if there is a problem with the telemetry of the current satellite
|
2019-04-16 07:47:26 +00:00
|
|
|
if (d_stat < 2 and d_sent_tlm_failed_msg == false)
|
2019-03-18 15:28:49 +00:00
|
|
|
{
|
|
|
|
if ((d_sample_counter - d_last_valid_preamble) > d_max_symbols_without_valid_frame)
|
|
|
|
{
|
2019-07-28 10:01:11 +00:00
|
|
|
int message = 1; // bad telemetry
|
2019-03-18 15:28:49 +00:00
|
|
|
this->message_port_pub(pmt::mp("telemetry_to_trk"), pmt::make_any(message));
|
|
|
|
d_sent_tlm_failed_msg = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-13 11:03:01 +00:00
|
|
|
// ******* frame sync ******************
|
2019-04-16 07:47:26 +00:00
|
|
|
switch (d_stat)
|
2016-03-30 19:09:38 +00:00
|
|
|
{
|
2019-04-16 07:47:26 +00:00
|
|
|
case 0: // no preamble information
|
|
|
|
{
|
2019-04-27 10:43:34 +00:00
|
|
|
// correlate with preamble
|
2019-04-16 08:08:22 +00:00
|
|
|
int32_t corr_value = 0;
|
2019-07-01 09:00:38 +00:00
|
|
|
if (d_symbol_history.size() >= GPS_CA_PREAMBLE_LENGTH_BITS)
|
2019-04-16 07:47:26 +00:00
|
|
|
{
|
|
|
|
// ******* preamble correlation ********
|
2019-07-01 09:00:38 +00:00
|
|
|
for (int32_t i = 0; i < GPS_CA_PREAMBLE_LENGTH_BITS; i++)
|
2019-04-16 07:47:26 +00:00
|
|
|
{
|
|
|
|
if (d_symbol_history[i] < 0.0) // symbols clipping
|
|
|
|
{
|
|
|
|
corr_value -= d_preamble_samples[i];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
corr_value += d_preamble_samples[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (abs(corr_value) >= d_samples_per_preamble)
|
|
|
|
{
|
|
|
|
d_preamble_index = d_sample_counter; // record the preamble sample stamp
|
|
|
|
DLOG(INFO) << "Preamble detection for GPS L1 satellite " << this->d_satellite;
|
2019-07-01 09:00:38 +00:00
|
|
|
decode_subframe();
|
2019-04-16 07:47:26 +00:00
|
|
|
d_stat = 1; // enter into frame pre-detection status
|
|
|
|
}
|
2020-06-19 00:15:56 +00:00
|
|
|
d_flag_TOW_set = false;
|
2019-04-16 07:47:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 1: // possible preamble lock
|
|
|
|
{
|
2019-04-27 10:43:34 +00:00
|
|
|
// correlate with preamble
|
2019-04-16 08:08:22 +00:00
|
|
|
int32_t corr_value = 0;
|
|
|
|
int32_t preamble_diff = 0;
|
2019-07-01 09:00:38 +00:00
|
|
|
if (d_symbol_history.size() >= GPS_CA_PREAMBLE_LENGTH_BITS)
|
2019-04-16 07:47:26 +00:00
|
|
|
{
|
|
|
|
// ******* preamble correlation ********
|
2019-07-01 09:00:38 +00:00
|
|
|
for (int32_t i = 0; i < GPS_CA_PREAMBLE_LENGTH_BITS; i++)
|
2019-04-16 07:47:26 +00:00
|
|
|
{
|
|
|
|
if (d_symbol_history[i] < 0.0) // symbols clipping
|
|
|
|
{
|
|
|
|
corr_value -= d_preamble_samples[i];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
corr_value += d_preamble_samples[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (abs(corr_value) >= d_samples_per_preamble)
|
|
|
|
{
|
|
|
|
// check preamble separation
|
|
|
|
preamble_diff = static_cast<int32_t>(d_sample_counter - d_preamble_index);
|
|
|
|
if (abs(preamble_diff - d_preamble_period_symbols) == 0)
|
|
|
|
{
|
|
|
|
DLOG(INFO) << "Preamble confirmation for SAT " << this->d_satellite;
|
|
|
|
d_preamble_index = d_sample_counter; // record the preamble sample stamp
|
2019-06-11 18:20:23 +00:00
|
|
|
if (corr_value < 0)
|
|
|
|
{
|
2020-06-19 00:15:56 +00:00
|
|
|
d_flag_PLL_180_deg_phase_locked = true;
|
2019-06-11 18:20:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-19 00:15:56 +00:00
|
|
|
d_flag_PLL_180_deg_phase_locked = false;
|
2019-06-11 18:20:23 +00:00
|
|
|
}
|
2019-07-01 09:00:38 +00:00
|
|
|
decode_subframe();
|
2019-04-16 07:47:26 +00:00
|
|
|
d_stat = 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (preamble_diff > d_preamble_period_symbols)
|
|
|
|
{
|
|
|
|
d_stat = 0; // start again
|
2020-06-19 00:15:56 +00:00
|
|
|
d_flag_TOW_set = false;
|
2019-04-16 07:47:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 2: // preamble acquired
|
|
|
|
{
|
|
|
|
if (d_sample_counter >= d_preamble_index + static_cast<uint64_t>(d_preamble_period_symbols))
|
|
|
|
{
|
|
|
|
DLOG(INFO) << "Preamble received for SAT " << this->d_satellite << "d_sample_counter=" << d_sample_counter << "\n";
|
|
|
|
// call the decoder
|
|
|
|
// 0. fetch the symbols into an array
|
|
|
|
d_preamble_index = d_sample_counter; // record the preamble sample stamp (t_P)
|
|
|
|
|
|
|
|
if (decode_subframe())
|
|
|
|
{
|
|
|
|
d_CRC_error_counter = 0;
|
|
|
|
d_flag_preamble = true; // valid preamble indicator (initialized to false every work())
|
2019-06-07 10:00:47 +00:00
|
|
|
gr::thread::scoped_lock lock(d_setlock);
|
2019-04-16 07:47:26 +00:00
|
|
|
d_last_valid_preamble = d_sample_counter;
|
|
|
|
if (!d_flag_frame_sync)
|
|
|
|
{
|
|
|
|
d_flag_frame_sync = true;
|
|
|
|
DLOG(INFO) << " Frame sync SAT " << this->d_satellite;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d_CRC_error_counter++;
|
|
|
|
if (d_CRC_error_counter > 2)
|
|
|
|
{
|
|
|
|
DLOG(INFO) << "Lost of frame sync SAT " << this->d_satellite;
|
|
|
|
d_flag_frame_sync = false;
|
|
|
|
d_stat = 0;
|
|
|
|
d_TOW_at_current_symbol_ms = 0;
|
|
|
|
d_TOW_at_Preamble_ms = 0;
|
|
|
|
d_CRC_error_counter = 0;
|
2020-06-19 00:15:56 +00:00
|
|
|
d_flag_TOW_set = false;
|
2019-04-16 07:47:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2016-03-30 19:09:38 +00:00
|
|
|
}
|
2012-11-25 11:15:11 +00:00
|
|
|
|
2018-08-13 11:03:01 +00:00
|
|
|
// 2. Add the telemetry decoder information
|
2019-04-16 07:47:26 +00:00
|
|
|
if (d_flag_preamble == true)
|
2017-01-28 14:31:04 +00:00
|
|
|
{
|
2020-06-23 07:47:58 +00:00
|
|
|
if (!(d_nav.get_TOW() == 0))
|
2019-04-23 10:27:18 +00:00
|
|
|
{
|
2020-06-23 07:47:58 +00:00
|
|
|
d_TOW_at_current_symbol_ms = static_cast<uint32_t>(d_nav.get_TOW() * 1000.0);
|
|
|
|
d_TOW_at_Preamble_ms = static_cast<uint32_t>(d_nav.get_TOW() * 1000.0);
|
2020-06-19 00:15:56 +00:00
|
|
|
d_flag_TOW_set = true;
|
2019-04-23 10:27:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-23 07:47:58 +00:00
|
|
|
DLOG(INFO) << "Received GPS L1 TOW equal to zero at sat " << d_nav.get_satellite_PRN();
|
2019-04-23 10:27:18 +00:00
|
|
|
}
|
2017-01-28 14:31:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-19 00:15:56 +00:00
|
|
|
if (d_flag_TOW_set == true)
|
2018-08-07 17:39:56 +00:00
|
|
|
{
|
2019-07-01 09:00:38 +00:00
|
|
|
d_TOW_at_current_symbol_ms += GPS_L1_CA_BIT_PERIOD_MS;
|
2018-08-07 17:39:56 +00:00
|
|
|
}
|
2017-01-28 14:31:04 +00:00
|
|
|
}
|
2013-07-04 13:47:40 +00:00
|
|
|
|
2020-06-19 00:15:56 +00:00
|
|
|
if (d_flag_TOW_set == true)
|
2018-03-03 01:03:39 +00:00
|
|
|
{
|
2018-08-07 17:39:56 +00:00
|
|
|
current_symbol.TOW_at_current_symbol_ms = d_TOW_at_current_symbol_ms;
|
2020-06-19 00:15:56 +00:00
|
|
|
current_symbol.Flag_valid_word = d_flag_TOW_set;
|
2018-03-03 01:03:39 +00:00
|
|
|
|
2020-06-19 00:15:56 +00:00
|
|
|
if (d_flag_PLL_180_deg_phase_locked == true)
|
2020-03-07 10:36:47 +00:00
|
|
|
{
|
|
|
|
// correct the accumulated phase for the Costas loop phase shift, if required
|
|
|
|
current_symbol.Carrier_phase_rads += GPS_PI;
|
|
|
|
}
|
|
|
|
|
2018-08-07 17:39:56 +00:00
|
|
|
if (d_dump == true)
|
2018-03-03 01:03:39 +00:00
|
|
|
{
|
2018-08-07 17:39:56 +00:00
|
|
|
// MULTIPLEXED FILE RECORDING - Record results to file
|
|
|
|
try
|
|
|
|
{
|
|
|
|
double tmp_double;
|
2018-08-10 18:34:03 +00:00
|
|
|
uint64_t tmp_ulong_int;
|
2018-08-07 17:39:56 +00:00
|
|
|
tmp_double = static_cast<double>(d_TOW_at_current_symbol_ms) / 1000.0;
|
|
|
|
d_dump_file.write(reinterpret_cast<char *>(&tmp_double), sizeof(double));
|
|
|
|
tmp_ulong_int = current_symbol.Tracking_sample_counter;
|
2018-08-10 18:34:03 +00:00
|
|
|
d_dump_file.write(reinterpret_cast<char *>(&tmp_ulong_int), sizeof(uint64_t));
|
2018-08-07 17:39:56 +00:00
|
|
|
tmp_double = static_cast<double>(d_TOW_at_Preamble_ms) / 1000.0;
|
|
|
|
d_dump_file.write(reinterpret_cast<char *>(&tmp_double), sizeof(double));
|
|
|
|
}
|
|
|
|
catch (const std::ifstream::failure &e)
|
|
|
|
{
|
|
|
|
LOG(WARNING) << "Exception writing observables dump file " << e.what();
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
}
|
|
|
|
|
2019-06-07 10:00:47 +00:00
|
|
|
// 3. Make the output (copy the object contents to the GNU Radio reserved memory)
|
2018-08-07 17:39:56 +00:00
|
|
|
*out[0] = current_symbol;
|
2018-03-03 01:03:39 +00:00
|
|
|
|
2018-08-07 17:39:56 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2018-12-03 21:08:19 +00:00
|
|
|
|
|
|
|
return 0;
|
2018-03-03 01:03:39 +00:00
|
|
|
}
|