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.
|
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*
|
2018-02-18 11:23:55 +00:00
|
|
|
* Copyright (C) 2010-2018 (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
|
2018-05-13 20:49:11 +00:00
|
|
|
* along with GNSS-SDR. If not, see <https://www.gnu.org/licenses/>.
|
2014-04-25 20:00:09 +00:00
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
2018-02-18 11:23:55 +00:00
|
|
|
|
2014-04-25 20:00:09 +00:00
|
|
|
#ifndef GNSS_SDR_VERSION
|
2017-02-06 15:36:21 +00:00
|
|
|
#define GNSS_SDR_VERSION "0.0.9"
|
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
|
|
|
|
|
2018-02-26 02:15:53 +00:00
|
|
|
#include "concurrent_map.h"
|
|
|
|
#include "concurrent_queue.h"
|
|
|
|
#include "control_thread.h"
|
|
|
|
#include "gnss_sdr_flags.h"
|
2014-04-25 20:00:09 +00:00
|
|
|
#include <boost/exception/diagnostic_information.hpp>
|
|
|
|
#include <boost/exception_ptr.hpp>
|
2018-03-03 01:03:39 +00:00
|
|
|
#include <boost/filesystem/operations.hpp> // for create_directories, exists
|
|
|
|
#include <boost/filesystem/path.hpp> // for path, operator<<
|
|
|
|
#include <boost/filesystem/path_traits.hpp> // for filesystem
|
2014-04-25 20:00:09 +00:00
|
|
|
#include <glog/logging.h>
|
2018-02-26 02:15:53 +00:00
|
|
|
#include <chrono>
|
|
|
|
#include <iostream>
|
|
|
|
#include <memory>
|
|
|
|
|
2014-04-25 20:00:09 +00:00
|
|
|
|
2015-08-06 15:05:15 +00:00
|
|
|
#if CUDA_GPU_ACCEL
|
2018-03-03 01:03:39 +00:00
|
|
|
// For the CUDA runtime routines (prefixed with "cuda_")
|
|
|
|
#include <cuda_runtime.h>
|
2015-08-06 15:05:15 +00:00
|
|
|
#endif
|
|
|
|
|
2014-04-25 20:00:09 +00:00
|
|
|
|
|
|
|
using google::LogMessage;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Concurrent queues that communicates the Telemetry Decoder
|
|
|
|
* to the Observables modules
|
|
|
|
*/
|
|
|
|
|
2015-06-05 16:46:00 +00:00
|
|
|
// For GPS NAVIGATION (L1)
|
2013-03-20 18:19:26 +00:00
|
|
|
concurrent_queue<Gps_Acq_Assist> global_gps_acq_assist_queue;
|
|
|
|
concurrent_map<Gps_Acq_Assist> global_gps_acq_assist_map;
|
2013-03-15 18:05:37 +00:00
|
|
|
|
2011-10-01 18:45:20 +00:00
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
const std::string intro_help(
|
2018-03-03 01:03:39 +00:00
|
|
|
std::string("\nGNSS-SDR is an Open Source GNSS Software Defined Receiver\n") +
|
|
|
|
"Copyright (C) 2010-2018 (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");
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2014-04-10 20:26:39 +00:00
|
|
|
const std::string gnss_sdr_version(GNSS_SDR_VERSION);
|
2011-10-01 18:45:20 +00:00
|
|
|
google::SetUsageMessage(intro_help);
|
2014-04-10 20:26:39 +00:00
|
|
|
google::SetVersionString(gnss_sdr_version);
|
2011-10-01 18:45:20 +00:00
|
|
|
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;
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2018-03-03 01:03:39 +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
|
|
|
|
|
|
|
|
if (GOOGLE_STRIP_LOG == 0)
|
2011-12-28 21:36:45 +00:00
|
|
|
{
|
2015-05-23 09:20:26 +00:00
|
|
|
google::InitGoogleLogging(argv[0]);
|
|
|
|
if (FLAGS_log_dir.empty())
|
2011-12-28 21:36:45 +00:00
|
|
|
{
|
2017-08-14 11:59:00 +00:00
|
|
|
std::cout << "Logging will be written at "
|
2015-05-23 09:20:26 +00:00
|
|
|
<< boost::filesystem::temp_directory_path()
|
|
|
|
<< std::endl
|
|
|
|
<< "Use gnss-sdr --log_dir=/path/to/log to change that."
|
2015-05-19 16:20:28 +00:00
|
|
|
<< std::endl;
|
2015-05-23 09:20:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
const boost::filesystem::path p(FLAGS_log_dir);
|
2015-05-23 09:20:26 +00:00
|
|
|
if (!boost::filesystem::exists(p))
|
2015-05-19 16:20:28 +00:00
|
|
|
{
|
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;
|
2018-03-03 01:03:39 +00:00
|
|
|
if (!boost::filesystem::create_directory(p, ec))
|
2015-05-23 09:20:26 +00:00
|
|
|
{
|
|
|
|
std::cout << "Could not create the " << FLAGS_log_dir << " folder. GNSS-SDR program ended." << std::endl;
|
|
|
|
google::ShutDownCommandLineFlags();
|
2017-08-11 03:18:38 +00:00
|
|
|
return 1;
|
2015-05-23 09:20:26 +00:00
|
|
|
}
|
2015-05-19 16:20:28 +00:00
|
|
|
}
|
2017-08-14 11:59:00 +00:00
|
|
|
std::cout << "Logging will be written at " << FLAGS_log_dir << std::endl;
|
2011-12-28 21:36:45 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-27 21:21:12 +00:00
|
|
|
|
2012-02-23 19:10:48 +00:00
|
|
|
std::unique_ptr<ControlThread> control_thread(new ControlThread());
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2012-02-08 19:50:16 +00:00
|
|
|
// record startup time
|
2017-08-11 03:18:38 +00:00
|
|
|
std::chrono::time_point<std::chrono::system_clock> start, end;
|
|
|
|
start = std::chrono::system_clock::now();
|
2012-02-08 19:50:16 +00:00
|
|
|
|
2013-08-02 16:00:12 +00:00
|
|
|
try
|
2018-03-03 01:03:39 +00:00
|
|
|
{
|
2013-08-02 16:00:12 +00:00
|
|
|
control_thread->run();
|
2018-03-03 01:03:39 +00:00
|
|
|
}
|
|
|
|
catch (const boost::exception& e)
|
|
|
|
{
|
|
|
|
if (GOOGLE_STRIP_LOG == 0)
|
2017-08-25 17:17:12 +00:00
|
|
|
{
|
|
|
|
LOG(WARNING) << "Boost exception: " << boost::diagnostic_information(e);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "Boost exception: " << boost::diagnostic_information(e) << std::endl;
|
|
|
|
}
|
|
|
|
google::ShutDownCommandLineFlags();
|
|
|
|
return 1;
|
2018-03-03 01:03:39 +00:00
|
|
|
}
|
|
|
|
catch (const std::exception& ex)
|
|
|
|
{
|
|
|
|
if (GOOGLE_STRIP_LOG == 0)
|
2017-08-25 17:17:12 +00:00
|
|
|
{
|
|
|
|
LOG(WARNING) << "C++ Standard Library exception: " << ex.what();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "C++ Standard Library exception: " << ex.what() << std::endl;
|
|
|
|
}
|
|
|
|
google::ShutDownCommandLineFlags();
|
|
|
|
return 1;
|
2018-03-03 01:03:39 +00:00
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
if (GOOGLE_STRIP_LOG == 0)
|
2017-08-25 17:17:12 +00:00
|
|
|
{
|
|
|
|
LOG(WARNING) << "Unexpected catch. This should not happen.";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "Unexpected catch. This should not happen." << std::endl;
|
|
|
|
}
|
|
|
|
google::ShutDownCommandLineFlags();
|
|
|
|
return 1;
|
2018-03-03 01:03:39 +00:00
|
|
|
}
|
2017-08-11 03:18:38 +00:00
|
|
|
|
2012-02-08 19:50:16 +00:00
|
|
|
// report the elapsed time
|
2017-08-11 03:18:38 +00:00
|
|
|
end = std::chrono::system_clock::now();
|
|
|
|
std::chrono::duration<double> elapsed_seconds = end - start;
|
|
|
|
|
2017-08-11 11:11:38 +00:00
|
|
|
std::cout << "Total GNSS-SDR run time: "
|
|
|
|
<< elapsed_seconds.count()
|
2013-08-02 16:00:12 +00:00
|
|
|
<< " [seconds]" << std::endl;
|
2012-02-08 19:50:16 +00:00
|
|
|
|
2011-12-26 05:04:27 +00:00
|
|
|
google::ShutDownCommandLineFlags();
|
2012-07-02 12:45:20 +00:00
|
|
|
std::cout << "GNSS-SDR program ended." << std::endl;
|
2016-03-04 14:26:55 +00:00
|
|
|
return 0;
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|