1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-11-17 15:24:56 +00:00
gnss-sdr/src/main/main.cc

185 lines
6.2 KiB
C++
Raw Normal View History

2014-04-25 20:00:09 +00:00
/*!
* \file main.cc
* \brief Main file of the GNSS-SDR program.
* \author Carlos Aviles, 2010. carlos.avilesr(at)googlemail.com
*
* It sets up the logging system, creates a ControlThread object,
* makes it run, and releases memory back when the main thread has ended.
*
* -------------------------------------------------------------------------
*
2015-01-08 18:49:59 +00:00
* Copyright (C) 2010-2015 (see AUTHORS file for a list of contributors)
2014-04-25 20:00:09 +00:00
*
* 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_VERSION
#define GNSS_SDR_VERSION "0.0.7"
2014-04-25 20:00:09 +00:00
#endif
2015-05-23 09:20:26 +00:00
#ifndef GOOGLE_STRIP_LOG
#define GOOGLE_STRIP_LOG 0
#endif
2014-04-25 20:00:09 +00:00
#include <ctime>
#include <cstdlib>
2014-04-25 20:00:09 +00:00
#include <memory>
#include <queue>
#include <boost/exception/diagnostic_information.hpp>
#include <boost/exception_ptr.hpp>
#include <boost/filesystem.hpp>
2015-01-09 12:47:52 +00:00
#include <boost/thread.hpp>
2014-04-25 20:00:09 +00:00
#include <gflags/gflags.h>
#include <glog/logging.h>
#include <gnuradio/msg_queue.h>
#include "control_thread.h"
#include "concurrent_queue.h"
#include "concurrent_map.h"
#include "gps_ephemeris.h"
#include "gps_cnav_ephemeris.h"
2014-04-25 20:00:09 +00:00
#include "gps_almanac.h"
#include "gps_iono.h"
#include "gps_cnav_iono.h"
2014-04-25 20:00:09 +00:00
#include "gps_utc_model.h"
#include "galileo_ephemeris.h"
#include "galileo_almanac.h"
#include "galileo_iono.h"
#include "galileo_utc_model.h"
#include "sbas_telemetry_data.h"
#include "sbas_ionospheric_correction.h"
#include "sbas_satellite_correction.h"
#include "sbas_ephemeris.h"
#include "sbas_time.h"
#if CUDA_GPU_ACCEL
2016-05-02 21:46:30 +00:00
// For the CUDA runtime routines (prefixed with "cuda_")
#include <cuda_runtime.h>
#endif
2014-04-25 20:00:09 +00:00
using google::LogMessage;
DECLARE_string(log_dir);
/*
* Concurrent queues that communicates the Telemetry Decoder
* to the Observables modules
*/
// For GPS NAVIGATION (L1)
concurrent_queue<Gps_Acq_Assist> global_gps_acq_assist_queue;
concurrent_map<Gps_Acq_Assist> global_gps_acq_assist_map;
int main(int argc, char** argv)
{
const std::string intro_help(
std::string("\nGNSS-SDR is an Open Source GNSS Software Defined Receiver\n")
+
2015-01-08 18:49:59 +00:00
"Copyright (C) 2010-2015 (see AUTHORS file for a list of contributors)\n"
+
"This program comes with ABSOLUTELY NO WARRANTY;\n"
+
"See COPYING file to see a copy of the General Public License\n \n");
2014-04-10 20:26:39 +00:00
const std::string gnss_sdr_version(GNSS_SDR_VERSION);
google::SetUsageMessage(intro_help);
2014-04-10 20:26:39 +00:00
google::SetVersionString(gnss_sdr_version);
google::ParseCommandLineFlags(&argc, &argv, true);
2014-04-10 20:26:39 +00:00
std::cout << "Initializing GNSS-SDR v" << gnss_sdr_version << " ... Please wait." << std::endl;
2015-09-01 22:38:46 +00:00
#if CUDA_GPU_ACCEL
// Reset the device
// cudaDeviceReset causes the driver to clean up all state. While
// not mandatory in normal operation, it is good practice. It is also
// needed to ensure correct operation when the application is being
// profiled. Calling cudaDeviceReset causes all profile data to be
// flushed before the application exits
cudaDeviceReset();
std::cout << "Reset CUDA device done " << std::endl;
#endif
2015-05-23 09:20:26 +00:00
if(GOOGLE_STRIP_LOG == 0)
{
2015-05-23 09:20:26 +00:00
google::InitGoogleLogging(argv[0]);
if (FLAGS_log_dir.empty())
{
2015-05-23 09:20:26 +00:00
std::cout << "Logging will be done at "
<< boost::filesystem::temp_directory_path()
<< std::endl
<< "Use gnss-sdr --log_dir=/path/to/log to change that."
<< std::endl;
2015-05-23 09:20:26 +00:00
}
else
{
const boost::filesystem::path p (FLAGS_log_dir);
if (!boost::filesystem::exists(p))
{
2015-05-23 09:20:26 +00:00
std::cout << "The path "
<< FLAGS_log_dir
<< " does not exist, attempting to create it."
<< std::endl;
boost::system::error_code ec;
boost::filesystem::create_directory(p, ec);
if(ec != 0)
{
std::cout << "Could not create the " << FLAGS_log_dir << " folder. GNSS-SDR program ended." << std::endl;
google::ShutDownCommandLineFlags();
std::exit(0);
}
}
2015-05-23 09:20:26 +00:00
std::cout << "Logging with be done at " << FLAGS_log_dir << std::endl;
}
}
std::unique_ptr<ControlThread> control_thread(new ControlThread());
// record startup time
struct timeval tv;
gettimeofday(&tv, NULL);
long long int begin = tv.tv_sec * 1000000 + tv.tv_usec;
try
{
control_thread->run();
}
catch( boost::exception & e )
{
LOG(FATAL) << "Boost exception: " << boost::diagnostic_information(e);
}
catch(std::exception const& ex)
{
LOG(FATAL) << "STD exception: " << ex.what();
}
2015-05-23 08:04:48 +00:00
catch(...)
{
LOG(INFO) << "Unexpected catch";
}
// 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 "
2014-09-12 18:23:39 +00:00
<< (static_cast<double>(end - begin)) / 1000000.0
<< " [seconds]" << std::endl;
google::ShutDownCommandLineFlags();
std::cout << "GNSS-SDR program ended." << std::endl;
return 0;
}