Commit 3e5b5a27 authored by Pavel Vainerman's avatar Pavel Vainerman

Рефакторинг uniset-admin:

1. Убрал лишние неиспользуемые функции 2. Добавил возможность обращения к удалённым датчикам 3. Новый формат задания списка датчиков в командной строке: id1@node@=val1,id2@node2=val2,id3=val3,id4=val4,...
parent 62c6a8a7
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
Name: libuniset Name: libuniset
Version: 0.99 Version: 0.99
Release: eter11 Release: eter13
Summary: UniSet - library for building distributed industrial control systems Summary: UniSet - library for building distributed industrial control systems
License: GPL License: GPL
Group: Development/C++ Group: Development/C++
...@@ -184,6 +184,12 @@ rm -f %buildroot%_libdir/*.la ...@@ -184,6 +184,12 @@ rm -f %buildroot%_libdir/*.la
%exclude %_pkgconfigdir/libUniSet.pc %exclude %_pkgconfigdir/libUniSet.pc
%changelog %changelog
* Thu Nov 11 2010 Pavel Vainerman <pv@altlinux.ru> 0.99-eter13
- uniset-admin refactor. ( [get|set]Value, call remote sensors)
* Mon Nov 08 2010 Pavel Vainerman <pv@altlinux.ru> 0.99-eter12
- fixed minor bug in uniset-codegen
* Mon Oct 18 2010 Pavel Vainerman <pv@altlinux.ru> 0.99-eter9 * Mon Oct 18 2010 Pavel Vainerman <pv@altlinux.ru> 0.99-eter9
- new build - new build
......
...@@ -45,6 +45,9 @@ inline void msleep( unsigned int m ) { usleep(m*1000); } ...@@ -45,6 +45,9 @@ inline void msleep( unsigned int m ) { usleep(m*1000); }
/*! Определения базовых типов библиотеки UniSet */ /*! Определения базовых типов библиотеки UniSet */
namespace UniSetTypes namespace UniSetTypes
{ {
class Configuration;
extern Configuration* conf;
typedef std::list<std::string> ListObjectName; /*!< Список объектов типа ObjectName */ typedef std::list<std::string> ListObjectName; /*!< Список объектов типа ObjectName */
typedef ObjectId SysId; typedef ObjectId SysId;
...@@ -249,6 +252,21 @@ namespace UniSetTypes ...@@ -249,6 +252,21 @@ namespace UniSetTypes
bool file_exist( const std::string filename ); bool file_exist( const std::string filename );
IDList explode( const std::string str, char sep=',' ); IDList explode( const std::string str, char sep=',' );
std::list<std::string> explode_str( const std::string str, char sep=',' );
struct ParamSInfo
{
IOController_i::SensorInfo si;
long val;
std::string fname; // fullname id@node or id
};
// Функция разбора строки вида: id1@node1=val1,id2@node2=val2,...
// Если '=' не указано, возвращается val=0
// Если @node не указано, возвращается node=DefaultObjectId
std::list<ParamSInfo> getSInfoList( std::string s, Configuration* conf=UniSetTypes::conf);
bool is_digit( const std::string s );
} }
#define atoi atoi##_Do_not_use_atoi_function_directly_Use_getIntProp90,_getArgInt_or_uni_atoi #define atoi atoi##_Do_not_use_atoi_function_directly_Use_getIntProp90,_getArgInt_or_uni_atoi
......
...@@ -179,7 +179,6 @@ using namespace UniSetTypes; ...@@ -179,7 +179,6 @@ using namespace UniSetTypes;
return result; return result;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
UniSetTypes::IDList UniSetTypes::explode( const string str, char sep ) UniSetTypes::IDList UniSetTypes::explode( const string str, char sep )
{ {
UniSetTypes::IDList l; UniSetTypes::IDList l;
...@@ -200,7 +199,105 @@ using namespace UniSetTypes; ...@@ -200,7 +199,105 @@ using namespace UniSetTypes;
return l; return l;
} }
// -------------------------------------------------------------------------
std::list<std::string> UniSetTypes::explode_str( const string str, char sep )
{
std::list<std::string> l;
string::size_type prev = 0;
string::size_type pos = 0;
do
{
pos = str.find(sep,prev);
string s(str.substr(prev,pos-prev));
if( !s.empty() )
{
l.push_back(s);
prev=pos+1;
}
}
while( pos!=string::npos );
return l;
}
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
bool UniSetTypes::is_digit( const std::string s )
{
for( std::string::const_iterator it=s.begin(); it!=s.end(); it++ )
{
if( !isdigit(*it) )
return false;
}
return true;
//return (std::count_if(s.begin(),s.end(),std::isdigit) == s.size()) ? true : false;
}
// --------------------------------------------------------------------------------------
std::list<UniSetTypes::ParamSInfo> UniSetTypes::getSInfoList( string str, Configuration* conf )
{
std::list<UniSetTypes::ParamSInfo> res;
std::list<std::string> l = UniSetTypes::explode_str(str,',');
for( std::list<std::string>::iterator it=l.begin(); it!=l.end(); it++ )
{
UniSetTypes::ParamSInfo item;
std::list<std::string> p = UniSetTypes::explode_str((*it),'=');
std::string s = "";
if( p.size() == 1 )
{
s = *(p.begin());
item.val = 0;
}
else if( p.size() == 2 )
{
s = *(p.begin());
item.val = uni_atoi(*(++p.begin()));
}
else
{
cerr << "WARNING: parse error for '" << (*it) << "'. IGNORE..." << endl;
continue;
}
item.fname = s;
std::list<std::string> t = UniSetTypes::explode_str(s,'@');
if( t.size() == 1 )
{
std::string s_id = *(t.begin());
if( is_digit(s_id) )
item.si.id = uni_atoi(s_id);
else
item.si.id = conf->getSensorID(s_id);
item.si.node = DefaultObjectId;
}
else if( t.size() == 2 )
{
std::string s_id = *(t.begin());
std::string s_node = *(++t.begin());
if( is_digit(s_id) )
item.si.id = uni_atoi(s_id);
else
item.si.id = conf->getSensorID(s_id);
if( is_digit(s_node.c_str()) )
item.si.node = uni_atoi(s_node);
else
item.si.node= conf->getNodeID(s_node);
}
else
{
cerr << "WARNING: parse error for '" << s << "'. IGNORE..." << endl;
continue;
}
res.push_back(item);
}
return res;
}
// --------------------------------------------------------------------------------------
UniversalIO::IOTypes UniSetTypes::getIOType( const std::string stype ) UniversalIO::IOTypes UniSetTypes::getIOType( const std::string stype )
{ {
if ( stype == "DI" || stype == "di" ) if ( stype == "DI" || stype == "di" )
......
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