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
b9c92a58
Commit
b9c92a58
authored
Dec 13, 2016
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(Modbus): рефакторинг кода и тестов, корректировка под 64bit
parent
de872cfc
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
73 additions
and
58 deletions
+73
-58
libuniset2.spec
conf/libuniset2.spec
+1
-0
MBExchange.cc
extensions/ModbusMaster/MBExchange.cc
+0
-0
MBTCPTestServer.cc
extensions/ModbusMaster/tests/MBTCPTestServer.cc
+9
-8
MBTCPTestServer.h
extensions/ModbusMaster/tests/MBTCPTestServer.h
+4
-4
run_test_mbtcpmaster.sh
extensions/ModbusMaster/tests/run_test_mbtcpmaster.sh
+1
-1
test_mbtcpmaster.cc
extensions/ModbusMaster/tests/test_mbtcpmaster.cc
+26
-18
test_mbtcpmultimaster.cc
extensions/ModbusMaster/tests/test_mbtcpmultimaster.cc
+2
-0
VTypes.h
extensions/include/VTypes.h
+30
-27
No files found.
conf/libuniset2.spec
View file @
b9c92a58
...
...
@@ -505,6 +505,7 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
%exclude %_pkgconfigdir/libUniSet2.pc
# history of current unpublished changes
# Modbus: refactoring code and test (for 64bit)
%changelog
* Mon Dec 12 2016 Pavel Vainerman <pv@altlinux.ru> 2.6-alt6
...
...
extensions/ModbusMaster/MBExchange.cc
View file @
b9c92a58
This diff is collapsed.
Click to expand it.
extensions/ModbusMaster/tests/MBTCPTestServer.cc
View file @
b9c92a58
// -------------------------------------------------------------------------
#include <sstream>
#include <limits>
#include <Poco/Net/NetException.h>
#include "UniSetTypes.h"
#include "MBTCPTestServer.h"
...
...
@@ -23,7 +24,7 @@ MBTCPTestServer::MBTCPTestServer( const std::unordered_set<ModbusAddr>& _vaddr,
sslot
(
NULL
),
vaddr
(
_vaddr
),
verbose
(
verb
),
replyVal
(
-
1
),
replyVal
(
std
::
numeric_limits
<
uint32_t
>::
max
()
),
forceSingleCoilCmd
(
false
),
lastWriteOutputSingleRegister
(
0
),
lastForceCoilsQ
(
0
,
0
),
...
...
@@ -122,7 +123,7 @@ ModbusRTU::mbErrCode MBTCPTestServer::readCoilStatus( ReadCoilMessage& query,
if
(
query
.
count
<=
1
)
{
if
(
replyVal
!=
-
1
)
if
(
replyVal
!=
std
::
numeric_limits
<
uint32_t
>::
max
()
)
reply
.
addData
(
replyVal
);
else
reply
.
addData
(
d
);
...
...
@@ -136,7 +137,7 @@ ModbusRTU::mbErrCode MBTCPTestServer::readCoilStatus( ReadCoilMessage& query,
for
(
;
num
<
query
.
count
;
num
++
,
reg
++
)
{
if
(
replyVal
!=
-
1
)
if
(
replyVal
!=
std
::
numeric_limits
<
uint32_t
>::
max
()
)
reply
.
addData
(
replyVal
);
else
reply
.
addData
(
d
);
...
...
@@ -167,7 +168,7 @@ ModbusRTU::mbErrCode MBTCPTestServer::readInputStatus( ReadInputStatusMessage& q
d
.
b
[
3
]
=
1
;
d
.
b
[
7
]
=
1
;
if
(
replyVal
==
-
1
)
if
(
replyVal
==
std
::
numeric_limits
<
uint32_t
>::
max
()
)
{
size_t
bnum
=
0
;
size_t
i
=
0
;
...
...
@@ -207,7 +208,7 @@ mbErrCode MBTCPTestServer::readInputRegisters( ReadInputMessage& query,
if
(
query
.
count
<=
1
)
{
if
(
replyVal
!=
-
1
)
if
(
replyVal
!=
std
::
numeric_limits
<
uint32_t
>::
max
()
)
reply
.
addData
(
replyVal
);
else
reply
.
addData
(
query
.
start
);
...
...
@@ -221,7 +222,7 @@ mbErrCode MBTCPTestServer::readInputRegisters( ReadInputMessage& query,
for
(
;
num
<
query
.
count
;
num
++
,
reg
++
)
{
if
(
replyVal
!=
-
1
)
if
(
replyVal
!=
std
::
numeric_limits
<
uint32_t
>::
max
()
)
reply
.
addData
(
replyVal
);
else
reply
.
addData
(
reg
);
...
...
@@ -252,7 +253,7 @@ ModbusRTU::mbErrCode MBTCPTestServer::readOutputRegisters(
if
(
query
.
count
<=
1
)
{
if
(
replyVal
!=
-
1
)
if
(
replyVal
!=
std
::
numeric_limits
<
uint32_t
>::
max
()
)
reply
.
addData
(
replyVal
);
else
reply
.
addData
(
query
.
start
);
...
...
@@ -266,7 +267,7 @@ ModbusRTU::mbErrCode MBTCPTestServer::readOutputRegisters(
for
(
;
num
<
query
.
count
;
num
++
,
reg
++
)
{
if
(
replyVal
!=
-
1
)
if
(
replyVal
!=
std
::
numeric_limits
<
uint32_t
>::
max
()
)
reply
.
addData
(
replyVal
);
else
reply
.
addData
(
reg
);
...
...
extensions/ModbusMaster/tests/MBTCPTestServer.h
View file @
b9c92a58
...
...
@@ -19,7 +19,7 @@ class MBTCPTestServer
verbose
=
state
;
}
inline
void
setReply
(
long
val
)
inline
void
setReply
(
uint32_t
val
)
{
replyVal
=
val
;
}
...
...
@@ -47,7 +47,7 @@ class MBTCPTestServer
{
return
forceSingleCoilCmd
;
}
inline
int
getLastWriteOutputSingleRegister
()
inline
int
16_t
getLastWriteOutputSingleRegister
()
{
return
lastWriteOutputSingleRegister
;
}
...
...
@@ -131,9 +131,9 @@ class MBTCPTestServer
std
::
unordered_set
<
uniset
::
ModbusRTU
::
ModbusAddr
>
vaddr
;
/*!< адреса данного узла */
bool
verbose
;
long
replyVal
;
uint32_t
replyVal
;
bool
forceSingleCoilCmd
;
int
lastWriteOutputSingleRegister
;
int
16_t
lastWriteOutputSingleRegister
;
uniset
::
ModbusRTU
::
ForceCoilsMessage
lastForceCoilsQ
;
uniset
::
ModbusRTU
::
WriteOutputMessage
lastWriteOutputQ
;
float
f2_test_value
=
{
0
.
0
};
...
...
extensions/ModbusMaster/tests/run_test_mbtcpmaster.sh
View file @
b9c92a58
...
...
@@ -15,7 +15,7 @@ cd -
--mbtcp-filter-value
1
\
--mbtcp-gateway-iaddr
localhost
\
--mbtcp-gateway-port
20048
\
--mbtcp-polltime
50
--mbtcp-recv-timeout
500
--mbtcp-polltime
50
--mbtcp-recv-timeout
500
#--mbtcp-log-add-levels any
#--mbtcp-default-mbinit-ok 1
#--dlog-add-levels any
...
...
extensions/ModbusMaster/tests/test_mbtcpmaster.cc
View file @
b9c92a58
...
...
@@ -222,12 +222,12 @@ TEST_CASE("MBTCPMaster: 0x03 (read register outputs or memories or read word out
REQUIRE
(
ui
->
getValue
(
1004
)
==
-
10
);
REQUIRE
(
ui
->
getValue
(
1005
)
==
-
10
);
REQUIRE
(
ui
->
getValue
(
1006
)
==
-
10
);
mbs
->
setReply
(
0
);
mbs
->
setReply
(
1
);
msleep
(
polltime
+
200
);
REQUIRE
(
ui
->
getValue
(
1003
)
==
0
);
REQUIRE
(
ui
->
getValue
(
1004
)
==
0
);
REQUIRE
(
ui
->
getValue
(
1005
)
==
0
);
REQUIRE
(
ui
->
getValue
(
1006
)
==
0
);
REQUIRE
(
ui
->
getValue
(
1003
)
==
1
);
REQUIRE
(
ui
->
getValue
(
1004
)
==
1
);
REQUIRE
(
ui
->
getValue
(
1005
)
==
1
);
REQUIRE
(
ui
->
getValue
(
1006
)
==
1
);
mbs
->
setReply
(
65535
);
msleep
(
polltime
+
200
);
REQUIRE
(
ui
->
getValue
(
1003
)
==
-
1
);
...
...
@@ -236,10 +236,14 @@ TEST_CASE("MBTCPMaster: 0x03 (read register outputs or memories or read word out
REQUIRE
(
ui
->
getValue
(
1006
)
==
-
1
);
REQUIRE
(
ui
->
getValue
(
1007
)
==
65535
);
// unsigned
mbs
->
setReply
(
0xffff
);
mbs
->
setReply
(
std
::
numeric_limits
<
uint16_t
>::
max
()
);
msleep
(
polltime
+
200
);
REQUIRE
(
(
uint16_t
)
ui
->
getValue
(
1009
)
==
std
::
numeric_limits
<
uint16_t
>::
max
()
);
// U2
mbs
->
setReply
(
std
::
numeric_limits
<
int16_t
>::
max
()
);
msleep
(
polltime
+
200
);
REQUIRE
(
ui
->
getValue
(
1008
)
==
0xffffffff
);
// I2
REQUIRE
(
ui
->
getValue
(
1009
)
==
0xffffffff
);
// U2
REQUIRE
(
(
int16_t
)
ui
->
getValue
(
1008
)
==
std
::
numeric_limits
<
int16_t
>::
max
()
);
// I2
mbs
->
setReply
(
0xff
);
msleep
(
polltime
+
200
);
REQUIRE
(
ui
->
getValue
(
1008
)
==
0x00ff00ff
);
// I2
...
...
@@ -281,10 +285,14 @@ TEST_CASE("MBTCPMaster: 0x04 (read input registers or memories or read word outp
REQUIRE
(
ui
->
getValue
(
1013
)
==
-
1
);
REQUIRE
(
ui
->
getValue
(
1014
)
==
65535
);
// unsigned
mbs
->
setReply
(
0xffff
);
mbs
->
setReply
(
std
::
numeric_limits
<
uint16_t
>::
max
()
);
msleep
(
polltime
+
200
);
REQUIRE
(
ui
->
getValue
(
1015
)
==
0xffffffff
);
// I2
REQUIRE
(
ui
->
getValue
(
1016
)
==
0xffffffff
);
// U2
REQUIRE
(
(
uint16_t
)
ui
->
getValue
(
1009
)
==
std
::
numeric_limits
<
uint16_t
>::
max
()
);
// U2
mbs
->
setReply
(
std
::
numeric_limits
<
int16_t
>::
max
()
);
msleep
(
polltime
+
200
);
REQUIRE
(
(
int16_t
)
ui
->
getValue
(
1008
)
==
std
::
numeric_limits
<
int16_t
>::
max
()
);
// I2
mbs
->
setReply
(
0xff
);
msleep
(
polltime
+
200
);
REQUIRE
(
ui
->
getValue
(
1015
)
==
0x00ff00ff
);
// I2
...
...
@@ -457,23 +465,23 @@ TEST_CASE("MBTCPMaster: 0x10 (write register outputs or memories)", "[modbus][0x
REQUIRE
(
q
.
addr
==
slaveADDR
);
REQUIRE
(
q
.
start
==
31
);
REQUIRE
(
q
.
quant
==
6
);
REQUIRE
(
q
.
data
[
0
]
==
(
u
nsigned
shor
t
)(
-
100
)
);
REQUIRE
(
q
.
data
[
2
]
==
(
u
nsigned
shor
t
)(
-
10
)
);
REQUIRE
(
q
.
data
[
3
]
==
(
u
nsigned
shor
t
)(
-
32767
)
);
REQUIRE
(
q
.
data
[
0
]
==
(
u
int16_
t
)(
-
100
)
);
REQUIRE
(
q
.
data
[
2
]
==
(
u
int16_
t
)(
-
10
)
);
REQUIRE
(
q
.
data
[
3
]
==
(
u
int16_
t
)(
-
32767
)
);
}
SECTION
(
"I2"
)
{
ui
->
setValue
(
1023
,
0xffffffff
);
REQUIRE
(
ui
->
getValue
(
1023
)
==
0xffffffff
);
ui
->
setValue
(
1023
,
std
::
numeric_limits
<
uint32_t
>::
max
()
);
REQUIRE
(
(
uint32_t
)
ui
->
getValue
(
1023
)
==
std
::
numeric_limits
<
uint32_t
>::
max
()
);
msleep
(
polltime
+
200
);
ModbusRTU
::
WriteOutputMessage
q
=
mbs
->
getLastWriteOutput
();
REQUIRE
(
q
.
addr
==
slaveADDR
);
REQUIRE
(
q
.
start
==
31
);
REQUIRE
(
q
.
quant
==
6
);
REQUIRE
(
q
.
data
[
4
]
==
0xffff
);
REQUIRE
(
q
.
data
[
5
]
==
0xffff
);
REQUIRE
(
q
.
data
[
4
]
==
std
::
numeric_limits
<
uint16_t
>::
max
()
);
REQUIRE
(
q
.
data
[
5
]
==
std
::
numeric_limits
<
uint16_t
>::
max
()
);
}
}
// -----------------------------------------------------------------------------
...
...
extensions/ModbusMaster/tests/test_mbtcpmultimaster.cc
View file @
b9c92a58
...
...
@@ -127,6 +127,8 @@ TEST_CASE("MBTCPMultiMaster: rotate channel", "[modbus][mbmaster][mbtcpmultimast
InitTest
();
CHECK
(
ui
->
isExist
(
mbID
)
);
mbs1
->
setReply
(
0
);
msleep
(
polltime
+
1000
);
REQUIRE
(
ui
->
getValue
(
1003
)
==
0
);
mbs1
->
setReply
(
100
);
mbs2
->
setReply
(
10
);
...
...
extensions/include/VTypes.h
View file @
b9c92a58
...
...
@@ -19,6 +19,7 @@
#define _RTUTypes_H_
// -----------------------------------------------------------------------------
#include <string>
#include <stdint.h>
#include <cmath>
#include <cstring>
#include <ostream>
...
...
@@ -61,7 +62,7 @@ namespace uniset
/*! тип хранения в памяти */
typedef
union
{
u
nsigned
shor
t
v
[
f2Size
];
u
int16_
t
v
[
f2Size
];
float
val
;
//
}
F2mem
;
// ------------------------------------------
...
...
@@ -147,7 +148,7 @@ namespace uniset
/*! тип хранения в памяти */
typedef
union
{
u
nsigned
shor
t
v
[
f4Size
];
u
int16_
t
v
[
f4Size
];
float
val
;
//
}
F4mem
;
// ------------------------------------------
...
...
@@ -202,8 +203,8 @@ namespace uniset
/*! тип хранения в памяти */
typedef
union
{
u
nsigned
shor
t
w
;
u
nsigned
char
b
[
bsize
];
u
int16_
t
w
;
u
int8_t
b
[
bsize
];
}
Bytemem
;
// ------------------------------------------
// конструкторы на разные случаи...
...
...
@@ -212,15 +213,11 @@ namespace uniset
raw
.
w
=
0
;
}
Byte
(
u
nsigned
char
b1
,
unsigned
char
b2
)
noexcept
Byte
(
u
int8_t
b1
,
uint8_t
b2
)
noexcept
{
raw
.
b
[
0
]
=
b1
;
raw
.
b
[
1
]
=
b2
;
}
Byte
(
const
long
&
val
)
noexcept
{
raw
.
w
=
val
;
}
Byte
(
const
ModbusRTU
::
ModbusData
dat
)
noexcept
{
...
...
@@ -240,16 +237,12 @@ namespace uniset
return
vtByte
;
}
// ------------------------------------------
operator
long
()
{
return
lroundf
(
raw
.
w
);
}
operator
unsigned
short
()
operator
uint16_t
()
{
return
raw
.
w
;
}
u
nsigned
char
operator
[](
const
in
t
i
)
u
int8_t
operator
[](
const
size_
t
i
)
{
return
raw
.
b
[
i
];
}
...
...
@@ -293,7 +286,7 @@ namespace uniset
return
raw
;
}
u
nsigned
shor
t
raw
;
u
int16_
t
raw
;
};
// --------------------------------------------------------------------------
class
Signed
...
...
@@ -332,7 +325,7 @@ namespace uniset
return
raw
;
}
signed
shor
t
raw
;
int16_
t
raw
;
};
// --------------------------------------------------------------------------
class
I2
...
...
@@ -344,8 +337,8 @@ namespace uniset
/*! тип хранения в памяти */
typedef
union
{
u
nsigned
shor
t
v
[
i2Size
];
int
val
;
//
u
int16_
t
v
[
i2Size
];
int
32_t
val
;
//
}
I2mem
;
// ------------------------------------------
// конструкторы на разные случаи...
...
...
@@ -354,7 +347,7 @@ namespace uniset
memset
(
raw
.
v
,
0
,
sizeof
(
raw
.
v
));
}
I2
(
int
v
)
noexcept
I2
(
int
32_t
v
)
noexcept
{
raw
.
val
=
v
;
}
...
...
@@ -377,7 +370,7 @@ namespace uniset
return
vtI2
;
}
// ------------------------------------------
operator
int
()
operator
int
32_t
()
{
return
raw
.
val
;
}
...
...
@@ -394,7 +387,7 @@ namespace uniset
raw_backorder
.
val
=
0
;
}
I2r
(
const
int
v
)
noexcept
:
I2
(
v
)
I2r
(
const
int
32_t
v
)
noexcept
:
I2
(
v
)
{
raw_backorder
=
raw
;
std
::
swap
(
raw_backorder
.
v
[
0
],
raw_backorder
.
v
[
1
]);
...
...
@@ -421,8 +414,8 @@ namespace uniset
/*! тип хранения в памяти */
typedef
union
{
u
nsigned
shor
t
v
[
u2Size
];
u
nsigned
in
t
val
;
//
u
int16_
t
v
[
u2Size
];
u
int32_
t
val
;
//
}
U2mem
;
// ------------------------------------------
// конструкторы на разные случаи...
...
...
@@ -431,7 +424,7 @@ namespace uniset
memset
(
raw
.
v
,
0
,
sizeof
(
raw
.
v
));
}
U2
(
u
nsigned
in
t
v
)
noexcept
U2
(
u
int32_
t
v
)
noexcept
{
raw
.
val
=
v
;
}
...
...
@@ -454,11 +447,21 @@ namespace uniset
return
vtU2
;
}
// ------------------------------------------
operator
unsigned
int
()
operator
uint32_t
()
{
return
raw
.
val
;
}
operator
long
()
{
return
raw
.
val
;
}
operator
unsigned
long
()
{
return
(
uint32_t
)
raw
.
val
;
}
U2mem
raw
;
};
// --------------------------------------------------------------------------
...
...
@@ -471,7 +474,7 @@ namespace uniset
raw_backorder
.
val
=
0
;
}
U2r
(
int
v
)
noexcept
:
U2
(
v
)
U2r
(
int
32_t
v
)
noexcept
:
U2
(
v
)
{
raw_backorder
=
raw
;
std
::
swap
(
raw_backorder
.
v
[
0
],
raw_backorder
.
v
[
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