Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
26e473c5
提交
26e473c5
authored
8月 20, 2019
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
init
上级
db665d73
全部展开
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
124 行增加
和
13 行删除
+124
-13
config.json
opencv-motion-detect/config.json
+2
-1
evmgr.cpp
opencv-motion-detect/evmgr.cpp
+118
-9
evpuller.cpp
opencv-motion-detect/evpuller.cpp
+0
-0
common.hpp
opencv-motion-detect/inc/common.hpp
+4
-3
没有找到文件。
opencv-motion-detect/config.json
浏览文件 @
26e473c5
...
...
@@ -2,10 +2,11 @@
"time"
:
0
,
"code"
:
0
,
"data"
:{
"
evmgr
"
:{
"
ILSEVMGR1
"
:{
"sn"
:
"ILSEVMGR1"
,
"addr"
:
"172.31.0.76"
,
"addr-cloud"
:
"172.31.0.76"
,
"proto"
:
"zmq"
,
"port-cloud"
:
5556
,
"port-router"
:
5550
,
"status"
:
1
,
...
...
opencv-motion-detect/evmgr.cpp
浏览文件 @
26e473c5
...
...
@@ -28,25 +28,133 @@ using namespace std;
**/
class
EvMgr
:
public
TinyThread
{
private
:
private
:
void
*
pRouterCtx
=
NULL
;
void
*
pRouter
=
NULL
;
json
config
;
string
devSn
;
void
init
(){
void
init
()
{
int
ret
;
bool
inited
=
false
;
// TODO: load config from local db
devSn
=
"ILSEVMGR1"
;
while
(
!
inited
)
{
try
{
config
=
json
::
parse
(
cloudutils
::
config
);
spdlog
::
info
(
"config dumps:
\n
{}"
,
config
.
dump
());
// TODO: verify sn
json
jmgr
=
config
[
"data"
][
devSn
];
string
proto
=
jmgr
[
"proto"
];
string
addr
;
if
(
proto
!=
"zmq"
){
spdlog
::
error
(
"evmgr {} unsupported protocol: {}, try fallback to zmq instead now..."
,
devSn
,
proto
);
}
protected
:
public
:
EvMgr
()
{
init
();
addr
=
"tcp://"
+
jmgr
[
"addr"
].
get
<
string
>
()
+
":"
+
to_string
(
jmgr
[
"port-router"
]);
// setup zmq
// TODO: connect to cloud
// router service
pRouterCtx
=
zmq_ctx_new
();
pRouter
=
zmq_socket
(
pRouterCtx
,
ZMQ_ROUTER
);
ret
=
zmq_bind
(
pRouter
,
addr
.
c_str
());
if
(
ret
<
0
)
{
spdlog
::
error
(
"evmgr {} failed to bind zmq at {} for reason: {}, retrying load configuration..."
,
devSn
,
addr
,
zmq_strerror
(
zmq_errno
()));
this_thread
::
sleep_for
(
chrono
::
seconds
(
3
));
continue
;
}
inited
=
true
;
}
catch
(
exception
&
e
)
{
spdlog
::
error
(
"evmgr {} exception on init() for: {}, retrying load configuration..."
,
devSn
,
e
.
what
());
this_thread
::
sleep_for
(
chrono
::
seconds
(
3
));
continue
;
}
}
spdlog
::
info
(
"evmgr {} successfuly inited"
,
devSn
);
}
~
EvMgr
(){
int
mqErrorMsg
(
string
cls
,
string
devSn
,
string
extraInfo
,
int
ret
)
{
if
(
ret
<
0
)
{
spdlog
::
error
(
"{} {} {}:{} "
,
cls
,
devSn
,
extraInfo
,
zmq_strerror
(
zmq_errno
()));
}
return
ret
;
}
};
void
handleMsg
(
string
body
[])
{
zmq_msg_t
msg
;
if
(
body
[
0
]
!=
devSn
)
{
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
spdlog
::
info
(
"evmgr {}, msg idRcv is {}, forwarding..."
,
devSn
,
body
[
0
]);
zmq_msg_init
(
&
msg
);
zmq_msg_init_data
(
&
msg
,
(
void
*
)
body
[
0
].
c_str
(),
body
[
0
].
size
(),
NULL
,
NULL
);
mqErrorMsg
(
"evmgr"
,
devSn
,
"failed to send zmq msg"
,
zmq_send_const
(
pRouter
,
zmq_msg_data
(
&
msg
),
body
[
0
].
size
(),
i
==
2
?
0
:
ZMQ_SNDMORE
));
zmq_msg_close
(
&
msg
);
}
}
else
{
// TODO: report msg
spdlog
::
info
(
"evmgr {} subsystem report msg received: {} {} {}"
,
devSn
,
body
[
0
],
body
[
1
],
body
[
2
]);
}
}
protected
:
void
run
(){
bool
bStopSig
=
false
;
int
ret
=
0
;
zmq_msg_t
msg
;
while
(
true
)
{
if
(
checkStop
()
==
true
)
{
bStopSig
=
true
;
break
;
}
string
msgBody
[
3
];
int64_t
more
=
0
;
// business logic
int
i
=
0
;
for
(;
i
<
3
;
i
++
)
{
mqErrorMsg
(
"evmgr"
,
devSn
,
"failed to init zmq msg"
,
zmq_msg_init
(
&
msg
));
mqErrorMsg
(
"evmgr"
,
devSn
,
"failed to recv zmq msg"
,
zmq_recvmsg
(
pRouter
,
&
msg
,
0
));
msgBody
[
i
]
=
string
((
char
*
)
zmq_msg_data
(
&
msg
));
zmq_msg_close
(
&
msg
);
spdlog
::
debug
(
"evmgr {} received[{}]: {} "
,
devSn
,
i
,
msgBody
[
i
]);
size_t
more_size
=
sizeof
(
more
);
mqErrorMsg
(
"evmgr"
,
devSn
,
"failed to get zmq sockopt"
,
zmq_getsockopt
(
pRouter
,
ZMQ_RCVMORE
,
&
more
,
&
more_size
));
if
(
!
more
)
{
break
;
}
}
if
(
i
>=
3
)
{
// full proto msg received.
handleMsg
(
msgBody
);
}
else
{
spdlog
::
warn
(
"partial msg recved, maybe hello msg: {}, {}, {}"
,
msgBody
[
0
],
msgBody
[
1
],
msgBody
[
2
]);
}
}
}
public
:
EvMgr
()
{
init
();
}
~
EvMgr
()
{
if
(
pRouter
!=
NULL
)
{
zmq_close
(
pRouter
);
pRouter
=
NULL
;
}
if
(
pRouterCtx
!=
NULL
){
zmq_ctx_destroy
(
pRouterCtx
);
pRouterCtx
=
NULL
;
}
}
};
int
main
(
int
argc
,
const
char
*
argv
[]){
int
main
(
int
argc
,
const
char
*
argv
[])
{
EvMgr
mgr
;
mgr
.
join
();
return
0
;
}
\ No newline at end of file
opencv-motion-detect/evpuller.cpp
浏览文件 @
26e473c5
差异被折叠。
点击展开。
opencv-motion-detect/inc/common.hpp
浏览文件 @
26e473c5
...
...
@@ -292,10 +292,11 @@ namespace cloudutils
"time":0,
"code":0,
"data":{
"
evmgr
":{
"
ILSEVMGR1
":{
"sn":"ILSEVMGR1",
"addr":"172.31.0.76",
"addr-cloud":"172.31.0.76",
"proto":"zmq",
"port-cloud":5556,
"port-router":5550,
"status":1,
...
...
@@ -312,7 +313,7 @@ namespace cloudutils
"sn":"ILSEVPULLER1",
"addr":"172.31.0.76",
"iid":1,
"port-pub":
"5556"
,
"port-pub":
5556
,
"status":1
}
],
...
...
@@ -355,7 +356,7 @@ namespace cloudutils
}
}
*/
const
char
*
config
=
"{
\"
time
\"
:0,
\"
code
\"
:0,
\"
data
\"
:{
\"
evmgr
\"
:{
\"
sn
\"
:
\"
ILSEVMGR1
\"
,
\"
addr
\"
:
\"
172.31.0.76
\"
,
\"
addr-cloud
\"
:
\"
172.31.0.76
\"
,
\"
port-cloud
\"
:5556,
\"
port-router
\"
:5550,
\"
status
\"
:1,
\"
ipcs
\"
:[{
\"
addr
\"
:
\"
172.31.0.51
\"
,
\"
proto
\"
:
\"
rtsp
\"
,
\"
user
\"
:
\"
admin
\"
,
\"
password
\"
:
\"
FWBWTU
\"
,
\"
status
\"
:1,
\"
modules
\"
:{
\"
evpuller
\"
:[{
\"
sn
\"
:
\"
ILSEVPULLER1
\"
,
\"
addr
\"
:
\"
172.31.0.76
\"
,
\"
iid
\"
:1,
\"
port-pub
\"
:
\"
5556
\"
,
\"
status
\"
:1}],
\"
evpusher
\"
:[{
\"
sn
\"
:
\"
ILSEVPUSHER1
\"
,
\"
iid
\"
:1,
\"
proto
\"
:
\"
rtsp
\"
,
\"
addrDest
\"
:
\"
40.73.41.176
\"
,
\"
portDest
\"
:554,
\"
user
\"
:
\"\"
,
\"
password
\"
:
\"\"
,
\"
token
\"
:
\"\"
,
\"
enabled
\"
:1,
\"
status
\"
:1}],
\"
evslicer
\"
:[{
\"
sn
\"
:
\"
ILSEVSLICER1
\"
,
\"
iid
\"
:1,
\"
path
\"
:
\"
slices
\"
,
\"
enabled
\"
:1,
\"
status
\"
:1}],
\"
evml
\"
:[{
\"
type
\"
:
\"
motion
\"
,
\"
sn
\"
:
\"
ILSEVMLMOTION1
\"
,
\"
iid
\"
:1,
\"
enabled
\"
:1,
\"
status
\"
:1}]}}]}}}"
;
const
char
*
config
=
"{
\"
time
\"
:0,
\"
code
\"
:0,
\"
data
\"
:{
\"
ILSEVMGR1
\"
:{
\"
sn
\"
:
\"
ILSEVMGR1
\"
,
\"
addr
\"
:
\"
172.31.0.76
\"
,
\"
addr-cloud
\"
:
\"
172.31.0.76
\"
,
\"
proto
\"
:
\"
zmq
\"
,
\"
port-cloud
\"
:5556,
\"
port-router
\"
:5550,
\"
status
\"
:1,
\"
ipcs
\"
:[{
\"
addr
\"
:
\"
172.31.0.51
\"
,
\"
proto
\"
:
\"
rtsp
\"
,
\"
user
\"
:
\"
admin
\"
,
\"
password
\"
:
\"
FWBWTU
\"
,
\"
status
\"
:1,
\"
modules
\"
:{
\"
evpuller
\"
:[{
\"
sn
\"
:
\"
ILSEVPULLER1
\"
,
\"
addr
\"
:
\"
172.31.0.76
\"
,
\"
iid
\"
:1,
\"
port-pub
\"
:5556
,
\"
status
\"
:1}],
\"
evpusher
\"
:[{
\"
sn
\"
:
\"
ILSEVPUSHER1
\"
,
\"
iid
\"
:1,
\"
proto
\"
:
\"
rtsp
\"
,
\"
addrDest
\"
:
\"
40.73.41.176
\"
,
\"
portDest
\"
:554,
\"
user
\"
:
\"\"
,
\"
password
\"
:
\"\"
,
\"
token
\"
:
\"\"
,
\"
enabled
\"
:1,
\"
status
\"
:1}],
\"
evslicer
\"
:[{
\"
sn
\"
:
\"
ILSEVSLICER1
\"
,
\"
iid
\"
:1,
\"
path
\"
:
\"
slices
\"
,
\"
enabled
\"
:1,
\"
status
\"
:1}],
\"
evml
\"
:[{
\"
type
\"
:
\"
motion
\"
,
\"
sn
\"
:
\"
ILSEVMLMOTION1
\"
,
\"
iid
\"
:1,
\"
enabled
\"
:1,
\"
status
\"
:1}]}}]}}}"
;
json
registry
(
const
char
*
sn
,
const
char
*
scn
,
int
iid
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论