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