2014-04-25 20:00:09 +00:00
|
|
|
/*!
|
2020-02-08 00:20:02 +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.
|
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2020-02-08 00:20:02 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2010-2019 (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.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2020-02-08 00:20:02 +00:00
|
|
|
*/
|
2018-02-18 11:23:55 +00:00
|
|
|
|
2014-04-25 20:00:09 +00:00
|
|
|
#ifndef GNSS_SDR_VERSION
|
2020-03-12 19:13:49 +00:00
|
|
|
#define GNSS_SDR_VERSION "0.0.12"
|
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"
|
2020-06-18 09:49:28 +00:00
|
|
|
#include "gnss_sdr_make_unique.h"
|
2018-12-09 22:07:10 +00:00
|
|
|
#include "gps_acq_assist.h"
|
2019-08-03 17:51:50 +00:00
|
|
|
#include <boost/exception/diagnostic_information.hpp> // for diagnostic_information
|
2019-03-05 07:59:04 +00:00
|
|
|
#include <boost/exception/exception.hpp> // for exception
|
|
|
|
#include <boost/thread/exceptions.hpp> // for thread_resource_error
|
2019-06-12 18:39:29 +00:00
|
|
|
#include <gflags/gflags.h> // for ShutDownCommandLineFlags
|
|
|
|
#include <glog/logging.h> // for FLAGS_log_dir
|
|
|
|
#include <chrono> // for time_point
|
|
|
|
#include <exception> // for exception
|
2020-07-07 16:53:50 +00:00
|
|
|
#include <iostream> // for operator<<
|
2019-06-12 18:39:29 +00:00
|
|
|
#include <memory> // for unique_ptr
|
|
|
|
#include <string> // for string
|
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
|
|
|
|
|
2019-06-10 19:41:13 +00:00
|
|
|
#if HAS_STD_FILESYSTEM
|
2019-06-12 18:39:29 +00:00
|
|
|
#include <system_error>
|
2019-06-10 19:41:13 +00:00
|
|
|
namespace errorlib = std;
|
2019-06-12 18:39:29 +00:00
|
|
|
#if HAS_STD_FILESYSTEM_EXPERIMENTAL
|
|
|
|
#include <experimental/filesystem>
|
|
|
|
namespace fs = std::experimental::filesystem;
|
|
|
|
#else
|
|
|
|
#include <filesystem>
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
#endif
|
2019-06-10 19:41:13 +00:00
|
|
|
#else
|
2019-06-12 18:39:29 +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
|
|
|
|
#include <boost/system/error_code.hpp> // for error_code
|
2019-06-10 19:41:13 +00:00
|
|
|
namespace fs = boost::filesystem;
|
|
|
|
namespace errorlib = boost::system;
|
|
|
|
#endif
|
2014-04-25 20:00:09 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Concurrent queues that communicates the Telemetry Decoder
|
|
|
|
* to the Observables modules
|
|
|
|
*/
|
|
|
|
|
2015-06-05 16:46:00 +00:00
|
|
|
// For GPS NAVIGATION (L1)
|
2019-02-22 09:47:24 +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") +
|
2019-02-10 20:56:40 +00:00
|
|
|
"Copyright (C) 2010-2019 (see AUTHORS file for a list of contributors)\n" +
|
2018-03-03 01:03:39 +00:00
|
|
|
"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);
|
2020-07-07 16:53:50 +00:00
|
|
|
std::cout << "Initializing GNSS-SDR v" << gnss_sdr_version << " ... Please wait.\n";
|
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();
|
2020-07-07 16:53:50 +00:00
|
|
|
std::cout << "Reset CUDA device done.\n";
|
2018-03-03 01:03:39 +00:00
|
|
|
#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 "
|
2019-06-10 19:41:13 +00:00
|
|
|
<< fs::temp_directory_path()
|
2020-07-07 16:53:50 +00:00
|
|
|
<< '\n'
|
|
|
|
<< "Use gnss-sdr --log_dir=/path/to/log to change that.\n";
|
2015-05-23 09:20:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-06-10 19:41:13 +00:00
|
|
|
const fs::path p(FLAGS_log_dir);
|
|
|
|
if (!fs::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
|
2020-07-07 16:53:50 +00:00
|
|
|
<< " does not exist, attempting to create it.\n";
|
2019-06-10 19:41:13 +00:00
|
|
|
errorlib::error_code ec;
|
|
|
|
if (!fs::create_directory(p, ec))
|
2015-05-23 09:20:26 +00:00
|
|
|
{
|
2020-07-07 16:53:50 +00:00
|
|
|
std::cerr << "Could not create the " << FLAGS_log_dir << " folder. GNSS-SDR program ended.\n";
|
2015-05-23 09:20:26 +00:00
|
|
|
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
|
|
|
}
|
2020-07-07 16:53:50 +00:00
|
|
|
std::cout << "Logging will be written at " << FLAGS_log_dir << '\n';
|
2011-12-28 21:36:45 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-27 21:21:12 +00:00
|
|
|
|
2019-08-12 22:19:31 +00:00
|
|
|
std::chrono::time_point<std::chrono::system_clock> start;
|
|
|
|
std::chrono::time_point<std::chrono::system_clock> end;
|
2017-08-11 03:18:38 +00:00
|
|
|
start = std::chrono::system_clock::now();
|
2019-02-14 21:49:36 +00:00
|
|
|
int return_code = 0;
|
2013-08-02 16:00:12 +00:00
|
|
|
try
|
2018-03-03 01:03:39 +00:00
|
|
|
{
|
2020-06-18 09:49:28 +00:00
|
|
|
auto control_thread = std::make_unique<ControlThread>();
|
2019-02-14 21:49:36 +00:00
|
|
|
// record startup time
|
|
|
|
start = std::chrono::system_clock::now();
|
2018-10-23 14:54:06 +00:00
|
|
|
return_code = control_thread->run();
|
2018-03-03 01:03:39 +00:00
|
|
|
}
|
2019-02-14 21:49:36 +00:00
|
|
|
catch (const boost::thread_resource_error& e)
|
|
|
|
{
|
2020-07-07 16:53:50 +00:00
|
|
|
std::cerr << "Failed to create boost thread.\n";
|
2019-02-14 21:49:36 +00:00
|
|
|
google::ShutDownCommandLineFlags();
|
2020-07-07 16:53:50 +00:00
|
|
|
std::cout << "GNSS-SDR program ended.\n";
|
2019-02-14 21:49:36 +00:00
|
|
|
return 1;
|
|
|
|
}
|
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);
|
2020-07-07 16:53:50 +00:00
|
|
|
std::cerr << boost::diagnostic_information(e) << '\n';
|
2017-08-25 17:17:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-07 16:53:50 +00:00
|
|
|
std::cerr << "Boost exception: " << boost::diagnostic_information(e) << '\n';
|
2017-08-25 17:17:12 +00:00
|
|
|
}
|
|
|
|
google::ShutDownCommandLineFlags();
|
2020-07-07 16:53:50 +00:00
|
|
|
std::cout << "GNSS-SDR program ended.\n";
|
2017-08-25 17:17:12 +00:00
|
|
|
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();
|
2020-07-07 16:53:50 +00:00
|
|
|
std::cerr << ex.what() << '\n';
|
2017-08-25 17:17:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-07 16:53:50 +00:00
|
|
|
std::cerr << "C++ Standard Library exception: " << ex.what() << '\n';
|
2017-08-25 17:17:12 +00:00
|
|
|
}
|
|
|
|
google::ShutDownCommandLineFlags();
|
2020-07-07 16:53:50 +00:00
|
|
|
std::cout << "GNSS-SDR program ended.\n";
|
2017-08-25 17:17:12 +00:00
|
|
|
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.";
|
2020-07-07 16:53:50 +00:00
|
|
|
std::cerr << "Unexpected error.\n";
|
2017-08-25 17:17:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-07 16:53:50 +00:00
|
|
|
std::cerr << "Unexpected catch. This should not happen.\n";
|
2017-08-25 17:17:12 +00:00
|
|
|
}
|
|
|
|
google::ShutDownCommandLineFlags();
|
2020-07-07 16:53:50 +00:00
|
|
|
std::cout << "GNSS-SDR program ended.\n";
|
2017-08-25 17:17:12 +00:00
|
|
|
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()
|
2020-07-07 16:53:50 +00:00
|
|
|
<< " [seconds]\n";
|
2012-02-08 19:50:16 +00:00
|
|
|
|
2011-12-26 05:04:27 +00:00
|
|
|
google::ShutDownCommandLineFlags();
|
2020-07-07 16:53:50 +00:00
|
|
|
std::cout << "GNSS-SDR program ended.\n";
|
2018-10-23 14:54:06 +00:00
|
|
|
return return_code;
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|