Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
1eedf992
提交
1eedf992
authored
10月 29, 2019
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feature: report edge box ip addresses
上级
e64ec7c5
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
129 行增加
和
13 行删除
+129
-13
evcloudsvc.cpp
opencv-motion-detect/evcloudsvc.cpp
+10
-2
evdaemon.cpp
opencv-motion-detect/evdaemon.cpp
+14
-11
networks.hpp
opencv-motion-detect/networks.hpp
+52
-0
test_ip.cpp
opencv-motion-detect/test_ip.cpp
+53
-0
没有找到文件。
opencv-motion-detect/evcloudsvc.cpp
浏览文件 @
1eedf992
...
...
@@ -481,10 +481,13 @@ private:
// message to evcloudsvc
// spdlog::info("evcloudsvc {} subsystem report msg received: {}; {}; {}", devSn, zmqhelper::body2str(body[0]), zmqhelper::body2str(body[1]), zmqhelper::body2str(body[2]));
if
(
meta
==
"pong"
||
meta
==
"ping"
)
{
// update status
spdlog
::
info
(
"evcloudsvc {}, ping msg from {}"
,
devSn
,
selfId
);
// handleConnection(selfId);
if
(
meta
==
"ping"
)
{
auto
ips
=
body2str
(
body
[
3
]);
spdlog
::
info
(
"evcloudsvc {}, ping msg from {}: {}"
,
devSn
,
selfId
,
ips
);
this
->
peerData
[
"info"
][
"ips"
][
selfId
]
=
ips
;
if
(
cachedMsg
.
find
(
selfId
)
!=
cachedMsg
.
end
())
{
while
(
!
cachedMsg
[
selfId
].
empty
())
{
lock_guard
<
mutex
>
lock
(
cacheLock
);
...
...
@@ -1109,6 +1112,11 @@ public:
EvCloudSvc
()
{
int
ret
=
0
;
this
->
peerData
[
"info"
]
=
json
();
this
->
peerData
[
"info"
][
"ips"
]
=
json
();
this
->
peerData
[
"config"
]
=
json
();
this
->
peerData
[
"status"
]
=
json
();
spdlog
::
info
(
"evcloudsvc boot"
);
loadConfigMap
();
char
*
strEnv
=
getenv
(
"HTTP_PORT"
);
...
...
opencv-motion-detect/evdaemon.cpp
浏览文件 @
1eedf992
...
...
@@ -18,6 +18,7 @@ update: 2019/09/10
#include "inc/database.h"
#include "inc/json.hpp"
#include "inc/utils.hpp"
#include "networks.hpp"
#include <unistd.h>
#include <sys/wait.h>
...
...
@@ -43,7 +44,6 @@ private:
thread
::
id
thIdMain
;
thread
thRouter
;
thread
thCloud
;
bool
bReload
=
false
;
bool
bBootstrap
=
true
;
bool
bColdStart
=
true
;
...
...
@@ -74,11 +74,12 @@ private:
/// tracking sub-systems: evmgr, evpuller, evpusher, evml*, evslicer etc.
json
mapSubSystems
;
json
jsonIPs
;
int
ping
(
void
*
s
)
{
int
ret
=
0
;
vector
<
vector
<
uint8_t
>
>
body
=
{
str2body
(
"evcloudsvc:0:0"
),
str2body
(
EV_MSG_META_PING
),
str2body
(
MSG_HELLO
)};
vector
<
vector
<
uint8_t
>
>
body
=
{
str2body
(
"evcloudsvc:0:0"
),
str2body
(
EV_MSG_META_PING
),
str2body
(
this
->
jsonIPs
.
dump
()
)};
ret
=
z_send_multiple
(
s
,
body
);
if
(
ret
<
0
)
{
...
...
@@ -733,14 +734,6 @@ public:
res
.
set_content
(
ret
.
dump
(),
"text/json"
);
});
svr
.
Get
(
"/sync-cloud"
,
[
this
](
const
Request
&
req
,
Response
&
res
)
{
json
ret
;
ret
[
"code"
]
=
0
;
ret
[
"msg"
]
=
"syncing ..."
;
res
.
set_content
(
ret
.
dump
(),
"text/json"
);
this
->
bReload
=
true
;
});
svr
.
Get
(
"/reset"
,
[](
const
Request
&
req
,
Response
&
res
)
{
json
ret
;
ret
[
"code"
]
=
0
;
...
...
@@ -771,12 +764,22 @@ public:
LVDB
::
getSn
(
info
);
}
catch
(
exception
&
e
)
{
spdlog
::
error
(
"evdaemon failed to get
sn
: {}"
,
e
.
what
());
spdlog
::
error
(
"evdaemon failed to get
local info
: {}"
,
e
.
what
());
exit
(
1
);
}
spdlog
::
info
(
"evdaemon boot
\n
{}"
,
info
.
dump
());
auto
ipAddrs
=
netutils
::
getIps
();
if
(
ipAddrs
.
size
()
==
0
)
{
spdlog
::
error
(
"evdaemon failed to start: no network available!"
);
exit
(
2
);
}
for
(
const
auto
&
[
k
,
v
]
:
ipAddrs
)
{
jsonIPs
.
push_back
(
k
);
}
devSn
=
info
[
"sn"
];
char
*
strEnv
=
getenv
(
"BOOTSTRAP"
);
...
...
opencv-motion-detect/networks.hpp
0 → 100644
浏览文件 @
1eedf992
#ifndef __EV_NETWORKS_H__
#define __EV_NETWORKS_H__
#include <sys/types.h>
#include <ifaddrs.h>
#include <netinet/in.h>
#include <string>
#include <arpa/inet.h>
#include <map>
#include <spdlog/spdlog.h>
namespace
netutils
{
using
namespace
std
;
map
<
string
,
string
>
getIps
()
{
map
<
string
,
string
>
ret
;
struct
ifaddrs
*
ifAddrStruct
=
nullptr
;
struct
ifaddrs
*
ifa
=
nullptr
;
void
*
tmpAddrPtr
=
nullptr
;
char
addressBuffer
[
INET_ADDRSTRLEN
];
getifaddrs
(
&
ifAddrStruct
);
for
(
ifa
=
ifAddrStruct
;
ifa
!=
nullptr
;
ifa
=
ifa
->
ifa_next
)
{
if
(
!
ifa
->
ifa_addr
)
{
continue
;
}
if
(
ifa
->
ifa_addr
->
sa_family
==
AF_INET
)
{
// check it is IP4
// is a valid IP4 Address
tmpAddrPtr
=&
((
struct
sockaddr_in
*
)
ifa
->
ifa_addr
)
->
sin_addr
;
int
ip
=
htonl
(
*
(
int
*
)
tmpAddrPtr
);
// printf("%d %d %d %d", ( ip >> 24) & 0xFF, (ip >> 16) & 0xFF, (ip>> 8) & 0xFF, (ip >> 0) & 0xFF);
if
(((
ip
>>
24
)
&
0xFF
)
==
127
)
{
continue
;
}
if
(
inet_ntop
(
AF_INET
,
tmpAddrPtr
,
addressBuffer
,
INET_ADDRSTRLEN
)
!=
nullptr
)
{
string
addrStr
(
addressBuffer
);
string
ifStr
(
ifa
->
ifa_name
);
ret
[
addrStr
]
=
ifStr
;
}
}
}
if
(
ifAddrStruct
!=
nullptr
)
freeifaddrs
(
ifAddrStruct
);
return
ret
;
}
}
#endif
\ No newline at end of file
opencv-motion-detect/test_ip.cpp
0 → 100644
浏览文件 @
1eedf992
#include <sys/types.h>
#include <ifaddrs.h>
#include <netinet/in.h>
#include <string>
#include <arpa/inet.h>
#include <map>
#include <spdlog/spdlog.h>
using
namespace
std
;
map
<
string
,
string
>
getIps
()
{
map
<
string
,
string
>
ret
;
struct
ifaddrs
*
ifAddrStruct
=
nullptr
;
struct
ifaddrs
*
ifa
=
nullptr
;
void
*
tmpAddrPtr
=
nullptr
;
char
addressBuffer
[
INET_ADDRSTRLEN
];
getifaddrs
(
&
ifAddrStruct
);
for
(
ifa
=
ifAddrStruct
;
ifa
!=
nullptr
;
ifa
=
ifa
->
ifa_next
)
{
if
(
!
ifa
->
ifa_addr
)
{
continue
;
}
if
(
ifa
->
ifa_addr
->
sa_family
==
AF_INET
)
{
// check it is IP4
// is a valid IP4 Address
tmpAddrPtr
=&
((
struct
sockaddr_in
*
)
ifa
->
ifa_addr
)
->
sin_addr
;
int
ip
=
htonl
(
*
(
int
*
)
tmpAddrPtr
);
// printf("%d %d %d %d", ( ip >> 24) & 0xFF, (ip >> 16) & 0xFF, (ip>> 8) & 0xFF, (ip >> 0) & 0xFF);
if
(((
ip
>>
24
)
&
0xFF
)
==
127
)
{
continue
;
}
if
(
inet_ntop
(
AF_INET
,
tmpAddrPtr
,
addressBuffer
,
INET_ADDRSTRLEN
)
!=
nullptr
)
{
string
addrStr
(
addressBuffer
);
string
ifStr
(
ifa
->
ifa_name
);
ret
[
addrStr
]
=
ifStr
;
}
}
}
if
(
ifAddrStruct
!=
nullptr
)
freeifaddrs
(
ifAddrStruct
);
return
ret
;
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
auto
r
=
getIps
();
for
(
const
auto
&
[
k
,
v
]
:
r
)
{
spdlog
::
info
(
"{} {}"
,
k
,
v
);
}
return
0
;
}
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论