Skip to content
Snippets Groups Projects
Commit 155a4390 authored by Gwenaelle ABEILLE's avatar Gwenaelle ABEILLE
Browse files

better managment of state machine

parent 8a915610
No related branches found
No related tags found
No related merge requests found
......@@ -184,8 +184,11 @@ void PulseGeneration::delete_device()
try
{
pulses->release();
if(generation_type.compare("CONTINUOUS") == 0)
if(!useExtStartTrigger && generation_type.compare("RETRIG") != 0)
{
start_trigger->release();
}
}catch(...)
{
//ignore
......@@ -198,7 +201,7 @@ void PulseGeneration::delete_device()
delete pulses;
pulses = 0;
}
if(generation_type.compare("CONTINUOUS") == 0)
if(!useExtStartTrigger && generation_type.compare("RETRIG") != 0)
if(start_trigger)
{
delete start_trigger;
......@@ -695,7 +698,26 @@ void PulseGeneration::get_device_property()
//-----------------------------------------------------------------------------
void PulseGeneration::always_executed_hook()
{
if(generation_type.compare("FINITE") == 0 && this->get_state() == Tango::RUNNING)
{
bool is_finished =false;
pulses->is_done(is_finished);
if(is_finished)
this->stop();
}
if(clock.compare("INTERNAL") != 0 && this->get_state() == Tango::RUNNING)
{
std::stringstream s;
for(int i=0; i<8;i++)
{
if(ctr_enable[i])
s<<"Delay ctr"<<i<<": "<<delay_ticks[i]<<" clk ticks; "
<<"Pulse width ctr"<<i<<": "<<pulse_width_ticks[i]<<" clk ticks"<<endl;
}
s << ends;
string status_str = s.str();
this->set_status(status_str.c_str());
}
}
//+----------------------------------------------------------------------------
//
......@@ -732,19 +754,6 @@ void PulseGeneration::read_attr_hardware(vector<long> &attr_list)
}
}*/
//this->set_internal_state();
if(clock.compare("INTERNAL") != 0 && this->get_state() == Tango::RUNNING)
{
std::stringstream s;
for(int i=0; i<8;i++)
{
if(ctr_enable[i])
s<<"Delay ctr"<<i<<": "<<delay_ticks[i]<<" clk ticks; "
<<"Pulse width ctr"<<i<<": "<<pulse_width_ticks[i]<<" clk ticks"<<endl;
}
s << ends;
string status_str = s.str();
this->set_status(status_str.c_str());
}
}
//+----------------------------------------------------------------------------
//
......@@ -2088,21 +2097,6 @@ void PulseGeneration::write_counter7Enable(Tango::WAttribute &attr)
this->init_counters();
}
//+----------------------------------------------------------------------------
//
// method : PulseGeneration::wait_and_stop
//
// description : static method to wait for end of generation
//
//-----------------------------------------------------------------------------
void PulseGeneration::wait_and_stop(void* me)
{
PulseGeneration* obj = (PulseGeneration*) me;
cout << "waiting" << endl;
obj->pulses->wait_finished(-1);
obj->stop();
cout << "finished" << endl;
}
//+------------------------------------------------------------------
/**
* method: PulseGeneration::start
......@@ -2149,19 +2143,6 @@ void PulseGeneration::start()
this->set_status("Warning: All counters are disable!");
this->set_state(Tango::RUNNING);
}
// this->update_values();
/*
static omni_thread* create(void (*fn)(void*), void* arg = NULL,
priority_t pri = PRIORITY_NORMAL);
static omni_thread* create(void* (*fn)(void*), void* arg = NULL,
priority_t pri = PRIORITY_NORMAL);*/
if(generation_type.compare("FINITE") == 0)
{
omni_thread::sleep(0,10000);
omni_thread::create(PulseGeneration::wait_and_stop,(void*)this);
}
}
......@@ -2179,23 +2160,24 @@ void PulseGeneration::stop()
{
DEBUG_STREAM << "PulseGeneration::stop(): entering... !" << endl;
if(generation_type.compare("RETRIG") !=0 && !useExtStartTrigger)
{
_NI660XSL_TRY_ACTION
(
pulses->stop(),
start_trigger->stop(),
"stop",
"PulseGeneration::stop",
this->set_internal_state()
);
if(generation_type.compare("RETRIG") !=0 && !useExtStartTrigger)
_NI660XSL_TRY_ACTION
(
start_trigger->stop(),
pulses->stop(),
"stop",
"PulseGeneration::stop",
this->set_internal_state()
);
}
//reconfigure everything here because when using a start trigger
// the start trigger in taken into account only when executing the first Start.
this->init_counters();
......@@ -2381,7 +2363,9 @@ void PulseGeneration::init_counters(void)
{
pulses->release();
if(!useExtStartTrigger && generation_type.compare("RETRIG") != 0)
{
start_trigger->release();
}
}catch(...)
{
......
......@@ -770,7 +770,6 @@ protected :
void init_counters(void);
void update_values(void);
void set_internal_state(void);
static void wait_and_stop(void* me);
ni660Xsl::OutputOperation* pulses;
ni660Xsl::FinitePulseTrainGeneration* start_trigger;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment