mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
The rotational speed message is now done via the logger.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "globals.h"
|
||||
#include "flags.h"
|
||||
#include "fluxmap.h"
|
||||
#include "logger.h"
|
||||
#include "usb/usb.h"
|
||||
#include "fluxsink/fluxsink.h"
|
||||
#include "lib/fluxsink/fluxsink.pb.h"
|
||||
@@ -14,22 +15,22 @@ public:
|
||||
{
|
||||
if (config.has_hard_sector_count())
|
||||
{
|
||||
int rotationalSpeedMs;
|
||||
nanoseconds_t oneRevolution;
|
||||
int retries = 5;
|
||||
usbSetDrive(_config.drive(), _config.high_density(), _config.index_mode());
|
||||
std::cout << "Measuring rotational speed... " << std::flush;
|
||||
Logger() << BeginSpeedOperationLogMessage();
|
||||
|
||||
do {
|
||||
nanoseconds_t oneRevolution = usbGetRotationalPeriod(_config.hard_sector_count());
|
||||
oneRevolution = usbGetRotationalPeriod(_config.hard_sector_count());
|
||||
_hardSectorThreshold = oneRevolution * 3 / (4 * _config.hard_sector_count());
|
||||
rotationalSpeedMs = oneRevolution / 1e6;
|
||||
retries--;
|
||||
} while ((rotationalSpeedMs == 0) && (retries > 0));
|
||||
} while ((oneRevolution == 0) && (retries > 0));
|
||||
|
||||
if (rotationalSpeedMs == 0) {
|
||||
if (oneRevolution == 0) {
|
||||
Error() << "Failed\nIs a disk in the drive?";
|
||||
}
|
||||
std::cout << fmt::format("{}ms\n", rotationalSpeedMs);
|
||||
|
||||
Logger() << EndSpeedOperationLogMessage(oneRevolution);
|
||||
}
|
||||
else
|
||||
_hardSectorThreshold = 0;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "globals.h"
|
||||
#include "flags.h"
|
||||
#include "fluxmap.h"
|
||||
#include "logger.h"
|
||||
#include "usb/usb.h"
|
||||
#include "fluxsource/fluxsource.h"
|
||||
#include "lib/fluxsource/fluxsource.pb.h"
|
||||
@@ -12,10 +13,9 @@ public:
|
||||
HardwareFluxSource(const HardwareFluxSourceProto& config):
|
||||
_config(config)
|
||||
{
|
||||
int rotationalSpeedMs;
|
||||
int retries = 5;
|
||||
usbSetDrive(_config.drive(), _config.high_density(), _config.index_mode());
|
||||
std::cout << "Measuring rotational speed... " << std::flush;
|
||||
Logger() << BeginSpeedOperationLogMessage();
|
||||
|
||||
do {
|
||||
_oneRevolution = usbGetRotationalPeriod(_config.hard_sector_count());
|
||||
@@ -24,15 +24,14 @@ public:
|
||||
else
|
||||
_hardSectorThreshold = 0;
|
||||
|
||||
rotationalSpeedMs = _oneRevolution / 1e6;
|
||||
retries--;
|
||||
} while ((rotationalSpeedMs == 0) && (retries > 0));
|
||||
} while ((_oneRevolution == 0) && (retries > 0));
|
||||
|
||||
if (rotationalSpeedMs == 0) {
|
||||
if (_oneRevolution == 0) {
|
||||
Error() << "Failed\nIs a disk in the drive?";
|
||||
}
|
||||
|
||||
std::cout << fmt::format("{}ms\n", rotationalSpeedMs);
|
||||
Logger() << EndSpeedOperationLogMessage(_oneRevolution);
|
||||
}
|
||||
|
||||
~HardwareFluxSource()
|
||||
|
||||
@@ -32,6 +32,20 @@ Logger& Logger::operator<<(std::shared_ptr<AnyLogMessage> message)
|
||||
{
|
||||
},
|
||||
|
||||
/* Start measuring the rotational speed */
|
||||
[](const BeginSpeedOperationLogMessage& m)
|
||||
{
|
||||
std::cout << "Measuring rotational speed... " << std::flush;
|
||||
},
|
||||
|
||||
/* Finish measuring the rotational speed */
|
||||
[](const EndSpeedOperationLogMessage& m)
|
||||
{
|
||||
std::cout << fmt::format("{:.1f}ms ({:.1f}rpm)\n",
|
||||
m.rotationalPeriod / 1e6,
|
||||
60e9 / m.rotationalPeriod);
|
||||
},
|
||||
|
||||
/* Indicates that we're working on a given cylinder and head */
|
||||
[](const DiskContextLogMessage& m)
|
||||
{
|
||||
|
||||
@@ -7,6 +7,12 @@ class TrackDataFlux;
|
||||
class TrackFlux;
|
||||
class Sector;
|
||||
|
||||
struct BeginSpeedOperationLogMessage {};
|
||||
struct EndSpeedOperationLogMessage
|
||||
{
|
||||
nanoseconds_t rotationalPeriod;
|
||||
};
|
||||
|
||||
struct DiskContextLogMessage
|
||||
{
|
||||
unsigned cylinder;
|
||||
@@ -35,6 +41,8 @@ typedef std::variant<std::string,
|
||||
SingleReadLogMessage,
|
||||
TrackReadLogMessage,
|
||||
DiskContextLogMessage,
|
||||
BeginSpeedOperationLogMessage,
|
||||
EndSpeedOperationLogMessage,
|
||||
BeginReadOperationLogMessage,
|
||||
EndReadOperationLogMessage,
|
||||
BeginWriteOperationLogMessage,
|
||||
|
||||
Reference in New Issue
Block a user