Commit 4139b7d7 authored by Pavel Vainerman's avatar Pavel Vainerman

add getConfIOType function to UniversalInterface.

parent ce4ba08d
......@@ -3,7 +3,7 @@
Name: libuniset
Version: 0.97
Release: eter58
Release: eter59
Summary: UniSet - library for building distributed industrial control systems
License: GPL
Group: Development/C++
......
......@@ -107,6 +107,7 @@ namespace UniSetTypes
xmlNode* getXMLObjectsSection();
xmlNode* getXMLControllersSection();
xmlNode* getXMLServicesSection();
xmlNode* getObjectInfo( UniSetTypes::ObjectId );
// net
inline unsigned int getCountOfNet() const { return countOfNet; }
......
......@@ -118,9 +118,14 @@ namespace UniSetTypes
/*! */
struct ObjectInfo
{
ObjectInfo():
id(DefaultObjectId),
repName(0),textName(0),data(0){}
ObjectId id; /*!< */
char* repName; /*!< */
char* textName; /*!< */
void* data;
};
typedef std::list<NodeInfo> ListOfNode;
......
......@@ -196,6 +196,9 @@ class UniversalInterface
UniSetTypes::ObjectType getType(UniSetTypes::ObjectId id, UniSetTypes::ObjectId node) throw(IO_THROW_EXCEPTIONS);
UniSetTypes::ObjectType getType(UniSetTypes::ObjectId id);
// read from xml (only for xml!)
UniversalIO::IOTypes getConfIOType( 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() );
......
......@@ -3101,3 +3101,17 @@ bool UniversalInterface::waitWorking( UniSetTypes::ObjectId id, int msec, int pm
}
// -----------------------------------------------------------------------------
UniversalIO::IOTypes UniversalInterface::getConfIOType( UniSetTypes::ObjectId id )
{
if( !conf )
return UniversalIO::UnknownIOType;
xmlNode* x = conf->getObjectInfo(id);
if( !x )
return UniversalIO::UnknownIOType;
UniXML_iterator it(x);
return UniSetTypes::getIOType( it.getProp("iotype") );
}
// -----------------------------------------------------------------------------
......@@ -188,6 +188,8 @@ unsigned int ObjectIndex_XML::read_section( UniXML& xml, const std::string sec,
delete[] omap[ind].textName;
omap[ind].textName = new char[textname.size()+1];
strcpy( omap[ind].textName, textname.c_str() );
omap[ind].data = (void*)(xmlNode*)it;
// cout << "read: " << "(" << ind << ") " << omap[ind].repName << "\t" << omap[ind].textName << endl;
ind++;
......@@ -257,6 +259,7 @@ unsigned int ObjectIndex_XML::read_nodes( UniXML& xml, const std::string sec, un
omap[ind].textName = new char[textname.size()+1];
strcpy( omap[ind].textName, textname.c_str() );
omap[ind].data = (void*)(xmlNode*)(it);
//
mok[omap[ind].repName] = ind;
......
......@@ -157,6 +157,9 @@ void ObjectIndex_idXML::read_section( UniXML& xml, const std::string sec )
inf.textName = new char[textname.size()+1];
strcpy( inf.textName, textname.c_str() );
inf.data = (void*)(xmlNode*)(it);
omap[inf.id] = inf;
}
}
......@@ -211,6 +214,8 @@ void ObjectIndex_idXML::read_nodes( UniXML& xml, const std::string sec )
inf.textName = new char[textname.size()+1];
strcpy( inf.textName, textname.c_str() );
inf.data = (void*)(xmlNode*)(it);
omap[inf.id] = inf;
}
......
......@@ -1012,6 +1012,15 @@ xmlNode* Configuration::getXMLServicesSection()
return xmlServicesSec;
}
// -------------------------------------------------------------------------
xmlNode* Configuration::getObjectInfo( UniSetTypes::ObjectId id )
{
const ObjectInfo* i = oind->getObjectInfo(id);
if( i )
return (xmlNode*)(i->data);
return 0;
}
// -------------------------------------------------------------------------
void uniset_init( int argc, const char* const* argv, const std::string xmlfile )
{
string confile = UniSetTypes::getArgParam( "--confile", argc, argv, xmlfile );
......
......@@ -11,6 +11,25 @@ int main( int argc, const char **argv )
{
uniset_init(argc,argv,"test.xml");
UniversalInterface ui;
cout << "** check getSensorID function **" << endl;
ObjectId id1 = conf->getSensorID("Input1_S");
if( id1 != 1 )
{
cout << "** FAILED! check getSensorID function **" << endl;
return 1;
}
cout << "** check getConfIOType function **" << endl;
UniversalIO::IOTypes t = ui.getConfIOType(id1);
cout << "sensor ID=" << id1 << " iotype=" << t << endl;
if( t != UniversalIO::DigitalInput )
{
cout << "** FAILED! check getSensorID function **" << endl;
return 1;
}
int id = conf->getArgInt("--sid");
if( id <= 0 )
......@@ -19,9 +38,8 @@ int main( int argc, const char **argv )
return 1;
}
UniversalInterface ui;
cout << "getChangedTime for ID=" << id << ":" << endl;
cout << "** check getChangedTime for ID=" << id << ":" << endl;
IOController_i::ShortIOInfo inf = ui.getChangedTime(id,conf->getLocalNode());
......@@ -33,6 +51,7 @@ int main( int argc, const char **argv )
cout << "id=" << id
<< " value=" << inf.value
<< " last changed: " << string(t_str) << endl;
}
catch( Exception& ex )
{
......
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