mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2024-12-15 04:30:33 +00:00
Avoid multithreading collision
This commit is contained in:
parent
cfc0a4a498
commit
74a1f76282
@ -197,7 +197,13 @@ void Channel::set_signal(const Gnss_Signal& gnss_signal)
|
||||
|
||||
void Channel::start_acquisition()
|
||||
{
|
||||
channel_fsm_.Event_start_acquisition();
|
||||
bool result = false;
|
||||
result = channel_fsm_.Event_start_acquisition();
|
||||
if(!result)
|
||||
{
|
||||
LOG(WARNING) << "Invalid channel event";
|
||||
return;
|
||||
}
|
||||
DLOG(INFO) << "Channel start_acquisition()";
|
||||
}
|
||||
|
||||
|
@ -53,53 +53,88 @@ ChannelFsm::ChannelFsm(std::shared_ptr<AcquisitionInterface> acquisition) :
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ChannelFsm::Event_start_acquisition()
|
||||
bool ChannelFsm::Event_start_acquisition()
|
||||
{
|
||||
mx.lock();
|
||||
d_state = 1;
|
||||
start_acquisition();
|
||||
DLOG(INFO) << "CH = " << channel_ << ". Ev start acquisition";
|
||||
mx.unlock();
|
||||
std::lock_guard<std::mutex> lk(mx);
|
||||
if((d_state == 1) || (d_state == 2))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
d_state = 1;
|
||||
start_acquisition();
|
||||
DLOG(INFO) << "CH = " << channel_ << ". Ev start acquisition";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ChannelFsm::Event_valid_acquisition()
|
||||
bool ChannelFsm::Event_valid_acquisition()
|
||||
{
|
||||
mx.lock();
|
||||
d_state = 2;
|
||||
start_tracking();
|
||||
DLOG(INFO) << "CH = " << channel_ << ". Ev valid acquisition";
|
||||
mx.unlock();
|
||||
std::lock_guard<std::mutex> lk(mx);
|
||||
if(d_state != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
d_state = 2;
|
||||
start_tracking();
|
||||
DLOG(INFO) << "CH = " << channel_ << ". Ev valid acquisition";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ChannelFsm::Event_failed_acquisition_repeat()
|
||||
bool ChannelFsm::Event_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()
|
||||
{
|
||||
mx.lock();
|
||||
d_state = 3;
|
||||
request_satellite();
|
||||
DLOG(INFO) << "CH = " << channel_ << ". Ev failed acquisition no repeat";
|
||||
mx.unlock();
|
||||
std::lock_guard<std::mutex> lk(mx);
|
||||
if(d_state != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
d_state = 1;
|
||||
start_acquisition();
|
||||
DLOG(INFO) << "CH = " << channel_ << ". Ev failed acquisition repeat";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ChannelFsm::Event_failed_tracking_standby()
|
||||
bool ChannelFsm::Event_failed_acquisition_no_repeat()
|
||||
{
|
||||
mx.lock();
|
||||
d_state = 0;
|
||||
notify_stop_tracking();
|
||||
DLOG(INFO) << "CH = " << channel_ << ". Ev failed tracking standby";
|
||||
mx.unlock();
|
||||
std::lock_guard<std::mutex> lk(mx);
|
||||
if(d_state != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
d_state = 3;
|
||||
request_satellite();
|
||||
DLOG(INFO) << "CH = " << channel_ << ". Ev failed acquisition no repeat";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool ChannelFsm::Event_failed_tracking_standby()
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(mx);
|
||||
if(d_state != 2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
d_state = 0;
|
||||
notify_stop_tracking();
|
||||
DLOG(INFO) << "CH = " << channel_ << ". Ev failed tracking standby";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void ChannelFsm::set_acquisition(std::shared_ptr<AcquisitionInterface> acquisition)
|
||||
|
@ -54,11 +54,11 @@ public:
|
||||
void set_channel(unsigned int channel);
|
||||
|
||||
//FSM EVENTS
|
||||
void Event_start_acquisition();
|
||||
void Event_valid_acquisition();
|
||||
void Event_failed_acquisition_repeat();
|
||||
void Event_failed_acquisition_no_repeat();
|
||||
void Event_failed_tracking_standby();
|
||||
bool Event_start_acquisition();
|
||||
bool Event_valid_acquisition();
|
||||
bool Event_failed_acquisition_repeat();
|
||||
bool Event_failed_acquisition_no_repeat();
|
||||
bool Event_failed_tracking_standby();
|
||||
|
||||
private:
|
||||
|
||||
|
@ -44,26 +44,27 @@ channel_msg_receiver_cc_sptr channel_msg_receiver_make_cc(ChannelFsm* channel_fs
|
||||
|
||||
void channel_msg_receiver_cc::msg_handler_events(pmt::pmt_t msg)
|
||||
{
|
||||
bool result = false;
|
||||
try
|
||||
{
|
||||
long int message = pmt::to_long(msg);
|
||||
switch (message)
|
||||
{
|
||||
case 1: //positive acquisition
|
||||
d_channel_fsm->Event_valid_acquisition();
|
||||
result = d_channel_fsm->Event_valid_acquisition();
|
||||
break;
|
||||
case 2: //negative acquisition
|
||||
if (d_repeat == true)
|
||||
{
|
||||
d_channel_fsm->Event_failed_acquisition_repeat();
|
||||
result = d_channel_fsm->Event_failed_acquisition_repeat();
|
||||
}
|
||||
else
|
||||
{
|
||||
d_channel_fsm->Event_failed_acquisition_no_repeat();
|
||||
result = d_channel_fsm->Event_failed_acquisition_no_repeat();
|
||||
}
|
||||
break;
|
||||
case 3: // tracking loss of lock event
|
||||
d_channel_fsm->Event_failed_tracking_standby();
|
||||
result = d_channel_fsm->Event_failed_tracking_standby();
|
||||
break;
|
||||
default:
|
||||
LOG(WARNING) << "Default case, invalid message.";
|
||||
@ -74,6 +75,10 @@ void channel_msg_receiver_cc::msg_handler_events(pmt::pmt_t msg)
|
||||
{
|
||||
LOG(WARNING) << "msg_handler_telemetry Bad any cast!";
|
||||
}
|
||||
if(!result)
|
||||
{
|
||||
LOG(WARNING) << "msg_handler_telemetry invalid event";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user