/*!
* \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 "boost/date_time/posix_time/posix_time.hpp"
using namespace std;
void Galileo_Navigation_Message::reset()
{
/*Word type 1: Ephemeris (1/4)*/
IOD_nav_1 = 0;
t0e = 0;
M0 = 0;
e = 0;
A = 0;
/*d_TOW_SF1 = 0;
d_TOW_SF2 = 0;
d_TOW_SF3 = 0;
d_TOW_SF4 = 0;
d_TOW_SF5 = 0;
d_IODE_SF2 = 0;
d_IODE_SF3 = 0;
d_Crs = 0;
d_Delta_n = 0;
d_M_0 = 0;
d_Cuc = 0;
d_e_eccentricity = 0;
d_Cus = 0;
d_sqrt_A = 0;
d_Toe = 0;
d_Toc = 0;
d_Cic = 0;
d_OMEGA0 = 0;
d_Cis = 0;
d_i_0 = 0;
d_Crc = 0;
d_OMEGA = 0;
d_OMEGA_DOT = 0;
d_IDOT = 0;
i_code_on_L2 = 0;
i_GPS_week = 0;
b_L2_P_data_flag = false;
i_SV_accuracy = 0;
i_SV_health = 0;
d_TGD = 0;
d_IODC = -1;
i_AODO = 0;
b_fit_interval_flag = false;
d_spare1 = 0;
d_spare2 = 0;
d_A_f0 = 0;
d_A_f1 = 0;
d_A_f2 = 0;
//clock terms
//d_master_clock=0;
d_dtr = 0;
d_satClkCorr = 0;
// satellite positions
d_satpos_X = 0;
d_satpos_Y = 0;
d_satpos_Z = 0;
// info
i_channel_ID = 0;
i_satellite_PRN = 0;
// time synchro
d_subframe_timestamp_ms = 0;
// flags
b_alert_flag = false;
b_integrity_status_flag = false;
b_antispoofing_flag = false;
// Ionosphere and UTC
flag_iono_valid = false;
flag_utc_model_valid = true;
d_alpha0 = 0;
d_alpha1 = 0;
d_alpha2 = 0;
d_alpha3 = 0;
d_beta0 = 0;
d_beta1 = 0;
d_beta2 = 0;
d_beta3 = 0;
d_A1 = 0;
d_A0 = 0;
d_t_OT = 0;
i_WN_T = 0;
d_DeltaT_LS = 0;
i_WN_LSF = 0;
i_DN = 0;
d_DeltaT_LSF= 0;
//Almanac
d_Toa = 0;
i_WN_A = 0;
for (int i=1; i < 32; i++ )
{
almanacHealth[i] = 0;
}
// Satellite velocity
d_satvel_X = 0;
d_satvel_Y = 0;
d_satvel_Z = 0;
//Plane A (info from http://www.navcen.uscg.gov/?Do=constellationStatus)
satelliteBlock[9] = "IIA";
satelliteBlock[31] = "IIR-M";
satelliteBlock[8] = "IIA";
satelliteBlock[7] = "IIR-M";
satelliteBlock[27] = "IIA";
//Plane B
satelliteBlock[16] = "IIR";
satelliteBlock[25] = "IIF";
satelliteBlock[28] = "IIR";
satelliteBlock[12] = "IIR-M";
satelliteBlock[30] = "IIA";
//Plane C
satelliteBlock[29] = "IIR-M";
satelliteBlock[3] = "IIA";
satelliteBlock[19] = "IIR";
satelliteBlock[17] = "IIR-M";
satelliteBlock[6] = "IIA";
//Plane D
satelliteBlock[2] = "IIR";
satelliteBlock[1] = "IIF";
satelliteBlock[21] = "IIR";
satelliteBlock[4] = "IIA";
satelliteBlock[11] = "IIR";
satelliteBlock[24] = "IIA"; // Decommissioned from active service on 04 Nov 2011
//Plane E
satelliteBlock[20] = "IIR";
satelliteBlock[22] = "IIR";
satelliteBlock[5] = "IIR-M";
satelliteBlock[18] = "IIR";
satelliteBlock[32] = "IIA";
satelliteBlock[10] = "IIA";
//Plane F
satelliteBlock[14] = "IIR";
satelliteBlock[15] = "IIR-M";
satelliteBlock[13] = "IIR";
satelliteBlock[23] = "IIR";
satelliteBlock[26] = "IIA";*/
}
Galileo_Navigation_Message::Galileo_Navigation_Message()
{
reset();
}
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_SUBFRAME_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_SUBFRAME_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(char *page){
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'}, page_INAV[235]={'\0'};
char Data_j[16]={'\0'}, Data_k[112]={'\0'}, page_number_bits[6]={'\0'};
char Data_jk_ephemeris[128]={'\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";
int flag_even_word_arrived=1; /*******************REMEMBER TO CHANGE flag_even_word_arrived=0 *****+**********/
int Page_type=0;
/* Test to decode page 1 even joined to its corresponding
The Even pages given here are without their tails bits*/
char page_Even[115]="000000010001011111010111101101100111110110101110101111100011001000000000001101110101110010000100101010100000010011";
//test to detect page 3------> char page_Even[115]="000000110001011111111111111100001001100110001000110001011111110011111100110001011000111110000011011111000011110000";
//test to detect page 10-----> char page_Even[115]="000010101111101010101010101010101010101010101010101010101010101010101010101010101010111100000000000000000000000000";
//test to detect page 5------> char page_Even[115]="000001010010000010000000100010000010111010100000011111110001111111000111111001011000110010110011111111110110000000";
//test to detect page 2------> char page_Even[115]="000000100001011111110010111010111100000010111100000010011100000000100001011110100111000111100111000000100000000010";
cout << "Start decoding Galileo I/NAV " << endl;
if(page[0]=='1') // if page is odd
{
strcpy(page_Odd, page);
//cout << "Page Odd " << endl << page_Odd<< endl;
if (flag_even_word_arrived==1) //to test the function and satisfy this condition the flag is INITIALIZED AT 1
{
strncpy(page_INAV, page_Even, 114); //Join pages: Even+Odd=INAV page
strncat(page_INAV, page_Odd,120);
//cout << "Page INAV Even+Odd " << endl << page_INAV << endl;
strncpy(Even_bit, &page_INAV[0], 1);
//cout << "Even bit = " << Even_bit << endl;
strncpy(Page_type_even, &page_INAV[1], 1);
//cout << "Page type even = " << Page_type_even << endl;
if(atoi(Page_type_even)==1) cout << "Alert frame "<< endl;
else cout << "Nominal Page" << endl;
strncpy(Data_k, &page_INAV[2], 112);
//cout << "Data_k " << endl << Data_k << endl;
strncpy(Odd_bit, &page_INAV[114], 1);
//cout << "Odd bit: " << Odd_bit << endl;
strncpy(Page_type_Odd, &page_INAV[115], 1);
//cout << "Page_type_Odd: " << Page_type_Odd << endl;
strncpy(Data_j, &page_INAV[116], 16);
//cout << "Data_j: " << endl << Data_j << endl;
strncpy(Reserved_1, &page_INAV[132], 40);
strncpy(SAR, &page_INAV[172], 22);
strncpy(Spare, &page_INAV[194], 2);
strncpy(CRC_data, &page_INAV[196], 24);
strncpy(Reserved_2, &page_INAV[220], 8);
strncpy(Tail_odd, &page_INAV[228], 6);
//cout << "tail odd: " << endl << Tail_odd << endl;
if(strcmp (Tail_odd,correct_tail) != 0)
cout << "Tail odd is not correct!" << endl;
else cout<<"Tail odd is correct!"<> 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);
cout << "Page number (first 6 bits of Data k converted to decimal) = " << Page_type << endl;
strncpy(Data_jk_ephemeris, Data_k, 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*/
//cout<<"Data j k ephemeris" << endl << Data_jk_ephemeris << endl;
page_jk_decoder(Data_jk_ephemeris); // Corresponding to ephemeris_decode.m in matlab code
flag_even_word_arrived=0;
}
} /*if(page[0]=='1') */
else{
cout << "Page Even" << endl;
strncpy(page_Even, &page[0], 114);
//cout << page_Even << endl;
strncpy(tail_Even, &page[114], 6);
if(strcmp (tail_Even,correct_tail) != 0)
cout << "Tail even is not correct!" << endl;
else cout<<"Tail even is correct!"<> str;
std::bitset data_jk_bits (str);
//cout << "Data_jk_bits (bitset) "<< endl << data_jk_bits << endl;
page_number = (int)read_navigation_unsigned(data_jk_bits, PAGE_TYPE_bit);
cout << "Page number (for the test it must return page 1) = " << 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_page1);
cout<<"IOD_nav_1= "<< IOD_nav_1 < subframe_bits;
std::bitset word_bits;
for (int i=0; i<10; i++)
{
memcpy(&gps_word, &subframe[i*4], sizeof(char)*4);
word_bits = std::bitset<(GPS_WORD_BITS+2)>(gps_word);
for (int j=0; j