diff --git a/src/algorithms/channel/adapters/channel.cc b/src/algorithms/channel/adapters/channel.cc index 4a14f3d7b..6e1d56569 100644 --- a/src/algorithms/channel/adapters/channel.cc +++ b/src/algorithms/channel/adapters/channel.cc @@ -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: diff --git a/src/algorithms/channel/adapters/channel.h b/src/algorithms/channel/adapters/channel.h index fa965b153..2008d4076 100644 --- a/src/algorithms/channel/adapters/channel.h +++ b/src/algorithms/channel/adapters/channel.h @@ -38,7 +38,7 @@ #include #include #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 queue_; concurrent_queue channel_internal_queue_; boost::thread ch_thread_; diff --git a/src/algorithms/channel/libs/CMakeLists.txt b/src/algorithms/channel/libs/CMakeLists.txt index d14fa2f7e..badf5f8b0 100644 --- a/src/algorithms/channel/libs/CMakeLists.txt +++ b/src/algorithms/channel/libs/CMakeLists.txt @@ -16,7 +16,7 @@ # along with GNSS-SDR. If not, see . # -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}) \ No newline at end of file +add_dependencies(channel_fsm glog-${glog_RELEASE}) diff --git a/src/algorithms/channel/libs/channel_fsm.cc b/src/algorithms/channel/libs/channel_fsm.cc new file mode 100644 index 000000000..7abb010be --- /dev/null +++ b/src/algorithms/channel/libs/channel_fsm.cc @@ -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 . + * + * ------------------------------------------------------------------------- + */ + +#include "channel_fsm.h" +#include +#include +#include +#include "control_message_factory.h" +#include "channel.h" + + +struct Ev_channel_start_acquisition: sc::event +{}; + +struct Ev_channel_valid_acquisition: sc::event +{}; + +struct Ev_channel_failed_acquisition_repeat: sc::event +{}; + +struct Ev_channel_failed_acquisition_no_repeat: sc::event +{}; + +struct Ev_channel_failed_tracking_standby: sc::event +{}; + +//struct Ev_channel_failed_tracking_reacq: sc::event +//{}; + +struct channel_idle_fsm_S0: public sc::state +{ +public: + // sc::transition(event, next state) + typedef sc::transition 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 +{ +public: + typedef mpl::list, + sc::transition, + sc::transition > reactions; + + channel_acquiring_fsm_S1(my_context ctx) : my_base(ctx) + { + //std::cout << "Enter Channel_Acq_S1 " << std::endl; + context ().start_acquisition(); + } +}; + + +struct channel_tracking_fsm_S2: public sc::state +{ +public: + typedef mpl::list, + sc::transition> reactions; + + channel_tracking_fsm_S2(my_context ctx) : my_base(ctx) + { + //std::cout << "Enter Channel_tracking_S2 " << std::endl; + context ().start_tracking(); + } + +}; + + +struct channel_waiting_fsm_S3: public sc::state +{ +public: + typedef sc::transition reactions; + + channel_waiting_fsm_S3(my_context ctx) : + my_base(ctx) + { + //std::cout << "Enter Channel_waiting_S3 " << std::endl; + context ().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 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 cmf(new ControlMessageFactory()); + if (queue_ != gr::msg_queue::make()) + { + queue_->handle(cmf->GetQueueMessage(channel_, 1)); + } +} + +void ChannelFsm::request_satellite() +{ + std::unique_ptr cmf(new ControlMessageFactory()); + if (queue_ != gr::msg_queue::make()) + { + queue_->handle(cmf->GetQueueMessage(channel_, 0)); + } +} + diff --git a/src/algorithms/channel/libs/gps_l1_ca_channel_fsm.h b/src/algorithms/channel/libs/channel_fsm.h similarity index 77% rename from src/algorithms/channel/libs/gps_l1_ca_channel_fsm.h rename to src/algorithms/channel/libs/channel_fsm.h index fa5610a95..6540cf78f 100644 --- a/src/algorithms/channel/libs/gps_l1_ca_channel_fsm.h +++ b/src/algorithms/channel/libs/channel_fsm.h @@ -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 #include @@ -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 +class ChannelFsm: public sc::state_machine { 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*/ diff --git a/src/algorithms/channel/libs/gps_l1_ca_channel_fsm.cc b/src/algorithms/channel/libs/gps_l1_ca_channel_fsm.cc deleted file mode 100644 index f6d51b453..000000000 --- a/src/algorithms/channel/libs/gps_l1_ca_channel_fsm.cc +++ /dev/null @@ -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 . - * - * ------------------------------------------------------------------------- - */ - -#include "gps_l1_ca_channel_fsm.h" -#include -#include -#include -#include "control_message_factory.h" -#include "channel.h" - - -struct Ev_gps_channel_start_acquisition: sc::event -{}; - -struct Ev_gps_channel_valid_acquisition: sc::event -{}; - -struct Ev_gps_channel_failed_acquisition_repeat: sc::event -{}; - -struct Ev_gps_channel_failed_acquisition_no_repeat: sc::event -{}; - -struct Ev_gps_channel_failed_tracking_standby: sc::event -{}; - -//struct Ev_gps_channel_failed_tracking_reacq: sc::event -//{}; - -struct gps_channel_idle_fsm_S0: public sc::state -{ -public: - // sc::transition(event, next state) - typedef sc::transition 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 -{ -public: - typedef mpl::list, - sc::transition, - sc::transition > reactions; - - gps_channel_acquiring_fsm_S1(my_context ctx) : my_base(ctx) - { - //std::cout << "Enter Channel_Acq_S1 " << std::endl; - context ().start_acquisition(); - } -}; - - -struct gps_channel_tracking_fsm_S2: public sc::state -{ -public: - typedef mpl::list, - sc::transition> reactions; - - gps_channel_tracking_fsm_S2(my_context ctx) : my_base(ctx) - { - //std::cout << "Enter Channel_tracking_S2 " << std::endl; - context ().start_tracking(); - } - -}; - - -struct gps_channel_waiting_fsm_S3: public sc::state -{ -public: - typedef sc::transition reactions; - - gps_channel_waiting_fsm_S3(my_context ctx) : - my_base(ctx) - { - //std::cout << "Enter Channel_waiting_S3 " << std::endl; - context ().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 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 cmf(new ControlMessageFactory()); - if (queue_ != gr::msg_queue::make()) - { - queue_->handle(cmf->GetQueueMessage(channel_, 1)); - } -} - -void GpsL1CaChannelFsm::request_satellite() -{ - std::unique_ptr cmf(new ControlMessageFactory()); - if (queue_ != gr::msg_queue::make()) - { - queue_->handle(cmf->GetQueueMessage(channel_, 0)); - } -} -