Skip to content
Snippets Groups Projects
Commit 09df2a73 authored by Claudio Scafuri's avatar Claudio Scafuri :speech_balloon:
Browse files

add property ReadThreadPollTime, use it for readthread sleep calculations

parent 67b651cd
No related branches found
No related tags found
No related merge requests found
01 - mettere property per tempo loop lettura
02 - separare Axis Init per i tre assi (o togliere del tutto?
03 - gestione ritardo / timeout / errore duranto lo switch di energia
04 - eventi da galil?
......
......@@ -317,6 +317,7 @@ void TwinApuId::get_device_property()
dev_prop.push_back(Tango::DbDatum("MaxTimeToInjectionPosition"));
dev_prop.push_back(Tango::DbDatum("maxTimeToEnergySwitch"));
dev_prop.push_back(Tango::DbDatum("HostPrivileges"));
dev_prop.push_back(Tango::DbDatum("ReadThreadPollTime"));
// is there at least one property to be read ?
if (dev_prop.size()>0)
......@@ -447,6 +448,17 @@ void TwinApuId::get_device_property()
// And try to extract HostPrivileges value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> hostPrivileges;
// Try to initialize ReadThreadPollTime from class property
cl_prop = ds_class->get_class_property(dev_prop[++i].name);
if (cl_prop.is_empty()==false) cl_prop >> readThreadPollTime;
else {
// Try to initialize ReadThreadPollTime from default device value
def_prop = ds_class->get_default_device_property(dev_prop[i].name);
if (def_prop.is_empty()==false) def_prop >> readThreadPollTime;
}
// And try to extract ReadThreadPollTime value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> readThreadPollTime;
}
/*----- PROTECTED REGION ID(TwinApuId::get_device_property_after) ENABLED START -----*/
......@@ -1141,7 +1153,31 @@ void TwinApuId::injection_position()
Tango::ERR);
}
/*----- PROTECTED REGION END -----*/ // TwinApuId::low_energy
}
/*----- PROTECTED REGION END -----*/ // TwinApuId::injection_position
//--------------------------------------------------------
/**
* Method : TwinApuId::add_dynamic_commands()
* Description : Create the dynamic commands if any
* for specified device.
*/
//--------------------------------------------------------
void TwinApuId::add_dynamic_commands()
{
/*----- PROTECTED REGION ID(TwinApuId::add_dynamic_commands) ENABLED START -----*/
// Add your own code to create and add dynamic commands if any
/*----- PROTECTED REGION END -----*/ // TwinApuId::add_dynamic_commands
}
/*----- PROTECTED REGION ID(TwinApu:namespace_ending) ENABLED START -----*/
// Additional Methods
//-------------------------------------------------------------------------------
/**
* assign privileges elevel based on host name from which the call is generated
......@@ -1192,27 +1228,5 @@ int TwinApuId::caller_privileges(void)
}
return NORMAL; //do not grant special privilege - but we should NOT arrive at this line
}
/*----- PROTECTED REGION END -----*/ // TwinApuId::injection_position
//--------------------------------------------------------
/**
* Method : TwinApuId::add_dynamic_commands()
* Description : Create the dynamic commands if any
* for specified device.
*/
//--------------------------------------------------------
void TwinApuId::add_dynamic_commands()
{
/*----- PROTECTED REGION ID(TwinApuId::add_dynamic_commands) ENABLED START -----*/
// Add your own code to create and add dynamic commands if any
/*----- PROTECTED REGION END -----*/ // TwinApuId::add_dynamic_commands
}
/*----- PROTECTED REGION ID(TwinApuId::namespace_ending) ENABLED START -----*/
// Additional Methods
/*----- PROTECTED REGION END -----*/ // TwinApuId::namespace_ending
} // namespace
......@@ -118,6 +118,8 @@ public:
// host:1 host is authorized can read and write when permitted
// host:0 host can only read
vector<string> hostPrivileges;
// ReadThreadPollTime: polling time for the read thread [ms]
Tango::DevULong readThreadPollTime;
bool mandatoryNotDefined;
......
......@@ -57,6 +57,11 @@
<type xsi:type="pogoDsl:StringVectorType"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
</deviceProperties>
<deviceProperties name="ReadThreadPollTime" description="polling time for the read thread [ms]">
<type xsi:type="pogoDsl:UIntType"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<DefaultPropValue>1000</DefaultPropValue>
</deviceProperties>
<commands name="State" description="This command gets the device state (stored in its &lt;i>device_state&lt;/i> data member) and returns it to the caller." execMethod="dev_state" displayLevel="OPERATOR" polledPeriod="0">
<argin description="none.">
<type xsi:type="pogoDsl:VoidType"/>
......
......@@ -446,6 +446,20 @@ void TwinApuIdClass::set_default_property()
}
else
add_wiz_dev_prop(prop_name, prop_desc);
prop_name = "ReadThreadPollTime";
prop_desc = "polling time for the read thread [ms]";
prop_def = "1000";
vect_data.clear();
vect_data.push_back("1000");
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);
}
//--------------------------------------------------------
......
......@@ -31,7 +31,8 @@ void* readthread::run_undetached(void*) {
Tango::DeviceProxy *high_energy_device = _devicebase->high_energy_device;
Tango::DeviceProxy *low_energy_device = _devicebase->low_energy_device;
Tango::DeviceProxy *energy_switch_device = _devicebase->energy_switch_device;
Tango::DevULong poll_time_l = _devicebase->readThreadPollTime;
double poll_time = (double(poll_time_l))/1000.0; //cast and transform in seconds
while (!abortflag) //one second loop
{
gettimeofday(&begin, NULL);
......@@ -92,8 +93,8 @@ void* readthread::run_undetached(void*) {
gettimeofday(&end, NULL);
double diff_time = ((end.tv_sec - begin.tv_sec)
+ ((double) (end.tv_usec - begin.tv_usec)) / 1000000);
double sleep_time = 1 - diff_time;
if (sleep_time > 1 || sleep_time < 0)
double sleep_time = poll_time - diff_time;
if (sleep_time < 0)
sleep_time = 0.99;
usleep(sleep_time * 1000000);
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment