read temperature via S.M.A.R.T and display

This commit is contained in:
2022-08-24 16:00:18 +02:00
parent 7dfa805044
commit 2df5ceb0c8
6 changed files with 54 additions and 7 deletions

View File

@ -14,6 +14,7 @@ uint64_t SMART::capacity = 0U;
uint32_t SMART::errorCount = 0U;
uint32_t SMART::powerOnHours = 0U;
uint32_t SMART::powerCycle = 0U;
uint32_t SMART::temperature = 0U;
/**
* \brief get and set S.M.A.R.T. values in Drive
@ -29,6 +30,7 @@ void SMART::readSMARTData(Drive* drive)
errorCount = 0U;
powerOnHours = 0U;
powerCycle = 0U;
temperature = 0U;
size_t len = 0; //lenght of found line
char* cLine = NULL; //found line
@ -50,9 +52,10 @@ void SMART::readSMARTData(Drive* drive)
SMART::parseErrorCount(sLine);
SMART::parsePowerOnHours(sLine);
SMART::parsePowerCycle(sLine);
SMART::parseTemperature(sLine);
}
pclose(outputfileSmart);
drive->setDriveSMARTData(modelFamily, modelName, serial, capacity, errorCount, powerOnHours, powerCycle); //wirte data in drive
drive->setDriveSMARTData(modelFamily, modelName, serial, capacity, errorCount, powerOnHours, powerCycle, temperature); //wirte data in drive
}
/**
@ -176,3 +179,26 @@ void SMART::parsePowerCycle(string sLine)
}
}
/**
* \brief parse temperature
* \param string output line of smartctl
* \return void
*/
void SMART::parseTemperature(string sLine)
{
string search("\"current\": ");
size_t found = sLine.find(search);
if (found!=string::npos)
{
sLine.erase(0, sLine.find(": ") + 2);
sLine.erase(sLine.length()-1, 2);
if(sLine == "{")
{
temperature = 0U; // this drive doesn't support temperatur
}
else
{
temperature = stol(sLine);
}
}
}