support smartctl usb contoller options
This commit is contained in:
parent
aa7ddf8b36
commit
0ad7de4352
@ -20,6 +20,7 @@ public:
|
||||
private:
|
||||
SMART(void);
|
||||
|
||||
static uint8_t parseExitStatus(string sLine);
|
||||
static void parseModelFamily(string sLine);
|
||||
static void parseModelName(string sLine);
|
||||
static void parseSerial(string sLine);
|
||||
|
@ -32,19 +32,25 @@ void SMART::readSMARTData(Drive* drive)
|
||||
powerCycle = 0U;
|
||||
temperature = 0U;
|
||||
|
||||
size_t len = 0; //lenght of found line
|
||||
char* cLine = NULL; //found line
|
||||
string sSmartctlCommands[] = {" --json -a ", " --json -d sntjmicron -a ", " --json -d sntasmedia -a ", " --json -d sntrealtek -a "};
|
||||
|
||||
string sCMD = ("smartctl --json -a ");
|
||||
for (string sSmartctlCommand : sSmartctlCommands)
|
||||
{
|
||||
string sCMD = ("smartctl");
|
||||
sCMD.append(sSmartctlCommand);
|
||||
sCMD.append(drive->getPath());
|
||||
const char *cpComand = sCMD.c_str();
|
||||
|
||||
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)
|
||||
{
|
||||
string sLine = string(cLine);
|
||||
|
||||
status = SMART::parseExitStatus(sLine);
|
||||
SMART::parseModelFamily(sLine);
|
||||
SMART::parseModelName(sLine);
|
||||
SMART::parseSerial(sLine);
|
||||
@ -54,10 +60,37 @@ void SMART::readSMARTData(Drive* drive)
|
||||
SMART::parsePowerCycle(sLine);
|
||||
SMART::parseTemperature(sLine);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief parse ModelFamiliy
|
||||
* \param string output line of smartctl
|
||||
@ -157,7 +190,6 @@ void SMART::parsePowerOnHours(string sLine)
|
||||
sLine.erase(0, sLine.find(": ") + 2);
|
||||
sLine.erase(sLine.length() - 1, 1);
|
||||
powerOnHours = stol(sLine);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -175,7 +207,6 @@ void SMART::parsePowerCycle(string sLine)
|
||||
sLine.erase(0, sLine.find(": ") + 2);
|
||||
sLine.erase(sLine.length() - 2, 2);
|
||||
powerCycle = stol(sLine);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,7 +225,7 @@ void SMART::parseTemperature(string sLine)
|
||||
sLine.erase(sLine.length() - 1, 2);
|
||||
if (sLine == "{")
|
||||
{
|
||||
temperature = 0U; // this drive doesn't support temperatur
|
||||
temperature = 0U; // this drive doesn't support temperature
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user