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
d910b649
Commit
d910b649
authored
Mar 12, 2021
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Plain Diff
backported to p9 as 2.9.4-alt0.M90P.0.2 (with rpmbph script)
parents
eceea3c3
c4a917f8
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
117 additions
and
17 deletions
+117
-17
libuniset2.spec
conf/libuniset2.spec
+5
-2
UWebSocketGate.cc
extensions/UWebSocketGate/UWebSocketGate.cc
+16
-10
UWebSocketGate.h
extensions/UWebSocketGate/UWebSocketGate.h
+1
-1
start_fg.sh
extensions/UWebSocketGate/start_fg.sh
+1
-1
test_uwebsocketgate.cc
extensions/UWebSocketGate/tests/test_uwebsocketgate.cc
+88
-1
tests_with_sm.sh
extensions/UWebSocketGate/tests/tests_with_sm.sh
+3
-2
uwebsocketgate-test-configure.xml
...ns/UWebSocketGate/tests/uwebsocketgate-test-configure.xml
+3
-0
No files found.
conf/libuniset2.spec
View file @
d910b649
...
...
@@ -27,7 +27,7 @@
Name: libuniset2
Version: 2.9.4
Release: alt0.M90P.0.
1
Release: alt0.M90P.0.
2
Summary: UniSet - library for building distributed industrial control systems
License: LGPL-2.1
...
...
@@ -576,9 +576,12 @@ rm -f %buildroot%_docdir/%oname/html/*.md5
# history of current unpublished changes
%changelog
* Fri Mar
05 2021 Pavel Vainerman <pv@altlinux.ru> 2.9.4-alt0.M90P.0.1
* Fri Mar
12 2021 Pavel Vainerman <pv@altlinux.ru> 2.9.4-alt0.M90P.0.2
- backport to ALTLinux p9 (by rpmbph script)
* Fri Mar 12 2021 Pavel Vainerman <pv@altlinux.ru> 2.9.4-alt0.2
- test build for websocketgate
* Sun Jan 31 2021 Pavel Vainerman <pv@altlinux.ru> 2.9.3-alt2
- fixed lib version
...
...
extensions/UWebSocketGate/UWebSocketGate.cc
View file @
d910b649
...
...
@@ -78,10 +78,10 @@ UWebSocketGate::UWebSocketGate( uniset::ObjectId id, xmlNode* cnode, const strin
setMaxSizeOfMessageQueue
(
sz
);
#ifndef DISABLE_REST_API
wsHeartbeatTime_sec
=
(
float
)
conf
->
getArgPInt
(
"--"
+
prefix
+
"
ws-
heartbeat-time"
,
it
.
getProp
(
"wsHeartbeatTimeTime"
),
int
(
wsHeartbeatTime_sec
*
1000
))
/
1000.0
;
wsSendTime_sec
=
(
float
)
conf
->
getArgPInt
(
"--"
+
prefix
+
"
ws-
send-time"
,
it
.
getProp
(
"wsSendTime"
),
int
(
wsSendTime_sec
*
1000.0
))
/
1000.0
;
wsMaxSend
=
conf
->
getArgPInt
(
"--"
+
prefix
+
"
ws-
max-send"
,
it
.
getProp
(
"wsMaxSend"
),
wsMaxSend
);
wsMaxCmd
=
conf
->
getArgPInt
(
"--"
+
prefix
+
"
ws-
max-cmd"
,
it
.
getProp
(
"wsMaxCmd"
),
wsMaxCmd
);
wsHeartbeatTime_sec
=
(
float
)
conf
->
getArgPInt
(
"--"
+
prefix
+
"heartbeat-time"
,
it
.
getProp
(
"wsHeartbeatTimeTime"
),
int
(
wsHeartbeatTime_sec
*
1000
))
/
1000.0
;
wsSendTime_sec
=
(
float
)
conf
->
getArgPInt
(
"--"
+
prefix
+
"send-time"
,
it
.
getProp
(
"wsSendTime"
),
int
(
wsSendTime_sec
*
1000.0
))
/
1000.0
;
wsMaxSend
=
conf
->
getArgPInt
(
"--"
+
prefix
+
"max-send"
,
it
.
getProp
(
"wsMaxSend"
),
wsMaxSend
);
wsMaxCmd
=
conf
->
getArgPInt
(
"--"
+
prefix
+
"max-cmd"
,
it
.
getProp
(
"wsMaxCmd"
),
wsMaxCmd
);
httpHost
=
conf
->
getArgParam
(
"--"
+
prefix
+
"httpserver-host"
,
"localhost"
);
httpPort
=
conf
->
getArgPInt
(
"--"
+
prefix
+
"httpserver-port"
,
8081
);
...
...
@@ -239,11 +239,11 @@ void UWebSocketGate::help_print()
cout
<<
"--prefix-max-messages-processing num - Количество uniset-сообщений обрабатывамых за один раз. По умолчанию 50. По умолчанию: 100"
<<
endl
;
cout
<<
"websockets: "
<<
endl
;
cout
<<
"--prefix-
ws-
max num - Максимальное количество websocket-ов"
<<
endl
;
cout
<<
"--prefix-
ws-
heartbeat-time msec - Период сердцебиения в соединении. По умолчанию: 3000 мсек"
<<
endl
;
cout
<<
"--prefix-
ws-
send-time msec - Период посылки сообщений. По умолчанию: 500 мсек"
<<
endl
;
cout
<<
"--prefix-
ws-max num
- Максимальное число сообщений посылаемых за один раз. По умолчанию: 200"
<<
endl
;
cout
<<
"--prefix-
ws-cmd num - Максимальное число команд обрабатываемых за один раз. По умолчанию: 1
00"
<<
endl
;
cout
<<
"--prefix-max num - Максимальное количество websocket-ов"
<<
endl
;
cout
<<
"--prefix-heartbeat-time msec - Период сердцебиения в соединении. По умолчанию: 3000 мсек"
<<
endl
;
cout
<<
"--prefix-send-time msec - Период посылки сообщений. По умолчанию: 500 мсек"
<<
endl
;
cout
<<
"--prefix-
max-send num
- Максимальное число сообщений посылаемых за один раз. По умолчанию: 200"
<<
endl
;
cout
<<
"--prefix-
max-cmd num - Максимальное число команд обрабатываемых за один раз. По умолчанию: 2
00"
<<
endl
;
cout
<<
"http: "
<<
endl
;
cout
<<
"--prefix-httpserver-host ip - IP на котором слушает http сервер. По умолчанию: localhost"
<<
endl
;
...
...
@@ -304,8 +304,8 @@ void UWebSocketGate::onActivate( ev::async& watcher, int revents )
{
if
(
!
s
->
isActive
()
)
{
s
->
doCommand
(
ui
);
s
->
set
(
loop
,
wscmd
);
s
->
doCommand
(
ui
);
}
}
}
...
...
@@ -844,6 +844,9 @@ void UWebSocketGate::UWebSocket::sensorInfo( const uniset::SensorMessage* sm )
// -----------------------------------------------------------------------------
void
UWebSocketGate
::
UWebSocket
::
doCommand
(
const
std
::
shared_ptr
<
UInterface
>&
ui
)
{
if
(
qcmd
.
empty
()
)
return
;
for
(
size_t
i
=
0
;
i
<
maxcmd
&&
!
qcmd
.
empty
();
i
++
)
{
auto
s
=
qcmd
.
front
();
...
...
@@ -893,6 +896,9 @@ void UWebSocketGate::UWebSocket::doCommand( const std::shared_ptr<UInterface>& u
sendResponse
(
s
);
}
}
if
(
!
qcmd
.
empty
()
&&
cmdsignal
)
cmdsignal
->
send
();
}
// -----------------------------------------------------------------------------
void
UWebSocketGate
::
UWebSocket
::
sendShortResponse
(
sinfo
&
si
)
...
...
extensions/UWebSocketGate/UWebSocketGate.h
View file @
d910b649
...
...
@@ -166,7 +166,7 @@ namespace uniset
- "set:id1=val1,id2=val2,name3=val4,..." - выставить значение датчиков
- "ask:id1,id2,name3,..." - подписаться на уведомления об изменении датчиков (sensorInfo)
- "del:id1,id2,name3,..." - отказаться от уведомления об изменении датчиков
- "get:id1,id2,name3,..." - получить текущее значение датчиков (разовое сообщение ShortSensorInfo)
- "get:id1,id2,name3,..." - получить текущее значение датчиков (разовое сообщение ShortSensorInfo)
*/
class
UWebSocketGate
:
public
UniSetObject
,
...
...
extensions/UWebSocketGate/start_fg.sh
View file @
d910b649
...
...
@@ -2,4 +2,4 @@
ulimit
-Sc
1000000
uniset2-start.sh
-f
./uniset2-wsgate
--confile
test.xml
--ws-name
UWebSocketGate1
--ws-log-add-levels
any
$*
uniset2-start.sh
-f
./uniset2-wsgate
--confile
test.xml
--ws-name
UWebSocketGate1
--ws-log-add-levels
any
--ws-max-cmd
3
$*
extensions/UWebSocketGate/tests/test_uwebsocketgate.cc
View file @
d910b649
...
...
@@ -129,7 +129,6 @@ TEST_CASE("[UWebSocketGate]: ask", "[uwebsocketgate]")
// sensorInfo
ui
->
setValue
(
2
,
84
);
memset
(
buffer
,
0
,
sizeof
(
buffer
));
ws
.
receiveFrame
(
buffer
,
sizeof
(
buffer
),
flags
);
...
...
@@ -146,7 +145,95 @@ TEST_CASE("[UWebSocketGate]: ask", "[uwebsocketgate]")
REQUIRE
(
j
->
get
(
"type"
).
convert
<
std
::
string
>
()
==
"SensorInfo"
);
REQUIRE
(
j
->
get
(
"iotype"
).
convert
<
std
::
string
>
()
==
"AI"
);
REQUIRE
(
j
->
get
(
"value"
).
convert
<
long
>
()
==
84
);
}
// -----------------------------------------------------------------------------
TEST_CASE
(
"[UWebSocketGate]: ask max"
,
"[uwebsocketgate][cmdmax]"
)
{
try
{
InitTest
();
HTTPClientSession
cs
(
addr
,
port
);
HTTPRequest
request
(
HTTPRequest
::
HTTP_GET
,
"/wsgate"
,
HTTPRequest
::
HTTP_1_1
);
HTTPResponse
response
;
WebSocket
ws
(
cs
,
request
,
response
);
ui
->
setValue
(
1
,
1
);
ui
->
setValue
(
2
,
42
);
ui
->
setValue
(
3
,
42
);
ui
->
setValue
(
4
,
1
);
ui
->
setValue
(
5
,
42
);
ui
->
setValue
(
6
,
42
);
std
::
string
cmd
(
"ask:1,2,3,4,5,6"
);
ws
.
sendFrame
(
cmd
.
data
(),
(
int
)
cmd
.
size
());
char
buffer
[
1024
]
=
{};
int
flags
;
ws
.
receiveFrame
(
buffer
,
sizeof
(
buffer
),
flags
);
REQUIRE
(
flags
==
WebSocket
::
FRAME_TEXT
);
Poco
::
JSON
::
Parser
parser
;
auto
result
=
parser
.
parse
(
buffer
);
Poco
::
JSON
::
Object
::
Ptr
json
=
result
.
extract
<
Poco
::
JSON
::
Object
::
Ptr
>
();
REQUIRE
(
json
);
// {
// "data": [
// {"type": "SensorInfo"...},
// {"type": "SensorInfo"...},
// {"type": "SensorInfo"...}
// ...
// ]
// }
auto
jdata
=
json
->
get
(
"data"
).
extract
<
Poco
::
JSON
::
Array
::
Ptr
>
();
REQUIRE
(
jdata
);
REQUIRE
(
jdata
->
size
()
==
6
);
for
(
int
i
=
0
;
i
<
6
;
i
++
)
{
auto
j
=
jdata
->
getObject
(
i
);
REQUIRE
(
j
);
REQUIRE
(
j
->
get
(
"type"
).
convert
<
std
::
string
>
()
==
"SensorInfo"
);
long
id
=
j
->
get
(
"id"
).
convert
<
long
>
();
if
(
id
==
1
||
id
==
3
)
{
REQUIRE
(
j
->
get
(
"iotype"
).
convert
<
std
::
string
>
()
==
"DI"
);
REQUIRE
(
j
->
get
(
"value"
).
convert
<
long
>
()
==
1
);
}
else
{
REQUIRE
(
j
->
get
(
"iotype"
).
convert
<
std
::
string
>
()
==
"AI"
);
REQUIRE
(
j
->
get
(
"value"
).
convert
<
long
>
()
==
42
);
}
}
// sensorInfo
ui
->
setValue
(
2
,
84
);
memset
(
buffer
,
0
,
sizeof
(
buffer
));
ws
.
receiveFrame
(
buffer
,
sizeof
(
buffer
),
flags
);
REQUIRE
(
flags
==
WebSocket
::
FRAME_TEXT
);
result
=
parser
.
parse
(
buffer
);
json
=
result
.
extract
<
Poco
::
JSON
::
Object
::
Ptr
>
();
REQUIRE
(
json
);
jdata
=
json
->
get
(
"data"
).
extract
<
Poco
::
JSON
::
Array
::
Ptr
>
();
REQUIRE
(
jdata
);
REQUIRE
(
jdata
->
size
()
==
1
);
auto
j
=
jdata
->
getObject
(
0
);
REQUIRE
(
j
);
REQUIRE
(
j
->
get
(
"type"
).
convert
<
std
::
string
>
()
==
"SensorInfo"
);
REQUIRE
(
j
->
get
(
"iotype"
).
convert
<
std
::
string
>
()
==
"AI"
);
REQUIRE
(
j
->
get
(
"value"
).
convert
<
long
>
()
==
84
);
}
// TODO: WTF?
catch
(
std
::
exception
&
ex
)
{}
}
// -----------------------------------------------------------------------------
TEST_CASE
(
"[UWebSocketGate]: del"
,
"[uwebsocketgate]"
)
...
...
extensions/UWebSocketGate/tests/tests_with_sm.sh
View file @
d910b649
...
...
@@ -9,7 +9,8 @@ cd ../../../Utilities/Admin/
cd
-
./uniset2-start.sh
-f
./tests-with-sm
$*
--
--confile
uwebsocketgate-test-configure.xml
--e-startup-pause
10
\
--ws-name
UWebSocketGate1
--ws-httpserverhost-addr
127.0.0.1
--ws-httpserver-port
8081
#--ws-log-add-levels any
--ws-name
UWebSocketGate1
--ws-httpserverhost-addr
127.0.0.1
--ws-httpserver-port
8081
--ws-max-cmd
3
# --ws-log-add-levels any
extensions/UWebSocketGate/tests/uwebsocketgate-test-configure.xml
View file @
d910b649
...
...
@@ -46,6 +46,9 @@
<item
id=
"1"
iotype=
"DI"
name=
"DI1_S"
textname=
"DI sensor 1"
/>
<item
id=
"2"
iotype=
"AI"
name=
"AI1_S"
textname=
"AI sensor 1"
default=
"2"
undefined_value=
"65635"
/>
<item
id=
"3"
iotype=
"AI"
name=
"AI2_S"
textname=
"AI sensor 2"
default=
"3"
/>
<item
id=
"4"
iotype=
"DI"
name=
"DI2_S"
textname=
"DI sensor 2"
/>
<item
id=
"5"
iotype=
"AI"
name=
"AI3_S"
textname=
"AI sensor 3"
default=
"2"
undefined_value=
"65635"
/>
<item
id=
"6"
iotype=
"AI"
name=
"AI4_S"
textname=
"AI sensor 4"
default=
"3"
/>
</sensors>
<thresholds/>
<controllers
name=
"Controllers"
>
...
...
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