/*!
* \file Galileo_Navigation_Message.cc
* \brief Implementation of a Galileo NAV Data message decoder as described in Galileo ICD
* \author Mara Branzanti 2013. mara.branzanti(at)gmail.com
* \author Javier Arribas, 2013. jarribas(at)cttc.es
*
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2013 (see AUTHORS file for a list of contributors)
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
*
* This file is part of GNSS-SDR.
*
* GNSS-SDR is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* GNSS-SDR is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNSS-SDR. If not, see .
*
* -------------------------------------------------------------------------
*/
#include "galileo_navigation_message.h"
#include
#include // for boost::crc_basic, boost::crc_optimal
#include
#include
#include
#include
using namespace std;
typedef boost::crc_optimal<24, 0x1864CFBu, 0x0, 0x0, false, false> CRC_Galileo_INAV_type;
void Galileo_Navigation_Message::reset()
{
flag_even_word = 0;
/*Word type 1: Ephemeris (1/4)*/
IOD_nav_1 = 0;
t0e_1 = 0;
M0_1 = 0;
e_1 = 0;
A_1 = 0;
/*Word type 2: Ephemeris (2/4)*/
IOD_nav_2 = 0; // IOD_nav page 2
OMEGA_0_2 = 0; // Longitude of ascending node of orbital plane at weekly epoch [semi-circles]
i_0_2 = 0; // Inclination angle at reference time [semi-circles]
omega_2 = 0; // Argument of perigee [semi-circles]
iDot_2 = 0; // Rate of inclination angle [semi-circles/sec]
/*Word type 3: Ephemeris (3/4) and SISA*/
IOD_nav_3 = 0; //
OMEGA_dot_3 = 0; // Rate of right ascension [semi-circles/sec]
delta_n_3 = 0; // Mean motion difference from computed value [semi-circles/sec]
C_uc_3 = 0; // Amplitude of the cosine harmonic correction term to the argument of latitude [radians]
C_us_3 = 0; // Amplitude of the sine harmonic correction term to the argument of latitude [radians]
C_rc_3 = 0; // Amplitude of the cosine harmonic correction term to the orbit radius [meters]
C_rs_3 = 0; // Amplitude of the sine harmonic correction term to the orbit radius [meters]
SISA_3 = 0; //
/*Word type 4: Ephemeris (4/4) and Clock correction parameters*/
IOD_nav_4 = 0; //
SV_ID_PRN_4 = 0; //
C_ic_4 = 0; // Amplitude of the cosine harmonic correction term to the angle of inclination [radians]
C_is_4 = 0; // Amplitude of the sine harmonic correction term to the angle of inclination [radians]
/*Clock correction parameters*/
t0c_4 = 0; //
af0_4 = 0; //
af1_4 = 0; //
af2_4 = 0; //
spare_4 = 0;
/*Word type 5: Ionospheric correction, BGD, signal health and data validity status and GST*/
/*Ionospheric correction*/
/*Az*/
ai0_5 = 0; //
ai1_5 = 0; //
ai2_5 = 0; //
/*Ionospheric disturbance flag*/
Region1_flag_5 = 0; //Region1_flag_5;
Region2_flag_5 = 0; //
Region3_flag_5 = 0; //
Region4_flag_5 = 0; //
Region5_flag_5 = 0; //
BGD_E1E5a_5 = 0; //
BGD_E1E5b_5 = 0; //
E5b_HS_5 = 0; //
E1B_HS_5 = 0; //
E5b_DVS_5 = 0; //
E1B_DVS_5 = 0; //
/*GST*/
WN_5 = 0;
TOW_5 = 0;
spare_5 = 0;
/*Word type 6: GST-UTC conversion parameters*/
A0_6 = 0;
A1_6 = 0;
Delta_tLS_6 = 0;
t0t_6 = 0;
WNot_6 = 0;
WN_LSF_6 = 0;
DN_6 = 0;
Delta_tLSF_6 = 0;
TOW_6 = 0;
/*Word type 7: Almanac for SVID1 (1/2), almanac reference time and almanac reference week number*/
IOD_a_7 = 0;
WN_a_7 = 0;
t0a_7 = 0;
SVID1_7 = 0;
Delta_alpha_7 = 0;
e_7 = 0;
omega_7 = 0;
delta_i_7 = 0;
Omega0_7 = 0;
Omega_dot_7 = 0;
M0_7 = 0;
/*Word type 8: Almanac for SVID1 (2/2) and SVID2 (1/2)*/
IOD_a_8 = 0;
af0_8 = 0;
af1_8 = 0;
E5b_HS_8 = 0;
E1B_HS_8 = 0;
SVID2_8 = 0;
DELTA_A_8 = 0;
e_8 = 0;
omega_8 = 0;
delta_i_8 = 0;
Omega0_8 = 0;
Omega_dot_8 = 0;
/*Word type 9: Almanac for SVID2 (2/2) and SVID3 (1/2)*/
IOD_a_9 = 0;
WN_a_9 = 0;
t0a_9 = 0;
M0_9 = 0;
af0_9 = 0;
af1_9 = 0;
E5b_HS_9 = 0;
E1B_HS_9 = 0;
SVID3_9 = 0;
DELTA_A_9 = 0;
e_9 = 0;
omega_9 = 0;
delta_i_9 = 0;
/*Word type 10: Almanac for SVID3 (2/2) and GST-GPS conversion parameters*/
IOD_a_10 = 0;
Omega0_10 = 0;
Omega_dot_10 = 0;
M0_10 = 0;
af0_10 = 0;
af1_10 = 0;
E5b_HS_10 = 0;
E1B_HS_10 = 0;
A_0G_10 = 0;
A_1G_10 = 0;
t_0G_10 = 0;
WN_0G_10 = 0;
/*Word type 0: I/NAV Spare Word*/
Time_0 = 0;
WN_0 = 0;
TOW_0 = 0;
}
Galileo_Navigation_Message::Galileo_Navigation_Message()
{
reset();
}
bool Galileo_Navigation_Message::CRC_test(std::bitset bits,boost::uint32_t checksum)
{
CRC_Galileo_INAV_type CRC_Galileo;
boost::uint32_t crc_computed;
// Galileo INAV frame for CRC is not an integer multiple of bytes
// it needs to be filled with zeroes at the start of the frame.
// This operation is done in the transformation from bits to bytes
// using boost::dynamic_bitset.
// ToDo: Use boost::dynamic_bitset for all the bitset operations in this class
boost::dynamic_bitset frame_bits(std::string(bits.to_string()));
std::vector bytes;
boost::to_block_range(frame_bits, std::back_inserter(bytes));
std::reverse(bytes.begin(),bytes.end());
CRC_Galileo.process_bytes( bytes.data(), GALILEO_DATA_FRAME_BYTES );
crc_computed=CRC_Galileo.checksum();
if (checksum==crc_computed){
return true;
}else{
return false;
}
}
unsigned long int Galileo_Navigation_Message::read_navigation_unsigned(std::bitset bits, const std::vector > parameter)
{
unsigned long int value = 0;
int num_of_slices = parameter.size();
for (int i=0; i bits, const std::vector > parameter)
{
unsigned long int value = 0;
int num_of_slices = parameter.size();
for (int i=0; i bits, const std::vector > parameter)
{
signed long int value = 0;
int num_of_slices = parameter.size();
// Discriminate between 64 bits and 32 bits compiler
int long_int_size_bytes = sizeof(signed long int);
if (long_int_size_bytes == 8) // if a long int takes 8 bytes, we are in a 64 bits system
{
// read the MSB and perform the sign extension
if (bits[GALILEO_DATA_JK_BITS - parameter[0].first] == 1)
{
value ^= 0xFFFFFFFFFFFFFFFF; //64 bits variable
}
else
{
value &= 0;
}
for (int i=0; i bits, const std::vector > parameter)
{
bool value;
if (bits[GALILEO_DATA_JK_BITS - parameter[0].first] == 1)
{
value = true;
}
else
{
value = false;
}
return value;
}
/*void Galileo_Navigation_Message::print_galileo_word_bytes(unsigned int GPS_word)
{
std::cout << " Word =";
std::cout << std::bitset<32>(GPS_word);
std::cout << std::endl;
}*/
void Galileo_Navigation_Message::split_page(const char *page, int flag_even_word){
// ToDo: Replace all the C structures and string operations with std::string and std::stringstream C++ classes.
// ToDo: Clean all the tests and create an independent google test code for the telemetry decoder.
cout << "--------------------------------------------------------------------------" << endl;
cout << "Entered in Galileo_Navigation_Message::split_page(char *page)" << endl << endl;;
char Even_bit[2]={'\0'}, Odd_bit[2]={'\0'}, Page_type_Odd[2]={'\0'}, Page_type_even[2]={'\0'}, tail_Even[7]={'\0'}; //HO DATO A TUTTI UNO SPAZIO IN PIÙ PER L'ULTIMO CARATTERE
char page_Odd[121]={'\0'};
char page_INAV[235]={'\0'};
char Data_j[16]={'\0'}, Data_k[112]={'\0'}, page_number_bits[6]={'\0'};
char Data_jk_ephemeris[129]={'\0'};
char Reserved_1[40]={'\0'};
char SAR[22]={'\0'};
char Spare[2]={'\0'};
char CRC_data[24]={'\0'};
char Reserved_2[8]={'\0'};
char Tail_odd[6]={'\0'};
//char correct_tail[7]="000000";
char correct_tail[7]="011110"; //the viterbi decoder output change the tail to this value (why?)
int Page_type=0;
static char page_Even[114];
/* Test to decode page 1 even joined to its corresponding
The Even pages given here are without their tails bits*/
//test to detect page 1------> char page_Even[115]="000000010001011111010111101101100111110110101110101111100011001000000000001101110101110010000100101010100000010011";
//test to detect page 2------> char page_Even[115]="000000100001011111110010111010111100000010111100000010011100000000100001011110100111000111100111000000100000000010";
//test to detect page 3------>char page_Even[115]="000000110001011111111111111100001001100110001000110001011111110011111100110001011000111110000011011111000011110000";
//test to detect page 4------>char page_Even[115]="000001000001011111001100000000000000101100000000000111010101111011011000000001000101001111101010011100000000010110://
/*test to detect page 5------>char page_Even[115]="000001010010000010000000100010000010111010100000011111110001111111000111111001011000110010110011111111110110000000";*/
//test to detect page 10-----> char page_Even[115]="000010101111101010101010101010101010101010101010101010101010101010101010101010101010111100000000000000000000000000";
//test to detect page 6------>char page_Even[115]="000001100000000000000000000000011100001100000000000000000000000000100011010111111010001101000011100001000110101101
/* test to detect page 7------> char page_Even[115]="000001111111101001011111010011000000000110100000001110010111111110010111110111101001000001110000111111110000101101"; */
/* test to detect page 8------> char page_Even[115]="000010001111000000100001111100000011000001111010100000000000110100000001111010011110111000011110111101001000001110"; */
/* test to detect page 9------> char page_Even[115]="000010011111101001011111111000101110001100000000011010100000000010111111100000001010101010101010101010101010101010"; */
/* test to detect page 10------> char page_Even[115]="000010101111101010101010101010101010101010101010101010101010101010101010101010101010111100000000000000000000000000"; */
/* test to detect page 0------> char page_Even[115]="000000001001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010010110001100101";*/
cout << "Start decoding Galileo I/NAV " << endl;
// cout<<"page input"<> s_page_number; // from stringstream to string
std::bitset page_type_bits (s_page_number); // from string to bitset
Page_type = (int)read_page_type_unsigned(page_type_bits, type);
std::cout << "Page number (first 6 bits of Data k converted to decimal) = " << Page_type << endl;
strncpy(Data_jk_ephemeris, &Data_k[0], 112); // Join data_j + data_k = Data_jk_ephemeris;
strncat(Data_jk_ephemeris, Data_j, 16); // Data_jk_ephemeris is the input for the function page decoder
//std::cout<<"Data j k ephemeris" << endl << Data_jk_ephemeris << endl;
page_jk_decoder(Data_jk_ephemeris); // Corresponding to ephemeris_decode.m in matlab code
//internal_flag_even_word_arrived=0;
}
} /*if(page[0]=='1') */
else{
strncpy(page_Even, &page[0], 114); //ora che ha memorizzato page even dovrebbe mantenerla per la prossima volta che entro nella funzione
std::cout << "Page even in split page" << std::endl << page_Even << std::endl;
strncpy(tail_Even, &page[114], 6);
if(strcmp (tail_Even,correct_tail) != 0)
std::cout << "Tail even is not correct!" << endl;
else std::cout<<"Tail even is correct!"<> str;
std::bitset data_jk_bits (str);
//std::cout << "Data_jk_bits (bitset) "<< endl << data_jk_bits << endl;
page_number = (int)read_navigation_unsigned(data_jk_bits, PAGE_TYPE_bit);
std::cout << "Page number = " << page_number << endl;
switch (page_number)
{
case 1: /*Word type 1: Ephemeris (1/4)*/
IOD_nav_1=(int)read_navigation_unsigned(data_jk_bits, IOD_nav_1_bit);
std::cout<<"IOD_nav_1= "<< IOD_nav_1 <