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
f49ef02c
Commit
f49ef02c
authored
May 04, 2015
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(LogicProcessor): рефакторинг, сделал тест основного функционала
parent
7388b589
Hide whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
610 additions
and
145 deletions
+610
-145
Element.cc
extensions/LogicProcessor/Element.cc
+11
-20
Element.h
extensions/LogicProcessor/Element.h
+12
-8
LProcessor.cc
extensions/LogicProcessor/LProcessor.cc
+32
-13
LProcessor.h
extensions/LogicProcessor/LProcessor.h
+34
-6
Makefile.am
extensions/LogicProcessor/Makefile.am
+1
-1
PassiveLProcessor.cc
extensions/LogicProcessor/PassiveLProcessor.cc
+1
-1
Schema.cc
extensions/LogicProcessor/Schema.cc
+30
-26
Schema.h
extensions/LogicProcessor/Schema.h
+49
-45
SchemaXML.cc
extensions/LogicProcessor/SchemaXML.cc
+11
-10
Makefile.am
extensions/LogicProcessor/tests/Makefile.am
+3
-3
NullSM.cc
extensions/LogicProcessor/tests/NullSM.cc
+20
-0
NullSM.h
extensions/LogicProcessor/tests/NullSM.h
+29
-0
exist.sh
extensions/LogicProcessor/tests/exist.sh
+3
-0
lp-configure.xml
extensions/LogicProcessor/tests/lp-configure.xml
+67
-0
lp_schema.xml
extensions/LogicProcessor/tests/lp_schema.xml
+44
-0
lproc-tests.at
extensions/LogicProcessor/tests/lproc-tests.at
+1
-1
lproc.cc
extensions/LogicProcessor/tests/lproc.cc
+164
-7
smview.sh
extensions/LogicProcessor/tests/smview.sh
+3
-0
tests.cc
extensions/LogicProcessor/tests/tests.cc
+80
-2
tests.sh
extensions/LogicProcessor/tests/tests.sh
+8
-0
uniset2-admin
extensions/LogicProcessor/tests/uniset2-admin
+2
-0
uniset2-functions.sh
extensions/LogicProcessor/tests/uniset2-functions.sh
+2
-0
uniset2-start.sh
extensions/LogicProcessor/tests/uniset2-start.sh
+2
-0
Makefile.am
extensions/Makefile.am
+1
-1
NullSM.h
extensions/SharedMemory/tests/NullSM.h
+0
-1
No files found.
extensions/LogicProcessor/Element.cc
View file @
f49ef02c
...
@@ -7,9 +7,9 @@ using namespace std;
...
@@ -7,9 +7,9 @@ using namespace std;
const
Element
::
ElementID
Element
::
DefaultElementID
=
"?id?"
;
const
Element
::
ElementID
Element
::
DefaultElementID
=
"?id?"
;
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
void
Element
::
addChildOut
(
Element
*
el
,
int
num
)
void
Element
::
addChildOut
(
std
::
shared_ptr
<
Element
>
el
,
int
num
)
{
{
if
(
el
==
this
)
if
(
el
.
get
()
==
this
)
{
{
ostringstream
msg
;
ostringstream
msg
;
msg
<<
"("
<<
myid
<<
"): ПОПТКА СДЕЛАТь ССЫЛКУ НА САМОГО СЕБЯ!!!"
;
msg
<<
"("
<<
myid
<<
"): ПОПТКА СДЕЛАТь ССЫЛКУ НА САМОГО СЕБЯ!!!"
;
...
@@ -17,7 +17,7 @@ void Element::addChildOut( Element* el, int num )
...
@@ -17,7 +17,7 @@ void Element::addChildOut( Element* el, int num )
}
}
for
(
auto
&
it
:
outs
)
for
(
const
auto
&
it
:
outs
)
{
{
if
(
it
.
el
==
el
)
if
(
it
.
el
==
el
)
{
{
...
@@ -37,10 +37,10 @@ void Element::addChildOut( Element* el, int num )
...
@@ -37,10 +37,10 @@ void Element::addChildOut( Element* el, int num )
throw
LogicException
(
msg
.
str
());
throw
LogicException
(
msg
.
str
());
}
}
outs
.
push_front
(
ChildInfo
(
el
,
num
)
);
outs
.
emplace_front
(
el
,
num
);
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
void
Element
::
delChildOut
(
Element
*
el
)
void
Element
::
delChildOut
(
std
::
shared_ptr
<
Element
>
el
)
{
{
for
(
auto
it
=
outs
.
begin
();
it
!=
outs
.
end
();
++
it
)
for
(
auto
it
=
outs
.
begin
();
it
!=
outs
.
end
();
++
it
)
{
{
...
@@ -55,32 +55,23 @@ void Element::delChildOut( Element* el )
...
@@ -55,32 +55,23 @@ void Element::delChildOut( Element* el )
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
void
Element
::
setChildOut
()
void
Element
::
setChildOut
()
{
{
bool
_myout
(
getOut
()
);
bool
_myout
=
getOut
(
);
for
(
auto
&
it
:
outs
)
for
(
auto
&&
it
:
outs
)
{
// try
// {
it
.
el
->
setIn
(
it
.
num
,
_myout
);
it
.
el
->
setIn
(
it
.
num
,
_myout
);
// }
// catch(...){}
}
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
Element
*
Element
::
find
(
ElementID
id
)
std
::
shared_ptr
<
Element
>
Element
::
find
(
ElementID
id
)
{
{
for
(
auto
&
it
:
outs
)
for
(
const
auto
&
it
:
outs
)
{
{
if
(
it
.
el
->
getId
()
==
id
)
if
(
it
.
el
->
getId
()
==
id
)
return
it
.
el
;
return
it
.
el
;
Element
*
el
(
it
.
el
->
find
(
id
)
);
return
it
.
el
->
find
(
id
);
if
(
el
!=
NULL
)
return
el
;
}
}
return
0
;
return
nullptr
;
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
void
Element
::
addInput
(
int
num
,
bool
state
)
void
Element
::
addInput
(
int
num
,
bool
state
)
...
...
extensions/LogicProcessor/Element.h
View file @
f49ef02c
#ifndef Element_H_
#ifndef Element_H_
#define Element_H_
#define Element_H_
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
#include <memory>
#include <string>
#include <string>
#include <list>
#include <list>
#include <ostream>
#include <ostream>
...
@@ -53,10 +54,10 @@ class Element
...
@@ -53,10 +54,10 @@ class Element
return
"?type?"
;
return
"?type?"
;
}
}
virtual
Element
*
find
(
ElementID
id
);
virtual
std
::
shared_ptr
<
Element
>
find
(
ElementID
id
);
virtual
void
addChildOut
(
Element
*
el
,
int
in_num
);
virtual
void
addChildOut
(
std
::
shared_ptr
<
Element
>
el
,
int
in_num
);
virtual
void
delChildOut
(
Element
*
el
);
virtual
void
delChildOut
(
std
::
shared_ptr
<
Element
>
el
);
inline
int
outCount
()
inline
int
outCount
()
{
{
return
outs
.
size
();
return
outs
.
size
();
...
@@ -71,12 +72,15 @@ class Element
...
@@ -71,12 +72,15 @@ class Element
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
Element
&
el
)
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
Element
&
el
)
{
{
return
os
<<
el
.
getType
()
<<
"("
<<
el
.
getId
()
<<
")"
;
return
os
<<
"["
<<
el
.
getType
()
<<
"]"
<<
el
.
getId
()
;
}
}
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
Element
*
el
)
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
std
::
shared_ptr
<
Element
>
el
)
{
{
return
os
<<
(
*
el
);
if
(
el
)
return
os
<<
(
*
(
el
.
get
()));
return
os
;
}
}
protected
:
protected
:
...
@@ -84,11 +88,11 @@ class Element
...
@@ -84,11 +88,11 @@ class Element
struct
ChildInfo
struct
ChildInfo
{
{
ChildInfo
(
Element
*
e
,
int
n
)
:
ChildInfo
(
std
::
shared_ptr
<
Element
>
e
,
int
n
)
:
el
(
e
),
num
(
n
)
{}
el
(
e
),
num
(
n
)
{}
ChildInfo
()
:
el
(
0
),
num
(
0
)
{}
ChildInfo
()
:
el
(
0
),
num
(
0
)
{}
Element
*
el
;
std
::
shared_ptr
<
Element
>
el
;
int
num
;
int
num
;
};
};
...
...
extensions/LogicProcessor/LProcessor.cc
View file @
f49ef02c
#include <iostream>
#include <iostream>
#include <algorithm>
#include "Configuration.h"
#include "Configuration.h"
#include "Extensions.h"
#include "Extensions.h"
#include "PassiveTimer.h"
#include "PassiveTimer.h"
...
@@ -19,17 +20,33 @@ LProcessor::LProcessor( const std::string& name ):
...
@@ -19,17 +20,33 @@ LProcessor::LProcessor( const std::string& name ):
smReadyTimeout
=
60000
;
smReadyTimeout
=
60000
;
else
if
(
smReadyTimeout
<
0
)
else
if
(
smReadyTimeout
<
0
)
smReadyTimeout
=
UniSetTimer
::
WaitUpTime
;
smReadyTimeout
=
UniSetTimer
::
WaitUpTime
;
sch
=
make_shared
<
SchemaXML
>
();
}
}
LProcessor
::~
LProcessor
()
LProcessor
::~
LProcessor
()
{
{
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
void
LProcessor
::
execute
(
const
string
&
lfile
)
void
LProcessor
::
open
(
const
string
&
lfile
)
{
{
if
(
isOpen
()
)
{
ostringstream
err
;
err
<<
logname
<<
"(execute): already opened from '"
<<
fSchema
<<
"'"
<<
endl
;
throw
SystemError
(
err
.
str
());
}
fSchema
=
lfile
;
build
(
lfile
);
build
(
lfile
);
}
// -------------------------------------------------------------------------
void
LProcessor
::
execute
(
const
std
::
string
&
lfile
)
{
if
(
!
lfile
.
empty
()
)
open
(
lfile
);
while
(
1
)
while
(
!
canceled
)
{
{
try
try
{
{
...
@@ -63,11 +80,11 @@ void LProcessor::build( const string& lfile )
...
@@ -63,11 +80,11 @@ void LProcessor::build( const string& lfile )
{
{
auto
conf
=
uniset_conf
();
auto
conf
=
uniset_conf
();
sch
.
read
(
lfile
);
sch
->
read
(
lfile
);
// составляем карту внешних входов
// составляем карту внешних входов
// считая, что в поле name записано название датчика
// считая, что в поле name записано название датчика
for
(
Schema
::
EXTiterator
it
=
sch
.
extBegin
();
it
!=
sch
.
extEnd
();
++
it
)
for
(
auto
it
=
sch
->
extBegin
();
it
!=
sch
->
extEnd
();
++
it
)
{
{
UniSetTypes
::
ObjectId
sid
=
conf
->
getSensorID
(
it
->
name
);
UniSetTypes
::
ObjectId
sid
=
conf
->
getSensorID
(
it
->
name
);
...
@@ -80,8 +97,9 @@ void LProcessor::build( const string& lfile )
...
@@ -80,8 +97,9 @@ void LProcessor::build( const string& lfile )
EXTInfo
ei
;
EXTInfo
ei
;
ei
.
sid
=
sid
;
ei
.
sid
=
sid
;
ei
.
state
=
false
;
ei
.
state
=
false
;
ei
.
lnk
=
&
(
*
it
)
;
ei
.
el
=
it
->
to
;
ei
.
iotype
=
conf
->
getIOType
(
sid
);
ei
.
iotype
=
conf
->
getIOType
(
sid
);
ei
.
numInput
=
it
->
numInput
;
if
(
ei
.
iotype
==
UniversalIO
::
UnknownIOType
)
if
(
ei
.
iotype
==
UniversalIO
::
UnknownIOType
)
{
{
...
@@ -92,7 +110,7 @@ void LProcessor::build( const string& lfile )
...
@@ -92,7 +110,7 @@ void LProcessor::build( const string& lfile )
extInputs
.
push_front
(
ei
);
extInputs
.
push_front
(
ei
);
}
}
for
(
Schema
::
OUTiterator
it
=
sch
.
outBegin
();
it
!=
sch
.
outEnd
();
++
it
)
for
(
auto
it
=
sch
->
outBegin
();
it
!=
sch
->
outEnd
();
++
it
)
{
{
UniSetTypes
::
ObjectId
sid
=
conf
->
getSensorID
(
it
->
name
);
UniSetTypes
::
ObjectId
sid
=
conf
->
getSensorID
(
it
->
name
);
...
@@ -104,7 +122,7 @@ void LProcessor::build( const string& lfile )
...
@@ -104,7 +122,7 @@ void LProcessor::build( const string& lfile )
EXTOutInfo
ei
;
EXTOutInfo
ei
;
ei
.
sid
=
sid
;
ei
.
sid
=
sid
;
ei
.
lnk
=
&
(
*
it
)
;
ei
.
el
=
it
->
from
;
ei
.
iotype
=
conf
->
getIOType
(
sid
);
ei
.
iotype
=
conf
->
getIOType
(
sid
);
if
(
ei
.
iotype
==
UniversalIO
::
UnknownIOType
)
if
(
ei
.
iotype
==
UniversalIO
::
UnknownIOType
)
...
@@ -115,7 +133,6 @@ void LProcessor::build( const string& lfile )
...
@@ -115,7 +133,6 @@ void LProcessor::build( const string& lfile )
extOuts
.
push_front
(
ei
);
extOuts
.
push_front
(
ei
);
}
}
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
/*!
/*!
...
@@ -138,22 +155,24 @@ void LProcessor::getInputs()
...
@@ -138,22 +155,24 @@ void LProcessor::getInputs()
void
LProcessor
::
processing
()
void
LProcessor
::
processing
()
{
{
// выcтавляем все внешние входы
// выcтавляем все внешние входы
for
(
auto
&
it
:
extInputs
)
for
(
const
auto
&
it
:
extInputs
)
it
.
lnk
->
to
->
setIn
(
it
.
lnk
->
numInput
,
it
.
state
);
it
.
el
->
setIn
(
it
.
numInput
,
it
.
state
);
// проходим по всем элементам
// проходим по всем элементам
for
(
auto
&
it
:
sch
)
for_each
(
sch
->
begin
(),
sch
->
end
(),
[](
Schema
::
ElementMap
::
value_type
it
)
{
it
.
second
->
tick
();
it
.
second
->
tick
();
}
);
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
void
LProcessor
::
setOuts
()
void
LProcessor
::
setOuts
()
{
{
// выcтавляем выходы
// выcтавляем выходы
for
(
auto
&
it
:
extOuts
)
for
(
const
auto
&
it
:
extOuts
)
{
{
try
try
{
{
ui
.
setValue
(
it
.
sid
,
it
.
lnk
->
from
->
getOut
(),
DefaultObjectId
);
ui
.
setValue
(
it
.
sid
,
it
.
el
->
getOut
(),
DefaultObjectId
);
}
}
catch
(
const
Exception
&
ex
)
catch
(
const
Exception
&
ex
)
{
{
...
...
extensions/LogicProcessor/LProcessor.h
View file @
f49ef02c
...
@@ -85,7 +85,8 @@
...
@@ -85,7 +85,8 @@
Логика исполняется в порядке следования в файле, сверху вниз (в порядке считывания из файла).
Логика исполняется в порядке следования в файле, сверху вниз (в порядке считывания из файла).
*/
*/
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
#include <map>
#include <list>
#include <atomic>
#include "UniSetTypes.h"
#include "UniSetTypes.h"
#include "UInterface.h"
#include "UInterface.h"
#include "Element.h"
#include "Element.h"
...
@@ -97,7 +98,30 @@ class LProcessor
...
@@ -97,7 +98,30 @@ class LProcessor
LProcessor
(
const
std
::
string
&
name
=
""
);
LProcessor
(
const
std
::
string
&
name
=
""
);
virtual
~
LProcessor
();
virtual
~
LProcessor
();
virtual
void
execute
(
const
string
&
lfile
);
void
open
(
const
std
::
string
&
lfile
);
inline
bool
isOpen
()
{
return
!
fSchema
.
empty
();
}
virtual
void
execute
(
const
std
::
string
&
lfile
=
""
);
virtual
void
terminate
()
{
canceled
=
true
;
}
inline
std
::
shared_ptr
<
SchemaXML
>
getScheme
()
{
return
sch
;
}
inline
int
getSleepTime
()
{
return
sleepTime
;
}
protected
:
protected
:
...
@@ -114,14 +138,15 @@ class LProcessor
...
@@ -114,14 +138,15 @@ class LProcessor
UniSetTypes
::
ObjectId
sid
;
UniSetTypes
::
ObjectId
sid
;
UniversalIO
::
IOType
iotype
;
UniversalIO
::
IOType
iotype
;
bool
state
;
bool
state
;
const
Schema
::
EXTLink
*
lnk
;
std
::
shared_ptr
<
Element
>
el
;
int
numInput
=
{
-
1
};
};
};
struct
EXTOutInfo
struct
EXTOutInfo
{
{
UniSetTypes
::
ObjectId
sid
;
UniSetTypes
::
ObjectId
sid
;
UniversalIO
::
IOType
iotype
;
UniversalIO
::
IOType
iotype
;
const
Schema
::
EXTOut
*
lnk
;
std
::
shared_ptr
<
Element
>
el
;
};
};
typedef
std
::
list
<
EXTInfo
>
EXTList
;
typedef
std
::
list
<
EXTInfo
>
EXTList
;
...
@@ -129,7 +154,8 @@ class LProcessor
...
@@ -129,7 +154,8 @@ class LProcessor
EXTList
extInputs
;
EXTList
extInputs
;
OUTList
extOuts
;
OUTList
extOuts
;
SchemaXML
sch
;
std
::
shared_ptr
<
SchemaXML
>
sch
;
UInterface
ui
;
UInterface
ui
;
int
sleepTime
;
int
sleepTime
;
...
@@ -137,9 +163,11 @@ class LProcessor
...
@@ -137,9 +163,11 @@ class LProcessor
std
::
string
logname
;
std
::
string
logname
;
private
:
std
::
atomic_bool
canceled
=
{
false
};
std
::
string
fSchema
=
{
""
};
private
:
};
};
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
#endif
#endif
extensions/LogicProcessor/Makefile.am
View file @
f49ef02c
...
@@ -43,7 +43,7 @@ pkgconfig_DATA = libUniSet2LogicProcessor.pc
...
@@ -43,7 +43,7 @@ pkgconfig_DATA = libUniSet2LogicProcessor.pc
all-local
:
all-local
:
ln
-sf
../LogicProcessor/
$(devel_include_HEADERS)
../include
ln
-sf
../LogicProcessor/
$(devel_include_HEADERS)
../include
SUBDIRS
=
tests
#
SUBDIRS=tests
include
$(top_builddir)/include.mk
include
$(top_builddir)/include.mk
...
...
extensions/LogicProcessor/PassiveLProcessor.cc
View file @
f49ef02c
...
@@ -200,7 +200,7 @@ void PassiveLProcessor::setOuts()
...
@@ -200,7 +200,7 @@ void PassiveLProcessor::setOuts()
{
{
try
try
{
{
shm
->
setValue
(
it
.
sid
,
it
.
lnk
->
from
->
getOut
()
);
shm
->
setValue
(
it
.
sid
,
it
.
el
->
getOut
()
);
}
}
catch
(
const
Exception
&
ex
)
catch
(
const
Exception
&
ex
)
{
{
...
...
extensions/LogicProcessor/Schema.cc
View file @
f49ef02c
...
@@ -13,20 +13,12 @@ Schema::Schema()
...
@@ -13,20 +13,12 @@ Schema::Schema()
Schema
::~
Schema
()
Schema
::~
Schema
()
{
{
for
(
auto
&
it
:
emap
)
{
if
(
it
.
second
!=
0
)
{
delete
it
.
second
;
it
.
second
=
0
;
}
}
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
void
Schema
::
link
(
Element
::
ElementID
rootID
,
Element
::
ElementID
childID
,
int
numIn
)
void
Schema
::
link
(
Element
::
ElementID
rootID
,
Element
::
ElementID
childID
,
int
numIn
)
{
{
Element
*
e1
=
0
;
std
::
shared_ptr
<
Element
>
e1
;
Element
*
e2
=
0
;
std
::
shared_ptr
<
Element
>
e2
;
auto
it
=
emap
.
find
(
rootID
);
auto
it
=
emap
.
find
(
rootID
);
...
@@ -58,8 +50,8 @@ void Schema::link( Element::ElementID rootID, Element::ElementID childID, int nu
...
@@ -58,8 +50,8 @@ void Schema::link( Element::ElementID rootID, Element::ElementID childID, int nu
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
void
Schema
::
unlink
(
Element
::
ElementID
rootID
,
Element
::
ElementID
childID
)
void
Schema
::
unlink
(
Element
::
ElementID
rootID
,
Element
::
ElementID
childID
)
{
{
Element
*
e1
(
0
)
;
std
::
shared_ptr
<
Element
>
e1
;
Element
*
e2
(
0
)
;
std
::
shared_ptr
<
Element
>
e2
;
auto
it
=
emap
.
find
(
rootID
);
auto
it
=
emap
.
find
(
rootID
);
...
@@ -86,7 +78,7 @@ void Schema::unlink( Element::ElementID rootID, Element::ElementID childID )
...
@@ -86,7 +78,7 @@ void Schema::unlink( Element::ElementID rootID, Element::ElementID childID )
e1
->
delChildOut
(
e2
);
e1
->
delChildOut
(
e2
);
// удаляем из списка соединений
// удаляем из списка соединений
for
(
auto
lit
=
inLinks
.
begin
();
lit
!=
inLinks
.
end
();
++
lit
)
for
(
auto
&&
lit
=
inLinks
.
begin
();
lit
!=
inLinks
.
end
();
++
lit
)
{
{
if
(
lit
->
from
==
e1
&&
lit
->
to
==
e2
)
if
(
lit
->
from
==
e1
&&
lit
->
to
==
e2
)
{
{
...
@@ -107,7 +99,7 @@ void Schema::extlink( const string& name, Element::ElementID childID, int numIn
...
@@ -107,7 +99,7 @@ void Schema::extlink( const string& name, Element::ElementID childID, int numIn
throw
LogicException
(
msg
.
str
());
throw
LogicException
(
msg
.
str
());
}
}
Element
*
el
(
it
->
second
);
auto
el
(
it
->
second
);
// добавляем новое соединение
// добавляем новое соединение
// el->addInput(numIn);
// el->addInput(numIn);
...
@@ -117,7 +109,7 @@ void Schema::extlink( const string& name, Element::ElementID childID, int numIn
...
@@ -117,7 +109,7 @@ void Schema::extlink( const string& name, Element::ElementID childID, int numIn
extLinks
.
push_front
(
EXTLink
(
name
,
el
,
numIn
)
);
extLinks
.
push_front
(
EXTLink
(
name
,
el
,
numIn
)
);
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
Element
*
Schema
::
manage
(
Element
*
el
)
std
::
shared_ptr
<
Element
>
Schema
::
manage
(
std
::
shared_ptr
<
Element
>
el
)
{
{
dinfo
<<
"Schema: manage new element id="
<<
el
->
getId
()
dinfo
<<
"Schema: manage new element id="
<<
el
->
getId
()
<<
" type="
<<
el
->
getType
()
<<
" type="
<<
el
->
getType
()
...
@@ -127,19 +119,19 @@ Element* Schema::manage( Element* el )
...
@@ -127,19 +119,19 @@ Element* Schema::manage( Element* el )
return
el
;
return
el
;
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
void
Schema
::
remove
(
Element
*
el
)
void
Schema
::
remove
(
std
::
shared_ptr
<
Element
>
el
)
{
{
for
(
auto
it
=
emap
.
begin
();
it
!=
emap
.
end
();
++
it
)
for
(
auto
&&
it
=
emap
.
begin
();
it
!=
emap
.
end
();
++
it
)
{
{
if
(
it
->
second
!
=
el
)
if
(
it
->
second
=
=
el
)
{
{
emap
.
erase
(
it
);
emap
.
erase
(
it
);
return
;
break
;
}
}
}
}
// помечаем внутренние связи
// помечаем внутренние связи
for
(
auto
&
lit
:
inLinks
)
for
(
auto
&
&
lit
:
inLinks
)
{
{
if
(
lit
.
from
==
el
)
if
(
lit
.
from
==
el
)
lit
.
from
=
0
;
lit
.
from
=
0
;
...
@@ -149,7 +141,7 @@ void Schema::remove( Element* el )
...
@@ -149,7 +141,7 @@ void Schema::remove( Element* el )
}
}
// помечаем внешние связи
// помечаем внешние связи
for
(
auto
&
lit
:
extLinks
)
for
(
auto
&
&
lit
:
extLinks
)
{
{
if
(
lit
.
to
==
el
)
if
(
lit
.
to
==
el
)
lit
.
to
=
0
;
lit
.
to
=
0
;
...
@@ -177,25 +169,37 @@ bool Schema::getOut( Element::ElementID ID )
...
@@ -177,25 +169,37 @@ bool Schema::getOut( Element::ElementID ID )
throw
LogicException
(
msg
.
str
());
throw
LogicException
(
msg
.
str
());
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
Element
*
Schema
::
find
(
Element
::
ElementID
id
)
std
::
shared_ptr
<
Element
>
Schema
::
find
(
Element
::
ElementID
id
)
{
{
auto
it
=
emap
.
find
(
id
);
auto
it
=
emap
.
find
(
id
);
if
(
it
!=
emap
.
end
()
)
if
(
it
!=
emap
.
end
()
)
return
it
->
second
;
return
it
->
second
;
return
0
;
return
nullptr
;
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
Element
*
Schema
::
findExtLink
(
const
string
&
name
)
std
::
shared_ptr
<
Element
>
Schema
::
findExtLink
(
const
string
&
name
)
{
{
// помечаем внешние связи
// помечаем внешние связи
for
(
auto
&
it
:
extLinks
)
for
(
const
auto
&
it
:
extLinks
)
{
{
if
(
it
.
name
==
name
)
if
(
it
.
name
==
name
)
return
it
.
to
;
return
it
.
to
;
}
}
return
0
;
return
nullptr
;
}
// -------------------------------------------------------------------------
std
::
shared_ptr
<
Element
>
Schema
::
findOut
(
const
string
&
name
)
{
// помечаем внешние связи
for
(
const
auto
&
it
:
outList
)
{
if
(
it
.
name
==
name
)
return
it
.
from
;
}
return
nullptr
;
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
extensions/LogicProcessor/Schema.h
View file @
f49ef02c
#ifndef Schema_H_
#ifndef Schema_H_
#define Schema_H_
#define Schema_H_
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
#include <memory>
#include <unordered_map>
#include <unordered_map>
#include "Element.h"
#include "Element.h"
#include "Schema.h"
#include "Schema.h"
...
@@ -11,46 +12,9 @@ class Schema
...
@@ -11,46 +12,9 @@ class Schema
Schema
();
Schema
();
virtual
~
Schema
();
virtual
~
Schema
();
Element
*
manage
(
Element
*
el
);
std
::
shared_ptr
<
Element
>
manage
(
std
::
shared_ptr
<
Element
>
el
);
void
remove
(
Element
*
el
);
// внутренее соединения
// между элементами
struct
INLink
{
INLink
(
Element
*
f
,
Element
*
t
,
int
ni
)
:
from
(
f
),
to
(
t
),
numInput
(
ni
)
{}
INLink
()
:
from
(
0
),
to
(
0
),
numInput
(
0
)
{}
Element
*
from
;
Element
*
to
;
int
numInput
;
};
// внешнее соединение
// что-то на вход элемента
struct
EXTLink
{
EXTLink
(
std
::
string
n
,
Element
*
t
,
int
ni
)
:
name
(
n
),
to
(
t
),
numInput
(
ni
)
{}
EXTLink
()
:
name
(
""
),
to
(
0
),
numInput
(
0
)
{}
std
::
string
name
;
Element
*
to
;
int
numInput
;
};
// наружный выход
struct
EXTOut
{
EXTOut
(
std
::
string
n
,
Element
*
f
)
:
name
(
n
),
from
(
f
)
{}
EXTOut
()
:
name
(
""
),
from
(
0
)
{}
std
::
string
name
;
Element
*
from
;
};
void
remove
(
std
::
shared_ptr
<
Element
>
el
);
void
link
(
Element
::
ElementID
rootID
,
Element
::
ElementID
childID
,
int
numIn
);
void
link
(
Element
::
ElementID
rootID
,
Element
::
ElementID
childID
,
int
numIn
);
void
unlink
(
Element
::
ElementID
rootID
,
Element
::
ElementID
childID
);
void
unlink
(
Element
::
ElementID
rootID
,
Element
::
ElementID
childID
);
...
@@ -59,7 +23,11 @@ class Schema
...
@@ -59,7 +23,11 @@ class Schema
void
setIn
(
Element
::
ElementID
ID
,
int
inNum
,
bool
state
);
void
setIn
(
Element
::
ElementID
ID
,
int
inNum
,
bool
state
);
bool
getOut
(
Element
::
ElementID
ID
);
bool
getOut
(
Element
::
ElementID
ID
);
typedef
std
::
unordered_map
<
Element
::
ElementID
,
Element
*>
ElementMap
;
struct
INLink
;
struct
EXTLink
;
struct
EXTOut
;
typedef
std
::
unordered_map
<
Element
::
ElementID
,
std
::
shared_ptr
<
Element
>>
ElementMap
;
typedef
std
::
list
<
INLink
>
InternalList
;
typedef
std
::
list
<
INLink
>
InternalList
;
typedef
std
::
list
<
EXTLink
>
ExternalList
;
typedef
std
::
list
<
EXTLink
>
ExternalList
;
typedef
std
::
list
<
EXTOut
>
OutputsList
;
typedef
std
::
list
<
EXTOut
>
OutputsList
;
...
@@ -141,9 +109,47 @@ class Schema
...
@@ -141,9 +109,47 @@ class Schema
}
}
// find
// find
Element
*
find
(
Element
::
ElementID
id
);
std
::
shared_ptr
<
Element
>
find
(
Element
::
ElementID
id
);
Element
*
findExtLink
(
const
std
::
string
&
name
);
std
::
shared_ptr
<
Element
>
findExtLink
(
const
std
::
string
&
name
);
Element
*
findOut
(
const
std
::
string
&
name
);
std
::
shared_ptr
<
Element
>
findOut
(
const
std
::
string
&
name
);
// -----------------------------------------------
// внутренее соединения
// между элементами
struct
INLink
{
INLink
(
std
::
shared_ptr
<
Element
>
f
,
std
::
shared_ptr
<
Element
>
t
,
int
ni
)
:
numInput
(
ni
)
{}
INLink
()
:
numInput
(
0
)
{}
std
::
shared_ptr
<
Element
>
from
;
std
::
shared_ptr
<
Element
>
to
;
int
numInput
;
};
// внешнее соединение
// что-то на вход элемента
struct
EXTLink
{
EXTLink
(
const
std
::
string
&
n
,
std
::
shared_ptr
<
Element
>
t
,
int
ni
)
:
name
(
n
),
to
(
t
),
numInput
(
ni
)
{}
EXTLink
()
:
name
(
""
),
numInput
(
0
)
{}
std
::
string
name
;
std
::
shared_ptr
<
Element
>
to
;
int
numInput
;
};
// наружный выход
struct
EXTOut
{
EXTOut
(
const
std
::
string
n
,
std
::
shared_ptr
<
Element
>
f
)
:
name
(
n
),
from
(
f
)
{}
EXTOut
()
:
name
(
""
)
{}
std
::
string
name
;
std
::
shared_ptr
<
Element
>
from
;
};
protected
:
protected
:
ElementMap
emap
;
// список элеметов
ElementMap
emap
;
// список элеметов
...
@@ -166,6 +172,4 @@ class SchemaXML:
...
@@ -166,6 +172,4 @@ class SchemaXML:
protected
:
protected
:
};
};
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
#endif
#endif
extensions/LogicProcessor/SchemaXML.cc
View file @
f49ef02c
#include <sstream>
#include <sstream>
#include <iostream>
#include <iostream>
#include "UniXML.h"
#include "UniXML.h"
#include "Extensions.h"
#include "Schema.h"
#include "Schema.h"
#include "TDelay.h"
#include "TDelay.h"
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
using
namespace
std
;
using
namespace
std
;
using
namespace
UniSetExtensions
;
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
SchemaXML
::
SchemaXML
()
SchemaXML
::
SchemaXML
()
{
{
...
@@ -55,18 +56,18 @@ void SchemaXML::read( const string& xmlfile )
...
@@ -55,18 +56,18 @@ void SchemaXML::read( const string& xmlfile )
int
inCount
=
xml
.
getPIntProp
(
it
,
"inCount"
,
1
);
int
inCount
=
xml
.
getPIntProp
(
it
,
"inCount"
,
1
);
if
(
type
==
"OR"
)
if
(
type
==
"OR"
)
manage
(
new
TOR
(
ID
,
inCount
)
);
manage
(
make_shared
<
TOR
>
(
ID
,
inCount
)
);
else
if
(
type
==
"AND"
)
else
if
(
type
==
"AND"
)
manage
(
new
TAND
(
ID
,
inCount
)
);
manage
(
make_shared
<
TAND
>
(
ID
,
inCount
)
);
else
if
(
type
==
"Delay"
)
else
if
(
type
==
"Delay"
)
{
{
int
delayMS
=
xml
.
getIntProp
(
it
,
"delayMS"
);
int
delayMS
=
xml
.
getIntProp
(
it
,
"delayMS"
);
manage
(
new
TDelay
(
ID
,
delayMS
,
inCount
)
);
manage
(
make_shared
<
TDelay
>
(
ID
,
delayMS
,
inCount
)
);
}
}
else
if
(
type
==
"NOT"
)
else
if
(
type
==
"NOT"
)
{
{
bool
defout
=
xml
.
getIntProp
(
it
,
"default_out_state"
);
bool
defout
=
xml
.
getIntProp
(
it
,
"default_out_state"
);
manage
(
new
TNOT
(
ID
,
defout
)
);
manage
(
make_shared
<
TNOT
>
(
ID
,
defout
)
);
}
}
else
else
{
{
...
@@ -104,26 +105,26 @@ void SchemaXML::read( const string& xmlfile )
...
@@ -104,26 +105,26 @@ void SchemaXML::read( const string& xmlfile )
if
(
type
==
"ext"
)
if
(
type
==
"ext"
)
{
{
cout
<<
"SchemaXML: set EXTlink: from="
<<
fID
<<
" to="
<<
tID
<<
" toInput="
<<
toIn
<<
endl
;
dinfo
<<
"SchemaXML: set EXTlink: from="
<<
fID
<<
" to="
<<
tID
<<
" toInput="
<<
toIn
<<
endl
;
extlink
(
fID
,
tID
,
toIn
);
extlink
(
fID
,
tID
,
toIn
);
}
}
else
if
(
type
==
"int"
)
else
if
(
type
==
"int"
)
{
{
cout
<<
"SchemaXML: set INTlink: from="
<<
fID
<<
" to="
<<
tID
<<
" toInput="
<<
toIn
<<
endl
;
dinfo
<<
"SchemaXML: set INTlink: from="
<<
fID
<<
" to="
<<
tID
<<
" toInput="
<<
toIn
<<
endl
;
link
(
fID
,
tID
,
toIn
);
link
(
fID
,
tID
,
toIn
);
}
}
else
if
(
type
==
"out"
)
else
if
(
type
==
"out"
)
{
{
Element
*
el
=
find
(
fID
);
auto
el
=
find
(
fID
);
if
(
el
==
0
)
if
(
!
el
)
{
{
ostringstream
msg
;
ostringstream
msg
;
msg
<<
"(SchemaXML::read): НЕ НАЙДЕН ЭЛЕМЕНТ С ID="
<<
fID
;
msg
<<
"(SchemaXML::read): НЕ НАЙДЕН ЭЛЕМЕНТ С ID="
<<
fID
;
throw
LogicException
(
msg
.
str
());
throw
LogicException
(
msg
.
str
());
}
}
cout
<<
"SchemaXML: set Out: from="
<<
fID
<<
" to="
<<
tID
<<
endl
;
dinfo
<<
"SchemaXML: set Out: from="
<<
fID
<<
" to="
<<
tID
<<
endl
;
outList
.
push_front
(
EXTOut
(
tID
,
el
)
);
outList
.
push_front
(
EXTOut
(
tID
,
el
)
);
}
}
}
}
...
...
extensions/LogicProcessor/tests/Makefile.am
View file @
f49ef02c
if
HAVE_TESTS
if
HAVE_TESTS
check_PROGRAMS
=
tests
#
check_PROGRAMS = tests
#
noinst_PROGRAMS = tests
noinst_PROGRAMS
=
tests
tests_SOURCES
=
tests.cc lproc.cc
tests_SOURCES
=
tests.cc
NullSM.cc
lproc.cc
tests_LDADD
=
$(top_builddir)
/lib/libUniSet2.la
$(top_builddir)
/extensions/lib/libUniSet2Extensions.la
\
tests_LDADD
=
$(top_builddir)
/lib/libUniSet2.la
$(top_builddir)
/extensions/lib/libUniSet2Extensions.la
\
$(top_builddir)
/extensions/LogicProcessor/libUniSet2LProcessor.la
$(top_builddir)
/extensions/LogicProcessor/libUniSet2LProcessor.la
tests_CPPFLAGS
=
-I
$(top_builddir)
/include
-I
$(top_builddir)
/extensions/include
-I
$(top_builddir)
/extensions/LogicProcessor
tests_CPPFLAGS
=
-I
$(top_builddir)
/include
-I
$(top_builddir)
/extensions/include
-I
$(top_builddir)
/extensions/LogicProcessor
...
...
extensions/LogicProcessor/tests/NullSM.cc
0 → 100644
View file @
f49ef02c
#include <memory>
#include "Configuration.h"
#include "NCRestorer.h"
#include "NullSM.h"
// --------------------------------------------------------------------------------
using
namespace
UniSetTypes
;
using
namespace
std
;
// --------------------------------------------------------------------------------
NullSM
::
NullSM
(
ObjectId
id
,
const
std
::
string
&
datfile
)
:
IONotifyController
(
id
)
{
shared_ptr
<
NCRestorer_XML
>
r
=
make_shared
<
NCRestorer_XML
>
(
datfile
);
restorer
=
std
::
static_pointer_cast
<
NCRestorer
>
(
r
);
}
// --------------------------------------------------------------------------------
NullSM
::~
NullSM
()
{
}
// --------------------------------------------------------------------------------
extensions/LogicProcessor/tests/NullSM.h
0 → 100644
View file @
f49ef02c
// --------------------------------------------------------------------------
#ifndef NullSM_H_
#define NullSM_H_
// --------------------------------------------------------------------------
#include <string>
#include "IONotifyController.h"
#include "NCRestorer.h"
// --------------------------------------------------------------------------
class
NullSM
:
public
IONotifyController
{
public
:
NullSM
(
UniSetTypes
::
ObjectId
id
,
const
std
::
string
&
datfile
);
virtual
~
NullSM
();
protected
:
virtual
void
loggingInfo
(
UniSetTypes
::
SensorMessage
&
sm
)
override
{};
virtual
void
dumpOrdersList
(
const
UniSetTypes
::
ObjectId
sid
,
const
IONotifyController
::
ConsumerListInfo
&
lst
)
override
{};
virtual
void
dumpThresholdList
(
const
UniSetTypes
::
ObjectId
sid
,
const
IONotifyController
::
ThresholdExtList
&
lst
)
override
{};
private
:
};
// --------------------------------------------------------------------------
#endif // NullSM_H_
// --------------------------------------------------------------------------
extensions/LogicProcessor/tests/exist.sh
0 → 100755
View file @
f49ef02c
#!/bin/sh
./uniset2-start.sh
-f
./uniset2-admin
--confile
./lp-configure.xml
--exist
extensions/LogicProcessor/tests/lp-configure.xml
0 → 100644
View file @
f49ef02c
<?xml version="1.0" encoding="utf-8"?>
<UNISETPLC
xmlns:xi=
"http://www.w3.org/2001/XInclude"
>
<UserData/>
<!-- Общие(стартовые) параметры по UniSet -->
<UniSet>
<NameService
host=
"localhost"
port=
"2809"
/>
<LocalNode
name=
"localhost"
/>
<RootSection
name=
"UNISET_LP"
/>
<CountOfNet
name=
"1"
/>
<RepeatCount
name=
"3"
/>
<RepeatTimeoutMS
name=
"50"
/>
<WatchDogTime
name=
"0"
/>
<PingNodeTime
name=
"0"
/>
<AutoStartUpTime
name=
"1"
/>
<DumpStateTime
name=
"10"
/>
<SleepTickMS
name=
"500"
/>
<UniSetDebug
levels=
""
name=
"ulog"
/>
<ConfDir
name=
"./"
/>
<DataDir
name=
"./"
/>
<BinDir
name=
"./"
/>
<LogDir
name=
"./"
/>
<DocDir
name=
"./"
/>
<LockDir
name=
"./"
/>
<Services/>
</UniSet>
<dlog
name=
"dlog"
/>
<settings>
<SharedMemory
name=
"SharedMemory"
shmID=
"SharedMemory"
/>
</settings>
<ObjectsMap
idfromfile=
"1"
>
<nodes
port=
"2809"
unet_broadcast_ip=
"192.168.1.255"
unet_broadcast_ip2=
"192.168.122.255"
>
<item
id=
"3000"
ip=
"127.0.0.1"
name=
"localhost"
textname=
"Локальный узел"
unet_ignore=
"0"
unet_port=
"2048"
/>
</nodes>
<!-- ************************ Датчики ********************** -->
<sensors
name=
"Sensors"
>
<item
id=
"500"
iotype=
"DI"
name=
"In1_S"
textname=
"In1"
/>
<item
id=
"501"
iotype=
"DI"
name=
"In2_S"
textname=
"In2"
/>
<item
id=
"502"
iotype=
"DI"
name=
"In3_S"
textname=
"In3"
/>
<item
id=
"503"
iotype=
"DI"
name=
"In4_S"
textname=
"In4"
/>
<item
id=
"504"
iotype=
"DI"
name=
"In5_S"
textname=
"In5"
/>
<item
id=
"505"
iotype=
"DI"
name=
"In6_S"
textname=
"In6"
/>
<item
id=
"506"
iotype=
"DI"
name=
"Out1_S"
textname=
"Out1"
/>
</sensors>
<thresholds
name=
"thresholds"
>
</thresholds>
<controllers
name=
"Controllers"
>
<item
id=
"5000"
name=
"SharedMemory1"
/>
<item
id=
"5003"
name=
"SharedMemory"
/>
</controllers>
<!-- ******************* Идентификаторы сервисов ***************** -->
<services
name=
"Services"
>
<item
id=
"5010"
name=
"InfoServer"
/>
<item
id=
"5011"
name=
"DBServer1"
/>
<item
id=
"5012"
name=
"PrintServer"
/>
<item
id=
"5013"
name=
"TimeService"
/>
</services>
<!-- ******************* Идентификаторы объектов ***************** -->
<objects
name=
"UniObjects"
>
<item
id=
"6000"
name=
"TestProc"
/>
<item
id=
"6001"
name=
"LProc1"
/>
</objects>
</ObjectsMap>
<messages
idfromfile=
"1"
name=
"messages"
>
</messages>
<Calibrations
name=
"Calibrations"
>
</Calibrations>
</UNISETPLC>
extensions/LogicProcessor/tests/lp_schema.xml
0 → 100644
View file @
f49ef02c
<?xml version="1.0" encoding="koi8-r"?>
<Schema>
<text-view>
----
1 --| |
2 --|TOR1|---| 1 -----
| | |----| |
---- 2 | |--|
|----|TAND3| |
---- | | | |
| | | ----- |
1 --|TOR2| | | 1 ---- -------
2 --| |--- | ---- ---| | | | out
| | | 1 | | 2 |TOR5|-----| Delay |----
---- |---|TOR4|-----| | | |
2 ----| | | | | |
---- ---- -------
</text-view>
<elements>
<item
id=
"1"
type=
"OR"
inCount=
"2"
/>
<item
id=
"2"
type=
"OR"
inCount=
"2"
/>
<item
id=
"3"
type=
"AND"
inCount=
"2"
/>
<item
id=
"4"
type=
"OR"
inCount=
"2"
/>
<item
id=
"5"
type=
"OR"
inCount=
"2"
/>
<item
id=
"6"
type=
"Delay"
inCount=
"1"
delayMS=
"3000"
/>
</elements>
<connections>
<item
type=
"ext"
from=
"In1_S"
to=
"1"
toInput=
"1"
/>
<item
type=
"ext"
from=
"In2_S"
to=
"1"
toInput=
"2"
/>
<item
type=
"ext"
from=
"In3_S"
to=
"2"
toInput=
"1"
/>
<item
type=
"ext"
from=
"In4_S"
to=
"2"
toInput=
"2"
/>
<item
type=
"ext"
from=
"In5_S"
to=
"4"
toInput=
"2"
/>
<item
type=
"ext"
from=
"In6_S"
to=
"5"
toInput=
"1"
/>
<item
type=
"int"
from=
"1"
to=
"3"
toInput=
"1"
/>
<item
type=
"int"
from=
"2"
to=
"3"
toInput=
"2"
/>
<item
type=
"int"
from=
"3"
to=
"4"
toInput=
"1"
/>
<item
type=
"int"
from=
"4"
to=
"5"
toInput=
"2"
/>
<item
type=
"int"
from=
"5"
to=
"6"
toInput=
"1"
/>
<item
type=
"out"
from=
"6"
to=
"Out1_S"
/>
</connections>
</Schema>
extensions/LogicProcessor/tests/lproc-tests.at
View file @
f49ef02c
AT_SETUP([LogicProcessor tests])
AT_SETUP([LogicProcessor tests])
AT_CHECK([$abs_top_builddir/testsuite/at-test-launch.sh $abs_top_builddir/extensions/LogicProcessor/tests tests],[0],[ignore],[ignore])
AT_CHECK([$abs_top_builddir/testsuite/at-test-launch.sh $abs_top_builddir/extensions/LogicProcessor/tests tests
.sh
],[0],[ignore],[ignore])
AT_CLEANUP
AT_CLEANUP
extensions/LogicProcessor/tests/lproc.cc
View file @
f49ef02c
#include <catch.hpp>
#include <catch.hpp>
#include <future>
#include <time.h>
#include <time.h>
#include "LProcessor.h"
#include "LProcessor.h"
#include "UniSetTypes.h"
#include "UniSetTypes.h"
#include "Schema.h"
#include "Schema.h"
#include "TDelay.h"
#include "TDelay.h"
// -----------------------------------------------------------------------------
using
namespace
std
;
using
namespace
std
;
using
namespace
UniSetTypes
;
using
namespace
UniSetTypes
;
// -----------------------------------------------------------------------------
static
shared_ptr
<
UInterface
>
ui
;
TEST_CASE
(
"Logic processor"
,
"[LogicProcessor]"
)
static
const
std
::
string
lp_schema
=
"lp_schema.xml"
;
// -----------------------------------------------------------------------------
bool
run_lproc
(
std
::
shared_ptr
<
LProcessor
>
lp
)
{
lp
->
execute
();
return
true
;
}
// -----------------------------------------------------------------------------
class
LPRunner
{
public
:
LPRunner
()
{
lp
=
make_shared
<
LProcessor
>
();
lp
->
open
(
lp_schema
);
res
=
std
::
async
(
std
::
launch
::
async
,
run_lproc
,
lp
);
}
~
LPRunner
()
{
if
(
lp
)
{
lp
->
terminate
();
res
.
get
();
}
}
inline
std
::
shared_ptr
<
LProcessor
>
get
()
{
return
lp
;
}
private
:
shared_ptr
<
LProcessor
>
lp
;
std
::
future
<
bool
>
res
;
};
// -----------------------------------------------------------------------------
void
InitTest
()
{
{
#if 0
auto
conf
=
uniset_conf
();
SECTION( "ShemaXML" )
CHECK
(
conf
!=
nullptr
);
if
(
!
ui
)
{
{
SchemaXML sch
;
ui
=
make_shared
<
UInterface
>
()
;
sch.read("schema.xml"
);
CHECK
(
ui
->
getObjectIndex
()
!=
nullptr
);
CHECK(
!sch.empty()
);
CHECK
(
ui
->
getConf
()
==
conf
);
}
}
#endif
}
// -----------------------------------------------------------------------------
TEST_CASE
(
"Logic processor: elements"
,
"[LogicProcessor][elements]"
)
{
SECTION
(
"TOR"
)
SECTION
(
"TOR"
)
{
{
TOR
e
(
"1"
,
2
);
// элемент на два входа..
TOR
e
(
"1"
,
2
);
// элемент на два входа..
...
@@ -100,3 +147,113 @@ TEST_CASE("Logic processor", "[LogicProcessor]")
...
@@ -100,3 +147,113 @@ TEST_CASE("Logic processor", "[LogicProcessor]")
CHECK
(
e
.
getOut
()
);
CHECK
(
e
.
getOut
()
);
}
}
}
}
// -----------------------------------------------------------------------------
TEST_CASE
(
"Logic processor: schema"
,
"[LogicProcessor][schema]"
)
{
SchemaXML
sch
;
sch
.
read
(
"schema.xml"
);
CHECK
(
!
sch
.
empty
()
);
REQUIRE
(
sch
.
size
()
==
6
);
REQUIRE
(
sch
.
find
(
"1"
)
!=
nullptr
);
REQUIRE
(
sch
.
find
(
"2"
)
!=
nullptr
);
REQUIRE
(
sch
.
find
(
"3"
)
!=
nullptr
);
REQUIRE
(
sch
.
find
(
"4"
)
!=
nullptr
);
REQUIRE
(
sch
.
find
(
"5"
)
!=
nullptr
);
REQUIRE
(
sch
.
find
(
"6"
)
!=
nullptr
);
REQUIRE
(
sch
.
findOut
(
"TestMode_S"
)
!=
nullptr
);
auto
e
=
sch
.
find
(
"6"
);
sch
.
remove
(
e
);
CHECK
(
sch
.
find
(
"6"
)
==
nullptr
);
}
// -----------------------------------------------------------------------------
TEST_CASE
(
"Logic processor: lp"
,
"[LogicProcessor][logic]"
)
{
InitTest
();
LPRunner
p
;
auto
lp
=
p
.
get
();
auto
sch
=
lp
->
getScheme
();
CHECK
(
sch
!=
nullptr
);
auto
e1
=
sch
->
find
(
"1"
);
REQUIRE
(
e1
!=
nullptr
);
auto
e2
=
sch
->
find
(
"2"
);
REQUIRE
(
e2
!=
nullptr
);
auto
e3
=
sch
->
find
(
"3"
);
REQUIRE
(
e3
!=
nullptr
);
auto
e4
=
sch
->
find
(
"4"
);
REQUIRE
(
e4
!=
nullptr
);
auto
e5
=
sch
->
find
(
"5"
);
REQUIRE
(
e5
!=
nullptr
);
auto
e6
=
sch
->
find
(
"6"
);
REQUIRE
(
e6
!=
nullptr
);
CHECK_FALSE
(
e1
->
getOut
()
);
CHECK_FALSE
(
e2
->
getOut
()
);
CHECK_FALSE
(
e3
->
getOut
()
);
CHECK_FALSE
(
e4
->
getOut
()
);
CHECK_FALSE
(
e5
->
getOut
()
);
CHECK_FALSE
(
e6
->
getOut
()
);
// e1
ui
->
setValue
(
500
,
1
);
msleep
(
lp
->
getSleepTime
()
+
10
);
CHECK
(
e1
->
getOut
()
);
CHECK_FALSE
(
e3
->
getOut
()
);
ui
->
setValue
(
500
,
0
);
msleep
(
lp
->
getSleepTime
()
+
10
);
CHECK_FALSE
(
e1
->
getOut
()
);
CHECK_FALSE
(
e3
->
getOut
()
);
ui
->
setValue
(
501
,
1
);
msleep
(
lp
->
getSleepTime
()
+
10
);
CHECK
(
e1
->
getOut
()
);
CHECK_FALSE
(
e3
->
getOut
()
);
// e4
CHECK_FALSE
(
e4
->
getOut
()
);
ui
->
setValue
(
504
,
1
);
msleep
(
lp
->
getSleepTime
()
+
10
);
CHECK
(
e4
->
getOut
()
);
// e5
CHECK
(
e5
->
getOut
()
);
ui
->
setValue
(
504
,
0
);
msleep
(
lp
->
getSleepTime
()
+
10
);
CHECK_FALSE
(
e4
->
getOut
()
);
// e5
CHECK_FALSE
(
e5
->
getOut
()
);
// e2
ui
->
setValue
(
503
,
1
);
msleep
(
lp
->
getSleepTime
()
+
10
);
CHECK
(
e2
->
getOut
()
);
// e3
CHECK
(
e3
->
getOut
()
);
// e4
CHECK
(
e4
->
getOut
()
);
// e5
CHECK
(
e5
->
getOut
()
);
// e6
CHECK_FALSE
(
e6
->
getOut
()
);
msleep
(
1000
);
CHECK_FALSE
(
e6
->
getOut
()
);
msleep
(
2100
);
CHECK
(
e6
->
getOut
()
);
}
// -----------------------------------------------------------------------------
extensions/LogicProcessor/tests/smview.sh
0 → 100755
View file @
f49ef02c
#!/bin/sh
./uniset2-start.sh
-f
./uniset2-sviewer-text
--confile
./lp-configure.xml
--exist
extensions/LogicProcessor/tests/tests.cc
View file @
f49ef02c
#define CATCH_CONFIG_
MAIN
#define CATCH_CONFIG_
RUNNER
#include <catch.hpp>
#include <catch.hpp>
// не удивляйтесь, что тут нет main().. она спрятана в catch.hpp :)
#include <string>
#include "Debug.h"
#include "UniSetActivator.h"
#include "NullSM.h"
#include "LProcessor.h"
// --------------------------------------------------------------------------
using
namespace
std
;
using
namespace
UniSetTypes
;
// --------------------------------------------------------------------------
int
main
(
int
argc
,
char
*
argv
[]
)
{
Catch
::
Session
session
;
if
(
argc
>
1
&&
(
strcmp
(
argv
[
1
],
"--help"
)
==
0
||
strcmp
(
argv
[
1
],
"-h"
)
==
0
)
)
{
cout
<<
"--confile - Использовать указанный конф. файл. По умолчанию configure.xml"
<<
endl
;
cout
<<
endl
<<
endl
<<
"--------------- CATCH HELP --------------"
<<
endl
;
session
.
showHelp
(
"tests"
);
return
0
;
}
int
returnCode
=
session
.
applyCommandLine
(
argc
,
argv
,
Catch
::
Session
::
OnUnusedOptions
::
Ignore
);
if
(
returnCode
!=
0
)
// Indicates a command line error
return
returnCode
;
try
{
auto
conf
=
uniset_init
(
argc
,
argv
,
"lp-configure.xml"
);
auto
act
=
UniSetActivator
::
Instance
();
ObjectId
ns_id
=
conf
->
getControllerID
(
"SharedMemory"
);
if
(
ns_id
==
DefaultObjectId
)
{
cerr
<<
"Not found ID for 'SharedMemory'"
<<
endl
;
return
1
;
}
auto
nullsm
=
make_shared
<
NullSM
>
(
ns_id
,
"lp-configure.xml"
);
act
->
add
(
nullsm
);
SystemMessage
sm
(
SystemMessage
::
StartUp
);
act
->
broadcast
(
sm
.
transport_msg
()
);
act
->
run
(
true
);
int
tout
=
6000
;
PassiveTimer
pt
(
tout
);
while
(
!
pt
.
checkTime
()
&&
!
act
->
exist
()
)
msleep
(
100
);
if
(
!
act
->
exist
()
)
{
cerr
<<
"(tests): UActivator not exist! (timeout="
<<
tout
<<
")"
<<
endl
;
return
1
;
}
return
session
.
run
();
}
catch
(
const
SystemError
&
err
)
{
cerr
<<
"(tests): "
<<
err
<<
endl
;
}
catch
(
const
Exception
&
ex
)
{
cerr
<<
"(tests): "
<<
ex
<<
endl
;
}
catch
(
const
std
::
exception
&
e
)
{
cerr
<<
"(tests): "
<<
e
.
what
()
<<
endl
;
}
catch
(...)
{
cerr
<<
"(tests): catch(...)"
<<
endl
;
}
return
1
;
}
extensions/LogicProcessor/tests/tests.sh
0 → 100755
View file @
f49ef02c
#!/bin/sh
./uniset2-start.sh
-f
./uniset2-admin
--confile
./lp-configure.xml
--create
./uniset2-start.sh
-f
./uniset2-admin
--confile
./lp-configure.xml
--exist
|
grep
-q
UNISET_LP/Controllers
||
exit
1
./uniset2-start.sh
-f
./tests
$*
--
--confile
./lp-configure.xml
--sleepTime
50
#--ulog-add-levels any
#--dlog-add-levels any
extensions/LogicProcessor/tests/uniset2-admin
0 → 120000
View file @
f49ef02c
../../../Utilities/Admin/uniset2-admin
\ No newline at end of file
extensions/LogicProcessor/tests/uniset2-functions.sh
0 → 120000
View file @
f49ef02c
../../../Utilities/scripts/uniset2-functions.sh
\ No newline at end of file
extensions/LogicProcessor/tests/uniset2-start.sh
0 → 120000
View file @
f49ef02c
../../../Utilities/scripts/uniset2-start.sh
\ No newline at end of file
extensions/Makefile.am
View file @
f49ef02c
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
############################################################################
############################################################################
if
HAVE_EXTENTIONS
if
HAVE_EXTENTIONS
SUBDIRS
=
lib include SharedMemory SharedMemory/tests IOControl LogicProcessor
\
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
\
RRDServer SharedMemoryPlus tests ModbusMaster/tests ModbusSlave/tests
RRDServer SharedMemoryPlus tests ModbusMaster/tests ModbusSlave/tests
...
...
extensions/SharedMemory/tests/NullSM.h
View file @
f49ef02c
...
@@ -20,7 +20,6 @@ class NullSM:
...
@@ -20,7 +20,6 @@ class NullSM:
virtual
void
dumpOrdersList
(
const
UniSetTypes
::
ObjectId
sid
,
const
IONotifyController
::
ConsumerListInfo
&
lst
)
override
{};
virtual
void
dumpOrdersList
(
const
UniSetTypes
::
ObjectId
sid
,
const
IONotifyController
::
ConsumerListInfo
&
lst
)
override
{};
virtual
void
dumpThresholdList
(
const
UniSetTypes
::
ObjectId
sid
,
const
IONotifyController
::
ThresholdExtList
&
lst
)
override
{};
virtual
void
dumpThresholdList
(
const
UniSetTypes
::
ObjectId
sid
,
const
IONotifyController
::
ThresholdExtList
&
lst
)
override
{};
virtual
void
readDump
()
override
{};
private
:
private
:
...
...
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