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

refactor: split write_channel method into write_channel_direct and start_channel_ramp

parent 646f4650
No related branches found
No related tags found
2 merge requests!4develop -> main,!3EnableRamps and OutputMemorizedChannelsAtInit properties
...@@ -609,7 +609,7 @@ void SingleShotAO::init_device() ...@@ -609,7 +609,7 @@ void SingleShotAO::init_device()
} }
if (outputMemorizedChannelsAtInit) { if (outputMemorizedChannelsAtInit) {
applyMemorizedAttr(kCHANNEL, &SingleShotAOManager::write_channel); // write memorized value to board output applyMemorizedAttr(kCHANNEL, &SingleShotAOManager::write_channel_direct); // write memorized value to board output (directly, without ramp)
} else { } else {
applyMemorizedAttr(kCHANNEL, &SingleShotAOManager::set_channel); // only apply memorized value to the device applyMemorizedAttr(kCHANNEL, &SingleShotAOManager::set_channel); // only apply memorized value to the device
} }
...@@ -978,8 +978,11 @@ void SingleShotAO::write_channel(yat4tango::DynamicAttributeWriteCallbackData & ...@@ -978,8 +978,11 @@ void SingleShotAO::write_channel(yat4tango::DynamicAttributeWriteCallbackData &
"could not write channel [unknown error]", "could not write channel [unknown error]",
"SingleShotAO::write_channel"); "SingleShotAO::write_channel");
} }
DEBUG_STREAM << "SingleShotAO::write_channel(): channel " << l_idx << " value set to " << l_val << endl;
yat4tango::PropertyHelper::set_memorized_attribute(this, l_attr_name, l_val); yat4tango::PropertyHelper::set_memorized_attribute(this, l_attr_name, l_val);
yat4tango::PropertyHelper::set_memorized_attribute(this, kINITIAL + std::to_string(l_idx), l_val);
DEBUG_STREAM << "SingleShotAO::write_channel(): memorized attribute " << l_attr_name << " set to " << l_val << endl;
} }
......
...@@ -250,6 +250,7 @@ void SingleShotAOManager::periodic_job_i() ...@@ -250,6 +250,7 @@ void SingleShotAOManager::periodic_job_i()
m_currentIndex[l_cpt] += 1; m_currentIndex[l_cpt] += 1;
if (m_currentIndex[l_cpt] == m_ramps[l_cpt].capacity()) if (m_currentIndex[l_cpt] == m_ramps[l_cpt].capacity())
{ {
DEBUG_STREAM << "Ramp finished for channel" << l_cpt << endl;
m_currentIndex[l_cpt] = -1; m_currentIndex[l_cpt] = -1;
m_initials[l_cpt] = m_channels[l_cpt]; m_initials[l_cpt] = m_channels[l_cpt];
m_ramps[l_cpt].clear(); m_ramps[l_cpt].clear();
...@@ -283,14 +284,9 @@ void SingleShotAOManager::set_channel(ChannelId_t p_chIdx, double p_val) ...@@ -283,14 +284,9 @@ void SingleShotAOManager::set_channel(ChannelId_t p_chIdx, double p_val)
} }
// ============================================================================ // ============================================================================
// SingleShotAOManager::write_channel () // SingleShotAOManager::write_channel_direct ()
// ============================================================================ // ============================================================================
void SingleShotAOManager::write_channel(ChannelId_t p_chIdx, double p_val) void SingleShotAOManager::write_channel_direct(ChannelId_t p_chIdx, double p_val)
{
DEBUG_STREAM << "write_channel " << p_chIdx << " : " << p_val << endl;
// if the speed is 0, write the value directly and skip ramp
if (m_speeds[p_chIdx] == 0.0 || !m_enable_ramps)
{ {
try try
{ {
...@@ -298,7 +294,7 @@ void SingleShotAOManager::write_channel(ChannelId_t p_chIdx, double p_val) ...@@ -298,7 +294,7 @@ void SingleShotAOManager::write_channel(ChannelId_t p_chIdx, double p_val)
m_ssao->write_scaled_channel((adl::ChanId)p_chIdx, p_val); m_ssao->write_scaled_channel((adl::ChanId)p_chIdx, p_val);
m_channels[p_chIdx] = p_val; m_channels[p_chIdx] = p_val;
m_initials[p_chIdx] = p_val; m_initials[p_chIdx] = p_val;
DEBUG_STREAM << "Speed is 0, writing directly the value" << std::endl; DEBUG_STREAM << "Writing directly the value" << std::endl;
} }
catch (const asl::DAQException &de) catch (const asl::DAQException &de)
{ {
...@@ -308,42 +304,23 @@ void SingleShotAOManager::write_channel(ChannelId_t p_chIdx, double p_val) ...@@ -308,42 +304,23 @@ void SingleShotAOManager::write_channel(ChannelId_t p_chIdx, double p_val)
RETHROW_DEVFAILED(df, RETHROW_DEVFAILED(df,
"DRIVER_FAILURE", "DRIVER_FAILURE",
"could not write channel [caught asl::DAQException]", "could not write channel [caught asl::DAQException]",
"SingleShotAOManager::write_channel"); "SingleShotAOManager::write_channel_direct");
} }
catch (...) catch (...)
{ {
ERROR_STREAM << "SingleShotAOManager::write_channel::unknown exception caught" << std::endl; ERROR_STREAM << "SingleShotAOManager::write_channel_direct::unknown exception caught" << std::endl;
m_state = Tango::FAULT; m_state = Tango::FAULT;
THROW_DEVFAILED("DRIVER_FAILURE", THROW_DEVFAILED("DRIVER_FAILURE",
"could not write channel [unknown error]", "could not write channel [unknown error]",
"SingleShotAOManager::write_channel"); "SingleShotAOManager::write_channel_direct");
} }
return;
}
// if a ramp is running, error
if (m_isRunning[p_chIdx])
{
THROW_DEVFAILED("DEVICE_FAILURE",
"could not write channel : a ramp is still in progress on this channel",
"SingleShotAOManager::write_channel");
} }
// if frequency = 0, error // ============================================================================
if (m_frequency == 0) // SingleShotAOManager::start_channel_ramp ()
{ // ============================================================================
THROW_DEVFAILED("DRIVER_FAILURE", void SingleShotAOManager::start_channel_ramp(ChannelId_t p_chIdx, double p_val)
"could not set a ramp on this channel. The frequency is 0",
"SingleShotAOManager::write_channel");
}
// if initial = channel, skip
if (m_initials[p_chIdx] == p_val)
{ {
DEBUG_STREAM << "Initial value is the same as the given value, skipping" << endl;
return;
}
// ramp determination // ramp determination
double l_delta = p_val - m_initials[p_chIdx]; double l_delta = p_val - m_initials[p_chIdx];
bool isDown = false; bool isDown = false;
...@@ -389,7 +366,47 @@ void SingleShotAOManager::write_channel(ChannelId_t p_chIdx, double p_val) ...@@ -389,7 +366,47 @@ void SingleShotAOManager::write_channel(ChannelId_t p_chIdx, double p_val)
m_ramps[p_chIdx].force_length(0); m_ramps[p_chIdx].force_length(0);
m_currentIndex[p_chIdx] = 0; m_currentIndex[p_chIdx] = 0;
m_ramps[p_chIdx] = l_buffer; m_ramps[p_chIdx] = l_buffer;
//m_channels[p_chIdx] = m_ramps[p_chIdx][0]; -- soso on ne met rien ici => à l'application }
// ============================================================================
// SingleShotAOManager::write_channel ()
// ============================================================================
void SingleShotAOManager::write_channel(ChannelId_t p_chIdx, double p_val)
{
DEBUG_STREAM << "write_channel " << p_chIdx << " : " << p_val << endl;
// if the speed is 0, write the value directly and skip ramp
if (m_speeds[p_chIdx] == 0.0 || !m_enable_ramps)
{
write_channel_direct(p_chIdx, p_val);
return;
}
// if a ramp is running, error
if (m_isRunning[p_chIdx])
{
THROW_DEVFAILED("DEVICE_FAILURE",
"could not write channel : a ramp is still in progress on this channel",
"SingleShotAOManager::write_channel");
}
// if frequency = 0, error
if (m_frequency == 0)
{
THROW_DEVFAILED("DRIVER_FAILURE",
"could not set a ramp on this channel. The frequency is 0",
"SingleShotAOManager::write_channel");
}
// if initial = channel, skip
if (m_initials[p_chIdx] == p_val)
{
DEBUG_STREAM << "Initial value is the same as the given value, skipping" << endl;
return;
}
// Create and start a ramp
start_channel_ramp(p_chIdx, p_val);
} }
// ============================================================================ // ============================================================================
......
...@@ -59,6 +59,12 @@ public: ...@@ -59,6 +59,12 @@ public:
//- write channel //- write channel
void write_channel(ChannelId_t p_chIdx, double p_val); void write_channel(ChannelId_t p_chIdx, double p_val);
//- write a channel directly (without ramp)
void write_channel_direct(ChannelId_t p_chIdx, double p_val);
//- create and start a ramp for channel
void start_channel_ramp(ChannelId_t p_chIdx, double p_val);
//- change period //- change period
void write_frequency(double p_frequency); void write_frequency(double p_frequency);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment