Commit 3e9fcd84 authored by Pavel Vainerman's avatar Pavel Vainerman

Доработал IOControl. Добавил поддержку режима тестирования.

parent 6363ba08
...@@ -129,6 +129,7 @@ ...@@ -129,6 +129,7 @@
<item default="-655360" iotype="AI" mb_vtype="I2" mbaddr="0x01" mbreg="0x12" mbtcp="2" mbtype="rtu" name="MB1_AS" priority="Medium" textname="Analog input"/> <item default="-655360" iotype="AI" mb_vtype="I2" mbaddr="0x01" mbreg="0x12" mbtcp="2" mbtype="rtu" name="MB1_AS" priority="Medium" textname="Analog input"/>
<item default="6553604" iotype="AI" mb_vtype="U2" mbaddr="0x01" mbreg="0x14" mbtcp="2" mbtype="rtu" name="MB2_AS" priority="Medium" textname="Analog input"/> <item default="6553604" iotype="AI" mb_vtype="U2" mbaddr="0x01" mbreg="0x14" mbtcp="2" mbtype="rtu" name="MB2_AS" priority="Medium" textname="Analog input"/>
<item default="65536045" iotype="AI" mb_vtype="F2" mbaddr="0x01" mbreg="0x17" mbtcp="2" mbtype="rtu" name="MB3_AS" priority="Medium" textname="Analog input"/> <item default="65536045" iotype="AI" mb_vtype="F2" mbaddr="0x01" mbreg="0x17" mbtcp="2" mbtype="rtu" name="MB3_AS" priority="Medium" textname="Analog input"/>
<item iotype="AI" name="IOTestMode_AS" priority="Medium" textname="testmode for IOControl"/>
</sensors> </sensors>
<thresholds name="thresholds"> <thresholds name="thresholds">
<sensor iotype="AI" name="AI_AS"> <sensor iotype="AI" name="AI_AS">
......
...@@ -43,7 +43,10 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID, ...@@ -43,7 +43,10 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID,
force_out(false), force_out(false),
activated(false), activated(false),
readconf_ok(false), readconf_ok(false),
term(false) term(false),
testMode_as(UniSetTypes::DefaultObjectId),
testmode(tmNone),
prev_testmode(tmNone)
{ {
// { // {
// string myfullname = conf->oind->getNameById(id); // string myfullname = conf->oind->getNameById(id);
...@@ -140,7 +143,7 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID, ...@@ -140,7 +143,7 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID,
if( testLamp_S == DefaultObjectId ) if( testLamp_S == DefaultObjectId )
{ {
ostringstream err; ostringstream err;
err << myname << ": не найден идентификатор для датчика ТестЛамп: " << testlamp; err << myname << ": Unkown ID for " << testlamp;
unideb[Debug::CRIT] << myname << "(init): " << err.str() << endl; unideb[Debug::CRIT] << myname << "(init): " << err.str() << endl;
throw SystemError(err.str()); throw SystemError(err.str());
} }
...@@ -148,6 +151,21 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID, ...@@ -148,6 +151,21 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID,
unideb[Debug::INFO] << myname << "(init): testLamp_S='" << testlamp << "'" << endl; unideb[Debug::INFO] << myname << "(init): testLamp_S='" << testlamp << "'" << endl;
} }
string tmode = conf->getArgParam("--io-test-mode",it.getProp("testmode_as"));
if( !tmode.empty() )
{
testMode_as = conf->getSensorID(tmode);
if( testMode_as == DefaultObjectId )
{
ostringstream err;
err << myname << ": Unknown ID for " << tmode;
unideb[Debug::CRIT] << myname << "(init): " << err.str() << endl;
throw SystemError(err.str());
}
unideb[Debug::INFO] << myname << "(init): testMode_as='" << testmode << "'" << endl;
}
shm = new SMInterface(icID,&ui,myid,ic); shm = new SMInterface(icID,&ui,myid,ic);
// определяем фильтр // определяем фильтр
...@@ -270,6 +288,7 @@ void IOControl::execute() ...@@ -270,6 +288,7 @@ void IOControl::execute()
shm->initAIterator(aitHeartBeat); shm->initAIterator(aitHeartBeat);
shm->initDIterator(ditTestLamp); shm->initDIterator(ditTestLamp);
shm->initAIterator(aitTestMode);
PassiveTimer ptAct(activateTimeout); PassiveTimer ptAct(activateTimeout);
while( !activated && !ptAct.checkTime() ) while( !activated && !ptAct.checkTime() )
...@@ -302,9 +321,10 @@ void IOControl::execute() ...@@ -302,9 +321,10 @@ void IOControl::execute()
while(!term) while(!term)
{ {
try try
{ {
if( !noCards ) if( !noCards )
{ {
check_testmode();
check_testlamp(); check_testlamp();
if( ptBlink.checkTime() ) if( ptBlink.checkTime() )
...@@ -370,6 +390,9 @@ void IOControl::execute() ...@@ -370,6 +390,9 @@ void IOControl::execute()
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
void IOControl::iopoll() void IOControl::iopoll()
{ {
if( testmode == tmOffPoll )
return;
// Опрос приоритетной очереди // Опрос приоритетной очереди
for( PIOMap::iterator it=pmap.begin(); it!=pmap.end(); ++it ) for( PIOMap::iterator it=pmap.begin(); it!=pmap.end(); ++it )
{ {
...@@ -415,7 +438,15 @@ void IOControl::ioread( IOInfo* it ) ...@@ -415,7 +438,15 @@ void IOControl::ioread( IOInfo* it )
if( it->ignore || it->ncard == defCardNum ) if( it->ignore || it->ncard == defCardNum )
return; return;
ComediInterface* card = cards.getCard(it->ncard); // если включён режим "в соответсвии с конфигурационным файлом"
// и при этом не стоит для этого канал "игнорировать в тестовом режиме"
if( testmode == tmConfigIgnore && !it->ignore_testmode )
return;
if( testmode == tmConfigEnable && !it->enable_testmode )
return;
ComediInterface* card = cards.getCard(it->ncard);
// cout << conf->oind->getMapName(it->si.id) // cout << conf->oind->getMapName(it->si.id)
// << " card=" << card << " ncard=" << it->ncard // << " card=" << card << " ncard=" << it->ncard
...@@ -713,6 +744,8 @@ bool IOControl::initIOItem( UniXML_iterator& it ) ...@@ -713,6 +744,8 @@ bool IOControl::initIOItem( UniXML_iterator& it )
inf.lamp = it.getIntProp("lamp"); inf.lamp = it.getIntProp("lamp");
inf.no_testlamp = it.getIntProp("no_iotestlamp"); inf.no_testlamp = it.getIntProp("no_iotestlamp");
inf.ignore_testmode = it.getIntProp("ignore_testmode");
inf.enable_testmode = it.getIntProp("enable_testmode");
inf.aref = 0; inf.aref = 0;
inf.range = 0; inf.range = 0;
...@@ -947,6 +980,70 @@ void IOControl::delBlink( IOInfo* io, BlinkList& lst ) ...@@ -947,6 +980,70 @@ void IOControl::delBlink( IOInfo* io, BlinkList& lst )
} }
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void IOControl::check_testmode()
{
if( testMode_as == DefaultObjectId )
return;
try
{
if( force_out )
testmode = shm->localGetValue( aitTestMode, testMode_as );
if( prev_testmode == testmode )
return;
prev_testmode = testmode;
// если режим "выключено всё"
// то гасим все выходы
if( testmode == tmOffPoll )
{
// выставляем безопасные состояния
for( IOMap::iterator it=iomap.begin(); it!=iomap.end(); ++it )
{
if( it->ignore )
continue;
ComediInterface* card = cards.getCard(it->ncard);
if( card == NULL )
continue;
try
{
if( it->subdev==DefaultSubdev || it->safety == NoSafety )
continue;
if( it->stype == UniversalIO::DigitalOutput || it->lamp )
{
bool set = it->invert ? !((bool)it->safety) : (bool)it->safety;
card->setDigitalChannel(it->subdev,it->channel,set);
}
else if( it->stype == UniversalIO::AnalogOutput )
{
card->setAnalogChannel(it->subdev,it->channel,it->safety,it->range,it->aref);
}
}
catch( Exception& ex )
{
unideb[Debug::LEVEL3] << myname << "(sigterm): " << ex << endl;
}
catch(...){}
}
}
}
catch( Exception& ex)
{
unideb[Debug::CRIT] << myname << "(check_testmode): " << ex << endl;
}
catch(...)
{
}
}
// -----------------------------------------------------------------------------
void IOControl::check_testlamp() void IOControl::check_testlamp()
{ {
if( testLamp_S == DefaultObjectId ) if( testLamp_S == DefaultObjectId )
...@@ -1232,6 +1329,16 @@ void IOControl::askSensors( UniversalIO::UIOCommand cmd ) ...@@ -1232,6 +1329,16 @@ void IOControl::askSensors( UniversalIO::UIOCommand cmd )
unideb[Debug::CRIT] << myname << "(askSensors): " << ex << endl; unideb[Debug::CRIT] << myname << "(askSensors): " << ex << endl;
} }
try
{
if( testMode_as != DefaultObjectId )
shm->askSensor(testMode_as,cmd);
}
catch( Exception& ex)
{
unideb[Debug::CRIT] << myname << "(askSensors): " << ex << endl;
}
for( IOMap::iterator it=iomap.begin(); it!=iomap.end(); ++it ) for( IOMap::iterator it=iomap.begin(); it!=iomap.end(); ++it )
{ {
if( it->ignore ) if( it->ignore )
...@@ -1273,6 +1380,11 @@ void IOControl::sensorInfo( UniSetTypes::SensorMessage* sm ) ...@@ -1273,6 +1380,11 @@ void IOControl::sensorInfo( UniSetTypes::SensorMessage* sm )
unideb[Debug::INFO] << myname << "(sensorInfo): test_lamp=" << sm->state << endl; unideb[Debug::INFO] << myname << "(sensorInfo): test_lamp=" << sm->state << endl;
isTestLamp = sm->state; isTestLamp = sm->state;
} }
else if( sm->id == testMode_as )
{
testmode = sm->value;
check_testmode();
}
for( IOMap::iterator it=iomap.begin(); it!=iomap.end(); ++it ) for( IOMap::iterator it=iomap.begin(); it!=iomap.end(); ++it )
{ {
......
...@@ -191,7 +191,9 @@ class IOControl: ...@@ -191,7 +191,9 @@ class IOControl:
aref(0), aref(0),
range(0), range(0),
lamp(false), lamp(false),
no_testlamp(false) no_testlamp(false),
ignore_testmode(false),
enable_testmode(false)
{} {}
...@@ -217,6 +219,8 @@ class IOControl: ...@@ -217,6 +219,8 @@ class IOControl:
bool lamp; /*!< признак, что данный выход является лампочкой (или сигнализатором) */ bool lamp; /*!< признак, что данный выход является лампочкой (или сигнализатором) */
bool no_testlamp; /*!< флаг исключения из 'проверки ламп' */ bool no_testlamp; /*!< флаг исключения из 'проверки ламп' */
bool ignore_testmode; /*!< флаг для режима тестирования tmConfigIgnore */
bool enable_testmode; /*!< флаг для режима тестирования tmConfigEnable */
friend std::ostream& operator<<(std::ostream& os, IOInfo& inf ); friend std::ostream& operator<<(std::ostream& os, IOInfo& inf );
}; };
...@@ -229,6 +233,14 @@ class IOControl: ...@@ -229,6 +233,14 @@ class IOControl:
int priority; int priority;
int index; int index;
}; };
enum TestModeID
{
tmNone = 0, /*!< тестовый режим отключён */
tmOffPoll = 1, /*!< отключить опрос */
tmConfigIgnore = 2, /*!< специальный режим, в соответсвии с настройкой 'ignore_testmode' */
tmConfigEnable = 3 /*!< специальный режим, в соответсвии с настройкой 'enable_testmode' */
};
void execute(); void execute();
...@@ -237,6 +249,7 @@ class IOControl: ...@@ -237,6 +249,7 @@ class IOControl:
void iopoll(); /*!< опрос карт в/в */ void iopoll(); /*!< опрос карт в/в */
void ioread( IOInfo* it ); void ioread( IOInfo* it );
void check_testlamp(); void check_testlamp();
void check_testmode();
void blink(); void blink();
// действия при завершении работы // действия при завершении работы
...@@ -334,6 +347,12 @@ class IOControl: ...@@ -334,6 +347,12 @@ class IOControl:
UniSetTypes::ObjectId sidTestSMReady; UniSetTypes::ObjectId sidTestSMReady;
bool term; bool term;
UniSetTypes::ObjectId testMode_as;
IOController::AIOStateList::iterator aitTestMode;
long testmode;
long prev_testmode;
private: private:
}; };
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment