Commit 2b8c397e authored by Pavel Vainerman's avatar Pavel Vainerman

Merge branch 'devel/master'

parents 38a454ba 34a31d77
......@@ -46,6 +46,10 @@ uniset-codegen: добавить ключ --gen-sensor-name для генери
- перевести PassiveTimer на использование crono:: (c++11)
SQL:
====
- добавить работу с History (при передаче указателя на SM в конструкторе).
Version 2.1
============
- smonit запись значений в файл (csv?,sqlite?)
......
......@@ -60,7 +60,7 @@ int main( int argc, char** argv )
std::list<ExtInfo> l;
for( auto&& it: lst )
for( auto && it : lst )
{
UniversalIO::IOType t = conf->getIOType( it.si.id );
......@@ -129,7 +129,7 @@ int main( int argc, char** argv )
cout << "\r" << " i = " << j << " " << flush;
for( const auto& it: l )
for( const auto& it : l )
{
try
{
......
%def_enable docs
%def_enable mysql
%def_enable sqlite
%def_enable pgsql
%def_enable python
%def_enable rrd
%def_enable io
......@@ -12,7 +13,7 @@
Name: libuniset2
Version: 2.0
Release: alt30
Release: alt31
Summary: UniSet - library for building distributed industrial control systems
......@@ -26,8 +27,9 @@ Packager: Pavel Vainerman <pv@altlinux.ru>
Source: %name-%version.tar
# manually removed: glibc-devel-static
# Automatically added by buildreq on Fri Nov 26 2010
BuildRequires: libcommoncpp2-devel libomniORB-devel libsigc++2.0-devel xsltproc catch
# Automatically added by buildreq on Mon May 11 2015
# optimized out: fontconfig gcc-c++ libcloog-isl4 libstdc++-devel libwayland-client libwayland-server libxml2-devel pkg-config python-base python-devel python-module-omniidl python-modules
BuildRequires: libcommoncpp2-devel libomniORB-devel libsigc++2-devel
%if_enabled io
BuildRequires: libcomedi-devel
......@@ -35,13 +37,17 @@ BuildRequires: libcomedi-devel
%if_enabled mysql
# Using old package name instead of libmysqlclient-devel it absent in branch 5.0 for yauza
BuildRequires: libMySQL-devel
BuildRequires: libmysqlclient-devel
%endif
%if_enabled sqlite
BuildRequires: libsqlite3-devel
%endif
%if_enabled pgsql
BuildRequires: libpqxx-devel
%endif
%if_enabled rrd
BuildRequires: librrd-devel
%endif
......@@ -175,6 +181,24 @@ Requires: %name-extension-common = %version-%release
Libraries needed to develop for uniset SQLite
%endif
%if_enabled pgsql
%package extension-pgsql
Group: Development/Databases
Summary: PostgreSQL-dbserver implementatioin for UniSet
Requires: %name-extension-common = %version-%release
%description extension-pgsql
PostgreSQL dbserver for %name
%package extension-pgsql-devel
Group: Development/Databases
Summary: Libraries needed to develop for uniset PostgreSQL
Requires: %name-extension-common-devel = %version-%release
%description extension-pgsql-devel
Libraries needed to develop for uniset PostgreSQL
%endif
%if_enabled rrd
%package extension-rrd
Group: Development/C++
......@@ -241,7 +265,7 @@ SharedMemoryPlus extension ('all in one') for libuniset
%build
%autoreconf
%configure %{subst_enable docs} %{subst_enable mysql} %{subst_enable sqlite} %{subst_enable python} %{subst_enable rrd} %{subst_enable io} %{subst_enable logicproc} %{subst_enable tests}
%configure %{subst_enable docs} %{subst_enable mysql} %{subst_enable sqlite} %{subst_enable pgsql} %{subst_enable python} %{subst_enable rrd} %{subst_enable io} %{subst_enable logicproc} %{subst_enable tests}
%make
%install
......@@ -292,6 +316,9 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
%if_enabled sqlite
%_includedir/%oname/sqlite/
%endif
%if_enabled pgsql
%_includedir/%oname/pgsql/
%endif
%_libdir/libUniSet2.so
%_datadir/idl/%oname/
......@@ -315,6 +342,15 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
%_pkgconfigdir/libUniSet2SQLite.pc
%endif
%if_enabled pgsql
%files extension-pgsql
%_bindir/%oname-pgsql-*dbserver
%_libdir/*-pgsql.so*
%files extension-pgsql-devel
%_pkgconfigdir/libUniSet2PostgreSQL.pc
%endif
%if_enabled python
%files -n python-module-%oname
%dir %python_sitelibdir/%oname
......@@ -409,6 +445,12 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
# ..
%changelog
* Mon May 11 2015 Pavel Vainerman <pv@altlinux.ru> 2.0-alt31
- Calibrations: fixed bug
- LogSession: fixed bug
- PQSQL: minor fixes, update requires
- make style
* Fri May 08 2015 Pavel Vainerman <pv@altlinux.ru> 2.0-alt30
- ModbusSlave: added support nbit='' for 0x06 and 0x10 function (setbug #7337)
......@@ -441,6 +483,9 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
- fixed bug in 'MBSlave' (thank`s Alexandr Hanadeev)
- add --xxx-set-prop-prefix for MBSlave
* Sat Apr 04 2015 Pavel Vainerman <pv@altlinux.ru> 2.0-alt24.1
- test pgsql extension build
* Thu Apr 02 2015 Pavel Vainerman <pv@altlinux.ru> 2.0-alt24
- codegen: modify interface for messages (setMsg())
- remove alarm() function (deprecated)
......@@ -498,6 +543,9 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
- fixed bug in specfile: --enable-doc --> --enable-docs
- transition to use shared_ptr wherever possible
* Sat Dec 20 2014 Pavel Vainerman <pv@altlinux.ru> 2.0-alt10.1
- added PostgreSQL support
* Mon Nov 24 2014 Pavel Vainerman <pv@altlinux.ru> 2.0-alt10
- use shared_ptr
......
......@@ -81,6 +81,23 @@ fi
AM_CONDITIONAL(DISABLE_MYSQL, test ${buildmysql} = false)
#check pgsql support
AC_MSG_CHECKING([postgresql support])
buildpgsql=true
AC_ARG_ENABLE(pgsql, AC_HELP_STRING([--disable-pgsql], [disable PostgreSQL support]),
[ if test $enableval = yes; then buildpgsql=true; else buildpgsql=false; fi],[ buildpgsql=true; ])
if test ${buildpgsql} = true; then
AC_MSG_RESULT([enabled])
PKG_CHECK_MODULES(PGSQL,libpqxx)
AC_SUBST(PGSQL_LIBS)
AC_SUBST(PGSQL_CFLAGS)
else
AC_MSG_RESULT([disabled])
fi
AM_CONDITIONAL(DISABLE_PGSQL, test ${buildpgsql} = false)
#check rrd support
AC_MSG_CHECKING([rrd support])
......@@ -330,6 +347,8 @@ AC_CONFIG_FILES([Makefile
extensions/DBServer-MySQL/libUniSet2MySQL.pc
extensions/DBServer-SQLite/Makefile
extensions/DBServer-SQLite/libUniSet2SQLite.pc
extensions/DBServer-PostgreSQL/Makefile
extensions/DBServer-PostgreSQL/libUniSet2PostgreSQL.pc
extensions/IOControl/Makefile
extensions/IOControl/libUniSet2IOControl.pc
extensions/ModbusMaster/Makefile
......
......@@ -36,7 +36,7 @@
using namespace UniSetTypes;
using namespace std;
// --------------------------------------------------------------------------
#define dblog if( ulog()->debugging(DBLogInfoLevel) ) (*(ulog().get()))[DBLogInfoLevel]
#define dblog if( ulog()->debugging(DBLogInfoLevel) ) ulog()->debug(DBLogInfoLevel)
// --------------------------------------------------------------------------
DBServer_MySQL::DBServer_MySQL(ObjectId id):
DBServer(id),
......
#ifndef DBServer_PostgreSQL_H_
#define DBServer_PostgreSQL_H_
// --------------------------------------------------------------------------
#include <map>
#include <queue>
#include "UniSetTypes.h"
#include "PostgreSQLInterface.h"
#include "DBServer.h"
//------------------------------------------------------------------------------------------
class DBServer_PostgreSQL:
public DBServer
{
public:
DBServer_PostgreSQL( UniSetTypes::ObjectId id, const std::string& prefix );
DBServer_PostgreSQL();
virtual ~DBServer_PostgreSQL();
static const Debug::type DBLogInfoLevel = Debug::LEVEL9;
/*! глобальная функция для инициализации объекта */
static std::shared_ptr<DBServer_PostgreSQL> init_dbserver( int argc, const char* const* argv, const std::string& prefix = "pgsql" );
/*! глобальная функция для вывода help-а */
static void help_print( int argc, const char* const* argv );
protected:
typedef std::map<int, std::string> DBTableMap;
virtual void initDB( std::shared_ptr<PostgreSQLInterface>& db ) {};
virtual void initDBTableMap(DBTableMap& tblMap) {};
virtual void timerInfo( const UniSetTypes::TimerMessage* tm ) override;
virtual void sysCommand( const UniSetTypes::SystemMessage* sm ) override;
virtual void sensorInfo( const UniSetTypes::SensorMessage* sm ) override;
virtual void confirmInfo( const UniSetTypes::ConfirmMessage* cmsg ) override;
virtual void sigterm( int signo ) override;
bool writeToBase( const string& query );
virtual void init_dbserver();
void createTables( std::shared_ptr<PostgreSQLInterface>& db );
inline const char* tblName(int key)
{
return tblMap[key].c_str();
}
enum Timers
{
PingTimer, /*!< таймер на переодическую проверку соединения с сервером БД */
ReconnectTimer, /*!< таймер на повторную попытку соединения с сервером БД (или восстановления связи) */
lastNumberOfTimer
};
std::shared_ptr<PostgreSQLInterface> db;
int PingTime;
int ReconnectTime;
bool connect_ok; /*! признак наличия соеднинения с сервером БД */
bool activate;
typedef std::queue<std::string> QueryBuffer;
QueryBuffer qbuf;
unsigned int qbufSize; // размер буфера сообщений.
bool lastRemove;
void flushBuffer();
UniSetTypes::uniset_mutex mqbuf;
private:
DBTableMap tblMap;
};
//------------------------------------------------------------------------------------------
#endif
if DISABLE_PGSQL
else
UPGSQL_VER=@LIBVER@
lib_LTLIBRARIES = libUniSet2-pgsql.la
libUniSet2_pgsql_la_LDFLAGS = -version-info $(UPGSQL_VER)
libUniSet2_pgsql_la_SOURCES = PostgreSQLInterface.cc DBServer_PostgreSQL.cc
libUniSet2_pgsql_la_LIBADD = $(top_builddir)/lib/libUniSet2.la $(PGSQL_LIBS)
libUniSet2_pgsql_la_CXXFLAGS = $(PGSQL_CFLAGS)
bin_PROGRAMS = @PACKAGE@-pgsql-dbserver
@PACKAGE@_pgsql_dbserver_LDADD = libUniSet2-pgsql.la $(top_builddir)/lib/libUniSet2.la $(PGSQL_LIBS)
@PACKAGE@_pgsql_dbserver_CXXFLAGS = $(PGSQL_CFLAGS)
@PACKAGE@_pgsql_dbserver_SOURCES = main.cc
noinst_PROGRAMS = pgsql-test
pgsql_test_LDADD = libUniSet2-pgsql.la $(top_builddir)/lib/libUniSet2.la $(PGSQL_LIBS)
pgsql_test_CXXFLAGS = $(PGSQL_CFLAGS)
pgsql_test_SOURCES = test.cc
# install
devel_include_HEADERS = *.h
devel_includedir = $(includedir)/@PACKAGE@/pgsql
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libUniSet2PostgreSQL.pc
endif
// --------------------------------------------------------------------------
#include <sstream>
#include <cstdio>
#include <UniSetTypes.h>
#include "PostgreSQLInterface.h"
// --------------------------------------------------------------------------
using namespace std;
using namespace UniSetTypes;
using namespace pqxx;
// --------------------------------------------------------------------------
PostgreSQLInterface::PostgreSQLInterface():
lastQ(""),
lastE(""),
last_inserted_id(0)
{
//db = make_shared<pqxx::connection>();
}
PostgreSQLInterface::~PostgreSQLInterface()
{
close();
}
// -----------------------------------------------------------------------------------------
bool PostgreSQLInterface::ping()
{
return db && db->is_open();
}
// -----------------------------------------------------------------------------------------
bool PostgreSQLInterface::connect( const string& host, const string& user, const string& pswd, const string& dbname)
{
if( db )
return true;
std::string conninfo = "dbname=" + dbname + " host=" + host + " user=" + user + " password=" + pswd;
try
{
db = make_shared<pqxx::connection>(conninfo);
return db->is_open();
}
catch( const std::exception& e )
{
cerr << e.what() << std::endl;
}
return false;
}
// -----------------------------------------------------------------------------------------
bool PostgreSQLInterface::close()
{
if( db )
{
db->disconnect();
db.reset();
}
return true;
}
// -----------------------------------------------------------------------------------------
bool PostgreSQLInterface::insert( const string& q )
{
if( !db )
return false;
try
{
work w( *(db.get()) );
w.exec(q);
w.commit();
return true;
}
catch( const std::exception& e )
{
//cerr << e.what() << std::endl;
lastE = string(e.what());
}
return false;
}
// -----------------------------------------------------------------------------------------
bool PostgreSQLInterface::insertAndSaveRowid( const string& q )
{
if( !db )
return false;
std::string qplus = q + " RETURNING id";
try
{
work w( *(db.get()) );
pqxx::result res = w.exec(qplus);
w.commit();
save_inserted_id(res);
return true;
}
catch( const std::exception& e )
{
//cerr << e.what() << std::endl;
lastE = string(e.what());
}
return false;
}
// -----------------------------------------------------------------------------------------
PostgreSQLResult PostgreSQLInterface::query( const string& q )
{
if( !db )
return PostgreSQLResult();
try
{
nontransaction n(*(db.get()));
/* Execute SQL query */
result res( n.exec(q) );
return PostgreSQLResult(res);
}
catch( const std::exception& e )
{
lastE = string(e.what());
}
return PostgreSQLResult();
}
// -----------------------------------------------------------------------------------------
string PostgreSQLInterface::error()
{
return lastE;
}
// -----------------------------------------------------------------------------------------
const string PostgreSQLInterface::lastQuery()
{
return lastQ;
}
// -----------------------------------------------------------------------------------------
double PostgreSQLInterface::insert_id()
{
return last_inserted_id;
}
// -----------------------------------------------------------------------------------------
void PostgreSQLInterface::save_inserted_id( const pqxx::result& res )
{
if( res.size() > 0 && res[0].size() > 0 )
last_inserted_id = res[0][0].as<int>();
}
// -----------------------------------------------------------------------------------------
bool PostgreSQLInterface::isConnection()
{
return (db && db->is_open());
}
// -----------------------------------------------------------------------------------------
int num_cols( PostgreSQLResult::iterator& it )
{
return it->size();
}
// -----------------------------------------------------------------------------------------
int as_int( PostgreSQLResult::iterator& it, int col )
{
// if( col<0 || col >it->size() )
// return 0;
return uni_atoi( (*it)[col] );
}
// -----------------------------------------------------------------------------------------
double as_double( PostgreSQLResult::iterator& it, int col )
{
return atof( ((*it)[col]).c_str() );
}
// -----------------------------------------------------------------------------------------
string as_string( PostgreSQLResult::iterator& it, int col )
{
return ((*it)[col]);
}
// -----------------------------------------------------------------------------------------
int as_int( PostgreSQLResult::COL::iterator& it )
{
return uni_atoi( (*it) );
}
// -----------------------------------------------------------------------------------------
double as_double( PostgreSQLResult::COL::iterator& it )
{
return atof( (*it).c_str() );
}
// -----------------------------------------------------------------------------------------
std::string as_string( PostgreSQLResult::COL::iterator& it )
{
return (*it);
}
// -----------------------------------------------------------------------------------------
#if 0
PostgreSQLResult::COL get_col( PostgreSQLResult::ROW::iterator& it )
{
return (*it);
}
#endif
// -----------------------------------------------------------------------------------------
PostgreSQLResult::~PostgreSQLResult()
{
}
// -----------------------------------------------------------------------------------------
PostgreSQLResult::PostgreSQLResult( const pqxx::result& res )
{
for (result::const_iterator c = res.begin(); c != res.end(); ++c)
{
COL col;
for( int i = 0; i < c.size(); i++ )
col.push_back( c[i].as<string>() );
row.push_back(col);
}
}
// -----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------
#ifndef PostgreSQLInterface_H_
#define PostgreSQLInterface_H_
// ---------------------------------------------------------------------------
#include <string>
#include <list>
#include <vector>
#include <iostream>
#include <pqxx/pqxx>
#include <PassiveTimer.h>
// ----------------------------------------------------------------------------
class PostgreSQLResult;
// ----------------------------------------------------------------------------
class PostgreSQLInterface
{
public:
PostgreSQLInterface();
~PostgreSQLInterface();
bool connect( const std::string& host, const std::string& user, const std::string& pswd, const std::string& dbname );
bool close();
bool isConnection();
bool ping(); // проверка доступности БД
PostgreSQLResult query( const std::string& q );
const std::string lastQuery();
bool insert( const std::string& q );
bool insertAndSaveRowid( const std::string& q );
double insert_id();
void save_inserted_id( const pqxx::result& res );
std::string error();
protected:
private:
std::shared_ptr<pqxx::connection> db;
std::string lastQ;
std::string lastE;
double last_inserted_id;
};
// ----------------------------------------------------------------------------------
class PostgreSQLResult
{
public:
PostgreSQLResult() {}
PostgreSQLResult( const pqxx::result& res );
~PostgreSQLResult();
typedef std::vector<std::string> COL;
typedef std::list<COL> ROW;
typedef ROW::iterator iterator;
inline iterator begin()
{
return row.begin();
}
inline iterator end()
{
return row.end();
}
inline operator bool()
{
return !row.empty();
}
inline int size()
{
return row.size();
}
inline bool empty()
{
return row.empty();
}
protected:
ROW row;
};
// ----------------------------------------------------------------------------
int num_cols( PostgreSQLResult::iterator& );
// ROW
int as_int( PostgreSQLResult::iterator&, int col );
double as_double( PostgreSQLResult::iterator&, int col );
std::string as_text( PostgreSQLResult::iterator&, int col );
// ----------------------------------------------------------------------------
// COL
int as_int( PostgreSQLResult::COL::iterator& );
double as_double( PostgreSQLResult::COL::iterator& );
std::string as_string( PostgreSQLResult::COL::iterator& );
//----------------------------------------------------------------------------
#endif
// ----------------------------------------------------------------------------------
#!/bin/sh
ln -s -f /usr/bin/uniset2-stop.sh stop.sh
ln -s -f ../../conf/test.xml test.xml
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: libUniSet2PostgreSQL
Description: Support library for libUniSet2PostgreSQL
Requires: libUniSet2 libpqxx
Version: @VERSION@
Libs: -L${libdir} -lUniSet2-pgsql
Cflags: -I${includedir}/@PACKAGE@ -I${includedir}/@PACKAGE@/pgsql
#include "Configuration.h"
#include "DBServer_PostgreSQL.h"
#include "UniSetActivator.h"
#include "Debug.h"
// --------------------------------------------------------------------------
using namespace UniSetTypes;
using namespace std;
// --------------------------------------------------------------------------
int main(int argc, char** argv)
{
try
{
if( argc > 1 && !strcmp(argv[1], "--help") )
{
DBServer_PostgreSQL::help_print(argc, argv);
return 0;
}
auto conf = uniset_init(argc, argv, "configure.xml");
auto dbs = DBServer_PostgreSQL::init_dbserver(argc, argv);
auto act = UniSetActivator::Instance();
act->add(dbs);
act->run(false);
}
catch( const Exception& ex )
{
cerr << "(DBServer_PosgreSQL::main): " << ex << endl;
}
catch( std::exception& ex )
{
cerr << "(DBServer_PosgreSQL::main): " << ex.what() << endl;
}
catch(...)
{
cerr << "(DBServer_PosgreSQL::main): catch ..." << endl;
}
return 0;
}
#!/bin/sh
ulimit -Sc 1000000
uniset2-start.sh -f ./uniset2-pgsql-dbserver --confile test.xml --name DBServer1 \
--ulog-add-levels info,crit,warn,level9,system \
--dbserver-buffer-size 100
#include <iostream>
#include <sstream>
#include "Exceptions.h"
#include "PostgreSQLInterface.h"
// --------------------------------------------------------------------------
using namespace UniSetTypes;
using namespace std;
// --------------------------------------------------------------------------
int main(int argc, char** argv)
{
std::string dbname("test-db");
if( argc > 1 )
dbname = string(argv[1]);
try
{
PostgreSQLInterface db;
if( !db.connect("localhost", "dbadmin", "dbadmin", dbname) )
{
cerr << "db connect error: " << db.error() << endl;
return 1;
}
stringstream q;
q << "SELECT * from main_history";
PostgreSQLResult r = db.query(q.str());
if( !r )
{
cerr << "db connect error: " << db.error() << endl;
return 1;
}
for( PostgreSQLResult::iterator it = r.begin(); it != r.end(); it++ )
{
cout << "ROW: ";
PostgreSQLResult::COL col(*it);
for( PostgreSQLResult::COL::iterator cit = it->begin(); cit != it->end(); cit++ )
cout << as_string(cit) << "(" << as_double(cit) << ") | ";
cout << endl;
}
db.close();
}
catch( const Exception& ex )
{
cerr << "(test): " << ex << endl;
}
catch( std::exception& ex )
{
cerr << "(test): " << ex.what() << endl;
}
catch(...)
{
cerr << "(test): catch ..." << endl;
}
return 0;
}
......@@ -20,7 +20,9 @@ libUniSet2IOControl_la_SOURCES = ComediInterface.cc IOControl.cc
@PACKAGE@_iocontrol_LDADD = libUniSet2IOControl.la \
$(top_builddir)/lib/libUniSet2.la \
$(top_builddir)/extensions/lib/libUniSet2Extensions.la $(COMEDI_LIBS) $(SIGC_LIBS) $(COMCPP_LIBS) -lm
$(top_builddir)/extensions/lib/libUniSet2Extensions.la \
$(top_builddir)/extensions/SharedMemory/libUniSet2SharedMemory.la \
$(COMEDI_LIBS) $(SIGC_LIBS) $(COMCPP_LIBS) -lm
@PACKAGE@_iocontrol_CXXFLAGS = $(COMEDI_CFLAGS) $(SIGC_CFLAGS) $(COMCPP_CFLAGS) \
-I$(top_builddir)/extensions/include \
-I$(top_builddir)/extensions/SharedMemory
......@@ -34,6 +36,7 @@ libUniSet2IOControl_la_SOURCES = ComediInterface.cc IOControl.cc
@PACKAGE@_iocalibr_LDADD = $(COMEDI_LIBS) \
$(top_builddir)/lib/libUniSet2.la \
$(top_builddir)/extensions/lib/libUniSet2Extensions.la \
$(top_builddir)/extensions/SharedMemory/libUniSet2SharedMemory.la \
-lm
@PACKAGE@_iocalibr_SOURCES = iocalibr.cc
......
......@@ -26,7 +26,8 @@ PassiveLProcessor::PassiveLProcessor( UniSetTypes::ObjectId objId,
UniXML::iterator it(confnode);
confnode = conf->getNode(myname);
string lfile = conf->getArgParam("--" + prefix + "-schema",it.getProp("schema"));
string lfile = conf->getArgParam("--" + prefix + "-schema", it.getProp("schema"));
if( lfile.empty() )
{
ostringstream err;
......
......@@ -60,7 +60,7 @@ int main(int argc, const char** argv)
return 1;
}
auto plp = PassiveLProcessor::init_plproc(argc,argv,shmID);
auto plp = PassiveLProcessor::init_plproc(argc, argv, shmID);
auto act = UniSetActivator::Instance();
act->add(plp);
......
......@@ -4,7 +4,8 @@
if HAVE_EXTENTIONS
SUBDIRS = lib include SharedMemory SharedMemory/tests IOControl LogicProcessor LogicProcessor/tests \
ModbusMaster ModbusSlave SMViewer UniNetwork UNetUDP UNetUDP/tests DBServer-MySQL DBServer-SQLite \
ModbusMaster ModbusSlave SMViewer UniNetwork UNetUDP UNetUDP/tests \
DBServer-MySQL DBServer-SQLite DBServer-PostgreSQL \
RRDServer SharedMemoryPlus tests ModbusMaster/tests ModbusSlave/tests
#SMDBServer
......
......@@ -1285,7 +1285,7 @@ ModbusRTU::mbErrCode MBSlave::real_write_it( IOMap::iterator& it, ModbusRTU::Mod
if( p->bitreg )
return real_bitreg_write_it(p->bitreg, dat[i++]);
return real_write_prop(p,dat,i,count);
return real_write_prop(p, dat, i, count);
}
// -------------------------------------------------------------------------
ModbusRTU::mbErrCode MBSlave::real_bitreg_write_it( std::shared_ptr<BitRegProperty>& bp, const ModbusRTU::ModbusData val )
......@@ -1302,13 +1302,13 @@ ModbusRTU::mbErrCode MBSlave::real_bitreg_write_it( std::shared_ptr<BitRegProper
if( p->si.id == DefaultObjectId )
continue;
ModbusRTU::ModbusData dat[]={d[i]};
ModbusRTU::ModbusData dat[] = {d[i]};
dinfo << myname << "(real_bitreg_write_it): set " << ModbusRTU::dat2str(bp->mbreg) << "(" << (int)bp->mbreg << ")"
<< " bit[" << i << "]=" << (int)dat[0] << " sid=" << p->si.id << endl;
int k=0;
real_write_prop(p,dat,k,1);
int k = 0;
real_write_prop(p, dat, k, 1);
}
return ModbusRTU::erNoError;
......@@ -1317,6 +1317,7 @@ ModbusRTU::mbErrCode MBSlave::real_bitreg_write_it( std::shared_ptr<BitRegProper
ModbusRTU::mbErrCode MBSlave::real_write_prop( IOProperty* p, ModbusRTU::ModbusData* dat, int& i, int count )
{
ModbusRTU::ModbusData mbval = dat[i++];
try
{
if( p->amode == MBSlave::amRO )
......
......@@ -979,14 +979,14 @@ TEST_CASE("Write(0x06,0x10): nbit", "[modbus][mbslave][mbtcpslave][writenbit]")
SECTION("Test: write06")
{
ModbusRTU::WriteSingleOutputRetMessage ret = mb->write06(slaveaddr, tREG,3);
ModbusRTU::WriteSingleOutputRetMessage ret = mb->write06(slaveaddr, tREG, 3);
REQUIRE( ret.start == tREG );
REQUIRE( ret.data == 3 );
REQUIRE( ui->getValue(2020) == 1 );
REQUIRE( ui->getValue(2021) == 1 );
REQUIRE( ui->getValue(2022) == 0 );
ret = mb->write06(slaveaddr, tREG,0);
ret = mb->write06(slaveaddr, tREG, 0);
REQUIRE( ret.start == tREG );
REQUIRE( ret.data == 0 );
REQUIRE( ui->getValue(2020) == 0 );
......
......@@ -243,7 +243,7 @@ bool SharedMemory::activateObject()
res = IONotifyController_LT::activateObject();
// инициализируем указатели
for( auto&& it : hlist )
for( auto && it : hlist )
{
it.a_it = myioEnd();
it.d_it = myioEnd();
......@@ -253,7 +253,7 @@ bool SharedMemory::activateObject()
for( auto& it : hist )
{
for( auto&& hit : it.hlst )
for( auto && hit : it.hlst )
hit.ioit = myioEnd();
}
......
......@@ -37,13 +37,13 @@ TEST_CASE("[SM]: get/set", "[sm][getset]")
{
InitTest();
ui->setValue(500,30);
ui->setValue(500, 30);
CHECK( ui->getValue(500) == 30 );
ui->setValue(500,-30);
ui->setValue(500, -30);
CHECK( ui->getValue(500) == -30 );
ui->setValue(500,0);
ui->setValue(500, 0);
CHECK( ui->getValue(500) == 0 );
}
// -----------------------------------------------------------------------------
......@@ -51,19 +51,20 @@ TEST_CASE("[SM]: threshold", "[sm][threshold]")
{
InitTest();
ui->setValue(503,30);
ui->setValue(503, 30);
CHECK( ui->getValue(504) == 0 );
ui->setValue(503,400);
ui->setValue(503, 400);
CHECK( ui->getValue(504) == 1 );
ui->setValue(503,25);
ui->setValue(503, 25);
CHECK( ui->getValue(504) == 0 );
}
// -----------------------------------------------------------------------------
TEST_CASE("[SM]: pulsar", "[sm][pulsar]")
{
InitTest();
while( ui->getValue(505) )
msleep(50);
......@@ -81,13 +82,13 @@ TEST_CASE("[SM]: heartbeat", "[sm][heartbeat]")
InitTest();
CHECK_FALSE( ui->getValue(507) );
ui->setValue(506,2);
ui->setValue(506, 2);
msleep(500);
CHECK( ui->getValue(507) );
msleep(2000);
CHECK_FALSE( ui->getValue(507) );
ui->setValue(506,4);
ui->setValue(506, 4);
msleep(2000);
CHECK( ui->getValue(507) );
}
......
......@@ -17,6 +17,7 @@ libUniSet2Network_la_SOURCES = UniExchange.cc
@PACKAGE@_network_LDADD = libUniSet2Network.la \
$(top_builddir)/lib/libUniSet2.la \
$(top_builddir)/extensions/lib/libUniSet2Extensions.la \
$(top_builddir)/extensions/SharedMemory/libUniSet2SharedMemory.la \
$(COMCPP_LIBS)
@PACKAGE@_network_CPPFLAGS = $(SIGC_CFLAGS) $(COMCPP_CFLAGS) -I$(top_builddir)/extensions/include
@PACKAGE@_network_SOURCES = uninet.cc
......
......@@ -68,6 +68,9 @@ class Calibration
/*! Тип для хранения значения */
typedef float TypeOfValue;
/*! выход за границы диапазона (TypeOfValue) */
static const TypeOfValue ValueOutOfRange;
/*! выход за границы диапазона */
static const long outOfRange;
......@@ -75,7 +78,7 @@ class Calibration
Получение калиброванного значения
\param raw - сырое значение
\param crop_raw - обрезать переданное значение по крайним точкам
\return Возвращает калиброванное
\return Возвращает калиброванное или outOfRange
*/
long getValue( long raw, bool crop_raw = false );
......
......@@ -10,7 +10,8 @@
using namespace std;
using namespace UniSetTypes;
// ----------------------------------------------------------------------------
const long Calibration::outOfRange = std::numeric_limits<Calibration::TypeOfValue>::max();
const Calibration::TypeOfValue Calibration::ValueOutOfRange = std::numeric_limits<Calibration::TypeOfValue>::max();
const long Calibration::outOfRange = std::numeric_limits<long>::max();
// ----------------------------------------------------------------------------
Calibration::Part::Part():
k(0)
......@@ -63,7 +64,7 @@ bool Calibration::Part::checkY( const TypeOfValue& y ) const
Calibration::TypeOfValue Calibration::Part::getY( const TypeOfValue& x ) const
{
if( !checkX(x) )
return Calibration::outOfRange;
return Calibration::ValueOutOfRange;
if( x == left_x() )
return left_y();
......@@ -77,7 +78,7 @@ Calibration::TypeOfValue Calibration::Part::getY( const TypeOfValue& x ) const
Calibration::TypeOfValue Calibration::Part::getX( const TypeOfValue& y ) const
{
if( !checkY(y) )
return Calibration::outOfRange;
return Calibration::ValueOutOfRange;
if( y == left_y() )
return left_x();
......@@ -307,7 +308,7 @@ long Calibration::getValue( long raw, bool crop_raw )
TypeOfValue q = fit->getY(raw);
if( q != outOfRange )
if( q != ValueOutOfRange )
{
if( szCache )
insertToCache(raw, tRound(q) );
......@@ -347,7 +348,7 @@ long Calibration::getRawValue( long cal, bool range )
{
TypeOfValue q = it.getX(cal);
if( q != outOfRange )
if( q != ValueOutOfRange )
return tRound(q);
}
......
......@@ -35,7 +35,7 @@ class TCPCheck
* \note Вызывается через system()! Это может быть опасно с точки зрения безопасности..
* \todo Возможно стоит написать свою реализацию ping
*/
bool ping( const std::string& _ip, timeout_t tout = 1000, timeout_t sleep_msec = 200, const std::string& ping_argc="-c 1 -w 0.1 -q -n" );
bool ping( const std::string& _ip, timeout_t tout = 1000, timeout_t sleep_msec = 200, const std::string& ping_argc = "-c 1 -w 0.1 -q -n" );
protected:
......@@ -52,7 +52,7 @@ class TCPCheck
int port = {0};
int tout_msec;
std::string ping_args={"-c 1 -w 0.1 -q -n"};
std::string ping_args = {"-c 1 -w 0.1 -q -n"};
};
// -----------------------------------------------------------------------------
#endif // _TCPCheck_H_
......
......@@ -54,6 +54,7 @@ bool TCPCheck::check( const std::string& _ip, int _port, timeout_t tout, timeout
void TCPCheck::check_thread()
{
setResult(false);
try
{
ost::Thread::setException(ost::Thread::throwException);
......@@ -98,6 +99,6 @@ void TCPCheck::ping_thread()
int ret = system(cmd.str().c_str());
int res = WEXITSTATUS(ret);
setResult((res==0));
setResult((res == 0));
}
// -----------------------------------------------------------------------------
......@@ -16,13 +16,11 @@ using namespace UniSetTypes;
// -------------------------------------------------------------------------
LogSession::~LogSession()
{
cancelled = true;
if( isRunning() )
{
cancelled = true;
ost::Thread::join();
disconnect();
// if( isRunning() )
// ost::Thread::join();
}
}
// -------------------------------------------------------------------------
......@@ -277,8 +275,6 @@ void LogSession::final()
{
}
delete this;
}
// -------------------------------------------------------------------------
void LogSession::connectFinalSession( FinalSlot sl )
......
......@@ -33,7 +33,7 @@ class TSRunner
TSRunner()
{
cancel = false;
res = std::async(std::launch::async,run_test_server);
res = std::async(std::launch::async, run_test_server);
}
~TSRunner()
......
......@@ -19,6 +19,14 @@ extensions/DBServer-SQLite/SQLiteInterface.cc
extensions/DBServer-SQLite/SQLiteInterface.h
extensions/DBServer-SQLite/test.cc
extensions/DBServer-SQLite/test.xml
extensions/DBServer-PostgreSQL/DBServer_PostgreSQL.cc
extensions/DBServer-PostgreSQL/DBServer_PostgreSQL.h
extensions/DBServer-PostgreSQL/libUniSet2PostgreSQL.pc.in
extensions/DBServer-PostgreSQL/main.cc
extensions/DBServer-PostgreSQL/Makefile.am
extensions/DBServer-PostgreSQL/PostgreSQLInterface.cc
extensions/DBServer-PostgreSQL/PostgreSQLInterface.h
extensions/DBServer-PostgreSQL/test.cc
extensions/include/Calibration.h
extensions/include/ComediInterface.h
extensions/include/DigitalFilter.h
......
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