Commit c6ffa6cc authored by Pavel Vainerman's avatar Pavel Vainerman

UniNetwork debugging part.2

parent 70196012
......@@ -3,7 +3,7 @@
Name: libuniset
Version: 0.96
Release: eter59
Release: eter60
Summary: UniSet - library for building distributed industrial control systems
License: GPL
Group: Development/C++
......@@ -179,6 +179,9 @@ rm -f %buildroot%_libdir/*.la
%exclude %_pkgconfigdir/libUniSet.pc
%changelog
* Thu Sep 10 2009 Pavel Vainerman <pv@altlinux.ru> 0.96-eter59
- UniNetwork debugging
* Wed Sep 09 2009 Pavel Vainerman <pv@altlinux.ru> 0.96-eter58
- UniNetwork debugging
......
......@@ -23,7 +23,10 @@ UniExchange::UniExchange( UniSetTypes::ObjectId id, UniSetTypes::ObjectId shmID,
SharedMemory* ic, const std::string prefix ):
IOController(id),
shm(0),
polltime(200)
polltime(200),
mymap(1),
maxIndex(0),
smReadyTimeout(15000)
{
cnode = conf->getNode(myname);
if( cnode == NULL )
......@@ -43,6 +46,20 @@ polltime(200)
polltime = 200;
dlog[Debug::INFO] << myname << "(init): polltime=" << polltime << endl;
int updatetime = conf->getArgInt("--" + prefix + "-updatetime",it.getProp("updatetime"));
if( updatetime <= 0 )
updatetime = 200;
dlog[Debug::INFO] << myname << "(init): updatetime=" << polltime << endl;
ptUpdate.setTiming(updatetime);
smReadyTimeout = atoi(conf->getArgParam("--io-sm-ready-timeout",it.getProp("ready_timeout")).c_str());
if( smReadyTimeout == 0 )
smReadyTimeout = 15000;
else if( smReadyTimeout < 0 )
smReadyTimeout = UniSetTimer::WaitUpTime;
dlog[Debug::INFO] << myname << "(init): smReadyTimeout=" << smReadyTimeout << endl;
if( it.goChildren() )
{
......@@ -88,7 +105,10 @@ polltime(200)
}
if( shm->isLocalwork() )
{
readConfiguration();
mymap.resize(maxIndex);
}
else
ic->addReadItem( sigc::mem_fun(this,&UniExchange::readItem) );
}
......@@ -103,6 +123,28 @@ UniExchange::~UniExchange()
// -----------------------------------------------------------------------------
void UniExchange::execute()
{
if( !shm->waitSMready(smReadyTimeout,50) )
{
ostringstream err;
err << myname << "(execute): SharedMemory "
<< smReadyTimeout << " ";
unideb[Debug::CRIT] << err.str() << endl;
throw SystemError(err.str());
}
PassiveTimer pt(UniSetTimer::WaitUpTime);
if( shm->isLocalwork() )
{
maxIndex = 0;
readConfiguration();
cerr << "************************** readConfiguration: " << pt.getCurrent() << " msec " << endl;
}
mymap.resize(maxIndex);
initIterators();
init_ok = true;
while(1)
{
for( NetNodeList::iterator it=nlst.begin(); it!=nlst.end(); ++it )
......@@ -146,6 +188,12 @@ void UniExchange::execute()
if( !ok && dlog.debugging(Debug::INFO) )
dlog[Debug::INFO] << myname << ": ****** cannot connect with node=" << it->node << endl;
}
if( ptUpdate.checkTime() )
{
updateLocalData();
ptUpdate.reset();
}
msleep(polltime);
}
......@@ -168,7 +216,11 @@ void UniExchange::NetNodeInfo::update( IOController_i::ShortMapSeq_var& map, SMI
{
shm->initDIterator(smap[i].dit);
shm->initAIterator(smap[i].ait);
smap[i].type = map[i].type;
smap[i].id = map[i].id;
}
smap[i].val = map[i].value;
try
{
......@@ -192,6 +244,66 @@ void UniExchange::NetNodeInfo::update( IOController_i::ShortMapSeq_var& map, SMI
}
}
// --------------------------------------------------------------------------
IOController_i::ShortMapSeq* UniExchange::getSensors()
{
if( !init_ok )
throw CORBA::COMM_FAILURE();
IOController_i::ShortMapSeq* res = new IOController_i::ShortMapSeq();
res->length( mymap.size() );
int i=0;
for( SList::iterator it=mymap.begin(); it!=mymap.end(); ++it )
{
IOController_i::ShortMap m;
m.id = it->id;
m.value = it->val;
m.type = it->type;
(*res)[i++] = m;
}
return res;
}
// --------------------------------------------------------------------------
void UniExchange::updateLocalData()
{
for( SList::iterator it=mymap.begin(); it!=mymap.end(); ++it )
{
try
{
if( it->type == UniversalIO::DigitalInput ||
it->type == UniversalIO::DigitalOutput )
{
it->val = shm->localGetState( it->dit, it->id );
}
else if( it->type == UniversalIO::AnalogInput ||
it->type == UniversalIO::AnalogOutput )
{
it->val = shm->localGetValue( it->ait, it->id );
}
}
catch( Exception& ex )
{
dlog[Debug::INFO] << "(update): " << ex << endl;
}
catch( ... )
{
dlog[Debug::INFO] << "(update): catch ..." << endl;
}
}
init_ok = true;
}
// --------------------------------------------------------------------------
void UniExchange::initIterators()
{
for( SList::iterator it=mymap.begin(); it!=mymap.end(); ++it )
{
shm->initDIterator(it->dit);
shm->initAIterator(it->ait);
}
}
// --------------------------------------------------------------------------
void UniExchange::askSensors( UniversalIO::UIOCommand cmd )
{
......@@ -345,10 +457,44 @@ bool UniExchange::readItem( UniXML& xml, UniXML_iterator& it, xmlNode* sec )
// ------------------------------------------------------------------------------------------
bool UniExchange::initItem( UniXML_iterator& it )
{
SInfo i;
i.id = DefaultObjectId;
if( it.getProp("id").empty() )
i.id = conf->getSensorID(it.getProp("name"));
else
{
i.id = it.getIntProp("id");
if( i.id <=0 )
i.id = DefaultObjectId;
}
if( i.id == DefaultObjectId )
{
if( dlog )
dlog[Debug::CRIT] << myname << "(initItem): Unknown ID for "
<< it.getProp("name") << endl;
return false;
}
i.type = UniSetTypes::getIOType(it.getProp("iotype"));
if( i.type == UniversalIO::UnknownIOType )
{
if( dlog )
dlog[Debug::CRIT] << myname << "(initItem): Unknown iotype= "
<< it.getProp("iotype") << " for " << it.getProp("name") << endl;
return false;
}
i.val = 0;
mymap[maxIndex++] = i;
if( maxIndex >= mymap.size() )
mymap.resize(maxIndex+10);
return true;
}
// ------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void UniExchange::help_print( int argc, const char** argv )
{
cout << "--unet-polltime msec - . 200 ." << endl;
......
......@@ -8,6 +8,7 @@
#include "IOController.h"
#include "SMInterface.h"
#include "SharedMemory.h"
#include "PassiveTimer.h"
// -----------------------------------------------------------------------------
class UniExchange:
public IOController
......@@ -26,6 +27,8 @@ class UniExchange:
/*! help- */
static void help_print( int argc, const char** argv );
virtual IOController_i::ShortMapSeq* getSensors();
protected:
virtual void processingMessage( UniSetTypes::VoidMessage* msg );
......@@ -42,8 +45,17 @@ class UniExchange:
struct SInfo
{
SInfo():
val(0),
id(UniSetTypes::DefaultObjectId),
type(UniversalIO::UnknownIOType)
{}
IOController::DIOStateList::iterator dit;
IOController::AIOStateList::iterator ait;
long val;
long id;
UniversalIO::IOTypes type;
};
typedef std::vector<SInfo> SList;
......@@ -70,8 +82,16 @@ class UniExchange:
bool check_item( UniXML_iterator& it );
bool readItem( UniXML& xml, UniXML_iterator& it, xmlNode* sec );
bool initItem( UniXML_iterator& it );
void updateLocalData();
void initIterators();
int polltime;
PassiveTimer ptUpdate;
bool init_ok;
SList mymap;
int maxIndex;
int smReadyTimeout;
private:
};
......
......@@ -4,5 +4,7 @@ export LD_LIBRARY_PATH="../../lib/.libs;../lib/.libs"
ulimit -Sc 10000000000
./uniset-start.sh -f ./uniset-network --confile test.xml --unet-id SharedMemory
./uniset-start.sh -f ./uniset-network --confile test.xml \
--smemory-id SharedMemory \
--unet-id UniExchange
......@@ -76,7 +76,7 @@ class IOController:
UniversalIO::IOTypes type = UniversalIO::DigitalInput,
UniSetTypes::ObjectId sup_id = UniSetTypes::DefaultObjectId );
/*! \warning , */
/*! \warning , */
virtual void saveValue(const IOController_i::SensorInfo& si, CORBA::Long value,
UniversalIO::IOTypes type = UniversalIO::AnalogInput,
UniSetTypes::ObjectId sup_id = UniSetTypes::DefaultObjectId );
......@@ -94,7 +94,7 @@ class IOController:
virtual UniSetTypes::IDSeq* setOutputSeq(const IOController_i::OutSeq& lst, UniSetTypes::ObjectId sup_id);
// ----------------------------------------------------------------
virtual UniversalIO::IOTypes getIOType(const IOController_i::SensorInfo& si);
virtual UniversalIO::IOTypes getIOType(const IOController_i::SensorInfo& si);
virtual IOController_i::ASensorInfoSeq* getAnalogSensorsMap();
virtual IOController_i::DSensorInfoSeq* getDigitalSensorsMap();
......
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