diff --git a/src/SingleShotAO.cpp b/src/SingleShotAO.cpp index 21f3c407deae2ba3c9d491c49d7d9b01ffb6ce28..c312cc24fd8e743d2bb9538e3c06016ae62d3dd4 100755 --- a/src/SingleShotAO.cpp +++ b/src/SingleShotAO.cpp @@ -219,7 +219,7 @@ void SingleShotAO::init_device() //-------------------------------------------- try { - get_device_property(); + get_device_properties(); } catch (const Tango::DevFailed& df) { @@ -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. // //----------------------------------------------------------------------------- -void SingleShotAO::get_device_property() +void SingleShotAO::get_device_properties() { // Initialize your default values here (if not done with POGO). //------------------------------------------------------------------ @@ -664,8 +664,7 @@ void SingleShotAO::always_executed_hook() //----------------------------------------------------------------------------- void SingleShotAO::read_attr_hardware(vector<long> &attr_list) { - //DEBUG_STREAM << "SingleShotAO::read_attr_hardware(vector<long> &attr_list) entering... "<< endl; - // Add your own code here + // nothing to do } @@ -678,7 +677,6 @@ void SingleShotAO::read_attr_hardware(vector<long> &attr_list) //----------------------------------------------------------------------------- void SingleShotAO::read_frequency(Tango::Attribute &attr) { - //DEBUG_STREAM << "SingleShotAO::read_frequency(Tango::Attribute &attr) entering... "<< endl; attr.set_value(&m_frequency); } @@ -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 @@ -768,15 +786,10 @@ Tango::ConstDevString SingleShotAO::dev_status() void SingleShotAO::read_channel(yat4tango::DynamicAttributeReadCallbackData & cbd) { yat::AutoMutex<> guard(m_lock); - std::string l_attr_name = cbd.dya->get_name(); - - // name will be channelX - std::string l_str = l_attr_name.substr(7, 2); - yat::uint16 l_idx = atoi(l_str.c_str()); + yat::uint16 l_idx = extractNumber(l_attr_name); // extract channel nb CHECK_MANAGER(); - // choose tab depending on l_idx double l_val = m_manager->get_channel(l_idx); cbd.tga->set_value(&l_val); } @@ -796,10 +809,7 @@ void SingleShotAO::write_channel(yat4tango::DynamicAttributeWriteCallbackData & cbd.tga->get_write_value(l_val); std::string l_attr_name = cbd.dya->get_name(); - - // name will be channelX - std::string l_str = l_attr_name.substr(7, 2); - yat::uint16 l_idx = atoi(l_str.c_str()); + yat::uint16 l_idx = extractNumber(l_attr_name); // extract channel nb CHECK_MANAGER(); try @@ -835,15 +845,10 @@ void SingleShotAO::write_channel(yat4tango::DynamicAttributeWriteCallbackData & void SingleShotAO::read_speed(yat4tango::DynamicAttributeReadCallbackData & cbd) { yat::AutoMutex<> guard(m_lock); - 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(); - // choose tab depending on l_idx + CHECK_MANAGER(); double l_val = m_manager->get_speed(l_idx); cbd.tga->set_value(&l_val); } @@ -859,16 +864,13 @@ void SingleShotAO::read_speed(yat4tango::DynamicAttributeReadCallbackData & cbd) //+------------------------------------------------------------------ void SingleShotAO::write_speed(yat4tango::DynamicAttributeWriteCallbackData & cbd) { - DEBUG_STREAM << "SingleShotAO::write_speed(): entering... !" << endl; + DEBUG_STREAM << "SingleShotAO::write_speed(): entering... !" << endl; double l_val; cbd.tga->get_write_value(l_val); std::string l_attr_name = cbd.dya->get_name(); - - // name will be speedX - std::string l_str = l_attr_name.substr(5, 2); - yat::uint16 l_idx = atoi(l_str.c_str()); + yat::uint16 l_idx = extractNumber(l_attr_name); // extract channel nb if (l_val < 0) { l_val = -l_val; @@ -909,15 +911,10 @@ void SingleShotAO::write_speed(yat4tango::DynamicAttributeWriteCallbackData & cb void SingleShotAO::read_initial(yat4tango::DynamicAttributeReadCallbackData & cbd) { yat::AutoMutex<> guard(m_lock); - std::string l_attr_name = cbd.dya->get_name(); - - // name will be initialX - std::string l_str = l_attr_name.substr(7, 2); - yat::uint16 l_idx = atoi(l_str.c_str()); + yat::uint16 l_idx = extractNumber(l_attr_name); // extract channel nb CHECK_MANAGER(); - // choose tab depending on l_idx double l_val = m_manager->get_initial(l_idx); cbd.tga->set_value(&l_val); } @@ -933,16 +930,13 @@ void SingleShotAO::read_initial(yat4tango::DynamicAttributeReadCallbackData & cb //+------------------------------------------------------------------ void SingleShotAO::write_initial(yat4tango::DynamicAttributeWriteCallbackData & cbd) { - DEBUG_STREAM << "SingleShotAO::write_initial(): entering... !" << endl; + DEBUG_STREAM << "SingleShotAO::write_initial(): entering... !" << endl; double l_val; cbd.tga->get_write_value(l_val); std::string l_attr_name = cbd.dya->get_name(); - - // name will be initialX - std::string l_str = l_attr_name.substr(7, 2); - yat::uint16 l_idx = atoi(l_str.c_str()); + yat::uint16 l_idx = extractNumber(l_attr_name); // extract channel nb CHECK_MANAGER(); try diff --git a/src/SingleShotAO.h b/src/SingleShotAO.h index 41ed3617534915d8456cfb8defab141e7a61e4d5..d6d477f8b0dab02fed5ecbf6d433b6fd7b7001d0 100755 --- a/src/SingleShotAO.h +++ b/src/SingleShotAO.h @@ -219,7 +219,7 @@ public : /** * Read the device properties from database */ - void get_device_property(); + void get_device_properties(); //@} // Here is the end of the automatic code generation part diff --git a/src/SingleShotAOManager.cpp b/src/SingleShotAOManager.cpp index 1a7122381e94e33a69abdf52bc698df03972c2e6..6e6c2e777344474bdce29b65bd4a68ff870882f2 100755 --- a/src/SingleShotAOManager.cpp +++ b/src/SingleShotAOManager.cpp @@ -180,7 +180,6 @@ void SingleShotAOManager::process_message (yat::Message& msg) //- THREAD_PERIODIC ------------------ case yat::TASK_PERIODIC: { - //DEBUG_STREAM << "SingleShotAOManager::handle_message::THREAD_PERIODIC" << std::endl; periodic_job_i(); } break; @@ -209,7 +208,6 @@ void SingleShotAOManager::periodic_job_i() //test if a ramp step must occur if (m_currentIndex[l_cpt] != -1) { - //DEBUG_STREAM << "Current index for channel" << l_cpt << ": " << m_currentIndex[l_cpt] << endl; m_isRunning[l_cpt] = true; double l_val = 0; l_val = m_ramps[l_cpt][m_currentIndex[l_cpt]];