Skip to content
Snippets Groups Projects

Refactoring of ContinuousAO code : Communalisation of copy/pasted portions of code

2 files
+ 191
462
Compare changes
  • Side-by-side
  • Inline

Files

+ 1089
1371
@@ -75,18 +75,20 @@ namespace ContinuousAO
@@ -75,18 +75,20 @@ namespace ContinuousAO
// - s : Device name
// - s : Device name
//
//
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
ContinuousAO::ContinuousAO(Tango::DeviceClass *cl,string &s):Tango::Device_2Impl(cl,s.c_str())
ContinuousAO::ContinuousAO(Tango::DeviceClass *cl,string &s) : Tango::Device_2Impl(cl,s.c_str()),
 
m_default_waveform(2, asl::AOScaledData(0))
{
{
init_device();
init_device();
}
}
ContinuousAO::ContinuousAO(Tango::DeviceClass *cl,const char *s):Tango::Device_2Impl(cl,s)
ContinuousAO::ContinuousAO(Tango::DeviceClass *cl,const char *s) : Tango::Device_2Impl(cl,s),
 
m_default_waveform(2, asl::AOScaledData(0))
{
{
init_device();
init_device();
}
}
ContinuousAO::ContinuousAO(Tango::DeviceClass *cl,const char *s,const char *d)
ContinuousAO::ContinuousAO(Tango::DeviceClass *cl,const char *s,const char *d) : Tango::Device_2Impl(cl,s,d),
:Tango::Device_2Impl(cl,s,d)
m_default_waveform(2, asl::AOScaledData(0))
{
{
init_device();
init_device();
}
}
@@ -99,51 +101,77 @@ ContinuousAO::ContinuousAO(Tango::DeviceClass *cl,const char *s,const char *d)
@@ -99,51 +101,77 @@ ContinuousAO::ContinuousAO(Tango::DeviceClass *cl,const char *s,const char *d)
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void ContinuousAO::delete_device()
void ContinuousAO::delete_device()
{
{
// Delete device's allocated object
if(m_ao)
if(ao)
{
{
delete ao;
delete m_ao;
ao = 0;
m_ao = 0;
}
}
if(ch0)
 
for (int i = 0; i < 8; i++)
{
{
delete ch0;
if (m_channel[i] != nullptr)
ch0 = 0;
}
if(ch1)
{
{
delete ch1;
delete m_channel[i];
ch1 = 0;
m_channel[i] = nullptr;
}
}
if(ch2)
{
delete ch2;
ch2 = 0;
}
}
if(ch3)
}
 
 
 
asl::AOScaledData ContinuousAO::assign_default_waveform(Tango::DevDouble p_ref, std::function <double(int, int)> p_lambda, int p_first_channel, int p_last_channel)
 
{
 
// default waveform for group defined
 
asl::AOScaledData result = asl::AOScaledData(bufferDepth);
 
 
double max_val;
 
 
if(aORefSource == adl::external_reference)
 
max_val = p_ref;
 
else
 
max_val = 10.0;
 
 
// fill buffer with a sin signal
 
for (unsigned long i = 0; i < bufferDepth; i++)
{
{
delete ch3;
(result)[i] = p_lambda(i, max_val);
ch3 = 0;
}
}
if(ch4)
 
//Assignation of waveform for group
 
for (int i = p_first_channel; i <= p_last_channel; i++)
{
{
delete ch4;
ACE_OS::memcpy(m_channel[i], result.base(), result.size());
ch4 = 0;
}
}
if(ch5)
 
return (result);
 
}
 
 
 
void ContinuousAO::activate_channel(int p_channel_index, vector<double>& p_channel_wave_form, asl::AOScaledData& p_default_waveform)
 
{
 
m_ac.id = p_channel_index;
 
if(aORefSource == adl::external_reference)
 
m_ac.volt_ref = aORefA;
 
m_config.add_active_channel(m_ac);
 
 
if(p_channel_wave_form.empty())
{
{
delete ch5;
WARN_STREAM<<"No waveform is saved in database for channel " << p_channel_index << ", using a default one"<<endl;
ch5 = 0;
m_config.set_channel_periodic_data(p_channel_index, p_default_waveform);
}
}
if(ch6)
else if(p_channel_wave_form.size() != bufferDepth)
{
{
delete ch6;
WARN_STREAM<<"The waveform saved in database for channel " << p_channel_index << " has a different size from property BufferDepth, using default waveform"<<endl;
ch6 = 0;
m_config.set_channel_periodic_data(p_channel_index, p_default_waveform);
}
}
if(ch7)
else
{
{
delete ch7;
asl::AOScaledData data(bufferDepth);
ch7 = 0;
for(int i=0; i<bufferDepth; i++)
 
data[i] = p_channel_wave_form[i];
 
// put the waveform in the configuration
 
m_config.set_channel_periodic_data(p_channel_index, data);
 
//cpy data in the attribute of the device
 
::memcpy(m_channel[p_channel_index], data.base(), data.size());
}
}
}
}
@@ -158,15 +186,8 @@ void ContinuousAO::init_device()
@@ -158,15 +186,8 @@ void ContinuousAO::init_device()
{
{
INFO_STREAM << "ContinuousAO::ContinuousAO() create device " << device_name << endl;
INFO_STREAM << "ContinuousAO::ContinuousAO() create device " << device_name << endl;
ao = 0;
m_ao = nullptr;
ch0 = 0;
ch1 = 0;
ch2 = 0;
ch3 = 0;
ch4 = 0;
ch5 = 0;
ch6 = 0;
ch7 = 0;
m_error_message = "An error has occured";
m_error_message = "An error has occured";
// Initialise variables to default values
// Initialise variables to default values
@@ -174,71 +195,39 @@ void ContinuousAO::init_device()
@@ -174,71 +195,39 @@ void ContinuousAO::init_device()
get_device_property();
get_device_property();
//- create a continuous analog output daq
//- create a continuous analog output daq
ao = new ADLinkContinuousAO(this);
m_ao = new ADLinkContinuousAO(this);
//- check memory allocation
//- check memory allocation
if (ao == 0)
if (m_ao == nullptr)
{
{
raise_error("ContinuousAO::init_device\nout of memory error while initializing ADLinkContinuousAO");
on_fault("ContinuousAO::init_device\nout of memory error while initializing ADLinkContinuousAO");
return;
return;
}
}
asl::ContinuousAOConfig config;
asl::ContinuousAOConfig config;
ch0 = new double[bufferDepth];
ch1 = new double[bufferDepth];
ch2 = new double[bufferDepth];
ch3 = new double[bufferDepth];
ch4 = new double[bufferDepth];
ch5 = new double[bufferDepth];
ch6 = new double[bufferDepth];
ch7 = new double[bufferDepth];
if(ch0 == 0 || ch1 == 0 || ch2 == 0 || ch3 == 0 || ch4 == 0 || ch5 == 0 ||ch6 == 0 || ch7 == 0)
{
raise_error("ContinuousAO::init_device\nout of memory error while initializing channel's datas");
return;
}
for (int i = 0; i < 8; i++)
// default waveform for group A (channel 0 to 3)
{
asl::AOScaledData default_waveformA(bufferDepth);
m_channel[i] = new double[bufferDepth];
double max_valA;
if(m_channel[i] == nullptr)
if(aORefSource == adl::external_reference)
max_valA = aORefA ;
else
max_valA = 10.0;
// fill buffer with a sin signal
for (unsigned long i = 0; i < bufferDepth; i++)
{
{
(default_waveformA)[i] = ::sin((double)i * 2. * 3.14159 / (double) bufferDepth) * max_valA;
on_fault("ContinuousAO::init_device\nout of memory error while initializing channel's datas");
 
return;
 
}
}
}
ACE_OS::memcpy(ch0, default_waveformA.base(), default_waveformA.size());
// default waveform for group A (channel 0 to 3)
ACE_OS::memcpy(ch1, default_waveformA.base(), default_waveformA.size());
m_default_waveform[0] = assign_default_waveform(aORefA, [&](int p_value, int p_max_value){
ACE_OS::memcpy(ch2, default_waveformA.base(), default_waveformA.size());
return (::sin((double)p_value * 2. * 3.14159 / (double) bufferDepth) * p_max_value);
ACE_OS::memcpy(ch3, default_waveformA.base(), default_waveformA.size());
}, 0, 3);
// default waveform for group A (channel 4 to 7)
// default waveform for group A (channel 0 to 3)
asl::AOScaledData default_waveformB(bufferDepth);
m_default_waveform[1] = assign_default_waveform(aORefB, [&](int p_value, int p_max_value){
double max_valB;
if (p_value < bufferDepth/2)
if(aORefSource == adl::external_reference)
return (p_max_value - 0.01);
max_valB = aORefB;
else
else
max_valB = 10.0;
return (-p_max_value + 0.01);
}, 4, 7);
// fill buffer with a square signal
for (i = 0; i < bufferDepth/2; i++)
{
default_waveformB[i] = max_valB - 0.01;
}
for (i = bufferDepth/2; i < bufferDepth; i++)
{
default_waveformB[i] = -max_valB + 0.01;
}
ACE_OS::memcpy(ch4, default_waveformB.base(), default_waveformB.size());
ACE_OS::memcpy(ch5, default_waveformB.base(), default_waveformB.size());
ACE_OS::memcpy(ch6, default_waveformB.base(), default_waveformB.size());
ACE_OS::memcpy(ch7, default_waveformB.base(), default_waveformB.size());
//--------------------------channels config------------------------------------
//--------------------------channels config------------------------------------
asl::ActiveAOChannel ac;
asl::ActiveAOChannel ac;
@@ -248,255 +237,38 @@ void ContinuousAO::init_device()
@@ -248,255 +237,38 @@ void ContinuousAO::init_device()
ac.volt_ref_src = (adl::VoltageReferenceSource)aORefSource;
ac.volt_ref_src = (adl::VoltageReferenceSource)aORefSource;
ac.volt_ref = 10.0;
ac.volt_ref = 10.0;
//- active/config. channel 0
//------active/m_config. channel 0---------
if(channel0Enable)
if(channel0Enable)
{
activate_channel(0, channel0Waveform, m_default_waveform[0]);
ac.id = 0;
if(aORefSource == adl::external_reference)
ac.volt_ref = aORefA;
config.add_active_channel(ac);
if(channel0Waveform.empty())
//------active/m_config. channel 1---------
{
WARN_STREAM<<"No waveform is saved in database for channel 0, using a default one"<<endl;
config.set_channel_periodic_data(0, default_waveformA);
}
else if(channel0Waveform.size() != bufferDepth)
{
WARN_STREAM<<"The waveform saved in database for channel 0 has a different size from property BufferDepth, "<<
"using default waveform"<<endl;
config.set_channel_periodic_data(0, default_waveformA);
}
else //put waveform of the Tango database in ch0
{
// copy the input data in a buffer of type asl::AOScaledData
asl::AOScaledData data(bufferDepth);
for(int i=0; i<bufferDepth; i++)
data[i] = channel0Waveform[i];
// put the waveform in the configuration
config.set_channel_periodic_data(0, data);
//cpy data in the attribute of the device
::memcpy(ch0, data.base(), data.size());
}
}
//- active/config. channel 1
if(channel1Enable)
if(channel1Enable)
{
activate_channel(1, channel1Waveform, m_default_waveform[0]);
ac.id = 1;
if(aORefSource == adl::external_reference)
ac.volt_ref = aORefA;
config.add_active_channel(ac);
if(channel1Waveform.empty())
//------active/m_config. channel 2---------
{
WARN_STREAM<<"No waveform is saved in database for channel 1, using a default one"<<endl;
config.set_channel_periodic_data(1, default_waveformA);
}
else if(channel1Waveform.size() != bufferDepth)
{
WARN_STREAM<<"The waveform saved in database for channel 1 has a different size from property BufferDepth, "<<
"using default waveform"<<endl;
config.set_channel_periodic_data(1, default_waveformA);
}
else //put waveform of the Tango database in ch1
{
// copy the input data in a buffer of type asl::AOScaledData
asl::AOScaledData data(bufferDepth);
for(int i=0; i<bufferDepth; i++)
data[i] = channel1Waveform[i];
// put the waveform in the configuration
config.set_channel_periodic_data(1, data);
//cpy data in the attribute of the device
::memcpy(ch1, data.base(), data.size());
}
}
//- active/config. channel 2
if(channel2Enable)
if(channel2Enable)
{
activate_channel(2, channel2Waveform, m_default_waveform[0]);
ac.id = 2;
if(aORefSource == adl::external_reference)
ac.volt_ref = aORefA;
config.add_active_channel(ac);
config.set_channel_periodic_data(2, default_waveformA);
if(channel2Waveform.empty())
//------active/m_config. channel 3---------
{
WARN_STREAM<<"No waveform is saved in database for channel 2, using a default one"<<endl;
config.set_channel_periodic_data(2, default_waveformA);
}
else if(channel2Waveform.size() != bufferDepth)
{
WARN_STREAM<<"The waveform saved in database for channel 2 has a different size from property BufferDepth, "<<
"using default waveform"<<endl;
config.set_channel_periodic_data(2, default_waveformA);
}
else //put waveform of the Tango database in ch2
{
// copy the input data in a buffer of type asl::AOScaledData
asl::AOScaledData data(bufferDepth);
for(int i=0; i<bufferDepth; i++)
data[i] = channel2Waveform[i];
// put the waveform in the configuration
config.set_channel_periodic_data(2, data);
//cpy data in the attribute of the device
::memcpy(ch2, data.base(), data.size());
}
}
//- active/config. channel 3
if(channel3Enable)
if(channel3Enable)
{
activate_channel(3, channel3Waveform, m_default_waveform[0]);
ac.id = 3;
if(aORefSource == adl::external_reference)
ac.volt_ref = aORefA;
config.add_active_channel(ac);
if(channel3Waveform.empty())
//------active/m_config. channel 4---------
{
WARN_STREAM<<"No waveform is saved in database for channel 3, using a default one"<<endl;
config.set_channel_periodic_data(3, default_waveformA);
}
else if(channel3Waveform.size() != bufferDepth)
{
WARN_STREAM<<"The waveform saved in database for channel 3 has a different size from property BufferDepth, "<<
"using default waveform"<<endl;
config.set_channel_periodic_data(3, default_waveformA);
}
else //put waveform of the Tango database in ch3
{
// copy the input data in a buffer of type asl::AOScaledData
asl::AOScaledData data(bufferDepth);
for(int i=0; i<bufferDepth; i++)
data[i] = channel3Waveform[i];
// put the waveform in the configuration
config.set_channel_periodic_data(3, data);
//cpy data in the attribute of the device
::memcpy(ch3, data.base(), data.size());
}
}
//- active/config. channel 4
if(channel4Enable)
if(channel4Enable)
{
activate_channel(4, channel4Waveform, m_default_waveform[1]);
ac.id = 4;
if(aORefSource == adl::external_reference)
ac.volt_ref = aORefB;
config.add_active_channel(ac);
if(channel4Waveform.empty())
//------active/m_config. channel 5---------
{
WARN_STREAM<<"No waveform is saved in database for channel 4, using a default one"<<endl;
config.set_channel_periodic_data(4, default_waveformB);
}
else if(channel4Waveform.size() != bufferDepth)
{
WARN_STREAM<<"The waveform saved in database for channel 4 has a different size from property BufferDepth, "<<
"using default waveform"<<endl;
config.set_channel_periodic_data(4, default_waveformB);
}
else //put waveform of the Tango database in ch4
{
// copy the input data in a buffer of type asl::AOScaledData
asl::AOScaledData data(bufferDepth);
for(int i=0; i<bufferDepth; i++)
data[i] = channel4Waveform[i];
// put the waveform in the configuration
config.set_channel_periodic_data(4, data);
//cpy data in the attribute of the device
::memcpy(ch4, data.base(), data.size());
}
}
//- active/config. channel 5
if(channel5Enable)
if(channel5Enable)
{
activate_channel(5, channel5Waveform, m_default_waveform[1]);
ac.id = 5;
if(aORefSource == adl::external_reference)
ac.volt_ref = aORefB;
config.add_active_channel(ac);
if(channel5Waveform.empty())
//------active/m_config. channel 6---------
{
WARN_STREAM<<"No waveform is saved in database for channel 5, using a default one"<<endl;
config.set_channel_periodic_data(5, default_waveformB);
}
else if(channel5Waveform.size() != bufferDepth)
{
WARN_STREAM<<"The waveform saved in database for channel 5 has a different size from property BufferDepth, "<<
"using default waveform"<<endl;
config.set_channel_periodic_data(5, default_waveformB);
}
else //put waveform of the Tango database in ch5
{
// copy the input data in a buffer of type asl::AOScaledData
asl::AOScaledData data(bufferDepth);
for(int i=0; i<bufferDepth; i++)
data[i] = channel5Waveform[i];
// put the waveform in the configuration
config.set_channel_periodic_data(5, data);
//cpy data in the attribute of the device
::memcpy(ch5, data.base(), data.size());
}
}
//- active/config. channel 6
if(channel6Enable)
if(channel6Enable)
{
activate_channel(6, channel6Waveform, m_default_waveform[1]);
ac.id = 6;
if(aORefSource == adl::external_reference)
ac.volt_ref = aORefB;
config.add_active_channel(ac);
if(channel6Waveform.empty())
//------active/m_config. channel 7---------
{
WARN_STREAM<<"No waveform is saved in database for channel 6, using a default one"<<endl;
config.set_channel_periodic_data(6, default_waveformB);
}
else if(channel6Waveform.size() != bufferDepth)
{
WARN_STREAM<<"The waveform saved in database for channel 6 has a different size from property BufferDepth, "<<
"using default waveform"<<endl;
config.set_channel_periodic_data(6, default_waveformB);
}
else //put waveform of the Tango database in ch6
{
// copy the input data in a buffer of type asl::AOScaledData
asl::AOScaledData data(bufferDepth);
for(int i=0; i<bufferDepth; i++)
data[i] = channel6Waveform[i];
// put the waveform in the configuration
config.set_channel_periodic_data(6, data);
//cpy data in the attribute of the device
::memcpy(ch6, data.base(), data.size());
}
}
//- active/config. channel 7
if(channel7Enable)
if(channel7Enable)
{
activate_channel(7, channel7Waveform, m_default_waveform[1]);
ac.id = 7;
if(aORefSource == adl::external_reference)
ac.volt_ref = aORefB;
config.add_active_channel(ac);
if(channel7Waveform.empty())
{
WARN_STREAM<<"No waveform is saved in database for channel 7, using a default one"<<endl;
config.set_channel_periodic_data(7, default_waveformB);
}
else if(channel7Waveform.size() != bufferDepth)
{
WARN_STREAM<<"The waveform saved in database for channel 7 has a different size from property BufferDepth, "<<
"using default waveform"<<endl;
config.set_channel_periodic_data(7, default_waveformB);
}
else //put waveform of the Tango database in ch7
{
// copy the input data in a buffer of type asl::AOScaledData
asl::AOScaledData data(bufferDepth);
for(int i=0; i<bufferDepth; i++)
data[i] = channel7Waveform[i];
// put the waveform in the configuration
config.set_channel_periodic_data(7, data);
//cpy data in the attribute of the device
::memcpy(ch7, data.base(), data.size());
}
}
//--------------------------------start trigger config---------------------------------
//--------------------------------start trigger config---------------------------------
if(startTrigger)
if(startTrigger)
{
{
@@ -531,33 +303,25 @@ void ContinuousAO::init_device()
@@ -531,33 +303,25 @@ void ContinuousAO::init_device()
DEBUG_STREAM<<"ContinuousAO::init_device : init acq"<<std::endl;
DEBUG_STREAM<<"ContinuousAO::init_device : init acq"<<std::endl;
try{
try{
_ASL_TRY(
m_ao->init(adl::DAQ2502, boardNum);
ao->init(adl::DAQ2502, boardNum),
"init",
"ContinuousAO::init_device"
);
DEBUG_STREAM<<"ContinuousAO::init_device : config acq"<<std::endl;
DEBUG_STREAM<<"ContinuousAO::init_device : config acq"<<std::endl;
try{
try{
_ASL_TRY(
m_ao->configure(config);
ao->configure(config),
"configure",
"ContinuousAO::init_device"
);
}
}
catch (...)
catch (...)
{
{
raise_error("ContinuousAO::init_device\nError while configuring driver");
on_fault("ContinuousAO::init_device\nError while configuring driver");
return;
return;
}
}
}
}
catch (...)
catch (...)
{
{
raise_error("ContinuousAO::init_device\nError while initializing the driver");
on_fault("ContinuousAO::init_device\nError while initializing the driver");
return;
return;
}
}
//ao->configure(config);
//m_ao->configure(config);
}
}
@@ -601,14 +365,14 @@ void ContinuousAO::get_device_property()
@@ -601,14 +365,14 @@ void ContinuousAO::get_device_property()
string default_aoref = "INTERN";
string default_aoref = "INTERN";
aORefSource = adl::internal_reference;
aORefSource = adl::internal_reference;
channel0Enable = 1;
channel0Enable = true;
channel1Enable = 0;
channel1Enable = false;
channel2Enable = 0;
channel2Enable = false;
channel3Enable = 0;
channel3Enable = false;
channel4Enable = 0;
channel4Enable = false;
channel5Enable = 0;
channel5Enable = false;
channel6Enable = 0;
channel6Enable = false;
channel7Enable = 0;
channel7Enable = false;
bufferDepth = 4096;
bufferDepth = 4096;
@@ -1073,11 +837,11 @@ void ContinuousAO::read_attr_hardware(vector<long> &attr_list)
@@ -1073,11 +837,11 @@ void ContinuousAO::read_attr_hardware(vector<long> &attr_list)
// Add your own code here
// Add your own code here
//---------------------------------
//---------------------------------
ao->lock_data();
m_ao->lock_data();
err_ctr = ao->err_ctr;
m_err_ctr = m_ao->err_ctr;
ao->unlock_data();
m_ao->unlock_data();
}
}
@@ -1100,68 +864,68 @@ void ContinuousAO::read_attr(Tango::Attribute &attr)
@@ -1100,68 +864,68 @@ void ContinuousAO::read_attr(Tango::Attribute &attr)
if (attr_name == "channel0")
if (attr_name == "channel0")
{
{
if(channel0Enable)
if(channel0Enable)
attr.set_value(ch0, bufferDepth);
attr.set_value(m_channel[0], bufferDepth);
else
else
attr.set_quality(Tango::ATTR_INVALID);
attr.set_quality(Tango::ATTR_INVALID);
}
}
else if (attr_name == "channel1")
else if (attr_name == "channel1")
{
{
if(channel1Enable)
if(channel1Enable)
attr.set_value(ch1, bufferDepth);
attr.set_value(m_channel[1], bufferDepth);
else
else
attr.set_quality(Tango::ATTR_INVALID);
attr.set_quality(Tango::ATTR_INVALID);
}
}
else if (attr_name == "channel2")
else if (attr_name == "channel2")
{
{
if(channel2Enable)
if(channel2Enable)
attr.set_value(ch2, bufferDepth);
attr.set_value(m_channel[2], bufferDepth);
else
else
attr.set_quality(Tango::ATTR_INVALID);
attr.set_quality(Tango::ATTR_INVALID);
}
}
else if (attr_name == "channel3")
else if (attr_name == "channel3")
{
{
if(channel3Enable)
if(channel3Enable)
attr.set_value(ch3, bufferDepth);
attr.set_value(m_channel[3], bufferDepth);
else
else
attr.set_quality(Tango::ATTR_INVALID);
attr.set_quality(Tango::ATTR_INVALID);
}
}
else if (attr_name == "channel4")
else if (attr_name == "channel4")
{
{
if(channel4Enable)
if(channel4Enable)
attr.set_value(ch4, bufferDepth);
attr.set_value(m_channel[4], bufferDepth);
else
else
attr.set_quality(Tango::ATTR_INVALID);
attr.set_quality(Tango::ATTR_INVALID);
}
}
else if (attr_name == "channel5")
else if (attr_name == "channel5")
{
{
if(channel5Enable)
if(channel5Enable)
attr.set_value(ch5, bufferDepth);
attr.set_value(m_channel[5], bufferDepth);
else
else
attr.set_quality(Tango::ATTR_INVALID);
attr.set_quality(Tango::ATTR_INVALID);
}
}
else if (attr_name == "channel6")
else if (attr_name == "channel6")
{
{
if(channel6Enable)
if(channel6Enable)
attr.set_value(ch6, bufferDepth);
attr.set_value(m_channel[6], bufferDepth);
else
else
attr.set_quality(Tango::ATTR_INVALID);
attr.set_quality(Tango::ATTR_INVALID);
}
}
else if (attr_name == "channel7")
else if (attr_name == "channel7")
{
{
if(channel7Enable)
if(channel7Enable)
attr.set_value(ch7, bufferDepth);
attr.set_value(m_channel[7], bufferDepth);
else
else
attr.set_quality(Tango::ATTR_INVALID);
attr.set_quality(Tango::ATTR_INVALID);
}
}
else if (attr_name == "errorCounter")
else if (attr_name == "errorCounter")
{
{
attr.set_value(&err_ctr);
attr.set_value(&m_err_ctr);
}
}
else if (attr_name == "useBoardFifo")
else if (attr_name == "useBoardFifo")
{
{
// the information about data loading on fifo in available only after Start command.
// the information about data loading on fifo in available only after Start command.
if(get_state() == Tango::RUNNING)
if(get_state() == Tango::RUNNING)
attr.set_value(&use_fifo);
attr.set_value(&m_use_fifo);
else
else
attr.set_quality(Tango::ATTR_INVALID);
attr.set_quality(Tango::ATTR_INVALID);
}
}
@@ -1221,15 +985,15 @@ void ContinuousAO::start()
@@ -1221,15 +985,15 @@ void ContinuousAO::start()
{
{
DEBUG_STREAM << "ContinuousAO::start(): entering... !" << endl;
DEBUG_STREAM << "ContinuousAO::start(): entering... !" << endl;
ao->lock_data();
m_ao->lock_data();
ao->err_ctr = 0;
m_ao->err_ctr = 0;
ao->unlock_data();
m_ao->unlock_data();
_ASL_TRY_ACTION
_ASL_TRY_ACTION
(
(
ao->start(),
m_ao->start(),
"start",
"start",
"ContinuousAO::start",
"ContinuousAO::start",
set_internal_state()
set_internal_state()
@@ -1237,7 +1001,7 @@ void ContinuousAO::start()
@@ -1237,7 +1001,7 @@ void ContinuousAO::start()
// get if the output data have been loaded in the onboard FIFO.
// get if the output data have been loaded in the onboard FIFO.
// depends on the size of the buffer.
// depends on the size of the buffer.
use_fifo = ao->use_board_fifo();
m_use_fifo = m_ao->use_board_fifo();
}
}
@@ -1257,7 +1021,7 @@ void ContinuousAO::stop()
@@ -1257,7 +1021,7 @@ void ContinuousAO::stop()
_ASL_TRY_ACTION
_ASL_TRY_ACTION
(
(
ao->stop(),
m_ao->stop(),
"stop",
"stop",
"ContinuousAO::stop",
"ContinuousAO::stop",
set_internal_state()
set_internal_state()
@@ -1290,8 +1054,8 @@ void ContinuousAO::set_aoscaled_data(const Tango::DevVarDoubleStringArray *argin
@@ -1290,8 +1054,8 @@ void ContinuousAO::set_aoscaled_data(const Tango::DevVarDoubleStringArray *argin
}
}
Tango::DevVarStringArray chan_dvsa = (*argin).svalue;
Tango::DevVarStringArray chan_dvsa = (*argin).svalue;
string chan_s = chan_dvsa[0];
string chan_s = chan_dvsa[0];
char chan = chan_s[0];
int channel_index = chan_s[0] - '0';
if(chan < '0' || chan > '7')
if(channel_index < 0 || channel_index > 7)
{
{
Tango::Except::throw_exception(
Tango::Except::throw_exception(
(const char*)("OPERATION_NOT_ALLOWED"),
(const char*)("OPERATION_NOT_ALLOWED"),
@@ -1311,78 +1075,32 @@ void ContinuousAO::set_aoscaled_data(const Tango::DevVarDoubleStringArray *argin
@@ -1311,78 +1075,32 @@ void ContinuousAO::set_aoscaled_data(const Tango::DevVarDoubleStringArray *argin
// stop the current generation
// stop the current generation
_ASL_TRY_ACTION
_ASL_TRY_ACTION
(
(
ao->stop(),
m_ao->stop(),
"stop",
"stop",
"ContinuousAO::set_aoscaled_data",
"ContinuousAO::set_aoscaled_data",
set_internal_state()
set_internal_state()
);
);
// get the configuration
// get the configuration
asl::ContinuousAOConfig config = ao->configuration();
asl::ContinuousAOConfig config = m_ao->configuration();
// copy the input data in a buffer of type asl::AOScaledData
// copy the input data in a buffer of type asl::AOScaledData
asl::AOScaledData data(bufferDepth);
asl::AOScaledData data(bufferDepth);
::memcpy(data.base(), (*argin).dvalue.get_buffer(), ((*argin).dvalue.length())*sizeof(double));
::memcpy(data.base(), (*argin).dvalue.get_buffer(), ((*argin).dvalue.length())*sizeof(double));
//NB: if a chan hasn't been enable with properties, 'ao' will do nothing
config.set_channel_periodic_data(chan - '0', data);
//NB: if a chan hasn't been enable with properties, 'm_ao' will do nothing
 
config.set_channel_periodic_data(channel_index, data);
// copy the new data in the attributes of the device.
// copy the new data in the attributes of the device.
switch(chan)
::memcpy(m_channel[channel_index], data.base(), data.size());
{
case '0':
::memcpy(ch0, data.base(), data.size());
//save the waveform in the database
//save the waveform in the database
save_waveform(ch0, "Channel0Waveform");
save_waveform(m_channel[channel_index], "Channel" + std::to_string(channel_index) + "Waveform");
break;
case '1':
::memcpy(ch1, data.base(), data.size());
//save the waveform in the database
save_waveform(ch1, "Channel1Waveform");
break;
case '2':
::memcpy(ch2, data.base(), data.size());
//save the waveform in the database
save_waveform(ch2, "Channel2Waveform");
break;
case '3':
::memcpy(ch3, data.base(), data.size());
//save the waveform in the database
save_waveform(ch3, "Channel3Waveform");
break;
case '4':
::memcpy(ch4, data.base(), data.size());
//save the waveform in the database
save_waveform(ch4, "Channel4Waveform");
break;
case '5':
::memcpy(ch5, data.base(), data.size());
//save the waveform in the database
save_waveform(ch5, "Channel5Waveform");
break;
case '6':
::memcpy(ch6, data.base(), data.size());
//save the waveform in the database
save_waveform(ch6, "Channel6Waveform");
break;
case '7':
::memcpy(ch7, data.base(), data.size());
//save the waveform in the database
save_waveform(ch7, "Channel7Waveform");
break;
default:
Tango::Except::throw_exception(
(const char*)("OPERATION_NOT_ALLOWED"),
(const char*)("The string argument must be between 0 and 7"),
(const char*)("ContinuousAO::set_aoscaled_data")
);
break;
}
// give the configuration with a new channel
// give the configuration with a new channel
_ASL_TRY_ACTION
_ASL_TRY_ACTION
(
(
ao->configure(config),
m_ao->configure(config),
"configure",
"configure",
"ContinuousAO::set_aoscaled_data",
"ContinuousAO::set_aoscaled_data",
set_internal_state()
set_internal_state()
@@ -1396,14 +1114,14 @@ void ContinuousAO::set_aoscaled_data(const Tango::DevVarDoubleStringArray *argin
@@ -1396,14 +1114,14 @@ void ContinuousAO::set_aoscaled_data(const Tango::DevVarDoubleStringArray *argin
//+------------------------------------------------------------------
//+------------------------------------------------------------------
void ContinuousAO::set_internal_state(void)
void ContinuousAO::set_internal_state(void)
{
{
if(ao == 0)
if(m_ao == 0)
{
{
set_state(Tango::UNKNOWN);
set_state(Tango::UNKNOWN);
set_status("The acquisition was not initialized properly");
set_status("The acquisition was not initialized properly");
}
}
else
else
{
{
switch(ao->state())
switch(m_ao->state())
{
{
case asl::ContinuousAO::STANDBY:
case asl::ContinuousAO::STANDBY:
set_state(Tango::STANDBY);
set_state(Tango::STANDBY);
@@ -1458,7 +1176,7 @@ void ContinuousAO::save_waveform(double* waveform, string wfm_channel)
@@ -1458,7 +1176,7 @@ void ContinuousAO::save_waveform(double* waveform, string wfm_channel)
);
);
}
}
void ContinuousAO::raise_error(std::string p_error_message)
void ContinuousAO::on_fault(std::string p_error_message)
{
{
m_error_message = p_error_message;
m_error_message = p_error_message;
set_state(Tango::FAULT);
set_state(Tango::FAULT);
Loading