Commit fa9c2024 by “liusq”

修改命令bug

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