1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-11-11 04:33:06 +00:00

moving things to trunk

git-svn-id: https://svn.code.sf.net/p/gnss-sdr/code/trunk@72 64b25241-fba3-4117-9849-534c7e92360d
This commit is contained in:
Carles Fernandez
2011-10-01 18:45:20 +00:00
parent 0d9423d5ed
commit 228fa3b797
199 changed files with 126904 additions and 0 deletions

View File

@@ -0,0 +1,266 @@
/*!
* \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
*
* Detailed description of the file here if needed.
*
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2011 (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.
*
* 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 "acquisition_interface.h"
#include "tracking_interface.h"
#include "telemetry_decoder_interface.h"
#include "configuration_interface.h"
#include "gnss_flowgraph.h"
#include <iostream>
#include <sstream>
#include <boost/lexical_cast.hpp>
#include <gnuradio/gr_io_signature.h>
#include <gnuradio/gr_message.h>
#include <glog/log_severity.h>
#include <glog/logging.h>
using google::LogMessage;
//! Constructor
Channel::Channel(ConfigurationInterface *configuration, unsigned int channel,
GNSSBlockInterface *pass_through, AcquisitionInterface *acq,
TrackingInterface *trk, TelemetryDecoderInterface *nav,
std::string role, std::string implementation, gr_msg_queue_sptr queue) :
pass_through_(pass_through), acq_(acq), trk_(trk), nav_(nav),
role_(role), implementation_(implementation), channel_(channel),
queue_(queue)
{
stop_ = false;
acq_->set_channel(channel_);
trk_->set_channel(channel_);
nav_->set_channel(channel_);
acq_->set_threshold(configuration->property("Acquisition"
+ boost::lexical_cast<std::string>(channel_) + ".threshold", 0.0));
acq_->set_doppler_max(configuration->property("Acquisition"
+ boost::lexical_cast<std::string>(channel_) + ".doppler_max",
10000));
acq_->set_doppler_step(configuration->property("Acquisition"
+ boost::lexical_cast<std::string>(channel_) + ".doppler_step",
250));
repeat_ = configuration->property("Acquisition" + boost::lexical_cast<
std::string>(channel_) + ".repeat_satellite", false);
std::cout << "Channel " << channel_ << " satellite repeat = " << repeat_
<< std::endl;
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;
}
//! Destructor
Channel::~Channel()
{
delete acq_;
delete trk_;
delete nav_;
delete pass_through_;
}
void Channel::connect(gr_top_block_sptr top_block)
{
if (connected_)
{
LOG_AT_LEVEL(WARNING) << "channel already connected internally";
return;
}
pass_through_->connect(top_block);
acq_->connect(top_block);
trk_->connect(top_block);
nav_->connect(top_block);
top_block->connect(pass_through_->get_right_block(), 0,
acq_->get_left_block(), 0);
DLOG(INFO) << "pass_through_ -> acquisition";
top_block->connect(pass_through_->get_right_block(), 0,
trk_->get_left_block(), 0);
DLOG(INFO) << "pass_through_ -> tracking";
top_block->connect(trk_->get_right_block(), 0, nav_->get_left_block(), 0); // channel 1
top_block->connect(trk_->get_right_block(), 1, nav_->get_left_block(), 1); // channel 2
top_block->connect(trk_->get_right_block(), 2, nav_->get_left_block(), 2); // channel 3
DLOG(INFO) << "tracking -> telemetry_decoder";
connected_ = true;
}
void Channel::disconnect(gr_top_block_sptr top_block)
{
if (!connected_)
{
LOG_AT_LEVEL(WARNING) << "Channel already disconnected internally";
return;
}
top_block->disconnect(acq_->get_right_block(), 0, trk_->get_left_block(),
0);
top_block->disconnect(trk_->get_right_block(), 0, nav_->get_left_block(),
0);
acq_->disconnect(top_block);
trk_->disconnect(top_block);
nav_->disconnect(top_block);
connected_ = false;
}
gr_basic_block_sptr Channel::get_left_block()
{
return pass_through_->get_left_block();
}
gr_basic_block_sptr Channel::get_right_block()
{
return nav_->get_right_block();
}
void Channel::set_satellite(unsigned int satellite)
{
satellite_ = satellite;
acq_->set_satellite(satellite);
trk_->set_satellite(satellite);
nav_->set_satellite(satellite);
}
void Channel::start_acquisition()
{
channel_fsm_.Event_gps_start_acquisition();
}
void Channel::start()
{
ch_thread_ = boost::thread(&Channel::run, this);
}
void Channel::run()
{
start_acquisition();
while (!stop_)
{
channel_internal_queue_.wait_and_pop(message_);
process_channel_messages();
}
}
/*
* \brief Set stop_ to true and blocks the calling thread until
* the thread of the constructor has completed
*/
void Channel::stop()
{
stop_ = true;
channel_internal_queue_.push(0); //message to stop channel
/* 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();
}
void Channel::process_channel_messages()
{
switch (message_)
{
case 0:
LOG_AT_LEVEL(INFO) << "Stop channel " << channel_;
break;
case 1:
LOG_AT_LEVEL(INFO) << "Channel " << channel_
<< " ACQ SUCCESS satellite " << satellite_;
channel_fsm_.Event_gps_valid_acquisition();
break;
case 2:
LOG_AT_LEVEL(INFO) << "Channel " << channel_
<< " ACQ FAILED satellite " << satellite_;
if (repeat_ == true)
{
channel_fsm_.Event_gps_failed_acquisition_repeat();
}
else
{
channel_fsm_.Event_gps_failed_acquisition_no_repeat();
}
break;
case 3:
LOG_AT_LEVEL(INFO) << "Channel " << channel_
<< " TRACKING FAILED satellite " << satellite_
<< ", reacquisition.";
channel_fsm_.Event_gps_failed_tracking();
break;
default:
LOG_AT_LEVEL(WARNING) << "Default case, invalid message.";
break;
}
}

View File

@@ -0,0 +1,121 @@
/*!
* \file channel.h
* \brief This class represents a GNSS channel.
* \author Carlos Aviles, 2010. carlos.avilesr(at)googlemail.com
* Luis Esteve, 2011. luis(at)epsilon-formacion.com
*
* It holds blocks for acquisition, tracking,
* navigation data extraction and pseudorange calculation.
*
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2011 (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.
*
* 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 CHANNEL_H_
#define CHANNEL_H_
#include <gnuradio/gr_null_sink.h>
#include <gnuradio/gr_msg_queue.h>
#include "channel_interface.h"
#include "gps_l1_ca_channel_fsm.h"
#include "control_message_factory.h"
#include "concurrent_queue.h"
class ConfigurationInterface;
class AcquisitionInterface;
class TrackingInterface;
class TelemetryDecoderInterface;
//class GpsL1CaChannelFsm;
/*!
* \brief This class represents a GNSS channel.
*
*/
class Channel: public ChannelInterface
{
public:
//! Constructor
Channel(ConfigurationInterface *configuration, unsigned int channel,
GNSSBlockInterface *pass_through, AcquisitionInterface *acq,
TrackingInterface *trk, TelemetryDecoderInterface *nav,
std::string role, std::string implementation,
gr_msg_queue_sptr queue);
//! Virtual destructor
virtual ~Channel();
void connect(gr_top_block_sptr top_block);
void disconnect(gr_top_block_sptr top_block);
gr_basic_block_sptr get_left_block();
gr_basic_block_sptr get_right_block();
std::string role(){ return role_;}
std::string implementation(){ return "Channel";}
size_t item_size(){ return 0;}
unsigned int satellite(){ return satellite_;}
AcquisitionInterface* acquisition(){ return acq_;}
TrackingInterface* tracking(){ return trk_;}
TelemetryDecoderInterface* telemetry(){ return nav_;}
void start_acquisition();
void set_satellite(unsigned int satellite);
void start();
void stop();
private:
GNSSBlockInterface *pass_through_;
AcquisitionInterface *acq_;
TrackingInterface *trk_;
TelemetryDecoderInterface *nav_;
std::string role_;
std::string implementation_;
unsigned int channel_;
unsigned int satellite_;
bool connected_;
bool stop_;
int message_;
bool repeat_;
GpsL1CaChannelFsm channel_fsm_;
gr_msg_queue_sptr queue_;
concurrent_queue<int> channel_internal_queue_;
boost::thread ch_thread_;
void run();
void process_channel_messages();
};
#endif /*CHANNEL_H_*/

View File

@@ -0,0 +1,3 @@
project : build-dir ../../../../build ;
obj channel : channel.cc ;

View File

@@ -0,0 +1,3 @@
build-project adapters ;
# build-project gnuradio_blocks ;
build-project libs ;

View File

@@ -0,0 +1,209 @@
/*!
* \file gps_l1_ca_channel_fsm.cc
* \briefState Machine for channel using boost::statechart
* \author Luis Esteve, 2011. luis(at)epsilon-formacion.com
*
* Detailed description of the file here if needed.
*
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2011 (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.
*
* 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 "gps_l1_ca_channel_fsm.h"
#include "control_message_factory.h"
#include "channel.h"
#include <glog/log_severity.h>
#include <glog/logging.h>
struct Ev_gps_channel_start_acquisition: sc::event<
Ev_gps_channel_start_acquisition>
{};
struct Ev_gps_channel_valid_acquisition: sc::event<
Ev_gps_channel_valid_acquisition>
{};
struct Ev_gps_channel_failed_acquisition_repeat: sc::event<
Ev_gps_channel_failed_acquisition_repeat>
{};
struct Ev_gps_channel_failed_acquisition_no_repeat: sc::event<
Ev_gps_channel_failed_acquisition_no_repeat>
{};
struct Ev_gps_channel_failed_tracking: sc::event<
Ev_gps_channel_failed_tracking>
{};
struct gps_channel_idle_fsm_S0: public sc::state<gps_channel_idle_fsm_S0,
GpsL1CaChannelFsm>
{
public:
// sc::transition(event, next state)
typedef sc::transition<Ev_gps_channel_start_acquisition,
gps_channel_acquiring_fsm_S1> reactions;
gps_channel_idle_fsm_S0(my_context ctx) :
my_base(ctx)
{
//std::cout << "Enter Channel_Idle_S0 " << std::endl;
}
};
struct gps_channel_acquiring_fsm_S1: public sc::state<
gps_channel_acquiring_fsm_S1, GpsL1CaChannelFsm>
{
public:
typedef mpl::list<sc::transition<
Ev_gps_channel_failed_acquisition_no_repeat,
gps_channel_waiting_fsm_S3>, sc::transition<
Ev_gps_channel_failed_acquisition_repeat,
gps_channel_acquiring_fsm_S1>, sc::transition<
Ev_gps_channel_valid_acquisition, gps_channel_tracking_fsm_S2> >
reactions;
gps_channel_acquiring_fsm_S1(my_context ctx) :
my_base(ctx)
{
//std::cout << "Enter Channel_Acq_S1 " << std::endl;
context<GpsL1CaChannelFsm> ().start_acquisition();
}
};
struct gps_channel_tracking_fsm_S2: public sc::state<
gps_channel_tracking_fsm_S2, GpsL1CaChannelFsm>
{
public:
typedef sc::transition<Ev_gps_channel_failed_tracking,
gps_channel_acquiring_fsm_S1> reactions;
gps_channel_tracking_fsm_S2(my_context ctx) :
my_base(ctx)
{
//std::cout << "Enter Channel_tracking_S2 " << std::endl;
context<GpsL1CaChannelFsm> ().start_tracking();
}
};
struct gps_channel_waiting_fsm_S3: public sc::state<
gps_channel_waiting_fsm_S3, GpsL1CaChannelFsm>
{
public:
typedef sc::transition<Ev_gps_channel_start_acquisition,
gps_channel_acquiring_fsm_S1> reactions;
gps_channel_waiting_fsm_S3(my_context ctx) :
my_base(ctx)
{
//std::cout << "Enter Channel_waiting_S3 " << std::endl;
context<GpsL1CaChannelFsm> ().request_satellite();
}
};
GpsL1CaChannelFsm::GpsL1CaChannelFsm()
{
initiate(); //start the FSM
}
GpsL1CaChannelFsm::GpsL1CaChannelFsm(AcquisitionInterface *acquisition) :
acq_(acquisition)
{
initiate(); //start the FSM
}
void GpsL1CaChannelFsm::Event_gps_start_acquisition()
{
this->process_event(Ev_gps_channel_start_acquisition());
}
void GpsL1CaChannelFsm::Event_gps_valid_acquisition()
{
this->process_event(Ev_gps_channel_valid_acquisition());
}
void GpsL1CaChannelFsm::Event_gps_failed_acquisition_repeat()
{
this->process_event(Ev_gps_channel_failed_acquisition_repeat());
}
void GpsL1CaChannelFsm::Event_gps_failed_acquisition_no_repeat()
{
this->process_event(Ev_gps_channel_failed_acquisition_no_repeat());
}
void GpsL1CaChannelFsm::Event_gps_failed_tracking()
{
this->process_event(Ev_gps_channel_failed_tracking());
}
void GpsL1CaChannelFsm::set_acquisition(AcquisitionInterface *acquisition)
{
acq_ = acquisition;
}
void GpsL1CaChannelFsm::set_tracking(TrackingInterface *tracking)
{
trk_ = tracking;
}
void GpsL1CaChannelFsm::set_queue(gr_msg_queue_sptr queue)
{
queue_ = queue;
}
void GpsL1CaChannelFsm::set_channel(unsigned int channel)
{
channel_ = channel;
}
void GpsL1CaChannelFsm::start_acquisition()
{
acq_->reset();
}
void GpsL1CaChannelFsm::start_tracking()
{
LOG_AT_LEVEL(INFO) << "Channel " << channel_
<< " passing prn code phase " << acq_->prn_code_phase();
LOG_AT_LEVEL(INFO) << "Channel " << channel_
<< " passing doppler freq shift " << acq_->doppler_freq_shift();
LOG_AT_LEVEL(INFO) << "Channel " << channel_
<< " passing acquisition sample stamp "
<< acq_->get_sample_stamp();
trk_->set_prn_code_phase(acq_->prn_code_phase());
trk_->set_doppler_freq_shift(acq_->doppler_freq_shift());
trk_->set_acq_sample_stamp(acq_->get_sample_stamp());
trk_->start_tracking();
}
void GpsL1CaChannelFsm::request_satellite()
{
ControlMessageFactory* cmf = new ControlMessageFactory();
if (queue_ != gr_msg_queue_sptr())
{
queue_->handle(cmf->GetQueueMessage(channel_, 0));
}
delete cmf;
}

View File

@@ -0,0 +1,96 @@
/*!
* \file gps_l1_ca_channel_fsm.h
* \brief State Machine for channel using boost::statechart
* \author Luis Esteve, 2011. luis(at)epsilon-formacion.com
*
*
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2011 (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.
*
* 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_GPS_L1_CA_CHANNEL_FSM_H
#define GNSS_SDR_GPS_L1_CA_CHANNEL_FSM_H
#include <boost/statechart/state_machine.hpp>
#include <boost/statechart/simple_state.hpp>
#include <boost/statechart/state.hpp>
#include <boost/statechart/transition.hpp>
#include <boost/statechart/custom_reaction.hpp>
#include <boost/mpl/list.hpp>
#include <queue>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include "acquisition_interface.h"
#include "tracking_interface.h"
#include "telemetry_decoder_interface.h"
#include <gnuradio/gr_msg_queue.h>
#include <iostream>
#include <cstring>
namespace sc = boost::statechart;
namespace mpl = boost::mpl;
struct gps_channel_idle_fsm_S0;
struct gps_channel_acquiring_fsm_S1;
struct gps_channel_tracking_fsm_S2;
struct gps_channel_waiting_fsm_S3;
/*!
* \brief This class implements a State Machine for channel using boost::statechart
*/
class GpsL1CaChannelFsm: public sc::state_machine<GpsL1CaChannelFsm,
gps_channel_idle_fsm_S0>
{
public:
GpsL1CaChannelFsm();
GpsL1CaChannelFsm(AcquisitionInterface *acquisition);
void set_acquisition(AcquisitionInterface *acquisition);
void set_tracking(TrackingInterface *tracking);
void set_queue(gr_msg_queue_sptr queue);
void set_channel(unsigned int channel);
void start_acquisition();
void start_tracking();
void request_satellite();
//FSM EVENTS
void Event_gps_start_acquisition();
void Event_gps_valid_acquisition();
void Event_gps_failed_acquisition_repeat();
void Event_gps_failed_acquisition_no_repeat();
void Event_gps_failed_tracking();
private:
AcquisitionInterface *acq_;
TrackingInterface *trk_;
TelemetryDecoderInterface *nav_;
gr_msg_queue_sptr queue_;
unsigned int channel_;
};
#endif /*GNSS_SDR_GPS_L1_CA_CHANNEL_FSM_H*/

View File

@@ -0,0 +1,3 @@
project : build-dir ../../../../build ;
obj gps_l1_ca_channel_fsm : gps_l1_ca_channel_fsm.cc ;