Perform retries when calculating drive RPM.

The drive RPM measurement fails about 3% of the time.  Retry up to
five times until it succeeds, and exit with an error if it doesn't.
This commit is contained in:
Howard M. Harte
2021-05-26 23:02:34 -07:00
parent 41cb53a550
commit 44b452b30b
2 changed files with 35 additions and 11 deletions

View File

@@ -12,14 +12,27 @@ public:
HardwareFluxSource(const HardwareFluxSourceProto& config):
_config(config)
{
int rotationalSpeedMs;
int retries = 5;
usbSetDrive(_config.drive(), _config.high_density(), _config.index_mode());
std::cerr << "Measuring rotational speed... " << std::flush;
_oneRevolution = usbGetRotationalPeriod(_config.hard_sector_count());
if (_config.hard_sector_count() != 0)
_hardSectorThreshold = _oneRevolution * 3 / (4 * _config.hard_sector_count());
else
_hardSectorThreshold = 0;
std::cerr << fmt::format("{}ms\n", _oneRevolution / 1e6);
std::cout << "Measuring rotational speed... " << std::flush;
do {
_oneRevolution = usbGetRotationalPeriod(_config.hard_sector_count());
if (_config.hard_sector_count() != 0)
_hardSectorThreshold = _oneRevolution * 3 / (4 * _config.hard_sector_count());
else
_hardSectorThreshold = 0;
rotationalSpeedMs = _oneRevolution / 1e6;
retries--;
} while ((rotationalSpeedMs == 0) && (retries > 0));
if (rotationalSpeedMs == 0) {
Error() << "Failed\nIs a disk in the drive?";
}
std::cout << fmt::format("{}ms\n", rotationalSpeedMs);
}
~HardwareFluxSource()