Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evcamera
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evcamera
Commits
69852f39
提交
69852f39
authored
6月 01, 2020
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
upload svc enhencement and bugfix
上级
ead11e58
隐藏空白字符变更
内嵌
并排
正在显示
13 个修改的文件
包含
203 行增加
和
35 行删除
+203
-35
evutils.cc
hi3518/evutils.cc
+15
-2
internal_types.h
hi3518/internal_types.h
+1
-0
main.cc
hi3518/main.cc
+27
-7
motion.cc
hi3518/motion.cc
+12
-0
motiondetect.hpp
hi3518/motiondetect.hpp
+32
-3
ntp.cc
hi3518/ntp.cc
+12
-0
ptz.cc
hi3518/ptz.cc
+12
-0
raw_tcp.cc
hi3518/raw_tcp.cc
+43
-17
raw_tcp.h
hi3518/raw_tcp.h
+3
-1
smart.cc
hi3518/smart.cc
+15
-2
evpacket.h
include/evpacket.h
+12
-0
mqtt_helper.cc
include/mqtt_helper.cc
+7
-3
videogateway.cc
server/videogateway.cc
+12
-0
没有找到文件。
hi3518/evutils.cc
浏览文件 @
69852f39
/**
* @file evutils.cc
*
* @brief this is the main file impelents helpers
*
* @ingroup evcamera
*
* @author Bruce Lu
* Contact: lzbgt@icloud.com
*
*/
#include "evutils.hpp"
#include "evutils.hpp"
using
namespace
std
;
using
namespace
std
;
using
namespace
jsoncons
;
using
namespace
jsoncons
;
using
namespace
jsoncons
::
literals
;
using
namespace
jsoncons
::
literals
;
unsigned
short
crc16
(
const
unsigned
char
*
data_p
,
unsigned
char
length
){
unsigned
short
crc16
(
const
unsigned
char
*
data_p
,
unsigned
char
length
)
{
unsigned
char
x
;
unsigned
char
x
;
unsigned
short
crc
=
0xFFFF
;
unsigned
short
crc
=
0xFFFF
;
while
(
length
--
){
while
(
length
--
)
{
x
=
crc
>>
8
^
*
data_p
++
;
x
=
crc
>>
8
^
*
data_p
++
;
x
^=
x
>>
4
;
x
^=
x
>>
4
;
crc
=
(
crc
<<
8
)
^
((
unsigned
short
)(
x
<<
12
))
^
((
unsigned
short
)(
x
<<
5
))
^
((
unsigned
short
)
x
);
crc
=
(
crc
<<
8
)
^
((
unsigned
short
)(
x
<<
12
))
^
((
unsigned
short
)(
x
<<
5
))
^
((
unsigned
short
)
x
);
...
...
hi3518/internal_types.h
浏览文件 @
69852f39
...
@@ -14,6 +14,7 @@ typedef struct ev_region_t {
...
@@ -14,6 +14,7 @@ typedef struct ev_region_t {
typedef
struct
ev_module_config_t
{
typedef
struct
ev_module_config_t
{
MqttHelper
*
pClient
;
MqttHelper
*
pClient
;
void
**
pPubCtx
;
void
**
pPubCtx
;
bool
isRecordRunning
;
struct
module
{
struct
module
{
struct
record
{
struct
record
{
int
interval
;
// in seconds
int
interval
;
// in seconds
...
...
hi3518/main.cc
浏览文件 @
69852f39
/**
* @file main.cc
*
* @brief this is the main file impelents evcamera
*
* @ingroup evcamera
*
* @author Bruce Lu
* Contact: lzbgt@icloud.com
*
*/
#include <iostream>
#include <iostream>
#include <string>
#include <string>
#include <chrono>
#include <chrono>
...
@@ -86,10 +98,10 @@ char *port = portArr;
...
@@ -86,10 +98,10 @@ char *port = portArr;
//
//
OrderedList
<
int64_t
>
*
gRecFilesList
=
nullptr
;
OrderedList
<
int64_t
>
*
gRecFilesList
=
nullptr
;
namespace
_upvariable_
{
namespace
_upvariable_
{
mutex
mut
;
mutex
mut
;
condition_variable
cv
;
condition_variable
cv
;
queue
<
upload_item_t
>
que
;
queue
<
upload_item_t
>
que
;
};
};
thread_upload_args_t
gUploadArgs
{
&
_upvariable_
::
mut
,
&
_upvariable_
::
cv
,
&
_upvariable_
::
que
,
&
gJsonConfig
,
dev_sn
,
&
gRecFilesList
};
thread_upload_args_t
gUploadArgs
{
&
_upvariable_
::
mut
,
&
_upvariable_
::
cv
,
&
_upvariable_
::
que
,
&
gJsonConfig
,
dev_sn
,
&
gRecFilesList
};
...
@@ -380,7 +392,7 @@ string verify_config(json &data)
...
@@ -380,7 +392,7 @@ string verify_config(json &data)
}
}
// check network connections
// check network connections
int
socket
=
0
;
int
socket
=
0
;
auto
rc
=
raw_connect
(
uri
.
Host
,
uri
.
Port
,
&
socket
);
auto
rc
=
raw_connect
_nonblock
(
uri
.
Host
,
uri
.
Port
,
&
socket
);
if
(
rc
<
0
||
socket
==
0
)
{
if
(
rc
<
0
||
socket
==
0
)
{
str
=
fmt
::
format
(
"failed to connect to {}:{}, {}"
,
k
,
value
,
data
.
to_string
());
str
=
fmt
::
format
(
"failed to connect to {}:{}, {}"
,
k
,
value
,
data
.
to_string
());
break
;
break
;
...
@@ -646,7 +658,7 @@ void handle_mqtt_req(MqttHelper *hlp, const void * const data, int len, string t
...
@@ -646,7 +658,7 @@ void handle_mqtt_req(MqttHelper *hlp, const void * const data, int len, string t
gUploadArgs
.
cv
->
notify_one
();
gUploadArgs
.
cv
->
notify_one
();
}
}
string
extra
;
string
extra
;
if
(
status
>
0
){
if
(
status
>
0
)
{
extra
=
", but it is scheduled in the future"
;
extra
=
", but it is scheduled in the future"
;
}
}
MqttMgr
::
report_response_args
(
gMqttClient
,
consts
::
pub_topic_response
+
rid
,
0
,
string
(
"request accepted"
)
+
extra
,
cmd
,
rid
,
data
);
MqttMgr
::
report_response_args
(
gMqttClient
,
consts
::
pub_topic_response
+
rid
,
0
,
string
(
"request accepted"
)
+
extra
,
cmd
,
rid
,
data
);
...
@@ -851,6 +863,7 @@ int main(int argc, char *argv[])
...
@@ -851,6 +863,7 @@ int main(int argc, char *argv[])
}
}
//
//
gConfigSystem
.
isRecordRunning
=
false
;
MaQueVideoEncodeCfg_s
cfg
;
MaQueVideoEncodeCfg_s
cfg
;
init_stream_cfg
(
&
cfg
);
init_stream_cfg
(
&
cfg
);
gConfigSystem
.
pPubCtx
=
&
pPubCtx
;
gConfigSystem
.
pPubCtx
=
&
pPubCtx
;
...
@@ -902,9 +915,16 @@ int main(int argc, char *argv[])
...
@@ -902,9 +915,16 @@ int main(int argc, char *argv[])
thVideoRecord
.
detach
();
thVideoRecord
.
detach
();
}
}
while
(
gConfigSystem
.
isRecordRunning
==
false
)
{
spdlog
::
info
(
"waiting for record svc to start"
);
this_thread
::
sleep_for
(
chrono
::
seconds
(
3
));
}
spdlog
::
info
(
"recording svc started, starting upload svc"
);
// start upload thread
// start upload thread
thread
thUpload
=
thread
(
upload_svc_entry
,
&
gUploadArgs
);
thread
thUpload
=
thread
(
upload_svc_entry
,
&
gUploadArgs
);
if
(
thUpload
.
joinable
()){
if
(
thUpload
.
joinable
())
{
thUpload
.
detach
();
thUpload
.
detach
();
spdlog
::
info
(
"started video upload service"
);
spdlog
::
info
(
"started video upload service"
);
}
}
...
...
hi3518/motion.cc
浏览文件 @
69852f39
/**
* @file motion.cc
*
* @brief this is the main file impelents motion
*
* @ingroup evcamera
*
* @author Bruce Lu
* Contact: lzbgt@icloud.com
*
*/
extern
"C"
{
extern
"C"
{
#include <maque_type.h>
#include <maque_type.h>
#include <maque_osd.h>
#include <maque_osd.h>
...
...
hi3518/motiondetect.hpp
浏览文件 @
69852f39
/**
* @file motiondetect.hpp
*
* @brief this is the main file impelents motion detect state machine
*
* @ingroup evcamera
*
* @author Bruce Lu
* Contact: lzbgt@icloud.com
*
*/
#ifndef __MOTION_DETECT_HPP__
#ifndef __MOTION_DETECT_HPP__
#define __MOTION_DETECT_HPP__
#define __MOTION_DETECT_HPP__
...
@@ -122,8 +134,8 @@ namespace md{
...
@@ -122,8 +134,8 @@ namespace md{
};
};
const
auto
may_generate_event
=
[
this
]{
const
auto
may_generate_event
=
[
this
]{
auto
now
=
chrono
::
duration_cast
<
chrono
::
milliseconds
>
(
chrono
::
system_clock
::
now
().
time_since_epoch
()).
count
();
auto
now
=
chrono
::
duration_cast
<
chrono
::
milliseconds
>
(
chrono
::
system_clock
::
now
().
time_since_epoch
()).
count
();
if
(
timeStart
!=
0
&&
(
now
-
timeStart
)
>=
kMaxDuration
*
1000
){
if
(
timeStart
!=
0
&&
(
(
now
-
timeStart
)
>=
kMaxDuration
*
1000
/*|| this->is("none"_s)*/
)
){
upload_item_t
item
{
timeStart
,
now
,
6
,
-
1
,
now
};
upload_item_t
item
{
timeStart
,
now
,
7
,
-
1
,
now
};
{
{
lock_guard
<
mutex
>
lg
(
*
gUploadArgs
.
mut
);
lock_guard
<
mutex
>
lg
(
*
gUploadArgs
.
mut
);
gUploadArgs
.
que
->
push
(
item
);
gUploadArgs
.
que
->
push
(
item
);
...
@@ -135,6 +147,23 @@ namespace md{
...
@@ -135,6 +147,23 @@ namespace md{
return
false
;
return
false
;
};
};
const
auto
generate_event
=
[
this
]{
auto
now
=
chrono
::
duration_cast
<
chrono
::
milliseconds
>
(
chrono
::
system_clock
::
now
().
time_since_epoch
()).
count
();
if
(
timeStart
!=
0
){
upload_item_t
item
{
timeStart
,
now
,
7
,
-
1
,
now
};
{
lock_guard
<
mutex
>
lg
(
*
gUploadArgs
.
mut
);
gUploadArgs
.
que
->
push
(
item
);
gUploadArgs
.
cv
->
notify_one
();
}
spdlog
::
info
(
"event generated: tss {}, tse {}, type {}"
,
timeStart
,
now
,
7
);
}
else
{
//spdlog::error("failed generate event: tss {}, tse {}, type {}", timeStart, now, 7);
}
timeStart
=
0
;
hasMotion
=
false
;
};
using
namespace
sml
;
using
namespace
sml
;
return
make_transition_table
(
return
make_transition_table
(
...
@@ -165,7 +194,7 @@ namespace md{
...
@@ -165,7 +194,7 @@ namespace md{
// "post"_s + sml::on_entry<_> / may_generate_event,
// "post"_s + sml::on_entry<_> / may_generate_event,
//
//
"none"
_s
+
sml
::
on_entry
<
_
>
/
[
this
]{
hasMotion
=
false
,
timeStart
=
0
;}
"none"
_s
+
sml
::
on_entry
<
_
>
/
generate_event
);
);
}
}
private
:
private
:
...
...
hi3518/ntp.cc
浏览文件 @
69852f39
/**
* @file ntp.cc
*
* @brief this is the main file impelents ntp update
*
* @ingroup evcamera
*
* @author Bruce Lu
* Contact: lzbgt@icloud.com
*
*/
#include <unistd.h>
#include <unistd.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
...
...
hi3518/ptz.cc
浏览文件 @
69852f39
/**
* @file ptz.cc
*
* @brief this is the main file impelents motor control ptz
*
* @ingroup evcamera
*
* @author Bruce Lu
* Contact: lzbgt@icloud.com
*
*/
#include <libxmmaque_api.h>
#include <libxmmaque_api.h>
#include <spdlog/spdlog.h>
#include <spdlog/spdlog.h>
#include <fmt/format.h>
#include <fmt/format.h>
...
...
hi3518/raw_tcp.cc
浏览文件 @
69852f39
/**
* @file raw_tcp.cc
*
* @brief this is the main file impelents raw tcp transfer
*
* @ingroup evcamera
*
* @author Bruce Lu
* Contact: lzbgt@icloud.com
*
*/
#include <sys/socket.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/time.h>
...
@@ -9,7 +21,7 @@
...
@@ -9,7 +21,7 @@
using
namespace
std
;
using
namespace
std
;
int
raw_connect
(
std
::
string
host
,
std
::
string
port
,
int
*
socket_
,
int
recv_timeout
,
int
send_timeout
)
int
_
raw_connect
(
std
::
string
host
,
std
::
string
port
,
int
*
socket_
,
int
recv_timeout
,
int
send_timeout
)
{
{
int
rv
=
0
;
int
rv
=
0
;
struct
addrinfo
hints
{};
struct
addrinfo
hints
{};
...
@@ -37,19 +49,21 @@ int raw_connect(std::string host, std::string port, int *socket_, int recv_timeo
...
@@ -37,19 +49,21 @@ int raw_connect(std::string host, std::string port, int *socket_, int recv_timeo
}
}
struct
timeval
timeout
;
struct
timeval
timeout
;
timeout
.
tv_sec
=
recv_timeout
;
if
(
recv_timeout
!=
0
){
timeout
.
tv_usec
=
0
;
timeout
.
tv_sec
=
recv_timeout
;
timeout
.
tv_usec
=
0
;
if
(
setsockopt
(
*
socket_
,
SOL_SOCKET
,
SO_RCVTIMEO
,
(
char
*
)
&
timeout
,
sizeof
(
timeout
))
<
0
)
{
if
(
setsockopt
(
*
socket_
,
SOL_SOCKET
,
SO_RCVTIMEO
,
(
char
*
)
&
timeout
,
sizeof
(
timeout
))
<
0
)
{
spdlog
::
error
(
"setsockopt SO_RCVTIMEO failed"
);
spdlog
::
error
(
"setsockopt SO_RCVTIMEO failed"
);
return
-
1
;
return
-
1
;
}
}
}
timeout
.
tv_sec
=
send_timeout
;
if
(
send_timeout
!=
0
){
timeout
.
tv_sec
=
send_timeout
;
if
(
setsockopt
(
*
socket_
,
SOL_SOCKET
,
SO_SNDTIMEO
,
(
char
*
)
&
timeout
,
sizeof
(
timeout
))
<
0
)
{
if
(
setsockopt
(
*
socket_
,
SOL_SOCKET
,
SO_SNDTIMEO
,
(
char
*
)
&
timeout
,
sizeof
(
timeout
))
<
0
)
{
spdlog
::
error
(
"setsockopt SO_SNDTIMEO failed"
);
spdlog
::
error
(
"setsockopt SO_SNDTIMEO failed"
);
return
-
1
;
return
-
1
;
}
}
}
rv
=
::
connect
(
*
socket_
,
rp
->
ai_addr
,
rp
->
ai_addrlen
);
rv
=
::
connect
(
*
socket_
,
rp
->
ai_addr
,
rp
->
ai_addrlen
);
...
@@ -75,17 +89,29 @@ int raw_connect(std::string host, std::string port, int *socket_, int recv_timeo
...
@@ -75,17 +89,29 @@ int raw_connect(std::string host, std::string port, int *socket_, int recv_timeo
}
}
string
raw_send
(
int
s
,
const
void
*
buf
,
size_t
len
){
int
raw_connect
(
std
::
string
host
,
std
::
string
port
,
int
*
socket_
){
return
_raw_connect
(
host
,
port
,
socket_
,
0
,
0
);
}
int
raw_connect_nonblock
(
std
::
string
host
,
std
::
string
port
,
int
*
socket_
,
int
recv_timeout
,
int
send_timeout
){
return
_raw_connect
(
host
,
port
,
socket_
,
recv_timeout
,
send_timeout
);
}
string
raw_send
(
int
s
,
const
void
*
buf
,
size_t
len
)
{
string
rc
;
string
rc
;
ssize_t
sent
=
0
;
ssize_t
sent
=
0
;
ssize_t
ret
=
0
;
int
retries
=
0
;
while
(
len
>
0
)
{
while
(
len
>
0
)
{
sent
=
::
send
(
s
,
buf
,
len
,
0
);
ret
=
::
send
(
s
,
(
char
*
)
buf
+
sent
,
len
,
MSG_NOSIGNAL
);
if
(
sent
<=
0
)
{
if
(
ret
<
0
)
{
break
;
break
;
}
}
len
-=
sent
;
len
-=
ret
;
sent
+=
ret
;
}
}
if
(
len
>
0
||
sent
<=
0
)
{
if
(
len
>
0
||
ret
<
0
)
{
rc
=
fmt
::
format
(
"failed to send: {}"
,
strerror
(
errno
));
rc
=
fmt
::
format
(
"failed to send: {}"
,
strerror
(
errno
));
}
}
return
rc
;
return
rc
;
...
...
hi3518/raw_tcp.h
浏览文件 @
69852f39
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
#include <mutex>
#include <mutex>
#include "common.h"
#include "common.h"
int
raw_connect
(
std
::
string
host
,
std
::
string
port
,
int
*
socket_
,
int
recv_timeout
=
3
,
int
send_timeout
=
3
);
int
raw_connect
(
std
::
string
host
,
std
::
string
port
,
int
*
socket_
);
int
raw_connect_nonblock
(
std
::
string
host
,
std
::
string
port
,
int
*
socket_
,
int
recv_timeout
=
5
,
int
send_timeout
=
5
);
std
::
string
raw_send
(
int
s
,
const
void
*
buf
,
size_t
len
);
std
::
string
raw_send
(
int
s
,
const
void
*
buf
,
size_t
len
);
#endif
#endif
\ No newline at end of file
hi3518/smart.cc
浏览文件 @
69852f39
/**
* @file smart.cc
*
* @brief this is the main file impelents smart detection
*
* @ingroup evcamera
*
* @author Bruce Lu
* Contact: lzbgt@icloud.com
*
*/
#include "smart.h"
#include "smart.h"
#include <spdlog/spdlog.h>
#include <spdlog/spdlog.h>
...
@@ -209,9 +221,10 @@ void maq_smart_task_entry(ev_module_config_t *pArg)
...
@@ -209,9 +221,10 @@ void maq_smart_task_entry(ev_module_config_t *pArg)
int
deltaMotionCnt
=
motionCnt_
-
motionCntLast
;
int
deltaMotionCnt
=
motionCnt_
-
motionCntLast
;
motionCntLast
=
motionCnt_
;
motionCntLast
=
motionCnt_
;
if
(
deltaTimeMs
==
0
){
if
(
deltaTimeMs
==
0
)
{
spdlog
::
warn
(
"no video frames in last ~5 seconds"
);
spdlog
::
warn
(
"no video frames in last ~5 seconds"
);
}
else
{
}
else
{
if
(
deltaMotionCnt
>=
motionCntThresh
)
{
if
(
deltaMotionCnt
>=
motionCntThresh
)
{
hasMotion
=
true
;
hasMotion
=
true
;
}
}
...
...
include/evpacket.h
浏览文件 @
69852f39
/**
* @file evpacket.h
*
* @brief this is the main file defines evpacket type
*
* @ingroup evcamera
*
* @author Bruce Lu
* Contact: lzbgt@icloud.com
*
*/
#ifndef __EVPACKET_H__
#ifndef __EVPACKET_H__
#define __EVPACKET_H__
#define __EVPACKET_H__
#include <mutex>
#include <mutex>
...
...
include/mqtt_helper.cc
浏览文件 @
69852f39
/**
/**
*
mqtt_helper.hpp
*
@file mqtt_helper.cc
*
*
* simplifies api for mqtt
* @brief this is the main file impelents mqtt helpers
*
* @ingroup evcamera
*
* @author Bruce Lu
* Contact: lzbgt@icloud.com
*
*
* Bruce.Lu @20200415
*/
*/
#include <mqtt_helper.hpp>
#include <mqtt_helper.hpp>
...
...
server/videogateway.cc
浏览文件 @
69852f39
/**
* @file videogateway.cc
*
* @brief this is the main file impelents video gateway
*
* @ingroup evcamera
*
* @author Bruce Lu
* Contact: lzbgt@icloud.com
*
*/
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论