From 64affbdfac61db2eae33265525b01f8fd8dc5614 Mon Sep 17 00:00:00 2001 From: gscalamera <graziano.scalamera@elettra.eu> Date: Fri, 11 Aug 2023 16:07:39 +0200 Subject: [PATCH] Add HasVelocityAcceleration flag --- src/ConexAgp.cpp | 32 ++++++++++++++++++++++++++++++++ src/ConexAgp.h | 2 ++ src/ConexAgpClass.cpp | 13 +++++++++++++ src/readthread.cpp | 21 ++++++++++++--------- 4 files changed, 59 insertions(+), 9 deletions(-) diff --git a/src/ConexAgp.cpp b/src/ConexAgp.cpp index cb1d261..2fe582e 100644 --- a/src/ConexAgp.cpp +++ b/src/ConexAgp.cpp @@ -310,6 +310,7 @@ void ConexAgp::get_device_property() dev_prop.push_back(Tango::DbDatum("DeviceName")); dev_prop.push_back(Tango::DbDatum("ControllerAddr")); dev_prop.push_back(Tango::DbDatum("LegacySerial")); + dev_prop.push_back(Tango::DbDatum("HasVelocityAcceleration")); // is there at least one property to be read ? if (dev_prop.size()>0) @@ -357,6 +358,17 @@ void ConexAgp::get_device_property() // And try to extract LegacySerial value from database if (dev_prop[i].is_empty()==false) dev_prop[i] >> legacySerial; + // Try to initialize HasVelocityAcceleration from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> hasVelocityAcceleration; + else { + // Try to initialize HasVelocityAcceleration from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> hasVelocityAcceleration; + } + // And try to extract HasVelocityAcceleration value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> hasVelocityAcceleration; + } /*----- PROTECTED REGION ID(ConexAgp::get_device_property_after) ENABLED START -----*/ @@ -485,6 +497,11 @@ void ConexAgp::read_Acceleration(Tango::Attribute &attr) { DEBUG_STREAM << "ConexAgp::read_Acceleration(Tango::Attribute &attr) entering... " << endl; /*----- PROTECTED REGION ID(ConexAgp::read_Acceleration) ENABLED START -----*/ + if(!hasVelocityAcceleration) + Tango::Except::throw_exception( + (const char *) "NotSupported", + (const char *) "Not supported", + (const char *) __func__, Tango::ERR); // Set the attribute value attr.set_value(attr_Acceleration_read); @@ -506,6 +523,11 @@ void ConexAgp::write_Acceleration(Tango::WAttribute &attr) Tango::DevDouble w_val; attr.get_write_value(w_val); /*----- PROTECTED REGION ID(ConexAgp::write_Acceleration) ENABLED START -----*/ + if(!hasVelocityAcceleration) + Tango::Except::throw_exception( + (const char *) "NotSupported", + (const char *) "Not supported", + (const char *) __func__, Tango::ERR); string resp("NO"); stringstream cmd; cmd << SET_ACCELERATION << w_val; @@ -527,6 +549,11 @@ void ConexAgp::read_Speed(Tango::Attribute &attr) DEBUG_STREAM << "ConexAgp::read_Speed(Tango::Attribute &attr) entering... " << endl; /*----- PROTECTED REGION ID(ConexAgp::read_Speed) ENABLED START -----*/ // Set the attribute value + if(!hasVelocityAcceleration) + Tango::Except::throw_exception( + (const char *) "NotSupported", + (const char *) "Not supported", + (const char *) __func__, Tango::ERR); attr.set_value(attr_Speed_read); /*----- PROTECTED REGION END -----*/ // ConexAgp::read_Speed @@ -547,6 +574,11 @@ void ConexAgp::write_Speed(Tango::WAttribute &attr) Tango::DevDouble w_val; attr.get_write_value(w_val); /*----- PROTECTED REGION ID(ConexAgp::write_Speed) ENABLED START -----*/ + if(!hasVelocityAcceleration) + Tango::Except::throw_exception( + (const char *) "NotSupported", + (const char *) "Not supported", + (const char *) __func__, Tango::ERR); string resp("NO"); stringstream cmd; cmd << SET_SPEED << w_val; diff --git a/src/ConexAgp.h b/src/ConexAgp.h index b72418e..4bb7c36 100644 --- a/src/ConexAgp.h +++ b/src/ConexAgp.h @@ -110,6 +110,8 @@ public: Tango::DevLong controllerAddr; // LegacySerial: Use legacy serial-srv Tango::DevBoolean legacySerial; + // HasVelocityAcceleration: VA and AC command supported + Tango::DevBoolean hasVelocityAcceleration; // Attribute data members public: diff --git a/src/ConexAgpClass.cpp b/src/ConexAgpClass.cpp index a947aab..18565d5 100644 --- a/src/ConexAgpClass.cpp +++ b/src/ConexAgpClass.cpp @@ -413,6 +413,19 @@ void ConexAgpClass::set_default_property() } else add_wiz_dev_prop(prop_name, prop_desc); + prop_name = "HasVelocityAcceleration"; + prop_desc = "VA and AC command supported"; + prop_def = "true"; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); } //-------------------------------------------------------- diff --git a/src/readthread.cpp b/src/readthread.cpp index 4045ed2..da6038b 100644 --- a/src/readthread.cpp +++ b/src/readthread.cpp @@ -144,15 +144,18 @@ void readthread::run(void *) *(_device->attr_TargetPosition_read) = postx; INFO_STREAM << __func__<<": " << posx << " -> "<<*(_device->attr_TargetPosition_read); usleep(10000); - double posa; - _device->SendReceive(string(GET_ACCELERATION), posa); - *(_device->attr_Acceleration_read) = posa; - INFO_STREAM << __func__<<": " << posx << " -> "<<*(_device->attr_Acceleration_read); - usleep(10000); - double posv; - _device->SendReceive(string(GET_SPEED), posv); - *(_device->attr_Speed_read) = posv; - INFO_STREAM << __func__<<": " << posx << " -> "<<*(_device->attr_Speed_read); + if(_device->hasVelocityAcceleration) + { + double posa; + _device->SendReceive(string(GET_ACCELERATION), posa); + *(_device->attr_Acceleration_read) = posa; + INFO_STREAM << __func__<<": " << posx << " -> "<<*(_device->attr_Acceleration_read); + usleep(10000); + double posv; + _device->SendReceive(string(GET_SPEED), posv); + *(_device->attr_Speed_read) = posv; + INFO_STREAM << __func__<<": " << posx << " -> "<<*(_device->attr_Speed_read); + } abort_sleep(1); } -- GitLab