Commit 5b3f66b1 authored by Pavel Vainerman's avatar Pavel Vainerman

Исправил ошибку с обработкой списка идентификаторов объектов в

uniset2-admin --oinfo. (функция не работала если задавать имена, а не числа).
parent ccb609bc
...@@ -843,22 +843,22 @@ int configure( const string& arg, UInterface& ui ) ...@@ -843,22 +843,22 @@ int configure( const string& arg, UInterface& ui )
int oinfo( const string& args, UInterface& ui ) int oinfo( const string& args, UInterface& ui )
{ {
auto conf = uniset_conf(); auto conf = uniset_conf();
auto sl = UniSetTypes::getSInfoList( args, conf ); auto sl = UniSetTypes::getObjectsList( args, conf );
for( auto && it : sl ) for( auto && it : sl )
{ {
if( it.si.node == DefaultObjectId ) if( it.node == DefaultObjectId )
it.si.node = conf->getLocalNode(); it.node = conf->getLocalNode();
try try
{ {
UniSetTypes::ObjectVar o = ui.resolve(it.si.id, it.si.node); UniSetTypes::ObjectVar o = ui.resolve(it.id, it.node);
UniSetObject_i_var obj = UniSetObject_i::_narrow(o); UniSetObject_i_var obj = UniSetObject_i::_narrow(o);
if(CORBA::is_nil(obj)) if(CORBA::is_nil(obj))
{ {
if( !quiet ) if( !quiet )
cout << "(oinfo): объект '" << it.si.id << "' недоступен" << endl; cout << "(oinfo): объект '" << it.id << "' недоступен" << endl;
} }
else else
{ {
...@@ -868,7 +868,7 @@ int oinfo( const string& args, UInterface& ui ) ...@@ -868,7 +868,7 @@ int oinfo( const string& args, UInterface& ui )
} }
catch( const Exception& ex ) catch( const Exception& ex )
{ {
cout << "ID='" << it.si.id << "' ERROR: " << ex << endl; cout << "ID='" << it.id << "' ERROR: " << ex << endl;
} }
cout << endl << endl; cout << endl << endl;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
Name: libuniset2 Name: libuniset2
Version: 2.1 Version: 2.1
Release: alt7.6 Release: alt7.7
Summary: UniSet - library for building distributed industrial control systems Summary: UniSet - library for building distributed industrial control systems
...@@ -456,6 +456,10 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname ...@@ -456,6 +456,10 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
# .. # ..
%changelog %changelog
* Tue Jun 16 2015 Pavel Vainerman <pv@altlinux.ru> 2.1-alt7.7
- fixed minor bug in uniset2-admin --oinfo (uniset2-vmonitor)
- vmonitor: add helper functions
* Wed Jun 10 2015 Pavel Vainerman <pv@altlinux.ru> 2.1-alt7.6 * Wed Jun 10 2015 Pavel Vainerman <pv@altlinux.ru> 2.1-alt7.6
- fixed libUniSet2Extensions.pc - fixed libUniSet2Extensions.pc
......
...@@ -192,6 +192,11 @@ namespace UniSetTypes ...@@ -192,6 +192,11 @@ namespace UniSetTypes
Если @node не указано, возвращается node=DefaultObjectId */ Если @node не указано, возвращается node=DefaultObjectId */
std::list<ParamSInfo> getSInfoList( const std::string& s, std::shared_ptr<UniSetTypes::Configuration> conf = nullptr ); std::list<ParamSInfo> getSInfoList( const std::string& s, std::shared_ptr<UniSetTypes::Configuration> conf = nullptr );
/*! Функция разбора строки вида: id1@node1,id2@node2,...
Если @node не указано, возвращается node=DefaultObjectId */
std::list<UniSetTypes::ConsumerInfo> getObjectsList( const std::string& s, std::shared_ptr<UniSetTypes::Configuration> conf = nullptr );
/*! проверка является текст в строке - числом..*/ /*! проверка является текст в строке - числом..*/
bool is_digit( const std::string& s ); bool is_digit( const std::string& s );
......
...@@ -325,7 +325,7 @@ std::list<UniSetTypes::ParamSInfo> UniSetTypes::getSInfoList( const string& str, ...@@ -325,7 +325,7 @@ std::list<UniSetTypes::ParamSInfo> UniSetTypes::getSInfoList( const string& str,
else else
item.si.id = conf->getSensorID(s_id); item.si.id = conf->getSensorID(s_id);
if( is_digit(s_node.c_str()) ) if( is_digit(s_node) )
item.si.node = uni_atoi(s_node); item.si.node = uni_atoi(s_node);
else else
item.si.node = conf->getNodeID(s_node); item.si.node = conf->getNodeID(s_node);
...@@ -342,7 +342,67 @@ std::list<UniSetTypes::ParamSInfo> UniSetTypes::getSInfoList( const string& str, ...@@ -342,7 +342,67 @@ std::list<UniSetTypes::ParamSInfo> UniSetTypes::getSInfoList( const string& str,
return std::move(res); return std::move(res);
} }
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
std::list<UniSetTypes::ConsumerInfo> UniSetTypes::getObjectsList( const string& str, std::shared_ptr<Configuration> conf )
{
if( conf == nullptr )
conf = uniset_conf();
std::list<UniSetTypes::ConsumerInfo> res;
auto lst = UniSetTypes::explode_str(str, ',');
for( const auto& it : lst )
{
UniSetTypes::ConsumerInfo item;
auto t = UniSetTypes::explode_str(it, '@');
if( t.size() == 1 )
{
std::string s_id(*(t.begin()));
if( is_digit(s_id) )
item.id = uni_atoi(s_id);
else
{
item.id = conf->getObjectID(s_id);
if( item.id == DefaultObjectId )
item.id = conf->getControllerID(s_id);
}
item.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.id = uni_atoi(s_id);
else
{
item.id = conf->getObjectID(s_id);
if( item.id == DefaultObjectId )
item.id = conf->getControllerID(s_id);
}
if( is_digit(s_node) )
item.node = uni_atoi(s_node);
else
item.node = conf->getNodeID(s_node);
}
else
{
cerr << "WARNING: parse error for '" << it << "'. IGNORE..." << endl;
continue;
}
res.push_back(item);
}
return std::move(res);
}
// --------------------------------------------------------------------------------------
UniversalIO::IOType UniSetTypes::getIOType( const std::string& stype ) UniversalIO::IOType UniSetTypes::getIOType( const std::string& stype )
{ {
if ( stype == "DI" || stype == "di" ) if ( stype == "DI" || stype == "di" )
......
...@@ -106,9 +106,53 @@ TEST_CASE("UniSetTypes: explode", "[utypes][explode]" ) ...@@ -106,9 +106,53 @@ TEST_CASE("UniSetTypes: explode", "[utypes][explode]" )
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
TEST_CASE("UniSetTypes: getSInfoList", "[utypes][getsinfo]" ) TEST_CASE("UniSetTypes: getSInfoList", "[utypes][getsinfo]" )
{ {
const std::string str1("id1@node1,id2,234,234@node5,45@245"); const std::string str1("Input4_S@node2,Input1_S,5,5@node3,6@1001");
auto t1 = UniSetTypes::getSInfoList(str1); auto t1 = UniSetTypes::getSInfoList(str1);
CHECK( t1.size() == 5 ); CHECK( t1.size() == 5 );
vector<UniSetTypes::ParamSInfo> v(t1.begin(),t1.end());
REQUIRE( v[0].si.id == 141 );
REQUIRE( v[0].si.node == 1001 );
REQUIRE( v[1].si.id == 1 );
REQUIRE( v[1].si.node == DefaultObjectId );
REQUIRE( v[2].si.id == 5 );
REQUIRE( v[2].si.node == DefaultObjectId );
REQUIRE( v[3].si.id == 5 );
REQUIRE( v[3].si.node == 1002 );
REQUIRE( v[4].si.id == 6 );
REQUIRE( v[4].si.node == 1001 );
}
// -----------------------------------------------------------------------------
TEST_CASE("UniSetTypes: getObjectsList", "[utypes][getolist]" )
{
const std::string str1("TestProc@node2,TestProc,102,102@node3,103@1001");
auto t1 = UniSetTypes::getObjectsList(str1);
CHECK( t1.size() == 5 );
vector<UniSetTypes::ConsumerInfo> v(t1.begin(),t1.end());
REQUIRE( v[0].id == 100 );
REQUIRE( v[0].node == 1001 );
REQUIRE( v[1].id == 100 );
REQUIRE( v[1].node == DefaultObjectId );
REQUIRE( v[2].id == 102 );
REQUIRE( v[2].node == DefaultObjectId );
REQUIRE( v[3].id == 102 );
REQUIRE( v[3].node == 1002 );
REQUIRE( v[4].id == 103 );
REQUIRE( v[4].node == 1001 );
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -56,14 +56,17 @@ ...@@ -56,14 +56,17 @@
--> -->
<nodes port="2809"> <nodes port="2809">
<item id="1000" name="localhost" alias="" textname="Локальный узел" ip="127.0.0.1"/> <item id="1000" name="localhost" alias="" textname="Локальный узел" ip="127.0.0.1"/>
<item id="1001" name="node2" alias="" textname="Локальный узел" ip="127.0.0.1"/> <item id="1001" name="node2" alias="" textname="Локальный узел N2" ip="127.0.0.1"/>
<item id="1002" name="node3" alias="" textname="Локальный узел N3" ip="127.0.0.1"/>
</nodes> </nodes>
<!-- ************************ Датчики ********************** --> <!-- ************************ Датчики ********************** -->
<sensors name="Sensors"> <sensors name="Sensors">
<item id="1" name="Input1_S" textname="Команда 1" node="" iotype="DI" priority="Medium" default="1" /> <item id="1" name="Input1_S" textname="Команда 1" node="" iotype="DI" priority="Medium" default="1" />
<item id="4" name="Input2_S" textname="Команда 2" node="" iotype="DI" priority="Medium" /> <item id="4" name="Input2_S" textname="Команда 2" node="" iotype="DI" priority="Medium" />
<item id="5" name="Input5_S" textname="Команда 2" node="" iotype="DI" priority="Medium" />
<item id="140" name="Input3_S" textname="Команда 3" node="" iotype="DI" priority="Medium"/> <item id="140" name="Input3_S" textname="Команда 3" node="" iotype="DI" priority="Medium"/>
<item id="141" name="Input4_S" textname="Команда 4" node="" iotype="DI" priority="Medium"/>
</sensors> </sensors>
<thresholds name="thresholds"> <thresholds name="thresholds">
...@@ -81,6 +84,9 @@ ...@@ -81,6 +84,9 @@
<!-- ******************* Идентификаторы объектов ***************** --> <!-- ******************* Идентификаторы объектов ***************** -->
<objects name="UniObjects"> <objects name="UniObjects">
<item id="100" name="TestProc"/> <item id="100" name="TestProc"/>
<item id="101" name="TestProc2"/>
<item id="102" name="TestProc3"/>
<item id="103" name="TestProc4"/>
</objects> </objects>
</ObjectsMap> </ObjectsMap>
......
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