2011-10-01 18:45:20 +00:00
|
|
|
/*!
|
|
|
|
* \file channel.cc
|
|
|
|
* \brief Implementation of a GPS_L1_CA_Channel with a Finite State Machine
|
|
|
|
* \author Carlos Aviles, 2010. carlos.avilesr(at)googlemail.com
|
|
|
|
* Luis Esteve, 2011. luis(at)epsilon-formacion.com
|
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*
|
2014-01-12 20:07:38 +00:00
|
|
|
* Copyright (C) 2010-2014 (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
|
|
|
|
* 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/>.
|
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "channel.h"
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <boost/lexical_cast.hpp>
|
2011-12-14 16:50:36 +00:00
|
|
|
#include <boost/thread/thread.hpp>
|
2011-10-01 18:45:20 +00:00
|
|
|
#include <glog/logging.h>
|
2014-01-12 20:07:38 +00:00
|
|
|
#include <gnuradio/io_signature.h>
|
|
|
|
#include <gnuradio/message.h>
|
|
|
|
#include "acquisition_interface.h"
|
|
|
|
#include "tracking_interface.h"
|
|
|
|
#include "telemetry_decoder_interface.h"
|
|
|
|
#include "configuration_interface.h"
|
|
|
|
#include "gnss_flowgraph.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-01 18:45:20 +00:00
|
|
|
|
|
|
|
using google::LogMessage;
|
|
|
|
|
2011-12-28 21:36:45 +00:00
|
|
|
// Constructor
|
2011-10-01 18:45:20 +00:00
|
|
|
Channel::Channel(ConfigurationInterface *configuration, unsigned int channel,
|
|
|
|
GNSSBlockInterface *pass_through, AcquisitionInterface *acq,
|
|
|
|
TrackingInterface *trk, TelemetryDecoderInterface *nav,
|
2013-07-04 13:47:40 +00:00
|
|
|
std::string role, std::string implementation, boost::shared_ptr<gr::msg_queue> queue) :
|
2012-11-01 18:26:58 +00:00
|
|
|
pass_through_(pass_through), acq_(acq), trk_(trk), nav_(nav),
|
|
|
|
role_(role), implementation_(implementation), channel_(channel),
|
|
|
|
queue_(queue)
|
2011-10-01 18:45:20 +00:00
|
|
|
{
|
|
|
|
stop_ = false;
|
|
|
|
acq_->set_channel(channel_);
|
|
|
|
trk_->set_channel(channel_);
|
|
|
|
nav_->set_channel(channel_);
|
|
|
|
|
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_);
|
|
|
|
|
2013-05-26 23:59:04 +00:00
|
|
|
// IMPORTANT: Do not change the order between set_doppler_max, set_doppler_step and set_threshold
|
|
|
|
|
2014-01-12 20:07:38 +00:00
|
|
|
unsigned int doppler_max = configuration->property("Acquisition" + boost::lexical_cast<std::string>(channel_) + ".doppler_max", 0);
|
|
|
|
if(doppler_max == 0) doppler_max = configuration->property("Acquisition.doppler_max", 0);
|
|
|
|
DLOG(INFO) << "Channel "<< channel_ << " Doppler_max = " << doppler_max;
|
2013-05-26 23:59:04 +00:00
|
|
|
|
|
|
|
acq_->set_doppler_max(doppler_max);
|
|
|
|
|
2014-01-12 20:07:38 +00:00
|
|
|
unsigned int doppler_step = configuration->property("Acquisition" + boost::lexical_cast<std::string>(channel_) + ".doppler_step" ,0);
|
|
|
|
if(doppler_step == 0) doppler_step = configuration->property("Acquisition.doppler_step", 500);
|
|
|
|
DLOG(INFO) << "Channel "<< channel_ << " Doppler_step = " << doppler_step;
|
2013-05-26 23:59:04 +00:00
|
|
|
|
|
|
|
acq_->set_doppler_step(doppler_step);
|
|
|
|
|
2014-01-12 20:07:38 +00:00
|
|
|
float threshold = configuration->property("Acquisition" + boost::lexical_cast<std::string>(channel_) + ".threshold", 0.0);
|
|
|
|
if(threshold == 0.0) threshold = configuration->property("Acquisition.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
|
|
|
|
2014-01-12 20:07:38 +00:00
|
|
|
repeat_ = configuration->property("Acquisition" + boost::lexical_cast<std::string>(channel_) + ".repeat_satellite", false);
|
|
|
|
DLOG(INFO) << "Channel " << channel_ << " satellite repeat = " << repeat_;
|
2011-10-01 18:45:20 +00:00
|
|
|
|
|
|
|
acq_->set_channel_queue(&channel_internal_queue_);
|
|
|
|
trk_->set_channel_queue(&channel_internal_queue_);
|
|
|
|
|
|
|
|
channel_fsm_.set_acquisition(acq_);
|
|
|
|
channel_fsm_.set_tracking(trk_);
|
|
|
|
channel_fsm_.set_channel(channel_);
|
|
|
|
channel_fsm_.set_queue(queue_);
|
|
|
|
|
|
|
|
connected_ = false;
|
|
|
|
message_ = 0;
|
2012-01-27 11:58:55 +00:00
|
|
|
gnss_signal_ = Gnss_Signal();
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-28 21:36:45 +00:00
|
|
|
// Destructor
|
2011-10-01 18:45:20 +00:00
|
|
|
Channel::~Channel()
|
|
|
|
{
|
|
|
|
delete acq_;
|
|
|
|
delete trk_;
|
|
|
|
delete nav_;
|
|
|
|
delete pass_through_;
|
|
|
|
}
|
|
|
|
|
2012-01-10 09:49:09 +00:00
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
if (connected_)
|
2011-12-28 21:36:45 +00:00
|
|
|
{
|
2014-03-16 19:58:29 +00:00
|
|
|
LOG(WARNING) << "channel already connected internally";
|
2011-12-28 21:36:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-10-01 18:45:20 +00:00
|
|
|
pass_through_->connect(top_block);
|
|
|
|
acq_->connect(top_block);
|
|
|
|
trk_->connect(top_block);
|
|
|
|
nav_->connect(top_block);
|
|
|
|
|
2012-11-01 18:26:58 +00:00
|
|
|
top_block->connect(pass_through_->get_right_block(), 0, acq_->get_left_block(), 0);
|
2011-10-01 18:45:20 +00:00
|
|
|
DLOG(INFO) << "pass_through_ -> acquisition";
|
2012-11-01 18:26:58 +00:00
|
|
|
top_block->connect(pass_through_->get_right_block(), 0, trk_->get_left_block(), 0);
|
2011-10-01 18:45:20 +00:00
|
|
|
DLOG(INFO) << "pass_through_ -> tracking";
|
2012-01-27 18:01:17 +00:00
|
|
|
top_block->connect(trk_->get_right_block(), 0, nav_->get_left_block(), 0);
|
2011-10-01 18:45:20 +00:00
|
|
|
DLOG(INFO) << "tracking -> telemetry_decoder";
|
|
|
|
connected_ = true;
|
|
|
|
}
|
|
|
|
|
2012-01-10 09:49:09 +00:00
|
|
|
|
2012-11-01 18:26:58 +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;
|
|
|
|
}
|
2012-11-01 18:26:58 +00:00
|
|
|
top_block->disconnect(pass_through_->get_right_block(), 0, acq_->get_left_block(), 0);
|
|
|
|
top_block->disconnect(pass_through_->get_right_block(), 0, trk_->get_left_block(), 0);
|
2012-01-11 09:01:24 +00:00
|
|
|
top_block->disconnect(trk_->get_right_block(), 0, nav_->get_left_block(), 0);
|
2012-02-17 14:28:32 +00:00
|
|
|
pass_through_->disconnect(top_block);
|
2011-10-01 18:45:20 +00:00
|
|
|
acq_->disconnect(top_block);
|
|
|
|
trk_->disconnect(top_block);
|
|
|
|
nav_->disconnect(top_block);
|
|
|
|
connected_ = false;
|
|
|
|
}
|
|
|
|
|
2012-01-10 09:49:09 +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
|
|
|
{
|
|
|
|
return pass_through_->get_left_block();
|
|
|
|
}
|
|
|
|
|
2012-01-10 09:49:09 +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
|
|
|
|
|
|
|
|
2012-01-27 11:58:55 +00:00
|
|
|
void Channel::set_signal(Gnss_Signal gnss_signal)
|
2011-10-01 18:45:20 +00:00
|
|
|
{
|
2012-01-31 00:03:08 +00:00
|
|
|
gnss_signal_ = gnss_signal;
|
2013-07-20 07:58:59 +00:00
|
|
|
const char * str = gnss_signal_.get_signal().c_str(); // get a C style null terminated string
|
2014-01-12 20:07:38 +00:00
|
|
|
std::memcpy((void*)gnss_synchro_.Signal, str, 3); // copy string into synchro char array: 2 char + null
|
2013-07-20 07:58:59 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-01-10 09:49:09 +00:00
|
|
|
|
|
|
|
|
2011-10-01 18:45:20 +00:00
|
|
|
void Channel::start_acquisition()
|
|
|
|
{
|
|
|
|
channel_fsm_.Event_gps_start_acquisition();
|
|
|
|
}
|
|
|
|
|
2012-01-10 09:49:09 +00:00
|
|
|
|
|
|
|
|
2011-10-01 18:45:20 +00:00
|
|
|
void Channel::start()
|
|
|
|
{
|
|
|
|
ch_thread_ = boost::thread(&Channel::run, this);
|
|
|
|
}
|
|
|
|
|
2012-01-10 09:49:09 +00:00
|
|
|
|
|
|
|
|
2011-10-01 18:45:20 +00:00
|
|
|
void Channel::run()
|
|
|
|
{
|
|
|
|
while (!stop_)
|
2011-12-28 21:36:45 +00:00
|
|
|
{
|
|
|
|
channel_internal_queue_.wait_and_pop(message_);
|
|
|
|
process_channel_messages();
|
|
|
|
}
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
2012-11-01 18:26:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Channel::standby()
|
|
|
|
{
|
2012-03-02 17:17:51 +00:00
|
|
|
channel_fsm_.Event_gps_failed_tracking_standby();
|
|
|
|
}
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2012-11-01 18:26:58 +00:00
|
|
|
|
|
|
|
|
2011-10-01 18:45:20 +00:00
|
|
|
/*
|
2011-12-28 21:36:45 +00:00
|
|
|
* Set stop_ to true and blocks the calling thread until
|
2011-10-01 18:45:20 +00:00
|
|
|
* the thread of the constructor has completed
|
|
|
|
*/
|
|
|
|
void Channel::stop()
|
|
|
|
{
|
|
|
|
channel_internal_queue_.push(0); //message to stop channel
|
2012-11-01 18:26:58 +00:00
|
|
|
stop_ = true;
|
2011-10-01 18:45:20 +00:00
|
|
|
/* When the boost::thread object that represents a thread of execution
|
|
|
|
* is destroyed the thread becomes detached. Once a thread is detached,
|
|
|
|
* it will continue executing until the invocation of the function or
|
|
|
|
* callable object supplied on construction has completed,
|
|
|
|
* or the program is terminated. In order to wait for a thread of
|
|
|
|
* execution to finish, the join() or timed_join() member functions of
|
|
|
|
* the boost::thread object must be used. join() will block the calling
|
|
|
|
* thread until the thread represented by the boost::thread object
|
|
|
|
* has completed.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
ch_thread_.join();
|
|
|
|
}
|
|
|
|
|
2012-11-01 18:26:58 +00:00
|
|
|
|
|
|
|
|
2011-10-01 18:45:20 +00:00
|
|
|
void Channel::process_channel_messages()
|
|
|
|
{
|
|
|
|
switch (message_)
|
|
|
|
{
|
2011-12-28 21:36:45 +00:00
|
|
|
case 0:
|
2012-04-11 18:44:56 +00:00
|
|
|
DLOG(INFO) << "Stop channel " << channel_;
|
2011-12-28 21:36:45 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2012-11-01 18:26:58 +00:00
|
|
|
DLOG(INFO) << "Channel " << channel_ << " ACQ SUCCESS satellite " <<
|
|
|
|
gnss_synchro_.System << " " << gnss_synchro_.PRN;
|
2011-12-28 21:36:45 +00:00
|
|
|
channel_fsm_.Event_gps_valid_acquisition();
|
|
|
|
break;
|
|
|
|
case 2:
|
2012-11-01 18:26:58 +00:00
|
|
|
DLOG(INFO) << "Channel " << channel_
|
|
|
|
<< " ACQ FAILED satellite " << gnss_synchro_.System << " " << gnss_synchro_.PRN;
|
2011-12-28 21:36:45 +00:00
|
|
|
if (repeat_ == true)
|
2011-10-01 18:45:20 +00:00
|
|
|
{
|
|
|
|
channel_fsm_.Event_gps_failed_acquisition_repeat();
|
|
|
|
}
|
2011-12-28 21:36:45 +00:00
|
|
|
else
|
2011-10-01 18:45:20 +00:00
|
|
|
{
|
|
|
|
channel_fsm_.Event_gps_failed_acquisition_no_repeat();
|
|
|
|
}
|
2011-12-28 21:36:45 +00:00
|
|
|
break;
|
|
|
|
default:
|
2014-03-16 19:58:29 +00:00
|
|
|
LOG(WARNING) << "Default case, invalid message.";
|
2011-12-28 21:36:45 +00:00
|
|
|
break;
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|