1 Star 0 Fork 20

MumiWHN/24041智能安防_3

forked from 刘军/24041智能安防 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
myonvif.cpp 3.54 KB
一键复制 编辑 原始数据 按行查看 历史
刘军 提交于 2024-09-12 09:50 . add MAINmenu
#include "myonvif.h"
MyOnvif::MyOnvif(QObject *parent) : QObject(parent)
{/*
this->DISCOVERY_PORT = 3702;
this->DISCOVERY_TIMEOUT = 6000; // 6 seconds
this->DISCOVERY_MESSAGE = QByteArray(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\" "
"xmlns:a=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\">"
"<s:Header>"
"<a:Action s:mustUnderstand=\"1\">http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe</a:Action>"
"<a:MessageID>uuid:00000000-0000-0000-0000-000000000000</a:MessageID>"
"<a:To s:mustUnderstand=\"1\">urn:schemas-xmlsoap-org:ws:2005:04:discovery</a:To>"
"</s:Header>"
"<s:Body>"
"<Probe xmlns=\"http://schemas.xmlsoap.org/ws/2005/04/discovery\">"
"<Types>dn:NetworkVideoTransmitter</Types>"
"<Scopes>onvif://www.onvif.org/Profile/S</Scopes>"
"</Probe>"
"</s:Body>"
"</s:Envelope>");*/
}
int MyOnvif::searchOnvifCamera()
{
const quint16 DISCOVERY_PORT = 3702;
const quint16 DISCOVERY_TIMEOUT = 6000; // 3 seconds
const QByteArray DISCOVERY_MESSAGE = QByteArray(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\" "
"xmlns:a=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\">"
"<s:Header>"
"<a:Action s:mustUnderstand=\"1\">http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe</a:Action>"
"<a:MessageID>uuid:00000000-0000-0000-0000-000000000000</a:MessageID>"
"<a:To s:mustUnderstand=\"1\">urn:schemas-xmlsoap-org:ws:2005:04:discovery</a:To>"
"</s:Header>"
"<s:Body>"
"<Probe xmlns=\"http://schemas.xmlsoap.org/ws/2005/04/discovery\">"
"<Types>dn:NetworkVideoTransmitter</Types>"
"<Scopes>onvif://www.onvif.org/Profile/S</Scopes>"
"</Probe>"
"</s:Body>"
"</s:Envelope>");
qDebug() << "into searchOnvifCamera:" ;
QUdpSocket socket;
QTimer timer;
// Bind the socket to the discovery port
if (!socket.bind(QHostAddress::AnyIPv4, DISCOVERY_PORT, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint)) {
qWarning() << "Failed to bind to port" << DISCOVERY_PORT;
return -1;
}
// Set up a timer to stop discovery after a certain period
QObject::connect(&timer, &QTimer::timeout, [&]() {
socket.close();
qInfo() << "Discovery finished.";
QCoreApplication::quit();
});
// Connect the readyRead signal to a slot that processes incoming datagrams
QObject::connect(&socket, &QUdpSocket::readyRead, [&]() {
while (socket.hasPendingDatagrams()) {
QNetworkDatagram datagram = socket.receiveDatagram();
QString message = QString::fromUtf8(datagram.data());
qDebug() << "Received message from" << datagram.senderAddress().toString() << ":" << datagram.senderPort();
qDebug() << "Message:" << message;
}
});
// Join the multicast group after binding
QNetworkInterface interface = QNetworkInterface::interfaceFromName("eth0"); // Use your actual interface name
socket.joinMulticastGroup(QHostAddress("239.255.255.250"), interface);
// Send the discovery message to the multicast address
socket.writeDatagram(DISCOVERY_MESSAGE, QHostAddress("239.255.255.250"), DISCOVERY_PORT);
// Start the timer
timer.start(DISCOVERY_TIMEOUT);
qDebug() << "leave searchOnvifCamera:";
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mumiwhn/24041-intelligent-security_3.git
git@gitee.com:mumiwhn/24041-intelligent-security_3.git
mumiwhn
24041-intelligent-security_3
24041智能安防_3
master

搜索帮助