Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
56997993
提交
56997993
authored
3月 02, 2020
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
new feature: hardware watchdog support [optional]
上级
75b89ac2
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
120 行增加
和
0 行删除
+120
-0
a.out
opencv-motion-detect/a.out
+0
-0
evdaemon.cpp
opencv-motion-detect/evdaemon.cpp
+120
-0
没有找到文件。
opencv-motion-detect/a.out
deleted
100755 → 0
浏览文件 @
75b89ac2
File deleted
opencv-motion-detect/evdaemon.cpp
浏览文件 @
56997993
...
@@ -15,6 +15,8 @@ update: 2019/09/10
...
@@ -15,6 +15,8 @@ update: 2019/09/10
#include <unistd.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/wait.h>
#include <fstream>
#include <fstream>
#include <fcntl.h>
#include <termios.h>
#include "inc/tinythread.hpp"
#include "inc/tinythread.hpp"
#include "inc/httplib.h"
#include "inc/httplib.h"
...
@@ -1067,14 +1069,132 @@ public:
...
@@ -1067,14 +1069,132 @@ public:
~
EvDaemon
()
{};
~
EvDaemon
()
{};
};
};
#define EV_WATCHDOG_STOP uint8_t(0xFD)
class
EvWatchDog
{
private
:
int
fd_dog
=
0
;
string
tty
;
bool
disabled
=
false
;
int
watchdog_init
(
string
ttyPath
)
{
const
char
*
tty
=
ttyPath
.
c_str
();
struct
termios
tio
;
int
tty_fd
;
memset
(
&
tio
,
0
,
sizeof
(
tio
));
tio
.
c_iflag
=
0
;
tio
.
c_oflag
=
0
;
tio
.
c_cflag
=
CS8
|
CREAD
|
CLOCAL
;
// 8n1, see termios.h for more information
tio
.
c_lflag
=
0
;
tio
.
c_cc
[
VMIN
]
=
1
;
tio
.
c_cc
[
VTIME
]
=
5
;
tty_fd
=
open
(
tty
,
O_RDWR
|
O_NONBLOCK
);
if
(
tty_fd
==
-
1
)
{
spdlog
::
error
(
"evdaemon failed to open tty {}"
,
tty
);
return
-
1
;
}
cfsetospeed
(
&
tio
,
B115200
);
// 115200 baud
//cfsetispeed(&tio,B115200);
if
(
-
1
==
tcsetattr
(
tty_fd
,
TCSANOW
,
&
tio
)){
spdlog
::
error
(
"evdaemon failed to set tty {}"
,
tty
);
return
-
1
;
}
return
tty_fd
;
}
int
watchdog_feed
(
int
fd
,
uint8_t
intervalMs
){
if
(
fd
<=
0
)
{
spdlog
::
error
(
"evdaemon invalid watchdog fd"
);
return
-
1
;
}
uint8_t
check
=
~
intervalMs
;
uint8_t
data
[]
=
{
0xFE
,
0xFE
,
intervalMs
,
check
,
0xEF
};
spdlog
::
info
(
"evdaemon feed watch dog: {}, {}"
,
intervalMs
,
check
);
if
(
-
1
==
write
(
fd
,
data
,
5
)){
spdlog
::
error
(
"evdaemon failed to write watchdog fd"
);
return
-
1
;
}
else
{
return
0
;
}
}
int
_EV_WATCHDOG_STOP
(
int
fd
){
return
watchdog_feed
(
fd
,
EV_WATCHDOG_STOP
);
}
int
watchdog_close
(
int
fd
)
{
spdlog
::
info
(
"evdaemon disabling watch dog.."
);
if
(
fd
>
0
)
{
_EV_WATCHDOG_STOP
(
fd
);
close
(
fd
);
}
return
0
;
}
public
:
EvWatchDog
()
=
delete
;
EvWatchDog
(
string
tty
)
:
tty
(
tty
){
if
((
fd_dog
=
watchdog_init
(
tty
))
<
0
)
{
spdlog
::
error
(
"evdaemon can't open watchdog tty, ignore watchdog"
);
fd_dog
=
0
;
}
}
thread
run
(){
thread
th
=
thread
([
this
](){
uint8_t
intval
=
10
;
if
(
this
->
fd_dog
>
0
)
{
while
(
!
this
->
disabled
)
{
watchdog_feed
(
this
->
fd_dog
,
intval
);
this_thread
::
sleep_for
(
chrono
::
milliseconds
(
intval
/
2
*
100
));
}
watchdog_close
(
this
->
fd_dog
);
this
->
fd_dog
=
0
;
}
else
{
this
->
fd_dog
=
0
;
}
});
return
th
;
}
void
stop
(){
if
(
fd_dog
>
0
&&
!
disabled
)
{
disabled
=
true
;
while
(
fd_dog
!=
0
)
{
spdlog
::
info
(
"evdaemon waiting watchdog to stop"
);
this_thread
::
sleep_for
(
chrono
::
milliseconds
(
500
));
}
}
}
};
EvWatchDog
gWatchDog
=
EvWatchDog
(
"/dev/ttyS1"
);
void
cleanup
(
int
signal
)
void
cleanup
(
int
signal
)
{
{
// STOP watch dog
spdlog
::
warn
(
"evdaemon received control signal {}, waiting to stop watch dog"
,
signal
);
gWatchDog
.
stop
();
spdlog
::
info
(
"evdaemon watchdog stopped, exiting"
);
while
(
waitpid
((
pid_t
)
(
-
1
),
0
,
WNOHANG
)
>
0
)
{}
while
(
waitpid
((
pid_t
)
(
-
1
),
0
,
WNOHANG
)
>
0
)
{}
exit
(
signal
);
}
}
int
main
()
int
main
()
{
{
signal
(
SIGCHLD
,
cleanup
);
signal
(
SIGCHLD
,
cleanup
);
signal
(
SIGINT
,
cleanup
);
signal
(
SIGTERM
,
cleanup
);
signal
(
SIGKILL
,
cleanup
);
thread
t
=
gWatchDog
.
run
();
if
(
t
.
joinable
()){
t
.
detach
();
}
//sigignore(SIGCHLD);
//sigignore(SIGCHLD);
EvDaemon
srv
;
EvDaemon
srv
;
srv
.
run
();
srv
.
run
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论