diff --git a/src/algorithms/channel/adapters/channel.cc b/src/algorithms/channel/adapters/channel.cc index ed8832c3f..8689a8d94 100644 --- a/src/algorithms/channel/adapters/channel.cc +++ b/src/algorithms/channel/adapters/channel.cc @@ -103,10 +103,7 @@ Channel::Channel(ConfigurationInterface *configuration, unsigned int channel, // Destructor -Channel::~Channel() -{ - channel_fsm_.terminate(); -} +Channel::~Channel(){} void Channel::connect(gr::top_block_sptr top_block) @@ -139,7 +136,6 @@ void Channel::connect(gr::top_block_sptr top_block) top_block->msg_connect(nav_->get_left_block(), pmt::mp("preamble_timestamp_s"), trk_->get_right_block(), pmt::mp("preamble_timestamp_s")); DLOG(INFO) << "MSG FEEDBACK CHANNEL telemetry_decoder -> tracking"; - //std::cout<<"has port: "<get_right_block()->has_msg_port(pmt::mp("events"))<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")); diff --git a/src/algorithms/channel/libs/channel_fsm.cc b/src/algorithms/channel/libs/channel_fsm.cc index 68e0798aa..e5cb34493 100644 --- a/src/algorithms/channel/libs/channel_fsm.cc +++ b/src/algorithms/channel/libs/channel_fsm.cc @@ -30,15 +30,10 @@ #include "channel_fsm.h" #include -#include -#include -#include -#include -#include #include #include "control_message_factory.h" - +/* struct Ev_channel_start_acquisition: sc::event {}; @@ -53,10 +48,9 @@ struct Ev_channel_failed_acquisition_no_repeat: sc::event {}; +*/ -//struct Ev_channel_failed_tracking_reacq: sc::event -//{}; - +/* struct channel_idle_fsm_S0: public sc::state { public: @@ -114,7 +108,7 @@ public: } ~channel_waiting_fsm_S3(){} }; - +*/ ChannelFsm::ChannelFsm() @@ -122,7 +116,7 @@ ChannelFsm::ChannelFsm() acq_ = nullptr; trk_ = nullptr; channel_ = 0; - initiate(); //start the FSM + d_state = 0; } @@ -132,51 +126,60 @@ ChannelFsm::ChannelFsm(std::shared_ptr acquisition) : { trk_ = nullptr; channel_ = 0; - initiate(); //start the FSM + d_state = 0; } void ChannelFsm::Event_start_acquisition() { - initiate(); - this->process_event(Ev_channel_start_acquisition()); + mx.lock(); + d_state = 1; + start_acquisition(); LOG(INFO) << "FSM Event_start_acquisition"; DLOG(INFO) << "CH = " << channel_ << ". Ev start acquisition"; + mx.unlock(); } void ChannelFsm::Event_valid_acquisition() { - this->process_event(Ev_channel_valid_acquisition()); + mx.lock(); + d_state = 2; + start_tracking(); DLOG(INFO) << "CH = " << channel_ << ". Ev valid acquisition"; + mx.unlock(); } void ChannelFsm::Event_failed_acquisition_repeat() { - this->process_event(Ev_channel_failed_acquisition_repeat()); + mx.lock(); + d_state = 1; + start_acquisition(); DLOG(INFO) << "CH = " << channel_ << ". Ev failed acquisition repeat"; + mx.unlock(); } void ChannelFsm::Event_failed_acquisition_no_repeat() { - this->process_event(Ev_channel_failed_acquisition_no_repeat()); + mx.lock(); + d_state = 3; + request_satellite(); DLOG(INFO) << "CH = " << channel_ << ". Ev failed acquisition no repeat"; + mx.unlock(); } -// 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()); + mx.lock(); + d_state = 0; + notify_stop_tracking(); DLOG(INFO) << "CH = " << channel_ << ". Ev failed tracking standby"; + mx.unlock(); } -//void ChannelFsm::Event_failed_tracking_reacq() { -// this->process_event(Ev_channel_failed_tracking_reacq()); -//} - void ChannelFsm::set_acquisition(std::shared_ptr acquisition) { acq_ = acquisition; diff --git a/src/algorithms/channel/libs/channel_fsm.h b/src/algorithms/channel/libs/channel_fsm.h index 997056723..02be4f1fc 100644 --- a/src/algorithms/channel/libs/channel_fsm.h +++ b/src/algorithms/channel/libs/channel_fsm.h @@ -1,12 +1,12 @@ /*! * \file channel_fsm.h - * \brief Interface of the State Machine for channel using boost::statechart - * \author Luis Esteve, 2011. luis(at)epsilon-formacion.com + * \brief Interface of the State Machine for channel + * \author Antonio Ramos, 2017. antonio.ramos(at)cttc.es * * * ------------------------------------------------------------------------- * - * Copyright (C) 2010-2015 (see AUTHORS file for a list of contributors) + * Copyright (C) 2010-2017 (see AUTHORS file for a list of contributors) * * GNSS-SDR is a software defined Global Navigation * Satellite Systems receiver @@ -32,26 +32,23 @@ #ifndef GNSS_SDR_CHANNEL_FSM_H #define GNSS_SDR_CHANNEL_FSM_H - -#include +#include #include #include "acquisition_interface.h" #include "tracking_interface.h" #include "telemetry_decoder_interface.h" - -namespace sc = boost::statechart; -namespace mpl = boost::mpl; - +/* 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 ChannelFsm: public sc::state_machine +class ChannelFsm { public: ChannelFsm(); @@ -61,24 +58,27 @@ public: void set_tracking(std::shared_ptr tracking); void set_queue(gr::msg_queue::sptr queue); void set_channel(unsigned int channel); - void start_acquisition(); - void start_tracking(); - void request_satellite(); - void notify_stop_tracking(); //FSM EVENTS 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_failed_tracking_standby(); private: + + void start_acquisition(); + void start_tracking(); + void request_satellite(); + void notify_stop_tracking(); + std::shared_ptr acq_; std::shared_ptr trk_; gr::msg_queue::sptr queue_; unsigned int channel_; + unsigned int d_state; + std::mutex mx; }; #endif /*GNSS_SDR_CHANNEL_FSM_H*/