2011-10-01 18:45:20 +00:00
|
|
|
/*!
|
|
|
|
* \file channel.cc
|
2016-05-04 22:26:59 +00:00
|
|
|
* \brief Implementation of a GNSS_Channel with a Finite State Machine
|
2011-10-01 18:45:20 +00:00
|
|
|
* \author Carlos Aviles, 2010. carlos.avilesr(at)googlemail.com
|
|
|
|
* Luis Esteve, 2011. luis(at)epsilon-formacion.com
|
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*
|
2018-05-13 20:49:11 +00:00
|
|
|
* Copyright (C) 2010-2018 (see AUTHORS file for a list of contributors)
|
2011-10-01 18:45:20 +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
|
2015-01-08 18:49:59 +00:00
|
|
|
* (at your option) any later version.
|
2011-10-01 18:45:20 +00:00
|
|
|
*
|
|
|
|
* 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/>.
|
2011-10-01 18:45:20 +00:00
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
2017-09-03 21:56:41 +00:00
|
|
|
|
2011-10-01 18:45:20 +00:00
|
|
|
#include "channel.h"
|
2019-03-04 07:12:50 +00:00
|
|
|
#include "acquisition_interface.h"
|
2019-03-05 11:33:54 +00:00
|
|
|
#include "channel_fsm.h"
|
2014-01-12 20:07:38 +00:00
|
|
|
#include "configuration_interface.h"
|
2018-02-25 00:00:17 +00:00
|
|
|
#include "gnss_sdr_flags.h"
|
2019-03-04 07:12:50 +00:00
|
|
|
#include "telemetry_decoder_interface.h"
|
|
|
|
#include "tracking_interface.h"
|
2018-02-26 02:15:53 +00:00
|
|
|
#include <glog/logging.h>
|
2019-03-05 11:33:54 +00:00
|
|
|
#include <cstring> // for memcpy
|
2019-03-04 07:12:50 +00:00
|
|
|
#include <utility>
|
2014-01-12 20:07:38 +00:00
|
|
|
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2011-12-28 21:36:45 +00:00
|
|
|
// Constructor
|
2018-12-03 16:58:18 +00:00
|
|
|
Channel::Channel(ConfigurationInterface* configuration, uint32_t channel, std::shared_ptr<AcquisitionInterface> acq,
|
2018-03-03 01:03:39 +00:00
|
|
|
std::shared_ptr<TrackingInterface> trk, std::shared_ptr<TelemetryDecoderInterface> nav,
|
|
|
|
std::string role, std::string implementation, gr::msg_queue::sptr queue)
|
2011-10-01 18:45:20 +00:00
|
|
|
{
|
2018-12-02 04:29:11 +00:00
|
|
|
acq_ = std::move(acq);
|
|
|
|
trk_ = std::move(trk);
|
|
|
|
nav_ = std::move(nav);
|
|
|
|
role_ = std::move(role);
|
|
|
|
implementation_ = std::move(implementation);
|
2016-04-25 18:34:27 +00:00
|
|
|
channel_ = channel;
|
2018-12-02 04:29:11 +00:00
|
|
|
queue_ = std::move(queue);
|
2018-01-08 11:03:32 +00:00
|
|
|
channel_fsm_ = std::make_shared<ChannelFsm>();
|
2016-04-15 14:33:41 +00:00
|
|
|
|
2017-09-03 21:56:41 +00:00
|
|
|
flag_enable_fpga = configuration->property("Channel.enable_FPGA", false);
|
2011-10-01 18:45:20 +00:00
|
|
|
acq_->set_channel(channel_);
|
|
|
|
trk_->set_channel(channel_);
|
|
|
|
nav_->set_channel(channel_);
|
|
|
|
|
2018-12-02 04:29:11 +00:00
|
|
|
gnss_synchro_ = Gnss_Synchro();
|
2012-11-01 18:26:58 +00:00
|
|
|
gnss_synchro_.Channel_ID = channel_;
|
2012-01-27 18:01:17 +00:00
|
|
|
acq_->set_gnss_synchro(&gnss_synchro_);
|
|
|
|
trk_->set_gnss_synchro(&gnss_synchro_);
|
|
|
|
|
2017-09-03 21:56:41 +00:00
|
|
|
// Provide a warning to the user about the change of parameter name
|
2018-03-03 01:03:39 +00:00
|
|
|
if (channel_ == 0)
|
2017-09-03 21:56:41 +00:00
|
|
|
{
|
2018-08-10 18:34:03 +00:00
|
|
|
int64_t deprecation_warning = configuration->property("GNSS-SDR.internal_fs_hz", 0);
|
2018-03-03 01:03:39 +00:00
|
|
|
if (deprecation_warning != 0)
|
2017-09-03 21:56:41 +00:00
|
|
|
{
|
|
|
|
std::cout << "WARNING: The global parameter name GNSS-SDR.internal_fs_hz has been DEPRECATED." << std::endl;
|
|
|
|
std::cout << "WARNING: Please replace it by GNSS-SDR.internal_fs_sps in your configuration file." << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-06 17:30:36 +00:00
|
|
|
// IMPORTANT: Do not change the order between set_doppler_step and set_threshold
|
2013-05-26 23:59:04 +00:00
|
|
|
|
2018-12-02 04:29:11 +00:00
|
|
|
uint32_t doppler_step = configuration->property("Acquisition_" + implementation_ + std::to_string(channel_) + ".doppler_step", 0);
|
2019-02-11 20:13:02 +00:00
|
|
|
if (doppler_step == 0)
|
|
|
|
{
|
|
|
|
doppler_step = configuration->property("Acquisition_" + implementation_ + ".doppler_step", 500);
|
|
|
|
}
|
|
|
|
if (FLAGS_doppler_step != 0)
|
|
|
|
{
|
|
|
|
doppler_step = static_cast<uint32_t>(FLAGS_doppler_step);
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
DLOG(INFO) << "Channel " << channel_ << " Doppler_step = " << doppler_step;
|
2013-05-26 23:59:04 +00:00
|
|
|
|
|
|
|
acq_->set_doppler_step(doppler_step);
|
|
|
|
|
2018-12-02 04:29:11 +00:00
|
|
|
float threshold = configuration->property("Acquisition_" + implementation_ + std::to_string(channel_) + ".threshold", 0.0);
|
2019-02-11 20:13:02 +00:00
|
|
|
if (threshold == 0.0)
|
|
|
|
{
|
|
|
|
threshold = configuration->property("Acquisition_" + implementation_ + ".threshold", 0.0);
|
|
|
|
}
|
2013-05-26 23:59:04 +00:00
|
|
|
|
|
|
|
acq_->set_threshold(threshold);
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2013-07-23 18:03:07 +00:00
|
|
|
acq_->init();
|
2013-07-04 13:47:40 +00:00
|
|
|
|
2018-12-02 04:29:11 +00:00
|
|
|
repeat_ = configuration->property("Acquisition_" + implementation_ + std::to_string(channel_) + ".repeat_satellite", false);
|
2014-01-12 20:07:38 +00:00
|
|
|
DLOG(INFO) << "Channel " << channel_ << " satellite repeat = " << repeat_;
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2018-01-08 11:03:32 +00:00
|
|
|
channel_fsm_->set_acquisition(acq_);
|
|
|
|
channel_fsm_->set_tracking(trk_);
|
2019-03-18 15:28:49 +00:00
|
|
|
channel_fsm_->set_telemetry(nav_);
|
2018-01-08 11:03:32 +00:00
|
|
|
channel_fsm_->set_channel(channel_);
|
|
|
|
channel_fsm_->set_queue(queue_);
|
2011-10-01 18:45:20 +00:00
|
|
|
|
|
|
|
connected_ = false;
|
2016-04-21 16:54:08 +00:00
|
|
|
|
|
|
|
gnss_signal_ = Gnss_Signal(implementation_);
|
2016-04-18 12:17:09 +00:00
|
|
|
|
2018-01-08 11:03:32 +00:00
|
|
|
channel_msg_rx = channel_msg_receiver_make_cc(channel_fsm_, repeat_);
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
2017-08-19 18:05:52 +00:00
|
|
|
|
2011-12-28 21:36:45 +00:00
|
|
|
// Destructor
|
2018-12-02 04:29:11 +00:00
|
|
|
Channel::~Channel() = default;
|
|
|
|
|
|
|
|
|
2013-07-04 13:47:40 +00:00
|
|
|
void Channel::connect(gr::top_block_sptr top_block)
|
2011-10-01 18:45:20 +00:00
|
|
|
{
|
|
|
|
acq_->connect(top_block);
|
|
|
|
trk_->connect(top_block);
|
|
|
|
nav_->connect(top_block);
|
|
|
|
|
2016-03-30 13:03:25 +00:00
|
|
|
//Synchronous ports
|
2012-01-27 18:01:17 +00:00
|
|
|
top_block->connect(trk_->get_right_block(), 0, nav_->get_left_block(), 0);
|
2019-03-18 15:28:49 +00:00
|
|
|
// Message ports
|
|
|
|
top_block->msg_connect(nav_->get_left_block(), pmt::mp("telemetry_to_trk"), trk_->get_right_block(), pmt::mp("telemetry_to_trk"));
|
2011-10-01 18:45:20 +00:00
|
|
|
DLOG(INFO) << "tracking -> telemetry_decoder";
|
2016-03-08 17:30:56 +00:00
|
|
|
|
2016-03-30 13:03:25 +00:00
|
|
|
// Message ports
|
2016-04-25 18:34:27 +00:00
|
|
|
top_block->msg_connect(acq_->get_right_block(), pmt::mp("events"), channel_msg_rx, pmt::mp("events"));
|
|
|
|
top_block->msg_connect(trk_->get_right_block(), pmt::mp("events"), channel_msg_rx, pmt::mp("events"));
|
2016-04-15 14:33:41 +00:00
|
|
|
|
2011-10-01 18:45:20 +00:00
|
|
|
connected_ = true;
|
|
|
|
}
|
|
|
|
|
2012-01-10 09:49:09 +00:00
|
|
|
|
2013-07-04 13:47:40 +00:00
|
|
|
void Channel::disconnect(gr::top_block_sptr top_block)
|
2011-10-01 18:45:20 +00:00
|
|
|
{
|
|
|
|
if (!connected_)
|
2011-12-28 21:36:45 +00:00
|
|
|
{
|
2014-03-16 19:58:29 +00:00
|
|
|
LOG(WARNING) << "Channel already disconnected internally";
|
2011-12-28 21:36:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-05-05 15:08:49 +00:00
|
|
|
|
2012-01-11 09:01:24 +00:00
|
|
|
top_block->disconnect(trk_->get_right_block(), 0, nav_->get_left_block(), 0);
|
2017-05-05 15:08:49 +00:00
|
|
|
|
2011-10-01 18:45:20 +00:00
|
|
|
acq_->disconnect(top_block);
|
|
|
|
trk_->disconnect(top_block);
|
|
|
|
nav_->disconnect(top_block);
|
|
|
|
connected_ = false;
|
|
|
|
}
|
|
|
|
|
2016-04-25 18:34:27 +00:00
|
|
|
|
2013-07-04 13:47:40 +00:00
|
|
|
gr::basic_block_sptr Channel::get_left_block()
|
2011-10-01 18:45:20 +00:00
|
|
|
{
|
2018-12-03 16:58:18 +00:00
|
|
|
LOG(ERROR) << "Deprecated call to get_left_block() in channel interface";
|
2018-12-10 17:39:14 +00:00
|
|
|
return nullptr;
|
2018-12-03 16:58:18 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 07:12:50 +00:00
|
|
|
|
2018-12-03 16:58:18 +00:00
|
|
|
gr::basic_block_sptr Channel::get_left_block_trk()
|
|
|
|
{
|
|
|
|
return trk_->get_left_block();
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 07:12:50 +00:00
|
|
|
|
2018-12-03 16:58:18 +00:00
|
|
|
gr::basic_block_sptr Channel::get_left_block_acq()
|
|
|
|
{
|
|
|
|
return acq_->get_left_block();
|
|
|
|
}
|
2016-04-25 18:34:27 +00:00
|
|
|
|
2019-03-04 07:12:50 +00:00
|
|
|
|
2013-07-04 13:47:40 +00:00
|
|
|
gr::basic_block_sptr Channel::get_right_block()
|
2011-10-01 18:45:20 +00:00
|
|
|
{
|
|
|
|
return nav_->get_right_block();
|
|
|
|
}
|
|
|
|
|
2012-01-10 09:49:09 +00:00
|
|
|
|
2015-05-15 16:19:10 +00:00
|
|
|
void Channel::set_signal(const Gnss_Signal& gnss_signal)
|
2011-10-01 18:45:20 +00:00
|
|
|
{
|
2018-01-08 11:54:35 +00:00
|
|
|
std::lock_guard<std::mutex> lk(mx);
|
2012-01-31 00:03:08 +00:00
|
|
|
gnss_signal_ = gnss_signal;
|
2015-05-13 21:50:21 +00:00
|
|
|
std::string str_aux = gnss_signal_.get_signal_str();
|
2018-03-03 01:03:39 +00:00
|
|
|
const char* str = str_aux.c_str(); // get a C style null terminated string
|
|
|
|
std::memcpy(static_cast<void*>(gnss_synchro_.Signal), str, 3); // copy string into synchro char array: 2 char + null
|
|
|
|
gnss_synchro_.Signal[2] = 0; // make sure that string length is only two characters
|
2012-01-31 00:03:08 +00:00
|
|
|
gnss_synchro_.PRN = gnss_signal_.get_satellite().get_PRN();
|
|
|
|
gnss_synchro_.System = gnss_signal_.get_satellite().get_system_short().c_str()[0];
|
2013-07-23 18:03:07 +00:00
|
|
|
acq_->set_local_code();
|
2012-01-30 14:13:34 +00:00
|
|
|
nav_->set_satellite(gnss_signal_.get_satellite());
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
2016-04-25 18:34:27 +00:00
|
|
|
|
2018-10-28 10:07:53 +00:00
|
|
|
void Channel::stop_channel()
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lk(mx);
|
|
|
|
bool result = channel_fsm_->Event_stop_channel();
|
|
|
|
if (!result)
|
|
|
|
{
|
|
|
|
LOG(WARNING) << "Invalid channel event";
|
|
|
|
return;
|
|
|
|
}
|
2019-03-05 11:33:54 +00:00
|
|
|
DLOG(INFO) << "Channel stop_channel()";
|
2018-10-28 10:07:53 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 07:12:50 +00:00
|
|
|
|
2011-10-01 18:45:20 +00:00
|
|
|
void Channel::start_acquisition()
|
|
|
|
{
|
2018-01-08 11:54:35 +00:00
|
|
|
std::lock_guard<std::mutex> lk(mx);
|
2018-01-08 09:57:01 +00:00
|
|
|
bool result = false;
|
2018-01-08 11:03:32 +00:00
|
|
|
result = channel_fsm_->Event_start_acquisition();
|
2018-03-03 01:03:39 +00:00
|
|
|
if (!result)
|
2018-01-08 09:57:01 +00:00
|
|
|
{
|
|
|
|
LOG(WARNING) << "Invalid channel event";
|
|
|
|
return;
|
|
|
|
}
|
2018-01-04 11:33:13 +00:00
|
|
|
DLOG(INFO) << "Channel start_acquisition()";
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|