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
a7246ca9
Commit
a7246ca9
authored
Oct 31, 2011
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(ModbusMaster): вынес ещё одну общую функцию в базовый класс
parent
bbdd555e
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
114 deletions
+81
-114
libuniset.spec
conf/libuniset.spec
+4
-1
MBExchange.cc
extensions/ModbusMaster/MBExchange.cc
+76
-1
MBTCPMaster.cc
extensions/ModbusMaster/MBTCPMaster.cc
+0
-112
start_fg_mbrtu.sh
extensions/ModbusMaster/start_fg_mbrtu.sh
+1
-0
No files found.
conf/libuniset.spec
View file @
a7246ca9
...
...
@@ -3,7 +3,7 @@
Name: libuniset
Version: 1.0
Release: alt
49
Release: alt
50
Summary: UniSet - library for building distributed industrial control systems
License: GPL
Group: Development/C++
...
...
@@ -212,6 +212,9 @@ rm -f %buildroot%_libdir/*.la
%changelog
* Mon Oct 31 2011 Pavel Vainerman <pv@altlinux.ru> 1.0-alt50
- ModbusMaster extensions code refactoring
* Tue Oct 25 2011 Pavel Vainerman <pv@altlinux.ru> 1.0-alt49
- added support 'const' and [private|protecte|public]
for <variables> in uniset-codegen
...
...
extensions/ModbusMaster/MBExchange.cc
View file @
a7246ca9
...
...
@@ -58,6 +58,9 @@ pollActivated(false)
recv_timeout
=
conf
->
getArgPInt
(
"--"
+
prefix
+
"-recv-timeout"
,
it
.
getProp
(
"recv_timeout"
),
500
);
int
tout
=
conf
->
getArgPInt
(
"--"
+
prefix
+
"-timeout"
,
it
.
getProp
(
"timeout"
),
5000
);
// для совместимости со старым RTUExchange
// надо обратывать и all-timeout
tout
=
conf
->
getArgPInt
(
"--"
+
prefix
+
"-all-timeout"
,
it
.
getProp
(
"all_timeout"
),
tout
);
ptTimeout
.
setTiming
(
tout
);
noQueryOptimization
=
conf
->
getArgInt
(
"--"
+
prefix
+
"-no-query-optimization"
,
it
.
getProp
(
"no_query_optimization"
));
...
...
@@ -189,6 +192,8 @@ void MBExchange::step()
if
(
!
checkProcActive
()
)
return
;
updateRespondSensors
();
if
(
sidHeartBeat
!=
DefaultObjectId
&&
ptHeartBeat
.
checkTime
()
)
{
try
...
...
@@ -219,7 +224,7 @@ void MBExchange::setProcActive( bool st )
// -----------------------------------------------------------------------------
void
MBExchange
::
sigterm
(
int
signo
)
{
dlog
[
Debug
::
WARN
]
<<
myname
<<
": ********* SIGTERM("
<<
signo
<<
") ********"
<<
endl
;
dlog
[
Debug
::
WARN
]
<<
myname
<<
": ********* SIGTERM("
<<
signo
<<
") ********"
<<
endl
;
setProcActive
(
false
);
UniSetObject_LT
::
sigterm
(
signo
);
}
...
...
@@ -2659,3 +2664,73 @@ bool MBExchange::RTUDevice::checkRespond()
return
(
prev
!=
resp_state
);
}
// -----------------------------------------------------------------------------
void
MBExchange
::
updateRespondSensors
()
{
bool
chanTimeout
=
false
;
{
uniset_mutex_lock
l
(
pollMutex
);
chanTimeout
=
pollActivated
&&
ptTimeout
.
checkTime
();
}
for
(
MBExchange
::
RTUDeviceMap
::
iterator
it1
=
rmap
.
begin
();
it1
!=
rmap
.
end
();
++
it1
)
{
RTUDevice
*
d
(
it1
->
second
);
if
(
chanTimeout
)
it1
->
second
->
resp_real
=
false
;
if
(
dlog
.
debugging
(
Debug
::
LEVEL4
)
)
{
dlog
[
Debug
::
LEVEL4
]
<<
myname
<<
": check respond addr="
<<
ModbusRTU
::
addr2str
(
d
->
mbaddr
)
<<
" respond_id="
<<
d
->
resp_id
<<
" real="
<<
d
->
resp_real
<<
" state="
<<
d
->
resp_state
<<
endl
;
}
if
(
d
->
checkRespond
()
&&
d
->
resp_id
!=
DefaultObjectId
)
{
try
{
bool
set
=
d
->
resp_invert
?
!
d
->
resp_state
:
d
->
resp_state
;
shm
->
localSaveState
(
d
->
resp_dit
,
d
->
resp_id
,
set
,
getId
());
}
catch
(
Exception
&
ex
)
{
dlog
[
Debug
::
CRIT
]
<<
myname
<<
"(step): (respond) "
<<
ex
<<
std
::
endl
;
}
}
}
}
// -----------------------------------------------------------------------------
void
MBExchange
::
execute
()
{
no_extimer
=
true
;
try
{
askTimer
(
tmExchange
,
0
);
}
catch
(...){}
initMB
(
false
);
while
(
1
)
{
try
{
step
();
}
catch
(
Exception
&
ex
)
{
dlog
[
Debug
::
CRIT
]
<<
myname
<<
"(execute): "
<<
ex
<<
std
::
endl
;
}
catch
(...)
{
dlog
[
Debug
::
CRIT
]
<<
myname
<<
"(execute): catch ..."
<<
endl
;
}
msleep
(
polltime
);
}
}
// -----------------------------------------------------------------------------
extensions/ModbusMaster/MBTCPMaster.cc
View file @
a7246ca9
...
...
@@ -117,54 +117,6 @@ void MBTCPMaster::sysCommand( UniSetTypes::SystemMessage *sm )
pollThread
->
start
();
}
// -----------------------------------------------------------------------------
void
MBTCPMaster
::
step
()
{
updateRespondSensors
();
MBExchange
::
step
();
}
// -----------------------------------------------------------------------------
void
MBTCPMaster
::
updateRespondSensors
()
{
bool
tcpIsTimeout
=
false
;
{
uniset_mutex_lock
l
(
tcpMutex
);
tcpIsTimeout
=
pollActivated
&&
ptTimeout
.
checkTime
();
}
if
(
dlog
.
debugging
(
Debug
::
LEVEL4
)
)
dlog
[
Debug
::
LEVEL4
]
<<
myname
<<
": tcpTimeout="
<<
tcpIsTimeout
<<
endl
;
for
(
MBTCPMaster
::
RTUDeviceMap
::
iterator
it1
=
rmap
.
begin
();
it1
!=
rmap
.
end
();
++
it1
)
{
RTUDevice
*
d
(
it1
->
second
);
if
(
tcpIsTimeout
)
d
->
resp_real
=
false
;
if
(
dlog
.
debugging
(
Debug
::
LEVEL4
)
)
{
dlog
[
Debug
::
LEVEL4
]
<<
myname
<<
": check respond addr="
<<
ModbusRTU
::
addr2str
(
d
->
mbaddr
)
<<
" respond_id="
<<
d
->
resp_id
<<
" real="
<<
d
->
resp_real
<<
" state="
<<
d
->
resp_state
<<
endl
;
}
if
(
d
->
checkRespond
()
&&
d
->
resp_id
!=
DefaultObjectId
)
{
try
{
bool
set
=
d
->
resp_invert
?
!
d
->
resp_state
:
d
->
resp_state
;
shm
->
localSaveState
(
d
->
resp_dit
,
d
->
resp_id
,
set
,
getId
());
}
catch
(
Exception
&
ex
)
{
dlog
[
Debug
::
CRIT
]
<<
myname
<<
"(step): (respond) "
<<
ex
<<
std
::
endl
;
}
}
}
}
// -----------------------------------------------------------------------------
void
MBTCPMaster
::
poll_thread
()
{
{
...
...
@@ -193,39 +145,6 @@ void MBTCPMaster::poll_thread()
}
}
// -----------------------------------------------------------------------------
void
MBTCPMaster
::
sigterm
(
int
signo
)
{
dlog
[
Debug
::
WARN
]
<<
myname
<<
": ********* SIGTERM("
<<
signo
<<
") ********"
<<
endl
;
setProcActive
(
false
);
/*! \todo Доделать выставление безопасного состояния на выходы.
И нужно ли это. Ведь может не хватить времени на "обмен"
*/
// выставление безопасного состояния на выходы....
/*
RSMap::iterator it=rsmap.begin();
for( ; it!=rsmap.end(); ++it )
{
// if( it->stype!=UniversalIO::DigitalOutput && it->stype!=UniversalIO::AnalogOutput )
// continue;
if( it->safety == NoSafetyState )
continue;
try
{
}
catch( UniSetTypes::Exception& ex )
{
dlog[Debug::WARN] << myname << "(sigterm): " << ex << std::endl;
}
catch(...){}
}
*/
UniSetObject_LT
::
sigterm
(
signo
);
}
// ------------------------------------------------------------------------------------------
void
MBTCPMaster
::
help_print
(
int
argc
,
const
char
*
const
*
argv
)
{
cout
<<
"Default: prefix='mbtcp'"
<<
endl
;
...
...
@@ -264,34 +183,3 @@ MBTCPMaster* MBTCPMaster::init_mbmaster( int argc, const char* const* argv,
return
new
MBTCPMaster
(
ID
,
icID
,
ic
,
prefix
);
}
// -----------------------------------------------------------------------------
void
MBTCPMaster
::
execute
()
{
no_extimer
=
true
;
try
{
askTimer
(
tmExchange
,
0
);
}
catch
(...){}
initMB
(
false
);
while
(
1
)
{
try
{
step
();
}
catch
(
Exception
&
ex
)
{
dlog
[
Debug
::
CRIT
]
<<
myname
<<
"(execute): "
<<
ex
<<
std
::
endl
;
}
catch
(...)
{
dlog
[
Debug
::
CRIT
]
<<
myname
<<
"(execute): catch ..."
<<
endl
;
}
msleep
(
polltime
);
}
}
// -----------------------------------------------------------------------------
extensions/ModbusMaster/start_fg_mbrtu.sh
View file @
a7246ca9
...
...
@@ -10,5 +10,6 @@ uniset-start.sh -f ./uniset-rtuexchange --confile test.xml \
--dlog-add-levels
info,crit,warn,level4,level3
\
--rs-force
0
\
--rs-force-out
0
\
--rs-polltime
3000
#,level3
# --rs-force 1 \
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