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)
{
// SET SUPL CLIENT INFORMATION
// GSM CELL PARAMETERS
mcc = i_mcc;
mns = i_mns;
lac = i_lac;
ci = i_ci;
supl_set_gsm_cell(&ctx,mcc,mns,lac,ci);
supl_set_gsm_cell(&ctx, mcc, mns, lac, ci);
// PERFORM SUPL COMMUNICATION
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;
err = supl_get_assist(&ctx, cstr, &assist);
if (err==0)
if (err == 0)
{
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_usec = (double)assist.time.stamp.tv_usec;
gps_time.valid = true;
}
// 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_beta2 = (double)assist.iono.b2 * BETA_2_LSB;
gps_iono.d_beta3 = (double)assist.iono.b3 * BETA_3_LSB;
gps_iono.valid=true;
gps_iono.valid = true;
}
// READ SV ALMANAC
@ -279,7 +275,7 @@ void gnss_sdr_supl_client::read_supl_data()
gps_eph_iterator->second.i_satellite_PRN = e->prn;
// SV navigation model
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.d_IODC = (double)e->IODC;
//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
{
@ -356,14 +352,14 @@ bool gnss_sdr_supl_client::load_ephemeris_xml(const std::string file_name)
}
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 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
{

View File

@ -31,13 +31,12 @@
* -------------------------------------------------------------------------
*/
#ifndef GNSS_SDR_VERSION
#define GNSS_SDR_VERSION "0.0.1"
#define GNSS_SDR_VERSION "0.0.2"
#endif
#include <boost/filesystem.hpp>
#include <boost/exception/diagnostic_information.hpp>
#include <boost/exception_ptr.hpp>
#include <gflags/gflags.h>
#include <glog/log_severity.h>
#include <glog/logging.h>
@ -48,17 +47,14 @@
#include <boost/thread/thread.hpp>
#include "concurrent_queue.h"
#include "concurrent_map.h"
#include "gps_ephemeris.h"
#include "gps_almanac.h"
#include "gps_iono.h"
#include "gps_utc_model.h"
#include "galileo_ephemeris.h"
#include "galileo_almanac.h"
#include "galileo_iono.h"
#include "galileo_utc_model.h"
#include <sys/time.h>
#include <ctime>
#include <memory>
@ -143,7 +139,7 @@ int main(int argc, char** argv)
boost::filesystem::create_directory(p);
}
std::cout << "Logging with be done at "
<< FLAGS_log_dir << std::endl;
<< FLAGS_log_dir << std::endl;
}
std::unique_ptr<ControlThread> control_thread(new ControlThread());
@ -153,22 +149,24 @@ int main(int argc, char** argv)
gettimeofday(&tv, NULL);
long long int begin = tv.tv_sec * 1000000 + tv.tv_usec;
try{
control_thread->run();
}catch( boost::exception & e )
try
{
DLOG(FATAL) << "Boost exception: " << boost::diagnostic_information(e);
control_thread->run();
}
catch( boost::exception & e )
{
DLOG(FATAL) << "Boost exception: " << boost::diagnostic_information(e);
}
catch(std::exception const& ex)
{
DLOG(FATAL) <<"STD exception: "<<ex.what();
DLOG(FATAL) << "STD exception: " << ex.what();
}
// report the elapsed time
gettimeofday(&tv, NULL);
long long int end = tv.tv_sec * 1000000 + tv.tv_usec;
std::cout << "Total GNSS-SDR run time "
<< ((double)(end - begin))/1000000.0
<< " [seconds]" << std::endl;
<< ((double)(end - begin))/1000000.0
<< " [seconds]" << std::endl;
google::ShutDownCommandLineFlags();
std::cout << "GNSS-SDR program ended." << std::endl;

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

View File

