support smartctl usb contoller options
This commit is contained in:
parent
aa7ddf8b36
commit
0ad7de4352
@ -20,6 +20,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
SMART(void);
|
SMART(void);
|
||||||
|
|
||||||
|
static uint8_t parseExitStatus(string sLine);
|
||||||
static void parseModelFamily(string sLine);
|
static void parseModelFamily(string sLine);
|
||||||
static void parseModelName(string sLine);
|
static void parseModelName(string sLine);
|
||||||
static void parseSerial(string sLine);
|
static void parseSerial(string sLine);
|
||||||
|
161
src/smart.cpp
161
src/smart.cpp
@ -21,7 +21,7 @@ uint32_t SMART::temperature = 0U;
|
|||||||
* \param pointer of Drive instance
|
* \param pointer of Drive instance
|
||||||
* \return void
|
* \return void
|
||||||
*/
|
*/
|
||||||
void SMART::readSMARTData(Drive* drive)
|
void SMART::readSMARTData(Drive *drive)
|
||||||
{
|
{
|
||||||
modelFamily.clear();
|
modelFamily.clear();
|
||||||
modelName.clear();
|
modelName.clear();
|
||||||
@ -32,19 +32,25 @@ void SMART::readSMARTData(Drive* drive)
|
|||||||
powerCycle = 0U;
|
powerCycle = 0U;
|
||||||
temperature = 0U;
|
temperature = 0U;
|
||||||
|
|
||||||
size_t len = 0; //lenght of found line
|
string sSmartctlCommands[] = {" --json -a ", " --json -d sntjmicron -a ", " --json -d sntasmedia -a ", " --json -d sntrealtek -a "};
|
||||||
char* cLine = NULL; //found line
|
|
||||||
|
|
||||||
string sCMD = ("smartctl --json -a ");
|
for (string sSmartctlCommand : sSmartctlCommands)
|
||||||
sCMD.append(drive->getPath());
|
{
|
||||||
const char* cpComand = sCMD.c_str();
|
string sCMD = ("smartctl");
|
||||||
|
sCMD.append(sSmartctlCommand);
|
||||||
|
sCMD.append(drive->getPath());
|
||||||
|
const char *cpComand = sCMD.c_str();
|
||||||
|
|
||||||
FILE* outputfileSmart = popen(cpComand, "r");
|
FILE *outputfileSmart = popen(cpComand, "r");
|
||||||
|
size_t len = 0; // length of found line
|
||||||
|
char *cLine = NULL; // found line
|
||||||
|
uint8_t status = 255;
|
||||||
|
|
||||||
while ((getline(&cLine, &len, outputfileSmart)) != -1)
|
while ((getline(&cLine, &len, outputfileSmart)) != -1)
|
||||||
{
|
{
|
||||||
string sLine = string(cLine);
|
string sLine = string(cLine);
|
||||||
|
|
||||||
|
status = SMART::parseExitStatus(sLine);
|
||||||
SMART::parseModelFamily(sLine);
|
SMART::parseModelFamily(sLine);
|
||||||
SMART::parseModelName(sLine);
|
SMART::parseModelName(sLine);
|
||||||
SMART::parseSerial(sLine);
|
SMART::parseSerial(sLine);
|
||||||
@ -54,8 +60,35 @@ void SMART::readSMARTData(Drive* drive)
|
|||||||
SMART::parsePowerCycle(sLine);
|
SMART::parsePowerCycle(sLine);
|
||||||
SMART::parseTemperature(sLine);
|
SMART::parseTemperature(sLine);
|
||||||
}
|
}
|
||||||
pclose(outputfileSmart);
|
|
||||||
drive->setDriveSMARTData(modelFamily, modelName, serial, capacity, errorCount, powerOnHours, powerCycle, temperature); //wirte data in drive
|
pclose(outputfileSmart);
|
||||||
|
|
||||||
|
if (status == 0U)
|
||||||
|
{
|
||||||
|
//Found S.M.A.R.T. data with this command
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
drive->setDriveSMARTData(modelFamily, modelName, serial, capacity, errorCount, powerOnHours, powerCycle, temperature); // wirte data in drive
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief parse ExitStatus
|
||||||
|
* \param string output line of smartctl
|
||||||
|
* \return uint_8 exit status
|
||||||
|
*/
|
||||||
|
uint8_t SMART::parseExitStatus(string sLine)
|
||||||
|
{
|
||||||
|
uint8_t exitStatus = -1;
|
||||||
|
string search("\"exit_status\": ");
|
||||||
|
size_t found = sLine.find(search);
|
||||||
|
if (found != string::npos)
|
||||||
|
{
|
||||||
|
sLine.erase(0, sLine.find(": ") + 1);
|
||||||
|
exitStatus = stol(sLine);
|
||||||
|
}
|
||||||
|
return exitStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -67,12 +100,12 @@ void SMART::parseModelFamily(string sLine)
|
|||||||
{
|
{
|
||||||
string search("\"model_family\": ");
|
string search("\"model_family\": ");
|
||||||
size_t found = sLine.find(search);
|
size_t found = sLine.find(search);
|
||||||
if (found!=string::npos)
|
if (found != string::npos)
|
||||||
{
|
{
|
||||||
sLine.erase(0, sLine.find(": ") + 3);
|
sLine.erase(0, sLine.find(": ") + 3);
|
||||||
sLine.erase(sLine.length()-3, 3);
|
sLine.erase(sLine.length() - 3, 3);
|
||||||
modelFamily = sLine;
|
modelFamily = sLine;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -84,12 +117,12 @@ void SMART::parseModelName(string sLine)
|
|||||||
{
|
{
|
||||||
string search("\"model_name\": ");
|
string search("\"model_name\": ");
|
||||||
size_t found = sLine.find(search);
|
size_t found = sLine.find(search);
|
||||||
if (found!=string::npos)
|
if (found != string::npos)
|
||||||
{
|
{
|
||||||
sLine.erase(0, sLine.find(": ") + 3);
|
sLine.erase(0, sLine.find(": ") + 3);
|
||||||
sLine.erase(sLine.length()-3, 3);
|
sLine.erase(sLine.length() - 3, 3);
|
||||||
modelName = sLine;
|
modelName = sLine;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -101,12 +134,12 @@ void SMART::parseSerial(string sLine)
|
|||||||
{
|
{
|
||||||
string search("\"serial_number\": ");
|
string search("\"serial_number\": ");
|
||||||
size_t found = sLine.find(search);
|
size_t found = sLine.find(search);
|
||||||
if (found!=string::npos)
|
if (found != string::npos)
|
||||||
{
|
{
|
||||||
sLine.erase(0, sLine.find(": ") + 3);
|
sLine.erase(0, sLine.find(": ") + 3);
|
||||||
sLine.erase(sLine.length()-3, 3);
|
sLine.erase(sLine.length() - 3, 3);
|
||||||
serial = sLine;
|
serial = sLine;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -118,12 +151,12 @@ void SMART::parseCapacity(string sLine)
|
|||||||
{
|
{
|
||||||
string search("\"bytes\": ");
|
string search("\"bytes\": ");
|
||||||
size_t found = sLine.find(search);
|
size_t found = sLine.find(search);
|
||||||
if (found!=string::npos)
|
if (found != string::npos)
|
||||||
{
|
{
|
||||||
sLine.erase(0, sLine.find(": ") + 2);
|
sLine.erase(0, sLine.find(": ") + 2);
|
||||||
sLine.erase(sLine.length()-1, 1);
|
sLine.erase(sLine.length() - 1, 1);
|
||||||
capacity = stol(sLine);
|
capacity = stol(sLine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -135,12 +168,12 @@ void SMART::parseErrorCount(string sLine)
|
|||||||
{
|
{
|
||||||
string search("\"error_count_total\": ");
|
string search("\"error_count_total\": ");
|
||||||
size_t found = sLine.find(search);
|
size_t found = sLine.find(search);
|
||||||
if (found!=string::npos)
|
if (found != string::npos)
|
||||||
{
|
{
|
||||||
sLine.erase(0, sLine.find(": ")+2);
|
sLine.erase(0, sLine.find(": ") + 2);
|
||||||
sLine.erase(sLine.length()-2, 2);
|
sLine.erase(sLine.length() - 2, 2);
|
||||||
errorCount = stol(sLine);
|
errorCount = stol(sLine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -152,13 +185,12 @@ void SMART::parsePowerOnHours(string sLine)
|
|||||||
{
|
{
|
||||||
string search("\"hours\": ");
|
string search("\"hours\": ");
|
||||||
size_t found = sLine.find(search);
|
size_t found = sLine.find(search);
|
||||||
if (found!=string::npos)
|
if (found != string::npos)
|
||||||
{
|
{
|
||||||
sLine.erase(0, sLine.find(": ") + 2);
|
sLine.erase(0, sLine.find(": ") + 2);
|
||||||
sLine.erase(sLine.length()-1, 1);
|
sLine.erase(sLine.length() - 1, 1);
|
||||||
powerOnHours = stol(sLine);
|
powerOnHours = stol(sLine);
|
||||||
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -170,13 +202,12 @@ void SMART::parsePowerCycle(string sLine)
|
|||||||
{
|
{
|
||||||
string search("\"power_cycle_count\": ");
|
string search("\"power_cycle_count\": ");
|
||||||
size_t found = sLine.find(search);
|
size_t found = sLine.find(search);
|
||||||
if (found!=string::npos)
|
if (found != string::npos)
|
||||||
{
|
{
|
||||||
sLine.erase(0, sLine.find(": ") + 2);
|
sLine.erase(0, sLine.find(": ") + 2);
|
||||||
sLine.erase(sLine.length()-2, 2);
|
sLine.erase(sLine.length() - 2, 2);
|
||||||
powerCycle = stol(sLine);
|
powerCycle = stol(sLine);
|
||||||
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -188,17 +219,17 @@ void SMART::parseTemperature(string sLine)
|
|||||||
{
|
{
|
||||||
string search("\"current\": ");
|
string search("\"current\": ");
|
||||||
size_t found = sLine.find(search);
|
size_t found = sLine.find(search);
|
||||||
if (found!=string::npos)
|
if (found != string::npos)
|
||||||
|
{
|
||||||
|
sLine.erase(0, sLine.find(": ") + 2);
|
||||||
|
sLine.erase(sLine.length() - 1, 2);
|
||||||
|
if (sLine == "{")
|
||||||
{
|
{
|
||||||
sLine.erase(0, sLine.find(": ") + 2);
|
temperature = 0U; // this drive doesn't support temperature
|
||||||
sLine.erase(sLine.length()-1, 2);
|
|
||||||
if(sLine == "{")
|
|
||||||
{
|
|
||||||
temperature = 0U; // this drive doesn't support temperatur
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
temperature = stol(sLine);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
temperature = stol(sLine);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user