|
uniset-algorithms 0.2
|
#include <SEESMode.h>
Открытые члены | |
| void | Destroy () |
| virtual bool | activate (SEES *sc) |
| virtual const string | modeName () |
| virtual SEESMessage::SEESMode | getMode () |
| bool | checkMode (SEES *sc) |
Открытые статические члены | |
| static SEESInitMode * | Instance () |
Режим "инициализации" или "повторной попытки"
| bool SEESInitMode::activate | ( | SEES * | sc | ) | [virtual] |
Переопределяет метод предка SEESMode.
Перекрестные ссылки SEES::initPause, SEESMessage::OffMode и SEESMessage::RunningMode.
{
SEES::dlog[Debug::INFO] << sc << ": init state..." << endl;
// время на инициализацию режима СЭС, а также
// состояния ГА
msleep(sc->initPause);
sc->updateValues();
sc->dis->updateValues();
sc->gen->updateValues();
sc->qg->updateValues();
if( sc->in_CtlMode_f == mOffControl ||
sc->in_CtlMode_f == mUndefined )
{
SEES::dlog[Debug::INFO] << sc << ": режим ручного управления..." << endl;
changeMode( SEESSleepMode::Instance(), sc );
return true;
}
{
if( sc->in_state_as == mPROTECTION )
{
SEES::dlog[Debug::INFO] << sc << "(activate): "
<< " state == mPROTECTION " << endl;
changeMode( SEESProtectionMode::Instance(), sc );
return true;
}
try
{
bool qg_prot = sc->qg->isProtection();
bool dis_prot = sc->dis->isProtection();
bool gen_prot = sc->gen->isProtection();
SEES::dlog[Debug::INFO] << sc << "(activate): "
<< " qg_prot=" << qg_prot
<< " gen_prot=" << gen_prot
<< " dis_prot=" << dis_prot << endl;
if( qg_prot || dis_prot || gen_prot )
{
SEES::dlog[Debug::INFO] << sc << ": init ProtectionMode\n";
changeMode( SEESProtectionMode::Instance(), sc );
return true;
}
#warning Maybe check state_as?
bool qg_state = sc->qg->isOnMode();
bool dis_state = sc->dis->isOnMode();
bool gen_state = sc->gen->isOnMode();
SEES::dlog[Debug::INFO] << sc << ": init Diesel=" << dis_state
<< " Generator=" << gen_state
<< " QG=" << qg_state
<< " sees=" << sc->in_state_as << endl;
// try
// {
// sc->updateValues();
// }
// catch( Exception& ex )
// {
// SEES::dlog[Debug::CRIT] << sc << ": (init): !!!!!!!!!! " << ex << endl;
// throw;
// }
if( ( dis_state && gen_state && qg_state ) || (sc->in_state_as == mON) )
{
sc->out_postID = sc->myPostID;
if( sc->in_CtlMode_f == mAuto )
{
if( sc->in_Leader_f )
{
SEES::dlog[Debug::INFO] << sc << ": to auto mode.." << endl;
changeMode( SEESOnAutoMode::Instance(), sc );
}
else
{
SEES::dlog[Debug::INFO] << sc << ": to reserv mode.." << endl;
changeMode( SEESOnReservMode::Instance(), sc );
}
return true;
}
SEES::dlog[Debug::INFO] << sc << ": to on mode.." << endl;
changeMode( SEESOnMode::Instance(), sc );
return true;
}
else if( ( dis_state && gen_state ) || ( sc->in_state_as == mRunning ) )
{
if( sc->in_CtlMode_f == mPultControl )
{
sc->out_postID = sc->myPostID;
changeMode( SEESRunningMode::Instance(), sc );
return true;
}
else if( sc->in_CtlMode_f == mAuto )
{
sc->out_postID = sc->myPostID;
// if( sc->in_Leader_f )
// {
if( sc->in_NoPower_S )
changeMode( SEESAutoWaitingMode::Instance(sc,SEESMessage::RunningMode,SEESProtectionMode::Instance()), sc );
else
changeMode( SEESAutoWaitingMode::Instance(sc,SEESMessage::OffMode,SEESProtectionMode::Instance()), sc );
// }
return true;
}
}
else if( (!dis_state && !gen_state && !qg_state) || (sc->in_state_as == mOFF) )
{
if( sc->in_CtlMode_f == mAuto )
{
sc->out_postID = sc->myPostID;
if( sc->in_Leader_f )
changeMode( SEESAutoMode::Instance(), sc );
else
changeMode( SEESReservMode::Instance(), sc );
return true;
}
sc->out_postID = sc->myPostID;
changeMode( SEESOffMode::Instance(), sc );
return true;
}
if( checkMode(sc) )
return true;
if( sc->in_state_as == mTRANSITIVE )
{
for( int i=0; i<sc->initAttempts; i++ )
{
msleep(sc->initPause);
sc->updateValues();
if( checkMode(sc) )
return true;
}
}
}
catch(Exception& ex)
{
SEES::dlog[Debug::WARN] << sc << ": " << ex << endl;
}
catch(...)
{
SEES::dlog[Debug::CRIT] << sc << ": неопределённое состояние" << endl;
}
// Undefined state logic....
SEES::dlog[Debug::INFO] << sc << ": state_as=" << sc->in_state_as
<< " " << txtModeName((ObjectMode)sc->in_state_as)
<< endl;
if( sc->in_state_as == mPROTECTION )
{
changeMode( SEESProtectionMode::Instance(), sc );
return true;
}
if( sc->in_CtlMode_f == mAuto )
{
// если состояние "переходное", то делаем несколько попыток
// подождать...
if( sc->in_state_as == mTRANSITIVE )
{
for( int i=0; i<sc->initAttempts; i++ )
{
msleep(sc->initPause);
sc->updateValues();
if( sc->in_state_as != mTRANSITIVE )
break;
}
}
if( sc->in_Leader_f )
{
if( sc->in_state_as == mON )
{
changeMode( SEESOnAutoMode::Instance(), sc );
return true;
}
else if( sc->in_state_as == mOFF )
{
changeMode( SEESAutoMode::Instance(), sc );
return true;
}
}
else
{
if( sc->in_state_as == mON )
{
changeMode( SEESOnReservMode::Instance(), sc );
return true;
}
else if( sc->in_state_as == mOFF )
{
changeMode( SEESReservMode::Instance(), sc );
return true;
}
}
}
SEES::dlog[Debug::CRIT] << sc << ": ПРОТИВОРЕЧИВОЕ СОСТОЯНИЕ" << endl;
// changeMode( SEESUndefinedMode::Instance(), sc );
changeMode( SEESProtectionMode::Instance(), sc );
}
return true;
}
1.7.4