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
75c1ac2a
Commit
75c1ac2a
authored
Oct 10, 2024
by
“liusq”
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改ping命令-02
parent
dcd3dc5e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
59 additions
and
5 deletions
+59
-5
CameraHandle.cpp
+2
-1
Common.cpp
+27
-0
Common.h
+24
-2
NonConnectedCameraHandle.cpp
+3
-1
VidesData.h
+3
-1
No files found.
CameraHandle.cpp
View file @
75c1ac2a
...
...
@@ -425,6 +425,7 @@ void CameraHandle::sdkDevSnapSyn(XSDK_HANDLE hDevice, int nChannel){
ScopeSemaphoreExit
guard
([
this
]()
{
semaphore
.
release
();
// 释放信号量
});
Common
&
instace
=
Common
::
getInstance
();
cv
::
Mat
image
;
MediaFaceImage
*
mediaFaceImage
=
MediaFaceImage
::
getInstance
();
qint64
currentTime
=
QDateTime
::
currentSecsSinceEpoch
();
...
...
@@ -434,7 +435,7 @@ void CameraHandle::sdkDevSnapSyn(XSDK_HANDLE hDevice, int nChannel){
if
(
offlineCount
>=
3
)
{
// 判断是否连续3次返回0
qInfo
()
<<
QString
(
"SN(%1): 设备离线"
).
arg
(
sSn
);
QString
ip
=
QString
::
fromUtf8
(
loginParam
->
sDevId
);
bool
is_ping
=
vides_data
::
pingAddress
(
ip
);
bool
is_ping
=
instace
.
pingAddress
(
ip
);
qDebug
()
<<
sSn
<<
":ping 的结果"
<<
is_ping
;
if
(
is_ping
){
...
...
Common.cpp
View file @
75c1ac2a
#include "Common.h"
#include "ScopeSemaphoreExit.h"
Common
::
Common
(){}
...
...
@@ -173,5 +174,31 @@ bool Common::receivePingReply(int sockfd, int sequence) {
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.h
View file @
75c1ac2a
...
...
@@ -11,7 +11,21 @@
#include <QMessageAuthenticationCode>
#include <QNetworkInterface>
#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
{
public
:
...
...
@@ -38,8 +52,16 @@ public:
QString
getVideoDownload
();
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
();
void
setImages
(
QString
images
);
...
...
NonConnectedCameraHandle.cpp
View file @
75c1ac2a
...
...
@@ -241,7 +241,9 @@ int NonConnectedCameraHandle::sdkDevLoginSyn(QString sDevId, int nDevPort,
return
loginResult
;
}
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
);
return
false
;
}
...
...
VidesData.h
View file @
75c1ac2a
...
...
@@ -535,6 +535,8 @@ inline bool pingAddress(const QString &address) {
}
inline
QString
findReachableIp
()
{
Common
&
instace
=
Common
::
getInstance
();
QList
<
QHostAddress
>
ipAddressesList
=
QNetworkInterface
::
allAddresses
();
for
(
const
QHostAddress
&
address
:
ipAddressesList
)
{
if
(
address
.
protocol
()
==
QAbstractSocket
::
IPv4Protocol
&&
!
address
.
isLoopback
())
{
...
...
@@ -544,7 +546,7 @@ inline QString findReachableIp() {
for
(
int
i
=
254
;
i
>=
1
;
--
i
)
{
// 从 254 开始递减
QString
ip
=
currentSubnet
+
QString
::
number
(
i
);
qInfo
()
<<
"Found findReachableIp IP:"
<<
ip
;
if
(
!
pingAddress
(
ip
))
{
if
(
!
instace
.
pingAddress
(
ip
))
{
qInfo
()
<<
"ping 不通的ip:"
<<
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