Skip to content
Snippets Groups Projects
Commit 2973a71d authored by Alexandre MALFREYT's avatar Alexandre MALFREYT
Browse files

refactor: rename get_device_property to get_device_properties and extract channel number logic

parent c725c419
Branches
Tags
2 merge requests!4develop -> main,!2[CTRLRFC-1594] Apply memorized dynamic attributes at init
...@@ -219,7 +219,7 @@ void SingleShotAO::init_device() ...@@ -219,7 +219,7 @@ void SingleShotAO::init_device()
//-------------------------------------------- //--------------------------------------------
try try
{ {
get_device_property(); get_device_properties();
} }
catch (const Tango::DevFailed& df) catch (const Tango::DevFailed& df)
{ {
...@@ -543,12 +543,12 @@ void SingleShotAO::init_device() ...@@ -543,12 +543,12 @@ void SingleShotAO::init_device()
//+---------------------------------------------------------------------------- //+----------------------------------------------------------------------------
// //
// method : SingleShotAO::get_device_property() // method : SingleShotAO::get_device_properties()
// //
// description : Read the device properties from database. // description : Read the device properties from database.
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void SingleShotAO::get_device_property() void SingleShotAO::get_device_properties()
{ {
// Initialize your default values here (if not done with POGO). // Initialize your default values here (if not done with POGO).
//------------------------------------------------------------------ //------------------------------------------------------------------
...@@ -664,8 +664,7 @@ void SingleShotAO::always_executed_hook() ...@@ -664,8 +664,7 @@ void SingleShotAO::always_executed_hook()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void SingleShotAO::read_attr_hardware(vector<long> &attr_list) void SingleShotAO::read_attr_hardware(vector<long> &attr_list)
{ {
//DEBUG_STREAM << "SingleShotAO::read_attr_hardware(vector<long> &attr_list) entering... "<< endl; // nothing to do
// Add your own code here
} }
...@@ -678,7 +677,6 @@ void SingleShotAO::read_attr_hardware(vector<long> &attr_list) ...@@ -678,7 +677,6 @@ void SingleShotAO::read_attr_hardware(vector<long> &attr_list)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void SingleShotAO::read_frequency(Tango::Attribute &attr) void SingleShotAO::read_frequency(Tango::Attribute &attr)
{ {
//DEBUG_STREAM << "SingleShotAO::read_frequency(Tango::Attribute &attr) entering... "<< endl;
attr.set_value(&m_frequency); attr.set_value(&m_frequency);
} }
...@@ -757,6 +755,26 @@ Tango::ConstDevString SingleShotAO::dev_status() ...@@ -757,6 +755,26 @@ Tango::ConstDevString SingleShotAO::dev_status()
} }
//+------------------------------------------------------------------
/**
* Extract the first number found in a string.
* Used for extracting the channel number from dynamic attribute names
* like "channelX", "speedX", "initialX" where X is the channel number.
*
* @param str The input string to search for numbers
* @return The first number found in the string
* @throws DevFailed if no number is found in the string
*/
int extractNumber(const std::string &str)
{
size_t pos = str.find_first_of("0123456789");
if (pos == std::string::npos)
raise_error("No number found in string", "extractNumber");
std::string numberStr = str.substr(pos);
return std::stoi(numberStr);
}
//+------------------------------------------------------------------ //+------------------------------------------------------------------
/** /**
* method: SingleShotAO::read_channel * method: SingleShotAO::read_channel
...@@ -768,15 +786,10 @@ Tango::ConstDevString SingleShotAO::dev_status() ...@@ -768,15 +786,10 @@ Tango::ConstDevString SingleShotAO::dev_status()
void SingleShotAO::read_channel(yat4tango::DynamicAttributeReadCallbackData & cbd) void SingleShotAO::read_channel(yat4tango::DynamicAttributeReadCallbackData & cbd)
{ {
yat::AutoMutex<> guard(m_lock); yat::AutoMutex<> guard(m_lock);
std::string l_attr_name = cbd.dya->get_name(); std::string l_attr_name = cbd.dya->get_name();
yat::uint16 l_idx = extractNumber(l_attr_name); // extract channel nb
// name will be channelX
std::string l_str = l_attr_name.substr(7, 2);
yat::uint16 l_idx = atoi(l_str.c_str());
CHECK_MANAGER(); CHECK_MANAGER();
// choose tab depending on l_idx
double l_val = m_manager->get_channel(l_idx); double l_val = m_manager->get_channel(l_idx);
cbd.tga->set_value(&l_val); cbd.tga->set_value(&l_val);
} }
...@@ -796,10 +809,7 @@ void SingleShotAO::write_channel(yat4tango::DynamicAttributeWriteCallbackData & ...@@ -796,10 +809,7 @@ void SingleShotAO::write_channel(yat4tango::DynamicAttributeWriteCallbackData &
cbd.tga->get_write_value(l_val); cbd.tga->get_write_value(l_val);
std::string l_attr_name = cbd.dya->get_name(); std::string l_attr_name = cbd.dya->get_name();
yat::uint16 l_idx = extractNumber(l_attr_name); // extract channel nb
// name will be channelX
std::string l_str = l_attr_name.substr(7, 2);
yat::uint16 l_idx = atoi(l_str.c_str());
CHECK_MANAGER(); CHECK_MANAGER();
try try
...@@ -835,15 +845,10 @@ void SingleShotAO::write_channel(yat4tango::DynamicAttributeWriteCallbackData & ...@@ -835,15 +845,10 @@ void SingleShotAO::write_channel(yat4tango::DynamicAttributeWriteCallbackData &
void SingleShotAO::read_speed(yat4tango::DynamicAttributeReadCallbackData & cbd) void SingleShotAO::read_speed(yat4tango::DynamicAttributeReadCallbackData & cbd)
{ {
yat::AutoMutex<> guard(m_lock); yat::AutoMutex<> guard(m_lock);
std::string l_attr_name = cbd.dya->get_name(); std::string l_attr_name = cbd.dya->get_name();
yat::uint16 l_idx = extractNumber(l_attr_name); // extract channel nb
// name will be speedX
std::string l_str = l_attr_name.substr(5, 2);
yat::uint16 l_idx = atoi(l_str.c_str());
CHECK_MANAGER(); CHECK_MANAGER();
// choose tab depending on l_idx
double l_val = m_manager->get_speed(l_idx); double l_val = m_manager->get_speed(l_idx);
cbd.tga->set_value(&l_val); cbd.tga->set_value(&l_val);
} }
...@@ -865,10 +870,7 @@ void SingleShotAO::write_speed(yat4tango::DynamicAttributeWriteCallbackData & cb ...@@ -865,10 +870,7 @@ void SingleShotAO::write_speed(yat4tango::DynamicAttributeWriteCallbackData & cb
cbd.tga->get_write_value(l_val); cbd.tga->get_write_value(l_val);
std::string l_attr_name = cbd.dya->get_name(); std::string l_attr_name = cbd.dya->get_name();
yat::uint16 l_idx = extractNumber(l_attr_name); // extract channel nb
// name will be speedX
std::string l_str = l_attr_name.substr(5, 2);
yat::uint16 l_idx = atoi(l_str.c_str());
if (l_val < 0) if (l_val < 0)
{ {
l_val = -l_val; l_val = -l_val;
...@@ -909,15 +911,10 @@ void SingleShotAO::write_speed(yat4tango::DynamicAttributeWriteCallbackData & cb ...@@ -909,15 +911,10 @@ void SingleShotAO::write_speed(yat4tango::DynamicAttributeWriteCallbackData & cb
void SingleShotAO::read_initial(yat4tango::DynamicAttributeReadCallbackData & cbd) void SingleShotAO::read_initial(yat4tango::DynamicAttributeReadCallbackData & cbd)
{ {
yat::AutoMutex<> guard(m_lock); yat::AutoMutex<> guard(m_lock);
std::string l_attr_name = cbd.dya->get_name(); std::string l_attr_name = cbd.dya->get_name();
yat::uint16 l_idx = extractNumber(l_attr_name); // extract channel nb
// name will be initialX
std::string l_str = l_attr_name.substr(7, 2);
yat::uint16 l_idx = atoi(l_str.c_str());
CHECK_MANAGER(); CHECK_MANAGER();
// choose tab depending on l_idx
double l_val = m_manager->get_initial(l_idx); double l_val = m_manager->get_initial(l_idx);
cbd.tga->set_value(&l_val); cbd.tga->set_value(&l_val);
} }
...@@ -939,10 +936,7 @@ void SingleShotAO::write_initial(yat4tango::DynamicAttributeWriteCallbackData & ...@@ -939,10 +936,7 @@ void SingleShotAO::write_initial(yat4tango::DynamicAttributeWriteCallbackData &
cbd.tga->get_write_value(l_val); cbd.tga->get_write_value(l_val);
std::string l_attr_name = cbd.dya->get_name(); std::string l_attr_name = cbd.dya->get_name();
yat::uint16 l_idx = extractNumber(l_attr_name); // extract channel nb
// name will be initialX
std::string l_str = l_attr_name.substr(7, 2);
yat::uint16 l_idx = atoi(l_str.c_str());
CHECK_MANAGER(); CHECK_MANAGER();
try try
......
...@@ -219,7 +219,7 @@ public : ...@@ -219,7 +219,7 @@ public :
/** /**
* Read the device properties from database * Read the device properties from database
*/ */
void get_device_property(); void get_device_properties();
//@} //@}
// Here is the end of the automatic code generation part // Here is the end of the automatic code generation part
......
...@@ -180,7 +180,6 @@ void SingleShotAOManager::process_message (yat::Message& msg) ...@@ -180,7 +180,6 @@ void SingleShotAOManager::process_message (yat::Message& msg)
//- THREAD_PERIODIC ------------------ //- THREAD_PERIODIC ------------------
case yat::TASK_PERIODIC: case yat::TASK_PERIODIC:
{ {
//DEBUG_STREAM << "SingleShotAOManager::handle_message::THREAD_PERIODIC" << std::endl;
periodic_job_i(); periodic_job_i();
} }
break; break;
...@@ -209,7 +208,6 @@ void SingleShotAOManager::periodic_job_i() ...@@ -209,7 +208,6 @@ void SingleShotAOManager::periodic_job_i()
//test if a ramp step must occur //test if a ramp step must occur
if (m_currentIndex[l_cpt] != -1) if (m_currentIndex[l_cpt] != -1)
{ {
//DEBUG_STREAM << "Current index for channel" << l_cpt << ": " << m_currentIndex[l_cpt] << endl;
m_isRunning[l_cpt] = true; m_isRunning[l_cpt] = true;
double l_val = 0; double l_val = 0;
l_val = m_ramps[l_cpt][m_currentIndex[l_cpt]]; l_val = m_ramps[l_cpt][m_currentIndex[l_cpt]];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment