Skip to content
Snippets Groups Projects
Commit a6daeef3 authored by Alexandre MALFREYT's avatar Alexandre MALFREYT
Browse files

refactor: improve code readability and structure in SingleShotAOManager

parent d4c1f252
No related branches found
No related tags found
2 merge requests!4develop -> main,!2[CTRLRFC-1594] Apply memorized dynamic attributes at init
......@@ -190,12 +190,15 @@ void SingleShotAOManager::process_message (yat::Message& msg)
//- not used in this example
}
break;
//- UNHANDLED MSG --------------------
default:
{
DEBUG_STREAM << "SingleShotAOManager::handle_message::unhandled msg type received" << std::endl;
break;
}
}
}
// ============================================================================
// SingleShotAOManager::periodic_job_i ()
......@@ -206,8 +209,12 @@ void SingleShotAOManager::periodic_job_i()
for (unsigned int l_cpt = 0;l_cpt < m_nb_chan;l_cpt++)
{
// test if a ramp step must occur
if (m_currentIndex[l_cpt] != -1)
if (m_currentIndex[l_cpt] == -1)
{
m_isRunning[l_cpt] = false;
continue;
}
m_isRunning[l_cpt] = true;
double l_val = 0;
l_val = m_ramps[l_cpt][m_currentIndex[l_cpt]];
......@@ -246,11 +253,6 @@ void SingleShotAOManager::periodic_job_i()
m_ramps[l_cpt].clear();
}
}
else
{
m_isRunning[l_cpt] = false;
}
}
}
// ============================================================================
......@@ -266,8 +268,9 @@ double SingleShotAOManager::get_channel(ChannelId_t p_chIdx)
// ============================================================================
void SingleShotAOManager::write_channel(ChannelId_t p_chIdx, double p_val)
{
DEBUG_STREAM << "write_channel : " << p_chIdx << " : " << p_val << " : " << endl;
DEBUG_STREAM << "write_channel " << p_chIdx << " : " << p_val << endl;
// if the speed is 0, write the value directly
if (m_speeds[p_chIdx] == 0.0)
{
try
......@@ -276,6 +279,7 @@ void SingleShotAOManager::write_channel(ChannelId_t p_chIdx, double p_val)
m_ssao->write_scaled_channel((adl::ChanId)p_chIdx, p_val);
m_channels[p_chIdx] = p_val;
m_initials[p_chIdx] = p_val;
DEBUG_STREAM << "Speed is 0, writing directly the value" << endl;
}
catch(const asl::DAQException& de)
{
......@@ -295,15 +299,18 @@ void SingleShotAOManager::write_channel(ChannelId_t p_chIdx, double p_val)
"could not write channel [unknown error]",
"SingleShotAOManager::write_channel");
}
return;
}
else
{
// check if a ramp is not running
if (!m_isRunning[p_chIdx])
{
// check if initial = channel
if (m_initials[p_chIdx] != p_val)
// if a ramp is not 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",
......@@ -311,6 +318,13 @@ void SingleShotAOManager::write_channel(ChannelId_t p_chIdx, double p_val)
"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
double l_delta = p_val - m_initials[p_chIdx];
bool isDown = false;
......@@ -328,18 +342,12 @@ void SingleShotAOManager::write_channel(ChannelId_t p_chIdx, double p_val)
l_buffer.force_length(ramp_size);
// check if ramp step is integer or not
bool isDeltaNotInt = false;
if (ramp_size != ((size_t)(floor(l_delta))))
{
isDeltaNotInt = true;
}
bool isDeltaNotInt = (ramp_size != ((size_t)(floor(l_delta))));
DEBUG_STREAM << "Real ramp steps number : " << ramp_size << endl;
for (unsigned int l_cpt = 0; l_cpt < ramp_size; l_cpt++)
{
if ((l_cpt == (ramp_size - 1)) &&
(isDeltaNotInt))
if ((l_cpt == (ramp_size - 1)) && (isDeltaNotInt))
{
// add the setpoint value at the end of table
l_buffer[l_cpt] = p_val;
......@@ -364,15 +372,6 @@ void SingleShotAOManager::write_channel(ChannelId_t p_chIdx, double p_val)
m_ramps[p_chIdx] = l_buffer;
//m_channels[p_chIdx] = m_ramps[p_chIdx][0]; -- soso on ne met rien ici => à l'application
}
}
else
{
THROW_DEVFAILED("DEVICE_FAILURE",
"could not write channel : a ramp is still in progress on this channel",
"SingleShotAOManager::write_channel");
}
}
}
// ============================================================================
// SingleShotAOManager::get_initial ()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment