1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-10-29 14:37:39 +00:00

code cleaning

git-svn-id: https://svn.code.sf.net/p/gnss-sdr/code/trunk@401 64b25241-fba3-4117-9849-534c7e92360d
This commit is contained in:
Carles Fernandez
2013-08-02 16:00:12 +00:00
parent b34a85c642
commit 05f09d1570
5 changed files with 687 additions and 605 deletions

View File

@@ -135,20 +135,18 @@ void gnss_sdr_supl_client::print_assistance()
} }
} }
} }
} }
int gnss_sdr_supl_client::get_assistance(int i_mcc, int i_mns, int i_lac, int i_ci) int gnss_sdr_supl_client::get_assistance(int i_mcc, int i_mns, int i_lac, int i_ci)
{ {
// SET SUPL CLIENT INFORMATION // SET SUPL CLIENT INFORMATION
// GSM CELL PARAMETERS // GSM CELL PARAMETERS
mcc = i_mcc; mcc = i_mcc;
mns = i_mns; mns = i_mns;
lac = i_lac; lac = i_lac;
ci = i_ci; ci = i_ci;
supl_set_gsm_cell(&ctx,mcc,mns,lac,ci); supl_set_gsm_cell(&ctx, mcc, mns, lac, ci);
// PERFORM SUPL COMMUNICATION // PERFORM SUPL COMMUNICATION
char *cstr = new char[server_name.length() + 1]; char *cstr = new char[server_name.length() + 1];
@@ -159,7 +157,7 @@ int gnss_sdr_supl_client::get_assistance(int i_mcc, int i_mns, int i_lac, int i_
//std::cout<<"mcc="<<mcc<<"mns="<<mns<<"lac="<<lac<<"ci="<<ci<<std::endl; //std::cout<<"mcc="<<mcc<<"mns="<<mns<<"lac="<<lac<<"ci="<<ci<<std::endl;
err = supl_get_assist(&ctx, cstr, &assist); err = supl_get_assist(&ctx, cstr, &assist);
if (err==0) if (err == 0)
{ {
read_supl_data(); read_supl_data();
} }
@@ -186,7 +184,6 @@ void gnss_sdr_supl_client::read_supl_data()
gps_time.d_tv_sec = (double)assist.time.stamp.tv_sec; gps_time.d_tv_sec = (double)assist.time.stamp.tv_sec;
gps_time.d_tv_usec = (double)assist.time.stamp.tv_usec; gps_time.d_tv_usec = (double)assist.time.stamp.tv_usec;
gps_time.valid = true; gps_time.valid = true;
} }
// READ UTC MODEL // READ UTC MODEL
@@ -215,8 +212,7 @@ void gnss_sdr_supl_client::read_supl_data()
gps_iono.d_beta1 = (double)assist.iono.b1 * BETA_1_LSB; gps_iono.d_beta1 = (double)assist.iono.b1 * BETA_1_LSB;
gps_iono.d_beta2 = (double)assist.iono.b2 * BETA_2_LSB; gps_iono.d_beta2 = (double)assist.iono.b2 * BETA_2_LSB;
gps_iono.d_beta3 = (double)assist.iono.b3 * BETA_3_LSB; gps_iono.d_beta3 = (double)assist.iono.b3 * BETA_3_LSB;
gps_iono.valid=true; gps_iono.valid = true;
} }
// READ SV ALMANAC // READ SV ALMANAC
@@ -279,7 +275,7 @@ void gnss_sdr_supl_client::read_supl_data()
gps_eph_iterator->second.i_satellite_PRN = e->prn; gps_eph_iterator->second.i_satellite_PRN = e->prn;
// SV navigation model // SV navigation model
gps_eph_iterator->second.i_code_on_L2 = e->bits; gps_eph_iterator->second.i_code_on_L2 = e->bits;
gps_eph_iterator->second.i_SV_accuracy = e->ura;//User Range Accuracy (URA) gps_eph_iterator->second.i_SV_accuracy = e->ura; //User Range Accuracy (URA)
gps_eph_iterator->second.i_SV_health = e->health; gps_eph_iterator->second.i_SV_health = e->health;
gps_eph_iterator->second.d_IODC = (double)e->IODC; gps_eph_iterator->second.d_IODC = (double)e->IODC;
//miss P flag (1 bit) //miss P flag (1 bit)
@@ -343,8 +339,8 @@ void gnss_sdr_supl_client::read_supl_data()
} }
} }
bool gnss_sdr_supl_client::load_ephemeris_xml(const std::string file_name)
bool gnss_sdr_supl_client::load_ephemeris_xml(const std::string file_name)
{ {
try try
{ {
@@ -356,14 +352,14 @@ bool gnss_sdr_supl_client::load_ephemeris_xml(const std::string file_name)
} }
catch (std::exception& e) catch (std::exception& e)
{ {
LOG_AT_LEVEL(ERROR)<< e.what() << "File: "<< file_name; LOG_AT_LEVEL(ERROR) << e.what() << "File: " << file_name;
return false; return false;
} }
return true; return true;
} }
bool gnss_sdr_supl_client::save_ephemeris_xml(const std::string file_name)
bool gnss_sdr_supl_client::save_ephemeris_xml(const std::string file_name)
{ {
try try
{ {

View File

@@ -31,13 +31,12 @@
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
*/ */
#ifndef GNSS_SDR_VERSION #ifndef GNSS_SDR_VERSION
#define GNSS_SDR_VERSION "0.0.1" #define GNSS_SDR_VERSION "0.0.2"
#endif #endif
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/exception/diagnostic_information.hpp> #include <boost/exception/diagnostic_information.hpp>
#include <boost/exception_ptr.hpp> #include <boost/exception_ptr.hpp>
#include <gflags/gflags.h> #include <gflags/gflags.h>
#include <glog/log_severity.h> #include <glog/log_severity.h>
#include <glog/logging.h> #include <glog/logging.h>
@@ -48,17 +47,14 @@
#include <boost/thread/thread.hpp> #include <boost/thread/thread.hpp>
#include "concurrent_queue.h" #include "concurrent_queue.h"
#include "concurrent_map.h" #include "concurrent_map.h"
#include "gps_ephemeris.h" #include "gps_ephemeris.h"
#include "gps_almanac.h" #include "gps_almanac.h"
#include "gps_iono.h" #include "gps_iono.h"
#include "gps_utc_model.h" #include "gps_utc_model.h"
#include "galileo_ephemeris.h" #include "galileo_ephemeris.h"
#include "galileo_almanac.h" #include "galileo_almanac.h"
#include "galileo_iono.h" #include "galileo_iono.h"
#include "galileo_utc_model.h" #include "galileo_utc_model.h"
#include <sys/time.h> #include <sys/time.h>
#include <ctime> #include <ctime>
#include <memory> #include <memory>
@@ -153,15 +149,17 @@ int main(int argc, char** argv)
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
long long int begin = tv.tv_sec * 1000000 + tv.tv_usec; long long int begin = tv.tv_sec * 1000000 + tv.tv_usec;
try{ try
{
control_thread->run(); control_thread->run();
}catch( boost::exception & e ) }
catch( boost::exception & e )
{ {
DLOG(FATAL) << "Boost exception: " << boost::diagnostic_information(e); DLOG(FATAL) << "Boost exception: " << boost::diagnostic_information(e);
} }
catch(std::exception const& ex) catch(std::exception const& ex)
{ {
DLOG(FATAL) <<"STD exception: "<<ex.what(); DLOG(FATAL) << "STD exception: " << ex.what();
} }
// report the elapsed time // report the elapsed time
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);

View File

@@ -1,16 +1,43 @@
/*!
* \file front_end_cal.cc
* \brief Implementation of the Front-end calibration program.
* \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 <http://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/
#include <exception> #include <exception>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <gflags/gflags.h> #include <gflags/gflags.h>
#include <glog/log_severity.h> #include <glog/log_severity.h>
#include <glog/logging.h> #include <glog/logging.h>
#include <boost/thread/mutex.hpp> #include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp> #include <boost/thread/thread.hpp>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include "file_configuration.h" #include "file_configuration.h"
#include "gps_navigation_message.h" #include "gps_navigation_message.h"
#include "gps_ephemeris.h" #include "gps_ephemeris.h"
#include "gps_almanac.h" #include "gps_almanac.h"
@@ -21,7 +48,6 @@
#include <ctime> #include <ctime>
#include <memory> #include <memory>
#include <math.h> #include <math.h>
#include "front_end_cal.h" #include "front_end_cal.h"
@@ -32,33 +58,32 @@ extern concurrent_map<Gps_Almanac> global_gps_almanac_map;
extern concurrent_map<Gps_Acq_Assist> global_gps_acq_assist_map; extern concurrent_map<Gps_Acq_Assist> global_gps_acq_assist_map;
FrontEndCal::FrontEndCal() FrontEndCal::FrontEndCal()
{ {}
}
FrontEndCal::~FrontEndCal() FrontEndCal::~FrontEndCal()
{ {}
}
bool FrontEndCal::read_assistance_from_XML() bool FrontEndCal::read_assistance_from_XML()
{ {
gnss_sdr_supl_client supl_client_ephemeris_; gnss_sdr_supl_client supl_client_ephemeris_;
std::string eph_xml_filename="gps_ephemeris.xml"; std::string eph_xml_filename = "gps_ephemeris.xml";
std::cout<< "SUPL: Try read GPS ephemeris from XML file "<<eph_xml_filename<<std::endl; std::cout << "SUPL: Try read GPS ephemeris from XML file " << eph_xml_filename << std::endl;
if (supl_client_ephemeris_.load_ephemeris_xml(eph_xml_filename)==true) if (supl_client_ephemeris_.load_ephemeris_xml(eph_xml_filename) == true)
{ {
std::map<int,Gps_Ephemeris>::iterator gps_eph_iter; std::map<int,Gps_Ephemeris>::iterator gps_eph_iter;
for(gps_eph_iter = supl_client_ephemeris_.gps_ephemeris_map.begin(); for(gps_eph_iter = supl_client_ephemeris_.gps_ephemeris_map.begin();
gps_eph_iter != supl_client_ephemeris_.gps_ephemeris_map.end(); gps_eph_iter != supl_client_ephemeris_.gps_ephemeris_map.end();
gps_eph_iter++) gps_eph_iter++)
{ {
std::cout<<"SUPL: Read XML Ephemeris for GPS SV "<<gps_eph_iter->first<<std::endl; std::cout << "SUPL: Read XML Ephemeris for GPS SV " << gps_eph_iter->first << std::endl;
std::cout << "New Ephemeris record inserted with Toe="<<gps_eph_iter->second.d_Toe<<" and GPS Week="<<gps_eph_iter->second.i_GPS_week<<std::endl; std::cout << "New Ephemeris record inserted with Toe=" << gps_eph_iter->second.d_Toe << " and GPS Week=" << gps_eph_iter->second.i_GPS_week << std::endl;
global_gps_ephemeris_map.write(gps_eph_iter->second.i_satellite_PRN,gps_eph_iter->second); global_gps_ephemeris_map.write(gps_eph_iter->second.i_satellite_PRN, gps_eph_iter->second);
} }
return true; return true;
}else{ }
std::cout<< "ERROR: SUPL client error reading XML"<<std::endl; else
{
std::cout << "ERROR: SUPL client error reading XML" << std::endl;
return false; return false;
} }
} }
@@ -73,115 +98,128 @@ int FrontEndCal::Get_SUPL_Assist()
int supl_lac; // Current network LAC (Location area code),16 bits, 1-65520 are valid values. int supl_lac; // Current network LAC (Location area code),16 bits, 1-65520 are valid values.
int supl_ci; // Cell Identity (16 bits, 0-65535 are valid values). int supl_ci; // Cell Identity (16 bits, 0-65535 are valid values).
// GNSS Assistance configuration // GNSS Assistance configuration
int error=0; int error = 0;
bool enable_gps_supl_assistance=configuration_->property("GNSS-SDR.SUPL_gps_enabled",false); bool enable_gps_supl_assistance = configuration_->property("GNSS-SDR.SUPL_gps_enabled", false);
if (enable_gps_supl_assistance==true) if (enable_gps_supl_assistance == true)
//SUPL SERVER TEST. Not operational yet! //SUPL SERVER TEST. Not operational yet!
{ {
DLOG(INFO) << "SUPL RRLP GPS assistance enabled!"<<std::endl; DLOG(INFO) << "SUPL RRLP GPS assistance enabled!" << std::endl;
std::string default_acq_server="supl.nokia.com"; std::string default_acq_server = "supl.nokia.com";
std::string default_eph_server="supl.google.com"; std::string default_eph_server = "supl.google.com";
supl_client_ephemeris_.server_name=configuration_->property("GNSS-SDR.SUPL_gps_ephemeris_server",default_acq_server); supl_client_ephemeris_.server_name = configuration_->property("GNSS-SDR.SUPL_gps_ephemeris_server", default_acq_server);
supl_client_acquisition_.server_name=configuration_->property("GNSS-SDR.SUPL_gps_acquisition_server",default_eph_server); supl_client_acquisition_.server_name = configuration_->property("GNSS-SDR.SUPL_gps_acquisition_server", default_eph_server);
supl_client_ephemeris_.server_port=configuration_->property("GNSS-SDR.SUPL_gps_ephemeris_port",7275); supl_client_ephemeris_.server_port = configuration_->property("GNSS-SDR.SUPL_gps_ephemeris_port", 7275);
supl_client_acquisition_.server_port=configuration_->property("GNSS-SDR.SUPL_gps_acquisition_port",7275); supl_client_acquisition_.server_port = configuration_->property("GNSS-SDR.SUPL_gps_acquisition_port", 7275);
supl_mcc=configuration_->property("GNSS-SDR.SUPL_MCC",244); supl_mcc = configuration_->property("GNSS-SDR.SUPL_MCC", 244);
supl_mns=configuration_->property("GNSS-SDR.SUPL_MNS",5); supl_mns = configuration_->property("GNSS-SDR.SUPL_MNS", 5);
std::string default_lac="0x59e2"; std::string default_lac = "0x59e2";
std::string default_ci="0x31b0"; std::string default_ci = "0x31b0";
try { try
supl_lac = boost::lexical_cast<int>(configuration_->property("GNSS-SDR.SUPL_LAC",default_lac)); {
} catch(boost::bad_lexical_cast &) { supl_lac = boost::lexical_cast<int>(configuration_->property("GNSS-SDR.SUPL_LAC", default_lac));
supl_lac=0x59e2;
} }
try { catch(boost::bad_lexical_cast &)
supl_ci = boost::lexical_cast<int>(configuration_->property("GNSS-SDR.SUPL_CI",default_ci)); {
} catch(boost::bad_lexical_cast &) { supl_lac = 0x59e2;
supl_ci=0x31b0; }
try
{
supl_ci = boost::lexical_cast<int>(configuration_->property("GNSS-SDR.SUPL_CI", default_ci));
}
catch(boost::bad_lexical_cast &)
{
supl_ci = 0x31b0;
} }
bool SUPL_read_gps_assistance_xml=configuration_->property("GNSS-SDR.SUPL_read_gps_assistance_xml",false); bool SUPL_read_gps_assistance_xml = configuration_->property("GNSS-SDR.SUPL_read_gps_assistance_xml", false);
if (SUPL_read_gps_assistance_xml==true) if (SUPL_read_gps_assistance_xml == true)
{ {
// read assistance from file // read assistance from file
read_assistance_from_XML(); read_assistance_from_XML();
}else{ }
else
{
// Request ephemeris from SUPL server // Request ephemeris from SUPL server
supl_client_ephemeris_.request=1; supl_client_ephemeris_.request = 1;
DLOG(INFO) << "SUPL: Try read GPS ephemeris from SUPL server.."<<std::endl; DLOG(INFO) << "SUPL: Trying to read GPS ephemeris from SUPL server...";
error=supl_client_ephemeris_.get_assistance(supl_mcc,supl_mns,supl_lac,supl_ci); error = supl_client_ephemeris_.get_assistance(supl_mcc, supl_mns, supl_lac, supl_ci);
if (error==0) if (error == 0)
{ {
std::map<int,Gps_Ephemeris>::iterator gps_eph_iter; std::map<int,Gps_Ephemeris>::iterator gps_eph_iter;
for(gps_eph_iter = supl_client_ephemeris_.gps_ephemeris_map.begin(); for(gps_eph_iter = supl_client_ephemeris_.gps_ephemeris_map.begin();
gps_eph_iter != supl_client_ephemeris_.gps_ephemeris_map.end(); gps_eph_iter != supl_client_ephemeris_.gps_ephemeris_map.end();
gps_eph_iter++) gps_eph_iter++)
{ {
DLOG(INFO) <<"SUPL: Received Ephemeris for GPS SV "<<gps_eph_iter->first<<std::endl; DLOG(INFO) << "SUPL: Received Ephemeris for GPS SV " << gps_eph_iter->first;
DLOG(INFO) << "New Ephemeris record inserted with Toe="<<gps_eph_iter->second.d_Toe<<" and GPS Week="<<gps_eph_iter->second.i_GPS_week<<std::endl; DLOG(INFO) << "New Ephemeris record inserted with Toe=" << gps_eph_iter->second.d_Toe << " and GPS Week=" << gps_eph_iter->second.i_GPS_week;
global_gps_ephemeris_map.write(gps_eph_iter->second.i_satellite_PRN,gps_eph_iter->second); global_gps_ephemeris_map.write(gps_eph_iter->second.i_satellite_PRN, gps_eph_iter->second);
} }
//Save ephemeris to XML file //Save ephemeris to XML file
std::string eph_xml_filename="gps_ephemeris.xml"; std::string eph_xml_filename = "gps_ephemeris.xml";
if (supl_client_ephemeris_.save_ephemeris_xml(eph_xml_filename)==true) if (supl_client_ephemeris_.save_ephemeris_xml(eph_xml_filename) == true)
{ {
DLOG(INFO) <<"SUPL: XML Ephemeris file created"<<std::endl; DLOG(INFO) << "SUPL: XML Ephemeris file created.";
} }
}else{ }
DLOG(INFO) << "ERROR: SUPL client for Ephemeris returned "<<error<<std::endl; else
DLOG(INFO) << "Please check internet connection and SUPL server configuration"<<error<<std::endl; {
DLOG(INFO) << "ERROR: SUPL client for Ephemeris returned " << error;
DLOG(INFO) << "Please check Internet connection and SUPL server configuration" << error;
} }
// Request almanac , IONO and UTC Model // Request almanac , IONO and UTC Model
supl_client_ephemeris_.request=0; supl_client_ephemeris_.request = 0;
DLOG(INFO) << "SUPL: Try read Almanac, Iono, Utc Model, Ref Time and Ref Location from SUPL server.."<<std::endl; DLOG(INFO) << "SUPL: Try read Almanac, Iono, Utc Model, Ref Time and Ref Location from SUPL server...";
error=supl_client_ephemeris_.get_assistance(supl_mcc,supl_mns,supl_lac,supl_ci); error = supl_client_ephemeris_.get_assistance(supl_mcc, supl_mns, supl_lac, supl_ci);
if (error==0) if (error == 0)
{ {
std::map<int,Gps_Almanac>::iterator gps_alm_iter; std::map<int,Gps_Almanac>::iterator gps_alm_iter;
for(gps_alm_iter = supl_client_ephemeris_.gps_almanac_map.begin(); for(gps_alm_iter = supl_client_ephemeris_.gps_almanac_map.begin();
gps_alm_iter != supl_client_ephemeris_.gps_almanac_map.end(); gps_alm_iter != supl_client_ephemeris_.gps_almanac_map.end();
gps_alm_iter++) gps_alm_iter++)
{ {
DLOG(INFO) <<"SUPL: Received Almanac for GPS SV "<<gps_alm_iter->first<<std::endl; DLOG(INFO) << "SUPL: Received Almanac for GPS SV " << gps_alm_iter->first;
global_gps_almanac_map.write(gps_alm_iter->first,gps_alm_iter->second); global_gps_almanac_map.write(gps_alm_iter->first, gps_alm_iter->second);
} }
if (supl_client_ephemeris_.gps_iono.valid==true) if (supl_client_ephemeris_.gps_iono.valid == true)
{ {
DLOG(INFO) <<"SUPL: Received GPS Iono"<<std::endl; DLOG(INFO) << "SUPL: Received GPS Iono";
global_gps_iono_map.write(0,supl_client_ephemeris_.gps_iono); global_gps_iono_map.write(0,supl_client_ephemeris_.gps_iono);
} }
if (supl_client_ephemeris_.gps_utc.valid==true) if (supl_client_ephemeris_.gps_utc.valid == true)
{ {
DLOG(INFO) <<"SUPL: Received GPS UTC Model"<<std::endl; DLOG(INFO) << "SUPL: Received GPS UTC Model";
global_gps_utc_model_map.write(0,supl_client_ephemeris_.gps_utc); global_gps_utc_model_map.write(0, supl_client_ephemeris_.gps_utc);
} }
}else{ }
DLOG(INFO) << "ERROR: SUPL client for Almanac returned "<<error<<std::endl; else
DLOG(INFO) << "Please check internet connection and SUPL server configuration"<<error<<std::endl; {
DLOG(INFO) << "ERROR: SUPL client for Almanac returned " << error;
DLOG(INFO) << "Please check Internet connection and SUPL server configuration" << error;
} }
// Request acquisition assistance // Request acquisition assistance
supl_client_acquisition_.request=2; supl_client_acquisition_.request = 2;
DLOG(INFO) << "SUPL: Try read Acquisition assistance from SUPL server.."<<std::endl; DLOG(INFO) << "SUPL: Trying to read Acquisition assistance from SUPL server...";
error=supl_client_acquisition_.get_assistance(supl_mcc,supl_mns,supl_lac,supl_ci); error = supl_client_acquisition_.get_assistance(supl_mcc, supl_mns, supl_lac, supl_ci);
if (error==0) if (error == 0)
{ {
std::map<int,Gps_Acq_Assist>::iterator gps_acq_iter; std::map<int,Gps_Acq_Assist>::iterator gps_acq_iter;
for(gps_acq_iter = supl_client_acquisition_.gps_acq_map.begin(); for(gps_acq_iter = supl_client_acquisition_.gps_acq_map.begin();
gps_acq_iter != supl_client_acquisition_.gps_acq_map.end(); gps_acq_iter != supl_client_acquisition_.gps_acq_map.end();
gps_acq_iter++) gps_acq_iter++)
{ {
DLOG(INFO) <<"SUPL: Received Acquisition assistance for GPS SV "<<gps_acq_iter->first<<std::endl; DLOG(INFO) << "SUPL: Received Acquisition assistance for GPS SV " << gps_acq_iter->first;
DLOG(INFO) << "New acq assist record inserted"<<std::endl; DLOG(INFO) << "New acq assist record inserted";
global_gps_acq_assist_map.write(gps_acq_iter->second.i_satellite_PRN,gps_acq_iter->second); global_gps_acq_assist_map.write(gps_acq_iter->second.i_satellite_PRN, gps_acq_iter->second);
} }
}else{ }
DLOG(INFO) << "ERROR: SUPL client for Acquisition assistance returned "<<error<<std::endl; else
DLOG(INFO) << "Please check internet connection and SUPL server configuration"<<error<<std::endl; {
DLOG(INFO) << "ERROR: SUPL client for Acquisition assistance returned " << error;
DLOG(INFO) << "Please check internet connection and SUPL server configuration" << error;
} }
} }
} }
@@ -191,42 +229,51 @@ int FrontEndCal::Get_SUPL_Assist()
void FrontEndCal::set_configuration(ConfigurationInterface *configuration) void FrontEndCal::set_configuration(ConfigurationInterface *configuration)
{ {
configuration_= configuration; configuration_ = configuration;
} }
bool FrontEndCal::get_ephemeris() bool FrontEndCal::get_ephemeris()
{ {
bool read_ephemeris_from_xml=configuration_->property("GNSS-SDR.read_eph_from_xml",false); bool read_ephemeris_from_xml=configuration_->property("GNSS-SDR.read_eph_from_xml", false);
if (read_ephemeris_from_xml==true) if (read_ephemeris_from_xml == true)
{ {
std::cout<< "Trying to read ephemeris from XML file..."<<std::endl; std::cout << "Trying to read ephemeris from XML file..." << std::endl;
if (read_assistance_from_XML()==false) if (read_assistance_from_XML() == false)
{ {
std::cout<< "ERROR: Could not read Ephemeris file: Trying to get ephemeris from SUPL server.."<<std::endl; std::cout << "ERROR: Could not read Ephemeris file: Trying to get ephemeris from SUPL server..." << std::endl;
if (Get_SUPL_Assist()==1) if (Get_SUPL_Assist() == 1)
{ {
return true; return true;
}else{ }
else
{
return false; return false;
} }
}else{
return true;
} }
}else{ else
std::cout<< "Trying to read ephemeris from SUPL server..."<<std::endl;
if (Get_SUPL_Assist()==0)
{ {
return true; return true;
}else{ }
}
else
{
std::cout << "Trying to read ephemeris from SUPL server..." << std::endl;
if (Get_SUPL_Assist() == 0)
{
return true;
}
else
{
return false; return false;
} }
} }
} }
arma::vec FrontEndCal::lla2ecef(arma::vec lla) arma::vec FrontEndCal::lla2ecef(arma::vec lla)
{ {
// WGS84 flattening // WGS84 flattening
double f; double f;
f = 1/298.257223563; f = 1/298.257223563;
@@ -235,148 +282,143 @@ arma::vec FrontEndCal::lla2ecef(arma::vec lla)
double R; double R;
R = 6378137; R = 6378137;
double phi,lambda; double phi, lambda;
arma::vec ellipsoid="0.0 0.0"; arma::vec ellipsoid = "0.0 0.0";
phi=(lla(0)/360.0)*GPS_TWO_PI; phi = (lla(0)/360.0) * GPS_TWO_PI;
lambda=(lla(1)/360.0)*GPS_TWO_PI; lambda = (lla(1)/360.0) * GPS_TWO_PI;
ellipsoid(0)=R; ellipsoid(0) = R;
ellipsoid(1)=sqrt(1-(1-f)*(1-f)); ellipsoid(1) = sqrt(1-(1-f)*(1-f));
arma::vec ecef="0.0 0.0 0.0 0.0"; arma::vec ecef = "0.0 0.0 0.0 0.0";
ecef = geodetic2ecef(phi, lambda,lla(3),ellipsoid); ecef = geodetic2ecef(phi, lambda, lla(3), ellipsoid);
return ecef; return ecef;
} }
arma::vec FrontEndCal::geodetic2ecef(double phi, double lambda, double h, arma::vec ellipsoid) arma::vec FrontEndCal::geodetic2ecef(double phi, double lambda, double h, arma::vec ellipsoid)
{ {
double a; double a;
a = ellipsoid(0); a = ellipsoid(0);
double e2; double e2;
e2 = ellipsoid(1)*ellipsoid(1); e2 = ellipsoid(1)*ellipsoid(1);
double sinphi,cosphi; double sinphi, cosphi;
sinphi = sin(phi); sinphi = sin(phi);
cosphi = cos(phi); cosphi = cos(phi);
double N; double N;
N = a / sqrt(1 - e2 * sinphi*sinphi); N = a / sqrt(1 - e2 * sinphi*sinphi);
arma::vec ecef="0.0 0.0 0.0 0.0"; arma::vec ecef = "0.0 0.0 0.0 0.0";
ecef(0) = (N + h) * cosphi * cos(lambda); ecef(0) = (N + h) * cosphi * cos(lambda);
ecef(1) = (N + h) * cosphi * sin(lambda); ecef(1) = (N + h) * cosphi * sin(lambda);
ecef(2)= (N*(1 - e2) + h) * sinphi; ecef(2) = (N*(1 - e2) + h) * sinphi;
return ecef; return ecef;
} }
double FrontEndCal::estimate_doppler_from_eph(unsigned int PRN, double TOW, double lat, double lon, double height) double FrontEndCal::estimate_doppler_from_eph(unsigned int PRN, double TOW, double lat, double lon, double height)
{ {
int num_secs = 10;
int num_secs=10; double step_secs = 0.5;
double step_secs=0.5;
//Observer position ECEF //Observer position ECEF
arma::vec obs_ecef= "0.0 0.0 0.0 0.0"; arma::vec obs_ecef = "0.0 0.0 0.0 0.0";
arma::vec lla = "0.0 0.0 0.0 0.0"; arma::vec lla = "0.0 0.0 0.0 0.0";
lla(0)=lat; lla(0) = lat;
lla(1)=lon; lla(1) = lon;
lla(2)=height; lla(2) = height;
obs_ecef=lla2ecef(lla); obs_ecef = lla2ecef(lla);
//Satellite positions ECEF //Satellite positions ECEF
std::map<int,Gps_Ephemeris> eph_map; std::map<int,Gps_Ephemeris> eph_map;
eph_map=global_gps_ephemeris_map.get_map_copy(); eph_map = global_gps_ephemeris_map.get_map_copy();
std::map<int,Gps_Ephemeris>::iterator eph_it; std::map<int,Gps_Ephemeris>::iterator eph_it;
eph_it=eph_map.find(PRN); eph_it = eph_map.find(PRN);
if (eph_it!=eph_map.end()) if (eph_it!=eph_map.end())
{ {
arma::vec SV_pos_ecef = "0.0 0.0 0.0 0.0"; arma::vec SV_pos_ecef = "0.0 0.0 0.0 0.0";
double obs_time_start,obs_time_stop; double obs_time_start, obs_time_stop;
obs_time_start=TOW-num_secs/2; obs_time_start = TOW - num_secs/2;
obs_time_stop=TOW+num_secs/2; obs_time_stop = TOW + num_secs/2;
int n_points=round((obs_time_stop-obs_time_start)/step_secs); int n_points = round((obs_time_stop - obs_time_start)/step_secs);
arma::vec ranges=arma::zeros(n_points,1); arma::vec ranges = arma::zeros(n_points, 1);
double obs_time=obs_time_start; double obs_time = obs_time_start;
for (int i=0;i<n_points;i++) for (int i=0; i<n_points; i++)
{ {
eph_it->second.satellitePosition(obs_time); eph_it->second.satellitePosition(obs_time);
SV_pos_ecef(0)=eph_it->second.d_satpos_X; SV_pos_ecef(0) = eph_it->second.d_satpos_X;
SV_pos_ecef(1)=eph_it->second.d_satpos_Y; SV_pos_ecef(1) = eph_it->second.d_satpos_Y;
SV_pos_ecef(2)=eph_it->second.d_satpos_Z; SV_pos_ecef(2) = eph_it->second.d_satpos_Z;
// SV distances to observer (true range) // SV distances to observer (true range)
ranges(i)=arma::norm(SV_pos_ecef-obs_ecef,2); ranges(i) = arma::norm(SV_pos_ecef-obs_ecef, 2);
obs_time+=step_secs; obs_time += step_secs;
} }
//Observer to satellite radial velocity // Observer to satellite radial velocity
//Numeric derivative: Positive slope means that the distance from obs to // Numeric derivative: Positive slope means that the distance from obs to
//satellite is increasing // satellite is increasing
arma::vec obs_to_sat_velocity; arma::vec obs_to_sat_velocity;
obs_to_sat_velocity=(ranges.subvec(1,(n_points-1))-ranges.subvec(0,(n_points-2)))/step_secs; obs_to_sat_velocity = (ranges.subvec(1, (n_points-1)) - ranges.subvec(0, (n_points-2)))/step_secs;
//Doppler equations are formulated accounting for positive velocities if the // Doppler equations are formulated accounting for positive velocities if the
//tx and rx are aproaching to each other. So, the satellite velocity must // tx and rx are approaching to each other. So, the satellite velocity must
//be redefined as: // be redefined as:
obs_to_sat_velocity=-obs_to_sat_velocity; obs_to_sat_velocity = -obs_to_sat_velocity;
//Doppler estimation //Doppler estimation
arma::vec Doppler_Hz; arma::vec Doppler_Hz;
Doppler_Hz=(obs_to_sat_velocity/GPS_C_m_s)*GPS_L1_FREQ_HZ; Doppler_Hz = (obs_to_sat_velocity/GPS_C_m_s)*GPS_L1_FREQ_HZ;
double mean_Doppler_Hz; double mean_Doppler_Hz;
mean_Doppler_Hz=arma::mean(Doppler_Hz); mean_Doppler_Hz = arma::mean(Doppler_Hz);
return mean_Doppler_Hz; return mean_Doppler_Hz;
return 0; return 0;
}else{ }
else
{
throw(1); throw(1);
} }
} }
void FrontEndCal::GPS_L1_front_end_model_E4000(double f_bb_true_Hz,double f_bb_meas_Hz,double fs_nominal_hz, double *estimated_fs_Hz, double *estimated_f_if_Hz, double *f_osc_err_ppm )
void FrontEndCal::GPS_L1_front_end_model_E4000(double f_bb_true_Hz, double f_bb_meas_Hz, double fs_nominal_hz, double *estimated_fs_Hz, double *estimated_f_if_Hz, double *f_osc_err_ppm)
{ {
double f_osc_n = 28.8e6;
double f_osc_n=28.8e6;
//PLL registers settings (according to E4000 datasheet) //PLL registers settings (according to E4000 datasheet)
double N=109; double N = 109;
double Y=65536; double Y = 65536;
double X=26487; double X = 26487;
double R=2; double R = 2;
// Obtained RF center frequency // Obtained RF center frequency
double f_rf_pll; double f_rf_pll;
f_rf_pll=(f_osc_n*(N+X/Y))/R; f_rf_pll = (f_osc_n*(N+X/Y))/R;
// RF frequency error caused by fractional PLL roundings // RF frequency error caused by fractional PLL roundings
double f_bb_err_pll; double f_bb_err_pll;
f_bb_err_pll=GPS_L1_FREQ_HZ-f_rf_pll; f_bb_err_pll = GPS_L1_FREQ_HZ - f_rf_pll;
// Measured F_rf error // Measured F_rf error
double f_rf_err; double f_rf_err;
f_rf_err=(f_bb_meas_Hz-f_bb_true_Hz)-f_bb_err_pll; f_rf_err = (f_bb_meas_Hz - f_bb_true_Hz) - f_bb_err_pll;
double f_osc_err_hz; double f_osc_err_hz;
f_osc_err_hz=(f_rf_err*R)/(N+X/Y); f_osc_err_hz = (f_rf_err*R)/(N+X/Y);
// OJO,segun los datos gnss, la IF positiva hace disminuir la fs!! // OJO,segun los datos gnss, la IF positiva hace disminuir la fs!!
f_osc_err_hz=-f_osc_err_hz; f_osc_err_hz = -f_osc_err_hz;
*f_osc_err_ppm=f_osc_err_hz/(f_osc_n/1e6); *f_osc_err_ppm = f_osc_err_hz/(f_osc_n/1e6);
double frac; double frac;
frac=fs_nominal_hz/f_osc_n; frac = fs_nominal_hz/f_osc_n;
*estimated_fs_Hz=frac*(f_osc_n+f_osc_err_hz);
*estimated_f_if_Hz=f_rf_err;
*estimated_fs_Hz = frac*(f_osc_n + f_osc_err_hz);
*estimated_f_if_Hz = f_rf_err;
} }

View File

@@ -1,3 +1,37 @@
/*!
* \file front_end_cal.h
* \brief Interface of the Front-end calibration program.
* \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 <http://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/
#ifndef GNSS_SDR_FRONT_END_CAL_H_
#define GNSS_SDR_FRONT_END_CAL_H_
#include "concurrent_map.h" #include "concurrent_map.h"
#include "armadillo" #include "armadillo"
@@ -56,14 +90,14 @@ private:
* *
*/ */
int Get_SUPL_Assist(); int Get_SUPL_Assist();
public: public:
/*! /*!
* \brief Sets the configuration data required by get_ephemeris function * \brief Sets the configuration data required by get_ephemeris function
* *
*/ */
void set_configuration(ConfigurationInterface *configuration); void set_configuration(ConfigurationInterface *configuration);
/*! /*!
* \brief This function connects to a Secure User Location Protocol (SUPL) server to obtain * \brief This function connects to a Secure User Location Protocol (SUPL) server to obtain
* the current GPS ephemeris and GPS assistance data. It requires the configuration parameters set by * the current GPS ephemeris and GPS assistance data. It requires the configuration parameters set by
@@ -71,6 +105,7 @@ public:
* *
*/ */
bool get_ephemeris(); bool get_ephemeris();
/*! /*!
* \brief This function estimates the GPS L1 satellite Doppler frequency [Hz] using the following data: * \brief This function estimates the GPS L1 satellite Doppler frequency [Hz] using the following data:
* 1- Orbital model from the ephemeris * 1- Orbital model from the ephemeris
@@ -79,6 +114,7 @@ public:
* *
*/ */
double estimate_doppler_from_eph(unsigned int PRN, double TOW, double lat, double lon, double height); double estimate_doppler_from_eph(unsigned int PRN, double TOW, double lat, double lon, double height);
/*! /*!
* \brief This function models the Elonics E4000 + RTL2832 front-end * \brief This function models the Elonics E4000 + RTL2832 front-end
* Inputs: * Inputs:
@@ -89,7 +125,7 @@ public:
* measurements and the front-end model * measurements and the front-end model
* estimated_f_if_bb_Hz - Equivalent bb if frequency estimation based on the * estimated_f_if_bb_Hz - Equivalent bb if frequency estimation based on the
* measurements and the front-end model * measurements and the front-end model
* Front-end TUNNER Elonics E4000 + RTL2832 sampler For GPS L1 1575.42 MHz * Front-end TUNER Elonics E4000 + RTL2832 sampler For GPS L1 1575.42 MHz
* *
*/ */
void GPS_L1_front_end_model_E4000(double f_bb_true_Hz,double f_bb_meas_Hz,double fs_nominal_hz, double *estimated_fs_Hz, double *estimated_f_if_Hz, double *f_osc_err_ppm ); void GPS_L1_front_end_model_E4000(double f_bb_true_Hz,double f_bb_meas_Hz,double fs_nominal_hz, double *estimated_fs_Hz, double *estimated_f_if_Hz, double *f_osc_err_ppm );
@@ -97,3 +133,5 @@ public:
FrontEndCal(); FrontEndCal();
~FrontEndCal(); ~FrontEndCal();
}; };
#endif

View File

@@ -129,7 +129,7 @@ void wait_message()
//acquisition->reset(); //acquisition->reset();
break; break;
case 3: case 3:
stop=true; stop = true;
break; break;
default: default:
break; break;
@@ -146,12 +146,11 @@ bool front_end_capture(ConfigurationInterface *configuration)
queue = gr::msg_queue::make(0); queue = gr::msg_queue::make(0);
top_block = gr::make_top_block("Acquisition test"); top_block = gr::make_top_block("Acquisition test");
GNSSBlockInterface *source; GNSSBlockInterface *source;
source=block_factory.GetSignalSource(configuration, queue); source = block_factory.GetSignalSource(configuration, queue);
GNSSBlockInterface *conditioner; GNSSBlockInterface *conditioner;
conditioner=block_factory.GetSignalConditioner(configuration,queue); conditioner = block_factory.GetSignalConditioner(configuration,queue);
gr::block_sptr sink; gr::block_sptr sink;
sink = gr::blocks::file_sink::make(sizeof(gr_complex), "tmp_capture.dat"); sink = gr::blocks::file_sink::make(sizeof(gr_complex), "tmp_capture.dat");
@@ -160,36 +159,36 @@ bool front_end_capture(ConfigurationInterface *configuration)
long fs_in_ = configuration->property("GNSS-SDR.internal_fs_hz", 2048000); long fs_in_ = configuration->property("GNSS-SDR.internal_fs_hz", 2048000);
int samples_per_code = round(fs_in_ int samples_per_code = round(fs_in_
/ (GPS_L1_CA_CODE_RATE_HZ / GPS_L1_CA_CODE_LENGTH_CHIPS)); / (GPS_L1_CA_CODE_RATE_HZ / GPS_L1_CA_CODE_LENGTH_CHIPS));
int nsamples=samples_per_code*50; int nsamples = samples_per_code * 50;
int skip_samples=fs_in_*5; // skip 5 seconds int skip_samples = fs_in_ * 5; // skip 5 seconds
gr::block_sptr head = gr::blocks::head::make(sizeof(gr_complex), nsamples); gr::block_sptr head = gr::blocks::head::make(sizeof(gr_complex), nsamples);
gr::block_sptr skiphead = gr::blocks::skiphead::make(sizeof(gr_complex), skip_samples); gr::block_sptr skiphead = gr::blocks::skiphead::make(sizeof(gr_complex), skip_samples);
try{ try
{
source->connect(top_block); source->connect(top_block);
conditioner->connect(top_block); conditioner->connect(top_block);
top_block->connect(source->get_right_block(), 0, conditioner->get_left_block(), 0); top_block->connect(source->get_right_block(), 0, conditioner->get_left_block(), 0);
top_block->connect(conditioner->get_right_block(), 0, skiphead, 0); top_block->connect(conditioner->get_right_block(), 0, skiphead, 0);
top_block->connect(skiphead, 0,head, 0); top_block->connect(skiphead, 0, head, 0);
top_block->connect(head, 0, sink, 0); top_block->connect(head, 0, sink, 0);
top_block->run(); top_block->run();
}catch(std::exception& e) }
catch(std::exception& e)
{ {
std::cout<<"Failure connecting the GNU Radio blocks "<<e.what()<<std::endl; std::cout << "Failure connecting the GNU Radio blocks " << e.what() << std::endl;
return false; return false;
} }
delete conditioner; delete conditioner;
delete source; delete source;
return true; return true;
} }
static time_t utc_time(int week, long tow) { static time_t utc_time(int week, long tow) {
time_t t; time_t t;
@@ -203,10 +202,11 @@ static time_t utc_time(int week, long tow) {
return t; return t;
} }
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
const std::string intro_help( const std::string intro_help(
std::string("\n RTL-SDR E4000 RF fornt-end center frequency and sampling rate calibration tool that uses GPS signals\n") std::string("\n RTL-SDR E4000 RF front-end center frequency and sampling rate calibration tool that uses GPS signals\n")
+ +
"Copyright (C) 2010-2013 (see AUTHORS file for a list of contributors)\n" "Copyright (C) 2010-2013 (see AUTHORS file for a list of contributors)\n"
+ +
@@ -214,7 +214,6 @@ int main(int argc, char** argv)
+ +
"See COPYING file to see a copy of the General Public License\n \n"); "See COPYING file to see a copy of the General Public License\n \n");
google::SetUsageMessage(intro_help); google::SetUsageMessage(intro_help);
google::SetVersionString(FRONT_END_CAL_VERSION); google::SetVersionString(FRONT_END_CAL_VERSION);
google::ParseCommandLineFlags(&argc, &argv, true); google::ParseCommandLineFlags(&argc, &argv, true);
@@ -253,25 +252,29 @@ int main(int argc, char** argv)
// 1. Load configuration parameters from config file // 1. Load configuration parameters from config file
ConfigurationInterface *configuration; ConfigurationInterface *configuration;
configuration= new FileConfiguration(FLAGS_config_file); configuration = new FileConfiguration(FLAGS_config_file);
front_end_cal.set_configuration(configuration); front_end_cal.set_configuration(configuration);
// 2. Get SUPL information from server: Ephemeris record, assistance info and TOW // 2. Get SUPL information from server: Ephemeris record, assistance info and TOW
if (front_end_cal.get_ephemeris()==true) if (front_end_cal.get_ephemeris() == true)
{ {
std::cout<<"SUPL data received OK!"<<std::endl; std::cout << "SUPL data received OK!" << std::endl;
}else{ }
std::cout<<"Failure connecting to SUPL server"<<std::endl; else
{
std::cout << "Failure connecting to SUPL server" <<std::endl;
} }
// 3. Capture some front-end samples to hard disk // 3. Capture some front-end samples to hard disk
if (front_end_capture(configuration)) if (front_end_capture(configuration))
{ {
std::cout<<"Front-end RAW samples captured"<<std::endl; std::cout << "Front-end RAW samples captured" << std::endl;
}else{ }
std::cout<<"Failure capturing front-end samples"<<std::endl; else
{
std::cout << "Failure capturing front-end samples" << std::endl;
} }
// 4. Setup GNU Radio flowgraph (file_source -> Acquisition_10m) // 4. Setup GNU Radio flowgraph (file_source -> Acquisition_10m)
@@ -282,12 +285,12 @@ int main(int argc, char** argv)
top_block = gr::make_top_block("Acquisition test"); top_block = gr::make_top_block("Acquisition test");
// Satellite signal definition // Satellite signal definition
gnss_synchro=new Gnss_Synchro(); gnss_synchro = new Gnss_Synchro();
gnss_synchro->Channel_ID=0; gnss_synchro->Channel_ID = 0;
gnss_synchro->System = 'G'; gnss_synchro->System = 'G';
std::string signal = "1C"; std::string signal = "1C";
signal.copy(gnss_synchro->Signal,2,0); signal.copy(gnss_synchro->Signal, 2, 0);
gnss_synchro->PRN=1; gnss_synchro->PRN = 1;
long fs_in_ = configuration->property("GNSS-SDR.internal_fs_hz", 2048000); long fs_in_ = configuration->property("GNSS-SDR.internal_fs_hz", 2048000);
@@ -301,7 +304,6 @@ int main(int argc, char** argv)
acquisition->set_doppler_max(configuration->property("Acquisition.doppler_max", 10000)); acquisition->set_doppler_max(configuration->property("Acquisition.doppler_max", 10000));
acquisition->set_doppler_step(configuration->property("Acquisition.doppler_step", 250)); acquisition->set_doppler_step(configuration->property("Acquisition.doppler_step", 250));
gr::block_sptr source; gr::block_sptr source;
source = gr::blocks::file_source::make(sizeof(gr_complex), "tmp_capture.dat"); source = gr::blocks::file_source::make(sizeof(gr_complex), "tmp_capture.dat");
@@ -310,13 +312,14 @@ int main(int argc, char** argv)
//head_sptr->set_length(nsamples); //head_sptr->set_length(nsamples);
//head_sptr->reset(); //head_sptr->reset();
try{ try
{
acquisition->connect(top_block); acquisition->connect(top_block);
top_block->connect(source, 0, acquisition->get_left_block(), 0); top_block->connect(source, 0, acquisition->get_left_block(), 0);
}catch(std::exception& e) }
catch(std::exception& e)
{ {
std::cout<<"Failure connecting the GNU Radio blocks "<<std::endl; std::cout << "Failure connecting the GNU Radio blocks " << std::endl;
} }
// 5. Run the flowgraph // 5. Run the flowgraph
@@ -332,43 +335,45 @@ int main(int argc, char** argv)
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
long long int begin = tv.tv_sec * 1000000 + tv.tv_usec; long long int begin = tv.tv_sec * 1000000 + tv.tv_usec;
bool start_msg=true; bool start_msg = true;
for (unsigned int PRN=1;PRN<33;PRN++) for (unsigned int PRN=1; PRN<33; PRN++)
{ {
gnss_synchro->PRN=PRN; gnss_synchro->PRN = PRN;
acquisition->set_gnss_synchro(gnss_synchro); acquisition->set_gnss_synchro(gnss_synchro);
acquisition->init(); acquisition->init();
acquisition->reset(); acquisition->reset();
stop=false; stop = false;
ch_thread = boost::thread(wait_message); ch_thread = boost::thread(wait_message);
top_block->run(); top_block->run();
if (start_msg==true) if (start_msg == true)
{ {
std::cout<<"Searching for GPS Satellites in L1 band..."<<std::endl; std::cout << "Searching for GPS Satellites in L1 band..." << std::endl;
std::cout<<"["; std::cout << "[";
start_msg=false; start_msg = false;
} }
if (gnss_sync_vector.size()>0) if (gnss_sync_vector.size()>0)
{ {
std::cout<<" "<<PRN<<" "; std::cout << " " << PRN << " ";
double doppler_measurement_hz=0; double doppler_measurement_hz = 0;
for (std::vector<Gnss_Synchro>::iterator it = gnss_sync_vector.begin() ; it != gnss_sync_vector.end(); ++it) for (std::vector<Gnss_Synchro>::iterator it = gnss_sync_vector.begin() ; it != gnss_sync_vector.end(); ++it)
{ {
doppler_measurement_hz+=(*it).Acq_doppler_hz; doppler_measurement_hz += (*it).Acq_doppler_hz;
} }
doppler_measurement_hz=doppler_measurement_hz/gnss_sync_vector.size(); doppler_measurement_hz = doppler_measurement_hz/gnss_sync_vector.size();
doppler_measurements_map.insert(std::pair<int,double>(PRN,doppler_measurement_hz)); doppler_measurements_map.insert(std::pair<int,double>(PRN, doppler_measurement_hz));
}else{ }
std::cout<<" . "; else
{
std::cout << " . ";
} }
channel_internal_queue.push(3); channel_internal_queue.push(3);
ch_thread.join(); ch_thread.join();
gnss_sync_vector.clear(); gnss_sync_vector.clear();
boost::dynamic_pointer_cast<gr::blocks::file_source>(source)->seek(0,0); boost::dynamic_pointer_cast<gr::blocks::file_source>(source)->seek(0, 0);
std::cout.flush(); std::cout.flush();
} }
std::cout<<"]"<<std::endl; std::cout << "]" << std::endl;
// report the elapsed time // report the elapsed time
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
@@ -379,12 +384,12 @@ int main(int argc, char** argv)
//6. find TOW from SUPL assistance //6. find TOW from SUPL assistance
double current_TOW=0; double current_TOW = 0;
if (global_gps_ephemeris_map.size()>0) if (global_gps_ephemeris_map.size() > 0)
{ {
std::map<int,Gps_Ephemeris> Eph_map; std::map<int,Gps_Ephemeris> Eph_map;
Eph_map=global_gps_ephemeris_map.get_map_copy(); Eph_map = global_gps_ephemeris_map.get_map_copy();
current_TOW=Eph_map.begin()->second.d_TOW; current_TOW = Eph_map.begin()->second.d_TOW;
time_t t = utc_time(Eph_map.begin()->second.i_GPS_week, (long int)current_TOW); time_t t = utc_time(Eph_map.begin()->second.i_GPS_week, (long int)current_TOW);
@@ -392,9 +397,11 @@ int main(int argc, char** argv)
fprintf(stdout, " GPS Week: %ld\n", Eph_map.begin()->second.i_GPS_week); fprintf(stdout, " GPS Week: %ld\n", Eph_map.begin()->second.i_GPS_week);
fprintf(stdout, " GPS TOW: %ld %lf\n", (long int)current_TOW, (long int)current_TOW*0.08); fprintf(stdout, " GPS TOW: %ld %lf\n", (long int)current_TOW, (long int)current_TOW*0.08);
fprintf(stdout, " ~ UTC: %s", ctime(&t)); fprintf(stdout, " ~ UTC: %s", ctime(&t));
std::cout<<"Current TOW obtained from SUPL assistance = "<<current_TOW<<std::endl; std::cout << "Current TOW obtained from SUPL assistance = " << current_TOW << std::endl;
}else{ }
std::cout<<"Unable to get Ephemeris SUPL assistance. TOW is unknown!"<<std::endl; else
{
std::cout << "Unable to get Ephemeris SUPL assistance. TOW is unknown!" << std::endl;
delete configuration; delete configuration;
delete acquisition; delete acquisition;
delete gnss_synchro; delete gnss_synchro;
@@ -408,15 +415,15 @@ int main(int argc, char** argv)
double lon_deg = configuration->property("GNSS-SDR.init_longitude_deg", 2.0); double lon_deg = configuration->property("GNSS-SDR.init_longitude_deg", 2.0);
double altitude_m = configuration->property("GNSS-SDR.init_altitude_m", 100); double altitude_m = configuration->property("GNSS-SDR.init_altitude_m", 100);
std::cout<<"Reference location (defined in config file):"<<std::endl; std::cout << "Reference location (defined in config file):" << std::endl;
std::cout<<"Latitude="<<lat_deg<<" [º]"<<std::endl; std::cout << "Latitude=" << lat_deg << " [<EFBFBD>]" << std::endl;
std::cout<<"Longitude="<<lon_deg<<" [º]"<<std::endl; std::cout << "Longitude=" << lon_deg << " [<EFBFBD>]" << std::endl;
std::cout<<"Altitude="<<altitude_m<<" [m]"<<std::endl; std::cout << "Altitude=" << altitude_m << " [m]" << std::endl;
if (doppler_measurements_map.size()==0) if (doppler_measurements_map.size() == 0)
{ {
std::cout<<"Sorry, no GPS satellites detected in the front-end capture, please check the antenna setup..."<<std::endl; std::cout << "Sorry, no GPS satellites detected in the front-end capture, please check the antenna setup..." << std::endl;
delete configuration; delete configuration;
delete acquisition; delete acquisition;
delete gnss_synchro; delete gnss_synchro;
@@ -429,70 +436,71 @@ int main(int argc, char** argv)
std::map<int,double> f_fs_estimation_Hz_map; std::map<int,double> f_fs_estimation_Hz_map;
std::map<int,double> f_ppm_estimation_Hz_map; std::map<int,double> f_ppm_estimation_Hz_map;
std::cout <<std::setiosflags(std::ios::fixed)<<std::setprecision(2)<< std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(2) <<
"Doppler analysis results:"<<std::endl; "Doppler analysis results:" << std::endl;
std::cout << "SV ID Measured [Hz] Predicted [Hz]" <<std::endl; std::cout << "SV ID Measured [Hz] Predicted [Hz]" << std::endl;
for (std::map<int,double>::iterator it = doppler_measurements_map.begin() ; it != doppler_measurements_map.end(); ++it) for (std::map<int,double>::iterator it = doppler_measurements_map.begin() ; it != doppler_measurements_map.end(); ++it)
{ {
try{ try
{
double doppler_estimated_hz; double doppler_estimated_hz;
doppler_estimated_hz=front_end_cal.estimate_doppler_from_eph(it->first,current_TOW,lat_deg,lon_deg,altitude_m); doppler_estimated_hz = front_end_cal.estimate_doppler_from_eph(it->first, current_TOW, lat_deg, lon_deg, altitude_m);
std::cout << " "<<it->first<<" "<<it->second<<" "<<doppler_estimated_hz<<std::endl; std::cout << " " << it->first << " " << it->second << " " << doppler_estimated_hz << std::endl;
// 7. Compute front-end IF and sampling frequency estimation // 7. Compute front-end IF and sampling frequency estimation
// Compare with the measurements and compute clock drift using FE model // Compare with the measurements and compute clock drift using FE model
double estimated_fs_Hz, estimated_f_if_Hz,f_osc_err_ppm; double estimated_fs_Hz, estimated_f_if_Hz, f_osc_err_ppm;
front_end_cal.GPS_L1_front_end_model_E4000(doppler_estimated_hz,it->second,fs_in_, &estimated_fs_Hz, &estimated_f_if_Hz, &f_osc_err_ppm ); front_end_cal.GPS_L1_front_end_model_E4000(doppler_estimated_hz, it->second,fs_in_, &estimated_fs_Hz, &estimated_f_if_Hz, &f_osc_err_ppm );
f_if_estimation_Hz_map.insert(std::pair<int,double>(it->first,estimated_f_if_Hz)); f_if_estimation_Hz_map.insert(std::pair<int,double>(it->first,estimated_f_if_Hz));
f_fs_estimation_Hz_map.insert(std::pair<int,double>(it->first,estimated_fs_Hz)); f_fs_estimation_Hz_map.insert(std::pair<int,double>(it->first,estimated_fs_Hz));
f_ppm_estimation_Hz_map.insert(std::pair<int,double>(it->first,f_osc_err_ppm)); f_ppm_estimation_Hz_map.insert(std::pair<int,double>(it->first,f_osc_err_ppm));
}
}catch(int ex) catch(int ex)
{ {
std::cout << " "<<it->first<<" "<<it->second<<" (Eph not found)"<<std::endl; std::cout << " " << it->first << " " << it->second << " (Eph not found)" << std::endl;
} }
} }
// FINAL FE estimations // FINAL FE estimations
double mean_f_if_Hz=0; double mean_f_if_Hz = 0;
double mean_fs_Hz=0; double mean_fs_Hz = 0;
double mean_osc_err_ppm=0; double mean_osc_err_ppm = 0;
int n_elements=f_if_estimation_Hz_map.size(); int n_elements = f_if_estimation_Hz_map.size();
for (std::map<int,double>::iterator it = f_if_estimation_Hz_map.begin() ; it != f_if_estimation_Hz_map.end(); ++it) for (std::map<int,double>::iterator it = f_if_estimation_Hz_map.begin() ; it != f_if_estimation_Hz_map.end(); ++it)
{ {
mean_f_if_Hz+=(*it).second; mean_f_if_Hz += (*it).second;
mean_fs_Hz+=f_fs_estimation_Hz_map.find((*it).first)->second; mean_fs_Hz += f_fs_estimation_Hz_map.find((*it).first)->second;
mean_osc_err_ppm+=f_ppm_estimation_Hz_map.find((*it).first)->second; mean_osc_err_ppm += f_ppm_estimation_Hz_map.find((*it).first)->second;
} }
mean_f_if_Hz/=n_elements; mean_f_if_Hz /= n_elements;
mean_fs_Hz/=n_elements; mean_fs_Hz /= n_elements;
mean_osc_err_ppm/=n_elements; mean_osc_err_ppm /= n_elements;
std::cout <<std::setiosflags(std::ios::fixed)<<std::setprecision(2)<<"Parameters estimation for Elonics E4000 Front-End:"<<std::endl; std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(2) << "Parameters estimation for Elonics E4000 Front-End:" << std::endl;
std::cout<<"Sampling frequency ="<<mean_fs_Hz<<" [Hz]"<<std::endl; std::cout << "Sampling frequency =" << mean_fs_Hz << " [Hz]" << std::endl;
std::cout<<"IF bias present in baseband="<<mean_f_if_Hz<<" [Hz]"<<std::endl; std::cout << "IF bias present in baseband=" << mean_f_if_Hz << " [Hz]" << std::endl;
std::cout<<"Reference oscillator error ="<<mean_osc_err_ppm<<" [ppm]"<<std::endl; std::cout << "Reference oscillator error =" << mean_osc_err_ppm << " [ppm]" << std::endl;
std::cout <<std::setiosflags(std::ios::fixed)<<std::setprecision(2)<<
"Corrected Doppler vs. Predicted"<<std::endl;
std::cout << "SV ID Corrected [Hz] Predicted [Hz]" <<std::endl;
std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(2)
<< "Corrected Doppler vs. Predicted" << std::endl;
std::cout << "SV ID Corrected [Hz] Predicted [Hz]" << std::endl;
for (std::map<int,double>::iterator it = doppler_measurements_map.begin() ; it != doppler_measurements_map.end(); ++it) for (std::map<int,double>::iterator it = doppler_measurements_map.begin() ; it != doppler_measurements_map.end(); ++it)
{ {
try{ try
double doppler_estimated_hz;
doppler_estimated_hz=front_end_cal.estimate_doppler_from_eph(it->first,current_TOW,lat_deg,lon_deg,altitude_m);
std::cout << " "<<it->first<<" "<<it->second -mean_f_if_Hz<<" "<<doppler_estimated_hz<<std::endl;
}catch(int ex)
{ {
std::cout << " "<<it->first<<" "<<it->second-mean_f_if_Hz<<" (Eph not found)"<<std::endl; double doppler_estimated_hz;
doppler_estimated_hz = front_end_cal.estimate_doppler_from_eph(it->first, current_TOW, lat_deg, lon_deg, altitude_m);
std::cout << " " << it->first << " " << it->second - mean_f_if_Hz << " " << doppler_estimated_hz << std::endl;
}
catch(int ex)
{
std::cout << " " << it->first << " " << it->second - mean_f_if_Hz << " (Eph not found)" << std::endl;
} }
} }