Commit c770e6b4 authored by Pavel Vainerman's avatar Pavel Vainerman

add new interface: getSensors()

parent 748186e5
......@@ -194,6 +194,18 @@ interface IOController_i : ObjectsManager_i
ShortIOInfo getChangedTime(in SensorInfo si) raises(NameNotFound);
/*! */
struct ShortMap
{
UniversalIO::IOTypes type;
long value;
long id;
};
typedef sequence<ShortMap> ShortMapSeq;
ShortMapSeq getSensors();
};
// --------------------------------------------------------------------------------------------------------------
......
......@@ -53,6 +53,11 @@
</History>
</SharedMemory>
<UniExchange name="UniExchange">
<item name="UniExchange2" node_id="Node2" sid_connection=""/>
<item id="3001" node_id="Node2" sid_connection=""/>
</UniExchange>
<MBMaster1 name="MBMaster1" iaddr="127.0.0.1" addr="0x31" port="30000"
levels="info,warn,crit" poll_time="200" reply_timeout="60"
/>
......@@ -156,6 +161,8 @@
<controllers name="Controllers">
<item name="SharedMemory"/>
<item name="UniExchange"/>
<item name="UniExchange2"/>
</controllers>
<!-- ******************* ***************** -->
......
......@@ -9,10 +9,21 @@ using namespace std;
using namespace UniSetTypes;
using namespace UniSetExtensions;
// --------------------------------------------------------------------------
UniExchange::NetNodeInfo::NetNodeInfo():
oref(CORBA::Object::_nil()),
id(DefaultObjectId),
node(conf->getLocalNode()),
sidConnection(DefaultObjectId),
smap(1)
{
}
// --------------------------------------------------------------------------
UniExchange::UniExchange( UniSetTypes::ObjectId id, UniSetTypes::ObjectId shmID,
SharedMemory* ic, const std::string prefix ):
IOController(id),
shm(0)
shm(0),
polltime(200)
{
cnode = conf->getNode(myname);
if( cnode == NULL )
......@@ -29,8 +40,6 @@ shm(0)
if( it.goChildren() )
{
UniSetTypes::ObjectId l_id = getSharedMemoryID();
for( ; it.getCurrent(); it.goNext() )
{
UniSetTypes::ObjectId id;
......@@ -39,10 +48,14 @@ shm(0)
if( !n.empty() )
id = it.getIntProp("id");
else
id = conf->getControllerID(n);
id = conf->getControllerID( it.getProp("name") );
if( id == DefaultObjectId )
{
if( n.empty() )
n = it.getProp("name");
throw SystemError("(UniExchange): Uknown ID for " + n );
}
UniSetTypes::ObjectId node;
......@@ -86,87 +99,88 @@ void UniExchange::execute()
{
for( NetNodeList::iterator it=nlst.begin(); it!=nlst.end(); ++it )
{
bool ok = false;
try
{
bool ok = false;;
/*
dlog[Debug::INFO] << myname << ": resolve id=" << it->id
<< " name=" << conf->oind->getNameById(it->id)
<< " node=" << it->node
<< endl;
*/
for(
unsigned int i=0; i<conf->getRepeatCount(); i++)
{
try
IOController_i::ShortMapSeq_var sseq = ui.getSensors( it->id, it->node );
ok = true;
it->update(sseq,shm);
}
catch( Exception& ex )
{
if( CORBA::is_nil(it->oref) )
dlog[Debug::INFO] << myname << "(execute): " << ex << endl;
}
catch( ... )
{
it->oref = ui.resolve( it->id, it->node );
dlog[Debug::INFO] << myname << "(execute): catch ..." << endl;
}
if( CORBA::is_nil(it->oref) )
continue;
it->shm = IONotifyController_i::_narrow(it->oref);
if( CORBA::is_nil(it->shm) )
if( it->sidConnection != DefaultObjectId )
{
it->oref = CORBA::Object::_nil();
msleep(conf->getRepeatTimeout());
continue;
try
{
shm->localSaveState(it->conn_dit,it->sidConnection,ok,getId());
}
if ( it->shm->exist() )
catch(...)
{
dlog[Debug::INFO] << " node=" << it->node << ": resolve OK ***" << endl;
ok = true;
break;
dlog[Debug::CRIT]<< myname << "(execute): sensor not avalible "
<< conf->oind->getNameById( it->sidConnection)
<< endl;
}
}
if( !ok )
dlog[Debug::INFO] << "****** cannot connect with node=" << it->node << endl;
}
catch(CORBA::TRANSIENT){}
catch(CORBA::OBJECT_NOT_EXIST){}
catch(CORBA::SystemException& ex){}
catch(...){}
it->oref = CORBA::Object::_nil();
msleep(conf->getRepeatTimeout());
msleep(polltime);
}
}
// -----------------------------------------------------------------------------
void UniExchange::NetNodeInfo::update( IOController_i::ShortMapSeq_var& map, SMInterface* shm )
{
bool reinit = false;
if( smap.size() != map->length() )
{
reinit = true;
// init new map...
smap.resize(map->length());
}
if( it->sidConnection != DefaultObjectId )
int size = map->length();
for( int i=0; i<size; i++ )
{
try
if( reinit )
{
// shm->saveLocalState( it->sidConnection, ok );
ui.saveState(it->sidConnection, ok, UniversalIO::DigitalInput,conf->getLocalNode());
}
catch(...){dlog[Debug::CRIT]<< myname << "(execute): sensor not avalible "<< conf->oind->getNameById( it->sidConnection) <<endl; }
shm->initDIterator(smap[i].dit);
shm->initAIterator(smap[i].ait);
}
if( !ok )
try
{
dlog[Debug::INFO] << "****** cannot connect with node=" << it->node << endl;
continue;
}
if( map[i].type == UniversalIO::DigitalInput )
shm->localSaveState( smap[i].dit, map[i].id, (map[i].value ? true : false ), shm->ID() );
else if( map[i].type == UniversalIO::DigitalOutput )
shm->localSetState( smap[i].dit, map[i].id, (map[i].value ? true : false ), shm->ID() );
else if( map[i].type == UniversalIO::AnalogInput )
shm->localSaveValue( smap[i].ait, map[i].id, map[i].value, shm->ID() );
else if( map[i].type == UniversalIO::AnalogOutput )
shm->localSetValue( smap[i].ait, map[i].id, map[i].value, shm->ID() );
}
catch( Exception& ex )
{
cout << myname << "(execute): " << ex << endl;
dlog[Debug::INFO] << "(update): " << ex << endl;
}
catch( ... )
{
cout << myname << "(execute): catch ..." << endl;
dlog[Debug::INFO] << "(update): catch ..." << endl;
}
}
msleep(200);
}
}
// -----------------------------------------------------------------------------
// --------------------------------------------------------------------------
void UniExchange::askSensors( UniversalIO::UIOCommand cmd )
{
}
// -----------------------------------------------------------------------------
void UniExchange::processingMessage( UniSetTypes::VoidMessage* msg )
......@@ -248,7 +262,9 @@ UniExchange* UniExchange::init_exchange( int argc, const char* const* argv,
UniSetTypes::ObjectId icID, SharedMemory* ic,
const std::string prefix )
{
string nm(conf->getArgParam("--uniexchange-id","UniExchange"));
string p("--" + prefix + "-id");
string nm(UniSetTypes::getArgParam(p,argc,argv,"UniExchange"));
UniSetTypes::ObjectId ID = conf->getControllerID(nm);
if( ID == UniSetTypes::DefaultObjectId )
{
......@@ -259,16 +275,6 @@ UniExchange* UniExchange::init_exchange( int argc, const char* const* argv,
return new UniExchange(ID,icID,ic,prefix);
}
// -----------------------------------------------------------------------------
IOController_i::ASensorInfoSeq* UniExchange::getAnalogSensorsMap()
{
}
// -----------------------------------------------------------------------------
IOController_i::DSensorInfoSeq* UniExchange::getDigitalSensorsMap()
{
}
// -----------------------------------------------------------------------------
void UniExchange::readConfiguration()
{
#warning !!!
......
......@@ -19,9 +19,6 @@ class UniExchange:
void execute();
virtual IOController_i::ASensorInfoSeq* getAnalogSensorsMap();
virtual IOController_i::DSensorInfoSeq* getDigitalSensorsMap();
static UniExchange* init_exchange( int argc, const char* const* argv,
UniSetTypes::ObjectId shmID, SharedMemory* ic=0,
const std::string prefix="unet" );
......@@ -43,13 +40,27 @@ class UniExchange:
std::string s_fvalue;
SMInterface* shm;
struct SInfo
{
IOController::DIOStateList::iterator dit;
IOController::AIOStateList::iterator ait;
};
typedef std::vector<SInfo> SList;
struct NetNodeInfo
{
NetNodeInfo();
CORBA::Object_var oref;
IONotifyController_i_var shm;
IOController_i_var shm;
UniSetTypes::ObjectId id;
UniSetTypes::ObjectId node;
UniSetTypes::ObjectId sidConnection; /*!< */
IOController::DIOStateList::iterator conn_dit;
SList smap;
void update(IOController_i::ShortMapSeq_var& map, SMInterface* shm );
};
typedef std::list<NetNodeInfo> NetNodeList;
......@@ -60,6 +71,8 @@ class UniExchange:
bool readItem( UniXML& xml, UniXML_iterator& it, xmlNode* sec );
bool initItem( UniXML_iterator& it );
int polltime;
private:
};
// -----------------------------------------------------------------------------
......
#!/bin/sh
ln -s -f ../../Utilities/scripts/uniset-start.sh
ln -s -f ../../Utilities/scripts/uniset-stop.sh stop.sh
ln -s -f ../../Utilities/scripts/uniset-functions.sh
ln -s -f ../../conf/test.xml test.xml
......@@ -4,7 +4,5 @@ export LD_LIBRARY_PATH="../../lib/.libs;../lib/.libs"
ulimit -Sc 10000000000
./uniset-start.sh -f ./uniset-network --smemory-id SharedMemory \
--unideb-add-levels info,crit,warn,level9,system \
--dlog-add-levels info,crit,warn
./uniset-start.sh -f ./uniset-network --confile test.xml --unet-id SharedMemory
......@@ -28,7 +28,6 @@ int main(int argc, const char **argv)
unideb.logFile( logname.c_str() );
dlog.logFile( logname.c_str() );
ObjectId shmID = DefaultObjectId;
string sID = conf->getArgParam("--smemory-id");
if( !sID.empty() )
......@@ -51,7 +50,8 @@ int main(int argc, const char **argv)
act.addObject(static_cast<class UniSetObject*>(shm));
SystemMessage sm(SystemMessage::StartUp);
act.broadcast( sm.transport_msg() );
act.run(false);
act.run(true);
shm->execute();
return 0;
}
catch(SystemError& err)
......
......@@ -124,6 +124,8 @@ class IOController:
virtual IOController_i::ShortIOInfo getChangedTime(const IOController_i::SensorInfo& si);
virtual IOController_i::ShortMapSeq* getSensors();
public:
struct DependsInfo;
......
......@@ -197,7 +197,8 @@ class UniversalInterface
UniSetTypes::ObjectType getType(UniSetTypes::ObjectId id);
IOController_i::ShortIOInfo getChangedTime( UniSetTypes::ObjectId id, UniSetTypes::ObjectId node );
IOController_i::ShortMapSeq* getSensors( UniSetTypes::ObjectId id,
UniSetTypes::ObjectId node=UniSetTypes::conf->getLocalNode() );
// /*! */
void registered(UniSetTypes::ObjectId id, const UniSetTypes::ObjectPtr oRef, bool force=false)throw(UniSetTypes::ORepFailed);
......
......@@ -2986,6 +2986,69 @@ UniSetTypes::IDSeq_var UniversalInterface::askSensorsSeq( UniSetTypes::IDList& l
throw UniSetTypes::TimeOut(set_err("UI(askSensorSeq): TimeOut ",sid,conf->getLocalNode()));
}
// -----------------------------------------------------------------------------
IOController_i::ShortMapSeq* UniversalInterface::getSensors( UniSetTypes::ObjectId id, UniSetTypes::ObjectId node )
{
try
{
CORBA::Object_var oref;
try
{
oref = rcache.resolve(id,node);
}
catch( NameNotFound ){}
for( unsigned int i=0; i<uconf->getRepeatCount(); i++)
{
try
{
if( CORBA::is_nil(oref) )
oref = resolve(id,node);
IOController_i_var iom = IOController_i::_narrow(oref);
return iom->getSensors();
}
catch(CORBA::TRANSIENT){}
catch(CORBA::OBJECT_NOT_EXIST){}
catch(CORBA::SystemException& ex){}
msleep(uconf->getRepeatTimeout());
oref = CORBA::Object::_nil();
}
}
catch(UniSetTypes::TimeOut){}
catch(IOController_i::NameNotFound &ex)
{
rcache.erase(id,node);
throw NameNotFound("UI(getSensors): "+string(ex.err));
}
catch(ORepFailed)
{
rcache.erase(id,node);
//
throw IOBadParam(set_err("UI(getSensors): ",id,node));
}
catch(CORBA::NO_IMPLEMENT)
{
rcache.erase(id,node);
throw IOBadParam(set_err("UI(getSensors): ",id,node));
}
catch(CORBA::OBJECT_NOT_EXIST)
{
rcache.erase(id,node);
throw IOBadParam(set_err("UI(getSensors): ",id,node));
}
catch(CORBA::COMM_FAILURE& ex)
{
//
}
catch(CORBA::SystemException& ex)
{
//
// unideb[Debug::WARN] << "UI(getValue): CORBA::SystemException" << endl;
}
rcache.erase(id,node);
throw UniSetTypes::TimeOut(set_err("UI(getSensors): TimeOut ",id,node));
}
// -----------------------------------------------------------------------------
bool UniversalInterface::waitReady( UniSetTypes::ObjectId id, int msec, int pmsec, ObjectId node )
{
PassiveTimer ptReady(msec);
......
......@@ -1411,3 +1411,38 @@ IOController_i::ShortIOInfo IOController::getChangedTime( const IOController_i::
throw IOController_i::NameNotFound(err.str().c_str());
}
// -----------------------------------------------------------------------------
IOController_i::ShortMapSeq* IOController::getSensors()
{
// !!!!!!
// _var-
IOController_i::ShortMapSeq* res = new IOController_i::ShortMapSeq();
res->length( aioList.size() + dioList.size() );
int i=0;
for( AIOStateList::iterator it=aioList.begin(); it!=aioList.end(); ++it)
{
IOController_i::ShortMap m;
{
uniset_spin_lock lock(it->second.val_lock,checkLockValuePause);
m.id = it->second.si.id;
m.value = it->second.value;
m.type = it->second.type;
}
(*res)[i++] = m;
}
for( DIOStateList::iterator it=dioList.begin(); it!=dioList.end(); ++it)
{
IOController_i::ShortMap m;
{
uniset_spin_lock lock(it->second.val_lock,checkLockValuePause);
m.id = it->second.si.id;
m.value = it->second.state ? 1 : 0;
m.type = it->second.type;
}
(*res)[i++] = m;
}
return res;
}
// -----------------------------------------------------------------------------
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