Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
715e60fd
提交
715e60fd
authored
4月 13, 2020
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test
上级
f59cb819
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
291 行增加
和
0 行删除
+291
-0
test_emplace.cpp
opencv-motion-detect/test_emplace.cpp
+17
-0
test_remove.cpp
opencv-motion-detect/test_remove.cpp
+11
-0
test_sshtun.cpp
opencv-motion-detect/test_sshtun.cpp
+9
-0
test_termio.cpp
opencv-motion-detect/test_termio.cpp
+118
-0
test_termio_bak.cpp
opencv-motion-detect/test_termio_bak.cpp
+136
-0
没有找到文件。
opencv-motion-detect/test_emplace.cpp
0 → 100644
浏览文件 @
715e60fd
#include <map>
#include <iostream>
using
namespace
std
;
int
main
(){
map
<
string
,
string
>
m
;
m
.
emplace
(
"a"
,
"b"
);
m
.
emplace
(
"a"
,
"c"
);
for
(
auto
&
[
k
,
v
]
:
m
)
{
cout
<<
k
<<
v
<<
endl
;
}
}
\ No newline at end of file
opencv-motion-detect/test_remove.cpp
0 → 100644
浏览文件 @
715e60fd
#include <string>
#include <algorithm>
#include <iostream>
using
namespace
std
;
int
main
(){
string
s
=
" I am seprated by spaces "
;
cout
<<
s
;
}
\ No newline at end of file
opencv-motion-detect/test_sshtun.cpp
0 → 100644
浏览文件 @
715e60fd
#include "reverse_tun.hpp"
int
main
()
{
thread
th
;
spdlog
::
info
(
"port remote: {}"
,
createReverseTun
(
"47.56.83.236"
,
2222
,
"root"
,
"Hz123456"
,
th
));
th
.
join
();
}
\ No newline at end of file
opencv-motion-detect/test_termio.cpp
0 → 100644
浏览文件 @
715e60fd
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <string.h> // needed for memset
#include <thread>
#include <chrono>
#include <signal.h>
#include <spdlog/spdlog.h>
#include <fmt/format.h>
using
namespace
std
;
using
namespace
std
::
chrono_literals
;
#define WATCHDOG_STOP uint8_t(0xFD)
#define WATCH
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
_watchdog_stop
(
int
fd
){
return
watchdog_feed
(
fd
,
WATCHDOG_STOP
);
}
int
watchdog_close
(
int
fd
)
{
spdlog
::
info
(
"evdaemon disabling watch dog.."
);
if
(
fd
>
0
)
{
_watchdog_stop
(
fd
);
close
(
fd
);
}
return
0
;
}
int
fd_dog
=
0
;
bool
watchdog_disable
=
false
;
void
sig_handler
(
int
signum
)
{
spdlog
::
warn
(
"evdaemon received control signal {}, waiting to stop watch dog"
,
signum
);
if
(
fd_dog
>
0
&&
!
watchdog_disable
)
{
watchdog_disable
=
true
;
while
(
fd_dog
!=
0
)
{
spdlog
::
info
(
"evdaemon waiting watchdog to stop"
);
this_thread
::
sleep_for
(
chrono
::
milliseconds
(
500
));
}
}
spdlog
::
info
(
"evdaemon watchdog stopped, exiting"
);
exit
(
signum
);
}
int
main
(
int
argc
,
char
**
argv
){
signal
(
SIGINT
,
sig_handler
);
signal
(
SIGTERM
,
sig_handler
);
signal
(
SIGKILL
,
sig_handler
);
thread
th
=
thread
([](){
fd_dog
=
watchdog_init
(
"/dev/ttyS1"
);
uint8_t
intval
=
10
;
if
(
fd_dog
>
0
)
{
while
(
!
watchdog_disable
)
{
watchdog_feed
(
fd_dog
,
intval
);
this_thread
::
sleep_for
(
chrono
::
milliseconds
(
intval
/
2
*
100
));
}
watchdog_close
(
fd_dog
);
fd_dog
=
0
;
}
else
{
fd_dog
=
0
;
}
});
th
.
join
();
return
0
;
}
\ No newline at end of file
opencv-motion-detect/test_termio_bak.cpp
0 → 100644
浏览文件 @
715e60fd
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <string.h> // needed for memset
#include <thread>
#include <chrono>
#include <signal.h>
#include <spdlog/spdlog.h>
#include <fmt/format.h>
using
namespace
std
;
using
namespace
std
::
chrono_literals
;
#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
sig_handler
(
int
signum
)
{
spdlog
::
warn
(
"evdaemon received control signal {}, waiting to stop watch dog"
,
signum
);
gWatchDog
.
stop
();
spdlog
::
info
(
"evdaemon watchdog stopped, exiting"
);
exit
(
signum
);
}
int
main
(
int
argc
,
char
**
argv
){
signal
(
SIGINT
,
sig_handler
);
signal
(
SIGTERM
,
sig_handler
);
signal
(
SIGKILL
,
sig_handler
);
gWatchDog
.
run
().
join
();
return
0
;
}
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论