Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
0a1a81dd
Commit
0a1a81dd
authored
Jan 03, 2015
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(IOBase): добавил (пропавший) механизм depend и тесты для него
parent
22b25cc4
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
354 additions
and
17 deletions
+354
-17
IOBase.h
extensions/include/IOBase.h
+12
-0
IOBase.cc
extensions/lib/IOBase.cc
+73
-4
Makefile.am
extensions/tests/Makefile.am
+1
-1
test_iobase.cc
extensions/tests/test_iobase.cc
+6
-9
test_iobase_with_sm.cc
extensions/tests/test_iobase_with_sm.cc
+199
-0
tests_with_sm.cc
extensions/tests/tests_with_sm.cc
+31
-1
tests_with_sm.h
extensions/tests/tests_with_sm.h
+15
-0
tests_with_sm.xml
extensions/tests/tests_with_sm.xml
+17
-2
No files found.
extensions/include/IOBase.h
View file @
0a1a81dd
...
@@ -46,6 +46,10 @@ struct IOBase
...
@@ -46,6 +46,10 @@ struct IOBase
debounce_state
(
false
),
debounce_state
(
false
),
ondelay_state
(
false
),
ondelay_state
(
false
),
offdelay_state
(
false
),
offdelay_state
(
false
),
d_id
(
UniSetTypes
::
DefaultObjectId
),
d_value
(
1
),
d_off_value
(
0
),
d_iotype
(
UniversalIO
::
UnknownIOType
),
t_ai
(
UniSetTypes
::
DefaultObjectId
),
t_ai
(
UniSetTypes
::
DefaultObjectId
),
front
(
false
),
front
(
false
),
front_type
(
ftUnknown
),
front_type
(
ftUnknown
),
...
@@ -64,6 +68,7 @@ struct IOBase
...
@@ -64,6 +68,7 @@ struct IOBase
bool
check_on_delay
(
bool
val
);
/*!< реализация задержки на включение */
bool
check_on_delay
(
bool
val
);
/*!< реализация задержки на включение */
bool
check_off_delay
(
bool
val
);
/*!< реализация задержки на отключение */
bool
check_off_delay
(
bool
val
);
/*!< реализация задержки на отключение */
bool
check_front
(
bool
val
);
/*!< реализация срабатывания по фронту сигнала */
bool
check_front
(
bool
val
);
/*!< реализация срабатывания по фронту сигнала */
bool
check_depend
(
SMInterface
*
shm
);
/*!< проверка разрешения(зависимости) от другого датчика */
IOController_i
::
SensorInfo
si
;
IOController_i
::
SensorInfo
si
;
UniversalIO
::
IOType
stype
;
/*!< тип канала (DI,DO,AI,AO) */
UniversalIO
::
IOType
stype
;
/*!< тип канала (DI,DO,AI,AO) */
...
@@ -101,6 +106,13 @@ struct IOBase
...
@@ -101,6 +106,13 @@ struct IOBase
bool
ondelay_state
;
/*!< значение для задержки включения */
bool
ondelay_state
;
/*!< значение для задержки включения */
bool
offdelay_state
;
/*!< значение для задержки отключения */
bool
offdelay_state
;
/*!< значение для задержки отключения */
// Зависимость (d - depend)
UniSetTypes
::
ObjectId
d_id
;
/*!< идентификатор датчика, от которого зависит данный */
IOController
::
IOStateList
::
iterator
d_it
;
/*! итератор на датчик от которого зависит данный */
long
d_value
;
/*!< разрешающее работу значение датчика от которого зависит данный */
long
d_off_value
;
/*!< блокирующее значение */
UniversalIO
::
IOType
d_iotype
;
// Порог
// Порог
UniSetTypes
::
ObjectId
t_ai
;
/*!< если данный датчик дискретный,
UniSetTypes
::
ObjectId
t_ai
;
/*!< если данный датчик дискретный,
и является пороговым, то в данном поле
и является пороговым, то в данном поле
...
...
extensions/lib/IOBase.cc
View file @
0a1a81dd
...
@@ -20,6 +20,30 @@ bool IOBase::check_channel_break( long val )
...
@@ -20,6 +20,30 @@ bool IOBase::check_channel_break( long val )
return
(
val
<
breaklim
);
return
(
val
<
breaklim
);
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
bool
IOBase
::
check_depend
(
SMInterface
*
shm
)
{
if
(
d_id
==
DefaultObjectId
)
return
true
;
if
(
d_iotype
==
UniversalIO
::
DI
||
d_iotype
==
UniversalIO
::
DO
)
{
if
(
(
bool
)
shm
->
localGetValue
(
d_it
,
d_id
)
==
(
bool
)
d_value
)
return
true
;
return
false
;
}
if
(
d_iotype
==
UniversalIO
::
AI
||
d_iotype
==
UniversalIO
::
AO
)
{
if
(
shm
->
localGetValue
(
d_it
,
d_id
)
==
d_value
)
return
true
;
return
false
;
}
return
true
;
}
// -----------------------------------------------------------------------------
bool
IOBase
::
check_debounce
(
bool
val
)
bool
IOBase
::
check_debounce
(
bool
val
)
{
{
// нет защиты от дребезга
// нет защиты от дребезга
...
@@ -124,6 +148,10 @@ void IOBase::processingAsAI( IOBase* it, long val, SMInterface* shm, bool force
...
@@ -124,6 +148,10 @@ void IOBase::processingAsAI( IOBase* it, long val, SMInterface* shm, bool force
}
}
// проверка зависимости
// проверка зависимости
if
(
!
it
->
check_depend
(
shm
)
)
val
=
it
->
d_off_value
;
else
{
if
(
!
it
->
nofilter
&&
it
->
df
.
size
()
>
1
)
if
(
!
it
->
nofilter
&&
it
->
df
.
size
()
>
1
)
{
{
if
(
it
->
f_median
)
if
(
it
->
f_median
)
...
@@ -159,6 +187,8 @@ void IOBase::processingAsAI( IOBase* it, long val, SMInterface* shm, bool force
...
@@ -159,6 +187,8 @@ void IOBase::processingAsAI( IOBase* it, long val, SMInterface* shm, bool force
if
(
!
it
->
noprecision
&&
it
->
cal
.
precision
>
0
)
if
(
!
it
->
noprecision
&&
it
->
cal
.
precision
>
0
)
val
*=
lround
(
pow10
(
it
->
cal
.
precision
));
val
*=
lround
(
pow10
(
it
->
cal
.
precision
));
}
}
}
// end of 'check_depend'
// если предыдущее значение "обрыв",
// если предыдущее значение "обрыв",
// то сбрасываем признак
// то сбрасываем признак
{
{
...
@@ -196,6 +226,9 @@ void IOBase::processingFasAI( IOBase* it, float fval, SMInterface* shm, bool for
...
@@ -196,6 +226,9 @@ void IOBase::processingFasAI( IOBase* it, float fval, SMInterface* shm, bool for
}
}
// проверка зависимости
// проверка зависимости
if
(
!
it
->
check_depend
(
shm
)
)
val
=
it
->
d_off_value
;
else
{
{
// Читаем с использованием фильтра...
// Читаем с использованием фильтра...
if
(
!
it
->
nofilter
)
if
(
!
it
->
nofilter
)
...
@@ -232,7 +265,9 @@ void IOBase::processingFasAI( IOBase* it, float fval, SMInterface* shm, bool for
...
@@ -232,7 +265,9 @@ void IOBase::processingFasAI( IOBase* it, float fval, SMInterface* shm, bool for
void
IOBase
::
processingAsDI
(
IOBase
*
it
,
bool
set
,
SMInterface
*
shm
,
bool
force
)
void
IOBase
::
processingAsDI
(
IOBase
*
it
,
bool
set
,
SMInterface
*
shm
,
bool
force
)
{
{
// проверка зависимости
// проверка зависимости
if
(
it
->
invert
)
if
(
!
it
->
check_depend
(
shm
)
)
set
=
(
bool
)
it
->
d_off_value
;
else
if
(
it
->
invert
)
set
^=
true
;
set
^=
true
;
// Проверяем именно в такой последовательности!
// Проверяем именно в такой последовательности!
...
@@ -253,6 +288,10 @@ void IOBase::processingAsDI( IOBase* it, bool set, SMInterface* shm, bool force
...
@@ -253,6 +288,10 @@ void IOBase::processingAsDI( IOBase* it, bool set, SMInterface* shm, bool force
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
long
IOBase
::
processingAsAO
(
IOBase
*
it
,
SMInterface
*
shm
,
bool
force
)
long
IOBase
::
processingAsAO
(
IOBase
*
it
,
SMInterface
*
shm
,
bool
force
)
{
{
// проверка зависимости
if
(
!
it
->
check_depend
(
shm
)
)
return
it
->
d_off_value
;
uniset_rwmutex_rlock
lock
(
it
->
val_lock
);
uniset_rwmutex_rlock
lock
(
it
->
val_lock
);
long
val
=
it
->
value
;
long
val
=
it
->
value
;
...
@@ -301,6 +340,10 @@ long IOBase::processingAsAO( IOBase* it, SMInterface* shm, bool force )
...
@@ -301,6 +340,10 @@ long IOBase::processingAsAO( IOBase* it, SMInterface* shm, bool force )
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
bool
IOBase
::
processingAsDO
(
IOBase
*
it
,
SMInterface
*
shm
,
bool
force
)
bool
IOBase
::
processingAsDO
(
IOBase
*
it
,
SMInterface
*
shm
,
bool
force
)
{
{
// проверка зависимости
if
(
!
it
->
check_depend
(
shm
)
)
return
(
bool
)
it
->
d_off_value
;
uniset_rwmutex_rlock
lock
(
it
->
val_lock
);
uniset_rwmutex_rlock
lock
(
it
->
val_lock
);
bool
set
=
it
->
value
;
bool
set
=
it
->
value
;
...
@@ -313,6 +356,10 @@ bool IOBase::processingAsDO( IOBase* it, SMInterface* shm, bool force )
...
@@ -313,6 +356,10 @@ bool IOBase::processingAsDO( IOBase* it, SMInterface* shm, bool force )
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
float
IOBase
::
processingFasAO
(
IOBase
*
it
,
SMInterface
*
shm
,
bool
force
)
float
IOBase
::
processingFasAO
(
IOBase
*
it
,
SMInterface
*
shm
,
bool
force
)
{
{
// проверка зависимости
if
(
!
it
->
check_depend
(
shm
)
)
return
(
float
)
it
->
d_off_value
;
uniset_rwmutex_rlock
lock
(
it
->
val_lock
);
uniset_rwmutex_rlock
lock
(
it
->
val_lock
);
long
val
=
it
->
value
;
long
val
=
it
->
value
;
...
@@ -428,12 +475,13 @@ bool IOBase::initItem( IOBase* b, UniXML::iterator& it, SMInterface* shm, const
...
@@ -428,12 +475,13 @@ bool IOBase::initItem( IOBase* b, UniXML::iterator& it, SMInterface* shm, const
int
def_filtersize
,
float
def_filterT
,
float
def_lsparam
,
int
def_filtersize
,
float
def_filterT
,
float
def_lsparam
,
float
def_iir_coeff_prev
,
float
def_iir_coeff_new
)
float
def_iir_coeff_prev
,
float
def_iir_coeff_new
)
{
{
auto
conf
=
uniset_conf
();
// Переопределять ID и name - нельзя..
// Переопределять ID и name - нельзя..
string
sname
(
it
.
getProp
(
"name"
)
);
string
sname
(
it
.
getProp
(
"name"
)
);
ObjectId
sid
=
DefaultObjectId
;
ObjectId
sid
=
DefaultObjectId
;
if
(
it
.
getProp
(
"id"
).
empty
()
)
if
(
it
.
getProp
(
"id"
).
empty
()
)
sid
=
uniset_conf
()
->
getSensorID
(
sname
);
sid
=
conf
->
getSensorID
(
sname
);
else
else
sid
=
it
.
getPIntProp
(
"id"
,
DefaultObjectId
);
sid
=
it
.
getPIntProp
(
"id"
,
DefaultObjectId
);
...
@@ -448,7 +496,7 @@ bool IOBase::initItem( IOBase* b, UniXML::iterator& it, SMInterface* shm, const
...
@@ -448,7 +496,7 @@ bool IOBase::initItem( IOBase* b, UniXML::iterator& it, SMInterface* shm, const
b
->
val_lock
.
setName
(
sname
+
"_lock"
);
b
->
val_lock
.
setName
(
sname
+
"_lock"
);
b
->
si
.
id
=
sid
;
b
->
si
.
id
=
sid
;
b
->
si
.
node
=
uniset_conf
()
->
getLocalNode
();
b
->
si
.
node
=
conf
->
getLocalNode
();
b
->
nofilter
=
initIntProp
(
it
,
"nofilter"
,
prefix
,
init_prefix_only
);
b
->
nofilter
=
initIntProp
(
it
,
"nofilter"
,
prefix
,
init_prefix_only
);
b
->
ignore
=
initIntProp
(
it
,
"ioignore"
,
prefix
,
init_prefix_only
);
b
->
ignore
=
initIntProp
(
it
,
"ioignore"
,
prefix
,
init_prefix_only
);
...
@@ -503,6 +551,27 @@ bool IOBase::initItem( IOBase* b, UniXML::iterator& it, SMInterface* shm, const
...
@@ -503,6 +551,27 @@ bool IOBase::initItem( IOBase* b, UniXML::iterator& it, SMInterface* shm, const
return
false
;
return
false
;
}
}
string
d_txt
(
initProp
(
it
,
"depend"
,
prefix
,
init_prefix_only
)
);
if
(
!
d_txt
.
empty
()
)
{
b
->
d_id
=
conf
->
getSensorID
(
d_txt
);
if
(
b
->
d_id
==
DefaultObjectId
)
{
if
(
dlog
&&
dlog
->
is_crit
()
)
dlog
->
crit
()
<<
myname
<<
"(IOBase::readItem): sensor='"
<<
it
.
getProp
(
"name"
)
<<
"' err: "
<<
" Unknown SensorID for depend='"
<<
d_txt
<<
endl
;
return
false
;
}
// по умолчанию срабатывание на "1"
b
->
d_value
=
initProp
(
it
,
"depend_value"
,
prefix
,
init_prefix_only
).
empty
()
?
1
:
initIntProp
(
it
,
"depend_value"
,
prefix
,
init_prefix_only
);
b
->
d_off_value
=
initIntProp
(
it
,
"depend_off_value"
,
prefix
,
init_prefix_only
);
b
->
d_iotype
=
conf
->
getIOType
(
b
->
d_id
);
shm
->
initIterator
(
b
->
d_it
);
}
b
->
cal
.
minRaw
=
0
;
b
->
cal
.
minRaw
=
0
;
b
->
cal
.
maxRaw
=
0
;
b
->
cal
.
maxRaw
=
0
;
b
->
cal
.
minCal
=
0
;
b
->
cal
.
minCal
=
0
;
...
@@ -586,7 +655,7 @@ bool IOBase::initItem( IOBase* b, UniXML::iterator& it, SMInterface* shm, const
...
@@ -586,7 +655,7 @@ bool IOBase::initItem( IOBase* b, UniXML::iterator& it, SMInterface* shm, const
string
tai
(
initProp
(
it
,
"threshold_aid"
,
prefix
,
init_prefix_only
));
string
tai
(
initProp
(
it
,
"threshold_aid"
,
prefix
,
init_prefix_only
));
if
(
!
tai
.
empty
()
)
if
(
!
tai
.
empty
()
)
{
{
b
->
t_ai
=
uniset_conf
()
->
getSensorID
(
tai
);
b
->
t_ai
=
conf
->
getSensorID
(
tai
);
if
(
b
->
t_ai
==
DefaultObjectId
)
if
(
b
->
t_ai
==
DefaultObjectId
)
{
{
if
(
dlog
&&
dlog
->
is_crit
()
)
if
(
dlog
&&
dlog
->
is_crit
()
)
...
...
extensions/tests/Makefile.am
View file @
0a1a81dd
...
@@ -11,7 +11,7 @@ tests_with_conf_SOURCES = tests_with_conf.cc test_calibration.cc test_iobase.c
...
@@ -11,7 +11,7 @@ tests_with_conf_SOURCES = tests_with_conf.cc test_calibration.cc test_iobase.c
tests_with_conf_LDADD
=
$(top_builddir)
/lib/libUniSet2.la
$(top_builddir)
/extensions/lib/libUniSet2Extensions.la
tests_with_conf_LDADD
=
$(top_builddir)
/lib/libUniSet2.la
$(top_builddir)
/extensions/lib/libUniSet2Extensions.la
tests_with_conf_CPPFLAGS
=
-I
$(top_builddir)
/include
-I
$(top_builddir)
/extensions/include
tests_with_conf_CPPFLAGS
=
-I
$(top_builddir)
/include
-I
$(top_builddir)
/extensions/include
tests_with_sm_SOURCES
=
tests_with_sm.cc test_ui.cc
tests_with_sm_SOURCES
=
tests_with_sm.cc test_ui.cc
test_iobase_with_sm.cc
tests_with_sm_LDADD
=
$(top_builddir)
/lib/libUniSet2.la
$(top_builddir)
/extensions/lib/libUniSet2Extensions.la
\
tests_with_sm_LDADD
=
$(top_builddir)
/lib/libUniSet2.la
$(top_builddir)
/extensions/lib/libUniSet2Extensions.la
\
$(top_builddir)
/extensions/SharedMemory/libUniSet2SharedMemory.la
$(SIGC_LIBS)
$(COMCPP_LIBS)
$(top_builddir)
/extensions/SharedMemory/libUniSet2SharedMemory.la
$(SIGC_LIBS)
$(COMCPP_LIBS)
tests_with_sm_CPPFLAGS
=
-I
$(top_builddir)
/include
-I
$(top_builddir)
/extensions/include
\
tests_with_sm_CPPFLAGS
=
-I
$(top_builddir)
/include
-I
$(top_builddir)
/extensions/include
\
...
...
extensions/tests/test_iobase.cc
View file @
0a1a81dd
...
@@ -47,6 +47,12 @@ TEST_CASE("IOBase default constructor","[iobase][extensions]")
...
@@ -47,6 +47,12 @@ TEST_CASE("IOBase default constructor","[iobase][extensions]")
CHECK_FALSE
(
ib
.
ondelay_state
);
/*!< значение для задержки включения */
CHECK_FALSE
(
ib
.
ondelay_state
);
/*!< значение для задержки включения */
CHECK_FALSE
(
ib
.
offdelay_state
);
/*!< значение для задержки отключения */
CHECK_FALSE
(
ib
.
offdelay_state
);
/*!< значение для задержки отключения */
// Зависимость (d - depend)
CHECK
(
ib
.
d_id
==
DefaultObjectId
);
/*!< идентификатор датчика, от которого зависит данный */
REQUIRE
(
ib
.
d_value
==
1
)
;
/*!< разрешающее работу значение датчика от которого зависит данный */
REQUIRE
(
ib
.
d_off_value
==
0
);
/*!< блокирующее значение */
REQUIRE
(
ib
.
d_iotype
==
UniversalIO
::
UnknownIOType
);
// Порог
// Порог
REQUIRE
(
ib
.
t_ai
==
DefaultObjectId
);
REQUIRE
(
ib
.
t_ai
==
DefaultObjectId
);
CHECK_FALSE
(
ib
.
front
);
// флаг работы по фронту
CHECK_FALSE
(
ib
.
front
);
// флаг работы по фронту
...
@@ -274,12 +280,3 @@ TEST_CASE("IOBase: channel break","[iobase][extensions]")
...
@@ -274,12 +280,3 @@ TEST_CASE("IOBase: channel break","[iobase][extensions]")
CHECK_FALSE
(
ib
.
check_channel_break
(
breakValue
)
);
CHECK_FALSE
(
ib
.
check_channel_break
(
breakValue
)
);
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
TEST_CASE
(
"IOBase with SM"
,
"[iobase][extensions]"
)
{
WARN
(
"IOBase with SM not yet!"
);
// rawdata
// ignore
// ioinvert
// precision
}
// -----------------------------------------------------------------------------
extensions/tests/test_iobase_with_sm.cc
0 → 100644
View file @
0a1a81dd
#include <catch.hpp>
// -----------------------------------------------------------------------------
#include <memory>
#include "Exceptions.h"
#include "Extensions.h"
#include "tests_with_sm.h"
#include "IOBase.h"
// -----------------------------------------------------------------------------
using
namespace
std
;
using
namespace
UniSetTypes
;
using
namespace
UniSetExtensions
;
// -----------------------------------------------------------------------------
static
SMInterface
*
shm
=
nullptr
;
static
void
init_test
()
{
shm
=
smiInstance
();
CHECK
(
shm
!=
nullptr
);
}
static
bool
init_iobase
(
IOBase
*
ib
,
const
std
::
string
&
sensor
)
{
init_test
();
CHECK
(
shm
!=
nullptr
);
auto
conf
=
uniset_conf
();
xmlNode
*
snode
=
conf
->
getXMLObjectNode
(
conf
->
getSensorID
(
sensor
)
);
CHECK
(
snode
!=
0
);
UniXML
::
iterator
it
(
snode
);
shm
->
initIterator
(
ib
->
d_it
);
shm
->
initIterator
(
ib
->
d_it
);
return
IOBase
::
initItem
(
ib
,
it
,
shm
,
""
,
false
);
}
// -----------------------------------------------------------------------------
TEST_CASE
(
"IOBase: DI depend on the DI"
,
"[iobase][depend][di-di][extensions]"
)
{
CHECK
(
uniset_conf
()
!=
nullptr
);
auto
conf
=
uniset_conf
();
init_test
();
ObjectId
di
=
conf
->
getSensorID
(
"DependTest_DI_S"
);
CHECK
(
di
!=
DefaultObjectId
);
SECTION
(
"DI depend on the DI (depend_value=0).."
)
{
IOBase
ib
;
CHECK
(
init_iobase
(
&
ib
,
"DependTest_DI3_S"
)
);
shm
->
setValue
(
di
,
0
);
CHECK_FALSE
(
ib
.
check_depend
(
shm
)
);
shm
->
setValue
(
di
,
1
);
CHECK
(
ib
.
check_depend
(
shm
)
);
}
SECTION
(
"DI depend on the DI (depend_value=1).."
)
{
IOBase
ib
;
CHECK
(
init_iobase
(
&
ib
,
"DependTest_DI4_S"
)
);
shm
->
setValue
(
di
,
0
);
CHECK
(
ib
.
check_depend
(
shm
)
);
shm
->
setValue
(
di
,
1
);
CHECK_FALSE
(
ib
.
check_depend
(
shm
)
);
}
SECTION
(
"DI depend on the DI (default value)"
)
{
IOBase
ib
;
CHECK
(
init_iobase
(
&
ib
,
"DependTest_DI5_S"
)
);
shm
->
setValue
(
di
,
0
);
CHECK_FALSE
(
ib
.
check_depend
(
shm
)
);
shm
->
setValue
(
di
,
1
);
CHECK
(
ib
.
check_depend
(
shm
)
);
}
}
// -----------------------------------------------------------------------------
TEST_CASE
(
"IOBase: DI depend on the AI"
,
"[iobase][depend][di-ai][extensions]"
)
{
CHECK
(
uniset_conf
()
!=
nullptr
);
auto
conf
=
uniset_conf
();
init_test
();
ObjectId
ai
=
conf
->
getSensorID
(
"DependTest_AI_AS"
);
CHECK
(
ai
!=
DefaultObjectId
);
SECTION
(
"DI depend on the AI (depend_value=0).."
)
{
IOBase
ib
;
CHECK
(
init_iobase
(
&
ib
,
"DependTest_DI1_S"
)
);
shm
->
setValue
(
ai
,
0
);
CHECK_FALSE
(
ib
.
check_depend
(
shm
)
);
shm
->
setValue
(
ai
,
1
);
CHECK
(
ib
.
check_depend
(
shm
)
);
}
SECTION
(
"DI depend on the AI (depend_value=1).."
)
{
IOBase
ib
;
CHECK
(
init_iobase
(
&
ib
,
"DependTest_DI2_S"
)
);
shm
->
setValue
(
ai
,
0
);
CHECK
(
ib
.
check_depend
(
shm
)
);
shm
->
setValue
(
ai
,
1
);
CHECK_FALSE
(
ib
.
check_depend
(
shm
)
);
}
SECTION
(
"DI depend on the AI (default value)"
)
{
IOBase
ib
;
CHECK
(
init_iobase
(
&
ib
,
"DependTest_DI6_S"
)
);
shm
->
setValue
(
ai
,
0
);
CHECK_FALSE
(
ib
.
check_depend
(
shm
)
);
shm
->
setValue
(
ai
,
1
);
CHECK
(
ib
.
check_depend
(
shm
)
);
}
}
// -----------------------------------------------------------------------------
TEST_CASE
(
"IOBase: AI depend on the AI"
,
"[iobase][depend][ai-ai][extensions]"
)
{
CHECK
(
uniset_conf
()
!=
nullptr
);
auto
conf
=
uniset_conf
();
init_test
();
ObjectId
ai
=
conf
->
getSensorID
(
"DependTest_AI_AS"
);
CHECK
(
ai
!=
DefaultObjectId
);
SECTION
(
"AI depend on the AI (depend_value=10).."
)
{
IOBase
ib
;
CHECK
(
init_iobase
(
&
ib
,
"DependTest_AI2_AS"
)
);
shm
->
setValue
(
ai
,
0
);
CHECK_FALSE
(
ib
.
check_depend
(
shm
)
);
IOBase
::
processingAsAI
(
&
ib
,
20
,
shm
,
true
);
REQUIRE
(
shm
->
getValue
(
ib
.
si
.
id
)
==
-
10
);
shm
->
setValue
(
ai
,
10
);
CHECK
(
ib
.
check_depend
(
shm
)
);
IOBase
::
processingAsAI
(
&
ib
,
20
,
shm
,
true
);
REQUIRE
(
shm
->
getValue
(
ib
.
si
.
id
)
==
20
);
shm
->
setValue
(
ai
,
2
);
CHECK_FALSE
(
ib
.
check_depend
(
shm
)
);
IOBase
::
processingAsAI
(
&
ib
,
20
,
shm
,
true
);
REQUIRE
(
shm
->
getValue
(
ib
.
si
.
id
)
==
-
10
);
}
}
// -----------------------------------------------------------------------------
TEST_CASE
(
"IOBase: AO depend on the DI"
,
"[iobase][depend][ao-di][extensions]"
)
{
CHECK
(
uniset_conf
()
!=
nullptr
);
auto
conf
=
uniset_conf
();
init_test
();
ObjectId
di
=
conf
->
getSensorID
(
"DependTest_DI_S"
);
CHECK
(
di
!=
DefaultObjectId
);
SECTION
(
"AO depend on the DI.."
)
{
IOBase
ib
;
CHECK
(
init_iobase
(
&
ib
,
"DependTest_AO2_AS"
)
);
shm
->
setValue
(
di
,
0
);
CHECK_FALSE
(
ib
.
check_depend
(
shm
)
);
REQUIRE
(
IOBase
::
processingAsAO
(
&
ib
,
shm
,
true
)
==
10000
);
shm
->
setValue
(
di
,
1
);
CHECK
(
ib
.
check_depend
(
shm
)
);
REQUIRE
(
IOBase
::
processingAsAO
(
&
ib
,
shm
,
true
)
==
15
);
// 15 - default value (см. tests_with_sm_xml)
shm
->
setValue
(
di
,
0
);
CHECK_FALSE
(
ib
.
check_depend
(
shm
)
);
REQUIRE
(
IOBase
::
processingAsAO
(
&
ib
,
shm
,
true
)
==
10000
);
}
}
// -----------------------------------------------------------------------------
TEST_CASE
(
"IOBase with SM"
,
"[iobase][extensions]"
)
{
WARN
(
"IOBase with SM not yet!"
);
// rawdata
// ignore
// ioinvert
// precision
}
// -----------------------------------------------------------------------------
extensions/tests/tests_with_sm.cc
View file @
0a1a81dd
...
@@ -6,12 +6,42 @@
...
@@ -6,12 +6,42 @@
#include "UniSetActivator.h"
#include "UniSetActivator.h"
#include "PassiveTimer.h"
#include "PassiveTimer.h"
#include "SharedMemory.h"
#include "SharedMemory.h"
#include "SMInterface.h"
#include "Extensions.h"
#include "Extensions.h"
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
using
namespace
std
;
using
namespace
std
;
using
namespace
UniSetTypes
;
using
namespace
UniSetTypes
;
using
namespace
UniSetExtensions
;
using
namespace
UniSetExtensions
;
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
static
SMInterface
*
smi
=
nullptr
;
static
SharedMemory
*
shm
=
nullptr
;
static
UInterface
*
ui
=
nullptr
;
static
ObjectId
myID
=
6000
;
// --------------------------------------------------------------------------
SharedMemory
*
shmInstance
()
{
if
(
shm
==
nullptr
)
throw
SystemError
(
"SharedMemory don`t initialize.."
);
return
shm
;
}
// --------------------------------------------------------------------------
SMInterface
*
smiInstance
()
{
if
(
smi
==
nullptr
)
{
if
(
shm
==
nullptr
)
throw
SystemError
(
"SharedMemory don`t initialize.."
);
if
(
ui
==
nullptr
)
ui
=
new
UInterface
();
smi
=
new
SMInterface
(
shm
->
getId
(),
ui
,
myID
,
shm
);
}
return
smi
;
}
// --------------------------------------------------------------------------
int
main
(
int
argc
,
char
*
argv
[]
)
int
main
(
int
argc
,
char
*
argv
[]
)
{
{
Catch
::
Session
session
;
Catch
::
Session
session
;
...
@@ -38,7 +68,7 @@ int main(int argc, char* argv[] )
...
@@ -38,7 +68,7 @@ int main(int argc, char* argv[] )
ulog.logFile( logname );
ulog.logFile( logname );
dlog.logFile( logname );
dlog.logFile( logname );
*/
*/
SharedMemory
*
shm
=
SharedMemory
::
init_smemory
(
argc
,
argv
);
shm
=
SharedMemory
::
init_smemory
(
argc
,
argv
);
if
(
!
shm
)
if
(
!
shm
)
return
1
;
return
1
;
...
...
extensions/tests/tests_with_sm.h
0 → 100644
View file @
0a1a81dd
#ifndef tests_with_sm_H_
#define tests_with_sm_H_
// --------------------------------------------------------------------------
#include <memory>
#include "SharedMemory.h"
#include "SMInterface.h"
// --------------------------------------------------------------------------
// Для некоторых тестов необходим SMInterface инициализированный для работы с SharedMemory
// поэтому сделана такая специальная функция
// реализацию смотри в tests_with_sm.cc
SMInterface
*
smiInstance
();
SharedMemory
*
shmInstance
();
// --------------------------------------------------------------------------
#endif // tests_with_sm_H_
\ No newline at end of file
extensions/tests/tests_with_sm.xml
View file @
0a1a81dd
...
@@ -231,8 +231,6 @@
...
@@ -231,8 +231,6 @@
<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=
"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=
"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=
"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:20:U:U"
/>
<item
id=
"55"
iotype=
"AI"
name=
"AI55_S"
textname=
"AI sensor 55"
rrd=
"1"
rrd1_ds=
"GAUGE:20:U:U"
/>
<item
id=
"56"
iotype=
"AI"
name=
"AI56_S"
textname=
"AI sensor 56"
rrd=
"2"
rrd2_ds=
"COUNTER:20:U:U"
/>
<item
id=
"56"
iotype=
"AI"
name=
"AI56_S"
textname=
"AI sensor 56"
rrd=
"2"
rrd2_ds=
"COUNTER:20:U:U"
/>
<item
id=
"57"
iotype=
"AI"
name=
"AI57_S"
textname=
"AI sensor 57"
rrd=
"2"
rrd2_ds=
"DERIVE:20:U:U"
/>
<item
id=
"57"
iotype=
"AI"
name=
"AI57_S"
textname=
"AI sensor 57"
rrd=
"2"
rrd2_ds=
"DERIVE:20:U:U"
/>
<item
id=
"58"
iotype=
"AO"
name=
"Lamp58_C"
textname=
"Lamp 58"
rrd=
"1"
rrd1_ds=
"GAUGE:20:U:U"
/>
<item
id=
"58"
iotype=
"AO"
name=
"Lamp58_C"
textname=
"Lamp 58"
rrd=
"1"
rrd1_ds=
"GAUGE:20:U:U"
/>
...
@@ -240,6 +238,23 @@
...
@@ -240,6 +238,23 @@
<item
id=
"63"
iotype=
"AI"
name=
"SVU_AskCount_AS"
textname=
"svu asl count"
/>
<item
id=
"63"
iotype=
"AI"
name=
"SVU_AskCount_AS"
textname=
"svu asl count"
/>
<item
id=
"64"
iotype=
"AI"
name=
"AI64_AS"
textname=
"AI64"
mbaddr=
"0x01"
mbfunc=
"0x03"
mbreg=
"64"
mbtype=
"rtu"
rs=
"5"
/>
<item
id=
"64"
iotype=
"AI"
name=
"AI64_AS"
textname=
"AI64"
mbaddr=
"0x01"
mbfunc=
"0x03"
mbreg=
"64"
mbtype=
"rtu"
rs=
"5"
/>
<item
id=
"65"
iotype=
"DI"
name=
"D65_S"
textname=
"D65"
threshold_aid=
"AI64_AS"
lowlimit=
"3"
hilimit=
"5"
threshold_invert=
"1"
rs=
"5"
/>
<item
id=
"65"
iotype=
"DI"
name=
"D65_S"
textname=
"D65"
threshold_aid=
"AI64_AS"
lowlimit=
"3"
hilimit=
"5"
threshold_invert=
"1"
rs=
"5"
/>
<!-- Depend test -->
<item
id=
"100"
iotype=
"AI"
name=
"DependTest_AI_AS"
textname=
"Depend test: AI1"
/>
<item
id=
"101"
iotype=
"AI"
name=
"DependTest_AI2_AS"
textname=
"Depend test: AI2"
depend=
"DependTest_AI_AS"
depend_value=
"10"
depend_off_value=
"-10"
/>
<item
id=
"103"
iotype=
"DI"
name=
"DependTest_DI1_S"
textname=
"Depend test: DI1"
depend=
"DependTest_AI_AS"
depend_value=
"1"
depend_off_value=
"0"
/>
<item
id=
"104"
iotype=
"DI"
name=
"DependTest_DI2_S"
textname=
"Depend test: DI2"
depend=
"DependTest_AI_AS"
depend_value=
"0"
depend_off_value=
"1"
/>
<item
id=
"112"
iotype=
"DI"
name=
"DependTest_DI6_S"
textname=
"Depend test: DI6"
depend=
"DependTest_AI_AS"
/>
<item
id=
"105"
iotype=
"AO"
name=
"DependTest_AO1_AS"
textname=
"Depend test: AO1"
depend=
"DependTest_AI_AS"
depend_value=
"10"
depend_off_value=
"10000"
/>
<item
id=
"106"
iotype=
"DO"
name=
"DependTest_DO1_S"
textname=
"Depend test: DO1"
depend=
"DependTest_AI_AS"
depend_value=
"-10"
depend_off_value=
"2"
/>
<item
id=
"107"
iotype=
"DI"
name=
"DependTest_DI_S"
textname=
"Depend test: DI"
/>
<item
id=
"108"
iotype=
"DI"
name=
"DependTest_DI3_S"
textname=
"Depend test: DI3"
depend=
"DependTest_DI_S"
depend_value=
"1"
depend_off_value=
"0"
/>
<item
id=
"109"
iotype=
"DI"
name=
"DependTest_DI4_S"
textname=
"Depend test: DI4"
depend=
"DependTest_DI_S"
depend_value=
"0"
depend_off_value=
"0"
/>
<item
id=
"110"
iotype=
"DI"
name=
"DependTest_DI5_S"
textname=
"Depend test: DI5"
depend=
"DependTest_DI_S"
/>
<item
id=
"111"
iotype=
"DO"
name=
"DependTest_DO2_S"
textname=
"Depend test: DO2"
depend=
"DependTest_DI_S"
depend_value=
"1"
depend_off_value=
"0"
/>
<item
id=
"113"
iotype=
"AO"
name=
"DependTest_AO2_AS"
textname=
"Depend test: AO2"
depend=
"DependTest_DI_S"
depend_value=
"1"
depend_off_value=
"10000"
default=
"15"
/>
</sensors>
</sensors>
<thresholds
name=
"thresholds"
>
<thresholds
name=
"thresholds"
>
<sensor
iotype=
"AI"
name=
"AI_AS"
>
<sensor
iotype=
"AI"
name=
"AI_AS"
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment