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
a411b49a
Commit
a411b49a
authored
Apr 19, 2011
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Добавил тестовую утилиту для UNet2
parent
562a159f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
297 additions
and
2 deletions
+297
-2
libuniset.spec
conf/libuniset.spec
+4
-1
Makefile.am
extensions/UNet2/Makefile.am
+6
-1
unet2-tester.cc
extensions/UNet2/unet2-tester.cc
+287
-0
No files found.
conf/libuniset.spec
View file @
a411b49a
...
...
@@ -3,7 +3,7 @@
Name: libuniset
Version: 1.0
Release: alt1
7
Release: alt1
8
Summary: UniSet - library for building distributed industrial control systems
License: GPL
Group: Development/C++
...
...
@@ -191,6 +191,9 @@ rm -f %buildroot%_libdir/*.la
%exclude %_pkgconfigdir/libUniSet.pc
%changelog
* Tue Apr 19 2011 Pavel Vainerman <pv@altlinux.ru> 1.0-alt18
- add unet2-tester
* Tue Mar 29 2011 Pavel Vainerman <pv@altlinux.ru> 1.0-alt17
- set encoding="utf-8" for codegen templates
...
...
extensions/UNet2/Makefile.am
View file @
a411b49a
bin_PROGRAMS
=
@PACKAGE@-unetexchange
bin_PROGRAMS
=
@PACKAGE@-unetexchange
@PACKAGE@-unet2-tester
# не забывайте править версию в pc-файле
UNET2_VER
=
@LIBVER@
...
...
@@ -19,6 +19,11 @@ libUniSetUNet2_la_SOURCES = UDPPacket.cc UNetReceiver.cc UNetSender.cc UNetExch
$(SIGC_LIBS)
$(COMCPP_LIBS)
@PACKAGE@
_unetexchange_CXXFLAGS
=
-I
$(top_builddir)
/extensions/include
-I
$(top_builddir)
/extensions/SharedMemory
$(SIGC_CFLAGS)
$(COMCPP_CFLAGS)
@PACKAGE@
_unet2_tester_SOURCES
=
UDPPacket.cc unet2-tester.cc
@PACKAGE@
_unet2_tester_LDADD
=
$(COMCPP_LIBS)
@PACKAGE@
_unet2_tester_CXXFLAGS
=
$(COMCPP_CFLAGS)
# install
devel_include_HEADERS
=
*
.h
devel_includedir
=
$(pkgincludedir)
/extensions
...
...
extensions/UNet2/unet2-tester.cc
0 → 100644
View file @
a411b49a
#include <cstdlib>
#include <errno.h>
#include <getopt.h>
#include <cstring>
#include <iostream>
#include <cc++/socket.h>
#include "UDPPacket.h"
// --------------------------------------------------------------------------
static
struct
option
longopts
[]
=
{
{
"help"
,
no_argument
,
0
,
'h'
},
{
"send"
,
required_argument
,
0
,
's'
},
{
"receive"
,
required_argument
,
0
,
'r'
},
{
"proc-id"
,
required_argument
,
0
,
'p'
},
{
"node-id"
,
required_argument
,
0
,
'n'
},
{
"send-pause"
,
required_argument
,
0
,
'x'
},
{
"timeout"
,
required_argument
,
0
,
't'
},
{
"data-count"
,
required_argument
,
0
,
'c'
},
{
"broadcast"
,
no_argument
,
0
,
'b'
},
{
"verbode"
,
required_argument
,
0
,
'v'
},
{
NULL
,
0
,
0
,
0
}
};
// --------------------------------------------------------------------------
using
namespace
std
;
using
namespace
UniSetUDP
;
// --------------------------------------------------------------------------
enum
Command
{
cmdNOP
,
cmdSend
,
cmdReceive
};
// --------------------------------------------------------------------------
static
bool
split_addr
(
const
string
addr
,
string
&
host
,
ost
::
tpport_t
&
port
)
{
string
::
size_type
pos
=
addr
.
rfind
(
':'
);
if
(
pos
!=
string
::
npos
)
{
host
=
addr
.
substr
(
0
,
pos
);
string
s_port
(
addr
.
substr
(
pos
+
1
,
addr
.
size
()
-
1
));
port
=
UniSetTypes
::
uni_atoi
(
s_port
.
c_str
());
return
true
;
}
return
false
;
}
// --------------------------------------------------------------------------
int
main
(
int
argc
,
char
*
argv
[])
{
int
optindex
=
0
;
int
opt
=
0
;
Command
cmd
=
cmdNOP
;
int
verb
=
0
;
std
::
string
addr
=
""
;
ost
::
tpport_t
port
=
0
;
int
usecpause
=
2000000
;
timeout_t
tout
=
TIMEOUT_INF
;
bool
broadcast
=
true
;
int
procID
=
1
;
int
nodeID
=
1
;
int
count
=
50
;
while
(
(
opt
=
getopt_long
(
argc
,
argv
,
"hs:r:vp:n:tb:"
,
longopts
,
&
optindex
))
!=
-
1
)
{
switch
(
opt
)
{
case
'h'
:
cout
<<
"-h|--help - this message"
<<
endl
;
cout
<<
"[-s|--send] host:port - Send message."
<<
endl
;
cout
<<
"[-c|--data-count] num - Send num count of value. Default: 50."
<<
endl
;
cout
<<
"[-r|--receive] host:port - Receive message."
<<
endl
;
cout
<<
"[-p|--proc-id] id - Set packet header. From 'procID'. Default: 1"
<<
endl
;
cout
<<
"[-n|--node-id] id - Set packet header. From 'nodeID'. Default: 1"
<<
endl
;
cout
<<
"[-t|--timeout] msec - timeout for receive. Default: 0 msec (waitup)."
<<
endl
;
cout
<<
"[-x|--send-pause] msec - pause for send packets. Default: 200 msec."
<<
endl
;
cout
<<
"[-b|--broadcast] - Set broadcast mode. Default: TRUE"
<<
endl
;
cout
<<
"[-v|--verbose] - verbose mode."
<<
endl
;
cout
<<
endl
;
return
0
;
case
'r'
:
cmd
=
cmdReceive
;
addr
=
string
(
optarg
);
break
;
case
's'
:
addr
=
string
(
optarg
);
cmd
=
cmdSend
;
break
;
case
't'
:
tout
=
UniSetTypes
::
uni_atoi
(
optarg
);
break
;
case
'x'
:
usecpause
=
UniSetTypes
::
uni_atoi
(
optarg
)
*
1000
;
break
;
case
'c'
:
count
=
UniSetTypes
::
uni_atoi
(
optarg
);
break
;
case
'p'
:
procID
=
UniSetTypes
::
uni_atoi
(
optarg
);
break
;
case
'n'
:
nodeID
=
UniSetTypes
::
uni_atoi
(
optarg
);
break
;
case
'b'
:
broadcast
=
true
;
break
;
case
'v'
:
verb
=
1
;
break
;
case
'?'
:
default:
cerr
<<
"? argumnet"
<<
endl
;
return
0
;
}
}
if
(
cmd
==
cmdNOP
)
{
cerr
<<
"No command... Use -h for help"
<<
endl
;
return
-
1
;
}
if
(
tout
<
0
)
tout
=
TIMEOUT_INF
;
ost
::
Thread
::
setException
(
ost
::
Thread
::
throwException
);
try
{
string
s_host
;
if
(
!
split_addr
(
addr
,
s_host
,
port
)
)
{
cerr
<<
"(main): Unknown 'host:port' for '"
<<
addr
<<
"'"
<<
endl
;
return
1
;
}
if
(
verb
)
{
cout
<<
" host="
<<
s_host
<<
" port="
<<
port
<<
" timeout="
;
if
(
tout
==
TIMEOUT_INF
)
cout
<<
"Waitup"
;
else
cout
<<
tout
;
cout
<<
" msecpause="
<<
usecpause
/
1000
<<
endl
;
}
ost
::
IPV4Host
host
(
s_host
.
c_str
());
// udp.UDPTransmit::setBroadcast(broadcast);
switch
(
cmd
)
{
case
cmdReceive
:
{
ost
::
UDPDuplex
udp
(
host
,
port
);
// char buf[UniSetUDP::MaxDataLen];
UniSetUDP
::
UDPMessage
pack
;
while
(
1
)
{
try
{
if
(
!
udp
.
isInputReady
(
tout
)
)
{
cout
<<
"(recv): Timeout.."
<<
endl
;
continue
;
}
size_t
ret
=
udp
.
UDPReceive
::
receive
(
&
(
pack
.
msg
),
sizeof
(
pack
.
msg
));
if
(
ret
<
sizeof
(
UniSetUDP
::
UDPHeader
)
)
{
cerr
<<
"(recv): FAILED header ret="
<<
ret
<<
" sizeof="
<<
sizeof
(
UniSetUDP
::
UDPHeader
)
<<
endl
;
continue
;
}
size_t
sz
=
pack
.
msg
.
header
.
dcount
*
sizeof
(
UniSetUDP
::
UDPData
)
+
sizeof
(
UniSetUDP
::
UDPHeader
);
if
(
ret
<
sz
)
{
cerr
<<
"(recv): FAILED data ret="
<<
ret
<<
" sizeof="
<<
sz
<<
" packnum="
<<
pack
.
msg
.
header
.
num
<<
endl
;
continue
;
}
if
(
verb
)
cout
<<
"receive OK. header: "
<<
pack
.
msg
.
header
<<
endl
;
}
catch
(
ost
::
SockException
&
e
)
{
cerr
<<
"(recv): "
<<
e
.
getString
()
<<
" ("
<<
addr
<<
")"
<<
endl
;
}
catch
(
...
)
{
cerr
<<
"(recv): catch ..."
<<
endl
;
}
}
}
break
;
case
cmdSend
:
{
ost
::
UDPSocket
*
udp
;
if
(
!
broadcast
)
udp
=
new
ost
::
UDPSocket
();
else
udp
=
new
ost
::
UDPBroadcast
(
host
,
port
);
UniSetUDP
::
UDPMessage
mypack
;
mypack
.
msg
.
header
.
nodeID
=
nodeID
;
mypack
.
msg
.
header
.
procID
=
procID
;
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
UDPData
d
(
i
,
i
);
mypack
.
addData
(
d
);
}
size_t
sz
=
mypack
.
byte_size
()
+
sizeof
(
UniSetUDP
::
UDPHeader
);
udp
->
setPeer
(
host
,
port
);
unsigned
long
packetnum
=
0
;
while
(
1
)
{
mypack
.
msg
.
header
.
num
=
packetnum
++
;
if
(
packetnum
>
UniSetUDP
::
MaxPacketNum
)
packetnum
=
1
;
try
{
if
(
udp
->
isPending
(
ost
::
Socket
::
pendingOutput
,
tout
)
)
{
if
(
verb
)
cout
<<
"(send): to addr="
<<
addr
<<
" count="
<<
count
<<
" bytes="
<<
sz
<<
endl
;
size_t
ret
=
udp
->
send
((
char
*
)
&
(
mypack
.
msg
),
sz
);
if
(
ret
<
sz
)
cerr
<<
"(send): FAILED ret="
<<
ret
<<
" < sizeof="
<<
sz
<<
endl
;
}
}
catch
(
ost
::
SockException
&
e
)
{
cerr
<<
"(send): "
<<
e
.
getString
()
<<
" ("
<<
addr
<<
")"
<<
endl
;
}
catch
(
...
)
{
cerr
<<
"(send): catch ..."
<<
endl
;
}
usleep
(
usecpause
);
}
}
break
;
default:
cerr
<<
endl
<<
"Unknown command: '"
<<
cmd
<<
"'. Use -h for help"
<<
endl
;
return
-
1
;
break
;
}
}
catch
(
ost
::
SockException
&
e
)
{
cerr
<<
"(main): "
<<
e
.
getString
()
<<
" ("
<<
addr
<<
")"
<<
endl
;
return
1
;
}
catch
(
...
)
{
cerr
<<
"(main): catch ..."
<<
endl
;
return
1
;
}
return
0
;
}
// --------------------------------------------------------------------------
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