Commit 8fa15ce5 authored by Vitaly Lipatov's avatar Vitaly Lipatov

add CardList class instead direct vector of ComediInterface,

introduce getCard function instead direct cards[] using with index checking
parent 73310d2f
...@@ -69,7 +69,7 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID, ...@@ -69,7 +69,7 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID,
unideb[Debug::LEVEL3] << myname << "(init): N" << i unideb[Debug::LEVEL3] << myname << "(init): N" << i
<< " (TestMode)!!! '" << " (TestMode)!!! '"
<< iodev << "'" << endl; << iodev << "'" << endl;
cards[i] = 0; cards[i] = NULL;
cout << "******************** CARD" << i << ": IO IMITATOR MODE ****************" << endl; cout << "******************** CARD" << i << ": IO IMITATOR MODE ****************" << endl;
} }
else else
...@@ -79,7 +79,7 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID, ...@@ -79,7 +79,7 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID,
cout << "card" << i << ": " << cards[i]->devname() << endl; cout << "card" << i << ": " << cards[i]->devname() << endl;
} }
if( cards[i] ) if( cards[i] != NULL )
{ {
for( int s=0; s<4; s++ ) for( int s=0; s<4; s++ )
{ {
...@@ -212,9 +212,6 @@ IOControl::~IOControl() ...@@ -212,9 +212,6 @@ IOControl::~IOControl()
// ݣ delete // ݣ delete
// cdiagram new // cdiagram new
// //
for( unsigned int i=0; i<cards.size(); i++ )
delete cards[i];
delete shm; delete shm;
} }
...@@ -341,20 +338,15 @@ void IOControl::execute() ...@@ -341,20 +338,15 @@ void IOControl::execute()
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
void IOControl::iopoll() void IOControl::iopoll()
{ {
ComediInterface* card = 0;
int val = 0;
for( IOMap::iterator it=iomap.begin(); it!=iomap.end(); ++it ) for( IOMap::iterator it=iomap.begin(); it!=iomap.end(); ++it )
{ {
if( it->ignore || it->ncard == defCardNum ) if( it->ignore || it->ncard == defCardNum )
continue; continue;
card = 0; ComediInterface* card = cards.getCard(it->ncard);
if( it->ncard >= 0 && it->ncard<cards.size() )
card = cards[it->ncard];
if( !card || it->subdev==DefaultSubdev || it->channel==DefaultChannel ) if( card == NULL || it->subdev==DefaultSubdev || it->channel==DefaultChannel )
continue; continue;
// cout << conf->oind->getMapName(it->si.id) // cout << conf->oind->getMapName(it->si.id)
...@@ -372,7 +364,7 @@ void IOControl::iopoll() ...@@ -372,7 +364,7 @@ void IOControl::iopoll()
{ {
if( it->stype == UniversalIO::AnalogInput ) if( it->stype == UniversalIO::AnalogInput )
{ {
val = card->getAnalogChannel(it->subdev,it->channel, it->range, it->aref); int val = card->getAnalogChannel(it->subdev,it->channel, it->range, it->aref);
/* /*
if( unideb.debugging(Debug::LEVEL3) ) if( unideb.debugging(Debug::LEVEL3) )
{ {
...@@ -561,7 +553,7 @@ bool IOControl::initIOItem( UniXML_iterator& it ) ...@@ -561,7 +553,7 @@ bool IOControl::initIOItem( UniXML_iterator& it )
else else
inf.ncard = atoi( c.c_str() ); inf.ncard = atoi( c.c_str() );
if( c.empty() || inf.ncard<0 || inf.ncard >= cards.size() ) if( c.empty() || inf.ncard < 0 || inf.ncard >= (int)cards.size() )
{ {
dlog[Debug::LEVEL3] << myname dlog[Debug::LEVEL3] << myname
<< "(initIOItem): (" << "(initIOItem): ("
...@@ -664,19 +656,15 @@ void IOControl::sigterm( int signo ) ...@@ -664,19 +656,15 @@ void IOControl::sigterm( int signo )
if( noCards ) if( noCards )
return; return;
ComediInterface* card = 0;
// //
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 )
continue; continue;
card = 0; ComediInterface* card = cards.getCard(it->ncard);
if( it->ncard>=0 && it->ncard<cards.size() )
card = cards[it->ncard];
if( !card ) if( card == NULL )
continue; continue;
try try
...@@ -710,23 +698,19 @@ void IOControl::initOutputs() ...@@ -710,23 +698,19 @@ void IOControl::initOutputs()
if( noCards ) if( noCards )
return; return;
ComediInterface* card = 0;
// //
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 )
continue; continue;
card = 0; ComediInterface* card = cards.getCard(it->ncard);
if( it->ncard>=0 && it->ncard<cards.size() )
card = cards[it->ncard]; if( card == NULL || it->subdev==DefaultSubdev || it->channel==DefaultChannel )
continue;
try try
{ {
if( !card || it->subdev==DefaultSubdev || it->channel==DefaultChannel )
continue;
if( it->lamp ) if( it->lamp )
card->setDigitalChannel(it->subdev,it->channel,(bool)it->defval); card->setDigitalChannel(it->subdev,it->channel,(bool)it->defval);
else if( it->stype == UniversalIO::DigitalOutput ) else if( it->stype == UniversalIO::DigitalOutput )
...@@ -746,18 +730,14 @@ void IOControl::initIOCard() ...@@ -746,18 +730,14 @@ void IOControl::initIOCard()
if( noCards ) if( noCards )
return; return;
ComediInterface* card = 0;
for( IOMap::iterator it=iomap.begin(); it!=iomap.end(); ++it ) for( IOMap::iterator it=iomap.begin(); it!=iomap.end(); ++it )
{ {
if( it->subdev == DefaultSubdev ) if( it->subdev == DefaultSubdev )
continue; continue;
card = 0; ComediInterface* card = cards.getCard(it->ncard);
if( it->ncard>=0 && it->ncard<cards.size() )
card = cards[it->ncard];
if( !card || it->subdev==DefaultSubdev || it->channel==DefaultChannel ) if( card == NULL || it->subdev==DefaultSubdev || it->channel==DefaultChannel )
continue; continue;
try try
...@@ -792,7 +772,6 @@ void IOControl::blink() ...@@ -792,7 +772,6 @@ void IOControl::blink()
if( lstBlink.empty() ) if( lstBlink.empty() )
return; return;
ComediInterface* card(0);
for( BlinkList::iterator it=lstBlink.begin(); it!=lstBlink.end(); ++it ) for( BlinkList::iterator it=lstBlink.begin(); it!=lstBlink.end(); ++it )
{ {
...@@ -801,15 +780,13 @@ void IOControl::blink() ...@@ -801,15 +780,13 @@ void IOControl::blink()
if( io->subdev == DefaultSubdev || io->channel==DefaultChannel ) if( io->subdev == DefaultSubdev || io->channel==DefaultChannel )
continue; continue;
card = 0;
if( io->ncard>=0 && io->ncard<cards.size() )
card = cards[io->ncard];
if( !card ) ComediInterface* card = cards.getCard(io->ncard);
if( card == NULL )
continue; continue;
try try
{ {
card->setDigitalChannel(io->subdev,io->channel,blink_state); card->setDigitalChannel(io->subdev,io->channel,blink_state);
} }
catch( Exception& ex ) catch( Exception& ex )
...@@ -916,7 +893,7 @@ IOControl* IOControl::init_iocontrol( int argc, char* argv[], ...@@ -916,7 +893,7 @@ IOControl* IOControl::init_iocontrol( int argc, char* argv[],
} }
int numcards = atoi(conf->getArgParam("--io-numcards","1").c_str()); int numcards = atoi(conf->getArgParam("--io-numcards","1").c_str());
if( numcards <=0 ) if( numcards <= 0 )
numcards = 1; numcards = 1;
...@@ -1117,17 +1094,14 @@ void IOControl::askSensors( UniversalIO::UIOCommand cmd ) ...@@ -1117,17 +1094,14 @@ void IOControl::askSensors( UniversalIO::UIOCommand cmd )
unideb[Debug::CRIT] << myname << "(askSensors): " << ex << endl; unideb[Debug::CRIT] << myname << "(askSensors): " << ex << endl;
} }
ComediInterface* card = 0;
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 )
continue; continue;
card = 0; ComediInterface* card = cards.getCard(it->ncard);
if( it->ncard>=0 && it->ncard<cards.size() )
card = cards[it->ncard]; if( card == NULL || it->subdev==DefaultSubdev || it->channel==DefaultChannel )
if( !card || it->subdev==DefaultSubdev || it->channel==DefaultChannel )
continue; continue;
if( it->stype == UniversalIO::AnalogOutput || if( it->stype == UniversalIO::AnalogOutput ||
...@@ -1206,12 +1180,10 @@ void IOControl::sensorInfo( UniSetTypes::SensorMessage* sm ) ...@@ -1206,12 +1180,10 @@ void IOControl::sensorInfo( UniSetTypes::SensorMessage* sm )
// ( ) // ( )
if( it->ignore || it->subdev==DefaultSubdev || it->channel==DefaultChannel ) if( it->ignore || it->subdev==DefaultSubdev || it->channel==DefaultChannel )
break; break;
ComediInterface* card = 0; ComediInterface* card = cards.getCard(it->ncard);
if( it->ncard>=0 && it->ncard<cards.size() )
card = cards[it->ncard]; if( card != NULL )
if( card )
card->setDigitalChannel(it->subdev,it->channel,1); card->setDigitalChannel(it->subdev,it->channel,1);
} }
} }
......
...@@ -24,6 +24,26 @@ ...@@ -24,6 +24,26 @@
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#warning .... #warning ....
class CardList:
public std::vector<ComediInterface*>
{
public:
CardList(int size) : std::vector<ComediInterface*>(size) { }
~CardList() {
for( unsigned int i=0; i<size(); i++ )
delete (*this)[i];
}
inline ComediInterface* getCard(int ncard) {
if( ncard >= 0 && ncard < (int)size() )
return (*this)[ncard];
return NULL;
}
};
/*! /*!
/. /.
: :
...@@ -70,7 +90,7 @@ class IOControl: ...@@ -70,7 +90,7 @@ class IOControl:
int subdev; /*!< (UNIO) (. comedi_test /) */ int subdev; /*!< (UNIO) (. comedi_test /) */
int channel; /*!< (UNIO) [0...23] */ int channel; /*!< (UNIO) [0...23] */
int ncard; /*!< [1|2]. 0 - */ int ncard; /*!< [1|2]. 0 - . FIXME from Lav: -1 - ? */
/*! /*!
0 - analog ref = analog ground 0 - analog ref = analog ground
...@@ -131,7 +151,7 @@ class IOControl: ...@@ -131,7 +151,7 @@ class IOControl:
xmlNode* cnode; /*!< xml- */ xmlNode* cnode; /*!< xml- */
int polltime; /*!< ( /), [] */ int polltime; /*!< ( /), [] */
std::vector<ComediInterface*> cards; CardList cards; /*!< - ComediInterface */
bool noCards; bool noCards;
......
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