Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gamera_videos_no_ui
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liusq
gamera_videos_no_ui
Commits
e14f599a
Commit
e14f599a
authored
Oct 10, 2024
by
郭峰
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature-1007488' into 'release'
修改ping命令-02 See merge request
!42
parents
c67e2b8e
75c1ac2a
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
58 additions
and
4 deletions
+58
-4
CameraHandle.cpp
+2
-1
Common.cpp
+27
-0
Common.h
+23
-1
NonConnectedCameraHandle.cpp
+3
-1
VidesData.h
+3
-1
No files found.
CameraHandle.cpp
View file @
e14f599a
...
@@ -425,6 +425,7 @@ void CameraHandle::sdkDevSnapSyn(XSDK_HANDLE hDevice, int nChannel){
...
@@ -425,6 +425,7 @@ void CameraHandle::sdkDevSnapSyn(XSDK_HANDLE hDevice, int nChannel){
ScopeSemaphoreExit
guard
([
this
]()
{
ScopeSemaphoreExit
guard
([
this
]()
{
semaphore
.
release
();
// 释放信号量
semaphore
.
release
();
// 释放信号量
});
});
Common
&
instace
=
Common
::
getInstance
();
cv
::
Mat
image
;
cv
::
Mat
image
;
MediaFaceImage
*
mediaFaceImage
=
MediaFaceImage
::
getInstance
();
MediaFaceImage
*
mediaFaceImage
=
MediaFaceImage
::
getInstance
();
qint64
currentTime
=
QDateTime
::
currentSecsSinceEpoch
();
qint64
currentTime
=
QDateTime
::
currentSecsSinceEpoch
();
...
@@ -434,7 +435,7 @@ void CameraHandle::sdkDevSnapSyn(XSDK_HANDLE hDevice, int nChannel){
...
@@ -434,7 +435,7 @@ void CameraHandle::sdkDevSnapSyn(XSDK_HANDLE hDevice, int nChannel){
if
(
offlineCount
>=
3
)
{
// 判断是否连续3次返回0
if
(
offlineCount
>=
3
)
{
// 判断是否连续3次返回0
qInfo
()
<<
QString
(
"SN(%1): 设备离线"
).
arg
(
sSn
);
qInfo
()
<<
QString
(
"SN(%1): 设备离线"
).
arg
(
sSn
);
QString
ip
=
QString
::
fromUtf8
(
loginParam
->
sDevId
);
QString
ip
=
QString
::
fromUtf8
(
loginParam
->
sDevId
);
bool
is_ping
=
vides_data
::
pingAddress
(
ip
);
bool
is_ping
=
instace
.
pingAddress
(
ip
);
qDebug
()
<<
sSn
<<
":ping 的结果"
<<
is_ping
;
qDebug
()
<<
sSn
<<
":ping 的结果"
<<
is_ping
;
if
(
is_ping
){
if
(
is_ping
){
...
...
Common.cpp
View file @
e14f599a
#include "Common.h"
#include "Common.h"
#include "ScopeSemaphoreExit.h"
Common
::
Common
(){}
Common
::
Common
(){}
...
@@ -173,5 +174,31 @@ bool Common::receivePingReply(int sockfd, int sequence) {
...
@@ -173,5 +174,31 @@ bool Common::receivePingReply(int sockfd, int sequence) {
return
false
;
return
false
;
}
}
bool
Common
::
pingAddress
(
const
QString
&
address
)
{
QByteArray
&&
byJsonIp
=
address
.
toUtf8
();
const
char
*
ipAddress
=
byJsonIp
.
data
();
int
sockfd
=
socket
(
AF_INET
,
SOCK_RAW
,
IPPROTO_ICMP
);
ScopeSemaphoreExit
guard
([
sockfd
]()
{
close
(
sockfd
);
});
if
(
sockfd
<
0
)
{
perror
(
"socket"
);
return
1
;
}
int
sequence
=
1
;
if
(
sendPingRequest
(
sockfd
,
ipAddress
,
sequence
))
{
if
(
receivePingReply
(
sockfd
,
sequence
))
{
qInfo
()
<<
"Ping to "
<<
ipAddress
<<
" successful!"
;
return
true
;
}
else
{
qInfo
()
<<
"Ping to "
<<
ipAddress
<<
" failed!"
;
return
false
;
}
}
return
false
;
}
Common
::~
Common
(){}
Common
::~
Common
(){}
Common.h
View file @
e14f599a
...
@@ -11,7 +11,21 @@
...
@@ -11,7 +11,21 @@
#include <QMessageAuthenticationCode>
#include <QMessageAuthenticationCode>
#include <QNetworkInterface>
#include <QNetworkInterface>
#include <map>
#include <map>
#include <QDebug>
#include <iostream>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/ip_icmp.h>
#include <sys/socket.h>
#include <unistd.h>
// ICMP 头部结构体
struct
ICMPHeader
{
uint8_t
type
;
// 类型
uint8_t
code
;
// 代码
uint16_t
checksum
;
// 校验和
uint16_t
id
;
// 标识符
uint16_t
sequence
;
// 序列号
};
class
Common
class
Common
{
{
public
:
public
:
...
@@ -39,6 +53,14 @@ public:
...
@@ -39,6 +53,14 @@ public:
QString
getVideoDownload
();
QString
getVideoDownload
();
void
setVideoDownload
(
QString
videoDownload
);
void
setVideoDownload
(
QString
videoDownload
);
uint16_t
calculateChecksum
(
uint16_t
*
buffer
,
int
size
);
bool
sendPingRequest
(
int
sockfd
,
const
char
*
ipAddress
,
int
sequence
);
bool
receivePingReply
(
int
sockfd
,
int
sequence
);
bool
pingAddress
(
const
QString
&
address
)
;
QString
getImages
();
QString
getImages
();
void
setImages
(
QString
images
);
void
setImages
(
QString
images
);
...
...
NonConnectedCameraHandle.cpp
View file @
e14f599a
...
@@ -241,7 +241,9 @@ int NonConnectedCameraHandle::sdkDevLoginSyn(QString sDevId, int nDevPort,
...
@@ -241,7 +241,9 @@ int NonConnectedCameraHandle::sdkDevLoginSyn(QString sDevId, int nDevPort,
return
loginResult
;
return
loginResult
;
}
}
bool
NonConnectedCameraHandle
::
distributionNetwork
(
QString
&
ip
,
QString
&
sSn
,
int
hDevice
){
bool
NonConnectedCameraHandle
::
distributionNetwork
(
QString
&
ip
,
QString
&
sSn
,
int
hDevice
){
if
(
ip
.
length
()
>
0
&&
vides_data
::
pingAddress
(
ip
)){
Common
&
instace
=
Common
::
getInstance
();
if
(
ip
.
length
()
>
0
&&
instace
.
pingAddress
(
ip
)){
qInfo
()
<<
QString
(
"SN(%1): 当前ip已被使用%2"
).
arg
(
sSn
).
arg
(
ip
);
qInfo
()
<<
QString
(
"SN(%1): 当前ip已被使用%2"
).
arg
(
sSn
).
arg
(
ip
);
return
false
;
return
false
;
}
}
...
...
VidesData.h
View file @
e14f599a
...
@@ -535,6 +535,8 @@ inline bool pingAddress(const QString &address) {
...
@@ -535,6 +535,8 @@ inline bool pingAddress(const QString &address) {
}
}
inline
QString
findReachableIp
()
{
inline
QString
findReachableIp
()
{
Common
&
instace
=
Common
::
getInstance
();
QList
<
QHostAddress
>
ipAddressesList
=
QNetworkInterface
::
allAddresses
();
QList
<
QHostAddress
>
ipAddressesList
=
QNetworkInterface
::
allAddresses
();
for
(
const
QHostAddress
&
address
:
ipAddressesList
)
{
for
(
const
QHostAddress
&
address
:
ipAddressesList
)
{
if
(
address
.
protocol
()
==
QAbstractSocket
::
IPv4Protocol
&&
!
address
.
isLoopback
())
{
if
(
address
.
protocol
()
==
QAbstractSocket
::
IPv4Protocol
&&
!
address
.
isLoopback
())
{
...
@@ -544,7 +546,7 @@ inline QString findReachableIp() {
...
@@ -544,7 +546,7 @@ inline QString findReachableIp() {
for
(
int
i
=
254
;
i
>=
1
;
--
i
)
{
// 从 254 开始递减
for
(
int
i
=
254
;
i
>=
1
;
--
i
)
{
// 从 254 开始递减
QString
ip
=
currentSubnet
+
QString
::
number
(
i
);
QString
ip
=
currentSubnet
+
QString
::
number
(
i
);
qInfo
()
<<
"Found findReachableIp IP:"
<<
ip
;
qInfo
()
<<
"Found findReachableIp IP:"
<<
ip
;
if
(
!
pingAddress
(
ip
))
{
if
(
!
instace
.
pingAddress
(
ip
))
{
qInfo
()
<<
"ping 不通的ip:"
<<
ip
;
qInfo
()
<<
"ping 不通的ip:"
<<
ip
;
return
ip
;
return
ip
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment