Commit 43a9e230 authored by Pavel Vainerman's avatar Pavel Vainerman Committed by Pavel Vainerman

[admin]: added 'sinfo' (get sensor info)

parent 392527bd
......@@ -51,6 +51,7 @@ static struct option longopts[] =
{ "getCalibrate", required_argument, 0, 'y' },
{ "getTimeChange", required_argument, 0, 't' },
{ "oinfo", required_argument, 0, 'p' },
{ "sinfo", required_argument, 0, 'j' },
{ "apiRequest", required_argument, 0, 'a' },
{ "verbose", no_argument, 0, 'v' },
{ "quiet", no_argument, 0, 'q' },
......@@ -79,15 +80,16 @@ int getTimeChange( const string& args, UInterface& ui );
int getState( const string& args, UInterface& ui );
int getCalibrate( const string& args, UInterface& ui );
int oinfo(const string& args, UInterface& ui, const string& userparam );
int sinfo(const string& args, UInterface& ui);
int apiRequest( const string& args, UInterface& ui, const string& query );
void sendText( const string& args, UInterface& ui, const string& txt, int mtype );
int freezeValue( const string& args, bool set, UInterface& ui );
// --------------------------------------------------------------------------
static void print_help(int width, const string& cmd, const string& help, const string& tab = " " )
static void print_help(int width, const string& cmd, const string& help, const string& tab = " ", const string& sep = " - " )
{
uniset::ios_fmt_restorer ifs(cout);
cout.setf(ios::left, ios::adjustfield);
cout << tab << setw(width) << cmd << " - " << help;
cout << tab << setw(width) << cmd << sep << help;
}
// --------------------------------------------------------------------------
static void short_usage()
......@@ -99,7 +101,7 @@ static void short_usage()
static void usage()
{
cout << "\nUsage: \n\tuniset-admin [--confile configure.xml] --command [arg]\n";
cout << endl;
cout << endl;
cout << "commands list:\n";
cout << "-----------------------------------------\n";
print_help(24, "-с|--confile file.xml ", "Используемый конфигурационный файл\n");
......@@ -116,6 +118,7 @@ static void usage()
print_help(36, "-l|--logrotate [FullObjName] ", "Посылка SystemMessage::LogRotate всем объектам (процессам) или заданному по имени (FullObjName).\n");
print_help(36, "-p|--oinfo id1@node1,id2@node2,id3,... [userparam]", "Получить информацию об объектах (SimpleInfo). \n");
print_help(36, "", "userparam - необязательный параметр передаваемый в getInfo() каждому объекту\n");
print_help(36, "-j|--sinfo id1@node1,id2@node2,id3,...", "Получить информацию о датчиках.\n");
cout << endl;
print_help(36, "-a|--apiRequest id1@node1,id2@node2,id3,... query", "Вызов REST API для каждого объекта\n");
print_help(36, "", "query - Запрос вида: /api/VERSION/query[?param1&param2...]\n");
......@@ -162,7 +165,7 @@ int main(int argc, char** argv)
while(1)
{
opt = getopt_long(argc, argv, "hk:beosfur:l:i::x:g:w:y:p:vqz:a:m:n:z:", longopts, &optindex);
opt = getopt_long(argc, argv, "hk:beosfur:l:i::x:g:w:y:p:vqz:a:m:n:z:j:", longopts, &optindex);
if( opt == -1 )
break;
......@@ -283,6 +286,15 @@ int main(int argc, char** argv)
}
break;
case 'j': //--sinfo
{
auto conf = uniset_init(argc, argv, conffile);
UInterface ui(conf);
ui.initBackId(uniset::AdminID);
return sinfo(optarg, ui);
}
break;
case 'a': //--apiRequest
{
// смотрим второй параметр
......@@ -1190,6 +1202,67 @@ int oinfo(const string& args, UInterface& ui, const string& userparam )
return 0;
}
// --------------------------------------------------------------------------------------
int sinfo(const string& args, UInterface& ui )
{
int err = 0;
auto conf = uniset_conf();
auto sl = uniset::getSInfoList(args, conf);
for( auto&& it : sl )
{
try
{
// проверка есть ли такой датчик, т.к. тут будет выкинуто исключение
// если его нет
UniversalIO::IOType t = conf->getIOType(it.si.id);
if( it.si.node == DefaultObjectId )
it.si.node = conf->getLocalNode();
IOController_i::SensorIOInfo_var sinf = ui.getSensorIOInfo(it.si);
#if 0
UniversalIO::IOType type; /*!< тип */
long priority; /*!< приоритет уведомления */
long default_val; /*!< значение по умолчанию */
CalibrateInfo ci; /*!< калибровочные параметры */
#endif
print_help(10, "id", std::to_string(it.si.id) + "\n", " ", " : ");
print_help(10, "node", std::to_string(it.si.node) + "\n", " ", " : ");
print_help(10, "value", std::to_string(sinf->value) + "\n", " ", " : ");
print_help(10, "real_value", std::to_string(sinf->real_value) + "\n", " ", " : ");
print_help(10, "frozen", std::to_string(sinf->frozen) + "\n", " ", " : ");
print_help(10, "blocked", std::to_string(sinf->blocked) + "\n", " ", " : ");
print_help(10, "undefined", std::to_string(sinf->undefined) + "\n", " ", " : ");
print_help(10, "dbignore", std::to_string(sinf->dbignore) + "\n", " ", " : ");
if( sinf->supplier == uniset::AdminID )
print_help(10, "supplier", "admin\n", " ", " : ");
else
print_help(10, "supplier", ORepHelpers::getShortName(conf->oind->getMapName(sinf->supplier)) + "\n", " ", " : ");
ostringstream ts;
ts << dateToString(sinf->tv_sec) << " " << timeToString(sinf->tv_sec) << "." << sinf->tv_nsec << "\n";
print_help(10, "changed", ts.str(), " ", " : ");
}
catch( const uniset::Exception& ex )
{
if( !quiet )
cerr << "(sinfo): " << ex << endl;;
err = 1;
}
catch( const std::exception& ex )
{
if( !quiet )
cerr << "(sinfo): std::exception: " << ex.what() << endl;
err = 1;
}
}
return err;
}
// --------------------------------------------------------------------------------------
int apiRequest( const string& args, UInterface& ui, const string& query )
{
auto conf = uniset_conf();
......
......@@ -21,6 +21,7 @@ ln -s -f admin.sh apiRequest
ln -s -f admin.sh sendText
ln -s -f admin.sh freeze
ln -s -f admin.sh unfreeze
ln -s -f admin.sh sinfo
ln -s -f ../../Utilities/scripts/uniset2-start.sh
ln -s -f ../../Utilities/scripts/uniset2-stop.sh stop.sh
......
......@@ -274,3 +274,51 @@ TEST_CASE("UInterface::freezeValue", "[UInterface][freezeValue]")
REQUIRE_NOTHROW( ui->setValue(aid, 200) );
REQUIRE( ui->getValue(aid) == 200 );
}
// -----------------------------------------------------------------------------
TEST_CASE("UInterface::getSensorIOInfo", "[UInterface][getSensorIOInfo]")
{
init();
auto conf = uniset_conf();
IOController_i::SensorInfo si;
si.id = aid;
si.node = conf->getLocalNode();
REQUIRE_NOTHROW( ui->setValue(si, 200, testOID) );
REQUIRE( ui->getValue(aid) == 200 );
REQUIRE_NOTHROW( ui->getSensorIOInfo(si) );
auto inf = ui->getSensorIOInfo(si);
REQUIRE( inf->supplier == testOID );
REQUIRE( inf->value == 200 );
REQUIRE( inf->real_value == 200 );
REQUIRE( inf->blocked == false );
REQUIRE( inf->frozen == false );
REQUIRE( inf->undefined == false );
REQUIRE( inf->tv_sec > 0 );
REQUIRE( inf->dbignore == false );
// freeze/unfreeze
REQUIRE_NOTHROW( ui->freezeValue(si, true, 10, testOID) );
inf = ui->getSensorIOInfo(si);
REQUIRE( inf->frozen == true );
REQUIRE( inf->supplier == testOID );
REQUIRE_NOTHROW( ui->freezeValue(si, false, 10, testOID) );
inf = ui->getSensorIOInfo(si);
REQUIRE( inf->frozen == false );
REQUIRE( inf->supplier == testOID );
// undef
REQUIRE_NOTHROW( ui->setUndefinedState( si, true, testOID ));
inf = ui->getSensorIOInfo(si);
REQUIRE( inf->undefined == true );
REQUIRE( inf->supplier == testOID );
REQUIRE_NOTHROW( ui->setUndefinedState( si, false, testOID ));
inf = ui->getSensorIOInfo(si);
REQUIRE( inf->undefined == false );
REQUIRE( inf->supplier == testOID );
}
......@@ -79,6 +79,9 @@ namespace uniset
//! Получение состояния для списка указанных датчиков
IOController_i::SensorInfoSeq_var getSensorSeq( const uniset::IDList& lst );
//! Получение состояния информации о датчике
IOController_i::SensorIOInfo_var getSensorIOInfo( const IOController_i::SensorInfo& si );
/*! Изменения состояния списка входов/выходов
\return Возвращает список не найденных идентификаторов */
uniset::IDSeq_var setOutputSeq( const IOController_i::OutSeq& lst, uniset::ObjectId sup_id );
......
......@@ -2236,6 +2236,82 @@ namespace uniset
}
// --------------------------------------------------------------------------------------------
IOController_i::SensorIOInfo_var UInterface::getSensorIOInfo( const IOController_i::SensorInfo& si )
{
if ( si.id == uniset::DefaultObjectId )
throw uniset::ORepFailed("UI(getSensorIOInfo): error node=uniset::DefaultObjectId");
if ( si.node == uniset::DefaultObjectId )
throw uniset::ORepFailed("UI(getSensorIOInfo): попытка обратиться к объекту с id=uniset::DefaultObjectId");
try
{
CORBA::Object_var oref;
try
{
oref = rcache.resolve(si.id, si.node);
}
catch( const uniset::NameNotFound& ) {}
for( size_t 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->getSensorIOInfo(si.id);
}
catch( const CORBA::TRANSIENT& ) {}
catch( const CORBA::OBJECT_NOT_EXIST& ) {}
catch( const CORBA::SystemException& ex ) {}
msleep(uconf->getRepeatTimeout());
oref = CORBA::Object::_nil();
}
}
catch( const uniset::TimeOut& ) {}
catch(const IOController_i::NameNotFound& ex)
{
rcache.erase(si.id, si.node);
throw uniset::NameNotFound("UI(getSensorIOInfo): " + string(ex.err));
}
catch(const IOController_i::IOBadParam& ex)
{
rcache.erase(si.id, si.node);
throw uniset::IOBadParam("UI(getSensorIOInfo): " + string(ex.err));
}
catch(const uniset::ORepFailed& )
{
rcache.erase(si.id, si.node);
// не смогли получить ссылку на объект
throw uniset::IOBadParam(set_err("UI(getSensorIOInfo): resolve failed ", si.id, si.node));
}
catch(const CORBA::NO_IMPLEMENT& )
{
rcache.erase(si.id, si.node);
throw uniset::IOBadParam(set_err("UI(getSensorIOInfo): method no implement", si.id, si.node));
}
catch( const CORBA::OBJECT_NOT_EXIST& )
{
rcache.erase(si.id, si.node);
throw uniset::IOBadParam(set_err("UI(getSensorIOInfo): object not exist", si.id, si.node));
}
catch( const CORBA::COMM_FAILURE& ex )
{
// ошибка системы коммуникации
}
catch( const CORBA::SystemException& ex )
{
// ошибка системы коммуникации
}
rcache.erase(si.id, si.node);
throw uniset::TimeOut(set_err("UI(getSensorIOInfo): Timeout", si.id, si.node));
}
// --------------------------------------------------------------------------------------------
uniset::IDSeq_var UInterface::setOutputSeq( const IOController_i::OutSeq& lst, uniset::ObjectId sup_id )
{
if( lst.length() == 0 )
......
......@@ -1083,6 +1083,16 @@ void IOController::getSensorInfo( Poco::JSON::Array::Ptr& jdata, std::shared_ptr
jsens->set("default_val", s->default_val);
jsens->set("dbignore", s->dbignore);
jsens->set("nchanges", s->nchanges);
jsens->set("undefined", s->undefined);
jsens->set("frozen", s->frozen);
jsens->set("blocked", s->blocked);
if( s->d_si.id != DefaultObjectId )
{
jsens->set("depend_sensor", ORepHelpers::getShortName(uniset_conf()->oind->getMapName(s->d_si.id)));
jsens->set("depend_sensor_id", s->d_si.id);
jsens->set("depend_value", s->d_value);
jsens->set("depend_off_value", s->d_off_value);
}
Poco::JSON::Object::Ptr calibr = uniset::json::make_child(jsens, "calibration");
calibr->set("cmin", s->ci.minCal);
......
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