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

(RRDStorage): предварительная версия, реализовал создание БД и

обновлений по таймеру.
parent de29e87d
#SUBDIRS=. tests
bin_PROGRAMS = UObject
UObject_SOURCES = UObject_SK.cc UObject.cc
bin_SCRIPTS = @PACKAGE@-codegen
UObject_SK.cc: UObject.src.xml
@UNISET_CODEGEN@ --ask -n UObject --topdir $(top_builddir)/ --no-main UObject.src.xml
xsldir = $(datadir)/uniset/xslt
xsl_DATA = *.xsl skel*
clean-local:
rm -rf *_SK.cc *_SK.h
all-local:
chmod 'a+x' @PACKAGE@-codegen
\ No newline at end of file
all-local: UObject_SK.cc UObject_SK.h
......@@ -9,8 +9,9 @@ test2_LDADD = $(top_builddir)/lib/libUniSet.la
test2_CXXFLAGS = -I$(top_builddir)/include
test2_SOURCES = TestGenAlone_SK.cc TestGenAlone.cc TestGenAlone-main.cc
GENERATED=TestGen_SK.h TestGen_SK.cc TestGen-main.cc
GENERATED=TestGen_SK.h TestGen_SK.cc TestGen-main.cc
GENERATED2=TestGenAlone_SK.h TestGenAlone_SK.cc TestGenAlone-main.cc
GENUOBJ=UObject_SK.cc UObject_SK.h
$(GENERATED): ../@PACKAGE@-codegen testgen.src.xml ../*.xsl
../@PACKAGE@-codegen -l $(top_builddir)/Utilities/codegen --local-include -n TestGen testgen.src.xml
......@@ -18,9 +19,12 @@ $(GENERATED): ../@PACKAGE@-codegen testgen.src.xml ../*.xsl
$(GENERATED2): ../@PACKAGE@-codegen testgen-alone.src.xml ../*.xsl
../@PACKAGE@-codegen -l $(top_builddir)/Utilities/codegen --local-include --alone -n TestGenAlone testgen-alone.src.xml
$(GENUOBJ): ../@PACKAGE@-codegen testgen.src.xml ../*.xsl
../@PACKAGE@-codegen -l $(top_builddir)/Utilities/codegen -n UObject --no-main uobject.src.xml
clean-local:
rm -rf $(GENERATED) $(GENERATED2)
rm -rf $(GENERATED) $(GENERATED2) $(GENUOBJ)
all-local: $(GENERATED) $(GENERATED2)
all-local: $(GENERATED) $(GENERATED2) $(GENUOBJ)
<?xml version="1.0" encoding="koi8-r"?>
<!--
name - название класса
msgcount - сколько сообщений обрабатывается за один раз
sleep_msec - пауза между итерациями в работе процесса
type
====
in - входные регистры (только для чтения)
out - выходные регистры (запись)
io - запись и чтение
-->
<Test>
<settings>
<set name="class-name" val="UObject"/>
<set name="msg-count" val="20"/>
<set name="sleep-msec" val="150"/>
<set name="arg-prefix" val=""/>
</settings>
<variables>
<!-- type = [int,str,bool,float]
int: max,min,no_range_exception=[0,1]
str:
float: max,min,no_range_exception=[0,1]
bool:
min - минимальное значение (может быть не задано)
max - максимальное значение (может быть не задано)
default - значение по умолчанию (может быть не задано)
no_range_exception=1 - при выходе за границы min или max только писать unideb[WARN].
-->
</variables>
<smap>
</smap>
<msgmap>
</msgmap>
</Test>
......@@ -121,6 +121,11 @@
<UNetExchange name="UNetExchange"/>
<HeartBeatTime time_msec="5000"/>
<TestGen input1_s="Input1_S" input2_s="DumpSensor1_S" name="TestGen" output1_c="DO_C"/>
<RRDStorage1 name="RRDStorage1">
<rrd filename="rrdtest.rrd" filter_field="rrd" filter_value="1" step="5" ds_field="rrd1_ds">
<item rra="RRA:AVERAGE:0.5:1:4320"/>
</rrd>
</RRDStorage1>
</settings>
<ObjectsMap idfromfile="1">
<!--
......@@ -193,7 +198,7 @@
<item id="51" iotype="DI" mbaddr="0x01" mbfunc="0x03" mbreg="0x01" ntit="1" mbtype="rtu" name="Input51_S" priority="Medium" rs="5" textname="Команда 2"/>
<item id="52" iotype="DI" mbaddr="0x01" mbfunc="0x06" mbreg="0x02" nbit="1" mbtype="rtu" name="Input52_S" priority="Medium" rs="5" textname="Команда 2"/>
<item id="53" iotype="DI" mbaddr="0x01" mbfunc="0x03" mbreg="0x01" nbit="2" mbtype="rtu" name="Input53_S" priority="Medium" rs="5" textname="Команда 2"/>
<item id="54" iotype="AI" name="AI54_S" textname="AI sensor 54" rrd="1" rrd1_ds="GAUGE:120:U:U"/>
</sensors>
<thresholds name="thresholds">
<sensor iotype="AI" name="AI_AS">
......@@ -230,6 +235,7 @@
<item id="6008" name="UNetExchange"/>
<item id="6009" name="MBMaster2"/>
<item id="6010" name="MBMultiMaster1"/>
<item id="6011" name="RRDStorage1"/>
</objects>
</ObjectsMap>
<messages idfromfile="1" name="messages">
......
......@@ -83,6 +83,25 @@ fi
AM_CONDITIONAL(DISABLE_MYSQL, test ${buildmysql} = false)
#check rrd support
AC_MSG_CHECKING([rrd support])
buildrrd=true
AC_ARG_ENABLE(rrd, AC_HELP_STRING([--disable-rrd], [disable RRD support]),
[ if test $enableval = yes; then buildrrd=true; else buildrrd=false; fi],[ buildrrd=true; ])
if test ${buildrrd} = true; then
AC_MSG_RESULT([enabled])
PKG_CHECK_MODULES(RRD,librrd)
AC_SUBST(RRD_LIBS)
AC_SUBST(RRD_CFLAGS)
else
AC_MSG_RESULT([disabled])
fi
AM_CONDITIONAL(DISABLE_RRD, test ${buildrrd} = false)
#check build extensions
ext=true
AC_MSG_CHECKING([Extensions])
......@@ -243,6 +262,8 @@ AC_CONFIG_FILES([Makefile
extensions/SharedMemory/Makefile
extensions/SharedMemory/libUniSetSharedMemory.pc
extensions/SharedMemoryPlus/Makefile
extensions/RRDStorage/Makefile
extensions/RRDStorage/libUniSetRRDStorage.pc
extensions/tests/Makefile
python/lib/Makefile
python/lib/pyUniSet/Makefile
......
......@@ -83,7 +83,7 @@
или \b bufferLastRemove="1", то терятся будут сообщения добавляемые в конец.
\section sec_DBS_Tables Таблицы SQLite
К основным таблицам относятся следующие:
К основным таблицам относятся следующие (описание в формате MySQL!):
\code
DROP TABLE IF EXISTS `main_history`;
CREATE TABLE `main_history` (
......
bin_PROGRAMS = @PACKAGE@-rrdstorage
RRD_VER=@LIBVER@
lib_LTLIBRARIES = libUniSetRRDStorage.la
libUniSetRRDStorage_la_LDFLAGS = -version-info $(RRD_VER)
libUniSetRRDStorage_la_LIBADD = $(top_builddir)/lib/libUniSet.la \
$(top_builddir)/extensions/SharedMemory/libUniSetSharedMemory.la \
$(top_builddir)/extensions/lib/libUniSetExtensions.la \
$(SIGC_LIBS) $(RRD_LIBS)
libUniSetRRDStorage_la_CXXFLAGS = -I$(top_builddir)/extensions/include \
-I$(top_builddir)/extensions/SharedMemory \
$(SIGC_CFLAGS) $(RRD_CFLAGS)
libUniSetRRDStorage_la_SOURCES = RRDStorage.cc
@PACKAGE@_rrdstorage_SOURCES = main.cc
@PACKAGE@_rrdstorage_LDADD = libUniSetRRDStorage.la $(top_builddir)/lib/libUniSet.la \
$(top_builddir)/extensions/SharedMemory/libUniSetSharedMemory.la \
$(top_builddir)/extensions/lib/libUniSetExtensions.la \
$(SIGC_LIBS) $(RRD_LIBS)
@PACKAGE@_rrdstorage_CXXFLAGS = -I$(top_builddir)/extensions/include \
-I$(top_builddir)/extensions/SharedMemory \
$(SIGC_CFLAGS) $(RRD_CFLAGS)
# install
devel_include_HEADERS = *.h
devel_includedir = $(pkgincludedir)/extensions
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libUniSetRRDStorage.pc
all-local:
ln -sf ../RRDStorage/$(devel_include_HEADERS) ../include
// -----------------------------------------------------------------------------
extern "C" {
#include <rrd.h>
}
#include <cmath>
#include <sstream>
#include "Exceptions.h"
#include "extensions/Extensions.h"
#include "RRDStorage.h"
// -----------------------------------------------------------------------------
using namespace std;
using namespace UniSetTypes;
using namespace UniSetExtensions;
// -----------------------------------------------------------------------------
RRDStorage::RRDStorage( UniSetTypes::ObjectId objId, xmlNode* cnode, UniSetTypes::ObjectId shmId, SharedMemory* ic,
const string prefix ):
UObject_SK(objId,cnode),
shm( new SMInterface(shmId,&ui,objId,ic) ),
prefix(prefix)
{
UniXML::iterator it(cnode);
UniXML::iterator it1(cnode);
if( !it1.goChildren() )
{
ostringstream err;
err << myname << "(init): empty rrd list...";
RRDStorage::dlog[Debug::CRIT] << err.str() << endl;
throw NameNotFound(err.str());
}
int tmID=1;
for( ;it1.getCurrent(); it1++,tmID++ )
initRRD(it1,tmID);
}
// -----------------------------------------------------------------------------
RRDStorage::~RRDStorage()
{
}
// -----------------------------------------------------------------------------
void RRDStorage::step()
{
}
//--------------------------------------------------------------------------------
void RRDStorage::initRRD( xmlNode* cnode, int tmID )
{
UniXML::iterator it(cnode);
string fname( it.getProp("filename") );
string ff( it.getProp("filter_field") );
string fv( it.getProp("filter_value") );
string cf( it.getProp("ds_field") );
if( cf.empty() )
cf = ff+fv+"_ds";
int rrdstep = it.getPIntProp("step",5);
int lastup = it.getPIntProp("lastup",0);
RRDStorage::dlog[Debug::INFO] << myname << "(init): add rrd: file='" << fname
<< " " << ff << "='" << fv
<< "' create='" << cf << "'"
<< " step=" << rrdstep
<< endl;
std::list<std::string> rralist;
UniXML::iterator it_rra(cnode);
if( !it_rra.goChildren() )
{
ostringstream err;
err << myname << "(init): rrd='" << fname << "' Unknown RRA list";
RRDStorage::dlog[Debug::CRIT] << err.str();
throw SystemError(err.str());
}
for(;it_rra.getCurrent(); it_rra++ )
{
string rra( it_rra.getProp("rra") );
if( rra.empty() )
{
ostringstream err;
err << myname << "(init): rrd='" << fname << "' Unkown RRA item.. <item rra='...'";
RRDStorage::dlog[Debug::CRIT] << err.str();
throw SystemError(err.str());
}
rralist.push_back(rra);
}
if( rralist.empty() )
{
ostringstream err;
err << myname << "(init): Not found RRA items...";
RRDStorage::dlog[Debug::CRIT] << err.str() << endl;
throw SystemError(err.str());
}
// try
{
xmlNode* snode = conf->getXMLSensorsSection();
if(!snode)
{
ostringstream err;
err << myname << "(init): Not found section <sensors>";
RRDStorage::dlog[Debug::CRIT] << err.str();
throw SystemError(err.str());
}
UniXML_iterator it1(snode);
if( !it1.goChildren() )
{
ostringstream err;
err << myname << "(init): section <sensors> empty?!";
RRDStorage::dlog[Debug::CRIT] << err.str();
throw SystemError(err.str());
}
DSMap dsmap;
// список параметров входящих в RRD
std::list<std::string> dslist;
for(;it1.getCurrent(); it1.goNext() )
{
if( !UniSetTypes::check_filter(it1,ff,fv) )
continue;
std::string a(it1.getProp(cf));
if( a.empty() )
{
ostringstream err;
err << myname << "(init): Unknown create parameters ('" << cf << "')";
RRDStorage::dlog[Debug::CRIT] << err.str();
throw SystemError(err.str());
}
std::string dsname(it1.getProp("name"));
ostringstream nm;
nm << "DS:" << dsname << ":" << a;
dslist.push_back(nm.str());
ObjectId sid = conf->getSensorID( dsname );
if( sid == DefaultObjectId )
{
ostringstream err;
err << myname << "(init): Unknown SensorID for '" << dsname << "'";
RRDStorage::dlog[Debug::CRIT] << err.str();
throw SystemError(err.str());
}
DSInfo ds(dsname,it1.getIntProp("default"));
dsmap.insert( DSMap::value_type(sid,ds) );
}
if( dslist.empty() )
{
ostringstream err;
err << myname << "(init): Not found RRD items...";
RRDStorage::dlog[Debug::CRIT] << err.str() << endl;
throw SystemError(err.str());
}
char argc = dslist.size() + rralist.size();
char** argv = new char*[ argc ];
int k=0;
for( std::list<std::string>::iterator i=dslist.begin(); i!=dslist.end(); ++i,k++ )
argv[k] = strdup(i->c_str());
for( std::list<std::string>::iterator i=rralist.begin(); i!=rralist.end(); ++i,k++ )
argv[k] = strdup(i->c_str());
// for( k=0; k<argc; k++ )
// cout << "*** argv[" << k << "]='" << argv[k] << "'" << endl;
// Собственно создаём RRD
rrd_clear_error();
if( rrd_create_r(fname.c_str(),rrdstep,lastup,argc,(const char**)argv) < 0 )
{
ostringstream err;
err << myname << "(init): Can`t create RRD ('" << fname << "'): err: " << string(rrd_get_error());
RRDStorage::dlog[Debug::CRIT] << err.str() << endl;
throw SystemError(err.str());
}
// Чистим выделенную память
for( k=0; k<argc; k++ )
free( argv[k] );
delete[] argv;
RRDInfo rrd(fname,tmID,rrdstep,dsmap);
rrdlist.push_back(rrd);
}
/* catch( Exception& ex )
{
RRDStorage::dlog[Debug::CRIT] << myname << "(init) " << ex << std::endl;
}
catch( ... )
{
RRDStorage::dlog[Debug::CRIT] << myname << "(init): catch ..." << std::endl;
}
*/
}
//--------------------------------------------------------------------------------
void RRDStorage::help_print( int argc, const char* const* argv )
{
cout << "--rrdstorage-name - ID for rrdstorage. Default: RRDStorage1. " << endl;
cout << "--rrdstorage-locale name - DB locale. Default: koi8-r. " << endl;
cout << "--rrdstorage-heartbeat-id name - ID for heartbeat sensor." << endl;
cout << "--rrdstorage-heartbeat-max val - max value for heartbeat sensor." << endl;
}
// -----------------------------------------------------------------------------
RRDStorage* RRDStorage::init_rrdstorage( int argc, const char* const* argv,
UniSetTypes::ObjectId icID, SharedMemory* ic,
const std::string prefix )
{
string name = conf->getArgParam("--" + prefix + "-name","RRDStorage");
if( name.empty() )
{
UniSetExtensions::dlog[Debug::CRIT] << "(RRDStorage): Unknown name. Usage: --" << prefix << "-name" << endl;
return 0;
}
ObjectId ID = conf->getObjectID(name);
if( ID == UniSetTypes::DefaultObjectId )
{
UniSetExtensions::dlog[Debug::CRIT] << "(RRDStorage): Not found ID for '" << name
<< " in '" << conf->getObjectsSection() << "' section" << endl;
return 0;
}
string confname = conf->getArgParam("--" + prefix + "-confnode",name);
xmlNode* cnode = conf->getNode(confname);
if( !cnode )
{
UniSetExtensions::dlog[Debug::CRIT] << "(RRDStorage): " << name << "(init): Not found <" + confname + ">" << endl;
return 0;
}
UniSetExtensions::dlog[Debug::INFO] << "(RRDStorage): name = " << name << "(" << ID << ")" << endl;
return new RRDStorage(ID,cnode,icID,ic,prefix);
}
// -----------------------------------------------------------------------------
void RRDStorage::askSensors( UniversalIO::UIOCommand cmd )
{
UObject_SK::askSensors(cmd);
for( RRDList::iterator it=rrdlist.begin(); it!=rrdlist.end(); ++it )
{
for( DSMap::iterator s=it->dsmap.begin(); s!=it->dsmap.end(); ++s )
{
try
{
shm->askSensor(s->first,cmd);
}
catch( std::exception& ex )
{
RRDStorage::dlog[Debug::CRIT] << myname << "(askSensors): " << ex.what() << endl;
}
}
}
}
// -----------------------------------------------------------------------------
void RRDStorage::sysCommand( UniSetTypes::SystemMessage* sm )
{
UObject_SK::sysCommand(sm);
if( sm->command == SystemMessage::StartUp || sm->command == SystemMessage::WatchDog )
{
for( RRDList::iterator it=rrdlist.begin(); it!=rrdlist.end(); ++it )
{
try
{
askTimer(it->tid,it->sec*1000);
}
catch( std::exception& ex )
{
RRDStorage::dlog[Debug::CRIT] << myname << "(askTimer): " << ex.what() << endl;
}
}
}
}
// -----------------------------------------------------------------------------
void RRDStorage::sensorInfo( UniSetTypes::SensorMessage* sm )
{
}
// -----------------------------------------------------------------------------
void RRDStorage::timerInfo( UniSetTypes::TimerMessage* tm )
{
for( RRDList::iterator it=rrdlist.begin(); it!=rrdlist.end(); ++it )
{
if( it->tid == tm->id )
{
ostringstream v;
v << time(0);
for( DSMap::iterator s=it->dsmap.begin(); s!=it->dsmap.end(); ++s )
v << ":" << s->second.value;
if( RRDStorage::dlog.debugging(Debug::INFO) )
RRDStorage::dlog[Debug::INFO] << myname << "(update): '" << it->filename << "' " << v.str() << endl;
rrd_clear_error();
const char* argv = v.str().c_str();
if( rrd_update_r(it->filename.c_str(),NULL,1,&argv) < 0 )
{
ostringstream err;
err << myname << "(update): Can`t update RRD ('" << it->filename << "'): err: " << string(rrd_get_error());
RRDStorage::dlog[Debug::CRIT] << err.str() << endl;
}
break;
}
}
}
// -----------------------------------------------------------------------------
#ifndef _RRDStorage_H_
#define _RRDStorage_H_
// -----------------------------------------------------------------------------
#include "UObject_SK.h"
#include "SMInterface.h"
#include "SharedMemory.h"
// -----------------------------------------------------------------------------
/*!
*/
class RRDStorage:
public UObject_SK
{
public:
RRDStorage( UniSetTypes::ObjectId objId, xmlNode* cnode, UniSetTypes::ObjectId shmID, SharedMemory* ic=0,
const std::string prefix="rrd" );
virtual ~RRDStorage();
/*! глобальная функция для инициализации объекта */
static RRDStorage* init_rrdstorage( int argc, const char* const* argv,
UniSetTypes::ObjectId shmID, SharedMemory* ic=0,
const std::string prefix="rrd" );
/*! глобальная функция для вывода help-а */
static void help_print( int argc, const char* const* argv );
protected:
RRDStorage();
virtual void askSensors( UniversalIO::UIOCommand cmd );
virtual void sensorInfo( UniSetTypes::SensorMessage* sm );
virtual void timerInfo( UniSetTypes::TimerMessage* tm );
virtual void sysCommand( UniSetTypes::SystemMessage* sm );
virtual void initRRD( xmlNode* cnode, int tmID );
void step();
SMInterface* shm;
struct DSInfo
{
std::string dsname;
long value;
DSInfo( const std::string& dsname, long defval ):
dsname(dsname),value(defval){}
};
typedef std::map<UniSetTypes::ObjectId,DSInfo> DSMap;
struct RRDInfo
{
std::string filename;
long tid;
long sec;
DSMap dsmap;
RRDInfo( const std::string& fname, long tmID, long sec, const DSMap& ds ):
filename(fname),tid(tmID),sec(sec),dsmap(ds){}
};
typedef std::list<RRDInfo> RRDList;
RRDList rrdlist;
private:
std::string prefix;
};
// -----------------------------------------------------------------------------
#endif // _RRDStorage_H_
// -----------------------------------------------------------------------------
#!/bin/sh
ln -s -f ../../Utilities/scripts/uniset-start.sh
ln -s -f ../../Utilities/scripts/uniset-stop.sh stop.sh
ln -s -f ../../Utilities/scripts/uniset-functions.sh
ln -s -f ../../conf/test.xml test.xml
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: libUniSetRRDStorage
Description: Support library for UniSetRRDStorage
Requires: libUniSetExtensions librrd
Version: @VERSION@
Libs: -L${libdir} -lUniSetRRDStorage
Cflags: -I${includedir}/uniset
#include <sstream>
#include "RRDStorage.h"
#include "Configuration.h"
#include "Debug.h"
#include "ObjectsActivator.h"
#include "Extensions.h"
// -----------------------------------------------------------------------------
using namespace std;
using namespace UniSetTypes;
using namespace UniSetExtensions;
// -----------------------------------------------------------------------------
int main( int argc, const char** argv )
{
if( argc>1 && (!strcmp(argv[1],"--help") || !strcmp(argv[1],"-h")) )
{
cout << "--smemory-id objectName - SharedMemory objectID. Default: autodetect" << endl;
cout << "--confile filename - configuration file. Default: configure.xml" << endl;
cout << "--rrdstorage-logfile filename - logfilename. Default: rrdstorage.log" << endl;
cout << endl;
RRDStorage::help_print(argc, argv);
return 0;
}
try
{
string confile=UniSetTypes::getArgParam("--confile",argc, argv, "configure.xml");
conf = new Configuration( argc, argv, confile );
string logfilename(conf->getArgParam("--rrdstorage-logfile"));
if( logfilename.empty() )
logfilename = "rrdstorage.log";
conf->initDebug(dlog,"dlog");
std::ostringstream logname;
string dir(conf->getLogDir());
logname << dir << logfilename;
unideb.logFile( logname.str() );
dlog.logFile( logname.str() );
ObjectId shmID = DefaultObjectId;
string sID = conf->getArgParam("--smemory-id");
if( !sID.empty() )
shmID = conf->getControllerID(sID);
else
shmID = getSharedMemoryID();
if( shmID == DefaultObjectId )
{
cerr << sID << "? SharedMemoryID not found in " << conf->getControllersSection() << " section" << endl;
return 1;
}
RRDStorage* db = RRDStorage::init_rrdstorage(argc,argv,shmID);
if( !db )
{
dlog[Debug::CRIT] << "(rrdstorage): init не прошёл..." << endl;
return 1;
}
db->init_dlog(dlog);
ObjectsActivator act;
act.addObject(static_cast<class UniSetObject*>(db));
SystemMessage sm(SystemMessage::StartUp);
act.broadcast( sm.transport_msg() );
unideb(Debug::ANY) << "\n\n\n";
unideb[Debug::ANY] << "(main): -------------- RRDStorage START -------------------------\n\n";
dlog(Debug::ANY) << "\n\n\n";
dlog[Debug::ANY] << "(main): -------------- RRDStorage START -------------------------\n\n";
act.run(false);
return 0;
}
catch( UniSetTypes::Exception& ex )
{
dlog[Debug::CRIT] << "(rrdstorage): " << ex << std::endl;
}
catch(...)
{
dlog[Debug::CRIT] << "(rrdstorage): catch ..." << std::endl;
}
return 1;
}
#!/bin/sh
uniset-start.sh -f ./uniset-rrdstorage --confile test.xml \
--rrd-name RRDStorage1 \
--dlog-add-levels info,crit,warn
// --------------------------------------------------------------------------
/*
DO NOT EDIT THIS FILE. IT IS AUTOGENERATED FILE.
ALL YOUR CHANGES WILL BE LOST.
НЕ РЕДАКТИРУЙТЕ ЭТОТ ФАЙЛ. ЭТОТ ФАЙЛ СОЗДАН АВТОМАТИЧЕСКИ.
ВСЕ ВАШИ ИЗМЕНЕНИЯ БУДУТ ПОТЕРЯНЫ.
*/
// --------------------------------------------------------------------------
// generate timestamp: 2013-12-10+04:00
// -----------------------------------------------------------------------------
#ifndef UObject_SK_H_
#define UObject_SK_H_
// -----------------------------------------------------------------------------
#include <string>
#include "UniSetObject.h"
#include "LT_Object.h"
#include "UniXML.h"
#include "Trigger.h"
#include "SMInterface.h"
#include "DebugStream.h"
// -----------------------------------------------------------------------------
class UObject_SK:
public UniSetObject,
public LT_Object
{
public:
UObject_SK( UniSetTypes::ObjectId id, xmlNode* node=UniSetTypes::conf->getNode("UObject"),
UniSetTypes::ObjectId shmID = UniSetTypes::DefaultObjectId );
UObject_SK( UniSetTypes::ObjectId id, xmlNode* node=UniSetTypes::conf->getNode("UObject"), const std::string& argprefix="" );
UObject_SK();
virtual ~UObject_SK();
......@@ -22,36 +33,57 @@ class UObject_SK:
bool alarm( UniSetTypes::ObjectId sid, bool state );
bool getState( UniSetTypes::ObjectId sid );
long getValue( UniSetTypes::ObjectId sid );
void setValue( UniSetTypes::ObjectId sid, long value );
void setState( UniSetTypes::ObjectId sid, bool state );
void askState( UniSetTypes::ObjectId sid, UniversalIO::UIOCommand );
void askValue( UniSetTypes::ObjectId sid, UniversalIO::UIOCommand );
void askThreshold ( UniSetTypes::ObjectId sensorId, UniSetTypes::ThresholdId tid,
UniversalIO::UIOCommand cmd,
CORBA::Long lowLimit, CORBA::Long hiLimit, CORBA::Long sensibility,
UniSetTypes::ObjectId backid = UniSetTypes::DefaultObjectId );
void askState( UniSetTypes::ObjectId sid, UniversalIO::UIOCommand, UniSetTypes::ObjectId node = UniSetTypes::conf->getLocalNode() );
void askValue( UniSetTypes::ObjectId sid, UniversalIO::UIOCommand, UniSetTypes::ObjectId node = UniSetTypes::conf->getLocalNode() );
void updateValues();
void setInfo( UniSetTypes::ObjectId code, bool state );
void setMsg( UniSetTypes::ObjectId code, bool state );
DebugStream dlog;
void init_dlog(DebugStream& dlog);
// Используемые идентификаторы
// Используемые идентификаторы сообщений
// Текущее значение и предыдущее значение
// --- public variables ---
// --- end of public variables ---
protected:
// --- protected variables ---
// ---- end of protected variables ----
virtual void callback();
virtual void processingMessage( UniSetTypes::VoidMessage* msg );
virtual void sysCommand( UniSetTypes::SystemMessage* sm );
virtual void askSensors( UniversalIO::UIOCommand cmd );
virtual void sensorInfo( UniSetTypes::SensorMessage* sm ){};
virtual void timerInfo( UniSetTypes::TimerMessage* tm ){};
virtual void askSensors( UniversalIO::UIOCommand cmd ){}
virtual void sensorInfo( UniSetTypes::SensorMessage* sm ){}
virtual void timerInfo( UniSetTypes::TimerMessage* tm ){}
virtual void sigterm( int signo );
virtual bool activateObject();
virtual void testMode( bool state );
void updatePreviousValues();
void checkSensors();
void updateOutputs( bool force );
bool checkTestMode();
void preAskSensors( UniversalIO::UIOCommand cmd );
void preSensorInfo( UniSetTypes::SensorMessage* sm );
void preTimerInfo( UniSetTypes::TimerMessage* tm );
void waitSM( int wait_msec );
void waitSM( int wait_msec, UniSetTypes::ObjectId testID = UniSetTypes::DefaultObjectId );
void resetMsg();
Trigger trResetMsg;
......@@ -63,24 +95,37 @@ class UObject_SK:
int sleep_msec; /*!< пауза между итерациями */
bool active;
bool isTestMode;
Trigger trTestMode;
UniSetTypes::ObjectId idTestMode_S; /*!< идентификатор для флага тестовго режима (для всех) */
UniSetTypes::ObjectId idLocalTestMode_S; /*!< идентификатор для флага тестовго режима (для данного узла) */
bool in_TestMode_S;
bool in_LocalTestMode_S;
UniSetTypes::ObjectId smTestID; /*!< идентификатор датчика для тестирования готовности SM */
// управление датчиком "сердцебиения"
PassiveTimer ptHeartBeat; /*! < период "сердцебиения" */
UniSetTypes::ObjectId idHeartBeat; /*! < идентификатор датчика (AI) "сердцебиения" */
int maxHeartBeat; /*! < сохраняемое значение */
xmlNode* confnode;
SMInterface shm;
/*! получить числовое свойство из конф. файла по привязанной confnode */
int getIntProp(const std::string& name) { return UniSetTypes::conf->getIntProp(confnode, name); }
/*! получить текстовое свойство из конф. файла по привязанной confnode */
inline const std::string getProp(const std::string& name) { return UniSetTypes::conf->getProp(confnode, name); }
int smReadyTimeout; /*!< время ожидания готовности SM */
bool activated;
int activateTimeout; /*!< время ожидания готовности UniSetObject к работе */
PassiveTimer ptStartUpTimeout; /*!< время на блокировку обработки WatchDog, если недавно был StartUp */
int askPause; /*!< пауза между неудачными попытками заказать датчики */
IOController_i::SensorInfo si;
private:
IOController_i::SensorInfo si;
// --- private variables ---
// --- end of private variables ---
bool end_private; // вспомогательное поле (для внутреннего использования при генерировании кода)
};
// -----------------------------------------------------------------------------
......
......@@ -6,6 +6,6 @@ libUniSetExtensions_la_LDFLAGS = -version-info $(UEXT_VER)
libUniSetExtensions_la_CPPFLAGS = $(SIGC_CFLAGS) -I$(top_builddir)/extensions/include
libUniSetExtensions_la_LIBADD = $(SIGC_LIBS) $(top_builddir)/lib/libUniSet.la
libUniSetExtensions_la_SOURCES = Extensions.cc SMInterface.cc Calibration.cc SingleProcess.cc \
IOBase.cc DigitalFilter.cc PID.cc MTR.cc VTypes.cc
IOBase.cc DigitalFilter.cc PID.cc MTR.cc VTypes.cc UObject_SK.cc
#UObject_SK.cc
\ No newline at end of file
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