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
5739065d
Commit
5739065d
authored
Jul 19, 2016
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(ModbusTCPSession): добавил обработку ситуации когда клиент уже закрыл соединение,
которое мы пытаемся создать. (modbustcpserver-echo): добавил возможность задать паузу после каждого ответа
parent
7173801a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
5 deletions
+30
-5
MBTCPServer.h
Utilities/MBTester/MBTCPServer.h
+7
-2
mbtcpserver.cc
Utilities/MBTester/mbtcpserver.cc
+9
-1
ModbusTCPSession.cc
src/Communications/Modbus/ModbusTCPSession.cc
+14
-2
No files found.
Utilities/MBTester/MBTCPServer.h
View file @
5739065d
...
@@ -23,6 +23,11 @@ class MBTCPServer
...
@@ -23,6 +23,11 @@ class MBTCPServer
replyVal
=
val
;
replyVal
=
val
;
}
}
inline
timeout_t
setAfterSendPause
(
timeout_t
msec
)
{
return
sslot
->
setAfterSendPause
(
msec
);
}
void
execute
();
/*!< основной цикл работы */
void
execute
();
/*!< основной цикл работы */
void
setLog
(
std
::
shared_ptr
<
DebugStream
>&
dlog
);
void
setLog
(
std
::
shared_ptr
<
DebugStream
>&
dlog
);
...
@@ -89,8 +94,8 @@ class MBTCPServer
...
@@ -89,8 +94,8 @@ class MBTCPServer
ModbusTCPServerSlot
*
sslot
;
ModbusTCPServerSlot
*
sslot
;
std
::
unordered_set
<
ModbusRTU
::
ModbusAddr
>
vaddr
;
/*!< адреса данного узла */
std
::
unordered_set
<
ModbusRTU
::
ModbusAddr
>
vaddr
;
/*!< адреса данного узла */
bool
verbose
;
bool
verbose
=
{
false
}
;
long
replyVal
;
long
replyVal
=
{
-
1
}
;
#if 0
#if 0
typedef std::unordered_map<ModbusRTU::mbErrCode, unsigned int> ExchangeErrorMap;
typedef std::unordered_map<ModbusRTU::mbErrCode, unsigned int> ExchangeErrorMap;
ExchangeErrorMap errmap; /*!< статистика обмена */
ExchangeErrorMap errmap; /*!< статистика обмена */
...
...
Utilities/MBTester/mbtcpserver.cc
View file @
5739065d
...
@@ -16,6 +16,7 @@ static struct option longopts[] =
...
@@ -16,6 +16,7 @@ static struct option longopts[] =
{
"myaddr"
,
required_argument
,
0
,
'a'
},
{
"myaddr"
,
required_argument
,
0
,
'a'
},
{
"port"
,
required_argument
,
0
,
'p'
},
{
"port"
,
required_argument
,
0
,
'p'
},
{
"const-reply"
,
required_argument
,
0
,
'c'
},
{
"const-reply"
,
required_argument
,
0
,
'c'
},
{
"after-send-pause"
,
required_argument
,
0
,
's'
},
{
NULL
,
0
,
0
,
0
}
{
NULL
,
0
,
0
,
0
}
};
};
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
...
@@ -29,6 +30,7 @@ static void print_help()
...
@@ -29,6 +30,7 @@ static void print_help()
printf
(
" myaddr=255 - Reply to all RTU-addresses.
\n
"
);
printf
(
" myaddr=255 - Reply to all RTU-addresses.
\n
"
);
printf
(
"[-p|--port] port - Server port. Default: 502.
\n
"
);
printf
(
"[-p|--port] port - Server port. Default: 502.
\n
"
);
printf
(
"[-c|--const-reply] val - Reply 'val' for all queries
\n
"
);
printf
(
"[-c|--const-reply] val - Reply 'val' for all queries
\n
"
);
printf
(
"[-s|--after-send-pause] msec - Pause after send request. Default: 0
\n
"
);
}
}
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
...
@@ -42,6 +44,7 @@ int main( int argc, char** argv )
...
@@ -42,6 +44,7 @@ int main( int argc, char** argv )
string
myaddr
(
"0x01"
);
string
myaddr
(
"0x01"
);
auto
dlog
=
make_shared
<
DebugStream
>
();
auto
dlog
=
make_shared
<
DebugStream
>
();
int
replyVal
=
-
1
;
int
replyVal
=
-
1
;
timeout_t
afterpause
=
0
;
ost
::
Thread
::
setException
(
ost
::
Thread
::
throwException
);
ost
::
Thread
::
setException
(
ost
::
Thread
::
throwException
);
...
@@ -49,7 +52,7 @@ int main( int argc, char** argv )
...
@@ -49,7 +52,7 @@ int main( int argc, char** argv )
{
{
while
(
1
)
while
(
1
)
{
{
opt
=
getopt_long
(
argc
,
argv
,
"hva:p:i:c:"
,
longopts
,
&
optindex
);
opt
=
getopt_long
(
argc
,
argv
,
"hva:p:i:c:
s:
"
,
longopts
,
&
optindex
);
if
(
opt
==
-
1
)
if
(
opt
==
-
1
)
break
;
break
;
...
@@ -80,6 +83,10 @@ int main( int argc, char** argv )
...
@@ -80,6 +83,10 @@ int main( int argc, char** argv )
replyVal
=
uni_atoi
(
optarg
);
replyVal
=
uni_atoi
(
optarg
);
break
;
break
;
case
's'
:
afterpause
=
uni_atoi
(
optarg
);
break
;
case
'?'
:
case
'?'
:
default:
default:
printf
(
"? argumnet
\n
"
);
printf
(
"? argumnet
\n
"
);
...
@@ -105,6 +112,7 @@ int main( int argc, char** argv )
...
@@ -105,6 +112,7 @@ int main( int argc, char** argv )
MBTCPServer
mbs
(
vaddr
,
iaddr
,
port
,
verb
);
MBTCPServer
mbs
(
vaddr
,
iaddr
,
port
,
verb
);
mbs
.
setLog
(
dlog
);
mbs
.
setLog
(
dlog
);
mbs
.
setVerbose
(
verb
);
mbs
.
setVerbose
(
verb
);
mbs
.
setAfterSendPause
(
afterpause
);
if
(
replyVal
!=
-
1
)
if
(
replyVal
!=
-
1
)
mbs
.
setReply
(
replyVal
);
mbs
.
setReply
(
replyVal
);
...
...
src/Communications/Modbus/ModbusTCPSession.cc
View file @
5739065d
...
@@ -55,8 +55,17 @@ ModbusTCPSession::ModbusTCPSession( int sfd, const std::unordered_set<ModbusAddr
...
@@ -55,8 +55,17 @@ ModbusTCPSession::ModbusTCPSession( int sfd, const std::unordered_set<ModbusAddr
ost
::
InetAddress
iaddr
=
sock
->
getIPV4Peer
(
&
p
);
ost
::
InetAddress
iaddr
=
sock
->
getIPV4Peer
(
&
p
);
// resolve..
// resolve..
caddr
=
string
(
iaddr
.
getHostname
()
);
if
(
!
iaddr
.
isInetAddress
()
)
{
ostringstream
err
;
err
<<
"(ModbusTCPSession): unknonwn ip(0.0.0.0) client disconnected?!"
;
if
(
dlog
->
is_crit
()
)
dlog
->
crit
()
<<
err
.
str
()
<<
endl
;
sock
.
reset
();
throw
SystemError
(
err
.
str
());
}
caddr
=
string
(
iaddr
.
getHostname
()
);
ostringstream
s
;
ostringstream
s
;
s
<<
iaddr
<<
":"
<<
p
;
s
<<
iaddr
<<
":"
<<
p
;
peername
=
s
.
str
();
peername
=
s
.
str
();
...
@@ -65,7 +74,10 @@ ModbusTCPSession::ModbusTCPSession( int sfd, const std::unordered_set<ModbusAddr
...
@@ -65,7 +74,10 @@ ModbusTCPSession::ModbusTCPSession( int sfd, const std::unordered_set<ModbusAddr
{
{
ostringstream
err
;
ostringstream
err
;
err
<<
ex
.
what
();
err
<<
ex
.
what
();
dlog
->
crit
()
<<
"(ModbusTCPSession): err: "
<<
err
.
str
()
<<
endl
;
if
(
dlog
->
is_crit
()
)
dlog
->
crit
()
<<
"(ModbusTCPSession): err: "
<<
err
.
str
()
<<
endl
;
sock
.
reset
();
throw
SystemError
(
err
.
str
());
throw
SystemError
(
err
.
str
());
}
}
...
...
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