Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
4a60847c
提交
4a60847c
authored
8月 23, 2019
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
init
上级
1735612e
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
92 行增加
和
55 行删除
+92
-55
evmgr.cpp
opencv-motion-detect/evmgr.cpp
+77
-50
evmlmotion.cpp
opencv-motion-detect/evmlmotion.cpp
+4
-4
zmqhelper.hpp
opencv-motion-detect/inc/zmqhelper.hpp
+11
-1
没有找到文件。
opencv-motion-detect/evmgr.cpp
浏览文件 @
4a60847c
...
@@ -54,7 +54,7 @@ private:
...
@@ -54,7 +54,7 @@ private:
config
=
json
::
parse
(
cloudutils
::
config
);
config
=
json
::
parse
(
cloudutils
::
config
);
spdlog
::
info
(
"config dumps:
\n
{}"
,
config
.
dump
());
spdlog
::
info
(
"config dumps:
\n
{}"
,
config
.
dump
());
// TODO: verify sn
// TODO: verify sn
if
(
!
config
.
count
(
"data"
)
||!
config
[
"data"
].
count
(
devSn
)
||!
config
[
"data"
][
devSn
].
count
(
"ipcs"
)){
if
(
!
config
.
count
(
"data"
)
||!
config
[
"data"
].
count
(
devSn
)
||!
config
[
"data"
][
devSn
].
count
(
"ipcs"
))
{
spdlog
::
error
(
"evmgr {} invalid config. reload now..."
,
devSn
);
spdlog
::
error
(
"evmgr {} invalid config. reload now..."
,
devSn
);
this_thread
::
sleep_for
(
chrono
::
seconds
(
3
));
this_thread
::
sleep_for
(
chrono
::
seconds
(
3
));
continue
;
continue
;
...
@@ -62,8 +62,8 @@ private:
...
@@ -62,8 +62,8 @@ private:
jmgr
=
config
[
"data"
][
devSn
];
jmgr
=
config
[
"data"
][
devSn
];
string
proto
=
jmgr
[
"proto"
];
string
proto
=
jmgr
[
"proto"
];
string
addr
;
string
addr
;
if
(
proto
!=
"zmq"
){
if
(
proto
!=
"zmq"
)
{
spdlog
::
error
(
"evmgr {} unsupported protocol: {}, try fallback to zmq instead now..."
,
devSn
,
proto
);
spdlog
::
error
(
"evmgr {} unsupported protocol: {}, try fallback to zmq instead now..."
,
devSn
,
proto
);
}
}
addr
=
"tcp://"
+
jmgr
[
"addr"
].
get
<
string
>
()
+
":"
+
to_string
(
jmgr
[
"port-router"
]);
addr
=
"tcp://"
+
jmgr
[
"addr"
].
get
<
string
>
()
+
":"
+
to_string
(
jmgr
[
"port-router"
]);
...
@@ -92,33 +92,55 @@ private:
...
@@ -92,33 +92,55 @@ private:
spdlog
::
info
(
"evmgr {} successfuly inited"
,
devSn
);
spdlog
::
info
(
"evmgr {} successfuly inited"
,
devSn
);
}
}
int
mqErrorMsg
(
string
cls
,
string
devSn
,
string
extraInfo
,
int
ret
)
{
int
mqErrorMsg
(
string
cls
,
string
devSn
,
string
extraInfo
,
int
ret
)
{
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
spdlog
::
error
(
"{} {} {}:{} "
,
cls
,
devSn
,
extraInfo
,
zmq_strerror
(
zmq_errno
()));
spdlog
::
error
(
"{} {} {}:{} "
,
cls
,
devSn
,
extraInfo
,
zmq_strerror
(
zmq_errno
()));
}
}
return
ret
;
return
ret
;
}
}
int
handleMsg
(
vector
<
vector
<
uint8_t
>
>
&
body
)
{
int
handleMsg
(
vector
<
vector
<
uint8_t
>
>
&
body
)
{
int
ret
=
0
;
int
ret
=
0
;
zmq_msg_t
msg
;
zmq_msg_t
msg
;
// ID_SENDER, ID_TARGET, meta ,MSG
// ID_SENDER, ID_TARGET, meta ,MSG
string
selfId
,
peerId
,
meta
;
string
selfId
,
peerId
,
meta
;
if
(
body
.
size
()
==
2
&&
body
[
1
].
size
()
==
0
)
{
if
(
body
.
size
()
==
2
&&
body
[
1
].
size
()
==
0
)
{
selfId
=
body2str
(
body
[
0
]);
selfId
=
body2str
(
body
[
0
]);
spdlog
::
warn
(
"evmgr {} peer disconnected: {}"
,
devSn
,
selfId
)
;
bool
eventConn
=
false
;
if
(
peerStatus
.
count
(
selfId
)
==
0
)
{
if
(
peerStatus
.
count
(
selfId
)
==
0
||
peerStatus
[
selfId
]
==
0
)
{
peerStatus
[
selfId
]
=
chrono
::
duration_cast
<
chrono
::
seconds
>
(
chrono
::
system_clock
::
now
().
time_since_epoch
()).
count
();
peerStatus
[
selfId
]
=
chrono
::
duration_cast
<
chrono
::
seconds
>
(
chrono
::
system_clock
::
now
().
time_since_epoch
()).
count
();
}
else
{
spdlog
::
info
(
"evmgr {} peer connected: {}"
,
devSn
,
selfId
);
eventConn
=
true
;
}
else
{
peerStatus
[
selfId
]
=
0
;
peerStatus
[
selfId
]
=
0
;
spdlog
::
warn
(
"evmgr {} peer disconnected: {}"
,
devSn
,
selfId
);
}
// event
json
jEvt
;
jEvt
[
"type"
]
=
EV_MSG_TYPE_CONN_STAT
;
jEvt
[
"gid"
]
=
selfId
;
if
(
eventConn
)
{
jEvt
[
"event"
]
=
EV_MSG_EVENT_CONN_CONN
;
}
else
{
jEvt
[
"event"
]
=
EV_MSG_EVENT_CONN_DISCONN
;
}
}
eventQue
.
push
(
jEvt
.
dump
());
if
(
eventQue
.
size
()
>
MAX_EVENT_QUEUE_SIZE
)
{
eventQue
.
pop
();
}
return
0
;
return
0
;
}
else
if
(
body
.
size
()
!=
4
)
{
}
else
if
(
body
.
size
()
!=
4
)
{
spdlog
::
warn
(
"evmgr {} dropped an invalid message, size: {}"
,
devSn
,
body
.
size
());
spdlog
::
warn
(
"evmgr {} dropped an invalid message, size: {}"
,
devSn
,
body
.
size
());
return
0
;
return
0
;
}
}
meta
=
body2str
(
body
[
2
]);
meta
=
body2str
(
body
[
2
]);
selfId
=
body2str
(
body
[
0
]);
selfId
=
body2str
(
body
[
0
]);
peerId
=
body2str
(
body
[
1
]);
peerId
=
body2str
(
body
[
1
]);
...
@@ -130,13 +152,14 @@ private:
...
@@ -130,13 +152,14 @@ private:
// message to other peer
// message to other peer
// check peer status
// check peer status
vector
<
vector
<
uint8_t
>
>
v
=
{
body
[
1
],
body
[
0
],
body
[
2
],
body
[
3
]};
vector
<
vector
<
uint8_t
>
>
v
=
{
body
[
1
],
body
[
0
],
body
[
2
],
body
[
3
]};
if
(
peerStatus
.
count
(
peerId
)
!=
0
&&
peerStatus
[
peerId
]
!=
0
)
{
if
(
peerStatus
.
count
(
peerId
)
!=
0
&&
peerStatus
[
peerId
]
!=
0
)
{
spdlog
::
info
(
"evmgr {} route msg from {} to {}"
,
devSn
,
selfId
,
peerId
);
spdlog
::
info
(
"evmgr {} route msg from {} to {}"
,
devSn
,
selfId
,
peerId
);
ret
=
z_send_multiple
(
pRouter
,
v
);
ret
=
z_send_multiple
(
pRouter
,
v
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
spdlog
::
error
(
"evmgr {} failed to send multiple: {}"
,
devSn
,
zmq_strerror
(
zmq_errno
()));
spdlog
::
error
(
"evmgr {} failed to send multiple: {}"
,
devSn
,
zmq_strerror
(
zmq_errno
()));
}
}
}
else
{
}
else
{
// cache
// cache
spdlog
::
warn
(
"evmgr {} cached msg from {} to {}"
,
devSn
,
selfId
,
peerId
);
spdlog
::
warn
(
"evmgr {} cached msg from {} to {}"
,
devSn
,
selfId
,
peerId
);
lock_guard
<
mutex
>
lock
(
cacheLock
);
lock_guard
<
mutex
>
lock
(
cacheLock
);
...
@@ -147,7 +170,7 @@ private:
...
@@ -147,7 +170,7 @@ private:
}
}
// check if event
// check if event
try
{
try
{
string
metaType
=
json
::
parse
(
meta
)[
"type"
];
string
metaType
=
json
::
parse
(
meta
)[
"type"
];
if
(
metaType
==
EV_MSG_META_EVENT
)
{
if
(
metaType
==
EV_MSG_META_EVENT
)
{
eventQue
.
push
(
body2str
(
body
[
3
]));
eventQue
.
push
(
body2str
(
body
[
3
]));
...
@@ -155,10 +178,12 @@ private:
...
@@ -155,10 +178,12 @@ private:
eventQue
.
pop
();
eventQue
.
pop
();
}
}
}
}
}
catch
(
exception
&
e
)
{
}
catch
(
exception
&
e
)
{
spdlog
::
error
(
"evmgr {} exception parse event msg from {} to {}: "
,
devSn
,
selfId
,
peerId
,
e
.
what
());
spdlog
::
error
(
"evmgr {} exception parse event msg from {} to {}: "
,
devSn
,
selfId
,
peerId
,
e
.
what
());
}
}
}
else
{
}
else
{
// message to mgr
// message to mgr
spdlog
::
info
(
"evmgr {} subsystem report msg received: {}; {}; {}"
,
devSn
,
zmqhelper
::
body2str
(
body
[
0
]),
zmqhelper
::
body2str
(
body
[
1
]),
zmqhelper
::
body2str
(
body
[
2
]));
spdlog
::
info
(
"evmgr {} subsystem report msg received: {}; {}; {}"
,
devSn
,
zmqhelper
::
body2str
(
body
[
0
]),
zmqhelper
::
body2str
(
body
[
1
]),
zmqhelper
::
body2str
(
body
[
2
]));
if
(
meta
==
"pong"
||
meta
==
"ping"
)
{
if
(
meta
==
"pong"
||
meta
==
"ping"
)
{
...
@@ -166,18 +191,19 @@ private:
...
@@ -166,18 +191,19 @@ private:
spdlog
::
info
(
"evmgr {}, ping msg from {}"
,
devSn
,
selfId
);
spdlog
::
info
(
"evmgr {}, ping msg from {}"
,
devSn
,
selfId
);
if
(
meta
==
"ping"
)
{
if
(
meta
==
"ping"
)
{
if
(
cachedMsg
.
find
(
selfId
)
!=
cachedMsg
.
end
())
{
if
(
cachedMsg
.
find
(
selfId
)
!=
cachedMsg
.
end
())
{
while
(
!
cachedMsg
[
selfId
].
empty
()){
while
(
!
cachedMsg
[
selfId
].
empty
())
{
lock_guard
<
mutex
>
lock
(
cacheLock
);
lock_guard
<
mutex
>
lock
(
cacheLock
);
auto
v
=
cachedMsg
[
selfId
].
front
();
auto
v
=
cachedMsg
[
selfId
].
front
();
cachedMsg
[
selfId
].
pop
();
cachedMsg
[
selfId
].
pop
();
ret
=
z_send_multiple
(
pRouter
,
v
);
ret
=
z_send_multiple
(
pRouter
,
v
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
spdlog
::
error
(
"evmgr {} failed to send multiple: {}"
,
devSn
,
zmq_strerror
(
zmq_errno
()));
spdlog
::
error
(
"evmgr {} failed to send multiple: {}"
,
devSn
,
zmq_strerror
(
zmq_errno
()));
}
}
}
}
}
}
}
}
}
else
{
}
else
{
// TODO:
// TODO:
spdlog
::
warn
(
"evmgr {} received unknown meta {} from {}"
,
devSn
,
meta
,
selfId
);
spdlog
::
warn
(
"evmgr {} received unknown meta {} from {}"
,
devSn
,
meta
,
selfId
);
}
}
...
@@ -186,43 +212,44 @@ private:
...
@@ -186,43 +212,44 @@ private:
return
ret
;
return
ret
;
}
}
int
get_monitor_event
(
void
*
monitor
,
int
*
value
,
char
**
address
)
int
get_monitor_event
(
void
*
monitor
,
int
*
value
,
char
**
address
)
{
{
// First frame in message contains event number and value
// First frame in message contains event number and value
zmq_msg_t
msg
;
zmq_msg_t
msg
;
zmq_msg_init
(
&
msg
);
zmq_msg_init
(
&
msg
);
if
(
zmq_msg_recv
(
&
msg
,
monitor
,
0
)
==
-
1
)
if
(
zmq_msg_recv
(
&
msg
,
monitor
,
0
)
==
-
1
)
return
-
1
;
// Interrupted, presumably
return
-
1
;
// Interrupted, presumably
assert
(
zmq_msg_more
(
&
msg
));
assert
(
zmq_msg_more
(
&
msg
));
uint8_t
*
data
=
(
uint8_t
*
)
zmq_msg_data
(
&
msg
);
uint8_t
*
data
=
(
uint8_t
*
)
zmq_msg_data
(
&
msg
);
uint16_t
event
=
*
(
uint16_t
*
)
(
data
);
uint16_t
event
=
*
(
uint16_t
*
)
(
data
);
if
(
value
)
if
(
value
)
*
value
=
*
(
uint32_t
*
)
(
data
+
2
);
*
value
=
*
(
uint32_t
*
)
(
data
+
2
);
// Second frame in message contains event address
// Second frame in message contains event address
zmq_msg_init
(
&
msg
);
zmq_msg_init
(
&
msg
);
if
(
zmq_msg_recv
(
&
msg
,
monitor
,
0
)
==
-
1
)
if
(
zmq_msg_recv
(
&
msg
,
monitor
,
0
)
==
-
1
)
return
-
1
;
// Interrupted, presumably
return
-
1
;
// Interrupted, presumably
assert
(
!
zmq_msg_more
(
&
msg
));
assert
(
!
zmq_msg_more
(
&
msg
));
if
(
address
)
{
if
(
address
)
{
uint8_t
*
data
=
(
uint8_t
*
)
zmq_msg_data
(
&
msg
);
uint8_t
*
data
=
(
uint8_t
*
)
zmq_msg_data
(
&
msg
);
size_t
size
=
zmq_msg_size
(
&
msg
);
size_t
size
=
zmq_msg_size
(
&
msg
);
*
address
=
(
char
*
)
malloc
(
size
+
1
);
*
address
=
(
char
*
)
malloc
(
size
+
1
);
memcpy
(
*
address
,
data
,
size
);
memcpy
(
*
address
,
data
,
size
);
(
*
address
)[
size
]
=
0
;
(
*
address
)[
size
]
=
0
;
}
}
return
event
;
return
event
;
}
}
protected
:
protected
:
void
run
(){
void
run
()
{
bool
bStopSig
=
false
;
bool
bStopSig
=
false
;
int
ret
=
0
;
int
ret
=
0
;
zmq_msg_t
msg
;
zmq_msg_t
msg
;
// TODO: don't need this anymore, since I've used the draft feature of ZOUTER_NOTIFICATION instead
// TODO: don't need this anymore, since I've used the draft feature of ZOUTER_NOTIFICATION instead
// disabled because:
// disabled because:
// 1. it can't determine which peer disconnected, but only the underline socket FD.
// 1. it can't determine which peer disconnected, but only the underline socket FD.
// 2. used the draft feature of ZMQ_ROUTER_NOTIFY instead to capture peer module disconnections such as evpuser, evmlmotion.
// 2. used the draft feature of ZMQ_ROUTER_NOTIFY instead to capture peer module disconnections such as evpuser, evmlmotion.
// thread thMon = thread([&,this](){
// thread thMon = thread([&,this](){
// int ret = 0;
// int ret = 0;
...
@@ -256,7 +283,7 @@ protected:
...
@@ -256,7 +283,7 @@ protected:
auto
body
=
z_recv_multiple
(
pRouter
,
false
);
auto
body
=
z_recv_multiple
(
pRouter
,
false
);
if
(
body
.
size
()
==
0
)
{
if
(
body
.
size
()
==
0
)
{
spdlog
::
error
(
"evmgr {} failed to receive multiple msg: {}"
,
devSn
,
zmq_strerror
(
zmq_errno
()));
spdlog
::
error
(
"evmgr {} failed to receive multiple msg: {}"
,
devSn
,
zmq_strerror
(
zmq_errno
()));
continue
;
continue
;
}
}
// full proto msg received.
// full proto msg received.
handleMsg
(
body
);
handleMsg
(
body
);
...
@@ -278,7 +305,7 @@ public:
...
@@ -278,7 +305,7 @@ public:
zmq_close
(
pRouter
);
zmq_close
(
pRouter
);
pRouter
=
NULL
;
pRouter
=
NULL
;
}
}
if
(
pRouterCtx
!=
NULL
){
if
(
pRouterCtx
!=
NULL
)
{
zmq_ctx_destroy
(
pRouterCtx
);
zmq_ctx_destroy
(
pRouterCtx
);
pRouterCtx
=
NULL
;
pRouterCtx
=
NULL
;
}
}
...
...
opencv-motion-detect/evmlmotion.cpp
浏览文件 @
4a60847c
...
@@ -453,9 +453,9 @@ private:
...
@@ -453,9 +453,9 @@ private:
evtState
=
IN
;
evtState
=
IN
;
json
p
;
json
p
;
spdlog
::
info
(
"state: PRE->IN"
);
spdlog
::
info
(
"state: PRE->IN"
);
p
[
"type"
]
=
"motion"
;
p
[
"type"
]
=
EV_MSG_TYPE_AI_MOTION
;
p
[
"gid"
]
=
selfId
;
p
[
"gid"
]
=
selfId
;
p
[
"event"
]
=
"end"
;
p
[
"event"
]
=
EV_MSG_EVENT_MOTION_START
;
p
[
"ts"
]
=
chrono
::
duration_cast
<
chrono
::
seconds
>
(
evtStartTmLast
.
time_since_epoch
()).
count
();
p
[
"ts"
]
=
chrono
::
duration_cast
<
chrono
::
seconds
>
(
evtStartTmLast
.
time_since_epoch
()).
count
();
//p["frame"] = origin.clone();
//p["frame"] = origin.clone();
evtQueue
->
push
(
p
.
dump
());
evtQueue
->
push
(
p
.
dump
());
...
@@ -489,9 +489,9 @@ private:
...
@@ -489,9 +489,9 @@ private:
spdlog
::
info
(
"state: POST->NONE"
);
spdlog
::
info
(
"state: POST->NONE"
);
evtState
=
NONE
;
evtState
=
NONE
;
json
p
;
json
p
;
p
[
"type"
]
=
"motion"
;
p
[
"type"
]
=
EV_MSG_TYPE_AI_MOTION
;
p
[
"gid"
]
=
selfId
;
p
[
"gid"
]
=
selfId
;
p
[
"event"
]
=
"end"
;
p
[
"event"
]
=
EV_MSG_EVENT_MOTION_END
;
p
[
"ts"
]
=
chrono
::
duration_cast
<
chrono
::
seconds
>
(
evtStartTmLast
.
time_since_epoch
()).
count
()
+
(
int
)(
detPara
.
post
/
2
);
p
[
"ts"
]
=
chrono
::
duration_cast
<
chrono
::
seconds
>
(
evtStartTmLast
.
time_since_epoch
()).
count
()
+
(
int
)(
detPara
.
post
/
2
);
evtQueue
->
push
(
p
.
dump
());
evtQueue
->
push
(
p
.
dump
());
if
(
evtQueue
->
size
()
>
MAX_EVENT_QUEUE_SIZE
*
2
)
{
if
(
evtQueue
->
size
()
>
MAX_EVENT_QUEUE_SIZE
*
2
)
{
...
...
opencv-motion-detect/inc/zmqhelper.hpp
浏览文件 @
4a60847c
...
@@ -20,8 +20,18 @@ namespace zmqhelper {
...
@@ -20,8 +20,18 @@ namespace zmqhelper {
#define EV_MSG_META_UPDATE "update"
#define EV_MSG_META_UPDATE "update"
#define EV_MSG_META_EVENT "event"
#define EV_MSG_META_EVENT "event"
#define EV_MSG_META_AVFORMATCTX "afctx"
#define EV_MSG_META_AVFORMATCTX "afctx"
#define EV_MSG_TYPE_AI_MOTION "ai_motion"
#define EV_MSG_TYPE_CONN_STAT "connstat"
#define EV_MSG_TYPE_SYS_STAT "sysstat"
#define EV_MSG_EVENT_MOTION_START "start"
#define EV_MSG_EVENT_MOTION_END "end"
#define EV_MSG_EVENT_CONN_CONN "connect"
#define EV_MSG_EVENT_CONN_DISCONN "disconnect"
#define EV_NUM_CACHE_PERPEER 100
#define EV_NUM_CACHE_PERPEER 100
#define MAX_EVENT_QUEUE_SIZE
2
0
#define MAX_EVENT_QUEUE_SIZE
5
0
//
//
string
body2str
(
vector
<
uint8_t
>
body
)
string
body2str
(
vector
<
uint8_t
>
body
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论