Skip to content
Snippets Groups Projects
Commit d77c4643 authored by Alexandre MALFREYT's avatar Alexandre MALFREYT Committed by Florent LANGLOIS
Browse files

fix: applied requested changes (by @langlois in !3)

parent e3d05be3
No related branches found
No related tags found
2 merge requests!4develop -> main,!3EnableRamps and OutputMemorizedChannelsAtInit properties
......@@ -380,14 +380,17 @@ void SingleShotAO::init_device()
// Remove existing dynamic attributes to avoid duplicates or other issues
// --------------------------------------------
if (m_dyn_attr_manager) {
try {
if (m_dyn_attr_manager)
{
try
{
m_dyn_attr_manager->remove_attributes();
delete m_dyn_attr_manager;
m_dyn_attr_manager = NULL;
DEBUG_STREAM << "Existing dynamic attributes manager cleaned up" << endl;
}
catch (...) {
catch (...)
{
ERROR_STREAM << "Error cleaning up existing dynamic attributes manager, continuing..." << endl;
// Continue anyway - we'll create a new one
}
......@@ -424,12 +427,6 @@ void SingleShotAO::init_device()
INFO_STREAM << "Creating dynamic attributes for " << m_nb_chan << " channels.";
INFO_STREAM << "Total attributes: " << m_nb_chan * (enableRamps ? 3 : 1) << endl;
// if enableRamps if false, skip speed and initial attributes
if (!enableRamps)
{
INFO_STREAM << "Ramps are disabled. Skipping speed and initial attributes" << std::endl;
}
for (unsigned int l_cpt = 0; l_cpt < m_nb_chan; l_cpt++)
{
yat::OSStream oss;
......@@ -454,7 +451,7 @@ void SingleShotAO::init_device()
dai_channel.tai.max_value = "10.0";
dai_channel.tai.min_value = "-10.0";
dai_channel.tai.description = "Output value for channel " + oss.str() + " (in measurementUnit).";
dai_channel.tai.format = "%1.2f";
dai_channel.tai.format = "%2.1f";
dai_channel.cdb = false;
//- read callback
......@@ -468,7 +465,8 @@ void SingleShotAO::init_device()
l_dynAttrList.push_back(dai_channel);
// if enableRamps if false, skip speed and initial attributes
if (!enableRamps) {
if (!enableRamps)
{
DEBUG_STREAM << "Ramps are disabled. Skipping speed and initial attributes for channel " << l_cpt << std::endl;
continue;
}
......@@ -490,7 +488,7 @@ void SingleShotAO::init_device()
dai_speed.tai.standard_unit = "V/s";
dai_speed.tai.display_unit = "V/s";
dai_speed.tai.description = "Speed for ramp generation, in V/s. If speed is NULL, no ramp generated but direct write on channel output " + oss.str() + " (in measurementUnit).";
dai_speed.tai.format = "%1.2f";
dai_speed.tai.format = "%2.1f";
//- cleanup tango db option: cleanup tango db when removing this dyn. attr. (i.e. erase its properties from db)
dai_speed.cdb = false;
......@@ -523,7 +521,7 @@ void SingleShotAO::init_device()
dai_initial.tai.standard_unit = "V";
dai_initial.tai.display_unit = "V";
dai_initial.tai.description = "Initial value for ramp function, in V. Defaults to last written value in channel attribute " + oss.str() + ".";
dai_initial.tai.format = "%1.2f";
dai_initial.tai.format = "%2.1f";
//- cleanup tango db option: cleanup tango db when removing this dyn. attr. (i.e. erase its properties from db)
dai_initial.cdb = false;
......@@ -543,17 +541,20 @@ void SingleShotAO::init_device()
INFO_STREAM << "Prepared " << l_dynAttrList.size() << " dynamic attributes for creation" << endl;
// Add all attributes
try {
try
{
m_dyn_attr_manager->add_attributes(l_dynAttrList);
INFO_STREAM << "Successfully added all dynamic attributes" << endl;
}
catch (Tango::DevFailed &df) {
catch (Tango::DevFailed &df)
{
ERROR_STREAM << "Failed to add dynamic attributes: " << df << endl;
m_currStatus = "Failed to add dynamic attributes. See log for details";
m_state = Tango::FAULT;
return;
}
catch (...) {
catch (...)
{
ERROR_STREAM << "Unknown exception when adding dynamic attributes" << endl;
m_currStatus = "Failed to add dynamic attributes. Unknown error";
m_state = Tango::FAULT;
......@@ -561,17 +562,21 @@ void SingleShotAO::init_device()
}
// Initialize maps in manager class for all channels
try {
for (unsigned int l_cpt = 0; l_cpt < m_nb_chan; l_cpt++) {
try
{
for (unsigned int l_cpt = 0; l_cpt < m_nb_chan; l_cpt++)
{
// Initialize with default values
m_manager->set_channel(l_cpt, 0.0);
if (enableRamps) {
if (enableRamps)
{
m_manager->set_speed(l_cpt, 0.0);
m_manager->set_initial(l_cpt, 0.0);
}
}
}
catch (Tango::DevFailed &df) {
catch (Tango::DevFailed &df)
{
ERROR_STREAM << "Failed to initialize channel maps: " << df << endl;
m_currStatus = "Failed to initialize channel maps. See log for details";
m_state = Tango::FAULT;
......@@ -588,7 +593,8 @@ void SingleShotAO::init_device()
auto applyMemorizedAttr = [&](const std::string& attrPrefix,
void (SingleShotAOManager::*setter)(yat::uint16, double))
{
try {
try
{
std::string attrName = attrPrefix + oss.str();
double val = yat4tango::PropertyHelper::get_memorized_attribute<double>(this, attrName);
DEBUG_STREAM << "Found memorized value for " << attrName << ": " << val << endl;
......@@ -599,18 +605,21 @@ void SingleShotAO::init_device()
// Write the value to the "write" attributes using helper function
setDynamicAttributeWriteValue(attrName, val);
}
catch (...) {
catch (...)
{
// nothing to do
}
};
// Get and set memorized values for speed, initial and channel
if (enableRamps) {
if (enableRamps)
{
applyMemorizedAttr(kSPEED, &SingleShotAOManager::set_speed);
applyMemorizedAttr(kINITIAL, &SingleShotAOManager::set_initial);
}
if (outputMemorizedChannelsAtInit) {
if (outputMemorizedChannelsAtInit)
{
applyMemorizedAttr(kCHANNEL, &SingleShotAOManager::write_channel_direct); // write memorized value to board output (directly, without ramp)
} else {
applyMemorizedAttr(kCHANNEL, &SingleShotAOManager::set_channel); // only apply memorized value to the device
......@@ -663,7 +672,8 @@ void SingleShotAO::get_device_property()
// Call database and extract values
//--------------------------------------------
if (Tango::Util::instance()->_UseDb==true) {
if (Tango::Util::instance()->_UseDb==true)
{
get_db_device()->get_property(dev_prop);
}
......@@ -736,7 +746,8 @@ void SingleShotAO::get_device_property()
ERROR_STREAM << "Required device property <BoardType> is missing" << endl;
critical_properties_missing = true;
}
if (critical_properties_missing) {
if (critical_properties_missing)
{
return;
}
......@@ -1131,7 +1142,8 @@ void SingleShotAO::write_initial(yat4tango::DynamicAttributeWriteCallbackData &
*/
bool SingleShotAO::setDynamicAttributeWriteValue(const std::string& attrName, double value)
{
try {
try
{
Tango::DeviceImpl* dev = static_cast<Tango::DeviceImpl*>(this);
Tango::DevDouble val_to_write = value;
......@@ -1142,12 +1154,14 @@ bool SingleShotAO::setDynamicAttributeWriteValue(const std::string& attrName, do
DEBUG_STREAM << "Set write value for " << attrName << " to " << value << endl;
return true;
}
catch (Tango::DevFailed &df) {
catch (Tango::DevFailed &df)
{
ERROR_STREAM << "Failed to set write value for " << attrName
<< ": " << df << endl;
return false;
}
catch (...) {
catch (...)
{
ERROR_STREAM << "Unknown exception setting write value for "
<< attrName << endl;
return false;
......@@ -1195,7 +1209,8 @@ void SingleShotAO::_abort()
// memorize the current initial_values and value of channels
for (unsigned int l_cpt = 0; l_cpt < m_nb_chan; l_cpt++)
{
if (m_manager->is_running(l_cpt)) {
if (m_manager->is_running(l_cpt))
{
DEBUG_STREAM << "Channel " << l_cpt << " is running. Memorizing values..." << std::endl;
double l_val_channel = m_manager->get_channel(l_cpt);
......
......@@ -87,7 +87,8 @@ __declspec(dllexport)
#endif
Tango::DeviceClass *_create_SingleShotAO_class(const char *name) {
Tango::DeviceClass *_create_SingleShotAO_class(const char *name)
{
return SingleShotAO_ns::SingleShotAOClass::init(name);
}
}
......
......@@ -54,9 +54,11 @@ public:
double get_channel(ChannelId_t p_chIdx);
//- set channel
// Updates the value for the channel in the device without sending it to hardware
void set_channel(ChannelId_t p_chIdx, double p_val);
//- write channel
// Writes value to the channel to the device and the hardware, with a ramp if speed is not null and EnableRamps property is true
void write_channel(ChannelId_t p_chIdx, double p_val);
//- write a channel directly (without ramp)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment