From 6eb559b976460349313950381236cfca0d397908 Mon Sep 17 00:00:00 2001 From: shuaijie Date: Fri, 15 Dec 2023 11:16:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20M900=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit M900问题修复 Log: M900问题修复 Bug: https://pms.uniontech.com/bug-view-221883.html Bug: https://pms.uniontech.com/bug-view-187791.html Bug: https://pms.uniontech.com/bug-view-207245.html Bug: https://pms.uniontech.com/bug-view-207187.html --- .../src/LoadInfo/ThreadPool.cpp | 14 + .../src/DeviceManager/DeviceMonitor.cpp | 2 + .../src/DeviceManager/DeviceNetwork.cpp | 3 +- .../src/GenerateDevice/DeviceFactory.cpp | 3 + .../src/GenerateDevice/DeviceGenerator.cpp | 55 +--- .../src/GenerateDevice/HWGenerator.cpp | 5 +- .../src/GenerateDevice/M900Generator.cpp | 273 ++++++++++++++++++ .../src/GenerateDevice/M900Generator.h | 32 ++ deepin-devicemanager/src/Tool/EDIDParser.cpp | 10 + deepin-devicemanager/src/Tool/EDIDParser.h | 7 + deepin-devicemanager/src/Tool/commontools.cpp | 52 ++++ deepin-devicemanager/src/Tool/commontools.h | 13 + deepin-devicemanager/src/commonfunction.cpp | 24 ++ 13 files changed, 438 insertions(+), 55 deletions(-) create mode 100644 deepin-devicemanager/src/GenerateDevice/M900Generator.cpp create mode 100644 deepin-devicemanager/src/GenerateDevice/M900Generator.h diff --git a/deepin-devicemanager-server/src/LoadInfo/ThreadPool.cpp b/deepin-devicemanager-server/src/LoadInfo/ThreadPool.cpp index a7ae0e46..8bf4bc9d 100644 --- a/deepin-devicemanager-server/src/LoadInfo/ThreadPool.cpp +++ b/deepin-devicemanager-server/src/LoadInfo/ThreadPool.cpp @@ -96,6 +96,13 @@ void ThreadPool::initCmd() cmdDmiSPN.canNotReplace = true; m_ListCmd.append(cmdDmiSPN); + // 添加dmidecode -t process命令 + Cmd cmdDmiPRO; + cmdDmiPRO.cmd = QString("%1 %2%3").arg("dmidecode -t processor > ").arg(PATH).arg("dmidecode_pro.txt"); + cmdDmiPRO.file = "dmidecode_pro.txt"; + cmdDmiPRO.canNotReplace = true; + m_ListCmd.append(cmdDmiPRO); + // 添加dmidecode -t 0命令 Cmd cmdDmi0; cmdDmi0.cmd = QString("%1 %2%3").arg("dmidecode -t 0 > ").arg(PATH).arg("dmidecode_0.txt"); @@ -131,6 +138,13 @@ void ThreadPool::initCmd() cmdDmi4.canNotReplace = true; m_ListCmd.append(cmdDmi4); + // 添加dmidecode -t 11命令 + Cmd cmdDmi11; + cmdDmi11.cmd = QString("%1 %2%3").arg("dmidecode -t 11 > ").arg(PATH).arg("dmidecode_11.txt"); + cmdDmi11.file = "dmidecode_11.txt"; + cmdDmi11.canNotReplace = true; + m_ListCmd.append(cmdDmi11); + // 添加dmidecode -t 13命令 Cmd cmdDmi13; cmdDmi13.cmd = QString("%1 %2%3").arg("dmidecode -t 13 > ").arg(PATH).arg("dmidecode_13.txt"); diff --git a/deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp b/deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp index 9e1c764c..2605a52a 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp +++ b/deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp @@ -163,6 +163,8 @@ void DeviceMonitor::setInfoFromEdid(const QMap &mapInfo) setAttribute(mapInfo, "Vendor", m_Vendor); setAttribute(mapInfo, "Date", m_ProductionWeek); setAttribute(mapInfo, "Display Input", m_DisplayInput); + setAttribute(mapInfo, "Model", m_Model); + if(m_Model.isEmpty()) m_Model = m_Name ; getOtherMapInfo(mapInfo); } diff --git a/deepin-devicemanager/src/DeviceManager/DeviceNetwork.cpp b/deepin-devicemanager/src/DeviceManager/DeviceNetwork.cpp index 107bb8d5..a4e2eb8d 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceNetwork.cpp +++ b/deepin-devicemanager/src/DeviceManager/DeviceNetwork.cpp @@ -48,7 +48,8 @@ void DeviceNetwork::setInfoFromLshw(const QMap &mapInfo) { if (!matchToLshw(mapInfo) && Common::boardVendorType() != "KLVV" && Common::boardVendorType() != "KLVU" - && Common::boardVendorType() != "PGUW" && Common::boardVendorType() != "PGUV") { + && Common::boardVendorType() != "PGUW" && Common::boardVendorType() != "PGUV" + && Common::boardVendorType() != "PANGUM900" ) { return; } // 设置由lshw获取的信息 diff --git a/deepin-devicemanager/src/GenerateDevice/DeviceFactory.cpp b/deepin-devicemanager/src/GenerateDevice/DeviceFactory.cpp index b686f610..e816c6d6 100644 --- a/deepin-devicemanager/src/GenerateDevice/DeviceFactory.cpp +++ b/deepin-devicemanager/src/GenerateDevice/DeviceFactory.cpp @@ -10,6 +10,7 @@ #include "KLUGenerator.h" #include "PanguGenerator.h" #include "PanguVGenerator.h" +#include "M900Generator.h" #include "HWGenerator.h" #include "KLVGenerator.h" #include "commonfunction.h" @@ -41,6 +42,8 @@ DeviceGenerator *DeviceFactory::getDeviceGenerator() generator = new KLVGenerator(); else if (type == "PGUV" || type == "PGUW") generator = new PanguVGenerator(); + else if (type == "PANGUM900") + generator = new M900Generator(); else if (type == "KLVU") generator = new KLUGenerator(); else diff --git a/deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp b/deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp index 3f698b1b..f0b3d0c3 100644 --- a/deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp +++ b/deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp @@ -25,6 +25,7 @@ #include "DeviceManager/DevicePrint.h" #include "DeviceManager/DeviceInput.h" #include "MacroDefinition.h" +#include "commontools.h" // Dtk头文件 #include @@ -86,58 +87,6 @@ void DeviceGenerator::generatorComputerDevice() DeviceManager::instance()->addComputerDevice(device); } -void mergeSortCpuInfoByLogicalID(QList > &lsCpu, QList > &tmpLst, int begin, int end) -{ - // 合并列表 - int left_length = (end - begin + 1) / 2; - int left_index = begin; - int right_index = begin + left_length; - int result_index = begin; - - // 合并左右区间 左区间未合并结束且右区间未合并结束时 - while (left_index < begin + left_length && right_index < end + 1) { - // 左右区间,哪个小先排哪个,下标加1 - if (lsCpu[left_index]["processor"].toInt() <= lsCpu[right_index]["processor"].toInt()) - tmpLst[result_index++] = lsCpu[left_index++]; - else - tmpLst[result_index++] = lsCpu[right_index++]; - } - - // 合并左区间剩余数据 - while (left_index < begin + left_length) - tmpLst[result_index++] = lsCpu[left_index++]; - - // 合并右区间剩余数据 - while (right_index < end + 1) - tmpLst[result_index++] = lsCpu[right_index++]; -} - -void sortCpuInfoByLogicalID(QList > &lsCpu, QList > &tmpLst, int begin, int end) -{ - // 列表个数为1,直接返回 - if (0 == end - begin) - return; - - // bug 后台获取CPU信息是按照物理CPU,核心,逻辑CPU顺序获取的 - // 界面上展示顺序混乱实际是按照物理CPU,核心,逻辑CPU顺序展示 - // 与产品沟通后,按照用户的使用感修改,CPU信息按照逻辑CPU的id从小到大显示 - // 区间个数为2 - if (1 == end - begin) { - // 前 processor > 后 processor 时交换位置 - if (lsCpu[begin]["processor"].toInt() > lsCpu[end]["processor"].toInt()) { - QMap tmpMap = lsCpu[begin]; - lsCpu[begin] = lsCpu[end]; - lsCpu[end] = tmpMap; - } - } else { - // 区间个数 > 2 递归 - sortCpuInfoByLogicalID(lsCpu, tmpLst, begin, (end - begin) / 2 + begin); - sortCpuInfoByLogicalID(lsCpu, tmpLst, (end - begin + 1) / 2 + begin, end); - mergeSortCpuInfoByLogicalID(lsCpu, tmpLst, begin, end); - lsCpu = tmpLst; - } -} - void DeviceGenerator::generatorCpuDevice() { // 生成CPU @@ -150,7 +99,7 @@ void DeviceGenerator::generatorCpuDevice() // 按照processor id 从小到大排序 if (lsCpu.size() > 1) - sortCpuInfoByLogicalID(srcLst, tmpLst, 0, lsCpu.size() - 1); + CommonTools::sortCpuInfoByLogicalID(srcLst, tmpLst, 0, lsCpu.size() - 1); // get info from lshw const QList > &lshwCpu = DeviceManager::instance()->cmdInfo("lshw_cpu"); diff --git a/deepin-devicemanager/src/GenerateDevice/HWGenerator.cpp b/deepin-devicemanager/src/GenerateDevice/HWGenerator.cpp index 4a928299..aa97e0b6 100644 --- a/deepin-devicemanager/src/GenerateDevice/HWGenerator.cpp +++ b/deepin-devicemanager/src/GenerateDevice/HWGenerator.cpp @@ -22,6 +22,7 @@ #include "DeviceManager/DeviceBluetooth.h" #include "DeviceManager/DeviceNetwork.h" #include "DeviceManager/DeviceMemory.h" +#include "commonfunction.h" HWGenerator::HWGenerator() { @@ -111,7 +112,9 @@ void HWGenerator::generatorGpuDevice() QStringList items = deviceInfo.split("\n"); QMap mapInfo; - for (QString itemStr : items) { + if(Common::boardVendorType() == "PANGUM900") + mapInfo.insert("Name", "PANGU M900"); + else for (QString itemStr : items) { if (itemStr.contains(":")) continue; QString curItemStr = itemStr.trimmed(); diff --git a/deepin-devicemanager/src/GenerateDevice/M900Generator.cpp b/deepin-devicemanager/src/GenerateDevice/M900Generator.cpp new file mode 100644 index 00000000..449cd5a5 --- /dev/null +++ b/deepin-devicemanager/src/GenerateDevice/M900Generator.cpp @@ -0,0 +1,273 @@ +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +// 项目自身文件 +#include "M900Generator.h" + +#include +#include +#include + +// 其它头文件 +#include "../DeviceManager/DeviceManager.h" +#include "DeviceManager/DeviceNetwork.h" +#include "DeviceManager/DeviceAudio.h" +#include "DeviceManager/DeviceCpu.h" +#include "DeviceManager/DeviceMonitor.h" +#include "commontools.h" +#include "EDIDParser.h" + +#include +#include +#include + + +M900Generator::M900Generator() +{ + +} +/* +:/sys/class/net/wlan0$ ls +addr_assign_type carrier device duplex ifindex name_assign_type phys_port_id proto_down subsystem wireless +address carrier_changes dev_id flags iflink netdev_group phys_port_name queues tx_queue_len +addr_len carrier_down_count dev_port gro_flush_timeout link_mode operstate phys_switch_id speed type +broadcast carrier_up_count dormant ifalias mtu phy80211 power statistics uevent +:/sys/class/net/wlan0$ ls device +class device driver ieee80211 modalias net power subsystem uevent vendor +:/sys/class/net/wlan0$ cat device/vendor +0x024c +uos@uos-PC:/sys/class/net/wlan0$ cat device/device +0xa822 +*/ + +void M900Generator::generatorNetworkDevice() +{ + QStringList ifconfigCardName = getNetworkInfoFromifconfig(); + const QList> lstInfo = DeviceManager::instance()->cmdInfo("lshw_network"); + QList >::const_iterator it = lstInfo.begin(); + for (; it != lstInfo.end(); ++it) { + if ((*it).size() < 2) { + continue; + } + QMap tempMap = *it; + + QString logicalName = tempMap["logical name"].trimmed(); + if (! ifconfigCardName.contains(logicalName)) + continue; + + if (logicalName.contains("wlan0")) { + QFile file("/sys/class/net/wlan0/device/vendor"); + if (file.open(QIODevice::ReadOnly)) { + + QString vendorInfo = file.readAll(); + if (vendorInfo.contains("024c", Qt::CaseInsensitive)) { + tempMap["vendor"] = "Realtek"; + } else if (vendorInfo.contains("12d1", Qt::CaseInsensitive)) { + tempMap["vendor"] = "HiSilicon"; + } + } + } else + tempMap["vendor"] = "HiSilicon"; + + DeviceNetwork *device = new DeviceNetwork(); + device->setInfoFromLshw(tempMap); + device->setCanEnale(false); + device->setCanUninstall(false); + device->setForcedDisplay(true); + DeviceManager::instance()->addNetworkDevice(device); + } +} + +QStringList M900Generator::getNetworkInfoFromifconfig() +{ + //通过ifconfig 判断网络是否valiate + QStringList ret; + QProcess process; + QString cmd = "ifconfig -s"; + process.start(cmd); + QString ifconfigInfo; + bool re = process.waitForFinished(-1); + if (!re) + return ret; + ifconfigInfo = process.readAllStandardOutput(); + //截取查询到的各个网卡连接信息 + QStringList list = ifconfigInfo.split("\n"); + for (int i = 1; i < list.size(); i++) { //skip Iface + //filter "lo" 网卡 + if (list.at(i).contains("lo")) + continue; + + QStringList line = list.at(i).split(" ", QString::SkipEmptyParts); + { + if (line.size() < 2) + continue; + if (line.at(0).isEmpty()) + continue; + else + ret.append(line.at(0)); + } + } + return ret; +} +/* +~$ cat /proc/asound/card0/codec#0 +Name: PANGU M900 Intergrated Audio +Vendor: HUAWEI +Model: PANGU M900 Intergrated Audio + +uos@uos-PC:~$ cat /sys/firmware/devicetree/base/vendor_info/Name +PANGU M900 Intergrated Audio +uos@uos-PC:~$ cat /sys/firmware/devicetree/base/vendor_info/Vendor +HUAWEI +*/ +void M900Generator::getAudioInfoFromCatAudio() /*this is for PAGU M900 special, conflict to master*/ +{ + QMap tempMap; + QFile file_vendor("/sys/firmware/devicetree/base/vendor_info/Vendor"); + if (file_vendor.open(QIODevice::ReadOnly)) { + QString vendorInfo = file_vendor.readAll(); + file_vendor.close(); + if (!vendorInfo.isEmpty()) { + tempMap["Vendor"] = vendorInfo; + } + } + + QFile file_name("/sys/firmware/devicetree/base/vendor_info/Name"); + if (file_name.open(QIODevice::ReadOnly)) { + QString nameInfo = file_name.readAll(); + file_name.close(); + if (!nameInfo.isEmpty()) { + tempMap["Name"] = nameInfo; + } + } + + if (tempMap.contains("Vendor") && tempMap.contains("Name")) { + DeviceAudio *device = new DeviceAudio(); + device->setCanEnale(false); + device->setCanUninstall(false); + device->setForcedDisplay(true); + device->setInfoFromCatAudio(tempMap); + DeviceManager::instance()->addAudioDevice(device); + } +} + +void M900Generator::generatorCpuDevice() /*this is for PAGU M900 special, conflict to master*/ +{ + // 生成CPU + // get info from lscpu + const QList > &lsCpu = DeviceManager::instance()->cmdInfo("lscpu"); + QList > tmpLst; + QList > srcLst; + tmpLst.append(lsCpu); + srcLst.append(lsCpu); + + // 按照processor id 从小到大排序 + if (lsCpu.size() > 1) + CommonTools::sortCpuInfoByLogicalID(srcLst, tmpLst, 0, lsCpu.size() - 1); + + // get info from lshw + const QList > &lshwCpu = DeviceManager::instance()->cmdInfo("lshw_cpu"); + QMap lshw = lshwCpu.size() > 0 ? lshwCpu[0] : QMap(); + lshw["vendor"] = "HiSilicon"; + + // get info from dmidecode -t 4 + const QList > &dmidecode4 = DeviceManager::instance()->cmdInfo("dmidecode4"); + QMap dmidecode = dmidecode4.size() > 0 ? dmidecode4[0] : QMap(); + dmidecode["Manufacturer"] = "HiSilicon"; + + // 获取逻辑数和core数 获取cpu个数 获取logical个数 + int coreNum = 0, logicalNum = 0; + const QList > &lsCpu_num = DeviceManager::instance()->cmdInfo("lscpu_num"); + if (lsCpu_num.size() <= 0) + return; + const QMap &map = lsCpu_num[0]; + if (map.find("core") != map.end()) + coreNum = map["core"].toInt(); + if (map.find("logical") != map.end()) + logicalNum = map["logical"].toInt(); + + // set cpu number + QSet allCPUS; + for (auto dd4 : dmidecode4) { + if (dd4.contains("Socket Designation")) + allCPUS.insert(dd4["Socket Designation"]); + } + DeviceManager::instance()->setCpuNum(allCPUS.isEmpty() ? dmidecode4.size() : allCPUS.size()); + + // set cpu info + QList >::const_iterator it = srcLst.begin(); + for (; it != srcLst.end(); ++it) { + DeviceCpu *device = new DeviceCpu; + device->setCpuInfo(*it, lshw, dmidecode, coreNum, logicalNum); + DeviceManager::instance()->addCpuDevice(device); + } + + DeviceManager::instance()->setCpuFrequencyIsCur(false); +} + +static void parseEDID(QStringList allEDIDS,QString input) +{ + for (auto edid:allEDIDS) { + QProcess process; + process.start(QString("hexdump %1").arg(edid)); + process.waitForFinished(-1); + + QString deviceInfo = process.readAllStandardOutput(); + if(deviceInfo.isEmpty()) + continue; + + QString edidStr; + QStringList lines = deviceInfo.split("\n"); + for (auto line:lines) { + QStringList words = line.trimmed().split(" "); + if(words.size() != 9) + continue; + + words.removeAt(0); + QString l = words.join(""); + l.append("\n"); + edidStr.append(l); + } + + lines = edidStr.split("\n"); + if(lines.size() > 3){ + EDIDParser edidParser; + QString errorMsg; + edidParser.setEdid(edidStr,errorMsg,"\n", false); + + QMap mapInfo; + mapInfo.insert("Vendor",edidParser.vendor()); + mapInfo.insert("Model",edidParser.model()); + mapInfo.insert("Date",edidParser.releaseDate()); + mapInfo.insert("Size",edidParser.screenSize()); + mapInfo.insert("Display Input",input); + + DeviceMonitor *device = new DeviceMonitor(); + device->setInfoFromEdid(mapInfo); + DeviceManager::instance()->addMonitor(device); + } + } +} + +void M900Generator::generatorMonitorDevice() +{ + QString toDir = "/sys/class/drm"; + QDir toDir_(toDir); + + if (!toDir_.exists()) + return; + + QFileInfoList fileInfoList = toDir_.entryInfoList(); + foreach(QFileInfo fileInfo, fileInfoList) { + if(fileInfo.fileName() == "." || fileInfo.fileName() == ".." || !fileInfo.fileName().startsWith("card")) + continue; + + if(QFile::exists(fileInfo.filePath() + "/" + "edid")) { + QStringList allEDIDS_all; + allEDIDS_all.append(fileInfo.filePath() + "/" + "edid"); + QString interface = fileInfo.fileName().remove("card0-").remove("card1-").remove("card2-"); + parseEDID(allEDIDS_all,interface); + } + } +} \ No newline at end of file diff --git a/deepin-devicemanager/src/GenerateDevice/M900Generator.h b/deepin-devicemanager/src/GenerateDevice/M900Generator.h new file mode 100644 index 00000000..17a10445 --- /dev/null +++ b/deepin-devicemanager/src/GenerateDevice/M900Generator.h @@ -0,0 +1,32 @@ +// Copyright (C) 2019 ~ 2020 Uniontech Software Technology Co.,Ltd. +// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#ifndef M900GENERATOR_H +#define M900GENERATOR_H + +#include +#include "HWGenerator.h" +#include "PanguVGenerator.h" + +/** + * @brief The PanguVGenerator class + * 将获取的设备信息生成设备对象,M900 下的生成器 + */ + +class M900Generator : public PanguVGenerator //HWGenerator +{ +public: + M900Generator(); + + +protected: + virtual void generatorNetworkDevice() override; + virtual QStringList getNetworkInfoFromifconfig() override; + virtual void getAudioInfoFromCatAudio() override; /*this is for PAGU M900 special, conflict to master*/ + virtual void generatorCpuDevice() override; /*this is for PAGU M900 special, conflict to master*/ + virtual void generatorMonitorDevice() override; +}; + +#endif // M900GENERATOR_H \ No newline at end of file diff --git a/deepin-devicemanager/src/Tool/EDIDParser.cpp b/deepin-devicemanager/src/Tool/EDIDParser.cpp index b8764113..aa702f73 100644 --- a/deepin-devicemanager/src/Tool/EDIDParser.cpp +++ b/deepin-devicemanager/src/Tool/EDIDParser.cpp @@ -88,6 +88,11 @@ const QString &EDIDParser::vendor()const return m_Vendor; } +const QString &EDIDParser::model()const +{ + return m_Model; +} + const QString &EDIDParser::releaseDate()const { return m_ReleaseDate; @@ -134,6 +139,11 @@ void EDIDParser::parserVendor() m_Vendor = QString(name); + QString h0a = getBytes(0, 10); + QString h0b = getBytes(0, 11); + + m_Model = h0a + h0b; + // // 将16进制的厂商信息转换成二进制的厂商信息 // QString binStr = hexToBin(vendorStr); diff --git a/deepin-devicemanager/src/Tool/EDIDParser.h b/deepin-devicemanager/src/Tool/EDIDParser.h index bc2badcf..0d6fac30 100644 --- a/deepin-devicemanager/src/Tool/EDIDParser.h +++ b/deepin-devicemanager/src/Tool/EDIDParser.h @@ -34,6 +34,12 @@ class EDIDParser */ const QString &vendor()const; + /** + * @brief model:获取厂商信息 + * @return 厂商信息 + */ + const QString &model()const; + /** * @brief releaseDate:获取生产日期 * @return 生产日期 @@ -131,6 +137,7 @@ class EDIDParser private: /**@brief:机器的存储模式不同,会导致计算结果不同,所以在解析的时候需要考虑大小端模式*/ QString m_Vendor; // 显示屏的厂商信息 + QString m_Model; // 显示屏的型号信息 QString m_ReleaseDate; // 显示屏的生产日期 QString m_ScreenSize; // 屏幕大小 bool m_LittleEndianMode; // 小端模式 diff --git a/deepin-devicemanager/src/Tool/commontools.cpp b/deepin-devicemanager/src/Tool/commontools.cpp index cb7cd86c..618ba6da 100644 --- a/deepin-devicemanager/src/Tool/commontools.cpp +++ b/deepin-devicemanager/src/Tool/commontools.cpp @@ -144,3 +144,55 @@ QString CommonTools::getUrl() return "https://drive-pre.uniontech.com/api/v1/drive/search"; } } + +void CommonTools::mergeSortCpuInfoByLogicalID(QList > &lsCpu, QList > &tmpLst, int begin, int end) +{ + // 合并列表 + int left_length = (end - begin + 1) / 2; + int left_index = begin; + int right_index = begin + left_length; + int result_index = begin; + + // 合并左右区间 左区间未合并结束且右区间未合并结束时 + while (left_index < begin + left_length && right_index < end + 1) { + // 左右区间,哪个小先排哪个,下标加1 + if (lsCpu[left_index]["processor"].toInt() <= lsCpu[right_index]["processor"].toInt()) + tmpLst[result_index++] = lsCpu[left_index++]; + else + tmpLst[result_index++] = lsCpu[right_index++]; + } + + // 合并左区间剩余数据 + while (left_index < begin + left_length) + tmpLst[result_index++] = lsCpu[left_index++]; + + // 合并右区间剩余数据 + while (right_index < end + 1) + tmpLst[result_index++] = lsCpu[right_index++]; +} + +void CommonTools::sortCpuInfoByLogicalID(QList > &lsCpu, QList > &tmpLst, int begin, int end) +{ + // 列表个数为1,直接返回 + if (0 == end - begin) + return; + + // bug 后台获取CPU信息是按照物理CPU,核心,逻辑CPU顺序获取的 + // 界面上展示顺序混乱实际是按照物理CPU,核心,逻辑CPU顺序展示 + // 与产品沟通后,按照用户的使用感修改,CPU信息按照逻辑CPU的id从小到大显示 + // 区间个数为2 + if (1 == end - begin) { + // 前 processor > 后 processor 时交换位置 + if (lsCpu[begin]["processor"].toInt() > lsCpu[end]["processor"].toInt()) { + QMap tmpMap = lsCpu[begin]; + lsCpu[begin] = lsCpu[end]; + lsCpu[end] = tmpMap; + } + } else { + // 区间个数 > 2 递归 + sortCpuInfoByLogicalID(lsCpu, tmpLst, begin, (end - begin) / 2 + begin); + sortCpuInfoByLogicalID(lsCpu, tmpLst, (end - begin + 1) / 2 + begin, end); + mergeSortCpuInfoByLogicalID(lsCpu, tmpLst, begin, end); + lsCpu = tmpLst; + } +} diff --git a/deepin-devicemanager/src/Tool/commontools.h b/deepin-devicemanager/src/Tool/commontools.h index b54fb2d9..1c276222 100644 --- a/deepin-devicemanager/src/Tool/commontools.h +++ b/deepin-devicemanager/src/Tool/commontools.h @@ -73,6 +73,19 @@ class CommonTools : public QObject */ static QString getUrl(); + /** + * @brief mergeSortCpuInfoByLogicalID: 获取状态类型类型对应的图标 + * @param lsCpu CPU信息 + * @return + */ + static void mergeSortCpuInfoByLogicalID(QList > &lsCpu, QList > &tmpLst, int begin, int end); + /** + * @brief sortCpuInfoByLogicalID: 依CPU ID排序 + * @param lsCpu CPU信息 + * @return + */ + static void sortCpuInfoByLogicalID(QList > &lsCpu, QList > &tmpLst, int begin, int end); + signals: public slots: diff --git a/deepin-devicemanager/src/commonfunction.cpp b/deepin-devicemanager/src/commonfunction.cpp index 44f7c8f9..c7225179 100644 --- a/deepin-devicemanager/src/commonfunction.cpp +++ b/deepin-devicemanager/src/commonfunction.cpp @@ -93,6 +93,26 @@ static bool isModeW525(void) return ret; } +/* +sudo dmidecode -t 11 | grep -i "String 4" +//PANGUM900 == empty +~/$ sudo dmidecode -t processor | grep -i "Version:" | cut -d ":" -f 2 | tr -d " " +PANGUM900 +*/ +static bool isModePANGUM900(void) +{ + bool ret = false; + QString result1; + QString key1 = "dmidecode_pro"; + QString result2; + QString key2 = "dmidecode_11"; + + if (DBusInterface::getInstance()->getInfo(key1, result1) && DBusInterface::getInstance()->getInfo(key2, result2)) { + ret = result1.contains("PANGU", Qt::CaseInsensitive) && result1.contains("M900", Qt::CaseInsensitive) && !result2.contains("String 4", Qt::CaseInsensitive); + } + return ret;; +} + QString Common::checkBoardVendorFlag() { if(specialComType != -1){ @@ -138,6 +158,10 @@ QString Common::checkBoardVendorFlag() if(boardVendorKey.isEmpty() && (isModeM900() || isModeW525())){ boardVendorKey = "PGUW"; } + + if(isModePANGUM900()) + boardVendorKey = "PANGUM900"; + qInfo() << "boardVendorKey:" << boardVendorKey; } qInfo() << "Current special computer type is " << boardVendorKey;