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
54e4c58a
Commit
54e4c58a
authored
Apr 02, 2015
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(codegen): Небольшой рефакторинг механизма работы с сообщениями,
убрали устаревшую функцию (alarm), добавил удобное значение по умолчанию... оставил только одну функцию setMsg().
parent
2d07bd4e
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
93 additions
and
99 deletions
+93
-99
ctl-cpp-cc-alone-ask.xsl
Utilities/codegen/ctl-cpp-cc-alone-ask.xsl
+0
-14
ctl-cpp-cc-alone.xsl
Utilities/codegen/ctl-cpp-cc-alone.xsl
+0
-14
ctl-cpp-cc-ask.xsl
Utilities/codegen/ctl-cpp-cc-ask.xsl
+0
-13
ctl-cpp-cc.xsl
Utilities/codegen/ctl-cpp-cc.xsl
+0
-13
ctl-cpp-common.xsl
Utilities/codegen/ctl-cpp-common.xsl
+20
-15
libuniset2.spec
conf/libuniset2.spec
+5
-1
uniset-codegen.dox
docs/DocPages/uniset-codegen.dox
+2
-4
UObject_SK.h
extensions/include/UObject_SK.h
+28
-3
UObject_SK.cc
extensions/lib/UObject_SK.cc
+38
-22
No files found.
Utilities/codegen/ctl-cpp-cc-alone-ask.xsl
View file @
54e4c58a
...
...
@@ -259,20 +259,6 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::updateOutputs( bool _force )
</xsl:for-each>
}
// -----------------------------------------------------------------------------
void
<xsl:value-of
select=
"$CLASSNAME"
/>
_SK::setMsg( UniSetTypes::ObjectId _code, bool _state )
{
// блокируем сброс (т.к. он автоматически по таймеру)
if( !_state )
{
ptResetMsg.reset();
return;
}
alarm( _code, _state );
ptResetMsg.reset();
}
// ----------------------------------------------------------------------------
<!-- END CC-FILE -->
</xsl:template>
...
...
Utilities/codegen/ctl-cpp-cc-alone.xsl
View file @
54e4c58a
...
...
@@ -197,20 +197,6 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::updateOutputs( bool _force )
-->
}
// -----------------------------------------------------------------------------
void
<xsl:value-of
select=
"$CLASSNAME"
/>
_SK::setMsg( UniSetTypes::ObjectId _code, bool _state )
{
// блокируем сброс (т.к. он автоматически по таймеру)
if( !_state )
{
ptResetMsg.reset();
return;
}
alarm( _code, _state );
ptResetMsg.reset();
}
// ----------------------------------------------------------------------------
<!-- END CC-FILE -->
</xsl:template>
...
...
Utilities/codegen/ctl-cpp-cc-ask.xsl
View file @
54e4c58a
...
...
@@ -238,19 +238,6 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::preAskSensors( UniversalIO::UIOComm
}
}
// -----------------------------------------------------------------------------
void
<xsl:value-of
select=
"$CLASSNAME"
/>
_SK::setMsg( UniSetTypes::ObjectId _code, bool _state )
{
// блокируем сброс (т.к. он автоматически по таймеру)
if( !_state )
{
ptResetMsg.reset();
return;
}
alarm( _code, _state );
ptResetMsg.reset();
}
// ----------------------------------------------------------------------------
<!-- END CC-FILE -->
</xsl:template>
...
...
Utilities/codegen/ctl-cpp-cc.xsl
View file @
54e4c58a
...
...
@@ -182,19 +182,6 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::preSensorInfo( const UniSetTypes::S
sensorInfo(sm);
}
// -----------------------------------------------------------------------------
void
<xsl:value-of
select=
"$CLASSNAME"
/>
_SK::setMsg( UniSetTypes::ObjectId code, bool state )
{
// блокируем сброс (т.к. он автоматически по таймеру)
if( !state )
{
ptResetMsg.reset();
return;
}
alarm( code, state );
ptResetMsg.reset();
}
// ----------------------------------------------------------------------------
<!-- END CC-FILE -->
</xsl:template>
...
...
Utilities/codegen/ctl-cpp-common.xsl
View file @
54e4c58a
...
...
@@ -164,12 +164,12 @@
</xsl:template>
<xsl:template
name=
"COMMON-HEAD-PUBLIC"
>
bool alarm( UniSetTypes::ObjectId sid, bool state );
long getValue( UniSetTypes::ObjectId sid );
void setValue( UniSetTypes::ObjectId sid, long value );
void askSensor( UniSetTypes::ObjectId sid, UniversalIO::UIOCommand, UniSetTypes::ObjectId node = UniSetTypes::uniset_conf()->getLocalNode() );
void updateValues();
void setMsg( UniSetTypes::ObjectId code, bool state );
virtual bool setMsg( UniSetTypes::ObjectId code, bool state = true );
std::shared_ptr
<
DebugStream
>
mylog;
void init_dlog( std::shared_ptr
<
DebugStream
>
d );
...
...
@@ -861,18 +861,20 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::checkSensors()
</xsl:for-each>
}
// -----------------------------------------------------------------------------
bool
<xsl:value-of
select=
"$CLASSNAME"
/>
_SK::
alarm
( UniSetTypes::ObjectId _code, bool _state )
bool
<xsl:value-of
select=
"$CLASSNAME"
/>
_SK::
setMsg
( UniSetTypes::ObjectId _code, bool _state )
{
if( _code == UniSetTypes::DefaultObjectId )
{
mycrit
<<
getName()
<<
"(alarm): попытка послать сообщение с DefaultObjectId"
<<
endl;
mycrit
<<
"(setMsg): попытка послать сообщение с DefaultObjectId"
<<
endl;
return false;
}
mylog8
<<
getName()
<<
"(alarm): "
<<
( _state ? "SEND " : "RESET " )
<<
endl;
mylog8
<<
"(setMsg): "
<<
( _state ? "SEND " : "RESET " )
<<
endl;
// взводим автоматический сброс
if( _state )
ptResetMsg.reset();
<xsl:for-each
select=
"//msgmap/item"
>
if( _code ==
<xsl:value-of
select=
"@name"
/>
)
{
...
...
@@ -888,14 +890,14 @@ bool <xsl:value-of select="$CLASSNAME"/>_SK::alarm( UniSetTypes::ObjectId _code,
}
catch( const std::exception
&
ex )
{
mycrit
<<
myname
<<
"(execute
): catch "
<<
ex.what()
<<
endl;
mycrit
<<
"(setMsg
): catch "
<<
ex.what()
<<
endl;
}
return false;
}
</xsl:for-each>
mylog8
<<
" not found MessgeOID?!!"
<<
endl;
mylog8
<<
"
(setMsg):
not found MessgeOID?!!"
<<
endl;
return false;
}
// -----------------------------------------------------------------------------
...
...
@@ -1190,25 +1192,28 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::resetMsg()
}
// -----------------------------------------------------------------------------
bool
<xsl:value-of
select=
"$CLASSNAME"
/>
_SK::
alarm
( UniSetTypes::ObjectId _code, bool _state )
bool
<xsl:value-of
select=
"$CLASSNAME"
/>
_SK::
setMsg
( UniSetTypes::ObjectId _code, bool _state )
{
if( _code == UniSetTypes::DefaultObjectId )
{
mycrit
<<
getName()
<<
"(alarm): попытка послать сообщение с DefaultObjectId"
mycrit
<<
"(setMsg): попытка послать сообщение с DefaultObjectId"
<<
endl;
return false;
}
mylog8
<<
getName()
<<
"(alarm
): ("
<<
_code
<<
")"
<<
( _state ? "SEND" : "RESET" )
<<
endl;
mylog8
<<
"(setMsg
): ("
<<
_code
<<
")"
<<
( _state ? "SEND" : "RESET" )
<<
endl;
// взводим таймер автоматического сброса
if( _state )
ptResetMsg.reset();
<xsl:for-each
select=
"//sensors/item"
>
<xsl:call-template
name=
"setmsg"
>
<xsl:with-param
name=
"GENTYPE"
select=
"'A'"
/>
</xsl:call-template>
</xsl:for-each>
mylog8
<<
" not found MessgeOID?!!"
<<
endl;
mylog8
<<
"
(setMsg):
not found MessgeOID?!!"
<<
endl;
return false;
}
// -----------------------------------------------------------------------------
...
...
conf/libuniset2.spec
View file @
54e4c58a
...
...
@@ -12,7 +12,7 @@
Name: libuniset2
Version: 2.0
Release: alt2
3
Release: alt2
4
Summary: UniSet - library for building distributed industrial control systems
...
...
@@ -409,6 +409,10 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
# ..
%changelog
* Thu Apr 02 2015 Pavel Vainerman <pv@altlinux.ru> 2.0-alt24
- codegen: modify interface for messages (setMsg())
- remove alarm() function (deprecated)
* Thu Mar 19 2015 Pavel Vainerman <pv@altlinux.ru> 2.0-alt23
- unetudp: fxied critial bug in "switching channels" (thank`s Alexey Surov)
...
...
docs/DocPages/uniset-codegen.dox
View file @
54e4c58a
...
...
@@ -145,14 +145,12 @@
\endcode
Для сообщений генерируется такой же набор "переменных" как и для полей указанных в \<smap> (см. \ref pg_Codegen_SMap). За исключением того,
что генерируется имя с префиксом \b mid_. И "привязка" идентификаторов не является обязательной.
\warning Датчики-сообщений \b ОБЯЗАТЕЛЬНО должны иметь тип \b "DI"
Для работы с сообщениями существует ряд правил:
- сообщения должны посылаться при помощи специальной (сгенерированной) функции
\b setMsg( UniSetTypes::ObjectId code, bool state ) или \b alarm( UniSetTypes::ObjectId code, bool state ).
Для передачи сообщения необходим вызов c параметром \b state=true.
\b setMsg( UniSetTypes::ObjectId code, bool state ). Для передачи сообщения необходим вызов c параметром \b state=true.
- Сообщения "автоматически" сбрасываются в "0" через \b resetMsgTime (настраиваемое в конф. секции), поэтому
вызывать функции с \b state=false нет смысла.
вызывать функции с \b state=false нет смысла.
Если указать resetMsgTime <=0 - автоматический сброс происходить не будет.
\section pg_Codegen_Variables Секция <variables>
В данной секции можно перечислить \b переменные разных типов, для которых будет сгенерирован код по их "инициализации"
...
...
extensions/include/UObject_SK.h
View file @
54e4c58a
...
...
@@ -8,7 +8,7 @@
ВСЕ ВАШИ ИЗМЕНЕНИЯ БУДУТ ПОТЕРЯНЫ.
*/
// --------------------------------------------------------------------------
// generate timestamp: 2015-0
3-06
+03:00
// generate timestamp: 2015-0
4-02
+03:00
// -----------------------------------------------------------------------------
#ifndef UObject_SK_H_
#define UObject_SK_H_
...
...
@@ -31,12 +31,12 @@ class UObject_SK:
virtual
~
UObject_SK
();
bool
alarm
(
UniSetTypes
::
ObjectId
sid
,
bool
state
);
long
getValue
(
UniSetTypes
::
ObjectId
sid
);
void
setValue
(
UniSetTypes
::
ObjectId
sid
,
long
value
);
void
askSensor
(
UniSetTypes
::
ObjectId
sid
,
UniversalIO
::
UIOCommand
,
UniSetTypes
::
ObjectId
node
=
UniSetTypes
::
uniset_conf
()
->
getLocalNode
()
);
void
updateValues
();
void
setMsg
(
UniSetTypes
::
ObjectId
code
,
bool
state
);
virtual
bool
setMsg
(
UniSetTypes
::
ObjectId
code
,
bool
state
=
true
);
std
::
shared_ptr
<
DebugStream
>
mylog
;
void
init_dlog
(
std
::
shared_ptr
<
DebugStream
>
d
);
...
...
@@ -81,6 +81,31 @@ class UObject_SK:
#ifndef mylogany
#define mylogany mylog->any()
#endif
// Вспомогательные функции для удобства логирования
// ------------------------------------------------------------
/*!< вывод в строку значение всех входов и выходов в формате
ObjectName:
in_xxx = val
in_xxx2 = val
out_zzz = val
...
*/
std
::
string
dumpIO
();
/*!< Вывод в строку названия входа/выхода в формате: in_xxx(SensorName)
\param id - идентификатор датчика
\param showLinkName - TRUE - выводить SensorName, FALSE - не выводить
*/
std
::
string
str
(
UniSetTypes
::
ObjectId
id
,
bool
showLinkName
=
true
);
/*!< Вывод значения входа/выхода в формате: in_xxx(SensorName)=val
\param id - идентификатор датчика
\param showLinkName - TRUE - выводить SensorName, FALSE - не выводить
*/
std
::
string
strval
(
UniSetTypes
::
ObjectId
id
,
bool
showLinkName
=
true
);
// ------------------------------------------------------------
// Используемые идентификаторы
...
...
extensions/lib/UObject_SK.cc
View file @
54e4c58a
...
...
@@ -11,11 +11,12 @@
ВСЕ ВАШИ ИЗМЕНЕНИЯ БУДУТ ПОТЕРЯНЫ.
*/
// --------------------------------------------------------------------------
// generate timestamp: 2015-0
3-06
+03:00
// generate timestamp: 2015-0
4-02
+03:00
// -----------------------------------------------------------------------------
#include <memory>
#include "Configuration.h"
#include "Exceptions.h"
#include "ORepHelpers.h"
#include "UObject_SK.h"
// -----------------------------------------------------------------------------
...
...
@@ -138,7 +139,11 @@ end_private(false)
sleep_msec
=
conf
->
getArgPInt
(
"--"
+
argprefix
+
"sleep-msec"
,
"150"
,
150
);
resetMsgTime
=
conf
->
getPIntProp
(
cnode
,
"resetMsgTime"
,
2000
);
string
s_resetTime
(
""
);
if
(
s_resetTime
.
empty
()
)
s_resetTime
=
"500"
;
resetMsgTime
=
uni_atoi
(
init3_str
(
conf
->
getArgParam
(
"--"
+
argprefix
+
"resetMsgTime"
),
conf
->
getProp
(
cnode
,
"resetMsgTime"
),
s_resetTime
));
ptResetMsg
.
setTiming
(
resetMsgTime
);
smReadyTimeout
=
conf
->
getArgInt
(
"--"
+
argprefix
+
"sm-ready-timeout"
,
""
);
...
...
@@ -182,21 +187,23 @@ void UObject_SK::checkSensors()
}
// -----------------------------------------------------------------------------
bool
UObject_SK
::
alarm
(
UniSetTypes
::
ObjectId
_code
,
bool
_state
)
bool
UObject_SK
::
setMsg
(
UniSetTypes
::
ObjectId
_code
,
bool
_state
)
{
if
(
_code
==
UniSetTypes
::
DefaultObjectId
)
{
mycrit
<<
getName
()
<<
"(alarm): попытка послать сообщение с DefaultObjectId"
<<
endl
;
mycrit
<<
"(setMsg): попытка послать сообщение с DefaultObjectId"
<<
endl
;
return
false
;
}
mylog8
<<
getName
()
<<
"(alarm): "
<<
(
_state
?
"SEND "
:
"RESET "
)
<<
endl
;
mylog8
<<
"(setMsg): "
<<
(
_state
?
"SEND "
:
"RESET "
)
<<
endl
;
// взводим автоматический сброс
if
(
_state
)
ptResetMsg
.
reset
();
mylog8
<<
" not found MessgeOID?!!"
<<
endl
;
mylog8
<<
"
(setMsg):
not found MessgeOID?!!"
<<
endl
;
return
false
;
}
// -----------------------------------------------------------------------------
...
...
@@ -215,6 +222,28 @@ void UObject_SK::testMode( bool _state )
}
// -----------------------------------------------------------------------------
std
::
string
UObject_SK
::
dumpIO
()
{
ostringstream
s
;
s
<<
myname
<<
": "
<<
endl
;
return
s
.
str
();
}
// ----------------------------------------------------------------------------
std
::
string
UObject_SK
::
str
(
UniSetTypes
::
ObjectId
id
,
bool
showLinkName
)
{
ostringstream
s
;
return
""
;
}
// ----------------------------------------------------------------------------
std
::
string
UObject_SK
::
strval
(
UniSetTypes
::
ObjectId
id
,
bool
showLinkName
)
{
ostringstream
s
;
return
""
;
}
// ----------------------------------------------------------------------------
// --------------------------------------------------------------------------
...
...
@@ -496,16 +525,3 @@ void UObject_SK::preAskSensors( UniversalIO::UIOCommand _cmd )
}
}
// -----------------------------------------------------------------------------
void
UObject_SK
::
setMsg
(
UniSetTypes
::
ObjectId
_code
,
bool
_state
)
{
// блокируем сброс (т.к. он автоматически по таймеру)
if
(
!
_state
)
{
ptResetMsg
.
reset
();
return
;
}
alarm
(
_code
,
_state
);
ptResetMsg
.
reset
();
}
// ----------------------------------------------------------------------------
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