Commit dc686e8c by 郭峰

Merge branch 'feature-1007488' into 'release'

修改命令bug

See merge request !38
parents 063dc84f fa9c2024
......@@ -241,7 +241,7 @@ int NonConnectedCameraHandle::sdkDevLoginSyn(QString sDevId, int nDevPort,
return loginResult;
}
bool NonConnectedCameraHandle::distributionNetwork(QString &ip,QString &sSn,int hDevice ){
if(vides_data::pingAddress(ip)){
if(ip.length()>0 && vides_data::pingAddress(ip)){
qInfo()<<QString("SN(%1): 当前ip已被使用%2").arg(sSn).arg(ip);
return false;
}
......
......@@ -442,8 +442,8 @@ inline bool GetNetworkInfoByQNetworkInterface(QString &mac, QString &subnetMask,
QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
foreach (QNetworkInterface interface, interfaces) {
if (interface.flags().testFlag(QNetworkInterface::IsUp) &&
interface.flags().testFlag(QNetworkInterface::IsRunning) &&
!interface.flags().testFlag(QNetworkInterface::IsLoopBack)) {
interface.flags().testFlag(QNetworkInterface::IsRunning) &&
!interface.flags().testFlag(QNetworkInterface::IsLoopBack)) {
mac = interface.hardwareAddress();
QList<QNetworkAddressEntry> addressEntries = interface.addressEntries();
......@@ -484,40 +484,38 @@ inline bool GetNetworkInfoByQNetworkInterface(QString &mac, QString &subnetMask,
}
inline bool pingAddress(const QString &address) {
QProcess process;
QString program = "ping";
QStringList arguments;
#ifdef Q_OS_WIN
// Windows 下通常不需要 sudo
arguments << "-n" << "1" << address;
// Windows 指令 "ping IP -n 1 -w 超时(ms)"
QString cmdstr = QString("ping %1 -n 1 -w %2")
.arg(address).arg(1000);
#else
// 不使用 sudo
arguments << "-c" << "1" << address;
// Linux 指令 "ping -c 1 IP"
QString cmdstr = QString("ping -c 1 %1")
.arg(address);
#endif
process.start(program, arguments);
if (!process.waitForStarted()) {
qWarning() << "Failed to start 'ping' process for" << address;
return false;
}
// 使用较长的超时值,确保进程有足够时间完成
if (!process.waitForFinished(3000)) {
process.kill(); // 如果超时,强制终止进程
qWarning() << "Ping process timed out for" << address;
return false;
}
QProcess cmd;
cmd.start(cmdstr);
cmd.waitForReadyRead(1000);
cmd.waitForFinished(1000);
QString output(process.readAllStandardOutput());
qDebug() << "Ping Output for" << address << ":" << output; // 调试输出
QString res = QString::fromLocal8Bit(cmd.readAll());
qInfo() << res;
// 简单的 Ping 成功检查逻辑
#ifdef Q_OS_WIN
return output.contains("TTL=");
if (res.indexOf("TTL") == -1)
#else
return output.contains("1 packets transmitted, 1 received");
if (!res.contains("1 packets transmitted, 1 received"))
#endif
{
qInfo() << address << QString::fromLocal8Bit("ping不通");
return false;
}
else
{
qInfo() << address << QString::fromLocal8Bit("ping通");
return true;
}
}
inline QString findReachableIp() {
......
......@@ -130,7 +130,9 @@ HEADERS += \
AlgorithmTaskManage.h \
BaseAlgorithm.h \
MqttSubscriber.h \
NonConnectedCameraHandle.h
NonConnectedCameraHandle.h \
RecognizedInfo.h
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment