1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-01-16 04:05:46 +00:00

Generic name for channel finite state machine, since it applies to all signals and not only to GPS L1 C/A

This commit is contained in:
Carles Fernandez 2015-05-21 11:29:56 +02:00
parent 114c7c5518
commit dcd59ed9bd
6 changed files with 247 additions and 247 deletions

View File

@ -190,7 +190,7 @@ void Channel::set_signal(const Gnss_Signal& gnss_signal)
void Channel::start_acquisition()
{
channel_fsm_.Event_gps_start_acquisition();
channel_fsm_.Event_start_acquisition();
}
@ -215,7 +215,7 @@ void Channel::run()
void Channel::standby()
{
channel_fsm_.Event_gps_failed_tracking_standby();
channel_fsm_.Event_failed_tracking_standby();
}
@ -260,18 +260,18 @@ void Channel::process_channel_messages()
case 1:
DLOG(INFO) << "Channel " << channel_ << " ACQ SUCCESS satellite " <<
gnss_synchro_.System << " " << gnss_synchro_.PRN;
channel_fsm_.Event_gps_valid_acquisition();
channel_fsm_.Event_valid_acquisition();
break;
case 2:
DLOG(INFO) << "Channel " << channel_
<< " ACQ FAILED satellite " << gnss_synchro_.System << " " << gnss_synchro_.PRN;
if (repeat_ == true)
{
channel_fsm_.Event_gps_failed_acquisition_repeat();
channel_fsm_.Event_failed_acquisition_repeat();
}
else
{
channel_fsm_.Event_gps_failed_acquisition_no_repeat();
channel_fsm_.Event_failed_acquisition_no_repeat();
}
break;
default:

View File

@ -38,7 +38,7 @@
#include <string>
#include <gnuradio/msg_queue.h>
#include "channel_interface.h"
#include "gps_l1_ca_channel_fsm.h"
#include "channel_fsm.h"
#include "control_message_factory.h"
#include "concurrent_queue.h"
#include "gnss_signal.h"
@ -104,7 +104,7 @@ private:
bool stop_;
int message_;
bool repeat_;
GpsL1CaChannelFsm channel_fsm_;
ChannelFsm channel_fsm_;
boost::shared_ptr<gr::msg_queue> queue_;
concurrent_queue<int> channel_internal_queue_;
boost::thread ch_thread_;

View File

