From d7b014e373ca17458e636588a0da51424b8056aa Mon Sep 17 00:00:00 2001 From: Javier Arribas Date: Fri, 15 Mar 2013 18:05:37 +0000 Subject: [PATCH] Experimental GPS assistence using Secure User Plane Protocol (SUPL) initial tests. Not usable yet! git-svn-id: https://svn.code.sf.net/p/gnss-sdr/code/trunk@348 64b25241-fba3-4117-9849-534c7e92360d --- conf/gnss-sdr.conf | 26 ++- src/algorithms/PVT/adapters/gps_l1_ca_pvt.cc | 11 -- .../PVT/gnuradio_blocks/gps_l1_ca_pvt_cc.cc | 42 ++--- .../PVT/gnuradio_blocks/gps_l1_ca_pvt_cc.h | 9 - src/core/libs/gnss_sdr_supl_client.cc | 2 + src/core/libs/supl/CMakeLists.txt | 2 +- src/core/receiver/CMakeLists.txt | 3 + src/core/receiver/concurrent_map.h | 87 ++++++++++ src/core/receiver/control_thread.cc | 158 ++++++++++++++++++ src/core/receiver/control_thread.h | 20 ++- src/core/receiver/gnss_flowgraph.cc | 9 - src/core/receiver/gnss_flowgraph.h | 7 +- src/main/CMakeLists.txt | 4 + src/main/main.cc | 5 + src/tests/CMakeLists.txt | 3 + src/tests/single_test_main.cc | 7 + src/tests/test_main.cc | 6 +- 17 files changed, 334 insertions(+), 67 deletions(-) create mode 100644 src/core/receiver/concurrent_map.h diff --git a/conf/gnss-sdr.conf b/conf/gnss-sdr.conf index 88d060476..d7b3f0ced 100644 --- a/conf/gnss-sdr.conf +++ b/conf/gnss-sdr.conf @@ -17,7 +17,7 @@ ControlThread.wait_for_flowgraph=false SignalSource.implementation=File_Signal_Source ;#filename: path to file with the captured GNSS signal samples to be processed -SignalSource.filename=/Users/carlesfernandez/Desktop/captures/cap2/agilent_cap2.dat +SignalSource.filename=/media/DATALOGGER/Agilent GPS Generator/cap2/agilent_cap2.dat ;#item_type: Type and resolution for each of the signal samples. Use only gr_complex in this version. SignalSource.item_type=gr_complex @@ -165,7 +165,7 @@ Resampler.sample_freq_out=4000000 ;######### CHANNELS GLOBAL CONFIG ############ ;#count: Number of available satellite channels. -Channels.count=5 +Channels.count=8 ;#in_acquisition: Number of channels simultaneously acquiring Channels.in_acquisition=1 @@ -360,7 +360,7 @@ Acquisition8.doppler_step=250 ;######### TRACKING GLOBAL CONFIG ############ ;#implementation: Selected tracking algorithm: [GPS_L1_CA_DLL_PLL_Tracking] or [GPS_L1_CA_DLL_FLL_PLL_Tracking] -Tracking.implementation=GPS_L1_CA_DLL_FLL_PLL_Tracking +Tracking.implementation=GPS_L1_CA_DLL_PLL_Optim_Tracking ;#item_type: Type and resolution for each of the signal samples. Use only [gr_complex] in this version. Tracking.item_type=gr_complex @@ -415,17 +415,29 @@ PVT.averaging_depth=10 PVT.flag_averaging=true ;#output_rate_ms: Period between two PVT outputs. Notice that the minimum period is equal to the tracking integration time (for GPS CA L1 is 1ms) [ms] -PVT.output_rate_ms=100; +PVT.output_rate_ms=100 ;#display_rate_ms: Position console print (std::out) interval [ms]. Notice that output_rate_ms<=display_rate_ms. -PVT.display_rate_ms=500; +PVT.display_rate_ms=500 -;#dump: Enable or disable the PVT internal binary data file logging [true] or [false] -PVT.dump=false +;# RINEX, KML, and NMEA output configuration ;#dump_filename: Log path and filename without extension. Notice that PVT will add ".dat" to the binary dump and ".kml" to GoogleEarth dump. PVT.dump_filename=./PVT +;#nmea_dump_filename: NMEA log path and filename +PVT.nmea_dump_filename=./gnss_sdr_pvt.nmea; + +;#flag_nmea_tty_port: Enable or disable the NMEA log to a serial TTY port (Can be used with real hardware or virtual one) +PVT.flag_nmea_tty_port=true; + +;#nmea_dump_devname: serial device descriptor for NMEA logging +PVT.nmea_dump_devname=/dev/pts/4 + + +;#dump: Enable or disable the PVT internal binary data file logging [true] or [false] +PVT.dump=false + ;######### OUTPUT_FILTER CONFIG ############ ;# Receiver output filter: Leave this block disabled in this version OutputFilter.implementation=Null_Sink_Output_Filter diff --git a/src/algorithms/PVT/adapters/gps_l1_ca_pvt.cc b/src/algorithms/PVT/adapters/gps_l1_ca_pvt.cc index b3996e300..4f28bf4ad 100644 --- a/src/algorithms/PVT/adapters/gps_l1_ca_pvt.cc +++ b/src/algorithms/PVT/adapters/gps_l1_ca_pvt.cc @@ -38,11 +38,6 @@ #include #include -extern concurrent_queue global_gps_ephemeris_queue; -extern concurrent_queue global_gps_iono_queue; -extern concurrent_queue global_gps_utc_model_queue; -extern concurrent_queue global_gps_almanac_queue; - using google::LogMessage; GpsL1CaPvt::GpsL1CaPvt(ConfigurationInterface* configuration, @@ -83,12 +78,6 @@ GpsL1CaPvt::GpsL1CaPvt(ConfigurationInterface* configuration, // make PVT object pvt_ = gps_l1_ca_make_pvt_cc(in_streams_, queue_, dump_, dump_filename_, averaging_depth, flag_averaging, output_rate_ms, display_rate_ms,flag_nmea_tty_port,nmea_dump_filename,nmea_dump_devname); DLOG(INFO) << "pvt(" << pvt_->unique_id() << ")"; - // set the navigation msg queue; - pvt_->set_ephemeris_queue(&global_gps_ephemeris_queue); - pvt_->set_iono_queue(&global_gps_iono_queue); - //pvt_->set_almanac_queue(&global_gps_almanac_queue); - pvt_->set_utc_model_queue(&global_gps_utc_model_queue); - DLOG(INFO) << "global navigation message queue assigned to pvt (" << pvt_->unique_id() << ")"; } diff --git a/src/algorithms/PVT/gnuradio_blocks/gps_l1_ca_pvt_cc.cc b/src/algorithms/PVT/gnuradio_blocks/gps_l1_ca_pvt_cc.cc index 8778a7c41..7be14dd50 100644 --- a/src/algorithms/PVT/gnuradio_blocks/gps_l1_ca_pvt_cc.cc +++ b/src/algorithms/PVT/gnuradio_blocks/gps_l1_ca_pvt_cc.cc @@ -42,9 +42,13 @@ #include "control_message_factory.h" #include "boost/date_time/posix_time/posix_time.hpp" #include "gnss_synchro.h" +#include "concurrent_map.h" using google::LogMessage; +extern concurrent_map global_gps_ephemeris_map; +extern concurrent_map global_gps_iono_map; +extern concurrent_map global_gps_utc_model_map; gps_l1_ca_pvt_cc_sptr gps_l1_ca_make_pvt_cc(unsigned int nchannels, gr_msg_queue_sptr queue, bool dump, std::string dump_filename, int averaging_depth, bool flag_averaging, int output_rate_ms, int display_rate_ms, bool flag_nmea_tty_port, std::string nmea_dump_filename, std::string nmea_dump_devname) @@ -156,42 +160,26 @@ int gps_l1_ca_pvt_cc::general_work (int noutput_items, gr_vector_int &ninput_ite pseudoranges[gnss_pseudoranges_iter->first] = pr; } - // ############ 1. READ EPHEMERIS FROM QUEUE ###################### // find the minimum index (nearest satellite, will be the reference) gnss_pseudoranges_iter = std::min_element(gnss_pseudoranges_map.begin(), gnss_pseudoranges_map.end(), pseudoranges_pairCompare_min); - // ############ 1.bis READ EPHEMERIS/UTC_MODE/IONO QUEUE #################### - Gps_Ephemeris gps_eph; - while (d_gps_eph_queue->try_pop(gps_eph) == true) - { - // DEBUG MESSAGE - std::cout << "New ephemeris record has arrived from SAT ID " - << gps_eph.i_satellite_PRN << " (Block " - << gps_eph.satelliteBlock[gps_eph.i_satellite_PRN] - << ")" << std::endl; - d_ls_pvt->gps_ephemeris_map[gps_eph.i_satellite_PRN] = gps_eph; - std::cout<<"SV "<try_pop(gps_utc_model) == true) - { - // DEBUG MESSAGE - std::cout << "New UTC model record has arrived "<< std::endl; + // ############ 1. READ EPHEMERIS/UTC_MODE/IONO FROM GLOBAL MAPS #### - d_ls_pvt->gps_utc_model=gps_utc_model; + d_ls_pvt->gps_ephemeris_map=global_gps_ephemeris_map.get_map_copy(); + + if (global_gps_utc_model_map.size()>0) + { + // UTC MODEL data is shared for all the GPS satellites. Read always at ID=0 + global_gps_utc_model_map.read(0,d_ls_pvt->gps_utc_model); } - Gps_Iono gps_iono; - while (d_gps_iono_queue->try_pop(gps_iono) == true) + if (global_gps_iono_map.size()>0) { - // DEBUG MESSAGE - std::cout << "New IONO record has arrived "<< std::endl; - - d_ls_pvt->gps_iono=gps_iono; + // IONO data is shared for all the GPS satellites. Read always at ID=0 + global_gps_iono_map.read(0,d_ls_pvt->gps_iono); } - - // ############ 2.bis COMPUTE THE PVT ################################ + // ############ 2 COMPUTE THE PVT ################################ if (gnss_pseudoranges_map.size() > 0 and d_ls_pvt->gps_ephemeris_map.size() >0) { // The GPS TX time is directly the Time of Week (TOW) associated to the current symbol of the reference channel diff --git a/src/algorithms/PVT/gnuradio_blocks/gps_l1_ca_pvt_cc.h b/src/algorithms/PVT/gnuradio_blocks/gps_l1_ca_pvt_cc.h index 0482455b7..ed0107165 100644 --- a/src/algorithms/PVT/gnuradio_blocks/gps_l1_ca_pvt_cc.h +++ b/src/algorithms/PVT/gnuradio_blocks/gps_l1_ca_pvt_cc.h @@ -36,7 +36,6 @@ #include #include #include -#include "concurrent_queue.h" #include "gps_navigation_message.h" #include "gps_ephemeris.h" #include "gps_utc_model.h" @@ -78,10 +77,6 @@ private: long unsigned int d_last_sample_nav_output; Kml_Printer d_kml_dump; Nmea_Printer *d_nmea_printer; - - concurrent_queue *d_gps_eph_queue; // Navigation ephemeris queue - concurrent_queue *d_gps_utc_model_queue; // Navigation UTC model queue - concurrent_queue *d_gps_iono_queue; // Navigation UTC model queue double d_tx_time; gps_l1_ca_ls_pvt *d_ls_pvt; @@ -91,10 +86,6 @@ public: * \brief Set the queue for getting navigation messages from the GpsL1CaTelemetryDecoder */ - void set_ephemeris_queue(concurrent_queue *eph_queue){d_gps_eph_queue=eph_queue;} - void set_utc_model_queue(concurrent_queue *utc_model_queue){d_gps_utc_model_queue=utc_model_queue;} - void set_iono_queue(concurrent_queue *iono_queue){d_gps_iono_queue=iono_queue;} - int general_work (int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); //!< PVT Signal Processing }; diff --git a/src/core/libs/gnss_sdr_supl_client.cc b/src/core/libs/gnss_sdr_supl_client.cc index 8a672ca93..4ad28285e 100644 --- a/src/core/libs/gnss_sdr_supl_client.cc +++ b/src/core/libs/gnss_sdr_supl_client.cc @@ -141,6 +141,8 @@ int gnss_sdr_supl_client::get_assistance(int i_mcc, int i_mns, int i_lac, int i_ int err; ctx.p.request=request; // select assistance info request from a pre-defined set + + //std::cout<<"mcc="<. + * + * ------------------------------------------------------------------------- + */ + +#ifndef GNSS_SDR_CONCURRENT_MAP_H +#define GNSS_SDR_CONCURRENT_MAP_H + +#include + +template + + +/*! + * \brief This class implements a thread-safe std::map + * + */ +class concurrent_map +{ + typedef typename std::map::iterator Data_iterator; //iterator is ambit dependant +private: + std::map the_map; + boost::mutex the_mutex; +public: + void write(int key, Data const& data) + { + boost::mutex::scoped_lock lock(the_mutex); + the_map.insert(std::pair(key,data)); + lock.unlock(); + } + + std::map get_map_copy() + { + boost::mutex::scoped_lock lock(the_mutex); + return the_map; + lock.unlock(); + } + + int size() + { + boost::mutex::scoped_lock lock(the_mutex); + return the_map.size(); + lock.unlock(); + } + + bool read(int key, Data& p_data) + { + boost::mutex::scoped_lock lock(the_mutex); + Data_iterator data_iter; + data_iter = the_map.find(key); + if (data_iter != the_map.end()) + { + p_data= data_iter->second; + lock.unlock(); + return true; + }else{ + lock.unlock(); + return false; + } + } +}; +#endif diff --git a/src/core/receiver/control_thread.cc b/src/core/receiver/control_thread.cc index 09114cf15..2b5e1a18b 100644 --- a/src/core/receiver/control_thread.cc +++ b/src/core/receiver/control_thread.cc @@ -33,6 +33,13 @@ */ #include "control_thread.h" +#include +#include "gps_ephemeris.h" +#include "gps_iono.h" +#include "gps_utc_model.h" +#include "gps_almanac.h" +#include "concurrent_queue.h" +#include "concurrent_map.h" #include #include #include @@ -44,6 +51,16 @@ #include #include +extern concurrent_map global_gps_ephemeris_map; +extern concurrent_map global_gps_iono_map; +extern concurrent_map global_gps_utc_model_map; + +extern concurrent_queue global_gps_ephemeris_queue; +extern concurrent_queue global_gps_iono_queue; +extern concurrent_queue global_gps_utc_model_queue; +extern concurrent_queue global_gps_almanac_queue; + + using google::LogMessage; DEFINE_string(config_file, "../conf/gnss-sdr.conf", @@ -111,6 +128,11 @@ void ControlThread::run() // start the keyboard_listener thread keyboard_thread_ = boost::thread(&ControlThread::keyboard_listener, this); + //start the GNSS SV data collector thread + gps_ephemeris_data_collector_thread_ =boost::thread(&ControlThread::gps_ephemeris_data_collector, this); + gps_iono_data_collector_thread_ =boost::thread(&ControlThread::gps_iono_data_collector, this); + gps_utc_model_data_collector_thread_ =boost::thread(&ControlThread::gps_utc_model_data_collector, this); + // Main loop to read and process the control messages while (flowgraph_->running() && !stop_) { @@ -118,6 +140,10 @@ void ControlThread::run() read_control_messages(); if (control_messages_ != 0) process_control_messages(); } + std::cout<<"Stopping GNSS-SDR, please wait!"<stop(); LOG_AT_LEVEL(INFO) << "Flowgraph stopped"; @@ -146,6 +172,53 @@ void ControlThread::init() stop_ = false; processed_control_messages_ = 0; applied_actions_ = 0; + + // GNSS Assistance configuration + bool enable_gps_supl_assistance=configuration_->property("SUPL_gps_enabled",false); + if (enable_gps_supl_assistance==true) + //SUPL SERVER TEST. Not operational yet! + { + std::string default_acq_server="supl.nokia.com"; + std::string default_eph_server="supl.google.com"; + supl_client_ephemeris_.server_name=configuration_->property("SUPL_ephemeris_server",default_acq_server); + supl_client_acquisition_.server_name=configuration_->property("SUPL_acquisition_server",default_eph_server); + supl_client_ephemeris_.server_port=configuration_->property("SUPL_ephemeris_port",7275); + supl_client_acquisition_.server_port=configuration_->property("SUPL_acquisition_server",7275); + + supl_mcc=configuration_->property("SUPL_MCC",244); + supl_mns=configuration_->property("SUPL_MNS",5); + + std::string default_lac="0x59e2"; + std::string default_ci="0x31b0"; + try { + supl_lac = boost::lexical_cast(configuration_->property("SUPL_LAC",default_lac)); + } catch(boost::bad_lexical_cast &) { + supl_lac=0x59e2; + } + try { + supl_ci = boost::lexical_cast(configuration_->property("SUPL_CI",default_ci)); + } catch(boost::bad_lexical_cast &) { + supl_ci=0x31b0; + } + + supl_client_ephemeris_.request=0; + int error=supl_client_ephemeris_.get_assistance(supl_mcc,supl_mns,supl_lac,supl_ci); + if (error==0) + { + std::cout<< "Try read ephemeris from GPS ephemeris data queue"<::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<<"Received Ephemeris for SV "<first< gps_eph_old.i_GPS_week) + { + global_gps_ephemeris_map.write(gps_eph.i_satellite_PRN,gps_eph); + }else{ + if (gps_eph.d_TOW>gps_eph_old.d_TOW) + { + global_gps_ephemeris_map.write(gps_eph.i_satellite_PRN,gps_eph); + }else{ + std::cout<<"not updating the existing ephemeris"< #include #include "control_message_factory.h" -#include +#include "gnss_sdr_supl_client.h" class GNSSFlowgraph; class ConfigurationInterface; @@ -104,9 +105,23 @@ public: private: + + /*! + * \brief SUPL assistance classes + */ + 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). + void init(); void read_control_messages(); void process_control_messages(); + void gps_ephemeris_data_collector(); + void gps_utc_model_data_collector(); + void gps_iono_data_collector(); void apply_action(unsigned int what); GNSSFlowgraph *flowgraph_; ConfigurationInterface *configuration_; @@ -118,6 +133,9 @@ private: unsigned int processed_control_messages_; unsigned int applied_actions_; boost::thread keyboard_thread_; + boost::thread gps_ephemeris_data_collector_thread_; + boost::thread gps_iono_data_collector_thread_; + boost::thread gps_utc_model_data_collector_thread_; void keyboard_listener(); }; diff --git a/src/core/receiver/gnss_flowgraph.cc b/src/core/receiver/gnss_flowgraph.cc index 6a514551c..c0fec607e 100644 --- a/src/core/receiver/gnss_flowgraph.cc +++ b/src/core/receiver/gnss_flowgraph.cc @@ -632,12 +632,3 @@ void GNSSFlowgraph::set_channels_state() << std::endl; } } - - - -void GNSSFlowgraph::apply_action(unsigned int what) -{ - DLOG(INFO) << "Applied action " << what << " to flowgraph"; - applied_actions_++; -} - diff --git a/src/core/receiver/gnss_flowgraph.h b/src/core/receiver/gnss_flowgraph.h index 7d632e350..6f4b0257a 100644 --- a/src/core/receiver/gnss_flowgraph.h +++ b/src/core/receiver/gnss_flowgraph.h @@ -114,8 +114,13 @@ public: private: void init(); - void apply_action(unsigned int what); + /*! + * \brief Populates the SV PRN list available for acquisition and tracking + */ void set_signals_list(); + /*! + * \brief Initializes the channels state (start acquisition or keep stanby) using the configuration parameters (number of channels and max channels in acquisition) + */ void set_channels_state(); bool connected_; bool running_; diff --git a/src/main/CMakeLists.txt b/src/main/CMakeLists.txt index 2fc5a62f6..067c939cc 100644 --- a/src/main/CMakeLists.txt +++ b/src/main/CMakeLists.txt @@ -21,6 +21,10 @@ include_directories( ${CMAKE_SOURCE_DIR}/src/core/system_parameters ${CMAKE_SOURCE_DIR}/src/core/interfaces ${CMAKE_SOURCE_DIR}/src/core/receiver + ${CMAKE_SOURCE_DIR}/src/core/libs + ${CMAKE_SOURCE_DIR}/src/core/libs/supl + ${CMAKE_SOURCE_DIR}/src/core/libs/supl/asn-rrlp + ${CMAKE_SOURCE_DIR}/src/core/libs/supl/asn-supl ${GLOG_INCLUDE_DIRS} ${GFlags_INCLUDE_DIRS} ${GNURADIO_CORE_INCLUDE_DIRS} diff --git a/src/main/main.cc b/src/main/main.cc index bf4778950..6be6d8c7f 100644 --- a/src/main/main.cc +++ b/src/main/main.cc @@ -44,6 +44,7 @@ #include #include #include "concurrent_queue.h" +#include "concurrent_map.h" #include "gps_navigation_message.h" #include "gps_ephemeris.h" #include "gps_almanac.h" @@ -71,6 +72,10 @@ concurrent_queue global_gps_iono_queue; concurrent_queue global_gps_utc_model_queue; concurrent_queue global_gps_almanac_queue; +concurrent_map global_gps_ephemeris_map; +concurrent_map global_gps_iono_map; +concurrent_map global_gps_utc_model_map; + int main(int argc, char** argv) { diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 51c6fcf5d..e78a03637 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -65,6 +65,9 @@ include_directories( ${CMAKE_SOURCE_DIR}/src/core/interfaces ${CMAKE_SOURCE_DIR}/src/core/receiver ${CMAKE_SOURCE_DIR}/src/core/libs + ${CMAKE_SOURCE_DIR}/src/core/libs/supl + ${CMAKE_SOURCE_DIR}/src/core/libs/supl/asn-rrlp + ${CMAKE_SOURCE_DIR}/src/core/libs/supl/asn-supl ${CMAKE_SOURCE_DIR}/src/algorithms/libs ${CMAKE_SOURCE_DIR}/src/algorithms/resampler/gnuradio_blocks ${CMAKE_SOURCE_DIR}/src/algorithms/channel/adapters diff --git a/src/tests/single_test_main.cc b/src/tests/single_test_main.cc index c51478dd3..0fa895213 100644 --- a/src/tests/single_test_main.cc +++ b/src/tests/single_test_main.cc @@ -32,6 +32,7 @@ #include #include #include +#include "concurrent_map.h" #include #include #include @@ -42,11 +43,17 @@ #include "concurrent_queue.h" #include "gps_navigation_message.h" + +concurrent_queue global_gps_ephemeris_queue2; concurrent_queue global_gps_ephemeris_queue; concurrent_queue global_gps_iono_queue; concurrent_queue global_gps_utc_model_queue; concurrent_queue global_gps_almanac_queue; +concurrent_map global_gps_ephemeris_map; +concurrent_map global_gps_iono_map; +concurrent_map global_gps_utc_model_map; + int main(int argc, char **argv) { google::ParseCommandLineFlags(&argc, &argv, true); diff --git a/src/tests/test_main.cc b/src/tests/test_main.cc index b08bd307c..b3c5267ad 100644 --- a/src/tests/test_main.cc +++ b/src/tests/test_main.cc @@ -42,6 +42,7 @@ #include #include #include "concurrent_queue.h" +#include "concurrent_map.h" #include "gps_navigation_message.h" #include "control_thread.h" @@ -67,11 +68,14 @@ #include "gnuradio_block/direct_resampler_conditioner_cc_test.cc" #include "string_converter/string_converter_test.cc" - +concurrent_queue global_gps_ephemeris_queue2; concurrent_queue global_gps_ephemeris_queue; concurrent_queue global_gps_iono_queue; concurrent_queue global_gps_utc_model_queue; concurrent_queue global_gps_almanac_queue; +concurrent_map global_gps_ephemeris_map; +concurrent_map global_gps_iono_map; +concurrent_map global_gps_utc_model_map; int main(int argc, char **argv)