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
e3cfe167
Commit
e3cfe167
authored
Oct 11, 2024
by
“liusq”
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改mqtt断线
parent
d18f6f37
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
66 additions
and
37 deletions
+66
-37
CameraHandle.cpp
+34
-35
CameraHandle.h
+1
-1
MqttSubscriber.cpp
+18
-1
MqttSubscriber.h
+6
-0
mainwindow.cpp
+5
-0
mainwindow.h
+2
-0
No files found.
CameraHandle.cpp
View file @
e3cfe167
...
...
@@ -439,7 +439,7 @@ void CameraHandle::sdkDevSnapSyn(XSDK_HANDLE hDevice, int nChannel){
qDebug
()
<<
sSn
<<
":ping 的结果"
<<
is_ping
;
if
(
is_ping
){
resetGb28181
();
deviceReboot
();
}
else
{
QString
ip
=
QString
::
fromUtf8
(
loginParam
->
sDevId
);
MainWindow
::
sp_this
->
clearOfflineCameraHandle
(
ip
,
loginParam
->
nDevPort
);
...
...
@@ -1017,7 +1017,7 @@ void CameraHandle::printWifi(XSDK_HANDLE hDevice,XSDK_CFG::NetWork_Wifi &cfg){
需注意和定时任务对比GB28181配置冲突处理
需确认修改IP后抓图是否正常,如不正常需在命令开始前增加删除句柄,命令完成后增加句柄以保证抓图实时性
*/
int
CameraHandle
::
resetGb28181
(){
int
CameraHandle
::
resetGb28181
(
QString
&
uuiq
){
NonConnectedCameraHandle
*
connectedCameraHandle
=
NonConnectedCameraHandle
::
getInstance
();
int
old
=
this
->
hDevice
;
qInfo
()
<<
QString
(
"SN(%1): resetGb28181老句柄%2"
).
arg
(
sSn
).
arg
(
old
);
...
...
@@ -1050,12 +1050,9 @@ int CameraHandle::resetGb28181(){
int
newHandle
=-
1
;
if
(
!
result
){
qInfo
()
<<
QString
(
"SN(%1): WIFI修改的前的句柄%2"
).
arg
(
sSn
).
arg
(
old
);
result
=
connectedCameraHandle
->
wifiChangeIp
(
reachableIp
,
old
,
sSn
);
is_wifi
=
true
;
if
(
result
){
QThread
::
sleep
(
1
);
//老句柄抓图不正常了
int
sdk_handle
=
this
->
sdkDevLoginSyn
(
reachableIp
,
loginParam
->
nDevPort
,
loginParam
->
sUserName
,
loginParam
->
sPassword
,
3000
);
if
(
sdk_handle
<
0
){
...
...
@@ -1075,44 +1072,46 @@ int CameraHandle::resetGb28181(){
}
}
// 阻塞等待5秒
QThread
::
sleep
(
5
);
QString
old_ip
;
MainWindow
::
sp_this
->
findSnMapIp
(
this
->
sSn
,
old_ip
);
if
(
old_ip
.
length
()
>
0
){
if
(
is_wifi
){
result
=
connectedCameraHandle
->
wifiChangeIp
(
old_ip
,
newHandle
,
sSn
);
QThread
::
sleep
(
1
);
int
sdk_handle
=
this
->
sdkDevLoginSyn
(
old_ip
,
loginParam
->
nDevPort
,
loginParam
->
sUserName
,
loginParam
->
sPassword
,
3000
);
if
(
sdk_handle
<
0
){
qInfo
()
<<
QString
(
"SN(%1): WIFI新句柄生成失败"
).
arg
(
sSn
);
this
->
hDevice
=
newHandle
;
return
-
1
;
}
else
{
XSDK_DevLogout
(
newHandle
);
qInfo
()
<<
QString
(
"SN(%1): WIFI新句柄生成成功"
).
arg
(
sSn
);
}
}
else
{
device
.
reachableIp
=
old_ip
;
device
.
sSn
=
sSn
;
bool
result
=
connectedCameraHandle
->
changeCameraIp
(
device
);
if
(
result
){
//QThread::sleep(5);
QTimer
::
singleShot
(
5000
,
this
,
[
this
,
&
is_wifi
,
&
result
,
&
uuiq
,
&
connectedCameraHandle
,
&
newHandle
,
&
device
,
&
old
]()
{
QString
old_ip
;
int
res
=
1
;
MainWindow
::
sp_this
->
findSnMapIp
(
this
->
sSn
,
old_ip
);
if
(
old_ip
.
length
()
>
0
){
if
(
is_wifi
){
result
=
connectedCameraHandle
->
wifiChangeIp
(
old_ip
,
newHandle
,
sSn
);
int
sdk_handle
=
this
->
sdkDevLoginSyn
(
old_ip
,
loginParam
->
nDevPort
,
loginParam
->
sUserName
,
loginParam
->
sPassword
,
3000
);
if
(
sdk_handle
<
0
){
qInfo
()
<<
QString
(
"SN(%1):
有线
新句柄生成失败"
).
arg
(
sSn
);
this
->
hDevice
=
old
;
re
turn
-
1
;
qInfo
()
<<
QString
(
"SN(%1):
WIFI
新句柄生成失败"
).
arg
(
sSn
);
this
->
hDevice
=
newHandle
;
re
s
=
-
1
;
}
else
{
XSDK_DevLogout
(
old
);
qInfo
()
<<
QString
(
"SN(%1): 有线新句柄生成成功"
).
arg
(
sSn
);
XSDK_DevLogout
(
newHandle
);
qInfo
()
<<
QString
(
"SN(%1): WIFI新句柄生成成功"
).
arg
(
sSn
);
}
}
else
{
device
.
reachableIp
=
old_ip
;
device
.
sSn
=
sSn
;
bool
result
=
connectedCameraHandle
->
changeCameraIp
(
device
);
if
(
result
){
int
sdk_handle
=
this
->
sdkDevLoginSyn
(
old_ip
,
loginParam
->
nDevPort
,
loginParam
->
sUserName
,
loginParam
->
sPassword
,
3000
);
if
(
sdk_handle
<
0
){
qInfo
()
<<
QString
(
"SN(%1): 有线新句柄生成失败"
).
arg
(
sSn
);
this
->
hDevice
=
old
;
res
=
-
1
;
}
else
{
XSDK_DevLogout
(
old
);
qInfo
()
<<
QString
(
"SN(%1): 有线新句柄生成成功"
).
arg
(
sSn
);
}
}
}
}
}
return
1
;
//this->updateSdkDevStatus(true
);
MainWindow
::
sp_this
->
mqttEmitAsynchronous
(
uuiq
,
res
,
device
.
sSn
);
return
res
;
}
);
//this->updateSdkDevStatus(true);
return
1
;
}
int
CameraHandle
::
forceWriteGb28181
(){
...
...
CameraHandle.h
View file @
e3cfe167
...
...
@@ -114,7 +114,7 @@ public:
//获取固件版本
void
findFirmwareVersion
(
QString
&
firmwareVersion
);
//复位GB28181
int
resetGb28181
();
int
resetGb28181
(
QString
&
uuiq
);
//强制gb28181配置后写入摄像头
int
forceWriteGb28181
();
...
...
MqttSubscriber.cpp
View file @
e3cfe167
...
...
@@ -57,6 +57,9 @@ void MqttSubscriber::init(vides_data::MqttConfig &config, QString &httpUrl, QStr
MqttSubscriber
::
MqttSubscriber
(
QObject
*
parent
)
:
QObject
(
parent
),
retryTimer
(
new
QTimer
(
this
)),
client
(
nullptr
)
{
connect
(
this
,
&
MqttSubscriber
::
asynchronousMqtt
,
this
,
&
MqttSubscriber
::
asynchronousPush
,
Qt
::
QueuedConnection
);
// 连接信号和槽
connect
(
this
,
&
MqttSubscriber
::
connectionLostSignal
,
this
,
&
MqttSubscriber
::
reconnectAndFetchConfig
,
Qt
::
QueuedConnection
);
...
...
@@ -104,6 +107,9 @@ void MqttSubscriber::start() {
qInfo
()
<<
"启动连接失败,返回编码"
<<
rc
;
}
}
void
MqttSubscriber
::
emitAsynchronous
(
QString
&
uniq
,
int
&
res
,
QString
&
sn
){
emit
asynchronousMqtt
(
uniq
,
res
,
sn
);
}
void
MqttSubscriber
::
onConnect
(
MQTTAsync_successData
*
response
)
{
...
...
@@ -227,7 +233,7 @@ int MqttSubscriber::messageArrived(char* topicName, int topicLen, MQTTAsync_mess
}
break
;
}
case
8
:
res
=
cameraHandle
->
resetGb28181
();
break
;
case
8
:
res
=
cameraHandle
->
resetGb28181
(
response
.
uniq
);
break
;
default
:
qInfo
()
<<
"Unknown message type"
;
break
;
}
}
...
...
@@ -244,6 +250,10 @@ int MqttSubscriber::messageArrived(char* topicName, int topicLen, MQTTAsync_mess
}
res
=
(
connectedCameraHandle
->
distributionNetwork
(
ipAddress
,
response
.
sn
,
hDevice
)
?
0x01
:-
1
);
}
if
(
response
.
msg_type
==
8
)
{
qInfo
()
<<
"mqtt 复位GB28181 异步走卡槽函数触发"
;
return
-
1
;
}
vides_data
::
requestMqttData
request
;
request
.
code
=
(
res
>=
0
)
?
0
:
0x01
;
...
...
@@ -255,6 +265,13 @@ int MqttSubscriber::messageArrived(char* topicName, int topicLen, MQTTAsync_mess
MQTTAsync_free
(
topicName
);
return
1
;
}
void
MqttSubscriber
::
asynchronousPush
(
QString
&
uniq
,
int
&
res
,
QString
&
sn
){
vides_data
::
requestMqttData
request
;
request
.
code
=
(
res
>=
0
)
?
0
:
0x01
;
request
.
msg
=
(
res
>=
0
)
?
"成功"
:
"失败"
;
request
.
uniq
=
uniq
;
sendSubscriptionConfirmation
(
request
,
sn
);
}
void
MqttSubscriber
::
sendSubscriptionConfirmation
(
const
vides_data
::
requestMqttData
&
response
,
QString
&
sn
)
{
QString
responseTopic
=
"/thingshub/"
+
response
.
uniq
+
"/device/post"
;
...
...
MqttSubscriber.h
View file @
e3cfe167
...
...
@@ -14,11 +14,16 @@ public:
void
init
(
vides_data
::
MqttConfig
&
config
,
QString
&
httpUrl
,
QString
&
serialNumber
);
void
start
();
void
emitAsynchronous
(
QString
&
uniq
,
int
&
res
,
QString
&
sn
);
signals
:
void
connectionLostSignal
();
void
asynchronousMqtt
(
QString
&
uniq
,
int
&
res
,
QString
&
sn
);
private
slots
:
void
reconnectAndFetchConfig
();
void
asynchronousPush
(
QString
&
uniq
,
int
&
res
,
QString
&
sn
);
private
:
MqttSubscriber
(
QObject
*
parent
=
nullptr
);
MqttSubscriber
()
=
delete
;
...
...
@@ -45,6 +50,7 @@ private:
void
onPublishSuccess
(
MQTTAsync_successData
*
response
);
void
onPublishFailure
(
MQTTAsync_failureData
*
response
);
void
sendSubscriptionConfirmation
(
const
vides_data
::
requestMqttData
&
response
,
QString
&
sn
);
static
MqttSubscriber
*
instance
;
};
...
...
mainwindow.cpp
View file @
e3cfe167
...
...
@@ -134,6 +134,11 @@ MainWindow::MainWindow():isResetting(false)
runOrRebootMqtt
(
mqttConfig
,
httpurl
,
serialNumber
);
}
void
MainWindow
::
mqttEmitAsynchronous
(
QString
&
uuiq
,
int
&
res
,
QString
&
sn
){
MqttSubscriber
*
subscriber
=
MqttSubscriber
::
getInstance
(
this
);
subscriber
->
emitAsynchronous
(
uuiq
,
res
,
sn
);
}
void
MainWindow
::
runOrRebootMqtt
(
vides_data
::
MqttConfig
&
mqtt_config
,
QString
&
httpUrl
,
QString
&
serialNumber
){
MqttSubscriber
*
subscriber
=
MqttSubscriber
::
getInstance
(
this
);
subscriber
->
init
(
mqtt_config
,
httpUrl
,
serialNumber
);
...
...
mainwindow.h
View file @
e3cfe167
...
...
@@ -49,6 +49,8 @@ public:
void
divParameterUpdate
(
vides_data
::
responseConfig
&
cloudConfig
,
QString
&
httpUrl
,
QString
&
serialNumber
);
static
MainWindow
*
sp_this
;
void
mqttEmitAsynchronous
(
QString
&
uniq
,
int
&
res
,
QString
&
sn
);
CameraHandle
*
findHandle
(
QString
sn
);
...
...
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