Use strongly typed enum for SmartAttributeUnit.

This commit is contained in:
Andrius Štikonas 2018-04-05 23:06:52 +01:00
parent 63cea60ff1
commit 876c037ebf
4 changed files with 205 additions and 211 deletions

View File

@ -27,7 +27,7 @@
static QString getAttrName(qint32 id); static QString getAttrName(qint32 id);
static QString getAttrDescription(qint32 id); static QString getAttrDescription(qint32 id);
static QString getPrettyValue(quint64 value, qint64 unit); static QString getPrettyValue(quint64 value, SmartAttributeUnit unit);
static SmartAttribute::Assessment getAssessment(const SmartAttributeParsedData& a); static SmartAttribute::Assessment getAssessment(const SmartAttributeParsedData& a);
static QString getRaw(quint64 raw); static QString getRaw(quint64 raw);
@ -68,28 +68,28 @@ QString SmartAttribute::assessmentToString(Assessment a)
} }
} }
static QString getPrettyValue(quint64 value, qint64 unit) static QString getPrettyValue(quint64 value, SmartAttributeUnit unit)
{ {
QString rval; QString rval;
switch (unit) { switch (unit) {
case SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_MSECONDS: case SmartAttributeUnit::Miliseconds:
rval = KFormat().formatDuration(value); rval = KFormat().formatDuration(value);
break; break;
case SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_SECTORS: case SmartAttributeUnit::Sectors:
rval = xi18ncp("@item:intable", "%1 sector", "%1 sectors", value); rval = xi18ncp("@item:intable", "%1 sector", "%1 sectors", value);
break; break;
case SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_MKELVIN: case SmartAttributeUnit::Milikelvin:
rval = SmartStatus::tempToString(value); rval = SmartStatus::tempToString(value);
break; break;
case SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE: case SmartAttributeUnit::None:
rval = QLocale().toString(value); rval = QLocale().toString(value);
break; break;
case SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_UNKNOWN: case SmartAttributeUnit::Unknown:
default: default:
rval = xi18nc("@item:intable not applicable", "N/A"); rval = xi18nc("@item:intable not applicable", "N/A");
break; break;

View File

@ -31,8 +31,8 @@
#define MSECOND_VALID_SHORT_MAX (60ULL * 60ULL * 1000ULL) #define MSECOND_VALID_SHORT_MAX (60ULL * 60ULL * 1000ULL)
#define MSECOND_VALID_LONG_MAX (30ULL * 365ULL * 24ULL * 60ULL * 60ULL * 1000ULL) #define MSECOND_VALID_LONG_MAX (30ULL * 365ULL * 24ULL * 60ULL * 60ULL * 1000ULL)
static const QMap<qint32, SmartAttributeParsedData::SmartAttributeUnit> tableUnit(); static QMap<qint32, SmartAttributeUnit> tableUnit();
static SmartAttributeParsedData::SmartQuirk getQuirk(QString model, QString firmware); static SmartQuirk getQuirk(QString model, QString firmware);
/** Creates a new SmartAttributeParsedData object. /** Creates a new SmartAttributeParsedData object.
@param disk the reference to the disk that this attribute is allocated to @param disk the reference to the disk that this attribute is allocated to
@ -56,9 +56,9 @@ SmartAttributeParsedData::SmartAttributeParsedData(SmartDiskInformation *disk,
m_GoodInThePast(true), m_GoodInThePast(true),
m_GoodInThePastValid(false), m_GoodInThePastValid(false),
m_Warn(false), m_Warn(false),
m_PrettyUnit(SMART_ATTRIBUTE_UNIT_UNKNOWN), m_PrettyUnit(SmartAttributeUnit::Unknown),
m_Disk(disk), m_Disk(disk),
m_Quirk((SmartAttributeParsedData::SmartQuirk) 0) m_Quirk(SmartQuirk::None)
{ {
if (disk) if (disk)
m_Quirk = getQuirk(disk->model(), disk->firmware()); m_Quirk = getQuirk(disk->model(), disk->firmware());
@ -88,7 +88,7 @@ SmartAttributeParsedData::SmartAttributeParsedData(SmartDiskInformation *disk,
m_Online = flagsObj[online].toBool(); m_Online = flagsObj[online].toBool();
if (!updateUnit()) if (!updateUnit())
m_PrettyUnit = SMART_ATTRIBUTE_UNIT_UNKNOWN; m_PrettyUnit = SmartAttributeUnit::Unknown;
makePretty(); makePretty();
@ -148,7 +148,7 @@ void SmartAttributeParsedData::validateValues()
/** Make a pretty value from raw based on attribute's id */ /** Make a pretty value from raw based on attribute's id */
void SmartAttributeParsedData::makePretty() void SmartAttributeParsedData::makePretty()
{ {
if (m_PrettyUnit == SMART_ATTRIBUTE_UNIT_UNKNOWN) if (m_PrettyUnit == SmartAttributeUnit::Unknown)
return; return;
switch (id()) { switch (id()) {
@ -230,41 +230,41 @@ void SmartAttributeParsedData::verifyAttribute()
void SmartAttributeParsedData::verifyTemperature() void SmartAttributeParsedData::verifyTemperature()
{ {
if (prettyUnit() != SMART_ATTRIBUTE_UNIT_MKELVIN) if (prettyUnit() != SmartAttributeUnit::Milikelvin)
return; return;
if (prettyValue() < MKELVIN_VALID_MIN || prettyValue() > MKELVIN_VALID_MAX) if (prettyValue() < MKELVIN_VALID_MIN || prettyValue() > MKELVIN_VALID_MAX)
m_PrettyUnit = SMART_ATTRIBUTE_UNIT_UNKNOWN; m_PrettyUnit = SmartAttributeUnit::Unknown;
} }
void SmartAttributeParsedData::verifyShortTime() void SmartAttributeParsedData::verifyShortTime()
{ {
if (prettyUnit() != SMART_ATTRIBUTE_UNIT_MSECONDS) if (prettyUnit() != SmartAttributeUnit::Miliseconds)
return; return;
if (prettyValue() < MSECOND_VALID_MIN || prettyValue() > MSECOND_VALID_SHORT_MAX) if (prettyValue() < MSECOND_VALID_MIN || prettyValue() > MSECOND_VALID_SHORT_MAX)
m_PrettyUnit = SMART_ATTRIBUTE_UNIT_UNKNOWN; m_PrettyUnit = SmartAttributeUnit::Unknown;
} }
void SmartAttributeParsedData::verifyLongTime() void SmartAttributeParsedData::verifyLongTime()
{ {
if (prettyUnit() != SMART_ATTRIBUTE_UNIT_MSECONDS) if (prettyUnit() != SmartAttributeUnit::Miliseconds)
return; return;
if (prettyValue() < MSECOND_VALID_MIN || prettyValue() > MSECOND_VALID_LONG_MAX) if (prettyValue() < MSECOND_VALID_MIN || prettyValue() > MSECOND_VALID_LONG_MAX)
m_PrettyUnit = SMART_ATTRIBUTE_UNIT_UNKNOWN; m_PrettyUnit = SmartAttributeUnit::Unknown;
} }
void SmartAttributeParsedData::verifySectors() void SmartAttributeParsedData::verifySectors()
{ {
if (prettyUnit() != SMART_ATTRIBUTE_UNIT_SECTORS) if (prettyUnit() != SmartAttributeUnit::Sectors)
return; return;
quint64 maxSectors = disk()->size() / 512ULL; quint64 maxSectors = disk()->size() / 512ULL;
if (prettyValue() == 0xFFFFFFFFULL || prettyValue() == 0xFFFFFFFFFFFFULL || (maxSectors > 0 if (prettyValue() == 0xFFFFFFFFULL || prettyValue() == 0xFFFFFFFFFFFFULL || (maxSectors > 0
&& prettyValue() > maxSectors)) && prettyValue() > maxSectors))
m_PrettyUnit = SMART_ATTRIBUTE_UNIT_UNKNOWN; m_PrettyUnit = SmartAttributeUnit::Unknown;
else if ((id() == 5 || id() == 197) && prettyValue() > 0) else if ((id() == 5 || id() == 197) && prettyValue() > 0)
m_Warn = true; m_Warn = true;
} }
@ -274,120 +274,120 @@ bool SmartAttributeParsedData::updateUnit()
if (m_Quirk) { if (m_Quirk) {
switch (id()) { switch (id()) {
case 3: case 3:
if (m_Quirk & SMART_QUIRK_3_UNUSED) { if (m_Quirk & SmartQuirk::SMART_QUIRK_3_UNUSED) {
m_PrettyUnit = SMART_ATTRIBUTE_UNIT_UNKNOWN; m_PrettyUnit = SmartAttributeUnit::Unknown;
return true; return true;
} }
break; break;
case 4: case 4:
if (m_Quirk & SMART_QUIRK_4_UNUSED) { if (m_Quirk & SmartQuirk::SMART_QUIRK_4_UNUSED) {
m_PrettyUnit = SMART_ATTRIBUTE_UNIT_UNKNOWN; m_PrettyUnit = SmartAttributeUnit::Unknown;
return true; return true;
} }
break; break;
case 5: case 5:
if (m_Quirk & SMART_QUIRK_5_UNKNOWN) if (m_Quirk & SmartQuirk::SMART_QUIRK_5_UNKNOWN)
return false; return false;
break; break;
case 9: case 9:
if (m_Quirk & SMART_QUIRK_9_POWERONMINUTES) { if (m_Quirk & SmartQuirk::SMART_QUIRK_9_POWERONMINUTES) {
m_PrettyUnit = SMART_ATTRIBUTE_UNIT_MSECONDS; m_PrettyUnit = SmartAttributeUnit::Miliseconds;
return true; return true;
} else if (m_Quirk & SMART_QUIRK_9_POWERONSECONDS) { } else if (m_Quirk & SmartQuirk::SMART_QUIRK_9_POWERONSECONDS) {
m_PrettyUnit = SMART_ATTRIBUTE_UNIT_MSECONDS; m_PrettyUnit = SmartAttributeUnit::Miliseconds;
return true; return true;
} else if (m_Quirk & SMART_QUIRK_9_POWERONHALFMINUTES) { } else if (m_Quirk & SmartQuirk::SMART_QUIRK_9_POWERONHALFMINUTES) {
m_PrettyUnit = SMART_ATTRIBUTE_UNIT_MSECONDS; m_PrettyUnit = SmartAttributeUnit::Miliseconds;
return true; return true;
} else if (m_Quirk & SMART_QUIRK_9_UNKNOWN) } else if (m_Quirk & SmartQuirk::SMART_QUIRK_9_UNKNOWN)
return false; return false;
break; break;
case 190: case 190:
if (m_Quirk & SMART_QUIRK_190_UNKNOWN) if (m_Quirk & SmartQuirk::SMART_QUIRK_190_UNKNOWN)
return false; return false;
break; break;
case 192: case 192:
if (m_Quirk & SMART_QUIRK_192_EMERGENCYRETRACTCYCLECT) { if (m_Quirk & SmartQuirk::SMART_QUIRK_192_EMERGENCYRETRACTCYCLECT) {
m_PrettyUnit = SMART_ATTRIBUTE_UNIT_NONE; m_PrettyUnit = SmartAttributeUnit::None;
return true; return true;
} }
break; break;
case 194: case 194:
if (m_Quirk & SMART_QUIRK_194_10XCELSIUS) { if (m_Quirk & SmartQuirk::SMART_QUIRK_194_10XCELSIUS) {
m_PrettyUnit = SMART_ATTRIBUTE_UNIT_MKELVIN; m_PrettyUnit = SmartAttributeUnit::Milikelvin;
return true; return true;
} else if (m_Quirk & SMART_QUIRK_194_UNKNOWN) } else if (m_Quirk & SmartQuirk::SMART_QUIRK_194_UNKNOWN)
return false; return false;
break; break;
case 197: case 197:
if (m_Quirk & SMART_QUIRK_197_UNKNOWN) if (m_Quirk & SmartQuirk::SMART_QUIRK_197_UNKNOWN)
return false; return false;
break; break;
case 198: case 198:
if (m_Quirk & SMART_QUIRK_198_UNKNOWN) if (m_Quirk & SmartQuirk::SMART_QUIRK_198_UNKNOWN)
return false; return false;
break; break;
case 200: case 200:
if (m_Quirk & SMART_QUIRK_200_WRITEERRORCOUNT) { if (m_Quirk & SmartQuirk::SMART_QUIRK_200_WRITEERRORCOUNT) {
m_PrettyUnit = SMART_ATTRIBUTE_UNIT_NONE; m_PrettyUnit = SmartAttributeUnit::None;
return true; return true;
} }
break; break;
case 201: case 201:
if (m_Quirk & SMART_QUIRK_201_DETECTEDTACOUNT) { if (m_Quirk & SmartQuirk::SMART_QUIRK_201_DETECTEDTACOUNT) {
m_PrettyUnit = SMART_ATTRIBUTE_UNIT_NONE; m_PrettyUnit = SmartAttributeUnit::None;
return true; return true;
} }
break; break;
case 225: case 225:
if (m_Quirk & SMART_QUIRK_225_TOTALLBASWRITTEN) { if (m_Quirk & SmartQuirk::SMART_QUIRK_225_TOTALLBASWRITTEN) {
m_PrettyUnit = SMART_ATTRIBUTE_UNIT_MB; m_PrettyUnit = SmartAttributeUnit::MB;
return true; return true;
} }
break; break;
case 226: case 226:
if (m_Quirk & SMART_QUIRK_226_TIMEWORKLOADMEDIAWEAR) { if (m_Quirk & SmartQuirk::SMART_QUIRK_226_TIMEWORKLOADMEDIAWEAR) {
m_PrettyUnit = SMART_ATTRIBUTE_UNIT_SMALL_PERCENT; m_PrettyUnit = SmartAttributeUnit::SmallPercent;
return true; return true;
} }
break; break;
case 227: case 227:
if (m_Quirk & SMART_QUIRK_227_TIMEWORKLOADHOSTREADS) { if (m_Quirk & SmartQuirk::SMART_QUIRK_227_TIMEWORKLOADHOSTREADS) {
m_PrettyUnit = SMART_ATTRIBUTE_UNIT_SMALL_PERCENT; m_PrettyUnit = SmartAttributeUnit::SmallPercent;
return true; return true;
} }
break; break;
case 228: case 228:
if (m_Quirk & SMART_QUIRK_228_WORKLOADTIMER) { if (m_Quirk & SmartQuirk::SMART_QUIRK_228_WORKLOADTIMER) {
m_PrettyUnit = SMART_ATTRIBUTE_UNIT_MSECONDS; m_PrettyUnit = SmartAttributeUnit::Miliseconds;
return true; return true;
} }
break; break;
case 232: case 232:
if (m_Quirk & SMART_QUIRK_232_AVAILABLERESERVEDSPACE) { if (m_Quirk & SmartQuirk::SMART_QUIRK_232_AVAILABLERESERVEDSPACE) {
m_PrettyUnit = SMART_ATTRIBUTE_UNIT_PERCENT; m_PrettyUnit = SmartAttributeUnit::Percent;
return true; return true;
} }
break; break;
case 233: case 233:
if (m_Quirk & SMART_QUIRK_233_MEDIAWEAROUTINDICATOR) { if (m_Quirk & SmartQuirk::SMART_QUIRK_233_MEDIAWEAROUTINDICATOR) {
m_PrettyUnit = SMART_ATTRIBUTE_UNIT_PERCENT; m_PrettyUnit = SmartAttributeUnit::Percent;
return true; return true;
} }
break; break;
@ -403,77 +403,77 @@ bool SmartAttributeParsedData::updateUnit()
return false; return false;
} }
static const QMap<qint32, SmartAttributeParsedData::SmartAttributeUnit> tableUnit() static QMap<qint32, SmartAttributeUnit> tableUnit()
{ {
QMap<qint32, SmartAttributeParsedData::SmartAttributeUnit> table; QMap<qint32, SmartAttributeUnit> table;
table.insert(1, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(1, SmartAttributeUnit::None);
table.insert(2, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_UNKNOWN); table.insert(2, SmartAttributeUnit::Unknown);
table.insert(3, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_MSECONDS); table.insert(3, SmartAttributeUnit::Miliseconds);
table.insert(4, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(4, SmartAttributeUnit::None);
table.insert(5, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_SECTORS); table.insert(5, SmartAttributeUnit::Sectors);
table.insert(6, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_UNKNOWN); table.insert(6, SmartAttributeUnit::Unknown);
table.insert(7, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(7, SmartAttributeUnit::None);
table.insert(8, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_UNKNOWN); table.insert(8, SmartAttributeUnit::Unknown);
table.insert(9, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_MSECONDS); table.insert(9, SmartAttributeUnit::Miliseconds);
table.insert(10, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(10, SmartAttributeUnit::None);
table.insert(11, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(11, SmartAttributeUnit::None);
table.insert(12, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(12, SmartAttributeUnit::None);
table.insert(13, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(13, SmartAttributeUnit::None);
table.insert(170, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_PERCENT); table.insert(170, SmartAttributeUnit::Percent);
table.insert(171, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(171, SmartAttributeUnit::None);
table.insert(172, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(172, SmartAttributeUnit::None);
table.insert(175, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(175, SmartAttributeUnit::None);
table.insert(176, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(176, SmartAttributeUnit::None);
table.insert(177, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(177, SmartAttributeUnit::None);
table.insert(178, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(178, SmartAttributeUnit::None);
table.insert(179, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(179, SmartAttributeUnit::None);
table.insert(180, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(180, SmartAttributeUnit::None);
table.insert(181, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(181, SmartAttributeUnit::None);
table.insert(182, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(182, SmartAttributeUnit::None);
table.insert(183, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(183, SmartAttributeUnit::None);
table.insert(184, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(184, SmartAttributeUnit::None);
table.insert(187, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_SECTORS); table.insert(187, SmartAttributeUnit::Sectors);
table.insert(188, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(188, SmartAttributeUnit::None);
table.insert(189, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(189, SmartAttributeUnit::None);
table.insert(190, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_MKELVIN); table.insert(190, SmartAttributeUnit::Milikelvin);
table.insert(191, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(191, SmartAttributeUnit::None);
table.insert(192, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(192, SmartAttributeUnit::None);
table.insert(193, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(193, SmartAttributeUnit::None);
table.insert(194, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_MKELVIN); table.insert(194, SmartAttributeUnit::Milikelvin);
table.insert(195, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(195, SmartAttributeUnit::None);
table.insert(196, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(196, SmartAttributeUnit::None);
table.insert(197, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_SECTORS); table.insert(197, SmartAttributeUnit::Sectors);
table.insert(198, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_SECTORS); table.insert(198, SmartAttributeUnit::Sectors);
table.insert(199, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(199, SmartAttributeUnit::None);
table.insert(200, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(200, SmartAttributeUnit::None);
table.insert(201, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(201, SmartAttributeUnit::None);
table.insert(202, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(202, SmartAttributeUnit::None);
table.insert(203, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_UNKNOWN); table.insert(203, SmartAttributeUnit::Unknown);
table.insert(204, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(204, SmartAttributeUnit::None);
table.insert(205, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(205, SmartAttributeUnit::None);
table.insert(206, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_UNKNOWN); table.insert(206, SmartAttributeUnit::Unknown);
table.insert(207, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_UNKNOWN); table.insert(207, SmartAttributeUnit::Unknown);
table.insert(208, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_UNKNOWN); table.insert(208, SmartAttributeUnit::Unknown);
table.insert(209, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_UNKNOWN); table.insert(209, SmartAttributeUnit::Unknown);
table.insert(220, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_UNKNOWN); table.insert(220, SmartAttributeUnit::Unknown);
table.insert(221, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(221, SmartAttributeUnit::None);
table.insert(222, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_MSECONDS); table.insert(222, SmartAttributeUnit::Miliseconds);
table.insert(223, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(223, SmartAttributeUnit::None);
table.insert(224, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_UNKNOWN); table.insert(224, SmartAttributeUnit::Unknown);
table.insert(225, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(225, SmartAttributeUnit::None);
table.insert(226, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_MSECONDS); table.insert(226, SmartAttributeUnit::Miliseconds);
table.insert(227, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(227, SmartAttributeUnit::None);
table.insert(228, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(228, SmartAttributeUnit::None);
table.insert(230, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_UNKNOWN); table.insert(230, SmartAttributeUnit::Unknown);
table.insert(231, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_MKELVIN); table.insert(231, SmartAttributeUnit::Milikelvin);
table.insert(232, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_PERCENT); table.insert(232, SmartAttributeUnit::Percent);
table.insert(233, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_UNKNOWN); table.insert(233, SmartAttributeUnit::Unknown);
table.insert(234, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_SECTORS); table.insert(234, SmartAttributeUnit::Sectors);
table.insert(235, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_UNKNOWN); table.insert(235, SmartAttributeUnit::Unknown);
table.insert(240, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_MSECONDS); table.insert(240, SmartAttributeUnit::Miliseconds);
table.insert(241, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_MB); table.insert(241, SmartAttributeUnit::MB);
table.insert(242, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_MB); table.insert(242, SmartAttributeUnit::MB);
table.insert(250, SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE); table.insert(250, SmartAttributeUnit::None);
return table; return table;
} }
@ -485,20 +485,20 @@ static const QVector<SmartAttributeParsedData::SmartQuirkDataBase> quirkDatabase
QVector<QuirkDatabase> quirkDb; QVector<QuirkDatabase> quirkDb;
quirkDb << QuirkDatabase(QStringLiteral("^(FUJITSU MHY2120BH|FUJITSU MHY2250BH)$"), QStringLiteral("^0085000B$"), quirkDb << QuirkDatabase(QStringLiteral("^(FUJITSU MHY2120BH|FUJITSU MHY2250BH)$"), QStringLiteral("^0085000B$"),
(SmartAttributeParsedData::SmartQuirk) (SmartAttributeParsedData::SMART_QUIRK_9_POWERONMINUTES | static_cast<SmartQuirk>(SmartQuirk::SMART_QUIRK_9_POWERONMINUTES |
SmartAttributeParsedData::SMART_QUIRK_197_UNKNOWN | SmartQuirk::SMART_QUIRK_197_UNKNOWN |
SmartAttributeParsedData::SMART_QUIRK_198_UNKNOWN)); SmartQuirk::SMART_QUIRK_198_UNKNOWN));
quirkDb << QuirkDatabase(QStringLiteral("^FUJITSU MHR2040AT$"), QStringLiteral(), quirkDb << QuirkDatabase(QStringLiteral("^FUJITSU MHR2040AT$"), QStringLiteral(),
(SmartAttributeParsedData::SmartQuirk) (SmartAttributeParsedData::SMART_QUIRK_9_POWERONSECONDS | static_cast<SmartQuirk>(SmartQuirk::SMART_QUIRK_9_POWERONSECONDS |
SmartAttributeParsedData::SMART_QUIRK_192_EMERGENCYRETRACTCYCLECT | SmartQuirk::SMART_QUIRK_192_EMERGENCYRETRACTCYCLECT |
SmartAttributeParsedData::SMART_QUIRK_200_WRITEERRORCOUNT)); SmartQuirk::SMART_QUIRK_200_WRITEERRORCOUNT));
quirkDb << QuirkDatabase(QStringLiteral("^FUJITSU MHS20[6432]0AT( .)?$"), QStringLiteral(), quirkDb << QuirkDatabase(QStringLiteral("^FUJITSU MHS20[6432]0AT( .)?$"), QStringLiteral(),
(SmartAttributeParsedData::SmartQuirk) (SmartAttributeParsedData::SMART_QUIRK_9_POWERONSECONDS | static_cast<SmartQuirk>(SmartQuirk::SMART_QUIRK_9_POWERONSECONDS |
SmartAttributeParsedData::SMART_QUIRK_192_EMERGENCYRETRACTCYCLECT | SmartQuirk::SMART_QUIRK_192_EMERGENCYRETRACTCYCLECT |
SmartAttributeParsedData::SMART_QUIRK_200_WRITEERRORCOUNT | SmartQuirk::SMART_QUIRK_200_WRITEERRORCOUNT |
SmartAttributeParsedData::SMART_QUIRK_201_DETECTEDTACOUNT)); SmartQuirk::SMART_QUIRK_201_DETECTEDTACOUNT));
quirkDb << QuirkDatabase(QStringLiteral("^(" quirkDb << QuirkDatabase(QStringLiteral("^("
"FUJITSU M1623TAU|" "FUJITSU M1623TAU|"
@ -516,34 +516,33 @@ static const QVector<SmartAttributeParsedData::SmartQuirkDataBase> quirkDatabase
"FUJITSU MP[A-G]3...A[HTEV]U?.*" "FUJITSU MP[A-G]3...A[HTEV]U?.*"
")$"), ")$"),
QStringLiteral(), QStringLiteral(),
SmartAttributeParsedData::SMART_QUIRK_9_POWERONSECONDS); SmartQuirk::SMART_QUIRK_9_POWERONSECONDS);
quirkDb << QuirkDatabase(QStringLiteral("^(" quirkDb << QuirkDatabase(QStringLiteral("^("
"SAMSUNG SV4012H|" "SAMSUNG SV4012H|"
"SAMSUNG SP(0451|08[0124]2|12[0145]3|16[0145]4)[CN]" "SAMSUNG SP(0451|08[0124]2|12[0145]3|16[0145]4)[CN]"
")$"), ")$"),
QStringLiteral(), QStringLiteral(),
SmartAttributeParsedData::SMART_QUIRK_9_POWERONHALFMINUTES); SmartQuirk::SMART_QUIRK_9_POWERONHALFMINUTES);
quirkDb << QuirkDatabase(QStringLiteral("^(" quirkDb << QuirkDatabase(QStringLiteral("^("
"SAMSUNG SV0412H|" "SAMSUNG SV0412H|"
"SAMSUNG SV1204H" "SAMSUNG SV1204H"
")$"), ")$"),
QStringLiteral(), QStringLiteral(),
(SmartAttributeParsedData::SmartQuirk) (SmartAttributeParsedData::SMART_QUIRK_9_POWERONHALFMINUTES | static_cast<SmartQuirk>(SmartQuirk::SMART_QUIRK_9_POWERONHALFMINUTES | SmartQuirk::SMART_QUIRK_194_10XCELSIUS));
SmartAttributeParsedData::SMART_QUIRK_194_10XCELSIUS));
quirkDb << QuirkDatabase(QStringLiteral("^SAMSUNG SP40A2H$"), quirkDb << QuirkDatabase(QStringLiteral("^SAMSUNG SP40A2H$"),
QStringLiteral("^RR100-07$"), QStringLiteral("^RR100-07$"),
SmartAttributeParsedData::SMART_QUIRK_9_POWERONHALFMINUTES); SmartQuirk::SMART_QUIRK_9_POWERONHALFMINUTES);
quirkDb << QuirkDatabase(QStringLiteral("^SAMSUNG SP80A4H$"), quirkDb << QuirkDatabase(QStringLiteral("^SAMSUNG SP80A4H$"),
QStringLiteral("^RT100-06$"), QStringLiteral("^RT100-06$"),
SmartAttributeParsedData::SMART_QUIRK_9_POWERONHALFMINUTES); SmartQuirk::SMART_QUIRK_9_POWERONHALFMINUTES);
quirkDb << QuirkDatabase(QStringLiteral("^SAMSUNG SP8004H$"), quirkDb << QuirkDatabase(QStringLiteral("^SAMSUNG SP8004H$"),
QStringLiteral("^QW100-61$"), QStringLiteral("^QW100-61$"),
SmartAttributeParsedData::SMART_QUIRK_9_POWERONHALFMINUTES); SmartQuirk::SMART_QUIRK_9_POWERONHALFMINUTES);
quirkDb << QuirkDatabase(QStringLiteral("^(" quirkDb << QuirkDatabase(QStringLiteral("^("
"Maxtor 2B0(0[468]|1[05]|20)H1|" "Maxtor 2B0(0[468]|1[05]|20)H1|"
@ -551,8 +550,7 @@ static const QVector<SmartAttributeParsedData::SmartQuirkDataBase> quirkDatabase
"Maxtor 4D0(20H1|40H2|60H3|80H4)" "Maxtor 4D0(20H1|40H2|60H3|80H4)"
")$"), ")$"),
QStringLiteral(), QStringLiteral(),
(SmartAttributeParsedData::SmartQuirk) (SmartAttributeParsedData::SMART_QUIRK_9_POWERONMINUTES | static_cast<SmartQuirk>(SmartQuirk::SMART_QUIRK_9_POWERONMINUTES | SmartQuirk::SMART_QUIRK_194_UNKNOWN));
SmartAttributeParsedData::SMART_QUIRK_194_UNKNOWN));
quirkDb << QuirkDatabase(QStringLiteral("^(" quirkDb << QuirkDatabase(QStringLiteral("^("
"Maxtor 2F0[234]0[JL]0|" "Maxtor 2F0[234]0[JL]0|"
@ -585,7 +583,7 @@ static const QVector<SmartAttributeParsedData::SmartQuirkDataBase> quirkDatabase
"Maxtor 7L(25|30)0[SR]0" "Maxtor 7L(25|30)0[SR]0"
")$"), ")$"),
QStringLiteral(), QStringLiteral(),
SmartAttributeParsedData::SMART_QUIRK_9_POWERONMINUTES); SmartQuirk::SMART_QUIRK_9_POWERONMINUTES);
quirkDb << QuirkDatabase(QStringLiteral("^(" quirkDb << QuirkDatabase(QStringLiteral("^("
"HITACHI_DK14FA-20B|" "HITACHI_DK14FA-20B|"
@ -595,34 +593,31 @@ static const QVector<SmartAttributeParsedData::SmartQuirkDataBase> quirkDatabase
"HTC4260[23]0G5CE00|HTC4260[56]0G8CE00" "HTC4260[23]0G5CE00|HTC4260[56]0G8CE00"
")$"), ")$"),
QStringLiteral(), QStringLiteral(),
(SmartAttributeParsedData::SmartQuirk) (SmartAttributeParsedData::SMART_QUIRK_9_POWERONMINUTES | static_cast<SmartQuirk>(SmartQuirk::SMART_QUIRK_9_POWERONMINUTES | SmartQuirk::SMART_QUIRK_193_LOADUNLOAD));
SmartAttributeParsedData::SMART_QUIRK_193_LOADUNLOAD));
quirkDb << QuirkDatabase(QStringLiteral("^HTS541010G9SA00$"), quirkDb << QuirkDatabase(QStringLiteral("^HTS541010G9SA00$"),
QStringLiteral("^MBZOC60P$"), QStringLiteral("^MBZOC60P$"),
SmartAttributeParsedData::SMART_QUIRK_5_UNKNOWN); SmartQuirk::SMART_QUIRK_5_UNKNOWN);
quirkDb << QuirkDatabase(QStringLiteral("^MCCOE64GEMPP$"), quirkDb << QuirkDatabase(QStringLiteral("^MCCOE64GEMPP$"),
QStringLiteral("^2.9.0[3-9]$"), QStringLiteral("^2.9.0[3-9]$"),
(SmartAttributeParsedData::SmartQuirk) (SmartAttributeParsedData::SMART_QUIRK_5_UNKNOWN | static_cast<SmartQuirk>(SmartQuirk::SMART_QUIRK_5_UNKNOWN | SmartQuirk::SMART_QUIRK_190_UNKNOWN));
SmartAttributeParsedData::SMART_QUIRK_190_UNKNOWN));
quirkDb << QuirkDatabase(QStringLiteral("^INTEL SSDSA2(CT|BT|CW|BW)[0-9]{3}G3.*$"), quirkDb << QuirkDatabase(QStringLiteral("^INTEL SSDSA2(CT|BT|CW|BW)[0-9]{3}G3.*$"),
QStringLiteral(), QStringLiteral(),
(SmartAttributeParsedData::SmartQuirk) static_cast<SmartQuirk>(SmartQuirk::SMART_QUIRK_3_UNUSED |
(SmartAttributeParsedData::SMART_QUIRK_3_UNUSED | SmartQuirk::SMART_QUIRK_4_UNUSED |
SmartAttributeParsedData::SMART_QUIRK_4_UNUSED | SmartQuirk::SMART_QUIRK_225_TOTALLBASWRITTEN |
SmartAttributeParsedData::SMART_QUIRK_225_TOTALLBASWRITTEN | SmartQuirk::SMART_QUIRK_226_TIMEWORKLOADMEDIAWEAR |
SmartAttributeParsedData::SMART_QUIRK_226_TIMEWORKLOADMEDIAWEAR | SmartQuirk::SMART_QUIRK_227_TIMEWORKLOADHOSTREADS |
SmartAttributeParsedData::SMART_QUIRK_227_TIMEWORKLOADHOSTREADS | SmartQuirk::SMART_QUIRK_228_WORKLOADTIMER |
SmartAttributeParsedData::SMART_QUIRK_228_WORKLOADTIMER | SmartQuirk::SMART_QUIRK_232_AVAILABLERESERVEDSPACE |
SmartAttributeParsedData::SMART_QUIRK_232_AVAILABLERESERVEDSPACE | SmartQuirk::SMART_QUIRK_233_MEDIAWEAROUTINDICATOR));
SmartAttributeParsedData::SMART_QUIRK_233_MEDIAWEAROUTINDICATOR));
return quirkDb; return quirkDb;
} }
static SmartAttributeParsedData::SmartQuirk getQuirk(QString model, QString firmware) static SmartQuirk getQuirk(QString model, QString firmware)
{ {
const QVector<SmartAttributeParsedData::SmartQuirkDataBase> db = quirkDatabase(); const QVector<SmartAttributeParsedData::SmartQuirkDataBase> db = quirkDatabase();
@ -645,5 +640,5 @@ static SmartAttributeParsedData::SmartQuirk getQuirk(QString model, QString firm
return item.quirk; return item.quirk;
} }
return (SmartAttributeParsedData::SmartQuirk) 0; return SmartQuirk::None;
} }

View File

@ -23,6 +23,45 @@
class SmartDiskInformation; class SmartDiskInformation;
/** SMART Quirk */
enum SmartQuirk {
None = 0x000000,
SMART_QUIRK_9_POWERONMINUTES = 0x000001,
SMART_QUIRK_9_POWERONSECONDS = 0x000002,
SMART_QUIRK_9_POWERONHALFMINUTES = 0x000004,
SMART_QUIRK_192_EMERGENCYRETRACTCYCLECT = 0x000008,
SMART_QUIRK_193_LOADUNLOAD = 0x000010,
SMART_QUIRK_194_10XCELSIUS = 0x000020,
SMART_QUIRK_194_UNKNOWN = 0x000040,
SMART_QUIRK_200_WRITEERRORCOUNT = 0x000080,
SMART_QUIRK_201_DETECTEDTACOUNT = 0x000100,
SMART_QUIRK_5_UNKNOWN = 0x000200,
SMART_QUIRK_9_UNKNOWN = 0x000400,
SMART_QUIRK_197_UNKNOWN = 0x000800,
SMART_QUIRK_198_UNKNOWN = 0x001000,
SMART_QUIRK_190_UNKNOWN = 0x002000,
SMART_QUIRK_232_AVAILABLERESERVEDSPACE = 0x004000,
SMART_QUIRK_233_MEDIAWEAROUTINDICATOR = 0x008000,
SMART_QUIRK_225_TOTALLBASWRITTEN = 0x010000,
SMART_QUIRK_4_UNUSED = 0x020000,
SMART_QUIRK_226_TIMEWORKLOADMEDIAWEAR = 0x040000,
SMART_QUIRK_227_TIMEWORKLOADHOSTREADS = 0x080000,
SMART_QUIRK_228_WORKLOADTIMER = 0x100000,
SMART_QUIRK_3_UNUSED = 0x200000,
};
/** A unit for SMART attributes */
enum class SmartAttributeUnit {
Unknown,
None,
Miliseconds,
Sectors,
Milikelvin,
SmallPercent, /* percentage with 3 decimal points */
Percent,
MB,
};
/** A SMART parsed attribute. /** A SMART parsed attribute.
It receives the attribute data from JSON, retrieve its data and validates its values. It receives the attribute data from JSON, retrieve its data and validates its values.
@ -32,55 +71,15 @@ class SmartDiskInformation;
class SmartAttributeParsedData class SmartAttributeParsedData
{ {
public: public:
/** A unit for SMART attributes */
enum SmartAttributeUnit {
SMART_ATTRIBUTE_UNIT_UNKNOWN,
SMART_ATTRIBUTE_UNIT_NONE,
SMART_ATTRIBUTE_UNIT_MSECONDS,
SMART_ATTRIBUTE_UNIT_SECTORS,
SMART_ATTRIBUTE_UNIT_MKELVIN,
SMART_ATTRIBUTE_UNIT_SMALL_PERCENT,
SMART_ATTRIBUTE_UNIT_PERCENT,
SMART_ATTRIBUTE_UNIT_MB,
_SMART_ATTRIBUTE_UNIT_MAX
};
/** SMART Quirk */
enum SmartQuirk {
SMART_QUIRK_9_POWERONMINUTES = 0x000001,
SMART_QUIRK_9_POWERONSECONDS = 0x000002,
SMART_QUIRK_9_POWERONHALFMINUTES = 0x000004,
SMART_QUIRK_192_EMERGENCYRETRACTCYCLECT = 0x000008,
SMART_QUIRK_193_LOADUNLOAD = 0x000010,
SMART_QUIRK_194_10XCELSIUS = 0x000020,
SMART_QUIRK_194_UNKNOWN = 0x000040,
SMART_QUIRK_200_WRITEERRORCOUNT = 0x000080,
SMART_QUIRK_201_DETECTEDTACOUNT = 0x000100,
SMART_QUIRK_5_UNKNOWN = 0x000200,
SMART_QUIRK_9_UNKNOWN = 0x000400,
SMART_QUIRK_197_UNKNOWN = 0x000800,
SMART_QUIRK_198_UNKNOWN = 0x001000,
SMART_QUIRK_190_UNKNOWN = 0x002000,
SMART_QUIRK_232_AVAILABLERESERVEDSPACE = 0x004000,
SMART_QUIRK_233_MEDIAWEAROUTINDICATOR = 0x008000,
SMART_QUIRK_225_TOTALLBASWRITTEN = 0x010000,
SMART_QUIRK_4_UNUSED = 0x020000,
SMART_QUIRK_226_TIMEWORKLOADMEDIAWEAR = 0x040000,
SMART_QUIRK_227_TIMEWORKLOADHOSTREADS = 0x080000,
SMART_QUIRK_228_WORKLOADTIMER = 0x100000,
SMART_QUIRK_3_UNUSED = 0x200000
};
/** SMART Quirk to some particular model and firmware */ /** SMART Quirk to some particular model and firmware */
struct SmartQuirkDataBase { struct SmartQuirkDataBase {
QString model; QString model;
QString firmware; QString firmware;
SmartAttributeParsedData::SmartQuirk quirk; SmartQuirk quirk;
SmartQuirkDataBase(const QString &m = QString(), SmartQuirkDataBase(const QString &m = QString(),
const QString &f = QString(), const QString &f = QString(),
SmartAttributeParsedData::SmartQuirk q = (SmartAttributeParsedData::SmartQuirk) 0) : SmartQuirk q = SmartQuirk::None) :
model(m), model(m),
firmware(f), firmware(f),
quirk(q) quirk(q)

View File

@ -108,16 +108,16 @@ bool SmartDiskInformation::updateTemperature()
airflowTemperatureCelsius = findAttribute(190); airflowTemperatureCelsius = findAttribute(190);
if (temperatureCelsius != nullptr if (temperatureCelsius != nullptr
&& temperatureCelsius->prettyUnit() == SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_MKELVIN) { && temperatureCelsius->prettyUnit() == SmartAttributeUnit::Milikelvin) {
m_Temperature = temperatureCelsius->prettyValue(); m_Temperature = temperatureCelsius->prettyValue();
return true; return true;
} else if (temperatureCelsius2 != nullptr } else if (temperatureCelsius2 != nullptr
&& temperatureCelsius2->prettyUnit() == SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_MKELVIN) { && temperatureCelsius2->prettyUnit() == SmartAttributeUnit::Milikelvin) {
m_Temperature = temperatureCelsius2->prettyValue(); m_Temperature = temperatureCelsius2->prettyValue();
return true; return true;
} else if (airflowTemperatureCelsius != nullptr } else if (airflowTemperatureCelsius != nullptr
&& airflowTemperatureCelsius->prettyUnit() == && airflowTemperatureCelsius->prettyUnit() ==
SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_MKELVIN) { SmartAttributeUnit::Milikelvin) {
m_Temperature = airflowTemperatureCelsius->prettyValue(); m_Temperature = airflowTemperatureCelsius->prettyValue();
return true; return true;
} }
@ -136,11 +136,11 @@ bool SmartDiskInformation::updatePowerOn()
powerOnSeconds = findAttribute(233); powerOnSeconds = findAttribute(233);
if (powerOnHours != nullptr if (powerOnHours != nullptr
&& powerOnHours->prettyUnit() == SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_MSECONDS) { && powerOnHours->prettyUnit() == SmartAttributeUnit::Miliseconds) {
m_PoweredOn = powerOnHours->prettyValue(); m_PoweredOn = powerOnHours->prettyValue();
return true; return true;
} else if (powerOnSeconds != nullptr } else if (powerOnSeconds != nullptr
&& powerOnSeconds->prettyUnit() == SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_MSECONDS) { && powerOnSeconds->prettyUnit() == SmartAttributeUnit::Miliseconds) {
m_PoweredOn = powerOnSeconds->prettyValue(); m_PoweredOn = powerOnSeconds->prettyValue();
return true; return true;
} }
@ -157,7 +157,7 @@ bool SmartDiskInformation::updatePowerCycle()
powerCycleCount = findAttribute(12); powerCycleCount = findAttribute(12);
if (powerCycleCount != nullptr if (powerCycleCount != nullptr
&& powerCycleCount->prettyUnit() == SmartAttributeParsedData::SMART_ATTRIBUTE_UNIT_NONE) { && powerCycleCount->prettyUnit() == SmartAttributeUnit::None) {
m_PowerCycles = powerCycleCount->prettyValue(); m_PowerCycles = powerCycleCount->prettyValue();
return true; return true;
} }