From d3593531ecd7fb0c046f2ab351c4b35b37c6b56e Mon Sep 17 00:00:00 2001 From: Spiros Date: Sat, 3 Aug 2024 03:23:22 +0300 Subject: [PATCH] Read SCSI power on count --- src/mainwindow.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 7fbcec4..207dd4a 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -341,6 +341,7 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal QString firmwareVersion = localObj["firmware_version"].toString(); double diskCapacityGB = localObj.value("user_capacity").toObject().value("bytes").toDouble() / 1e9; int diskCapacityGbInt = static_cast(diskCapacityGB); + int powerCycleCountInt = localObj["power_cycle_count"].toInt(-1); int temperatureInt = localObj["temperature"].toObject()["current"].toInt(); int totalWritesInt = 0; int totalReadsInt = 0; @@ -360,12 +361,7 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal QString percentage = ""; QString serialNumber = localObj["serial_number"].toString(); QJsonObject deviceObj = localObj["device"].toObject(); - QString protocol = deviceObj["protocol"].toString(); - if (protocol == "SCSI") { - modelName = localObj["scsi_model_name"].toString(); - } - QString type = deviceObj["type"].toString(); QString name = deviceObj["name"].toString(); QJsonArray outputArray = localObj.value("smartctl").toObject()["output"].toArray(); @@ -374,6 +370,13 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal QJsonArray ataSelfTestsTable = localObj["ata_smart_self_test_log"].toObject()["standard"].toObject()["table"].toArray(); bool isNvme = (protocol == "NVMe"); + bool isScsi = (protocol == "SCSI"); + + if (isScsi) { + modelName = localObj["scsi_model_name"].toString(); + powerCycleCountInt = localObj["scsi_start_stop_cycle_counter"].toObject().value("accumulated_load_unload_cycles").toInt(-1); + } + bool nvmeHasSelfTest = false; auto createTablePopup = [=](QJsonArray selfTestsTable) { @@ -466,7 +469,6 @@ void MainWindow::populateWindow(const QJsonObject &localObj, const QString &heal rotationRateLineEdit->setText(rotationRate); rotationRateLineEdit->setAlignment(Qt::AlignRight); - int powerCycleCountInt = localObj["power_cycle_count"].toInt(-1); QString powerCycleCount; if (powerCycleCountInt >= 0) { powerCycleCount = QString::number(powerCycleCountInt) + " " + tr("count");