1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-14 20:20:35 +00:00

Added CRC 24 checksum algorithm for Galileo INAV frames

git-svn-id: https://svn.code.sf.net/p/gnss-sdr/code/trunk@402 64b25241-fba3-4117-9849-534c7e92360d
This commit is contained in:
Javier Arribas 2013-08-14 16:10:24 +00:00
parent 05f09d1570
commit ad6210a900
3 changed files with 70 additions and 3 deletions

View File

@ -65,6 +65,8 @@ const int GALILEO_INAV_INTERLEAVER_COLS = 30;
const int GALILEO_PAGE_TYPE_BITS = 6; const int GALILEO_PAGE_TYPE_BITS = 6;
const int GALILEO_DATA_JK_BITS =128; const int GALILEO_DATA_JK_BITS =128;
const int GALILEO_DATA_FRAME_BITS =196;
const int GALILEO_DATA_FRAME_BYTES =25;
const std::vector<std::pair<int,int>> type({{1,6}}); const std::vector<std::pair<int,int>> type({{1,6}});
const std::vector<std::pair<int,int>> PAGE_TYPE_bit({{1,6}});; const std::vector<std::pair<int,int>> PAGE_TYPE_bit({{1,6}});;

View File

@ -30,13 +30,20 @@
*/ */
#include "galileo_navigation_message.h" #include "galileo_navigation_message.h"
#include "boost/date_time/posix_time/posix_time.hpp" #include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/crc.hpp> // for boost::crc_basic, boost::crc_optimal
#include <boost/dynamic_bitset.hpp>
#include <iostream> #include <iostream>
#include <cstring> #include <cstring>
#include <string> #include <string>
using namespace std; using namespace std;
typedef boost::crc_optimal<24, 0x1864CFBu, 0x0, 0x0, false, false> CRC_Galileo_INAV_type;
void Galileo_Navigation_Message::reset() void Galileo_Navigation_Message::reset()
{ {
flag_even_word = 0; flag_even_word = 0;
@ -188,6 +195,37 @@ Galileo_Navigation_Message::Galileo_Navigation_Message()
reset(); reset();
} }
bool Galileo_Navigation_Message::CRC_test(std::bitset<GALILEO_DATA_FRAME_BITS> 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<unsigned char> frame_bits(std::string(bits.to_string()));
std::vector<unsigned char> 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<GALILEO_DATA_JK_BITS> bits, const std::vector<std::pair<int,int> > parameter) unsigned long int Galileo_Navigation_Message::read_navigation_unsigned(std::bitset<GALILEO_DATA_JK_BITS> bits, const std::vector<std::pair<int,int> > parameter)
{ {
unsigned long int value = 0; unsigned long int value = 0;
@ -312,6 +350,10 @@ bool Galileo_Navigation_Message::read_navigation_bool(std::bitset<GALILEO_DATA_J
void Galileo_Navigation_Message::split_page(const char *page, int flag_even_word){ 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 << "--------------------------------------------------------------------------" << endl;
cout << "Entered in Galileo_Navigation_Message::split_page(char *page)" << endl << endl;; cout << "Entered in Galileo_Navigation_Message::split_page(char *page)" << endl << endl;;
@ -323,6 +365,7 @@ void Galileo_Navigation_Message::split_page(const char *page, int flag_even_word
char Reserved_1[40]={'\0'}; char Reserved_1[40]={'\0'};
char SAR[22]={'\0'}; char SAR[22]={'\0'};
char Spare[2]={'\0'}; char Spare[2]={'\0'};
char CRC_data[24]={'\0'}; char CRC_data[24]={'\0'};
char Reserved_2[8]={'\0'}; char Reserved_2[8]={'\0'};
char Tail_odd[6]={'\0'}; char Tail_odd[6]={'\0'};
@ -397,7 +440,27 @@ void Galileo_Navigation_Message::split_page(const char *page, int flag_even_word
std::cout << "Tail odd is not correct!" << endl; std::cout << "Tail odd is not correct!" << endl;
else std::cout<<"Tail odd is correct!"<<endl; else std::cout<<"Tail odd is correct!"<<endl;
/************ CRC cycle control *********/ //************ CRC checksum control *******/
std::stringstream TLM_word_for_CRC_stream;
TLM_word_for_CRC_stream<<page_INAV;
std::string TLM_word_for_CRC;
TLM_word_for_CRC=TLM_word_for_CRC_stream.str().substr(0,GALILEO_DATA_FRAME_BITS);
std::cout <<"frame for CRC="<<TLM_word_for_CRC<<std::endl;
std::cout <<"frame length="<<TLM_word_for_CRC.length()<<std::endl;
std::bitset<GALILEO_DATA_FRAME_BITS> TLM_word_for_CRC_bits(TLM_word_for_CRC);
std::bitset<24> checksum(CRC_data);
if (CRC_test(TLM_word_for_CRC_bits,checksum.to_ulong())==true)
{
// CRC correct: Decode word
std::cout<<"CRC correct!"<<std::endl;
}else{
// CRC wrong.. discard frame
std::cout<<"CRC error!"<<std::endl;
}
//********** end of CRC checksum control ***/
strncpy(page_number_bits, &Data_k[0], 6); strncpy(page_number_bits, &Data_k[0], 6);
std::cout << "Page number bits from Data k" << endl << page_number_bits << endl; std::cout << "Page number bits from Data k" << endl << page_number_bits << endl;

View File

@ -38,7 +38,8 @@
#include <string> #include <string>
#include <algorithm> #include <algorithm>
#include <bitset> #include <bitset>
#include "boost/assign.hpp" #include <boost/assign.hpp>
#include <boost/cstdint.hpp> // for boost::uint16_t
#include <cmath> #include <cmath>
#include <utility> #include <utility>
@ -51,6 +52,7 @@ class Galileo_Navigation_Message {
private: private:
bool CRC_test(std::bitset<GALILEO_DATA_FRAME_BITS> bits,boost::uint32_t checksum);
bool read_navigation_bool(std::bitset<GALILEO_DATA_JK_BITS> bits, const std::vector<std::pair<int,int> > parameter); bool read_navigation_bool(std::bitset<GALILEO_DATA_JK_BITS> bits, const std::vector<std::pair<int,int> > parameter);
//void print_galileo_word_bytes(unsigned int GPS_word); //void print_galileo_word_bytes(unsigned int GPS_word);
unsigned long int read_navigation_unsigned(std::bitset<GALILEO_DATA_JK_BITS> bits, const std::vector< std::pair<int,int> > parameter); unsigned long int read_navigation_unsigned(std::bitset<GALILEO_DATA_JK_BITS> bits, const std::vector< std::pair<int,int> > parameter);