@ -1,99 +1,137 @@
/*!
* \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 "armadillo"
class FrontEndCal
{
private:
ConfigurationInterface *configuration_;
ConfigurationInterface *configuration_;
/*!
* \brief LLA2ECEF Convert geodetic coordinates to Earth-centered Earth-fixed
* (ECEF) coordinates. P = LLA2ECEF( LLA ) converts an M-by-3 array of geodetic coordinates
* (latitude, longitude and altitude), LLA, to an M-by-3 array of ECEF
* coordinates, P. LLA is in [degrees degrees meters]. P is in meters.
* The default ellipsoid planet is WGS84. Original copyright (c) by Kai Borre.
*/
arma::vec lla2ecef(arma::vec lla);
/*!
* GEODETIC2ECEF Convert geodetic to geocentric (ECEF) coordinates
* [X, Y, Z] = GEODETIC2ECEF(PHI, LAMBDA, H, ELLIPSOID) converts geodetic
* point locations specified by the coordinate arrays PHI (geodetic
* latitude in radians), LAMBDA (longitude in radians), and H (ellipsoidal
* height) to geocentric Cartesian coordinates X, Y, and Z. The geodetic
* coordinates refer to the reference ellipsoid specified by ELLIPSOID (a
* row vector with the form [semimajor axis, eccentricity]). H must use
* the same units as the semimajor axis; X, Y, and Z will be expressed in
* these units also.
*
* The geocentric Cartesian coordinate system is fixed with respect to the
* Earth, with its origin at the center of the ellipsoid and its X-, Y-,
* and Z-axes intersecting the surface at the following points:
* PHI LAMBDA
* X-axis: 0 0 (Equator at the Prime Meridian)
* Y-axis: 0 pi/2 (Equator at 90-degrees East
* Z-axis: pi/2 0 (North Pole)
*
* A common synonym is Earth-Centered, Earth-Fixed coordinates, or ECEF.
*
* See also ECEF2GEODETIC, ECEF2LV, GEODETIC2GEOCENTRICLAT, LV2ECEF.
*
* Copyright 2004-2009 The MathWorks, Inc.
* $Revision: 1.1.6.4 $ $Date: 2009/04/15 23:34:46 $
* Reference
* ---------
* Paul R. Wolf and Bon A. Dewitt, "Elements of Photogrammetry with
* Applications in GIS," 3rd Ed., McGraw-Hill, 2000 (Appendix F-3).
*/
arma::vec geodetic2ecef(double phi, double lambda, double h, arma::vec ellipsoid);
/*!
* \brief Reads the ephemeris data from an external XML file
*
*/
bool read_assistance_from_XML();
/*!
* \brief Connects to Secure User Location Protocol (SUPL) server to obtain
* the current GPS ephemeris and GPS assistance data.
*
*/
int Get_SUPL_Assist();
/*!
* \brief LLA2ECEF Convert geodetic coordinates to Earth-centered Earth-fixed
* (ECEF) coordinates. P = LLA2ECEF( LLA ) converts an M-by-3 array of geodetic coordinates
* (latitude, longitude and altitude), LLA, to an M-by-3 array of ECEF
* coordinates, P. LLA is in [degrees degrees meters]. P is in meters.
* The default ellipsoid planet is WGS84. Original copyright (c) by Kai Borre.
*/
arma::vec lla2ecef(arma::vec lla);
/*!
* GEODETIC2ECEF Convert geodetic to geocentric (ECEF) coordinates
* [X, Y, Z] = GEODETIC2ECEF(PHI, LAMBDA, H, ELLIPSOID) converts geodetic
* point locations specified by the coordinate arrays PHI (geodetic
* latitude in radians), LAMBDA (longitude in radians), and H (ellipsoidal
* height) to geocentric Cartesian coordinates X, Y, and Z. The geodetic
* coordinates refer to the reference ellipsoid specified by ELLIPSOID (a
* row vector with the form [semimajor axis, eccentricity]). H must use
* the same units as the semimajor axis; X, Y, and Z will be expressed in
* these units also.
*
* The geocentric Cartesian coordinate system is fixed with respect to the
* Earth, with its origin at the center of the ellipsoid and its X-, Y-,
* and Z-axes intersecting the surface at the following points:
* PHI LAMBDA
* X-axis: 0 0 (Equator at the Prime Meridian)
* Y-axis: 0 pi/2 (Equator at 90-degrees East
* Z-axis: pi/2 0 (North Pole)
*
* A common synonym is Earth-Centered, Earth-Fixed coordinates, or ECEF.
*
* See also ECEF2GEODETIC, ECEF2LV, GEODETIC2GEOCENTRICLAT, LV2ECEF.
*
* Copyright 2004-2009 The MathWorks, Inc.
* $Revision: 1.1.6.4 $ $Date: 2009/04/15 23:34:46 $
* Reference
* ---------
* Paul R. Wolf and Bon A. Dewitt, "Elements of Photogrammetry with
* Applications in GIS," 3rd Ed., McGraw-Hill, 2000 (Appendix F-3).
*/
arma::vec geodetic2ecef(double phi, double lambda, double h, arma::vec ellipsoid);
/*!
* \brief Reads the ephemeris data from an external XML file
*
*/
bool read_assistance_from_XML();
/*!
* \brief Connects to Secure User Location Protocol (SUPL) server to obtain
* the current GPS ephemeris and GPS assistance data.
*
*/
int Get_SUPL_Assist();
public:
/*!
* \brief Sets the configuration data required by get_ephemeris function
*
*/
void set_configuration(ConfigurationInterface *configuration);
/*!
* \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
* set_configuration function.
*
*/
bool get_ephemeris();
/*!
* \brief Sets the configuration data required by get_ephemeris function
*
*/
void set_configuration(ConfigurationInterface *configuration);
/*!
* \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
* set_configuration function.
*
*/
bool get_ephemeris();
/*!
* \brief This function estimates the GPS L1 satellite Doppler frequency [Hz] using the following data:
* 1- Orbital model from the ephemeris
* 2- Approximate GPS Time of Week (TOW)
* 3- Approximate receiver Latitude and Longitude (WGS-84)
*
*/
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
* Inputs:
* f_bb_true_Hz - Ideal output frequency in baseband [Hz]
* f_in_bb_meas_Hz - measured output frequency in baseband [Hz]
* Outputs:
* estimated_fs_Hz - Sampling frequency estimation based on the
* measurements and the front-end model
* estimated_f_if_bb_Hz - Equivalent bb if frequency estimation based on the
* measurements and the front-end model
* Front-end TUNNER 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 );
/*!
* \brief This function estimates the GPS L1 satellite Doppler frequency [Hz] using the following data:
* 1- Orbital model from the ephemeris
* 2- Approximate GPS Time of Week (TOW)
* 3- Approximate receiver Latitude and Longitude (WGS-84)
*
*/
double estimate_doppler_from_eph(unsigned int PRN, double TOW, double lat, double lon, double height);
FrontEndCal();
~FrontEndCal();
/*!
* \brief This function models the Elonics E4000 + RTL2832 front-end
* Inputs:
* f_bb_true_Hz - Ideal output frequency in baseband [Hz]
* f_in_bb_meas_Hz - measured output frequency in baseband [Hz]
* Outputs:
* estimated_fs_Hz - Sampling frequency estimation based on the
* measurements and the front-end model
* estimated_f_if_bb_Hz - Equivalent bb if frequency estimation based on the
* measurements and the front-end model
* 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 );
FrontEndCal();
~FrontEndCal();
};
#endif

View File

@ -81,7 +81,7 @@ using google::LogMessage;
DECLARE_string(log_dir);
DEFINE_string(config_file, "../conf/front-end-cal.conf",
"Path to the file containing the configuration parameters");
"Path to the file containing the configuration parameters");
concurrent_queue<Gps_Ephemeris> global_gps_ephemeris_queue;
concurrent_queue<Gps_Iono> global_gps_iono_queue;
@ -116,24 +116,24 @@ void wait_message()
{
while (!stop)
{
int message;
channel_internal_queue.wait_and_pop(message);
//std::cout<<"Acq mesage rx="<<message<<std::endl;
switch (message)
{
case 1: // Positive acq
gnss_sync_vector.push_back(*gnss_synchro);
//acquisition->reset();
break;
case 2: // negative acq
//acquisition->reset();
break;
case 3:
stop=true;
break;
default:
break;
}
int message;
channel_internal_queue.wait_and_pop(message);
//std::cout<<"Acq mesage rx="<<message<<std::endl;
switch (message)
{
case 1: // Positive acq
gnss_sync_vector.push_back(*gnss_synchro);
//acquisition->reset();
break;
case 2: // negative acq
//acquisition->reset();
break;
case 3:
stop = true;
break;
default:
break;
}
}
}
@ -146,12 +146,11 @@ bool front_end_capture(ConfigurationInterface *configuration)
queue = gr::msg_queue::make(0);
top_block = gr::make_top_block("Acquisition test");
GNSSBlockInterface *source;
source=block_factory.GetSignalSource(configuration, queue);
source = block_factory.GetSignalSource(configuration, queue);
GNSSBlockInterface *conditioner;
conditioner=block_factory.GetSignalConditioner(configuration,queue);
conditioner = block_factory.GetSignalConditioner(configuration,queue);
gr::block_sptr sink;
sink = gr::blocks::file_sink::make(sizeof(gr_complex), "tmp_capture.dat");
@ -160,53 +159,54 @@ bool front_end_capture(ConfigurationInterface *configuration)
long fs_in_ = configuration->property("GNSS-SDR.internal_fs_hz", 2048000);
int samples_per_code = round(fs_in_
/ (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 skiphead = gr::blocks::skiphead::make(sizeof(gr_complex), skip_samples);
try{
source->connect(top_block);
conditioner->connect(top_block);
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(skiphead, 0,head, 0);
top_block->connect(head, 0, sink, 0);
top_block->run();
}catch(std::exception& e)
try
{
std::cout<<"Failure connecting the GNU Radio blocks "<<e.what()<<std::endl;
return false;
source->connect(top_block);
conditioner->connect(top_block);
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(skiphead, 0, head, 0);
top_block->connect(head, 0, sink, 0);
top_block->run();
}
catch(std::exception& e)
{
std::cout << "Failure connecting the GNU Radio blocks " << e.what() << std::endl;
return false;
}
delete conditioner;
delete source;
return true;
}
static time_t utc_time(int week, long tow) {
time_t t;
time_t t;
/* Jan 5/6 midnight 1980 - beginning of GPS time as Unix time */
t = 315964801;
/* Jan 5/6 midnight 1980 - beginning of GPS time as Unix time */
t = 315964801;
/* soon week will wrap again, uh oh... */
/* TS 44.031: GPSTOW, range 0-604799.92, resolution 0.08 sec, 23-bit presentation */
t += (1024 + week) * 604800 + tow*0.08;
/* soon week will wrap again, uh oh... */
/* TS 44.031: GPSTOW, range 0-604799.92, resolution 0.08 sec, 23-bit presentation */
t += (1024 + week) * 604800 + tow*0.08;
return t;
return t;
}
int main(int argc, char** argv)
{
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"
+
@ -214,7 +214,6 @@ int main(int argc, char** argv)
+
"See COPYING file to see a copy of the General Public License\n \n");
google::SetUsageMessage(intro_help);
google::SetVersionString(FRONT_END_CAL_VERSION);
google::ParseCommandLineFlags(&argc, &argv, true);
@ -224,12 +223,12 @@ int main(int argc, char** argv)
google::InitGoogleLogging(argv[0]);
if (FLAGS_log_dir.empty())
{
std::cout << "Logging will be done at "
std::cout << "Logging will be done at "
<< "/tmp"
<< std::endl
<< "Use front-end-cal --log_dir=/path/to/log to change that."
<< std::endl;
<< "/tmp"
<< std::endl
<< "Use front-end-cal --log_dir=/path/to/log to change that."
<< std::endl;
}
else
{
@ -237,13 +236,13 @@ int main(int argc, char** argv)
if (!boost::filesystem::exists(p))
{
std::cout << "The path "
<< FLAGS_log_dir
<< " does not exist, attempting to create it"
<< std::endl;
<< FLAGS_log_dir
<< " does not exist, attempting to create it"
<< std::endl;
boost::filesystem::create_directory(p);
}
std::cout << "Logging with be done at "
<< FLAGS_log_dir << std::endl;
<< FLAGS_log_dir << std::endl;
}
@ -253,26 +252,30 @@ int main(int argc, char** argv)
// 1. Load configuration parameters from config file
ConfigurationInterface *configuration;
configuration= new FileConfiguration(FLAGS_config_file);
configuration = new FileConfiguration(FLAGS_config_file);
front_end_cal.set_configuration(configuration);
// 2. Get SUPL information from server: Ephemeris record, assistance info and TOW
if (front_end_cal.get_ephemeris()==true)
{
std::cout<<"SUPL data received OK!"<<std::endl;
}else{
std::cout<<"Failure connecting to SUPL server"<<std::endl;
}
if (front_end_cal.get_ephemeris() == true)
{
std::cout << "SUPL data received OK!" << std::endl;
}
else
{
std::cout << "Failure connecting to SUPL server" <<std::endl;
}
// 3. Capture some front-end samples to hard disk
if (front_end_capture(configuration))
{
std::cout<<"Front-end RAW samples captured"<<std::endl;
}else{
std::cout<<"Failure capturing front-end samples"<<std::endl;
}
{
std::cout << "Front-end RAW samples captured" << std::endl;
}
else
{
std::cout << "Failure capturing front-end samples" << std::endl;
}
// 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");
// Satellite signal definition
gnss_synchro=new Gnss_Synchro();
gnss_synchro->Channel_ID=0;
gnss_synchro = new Gnss_Synchro();
gnss_synchro->Channel_ID = 0;
gnss_synchro->System = 'G';
std::string signal = "1C";
signal.copy(gnss_synchro->Signal,2,0);
gnss_synchro->PRN=1;
signal.copy(gnss_synchro->Signal, 2, 0);
gnss_synchro->PRN = 1;
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_step(configuration->property("Acquisition.doppler_step", 250));
gr::block_sptr source;
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->reset();
try{
acquisition->connect(top_block);
top_block->connect(source, 0, acquisition->get_left_block(), 0);
}catch(std::exception& e)
try
{
std::cout<<"Failure connecting the GNU Radio blocks "<<std::endl;
acquisition->connect(top_block);
top_block->connect(source, 0, acquisition->get_left_block(), 0);
}
catch(std::exception& e)
{
std::cout << "Failure connecting the GNU Radio blocks " << std::endl;
}
// 5. Run the flowgraph
@ -332,169 +335,174 @@ int main(int argc, char** argv)
gettimeofday(&tv, NULL);
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++)
{
gnss_synchro->PRN=PRN;
acquisition->set_gnss_synchro(gnss_synchro);
acquisition->init();
acquisition->reset();
stop=false;
ch_thread = boost::thread(wait_message);
top_block->run();
if (start_msg==true)
for (unsigned int PRN=1; PRN<33; PRN++)
{
std::cout<<"Searching for GPS Satellites in L1 band..."<<std::endl;
std::cout<<"[";
start_msg=false;
gnss_synchro->PRN = PRN;
acquisition->set_gnss_synchro(gnss_synchro);
acquisition->init();
acquisition->reset();
stop = false;
ch_thread = boost::thread(wait_message);
top_block->run();
if (start_msg == true)
{
std::cout << "Searching for GPS Satellites in L1 band..." << std::endl;
std::cout << "[";
start_msg = false;
}
if (gnss_sync_vector.size()>0)
{
std::cout << " " << PRN << " ";
double doppler_measurement_hz = 0;
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 = doppler_measurement_hz/gnss_sync_vector.size();
doppler_measurements_map.insert(std::pair<int,double>(PRN, doppler_measurement_hz));
}
else
{
std::cout << " . ";
}
channel_internal_queue.push(3);
ch_thread.join();
gnss_sync_vector.clear();
boost::dynamic_pointer_cast<gr::blocks::file_source>(source)->seek(0, 0);
std::cout.flush();
}
if (gnss_sync_vector.size()>0)
{
std::cout<<" "<<PRN<<" ";
double doppler_measurement_hz=0;
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=doppler_measurement_hz/gnss_sync_vector.size();
doppler_measurements_map.insert(std::pair<int,double>(PRN,doppler_measurement_hz));
}else{
std::cout<<" . ";
}
channel_internal_queue.push(3);
ch_thread.join();
gnss_sync_vector.clear();
boost::dynamic_pointer_cast<gr::blocks::file_source>(source)->seek(0,0);
std::cout.flush();
}
std::cout<<"]"<<std::endl;
std::cout << "]" << std::endl;
// report the elapsed time
gettimeofday(&tv, NULL);
long long int end = tv.tv_sec * 1000000 + tv.tv_usec;
std::cout << "Total signal acquisition run time "
<< ((double)(end - begin))/1000000.0
<< " [seconds]" << std::endl;
<< ((double)(end - begin))/1000000.0
<< " [seconds]" << std::endl;
//6. find TOW from SUPL assistance
double current_TOW=0;
if (global_gps_ephemeris_map.size()>0)
{
std::map<int,Gps_Ephemeris> Eph_map;
Eph_map=global_gps_ephemeris_map.get_map_copy();
current_TOW=Eph_map.begin()->second.d_TOW;
double current_TOW = 0;
if (global_gps_ephemeris_map.size() > 0)
{
std::map<int,Gps_Ephemeris> Eph_map;
Eph_map = global_gps_ephemeris_map.get_map_copy();
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);
fprintf(stdout, "Reference Time:\n");
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, " ~ UTC: %s", ctime(&t));
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;
delete configuration;
delete acquisition;
delete gnss_synchro;
google::ShutDownCommandLineFlags();
std::cout << "GNSS-SDR Front-end calibration program ended." << std::endl;
return 0;
}
fprintf(stdout, "Reference Time:\n");
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, " ~ UTC: %s", ctime(&t));
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;
delete configuration;
delete acquisition;
delete gnss_synchro;
google::ShutDownCommandLineFlags();
std::cout << "GNSS-SDR Front-end calibration program ended." << std::endl;
return 0;
}
//Get user position from config file (or from SUPL using GSM Cell ID)
double lat_deg = configuration->property("GNSS-SDR.init_latitude_deg", 41.0);
double lon_deg = configuration->property("GNSS-SDR.init_longitude_deg", 2.0);
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<<"Longitude="<<lon_deg<<" [º]"<<std::endl;
std::cout<<"Altitude="<<altitude_m<<" [m]"<<std::endl;
std::cout << "Latitude=" << lat_deg << " [¼]" << std::endl;
std::cout << "Longitude=" << lon_deg << " [¼]" << std::endl;
std::cout << "Altitude=" << altitude_m << " [m]" << std::endl;
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;
delete configuration;
delete acquisition;
delete gnss_synchro;
google::ShutDownCommandLineFlags();
std::cout << "GNSS-SDR Front-end calibration program ended." << std::endl;
return 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;
delete configuration;
delete acquisition;
delete gnss_synchro;
google::ShutDownCommandLineFlags();
std::cout << "GNSS-SDR Front-end calibration program ended." << std::endl;
return 0;
}
std::map<int,double> f_if_estimation_Hz_map;
std::map<int,double> f_fs_estimation_Hz_map;
std::map<int,double> f_ppm_estimation_Hz_map;
std::cout <<std::setiosflags(std::ios::fixed)<<std::setprecision(2)<<
"Doppler analysis results:"<<std::endl;
std::cout << std::setiosflags(std::ios::fixed) << std::setprecision(2) <<
"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)
{
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<<" "<<doppler_estimated_hz<<std::endl;
// 7. Compute front-end IF and sampling frequency estimation
// Compare with the measurements and compute clock drift using FE model
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 );
{
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 << " " << doppler_estimated_hz << std::endl;
// 7. Compute front-end IF and sampling frequency estimation
// Compare with the measurements and compute clock drift using FE model
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 );
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_ppm_estimation_Hz_map.insert(std::pair<int,double>(it->first,f_osc_err_ppm));
}catch(int ex)
{
std::cout << " "<<it->first<<" "<<it->second<<" (Eph not found)"<<std::endl;
}
}
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_ppm_estimation_Hz_map.insert(std::pair<int,double>(it->first,f_osc_err_ppm));
}
catch(int ex)
{
std::cout << " " << it->first << " " << it->second << " (Eph not found)" << std::endl;
}
}
// FINAL FE estimations
double mean_f_if_Hz=0;
double mean_fs_Hz=0;
double mean_osc_err_ppm=0;
int n_elements=f_if_estimation_Hz_map.size();
double mean_f_if_Hz = 0;
double mean_fs_Hz = 0;
double mean_osc_err_ppm = 0;
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)
{
mean_f_if_Hz+=(*it).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_f_if_Hz += (*it).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_f_if_Hz/=n_elements;
mean_fs_Hz/=n_elements;
mean_osc_err_ppm/=n_elements;
mean_f_if_Hz /= n_elements;
mean_fs_Hz /= 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<<"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 <<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 << "Sampling frequency =" << mean_fs_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 << 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)
{
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;
}
}
{
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;
}
}
// 8. Generate GNSS-SDR config file.