diff --git a/include/drive.h b/include/drive.h index a4e0771..7e46575 100644 --- a/include/drive.h +++ b/include/drive.h @@ -44,11 +44,13 @@ private: uint32_t u32ErrorCount = 0U; uint32_t u32PowerOnHours = 0U; //in hours uint32_t u32PowerCycles = 0U; + uint32_t u32Temperature = 0U; //in Fahrenheit, just kidding: degree Celsius time_t u32Timestamp = 0U; //unix timestamp for detecting a frozen drive double d32TaskPercentage = 0U; //in percent for Shred (1 to 100) time_t u32TimestampTaskStart = 0U; //unix timestamp for duration of an action time_t u32TaskDuration = 0U; //time needed to complete the task + private: void setTimestamp(); @@ -68,6 +70,7 @@ public: uint32_t getErrorCount(void); uint32_t getPowerOnHours(void); //in hours uint32_t getPowerCycles(void); + uint32_t getTemperature(void); //in Fahrenheit, just kidding: degree Celsius void checkFrozenDrive(void); void setDriveSMARTData( string modelFamily, @@ -76,12 +79,14 @@ public: uint64_t capacity, uint32_t errorCount, uint32_t powerOnHours, - uint32_t powerCycles); + uint32_t powerCycles, + uint32_t temperature); string sCapacityToText(); string sErrorCountToText(); string sPowerOnHoursToText(); string sPowerCyclesToText(); + string sTemperatureToText(); void setTaskPercentage(double d32TaskPercentage); double getTaskPercentage(void); diff --git a/include/smart.h b/include/smart.h index 99e6cca..37890f1 100644 --- a/include/smart.h +++ b/include/smart.h @@ -27,6 +27,7 @@ private: static void parseErrorCount(string sLine); static void parsePowerOnHours(string sLine); static void parsePowerCycle(string sLine); + static void parseTemperature(string sLine); static string modelFamily; static string modelName; @@ -35,6 +36,7 @@ private: static uint32_t errorCount; static uint32_t powerOnHours; static uint32_t powerCycle; + static uint32_t temperature; }; #endif // SMART_H_ \ No newline at end of file diff --git a/include/tui.h b/include/tui.h index 7f122f7..ed37805 100644 --- a/include/tui.h +++ b/include/tui.h @@ -56,7 +56,7 @@ private: static WINDOW *createOverViewWindow( int iXSize, int iYSize); static WINDOW *createDetailViewWindow( int iXSize, int iYSize, int iXStart, Drive drive); static WINDOW *overwriteDetailViewWindow( int iXSize, int iYSize, int iXStart); - static WINDOW *createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, int iListIndex, string sModelFamily, string sSerial, string sCapacity, string sState, string sTime, string sSpeed, bool bSelected); + static WINDOW *createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, int iListIndex, string sModelFamily, string sSerial, string sCapacity, string sState, string sTime, string sSpeed, string sTemp, bool bSelected); static WINDOW *createSystemStats(int iXSize, int iYSize, int iXStart, int iYStart); static WINDOW *createMenuView(int iXSize, int iYSize, int iXStart, int iYStart, struct MenuState menustate); static WINDOW *createDialog(int iXSize, int iYSize, int iXStart, int iYStart, string selectedTask, string optionA, string optionB); diff --git a/src/drive.cpp b/src/drive.cpp index 70006f8..35f90aa 100644 --- a/src/drive.cpp +++ b/src/drive.cpp @@ -46,6 +46,11 @@ uint32_t Drive::getPowerCycles(void) return u32PowerCycles; } +uint32_t Drive::getTemperature(void) +{ + return u32Temperature; +} + string Drive::sCapacityToText() { char acBuffer[16]; @@ -91,6 +96,11 @@ string Drive::sPowerCyclesToText() return to_string(getPowerCycles()); } +string Drive::sTemperatureToText() +{ + return to_string(getTemperature())+" C";; +} + void Drive::setTaskPercentage(double d32TaskPercentage) { if(d32TaskPercentage <= 100) @@ -122,7 +132,8 @@ void Drive::setDriveSMARTData( string modelFamily, uint64_t capacity, uint32_t errorCount, uint32_t powerOnHours, - uint32_t powerCycle) + uint32_t powerCycle, + uint32_t temperature) { this->sModelFamily = modelFamily; sModelName = modelName; @@ -131,6 +142,7 @@ void Drive::setDriveSMARTData( string modelFamily, u32ErrorCount = errorCount; u32PowerOnHours = powerOnHours; u32PowerCycles = powerCycle; + u32Temperature = temperature; } diff --git a/src/smart.cpp b/src/smart.cpp index 1a787af..a19fa67 100644 --- a/src/smart.cpp +++ b/src/smart.cpp @@ -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); + } + } +} diff --git a/src/tui.cpp b/src/tui.cpp index b6c54c5..78ca451 100644 --- a/src/tui.cpp +++ b/src/tui.cpp @@ -74,11 +74,12 @@ void TUI::updateTUI(list * plistDrives, uint8_t u8SelectedEntry) for (it = plistDrives->begin(); it != plistDrives->end(); ++it) { string sModelFamily = it->getModelFamily(); - string sSerial = it->getSerial(); + string sSerial = "SN: " + it->getSerial(); string sCapacity = it->sCapacityToText(); string sState = " "; string sSpeed = " "; string sTime = " "; + string sTemp = it->sTemperatureToText(); bool bSelectedEntry = false; @@ -151,7 +152,7 @@ void TUI::updateTUI(list * plistDrives, uint8_t u8SelectedEntry) break; } - WINDOW * tmp = createEntryWindow( ((int)(u16StdscrX/3) - 2), 5, 3, (5* (u8Index) )+3, (distance(plistDrives->begin(), it)+1), sModelFamily, sSerial, sCapacity, sState, sTime, sSpeed, bSelectedEntry); + WINDOW * tmp = createEntryWindow( ((int)(u16StdscrX/3) - 2), 5, 3, (5* (u8Index) )+3, (distance(plistDrives->begin(), it)+1), sModelFamily, sSerial, sCapacity, sState, sTime, sSpeed, sTemp, bSelectedEntry); wrefresh(tmp); u8Index++; }//end loop though drives @@ -308,7 +309,7 @@ WINDOW* TUI::overwriteDetailViewWindow( int iXSize, int iYSize, int iXStart) return newWindow; } -WINDOW* TUI::createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, int iListIndex, string sModelFamily, string sSerial, string sCapacity, string sState, string sTime, string sSpeed, bool bSelected) +WINDOW* TUI::createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, int iListIndex, string sModelFamily, string sSerial, string sCapacity, string sState, string sTime, string sSpeed, string sTemp, bool bSelected) { WINDOW *newWindow; newWindow = newwin(iYSize, iXSize, iYStart, iXStart); @@ -333,6 +334,7 @@ WINDOW* TUI::createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, mvwaddstr(newWindow,1, 5, sModelFamily.c_str()); mvwaddstr(newWindow,2, 5, sSerial.c_str()); mvwaddstr(newWindow,3, 5, sCapacity.c_str()); + mvwaddstr(newWindow,3, 5+sCapacity.length()+3, sTemp.c_str()); mvwaddstr(newWindow,1, iXSize-sSpeed.length()-5, sSpeed.c_str()); mvwaddstr(newWindow,2, iXSize-sState.length()-5, sState.c_str());