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
93324592
Commit
93324592
authored
Aug 09, 2024
by
“liusq”
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增mqtt控制相机重合关闭
parent
6d4d10ba
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
84 additions
and
20 deletions
+84
-20
CameraHandle.cpp
+23
-3
CameraHandle.h
+3
-1
MqttSubscriber.cpp
+49
-10
MqttSubscriber.h
+1
-1
VidesData.h
+8
-5
No files found.
CameraHandle.cpp
View file @
93324592
...
@@ -1073,7 +1073,7 @@ void CameraHandle::sdkDevSpvMn(const char *spvMn){
...
@@ -1073,7 +1073,7 @@ void CameraHandle::sdkDevSpvMn(const char *spvMn){
qInfo
()
<<
"sdkDevSpvMn 28181->修改失败"
<<
res
;
qInfo
()
<<
"sdkDevSpvMn 28181->修改失败"
<<
res
;
}
}
}
}
void
CameraHandle
::
deviceReboot
(
bool
isCloseHandle
){
int
CameraHandle
::
deviceReboot
(
bool
isCloseHandle
){
int
nRet
=
0
;
int
nRet
=
0
;
XSDK_CFG
::
OPMachine
cfg
;
XSDK_CFG
::
OPMachine
cfg
;
cfg
.
Action
.
SetValue
(
"Reboot"
);
cfg
.
Action
.
SetValue
(
"Reboot"
);
...
@@ -1082,16 +1082,36 @@ void CameraHandle::deviceReboot(bool isCloseHandle){
...
@@ -1082,16 +1082,36 @@ void CameraHandle::deviceReboot(bool isCloseHandle){
nRet
=
XSDK_DevSetSysConfig
(
hDevice
,
JK_OPMachine
,
pCfg
,
strlen
(
pCfg
),
1
,
3000
,
EXCMD_SYSMANAGER_REQ
);
nRet
=
XSDK_DevSetSysConfig
(
hDevice
,
JK_OPMachine
,
pCfg
,
strlen
(
pCfg
),
1
,
3000
,
EXCMD_SYSMANAGER_REQ
);
if
(
nRet
<
0
){
if
(
nRet
<
0
){
qInfo
()
<<
sSn
<<
"重启相机失败"
<<
nRet
;
qInfo
()
<<
sSn
<<
"重启相机失败"
<<
nRet
;
return
;
return
0
;
}
}
if
(
isCloseHandle
){
if
(
isCloseHandle
){
return
;
return
0
;
}
}
QString
ip
=
QString
::
fromUtf8
(
loginParam
->
sDevId
);
QString
ip
=
QString
::
fromUtf8
(
loginParam
->
sDevId
);
MainWindow
::
sp_this
->
clearOfflineCameraHandle
(
ip
,
loginParam
->
nDevPort
);
MainWindow
::
sp_this
->
clearOfflineCameraHandle
(
ip
,
loginParam
->
nDevPort
);
return
nRet
;
}
}
int
CameraHandle
::
deviceShutdown
()
{
int
nRet
=
0
;
XSDK_CFG
::
OPMachine
cfg
;
cfg
.
Action
.
SetValue
(
"Shutdown"
);
const
char
*
pCfg
=
cfg
.
ToString
();
nRet
=
XSDK_DevSetSysConfig
(
hDevice
,
JK_OPMachine
,
pCfg
,
strlen
(
pCfg
),
1
,
3000
,
EXCMD_SYSMANAGER_REQ
);
if
(
nRet
<
0
){
qInfo
()
<<
sSn
<<
"设备关机失败"
<<
nRet
;
return
0
;
}
QString
ip
=
QString
::
fromUtf8
(
loginParam
->
sDevId
);
MainWindow
::
sp_this
->
clearOfflineCameraHandle
(
ip
,
loginParam
->
nDevPort
);
return
nRet
;
}
bool
CameraHandle
::
polygonsOverlap
(
ParkingSpaceInfo
&
poly1
,
ParkingSpaceInfo
&
poly2
)
{
bool
CameraHandle
::
polygonsOverlap
(
ParkingSpaceInfo
&
poly1
,
ParkingSpaceInfo
&
poly2
)
{
QPolygonF
realPolygon
;
QPolygonF
realPolygon
;
...
...
CameraHandle.h
View file @
93324592
...
@@ -100,7 +100,9 @@ public:
...
@@ -100,7 +100,9 @@ public:
void
updateSdkDevSpvMn
(
vides_data
::
responseGb28181
*
gb28181
);
void
updateSdkDevSpvMn
(
vides_data
::
responseGb28181
*
gb28181
);
//重启设备
//重启设备
void
deviceReboot
(
bool
isCloseHandle
);
int
deviceReboot
(
bool
isCloseHandle
);
//设备关机
int
deviceShutdown
();
//获取固件版本
//获取固件版本
void
findFirmwareVersion
(
QString
&
firmwareVersion
);
void
findFirmwareVersion
(
QString
&
firmwareVersion
);
...
...
MqttSubscriber.cpp
View file @
93324592
#include "MqttSubscriber.h"
#include "MqttSubscriber.h"
#include "mainwindow.h"
#include "CameraHandle.h"
MqttSubscriber
*
MqttSubscriber
::
instance
=
nullptr
;
MqttSubscriber
*
MqttSubscriber
::
instance
=
nullptr
;
MqttSubscriber
*
MqttSubscriber
::
getInstance
(
vides_data
::
MqttConfig
&
config
,
QObject
*
parent
)
{
MqttSubscriber
*
MqttSubscriber
::
getInstance
(
vides_data
::
MqttConfig
&
config
,
QObject
*
parent
)
{
...
@@ -101,22 +103,59 @@ int MqttSubscriber::messageArrived(char* topicName, int topicLen, MQTTAsync_mess
...
@@ -101,22 +103,59 @@ int MqttSubscriber::messageArrived(char* topicName, int topicLen, MQTTAsync_mess
QString
topic
(
topicName
);
QString
topic
(
topicName
);
QString
payload
=
QString
::
fromUtf8
(
reinterpret_cast
<
const
char
*>
(
m
->
payload
),
m
->
payloadlen
);
QString
payload
=
QString
::
fromUtf8
(
reinterpret_cast
<
const
char
*>
(
m
->
payload
),
m
->
payloadlen
);
qInfo
()
<<
"Message arrived"
;
vides_data
::
responseMqttData
response
;
qInfo
()
<<
"Topic:"
<<
topic
;
QJsonDocument
jsonDoc
=
QJsonDocument
::
fromJson
(
payload
.
toUtf8
());
qInfo
()
<<
"Payload:"
<<
payload
;
if
(
!
jsonDoc
.
isNull
()
&&
jsonDoc
.
isObject
())
{
qInfo
()
<<
"topicLen"
<<
topicLen
;
QJsonObject
jsonObj
=
jsonDoc
.
object
();
response
.
msg_type
=
jsonObj
[
"msg_type"
].
toInt
();
response
.
sn
=
jsonObj
[
"sn"
].
toString
();
response
.
uniq
=
jsonObj
[
"uniq"
].
toString
();
}
else
{
qInfo
()
<<
"Failed to parse JSON payload"
;
}
int
res
=-
2
;
//1开 2关 3 重启
CameraHandle
*
cameraHandle
=
MainWindow
::
sp_this
->
findHandle
(
response
.
sn
);
if
(
cameraHandle
==
nullptr
){
qInfo
()
<<
"不存在该相机"
;
return
1
;
}
if
(
response
.
msg_type
==
2
){
res
=
cameraHandle
->
deviceShutdown
();
}
if
(
response
.
msg_type
==
3
){
res
=
cameraHandle
->
deviceReboot
(
false
);
}
vides_data
::
requestMqttData
request
;
qInfo
()
<<
"res"
<<
res
;
request
.
code
=
res
>=
0
?
0
:
0x01
;
request
.
uniq
=
response
.
uniq
;
request
.
sn
=
response
.
sn
;
sendSubscriptionConfirmation
(
request
);
MQTTAsync_freeMessage
(
&
m
);
MQTTAsync_freeMessage
(
&
m
);
MQTTAsync_free
(
topicName
);
MQTTAsync_free
(
topicName
);
return
1
;
return
1
;
}
}
void
MqttSubscriber
::
sendSubscriptionConfirmation
(
const
std
::
string
&
messageId
)
{
void
MqttSubscriber
::
sendSubscriptionConfirmation
(
const
vides_data
::
requestMqttData
&
response
)
{
std
::
string
confirmationTopic
=
"confirmation/subscription"
;
std
::
string
confirmationMessage
=
"Subscription confirmed with message ID: "
+
messageId
;
QString
responseTopic
=
"/thingshub/"
+
response
.
sn
+
"/device/post"
;
QByteArray
bResponseTopic
=
responseTopic
.
toUtf8
();
char
*
cResponseTopic
=
bResponseTopic
.
data
();
qInfo
()
<<
"sendSubscriptionConfirmation"
<<
cResponseTopic
;
// 将 struct 转换成 JSON 格式
QJsonObject
json
;
json
[
"code"
]
=
response
.
code
;
json
[
"uniq"
]
=
response
.
uniq
;
QJsonDocument
jsonDoc
(
json
);
QByteArray
payload
=
jsonDoc
.
toJson
(
QJsonDocument
::
Compact
);
MQTTAsync_message
pubmsg
=
MQTTAsync_message_initializer
;
MQTTAsync_message
pubmsg
=
MQTTAsync_message_initializer
;
pubmsg
.
payload
=
const_cast
<
char
*>
(
confirmationMessage
.
c_str
());
pubmsg
.
payloadlen
=
confirmationMessage
.
length
();
pubmsg
.
payload
=
const_cast
<
char
*>
(
payload
.
data
());
pubmsg
.
payloadlen
=
payload
.
size
();
pubmsg
.
qos
=
config
.
qos
;
pubmsg
.
qos
=
config
.
qos
;
pubmsg
.
retained
=
0
;
pubmsg
.
retained
=
0
;
...
@@ -130,7 +169,7 @@ void MqttSubscriber::sendSubscriptionConfirmation(const std::string& messageId)
...
@@ -130,7 +169,7 @@ void MqttSubscriber::sendSubscriptionConfirmation(const std::string& messageId)
opts
.
context
=
this
;
opts
.
context
=
this
;
int
rc
;
int
rc
;
if
((
rc
=
MQTTAsync_sendMessage
(
client
,
c
onfirmationTopic
.
c_str
()
,
&
pubmsg
,
&
opts
))
!=
MQTTASYNC_SUCCESS
)
{
if
((
rc
=
MQTTAsync_sendMessage
(
client
,
c
ResponseTopic
,
&
pubmsg
,
&
opts
))
!=
MQTTASYNC_SUCCESS
)
{
qInfo
()
<<
"发送消息失败,返回编码"
<<
rc
;
qInfo
()
<<
"发送消息失败,返回编码"
<<
rc
;
}
}
}
}
...
...
MqttSubscriber.h
View file @
93324592
...
@@ -34,7 +34,7 @@ private:
...
@@ -34,7 +34,7 @@ private:
void
onPublishSuccess
(
MQTTAsync_successData
*
response
);
void
onPublishSuccess
(
MQTTAsync_successData
*
response
);
void
onPublishFailure
(
MQTTAsync_failureData
*
response
);
void
onPublishFailure
(
MQTTAsync_failureData
*
response
);
void
sendSubscriptionConfirmation
(
const
std
::
string
&
messageId
);
void
sendSubscriptionConfirmation
(
const
vides_data
::
requestMqttData
&
response
);
static
MqttSubscriber
*
instance
;
static
MqttSubscriber
*
instance
;
};
};
...
...
VidesData.h
View file @
93324592
...
@@ -294,14 +294,17 @@ struct responseConfig {
...
@@ -294,14 +294,17 @@ struct responseConfig {
Camera
camera
;
Camera
camera
;
MqttConfig
mqttConfig
;
MqttConfig
mqttConfig
;
};
};
struct
Devices
{
QString
id
;
QString
state
;
};
struct
responseMqttData
{
struct
responseMqttData
{
uint8_t
msg_type
;
uint8_t
msg_type
;
std
::
list
<
Devices
>
devices
;
QString
sn
;
QString
uniq
;
};
struct
requestMqttData
{
QString
sn
;
int
code
;
QString
uniq
;
};
};
inline
bool
isVirtualMachine
()
inline
bool
isVirtualMachine
()
...
...
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