You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

664 lines
17 KiB
C++

/*
* SYSRestart.cpp
*
* Author: Aleksey Gerasimenko
* gerasimenko.aleksey.n@gmail.com
*/
#include "SYSCTRL/SYSRestart.h"
namespace SYSCTRL
{
//CONSTRUCTOR
SYSRestart::SYSRestart(SYSCTRL::SystemEnvironment& env):
m_env(env),
m_mode(SYSCTRL::SYSRestart::UNDEFINED),
m_state(SYSCTRL::SYSRestart::EMPTY),
m_state_bit_field(),
m_time_sample(-1.0),
m_config(),
m_registers(),
status(),
_execute(&SYSCTRL::SYSRestart::_execute_undef),
_state_run(&SYSCTRL::SYSRestart::_state_empty)
//
{}//CONSTRUCTOR
void SYSRestart::setup(float time_sample)
{
if(m_mode == SYSCTRL::SYSRestart::UNDEFINED)
{
if(time_sample > FP_ZERO)
{
m_time_sample = time_sample;
m_mode = SYSCTRL::SYSRestart::CONFIGURATE;
//
}//if
//
}//if
//
}//
//
void SYSRestart::configure(SYSRestartConfiguration& config)
{
bool _status = true;
if(m_mode == SYSCTRL::SYSRestart::CONFIGURATE)
{
m_config = config;
if((m_config.enable.equipment.all != (uint16_t)0)||
(m_config.enable.phase_a.all != (uint16_t)0)||
(m_config.enable.phase_b.all != (uint16_t)0)||
(m_config.enable.phase_c.all != (uint16_t)0))
{
_status &= m_config.period_timer_hold_fault > m_time_sample ? true : false;
_status &= m_config.period_timer_selfclear_attempts > m_time_sample ? true : false;
_status &= m_config.period_timer_turnon_switch > m_time_sample ? true : false;
_status &= m_config.attempts > 0 ? true : false;
}//if
//
m_registers.counter_attempts = 0;
m_registers.counter_timer = FP_ZERO;
m_registers.counter_timer_selfclear_attempts = FP_ZERO;
m_registers.status.all = 0;
//
if(_status)
{
m_mode = SYSCTRL::SYSRestart::OPERATIONAL;
_execute = &SYSCTRL::SYSRestart::_execute_operational;
if((m_config.restart_enable.signal.enable)&&
((m_config.enable.equipment.all != (uint16_t)0)||
(m_config.enable.phase_a.all != (uint16_t)0)||
(m_config.enable.phase_b.all != (uint16_t)0)||
(m_config.enable.phase_c.all != (uint16_t)0)))
{
_state_run = &SYSCTRL::SYSRestart::_state_free;
m_state = SYSCTRL::SYSRestart::FREE;
}
else
{
_state_run = &SYSCTRL::SYSRestart::_state_empty;
m_state = SYSCTRL::SYSRestart::EMPTY;
//
}// if else
//
}//if
//
}//if
//
}//
//
SYSRestart::mode_t SYSRestart::get_mode()
{
return m_mode;
//
}//
//
SYSRestart::state_t SYSRestart::get_state()
{
return m_state;
}//
//
#pragma CODE_SECTION("ramfuncs");
uint16_t SYSRestart::get_state_steps()
{
return m_state_bit_field.all;
//
}//
//
uint16_t SYSRestart::get_attempts()
{
return m_registers.counter_attempts;
//
}//
//
bool SYSRestart::compare(SYSCTRL::SYSRestart::mode_t mode)
{
return mode == m_mode;
//
}//
//
bool SYSRestart::compare_state(SYSRestart::SYSRestart::state_t state)
{
return state == m_state;
//
}//
//
#pragma CODE_SECTION("ramfuncs");
void SYSRestart::execute()
{
(this->*_execute)();
}//
//
void SYSRestart::_execute_undef()
{}//
//
#pragma CODE_SECTION("ramfuncs");
void SYSRestart::_execute_operational()
{
if(m_config.restart_enable.signal.enable)
{
m_registers.status_fault_register.equipment.all = m_config.enable.equipment.all & m_env.system_faults_register.equipment.all;
m_registers.status_fault_register.phase_a.all = m_config.enable.phase_a.all & m_env.system_faults_register.phase_a.all;
m_registers.status_fault_register.phase_b.all = m_config.enable.phase_b.all & m_env.system_faults_register.phase_b.all;
m_registers.status_fault_register.phase_c.all = m_config.enable.phase_c.all & m_env.system_faults_register.phase_c.all;
//
m_registers.status.signal.fault = m_registers.status_fault_register.equipment.all == (uint16_t)0 ? false : true;
m_registers.status.signal.fault |= m_registers.status_fault_register.phase_a.all == (uint16_t)0 ? false : true;
m_registers.status.signal.fault |= m_registers.status_fault_register.phase_b.all == (uint16_t)0 ? false : true;
m_registers.status.signal.fault |= m_registers.status_fault_register.phase_c.all == (uint16_t)0 ? false : true;
//
if(m_registers.counter_attempts != 0)
{
if(m_registers.counter_timer_selfclear_attempts < m_config.period_timer_selfclear_attempts)
{
m_registers.counter_timer_selfclear_attempts += m_time_sample;
}
else
{
m_registers.counter_attempts = 0;
m_registers.counter_timer_selfclear_attempts = FP_ZERO;
}
}
//
SYSCTRL::MonitorDigitalInputSignal::implement(m_registers.status.signal.fault, m_registers.monitor_fault);
//
_state_execute();
//
}
else
{
_set_state_free();
//
}//if else
//
}//
//
#pragma CODE_SECTION("ramfuncs");
inline void SYSRestart::_set_state_empty()
{
m_state = SYSCTRL::SYSRestart::EMPTY;
m_state_bit_field.all = 0;
m_state_bit_field.signal.empty = 1;
//
m_registers.counter_timer = FP_ZERO;
//
m_registers.status.signal.resetfault = 0;
m_registers.status.signal.freezefault = 0;
m_registers.status.signal.startup = 0;
m_registers.status.signal.turnon_q1 = 0;
m_registers.status.signal.turnon_km1 = 0;
m_registers.status.signal.turnon_km3 = 0;
status.all = m_registers.status.all;
//
SYSCTRL::MonitorDigitalInputSignal::preset(false, m_registers.monitor_fault);
//
_state_run = &SYSCTRL::SYSRestart::_state_empty;
//
}//
//
#pragma CODE_SECTION("ramfuncs");
inline void SYSRestart::_set_state_free()
{
m_state = SYSCTRL::SYSRestart::FREE;
m_state_bit_field.all = 0;
m_state_bit_field.signal.free = 1;
//
m_registers.counter_timer = FP_ZERO;
//
m_registers.status.signal.resetfault = 0;
m_registers.status.signal.freezefault = 0;
m_registers.status.signal.startup = 0;
m_registers.status.signal.turnon_q1 = 0;
m_registers.status.signal.turnon_km1 = 0;
m_registers.status.signal.turnon_km3 = 0;
//
status.all = m_registers.status.all;
//
_state_run = &SYSCTRL::SYSRestart::_state_free;
//
}//
//
#pragma CODE_SECTION("ramfuncs");
inline void SYSRestart::_set_state_holdfault()
{
m_state = SYSCTRL::SYSRestart::HOLDFAULT;
m_state_bit_field.signal.free = 0;
m_state_bit_field.signal.holdfault = 1;
//
m_registers.counter_timer = FP_ZERO;
//
m_registers.status.signal.resetfault = 0;
m_registers.status.signal.freezefault = 0;
m_registers.status.signal.startup = 0;
m_registers.status.signal.turnon_q1 = 0;
m_registers.status.signal.turnon_km1 = 0;
m_registers.status.signal.turnon_km3 = 0;
//
status.all = m_registers.status.all;
//
_state_run = &SYSCTRL::SYSRestart::_state_holdfault;
//
}//
//
#pragma CODE_SECTION("ramfuncs");
inline void SYSRestart::_set_state_resetfault()
{
m_state = SYSCTRL::SYSRestart::RESETFAULT;
m_state_bit_field.signal.resetfault = 1;
//
m_registers.counter_timer = FP_ZERO;
//
m_registers.status.signal.resetfault = 1;
m_registers.status.signal.freezefault = 0;
m_registers.status.signal.startup = 0;
m_registers.status.signal.turnon_q1 = 0;
m_registers.status.signal.turnon_km1 = 0;
m_registers.status.signal.turnon_km3 = 0;
//
status.all = m_registers.status.all;
//
_state_run = &SYSCTRL::SYSRestart::_state_resetfault;
//
}//
//
#pragma CODE_SECTION("ramfuncs");
inline void SYSRestart::_set_state_freezefault()
{
m_state = SYSCTRL::SYSRestart::FREEZEFAULT;
m_state_bit_field.all = 0;
m_state_bit_field.signal.freezefault = 1;
//
m_registers.counter_timer = FP_ZERO;
//
m_registers.status.signal.resetfault = 0;
m_registers.status.signal.freezefault = 1;
m_registers.status.signal.startup = 0;
m_registers.status.signal.turnon_q1 = 0;
m_registers.status.signal.turnon_km1 = 0;
m_registers.status.signal.turnon_km3 = 0;
//
status.all = m_registers.status.all;
//
_state_run = &SYSCTRL::SYSRestart::_state_freezefault;
//
}//
//
#pragma CODE_SECTION("ramfuncs");
inline void SYSRestart::_set_state_holdstop()
{
m_state = SYSCTRL::SYSRestart::HOLDSTOP;
m_state_bit_field.signal.holdstop = 1;
//
m_registers.counter_timer = FP_ZERO;
//
m_registers.status.signal.resetfault = 0;
m_registers.status.signal.freezefault = 0;
m_registers.status.signal.startup = 0;
m_registers.status.signal.turnon_q1 = 0;
m_registers.status.signal.turnon_km1 = 0;
m_registers.status.signal.turnon_km3 = 0;
//
status.all = m_registers.status.all;
//
_state_run = &SYSCTRL::SYSRestart::_state_holdstop;
//
}//
//
#pragma CODE_SECTION("ramfuncs");
inline void SYSRestart::_set_state_turnon_q1()
{
m_state = SYSCTRL::SYSRestart::TURNONQ1;
m_state_bit_field.signal.turnonq1 = 1;
//
m_registers.counter_timer = FP_ZERO;
//
m_registers.status.signal.resetfault = 0;
m_registers.status.signal.freezefault = 0;
m_registers.status.signal.startup = 0;
m_registers.status.signal.turnon_q1 = 1;
m_registers.status.signal.turnon_km1 = 0;
m_registers.status.signal.turnon_km3 = 0;
//
status.all = m_registers.status.all;
//
_state_run = &SYSCTRL::SYSRestart::_state_turnon_q1;
//
}//
//
#pragma CODE_SECTION("ramfuncs");
inline void SYSRestart::_set_state_turnon_km1()
{
m_state = SYSCTRL::SYSRestart::TURNONKM1;
m_state_bit_field.signal.turnonkm1 = 1;
//
m_registers.counter_timer = FP_ZERO;
//
m_registers.status.signal.resetfault = 0;
m_registers.status.signal.freezefault = 0;
m_registers.status.signal.startup = 0;
m_registers.status.signal.turnon_q1 = 0;
m_registers.status.signal.turnon_km1 = 1;
m_registers.status.signal.turnon_km3 = 0;
//
status.all = m_registers.status.all;
//
_state_run = &SYSCTRL::SYSRestart::_state_turnon_km1;
//
//
}//
//
#pragma CODE_SECTION("ramfuncs");
inline void SYSRestart::_set_state_turnon_km3()
{
m_state = SYSCTRL::SYSRestart::TURNONKM3;
m_state_bit_field.signal.turnonkm3 = 1;
//
m_registers.counter_timer = FP_ZERO;
//
m_registers.status.signal.resetfault = 0;
m_registers.status.signal.freezefault = 0;
m_registers.status.signal.startup = 0;
m_registers.status.signal.turnon_q1 = 0;
m_registers.status.signal.turnon_km1 = 0;
m_registers.status.signal.turnon_km3 = 1;
//
status.all = m_registers.status.all;
//
_state_run = &SYSCTRL::SYSRestart::_state_turnon_km3;
//
//
}//
//
#pragma CODE_SECTION("ramfuncs");
inline void SYSRestart::_set_state_startup()
{
m_state = SYSCTRL::SYSRestart::STARTUP;
m_state_bit_field.signal.turnonq1 = 1;
m_state_bit_field.signal.turnonkm1 = 1;
m_state_bit_field.signal.turnonkm3 = 1;
m_state_bit_field.signal.startup = 1;
//
m_registers.counter_timer = FP_ZERO;
//
m_registers.status.signal.resetfault = 0;
m_registers.status.signal.freezefault = 0;
m_registers.status.signal.startup = 1;
m_registers.status.signal.turnon_q1 = 0;
m_registers.status.signal.turnon_km1 = 0;
m_registers.status.signal.turnon_km3 = 0;
status.all = m_registers.status.all;
//
m_registers.counter_attempts++;
//
_state_run = &SYSCTRL::SYSRestart::_state_startup;
//
}//
//
#pragma CODE_SECTION("ramfuncs");
void SYSRestart::_state_execute()
{
(this->*_state_run)();
//
}//
//
#pragma CODE_SECTION("ramfuncs");
void SYSRestart::_state_empty()
{}//
//
#pragma CODE_SECTION("ramfuncs");
void SYSRestart::_state_free()
{
// Change State if appropriate conditions was happened
if(m_registers.monitor_fault.signal.is_on)
{
_set_state_holdfault();
//
}//if
//
}//
//
#pragma CODE_SECTION("ramfuncs");
void SYSRestart::_state_holdfault()
{
// Change State if appropriate conditions was happened
if(m_registers.counter_timer < m_config.period_timer_hold_fault)
{
m_registers.counter_timer += m_time_sample;
//
}//if
if(!m_env.system_fault.boolbit.b0)
{
_set_state_free();
//
}//if
if(m_registers.counter_attempts >= m_config.attempts)
{
_set_state_freezefault();
//
}//if
if(m_env.system_fault.boolbit.b0 & (m_registers.counter_timer >= m_config.period_timer_hold_fault))
{
_set_state_resetfault();
//
}//if
//
}//
//
#pragma CODE_SECTION("ramfuncs");
void SYSRestart::_state_resetfault()
{
// Change State if appropriate conditions was happened
if(m_registers.counter_timer < m_config.period_timer_reset)
{
m_registers.counter_timer += m_time_sample;
//
}//if
if(!m_env.system_fault.boolbit.b0)
{
_set_state_holdstop();
//
}//if
if(m_env.system_fault.boolbit.b0 & (m_registers.counter_timer >= m_config.period_timer_reset))
{
_set_state_freezefault();
//
}//if
//
}//
//
#pragma CODE_SECTION("ramfuncs");
void SYSRestart::_state_freezefault()
{
// Change State if appropriate conditions was happened
if(!m_env.system_fault.boolbit.b0)
{
_set_state_free();
//
}//if
//
}//
//
#pragma CODE_SECTION("ramfuncs");
void SYSRestart::_state_holdstop()
{
// Change State if appropriate conditions was happened
if(m_registers.counter_timer < m_config.period_timer_hold_stop)
{
m_registers.counter_timer += m_time_sample;
//
}//if
if(m_env.system_fault.boolbit.b0 |
(!m_env.system_fault.boolbit.b0 & m_env.remote_stop.state.signal.is_on)
)
{
_set_state_free();
//
}//if
if(!m_env.system_fault.boolbit.b0 &
!m_env.system_ready.boolbit.b0 &
(m_registers.counter_timer >= m_config.period_timer_hold_stop)
)
{
_set_state_turnon_q1();
//
}//if
if(!m_env.system_fault.boolbit.b0 & m_env.system_ready.boolbit.b0)
{
_set_state_startup();
//
}//if
//
}//
//
#pragma CODE_SECTION("ramfuncs");
void SYSRestart::_state_turnon_q1()
{
if(m_registers.counter_timer < m_config.period_timer_turnon_switch)
{
m_registers.counter_timer += m_time_sample;
//
}//if
//
if(m_env.system_fault.boolbit.b0 |
(m_registers.counter_timer >= m_config.period_timer_turnon_switch)
)
{
_set_state_free();
//
}//if
//
if(!m_env.system_fault.boolbit.b0 & m_env.input_discrete.signal.auxiliary_q1)
{
_set_state_turnon_km1();
//
}//if
if(!m_env.system_fault.boolbit.b0 & m_env.system_ready.boolbit.b0)
{
_set_state_startup();
//
}//if
}//
//
#pragma CODE_SECTION("ramfuncs");
void SYSRestart::_state_turnon_km1()
{
if(m_registers.counter_timer < m_config.period_timer_turnon_switch)
{
m_registers.counter_timer += m_time_sample;
//
}//if
if(m_env.system_fault.boolbit.b0 |
(m_registers.counter_timer >= m_config.period_timer_turnon_switch)
)
{
_set_state_free();
//
}//if
//
//
if(!m_env.system_fault.boolbit.b0 & m_env.input_discrete.signal.auxiliary_km1)
{
_set_state_turnon_km3();
//
}//if
if(!m_env.system_fault.boolbit.b0 & m_env.system_ready.boolbit.b0)
{
_set_state_startup();
//
}//if
}//
//
#pragma CODE_SECTION("ramfuncs");
void SYSRestart::_state_turnon_km3()
{
if(m_registers.counter_timer < m_config.period_timer_turnon_switch)
{
m_registers.counter_timer += m_time_sample;
//
}//if
if(m_env.system_fault.boolbit.b0 |
(m_registers.counter_timer >= m_config.period_timer_turnon_switch)
)
{
_set_state_free();
//
}//if
//
if(!m_env.system_fault.boolbit.b0 & m_env.system_ready.boolbit.b0)
{
_set_state_startup();
//
}//if
}//
#pragma CODE_SECTION("ramfuncs");
void SYSRestart::_state_startup()
{
// Change State if appropriate conditions was happened
if(m_registers.counter_timer < m_config.period_timer_startup)
{
m_registers.counter_timer += m_time_sample;
//
}//if
if(m_env.system_fault.boolbit.b0 |
(m_registers.counter_timer >= m_config.period_timer_startup) |
(m_env.enable_work.boolbit.b0) |
(m_env.remote_stop.state.signal.is_on)
)
{
_set_state_free();
//
}//if
//
}//
//
} /* namespace SYSCTRL */