fix parsing and set dev version

This commit is contained in:
2026-05-01 15:01:49 +02:00
parent 203b4a0c85
commit 753dde833f
2 changed files with 69 additions and 63 deletions
+2 -2
View File
@@ -8,7 +8,7 @@
#ifndef REHDD_H_ #ifndef REHDD_H_
#define REHDD_H_ #define REHDD_H_
#define REHDD_VERSION "V1.3.1" #define REHDD_VERSION "V1.4.0-dev"
// Drive handling Settings // Drive handling Settings
#define WORSE_HOURS 19200 // mark drive if at this limit or beyond #define WORSE_HOURS 19200 // mark drive if at this limit or beyond
@@ -20,7 +20,7 @@
// Logger Settings // Logger Settings
#define LOG_PATH "./reHDD.log" #define LOG_PATH "./reHDD.log"
#define DESCRIPTION "reHDD - Copyright Hendrik Schutter 2025" #define DESCRIPTION "reHDD - Copyright Hendrik Schutter 2026"
#define DEVICE_ID "generic" #define DEVICE_ID "generic"
#define SOFTWARE_VERSION REHDD_VERSION #define SOFTWARE_VERSION REHDD_VERSION
#define HARDWARE_VERSION "generic" #define HARDWARE_VERSION "generic"
+24 -18
View File
@@ -34,11 +34,11 @@ struct SMARTParseContext
// Parser state machine // Parser state machine
enum State enum State
{ {
SEARCHING, // Looking for next field SEARCHING, // Looking for next field
IN_ATTRIBUTE_5, // Inside ID 5 object IN_ATTRIBUTE_5, // Inside ID 5 object
IN_ATTRIBUTE_197, // Inside ID 197 object IN_ATTRIBUTE_197, // Inside ID 197 object
IN_ATTRIBUTE_198, // Inside ID 198 object IN_ATTRIBUTE_198, // Inside ID 198 object
IN_RAW_SECTION // Inside "raw": { } of current attribute IN_RAW_SECTION // Inside "raw": { } of current attribute
}; };
State state; State state;
@@ -96,7 +96,8 @@ static uint64_t extractIntegerValue(const string &line)
// Remove whitespace, commas, braces // Remove whitespace, commas, braces
valueStr.erase(remove_if(valueStr.begin(), valueStr.end(), valueStr.erase(remove_if(valueStr.begin(), valueStr.end(),
[](char c) { return c == ' ' || c == ',' || c == '}' || c == '\n'; }), [](char c)
{ return c == ' ' || c == ',' || c == '}' || c == '\n'; }),
valueStr.end()); valueStr.end());
// Verify it's a valid number // Verify it's a valid number
@@ -214,8 +215,9 @@ static void processLine(const string &line, SMARTParseContext &ctx)
{ {
ctx.state = SMARTParseContext::IN_RAW_SECTION; ctx.state = SMARTParseContext::IN_RAW_SECTION;
} }
// Look for end of attribute object // Look for end of attribute object (more indented closing brace = end of attribute)
else if (trimmed.find("},") == 0 || trimmed.find("}") == 0) // " }," or " }" at attribute level (6 spaces)
else if (line.find(" },") == 0 || line.find(" }") == 0)
{ {
ctx.state = SMARTParseContext::SEARCHING; ctx.state = SMARTParseContext::SEARCHING;
ctx.currentAttributeId = 0; ctx.currentAttributeId = 0;
@@ -242,10 +244,15 @@ static void processLine(const string &line, SMARTParseContext &ctx)
ctx.uncorrectableSectors = static_cast<uint32_t>(value); ctx.uncorrectableSectors = static_cast<uint32_t>(value);
} }
// Exit raw section after finding value // Stay in raw section - closing brace will exit
ctx.state = (ctx.currentAttributeId == 5) ? SMARTParseContext::IN_ATTRIBUTE_5 : }
(ctx.currentAttributeId == 197) ? SMARTParseContext::IN_ATTRIBUTE_197 : // Look for end of raw object (less indented = back to attribute level)
SMARTParseContext::IN_ATTRIBUTE_198; // " }" at raw level (8 spaces)
else if (line.find(" }") == 0)
{
// Return to attribute state (raw section closed)
ctx.state = (ctx.currentAttributeId == 5) ? SMARTParseContext::IN_ATTRIBUTE_5 : (ctx.currentAttributeId == 197) ? SMARTParseContext::IN_ATTRIBUTE_197
: SMARTParseContext::IN_ATTRIBUTE_198;
} }
break; break;
} }
@@ -264,11 +271,11 @@ void SMART::readSMARTData(Drive *drive)
// Command order optimized for USB adapters // Command order optimized for USB adapters
// Standard commands first, then device-specific variants // Standard commands first, then device-specific variants
string sSmartctlCommands[] = { string sSmartctlCommands[] = {
" --json -a ", // Try standard first " --json -a ", // Try standard first
" --json -d sat -a ", // SAT (SCSI/ATA Translation) - most USB adapters " --json -d sat -a ", // SAT (SCSI/ATA Translation) - most USB adapters
" --json -d usbjmicron -a ", // USB JMicron " --json -d usbjmicron -a ", // USB JMicron
" --json -d usbprolific -a ", // USB Prolific " --json -d usbprolific -a ", // USB Prolific
" --json -d usbsunplus -a " // USB Sunplus " --json -d usbsunplus -a " // USB Sunplus
}; };
for (const string &sSmartctlCommand : sSmartctlCommands) for (const string &sSmartctlCommand : sSmartctlCommands)
@@ -376,6 +383,5 @@ void SMART::readSMARTData(Drive *drive)
ctx.temperature, ctx.temperature,
ctx.reallocatedSectors, ctx.reallocatedSectors,
ctx.pendingSectors, ctx.pendingSectors,
ctx.uncorrectableSectors ctx.uncorrectableSectors);
);
} }