@ -16,7 +16,7 @@
# along with GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
#
set(CHANNEL_FSM_SOURCES gps_l1_ca_channel_fsm.cc )
set(CHANNEL_FSM_SOURCES channel_fsm.cc )
include_directories(
$(CMAKE_CURRENT_SOURCE_DIR)
@ -33,4 +33,4 @@ include_directories(
file(GLOB CHANNEL_FSM_HEADERS "*.h")
add_library(channel_fsm ${CHANNEL_FSM_SOURCES} ${CHANNEL_FSM_HEADERS})
source_group(Headers FILES ${CHANNEL_FSM_HEADERS})
add_dependencies(channel_fsm glog-${glog_RELEASE})
add_dependencies(channel_fsm glog-${glog_RELEASE})

View File

@ -0,0 +1,222 @@
/*!
* \file channel_fsm.cc
* \brief Implementation of a State Machine for channel using boost::statechart
* \author Luis Esteve, 2011. luis(at)epsilon-formacion.com
*
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2015 (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_fsm.h"
#include <list>
#include <memory>
#include <glog/logging.h>
#include "control_message_factory.h"
#include "channel.h"
struct Ev_channel_start_acquisition: sc::event<Ev_channel_start_acquisition>
{};
struct Ev_channel_valid_acquisition: sc::event<Ev_channel_valid_acquisition>
{};
struct Ev_channel_failed_acquisition_repeat: sc::event<Ev_channel_failed_acquisition_repeat>
{};
struct Ev_channel_failed_acquisition_no_repeat: sc::event<Ev_channel_failed_acquisition_no_repeat>
{};
struct Ev_channel_failed_tracking_standby: sc::event<Ev_channel_failed_tracking_standby>
{};
//struct Ev_channel_failed_tracking_reacq: sc::event<Ev_channel_failed_tracking_reacq>
//{};
struct channel_idle_fsm_S0: public sc::state<channel_idle_fsm_S0, ChannelFsm>
{
public:
// sc::transition(event, next state)
typedef sc::transition<Ev_channel_start_acquisition, channel_acquiring_fsm_S1> reactions;
channel_idle_fsm_S0(my_context ctx) : my_base(ctx)
{
//std::cout << "Enter Channel_Idle_S0 " << std::endl;
}
};
struct channel_acquiring_fsm_S1: public sc::state<channel_acquiring_fsm_S1, ChannelFsm>
{
public:
typedef mpl::list<sc::transition<Ev_channel_failed_acquisition_no_repeat, channel_waiting_fsm_S3>,
sc::transition<Ev_channel_failed_acquisition_repeat, channel_acquiring_fsm_S1>,
sc::transition<Ev_channel_valid_acquisition, channel_tracking_fsm_S2> > reactions;
channel_acquiring_fsm_S1(my_context ctx) : my_base(ctx)
{
//std::cout << "Enter Channel_Acq_S1 " << std::endl;
context<ChannelFsm> ().start_acquisition();
}
};
struct channel_tracking_fsm_S2: public sc::state<channel_tracking_fsm_S2, ChannelFsm>
{
public:
typedef mpl::list<sc::transition<Ev_channel_failed_tracking_standby, channel_idle_fsm_S0>,
sc::transition<Ev_channel_start_acquisition, channel_acquiring_fsm_S1>> reactions;
channel_tracking_fsm_S2(my_context ctx) : my_base(ctx)
{
//std::cout << "Enter Channel_tracking_S2 " << std::endl;
context<ChannelFsm> ().start_tracking();
}
};
struct channel_waiting_fsm_S3: public sc::state<channel_waiting_fsm_S3, ChannelFsm>
{
public:
typedef sc::transition<Ev_channel_start_acquisition,
channel_acquiring_fsm_S1> reactions;
channel_waiting_fsm_S3(my_context ctx) :
my_base(ctx)
{
//std::cout << "Enter Channel_waiting_S3 " << std::endl;
context<ChannelFsm> ().request_satellite();
}
~channel_waiting_fsm_S3(){}
};
ChannelFsm::ChannelFsm()
{
acq_ = nullptr;
trk_ = nullptr;
channel_ = 0;
initiate(); //start the FSM
}
ChannelFsm::ChannelFsm(AcquisitionInterface *acquisition) :
acq_(acquisition)
{
trk_ = nullptr;
channel_ = 0;
initiate(); //start the FSM
}
void ChannelFsm::Event_start_acquisition()
{
this->process_event(Ev_channel_start_acquisition());
}
void ChannelFsm::Event_valid_acquisition()
{
this->process_event(Ev_channel_valid_acquisition());
}
void ChannelFsm::Event_failed_acquisition_repeat()
{
this->process_event(Ev_channel_failed_acquisition_repeat());
}
void ChannelFsm::Event_failed_acquisition_no_repeat()
{
this->process_event(Ev_channel_failed_acquisition_no_repeat());
}
// Something is wrong here, we are using a memory after it ts freed
void ChannelFsm::Event_failed_tracking_standby()
{
this->process_event(Ev_channel_failed_tracking_standby());
}
//void ChannelFsm::Event_failed_tracking_reacq() {
// this->process_event(Ev_channel_failed_tracking_reacq());
//}
void ChannelFsm::set_acquisition(AcquisitionInterface *acquisition)
{
acq_ = acquisition;
}
void ChannelFsm::set_tracking(TrackingInterface *tracking)
{
trk_ = tracking;
}
void ChannelFsm::set_queue(boost::shared_ptr<gr::msg_queue> queue)
{
queue_ = queue;
}
void ChannelFsm::set_channel(unsigned int channel)
{
channel_ = channel;
}
void ChannelFsm::start_acquisition()
{
acq_->reset();
}
void ChannelFsm::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();
std::unique_ptr<ControlMessageFactory> cmf(new ControlMessageFactory());
if (queue_ != gr::msg_queue::make())
{
queue_->handle(cmf->GetQueueMessage(channel_, 1));
}
}
void ChannelFsm::request_satellite()
{
std::unique_ptr<ControlMessageFactory> cmf(new ControlMessageFactory());
if (queue_ != gr::msg_queue::make())
{
queue_->handle(cmf->GetQueueMessage(channel_, 0));
}
}

View File

@ -1,5 +1,5 @@
/*!
* \file gps_l1_ca_channel_fsm.h
* \file channel_fsm.h
* \brief Interface of the State Machine for channel using boost::statechart
* \author Luis Esteve, 2011. luis(at)epsilon-formacion.com
*
@ -29,8 +29,8 @@
* -------------------------------------------------------------------------
*/
#ifndef GNSS_SDR_GPS_L1_CA_CHANNEL_FSM_H
#define GNSS_SDR_GPS_L1_CA_CHANNEL_FSM_H
#ifndef GNSS_SDR_CHANNEL_FSM_H
#define GNSS_SDR_CHANNEL_FSM_H
#include <cstring>
#include <iostream>
@ -52,19 +52,19 @@
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;
struct channel_idle_fsm_S0;
struct channel_acquiring_fsm_S1;
struct channel_tracking_fsm_S2;
struct 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>
class ChannelFsm: public sc::state_machine<ChannelFsm, channel_idle_fsm_S0>
{
public:
GpsL1CaChannelFsm();
GpsL1CaChannelFsm(AcquisitionInterface *acquisition);
ChannelFsm();
ChannelFsm(AcquisitionInterface *acquisition);
void set_acquisition(AcquisitionInterface *acquisition);
void set_tracking(TrackingInterface *tracking);
@ -75,12 +75,12 @@ public:
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_start_acquisition();
void Event_valid_acquisition();
void Event_failed_acquisition_repeat();
void Event_failed_acquisition_no_repeat();
//void Event_gps_failed_tracking_reacq();
void Event_gps_failed_tracking_standby();
void Event_failed_tracking_standby();
private:
AcquisitionInterface *acq_;
@ -89,4 +89,4 @@ private:
unsigned int channel_;
};
#endif /*GNSS_SDR_GPS_L1_CA_CHANNEL_FSM_H*/
#endif /*GNSS_SDR_CHANNEL_FSM_H*/

View File

@ -1,222 +0,0 @@
/*!
* \file gps_l1_ca_channel_fsm.cc
* \brief Implementation of a State Machine for channel using boost::statechart
* \author Luis Esteve, 2011. luis(at)epsilon-formacion.com
*
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2015 (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 <list>
#include <memory>
#include <glog/logging.h>
#include "control_message_factory.h"
#include "channel.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_standby: sc::event<Ev_gps_channel_failed_tracking_standby>
{};
//struct Ev_gps_channel_failed_tracking_reacq: sc::event<Ev_gps_channel_failed_tracking_reacq>
//{};
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 mpl::list<sc::transition<Ev_gps_channel_failed_tracking_standby, gps_channel_idle_fsm_S0>,
sc::transition<Ev_gps_channel_start_acquisition, 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();
}
~gps_channel_waiting_fsm_S3(){}
};
GpsL1CaChannelFsm::GpsL1CaChannelFsm()
{
acq_ = nullptr;
trk_ = nullptr;
channel_ = 0;
initiate(); //start the FSM
}
GpsL1CaChannelFsm::GpsL1CaChannelFsm(AcquisitionInterface *acquisition) :
acq_(acquisition)
{
trk_ = nullptr;
channel_ = 0;
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());
}
// Something is wrong here, we are using a memory after it ts freed
void GpsL1CaChannelFsm::Event_gps_failed_tracking_standby()
{
this->process_event(Ev_gps_channel_failed_tracking_standby());
}
//void GpsL1CaChannelFsm::Event_gps_failed_tracking_reacq() {
// this->process_event(Ev_gps_channel_failed_tracking_reacq());
//}
void GpsL1CaChannelFsm::set_acquisition(AcquisitionInterface *acquisition)
{
acq_ = acquisition;
}
void GpsL1CaChannelFsm::set_tracking(TrackingInterface *tracking)
{
trk_ = tracking;
}
void GpsL1CaChannelFsm::set_queue(boost::shared_ptr<gr::msg_queue> 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();
std::unique_ptr<ControlMessageFactory> cmf(new ControlMessageFactory());
if (queue_ != gr::msg_queue::make())
{
queue_->handle(cmf->GetQueueMessage(channel_, 1));
}
}
void GpsL1CaChannelFsm::request_satellite()
{
std::unique_ptr<ControlMessageFactory> cmf(new ControlMessageFactory());
if (queue_ != gr::msg_queue::make())
{
queue_->handle(cmf->GetQueueMessage(channel_, 0));
}
}