Commit e3a66fe1 authored by Pavel Vainerman's avatar Pavel Vainerman

add new functions (and test): http://bugs.etersoft.ru/show_bug.cgi?id=4217

parent f2377dd4
......@@ -182,6 +182,18 @@ interface IOController_i : ObjectsManager_i
ӣ .
*/
UniSetTypes::IDSeq setOutputSeq( in OutSeq lst, in UniSetTypes::ObjectId sup_id );
/*! */
struct ShortIOInfo
{
long value;
long tv_sec; /*!< , (gettimeofday) */
long tv_usec; /*!< , (gettimeofday) */
};
ShortIOInfo getChangedTime(in SensorInfo si) raises(NameNotFound);
};
// --------------------------------------------------------------------------------------------------------------
......
......@@ -3,7 +3,7 @@
Name: libuniset
Version: 0.96
Release: eter39
Release: eter45
Summary: UniSet - library for building distributed industrial control systems
......@@ -177,6 +177,18 @@ rm -f %buildroot%_libdir/*.la
%exclude %_pkgconfigdir/libUniSet.pc
%changelog
* Fri Aug 14 2009 Pavel Vainerman <pv@altlinux.ru> 0.96-eter44
- new build
* Thu Aug 13 2009 Pavel Vainerman <pv@altlinux.ru> 0.96-eter41
- new build
* Wed Aug 12 2009 Pavel Vainerman <pv@altlinux.ru> 0.96-eter40
- new build
* Wed Aug 12 2009 Pavel Vainerman <pv@altlinux.ru> 0.96-eter39
- new build
* Thu Aug 06 2009 Pavel Vainerman <pv@altlinux.ru> 0.96-eter38
- new build
......
......@@ -122,6 +122,8 @@ class IOController:
UniSetTypes::Message::Priority getPriority(const IOController_i::SensorInfo& si,
UniversalIO::IOTypes type);
virtual IOController_i::ShortIOInfo getChangedTime(const IOController_i::SensorInfo& si);
public:
struct DependsInfo;
......
......@@ -176,7 +176,7 @@ class UniversalInterface
UniSetTypes::ObjectId backid = UniSetTypes::DefaultObjectId );
void askRemoteOutput( UniSetTypes::ObjectId id, UniversalIO::UIOCommand cmd, UniSetTypes::ObjectId node,
UniSetTypes::ObjectId backid = UniSetTypes::DefaultObjectId )throw(IO_THROW_EXCEPTIONS);
UniSetTypes::ObjectId backid = UniSetTypes::DefaultObjectId )throw(IO_THROW_EXCEPTIONS);
//!
void askTimer( UniSetTypes::TimerId timerid, CORBA::Long timeMS, CORBA::Short ticks=-1,
......@@ -191,11 +191,14 @@ class UniversalInterface
UniSetTypes::ObjectId backid = UniSetTypes::DefaultObjectId ) throw(IO_THROW_EXCEPTIONS);
UniversalIO::IOTypes getIOType(UniSetTypes::ObjectId id, UniSetTypes::ObjectId node) throw(IO_THROW_EXCEPTIONS);
UniversalIO::IOTypes getIOType(UniSetTypes::ObjectId id, UniSetTypes::ObjectId node) throw(IO_THROW_EXCEPTIONS);
UniversalIO::IOTypes getIOType(UniSetTypes::ObjectId id);
UniSetTypes::ObjectType getType(UniSetTypes::ObjectId id, UniSetTypes::ObjectId node) throw(IO_THROW_EXCEPTIONS);
UniSetTypes::ObjectType getType(UniSetTypes::ObjectId id, UniSetTypes::ObjectId node) throw(IO_THROW_EXCEPTIONS);
UniSetTypes::ObjectType getType(UniSetTypes::ObjectId id);
IOController_i::ShortIOInfo getChangedTime( UniSetTypes::ObjectId id, UniSetTypes::ObjectId node );
// /*! */
void registered(UniSetTypes::ObjectId id, const UniSetTypes::ObjectPtr oRef, bool force=false)throw(UniSetTypes::ORepFailed);
void registered(UniSetTypes::ObjectId id, UniSetTypes::ObjectId node, const UniSetTypes::ObjectPtr oRef, bool force=false)throw(UniSetTypes::ORepFailed);
......
......@@ -2188,6 +2188,78 @@ void UniversalInterface::fastSaveState( IOController_i::SensorInfo& si, bool sta
}
// ------------------------------------------------------------------------------------------------------------
IOController_i::ShortIOInfo UniversalInterface::getChangedTime( UniSetTypes::ObjectId id, UniSetTypes::ObjectId node )
{
if( id == DefaultObjectId )
throw ORepFailed("UI(getChangedTime): Unknown id=UniSetTypes::DefaultObjectId");
IOController_i::SensorInfo si;
si.id = id;
si.node = node;
try
{
CORBA::Object_var oref;
try
{
oref = rcache.resolve(si.id, si.node);
}
catch( NameNotFound ){}
for (unsigned int i=0; i<uconf->getRepeatCount(); i++)
{
try
{
if( CORBA::is_nil(oref) )
oref = resolve( si.id, si.node );
IOController_i_var iom = IOController_i::_narrow(oref);
return iom->getChangedTime(si);
}
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(si.id, si.node);
unideb[Debug::WARN] << "UI(getChangedTime): " << ex.err << endl;
}
catch(ORepFailed)
{
rcache.erase(si.id, si.node);
unideb[Debug::WARN] << set_err("UI(getChangedTime): ",si.id,si.node) << endl;
}
catch(CORBA::NO_IMPLEMENT)
{
rcache.erase(si.id, si.node);
unideb[Debug::WARN] << set_err("UI(getChangedTime): ",si.id,si.node) << endl;
}
catch(CORBA::OBJECT_NOT_EXIST)
{
rcache.erase(si.id, si.node);
unideb[Debug::WARN] << set_err("UI(getChangedTime): ",si.id,si.node) << endl;
}
catch(CORBA::COMM_FAILURE)
{
//
// unideb[Debug::WARN] << "UI(saveState): CORBA::COMM_FAILURE " << endl;
}
catch(CORBA::SystemException& ex)
{
//
// unideb[Debug::WARN] << "UI(saveState): CORBA::SystemException" << endl;
}
catch(...){}
rcache.erase(si.id, si.node);
throw UniSetTypes::TimeOut(set_err("UI(getChangedTime): TimeOut ",si.id, si.node));
}
// ------------------------------------------------------------------------------------------------------------
ObjectPtr UniversalInterface::CacheOfResolve::resolve( ObjectId id, ObjectId node )
throw(NameNotFound)
......
......@@ -913,7 +913,10 @@ IOController_i::DigitalIOInfo IOController::getDInfo(const IOController_i::Senso
{
DIOStateList::iterator it = dioList.find( key(si.id, si.node) );
if( it!=dioList.end() )
{
uniset_spin_lock lock(it->second.val_lock,checkLockValuePause);
return it->second;
}
// -------------
ostringstream err;
......@@ -926,7 +929,10 @@ IOController_i::AnalogIOInfo IOController::getAInfo(const IOController_i::Sensor
{
AIOStateList::iterator it = aioList.find( key(si.id, si.node) );
if( it!=aioList.end() )
{
uniset_spin_lock lock(it->second.val_lock,checkLockValuePause);
return it->second;
}
// -------------
ostringstream err;
......@@ -1362,3 +1368,35 @@ IDSeq* IOController::setOutputSeq(const IOController_i::OutSeq& lst, ObjectId su
return badlist.getIDSeq();
}
// -----------------------------------------------------------------------------
IOController_i::ShortIOInfo IOController::getChangedTime( const IOController_i::SensorInfo& si )
{
DIOStateList::iterator dit = dioList.find( key(si.id, si.node) );
if( dit!=dioList.end() )
{
IOController_i::ShortIOInfo i;
uniset_spin_lock lock(dit->second.val_lock,checkLockValuePause);
i.value = dit->second.state ? 1 : 0;
i.tv_sec = dit->second.tv_sec;
i.tv_usec = dit->second.tv_usec;
return i;
}
AIOStateList::iterator ait = aioList.find( key(si.id, si.node) );
if( ait!=aioList.end() )
{
IOController_i::ShortIOInfo i;
uniset_spin_lock lock(ait->second.val_lock,checkLockValuePause);
i.value = ait->second.value;
i.tv_sec = ait->second.tv_sec;
i.tv_usec = ait->second.tv_usec;
return i;
}
// -------------
ostringstream err;
err << myname << "(getChangedTime): () "
<< conf->oind->getNameById(si.id) << " ";
unideb[Debug::INFO] << err.str() << endl;
throw IOController_i::NameNotFound(err.str().c_str());
}
// -----------------------------------------------------------------------------
......@@ -2,10 +2,16 @@
# This file is part of the UniSet library #
############################################################################
noinst_PROGRAMS = passivetimer
noinst_PROGRAMS = passivetimer ui
passivetimer_SOURCES = passivetimer.cc
passivetimer_LDADD = $(top_builddir)/lib/libUniSet.la
passivetimer_CPPFLAGS = -I$(top_builddir)/include
ui_SOURCES = ui.cc
ui_LDADD = $(top_builddir)/lib/libUniSet.la
ui_CPPFLAGS = -I$(top_builddir)/include
include $(top_builddir)/conf/setting.mk
#!/bin/sh
ln -s -f /usr/bin/uniset-stop.sh stop.sh
ln -s -f ../conf/test.xml test.xml
#include "UniversalInterface.h"
#include "UniSetTypes.h"
using namespace std;
using namespace UniSetTypes;
int main( int argc, const char **argv )
{
try
{
uniset_init(argc,argv,"test.xml");
int id = conf->getArgInt("--sid");
if( id <=0 )
{
cerr << "unknown sensor ID. Use --sid " << endl;
return 1;
}
UniversalInterface ui;
cout << "getChangedTime for ID=" << id << ":" << endl;
IOController_i::ShortIOInfo inf = ui.getChangedTime(id,conf->getLocalNode());
struct tm* tms = localtime(&inf.tv_sec);
char dbuf[20];
snprintf(dbuf,sizeof(dbuf),"%02d/%02d/%04d ", tms->tm_mday, tms->tm_mon+1, tms->tm_year+1900);
char tbuf[20];
snprintf(tbuf,sizeof(tbuf),"%02d:%02d:%02d ", tms->tm_hour, tms->tm_min, tms->tm_sec);
cout << "id=" << id
<< " value=" << inf.value
<< " last changed: " << string(dbuf) << " " << string(tbuf)
<< endl;
}
catch( Exception& ex )
{
cout << "(uitest):" << ex << endl;
}
catch(...)
{
cout << "(uitest): catch ..."<< endl;
}
return 0;
}
#!/bin/sh
SID=$1
[ -z "$SID" ] && SID=1
uniset-start.sh -f ./ui --confile test.xml --sid $SID
#--unideb-add-levels system,info,level9
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