mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
Replace the Error() object with an error() function which takes fmt
formatspecs, making for much cleaner code. Reformatted everything. This actually happened in multiple steps but then I corrupted my local repository and I had to recover from the working tree.
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
#include "lib/fluxsource/fluxsource.pb.h"
|
||||
#include "fluxsource/fluxsource.h"
|
||||
#include "proto.h"
|
||||
#include "fmt/format.h"
|
||||
#include <fstream>
|
||||
|
||||
struct A2Rv2Flux
|
||||
@@ -121,7 +120,7 @@ public:
|
||||
}
|
||||
|
||||
default:
|
||||
Error() << "unsupported A2R version";
|
||||
error("unsupported A2R version");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +140,7 @@ public:
|
||||
}
|
||||
|
||||
default:
|
||||
Error() << "unsupported A2R version";
|
||||
error("unsupported A2R version");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,7 +163,7 @@ private:
|
||||
offset += br.read_le32() + 8;
|
||||
}
|
||||
|
||||
Error() << "A2R file missing chunk";
|
||||
error("A2R file missing chunk");
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include "lib/fluxsource/fluxsource.pb.h"
|
||||
#include "fluxsource/fluxsource.h"
|
||||
#include "proto.h"
|
||||
#include "fmt/format.h"
|
||||
#include <fstream>
|
||||
|
||||
struct CwfHeader
|
||||
@@ -14,7 +13,7 @@ struct CwfHeader
|
||||
uint8_t version; // version of this file
|
||||
uint8_t clock_rate; // clock rate used: 0, 1, 2 (2 = 28MHz)
|
||||
uint8_t drive_type; // type of drive
|
||||
uint8_t tracks; // number of tracks
|
||||
uint8_t tracks; // number of tracks
|
||||
uint8_t sides; // number of sides
|
||||
uint8_t index_mark; // nonzero if index marks are included
|
||||
uint8_t step; // track stepping interval
|
||||
@@ -24,7 +23,7 @@ struct CwfHeader
|
||||
|
||||
struct CwfTrack
|
||||
{
|
||||
uint8_t track; // sequential
|
||||
uint8_t track; // sequential
|
||||
uint8_t side;
|
||||
uint8_t unused[2];
|
||||
uint8_t length[4]; // little-endian
|
||||
@@ -33,109 +32,120 @@ struct CwfTrack
|
||||
class CwfFluxSource : public TrivialFluxSource
|
||||
{
|
||||
public:
|
||||
CwfFluxSource(const CwfFluxSourceProto& config):
|
||||
_config(config)
|
||||
CwfFluxSource(const CwfFluxSourceProto& config): _config(config)
|
||||
{
|
||||
_if.open(_config.filename(), std::ios::in | std::ios::binary);
|
||||
if (!_if.is_open())
|
||||
Error() << fmt::format("cannot open input file '{}': {}",
|
||||
_config.filename(), strerror(errno));
|
||||
_if.open(_config.filename(), std::ios::in | std::ios::binary);
|
||||
if (!_if.is_open())
|
||||
error("cannot open input file '{}': {}",
|
||||
_config.filename(),
|
||||
strerror(errno));
|
||||
|
||||
_if.read((char*) &_header, sizeof(_header));
|
||||
check_for_error();
|
||||
_if.read((char*)&_header, sizeof(_header));
|
||||
check_for_error();
|
||||
|
||||
if ((_header.file_id[0] != 'C')
|
||||
|| (_header.file_id[1] != 'W')
|
||||
|| (_header.file_id[2] != 'S')
|
||||
|| (_header.file_id[3] != 'F'))
|
||||
Error() << "input not a CWF file";
|
||||
if ((_header.file_id[0] != 'C') || (_header.file_id[1] != 'W') ||
|
||||
(_header.file_id[2] != 'S') || (_header.file_id[3] != 'F'))
|
||||
error("input not a CWF file");
|
||||
|
||||
switch (_header.clock_rate)
|
||||
{
|
||||
case 1: _clockRate = 14161000.0; break;
|
||||
case 2: _clockRate = 28322000.0; break;
|
||||
default:
|
||||
Error() << "unsupported clock rate";
|
||||
}
|
||||
switch (_header.clock_rate)
|
||||
{
|
||||
case 1:
|
||||
_clockRate = 14161000.0;
|
||||
break;
|
||||
case 2:
|
||||
_clockRate = 28322000.0;
|
||||
break;
|
||||
default:
|
||||
error("unsupported clock rate");
|
||||
}
|
||||
|
||||
std::cout << fmt::format("CWF {}x{} = {} tracks, {} sides\n",
|
||||
_header.tracks, _header.step, _header.tracks*_header.step, _header.sides);
|
||||
std::cout << fmt::format("CWF sample clock rate: {} MHz\n", _clockRate / 1e6);
|
||||
std::cout << fmt::format("CWF {}x{} = {} tracks, {} sides\n",
|
||||
_header.tracks,
|
||||
_header.step,
|
||||
_header.tracks * _header.step,
|
||||
_header.sides);
|
||||
std::cout << fmt::format(
|
||||
"CWF sample clock rate: {} MHz\n", _clockRate / 1e6);
|
||||
|
||||
int tracks = _header.tracks*_header.sides;
|
||||
for (int i=0; i<tracks; i++)
|
||||
{
|
||||
CwfTrack trackheader;
|
||||
_if.read((char*) &trackheader, sizeof(trackheader));
|
||||
check_for_error();
|
||||
int tracks = _header.tracks * _header.sides;
|
||||
for (int i = 0; i < tracks; i++)
|
||||
{
|
||||
CwfTrack trackheader;
|
||||
_if.read((char*)&trackheader, sizeof(trackheader));
|
||||
check_for_error();
|
||||
|
||||
uint32_t length = Bytes(trackheader.length, 4).reader().read_le32() - sizeof(CwfTrack);
|
||||
unsigned track_number = trackheader.track * _header.step;
|
||||
uint32_t length =
|
||||
Bytes(trackheader.length, 4).reader().read_le32() -
|
||||
sizeof(CwfTrack);
|
||||
unsigned track_number = trackheader.track * _header.step;
|
||||
|
||||
off_t pos = _if.tellg();
|
||||
_trackOffsets[std::make_pair(track_number, trackheader.side)] = std::make_pair(pos, length);
|
||||
_if.seekg(pos + length);
|
||||
}
|
||||
}
|
||||
off_t pos = _if.tellg();
|
||||
_trackOffsets[std::make_pair(track_number, trackheader.side)] =
|
||||
std::make_pair(pos, length);
|
||||
_if.seekg(pos + length);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
std::unique_ptr<const Fluxmap> readSingleFlux(int track, int side)
|
||||
{
|
||||
const auto& p = _trackOffsets.find(std::make_pair(track, side));
|
||||
if (p == _trackOffsets.end())
|
||||
return std::make_unique<const Fluxmap>();
|
||||
const auto& p = _trackOffsets.find(std::make_pair(track, side));
|
||||
if (p == _trackOffsets.end())
|
||||
return std::make_unique<const Fluxmap>();
|
||||
|
||||
off_t pos = p->second.first;;
|
||||
size_t length = p->second.second;
|
||||
_if.seekg(pos);
|
||||
off_t pos = p->second.first;
|
||||
;
|
||||
size_t length = p->second.second;
|
||||
_if.seekg(pos);
|
||||
|
||||
std::unique_ptr<Fluxmap> fluxmap(new Fluxmap);
|
||||
uint32_t pending = 0;
|
||||
bool oldindex = true;
|
||||
for (size_t cursor = 0; cursor < length; cursor++)
|
||||
{
|
||||
uint32_t b = _if.get();
|
||||
bool index = !!(b & 0x80);
|
||||
b &= 0x7f;
|
||||
if (b == 0x7f)
|
||||
{
|
||||
pending += 0x7f;
|
||||
continue;
|
||||
}
|
||||
b += pending;
|
||||
pending = 0;
|
||||
std::unique_ptr<Fluxmap> fluxmap(new Fluxmap);
|
||||
uint32_t pending = 0;
|
||||
bool oldindex = true;
|
||||
for (size_t cursor = 0; cursor < length; cursor++)
|
||||
{
|
||||
uint32_t b = _if.get();
|
||||
bool index = !!(b & 0x80);
|
||||
b &= 0x7f;
|
||||
if (b == 0x7f)
|
||||
{
|
||||
pending += 0x7f;
|
||||
continue;
|
||||
}
|
||||
b += pending;
|
||||
pending = 0;
|
||||
|
||||
double interval_us = b * (1e6/_clockRate);
|
||||
fluxmap->appendInterval(interval_us / US_PER_TICK);
|
||||
fluxmap->appendPulse();
|
||||
double interval_us = b * (1e6 / _clockRate);
|
||||
fluxmap->appendInterval(interval_us / US_PER_TICK);
|
||||
fluxmap->appendPulse();
|
||||
|
||||
if (index && !oldindex)
|
||||
fluxmap->appendIndex();
|
||||
oldindex = index;
|
||||
}
|
||||
check_for_error();
|
||||
if (index && !oldindex)
|
||||
fluxmap->appendIndex();
|
||||
oldindex = index;
|
||||
}
|
||||
check_for_error();
|
||||
|
||||
return fluxmap;
|
||||
return fluxmap;
|
||||
}
|
||||
|
||||
void recalibrate() {}
|
||||
|
||||
private:
|
||||
void check_for_error()
|
||||
{
|
||||
if (_if.fail())
|
||||
Error() << fmt::format("SCP read I/O error: {}", strerror(errno));
|
||||
}
|
||||
void check_for_error()
|
||||
{
|
||||
if (_if.fail())
|
||||
error("SCP read I/O error: {}", strerror(errno));
|
||||
}
|
||||
|
||||
private:
|
||||
const CwfFluxSourceProto& _config;
|
||||
std::ifstream _if;
|
||||
CwfHeader _header;
|
||||
nanoseconds_t _clockRate;
|
||||
std::map<std::pair<int, int>, std::pair<off_t, size_t>> _trackOffsets;
|
||||
std::ifstream _if;
|
||||
CwfHeader _header;
|
||||
nanoseconds_t _clockRate;
|
||||
std::map<std::pair<int, int>, std::pair<off_t, size_t>> _trackOffsets;
|
||||
};
|
||||
|
||||
std::unique_ptr<FluxSource> FluxSource::createCwfFluxSource(const CwfFluxSourceProto& config)
|
||||
std::unique_ptr<FluxSource> FluxSource::createCwfFluxSource(
|
||||
const CwfFluxSourceProto& config)
|
||||
{
|
||||
return std::unique_ptr<FluxSource>(new CwfFluxSource(config));
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#include "fluxmap.h"
|
||||
#include "fluxsource/fluxsource.h"
|
||||
#include "lib/fluxsource/fluxsource.pb.h"
|
||||
#include "fmt/format.h"
|
||||
|
||||
class EraseFluxSource : public TrivialFluxSource
|
||||
{
|
||||
@@ -13,16 +12,14 @@ public:
|
||||
public:
|
||||
std::unique_ptr<const Fluxmap> readSingleFlux(int track, int side) override
|
||||
{
|
||||
return std::unique_ptr<const Fluxmap>();
|
||||
return std::unique_ptr<const Fluxmap>();
|
||||
}
|
||||
|
||||
void recalibrate() {}
|
||||
};
|
||||
|
||||
std::unique_ptr<FluxSource> FluxSource::createEraseFluxSource(const EraseFluxSourceProto& config)
|
||||
std::unique_ptr<FluxSource> FluxSource::createEraseFluxSource(
|
||||
const EraseFluxSourceProto& config)
|
||||
{
|
||||
return std::make_unique<EraseFluxSource>(config);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "fluxsource/fluxsource.h"
|
||||
#include "proto.h"
|
||||
#include "fl2.h"
|
||||
#include "fmt/format.h"
|
||||
#include "fluxmap.h"
|
||||
#include <fstream>
|
||||
|
||||
@@ -57,7 +56,7 @@ private:
|
||||
void check_for_error(std::ifstream& ifs)
|
||||
{
|
||||
if (ifs.fail())
|
||||
Error() << fmt::format("FL2 read I/O error: {}", strerror(errno));
|
||||
error("FL2 read I/O error: {}", strerror(errno));
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "lib/config.pb.h"
|
||||
#include "proto.h"
|
||||
#include "utils.h"
|
||||
#include "fmt/format.h"
|
||||
#include <regex>
|
||||
|
||||
static bool ends_with(const std::string& value, const std::string& ending)
|
||||
@@ -47,7 +46,7 @@ std::unique_ptr<FluxSource> FluxSource::create(const FluxSourceProto& config)
|
||||
return createFlxFluxSource(config.flx());
|
||||
|
||||
default:
|
||||
Error() << "bad input disk configuration";
|
||||
error("bad input disk configuration");
|
||||
return std::unique_ptr<FluxSource>();
|
||||
}
|
||||
}
|
||||
@@ -123,7 +122,7 @@ void FluxSource::updateConfigForFilename(
|
||||
}
|
||||
}
|
||||
|
||||
Error() << fmt::format("unrecognised flux filename '{}'", filename);
|
||||
error("unrecognised flux filename '{}'", filename);
|
||||
}
|
||||
|
||||
class TrivialFluxSourceIterator : public FluxSourceIterator
|
||||
|
||||
@@ -79,7 +79,7 @@ class EmptyFluxSourceIterator : public FluxSourceIterator
|
||||
|
||||
std::unique_ptr<const Fluxmap> next() override
|
||||
{
|
||||
Error() << "no flux to read";
|
||||
error("no flux to read");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include "kryoflux.h"
|
||||
#include "protocol.h"
|
||||
#include "lib/fluxsource/flx.h"
|
||||
#include "fmt/format.h"
|
||||
|
||||
std::unique_ptr<Fluxmap> readFlxBytes(const Bytes& bytes)
|
||||
{
|
||||
@@ -14,7 +13,7 @@ std::unique_ptr<Fluxmap> readFlxBytes(const Bytes& bytes)
|
||||
for (;;)
|
||||
{
|
||||
if (br.eof())
|
||||
Error() << fmt::format("malformed FLX stream");
|
||||
error("malformed FLX stream");
|
||||
uint8_t b = br.read_8();
|
||||
if (b == 0)
|
||||
break;
|
||||
@@ -36,7 +35,7 @@ std::unique_ptr<Fluxmap> readFlxBytes(const Bytes& bytes)
|
||||
default:
|
||||
{
|
||||
if (b < 32)
|
||||
Error() << fmt::format("unknown FLX opcode 0x{:2x}", b);
|
||||
error("unknown FLX opcode 0x{:2x}", b);
|
||||
nanoseconds_t interval = b * FLX_TICK_NS;
|
||||
fluxmap->appendInterval(interval / NS_PER_TICK);
|
||||
fluxmap->appendPulse();
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include "fluxsource/fluxsource.h"
|
||||
#include "lib/fluxsource/fluxsource.pb.h"
|
||||
#include "lib/readerwriter.h"
|
||||
#include "fmt/format.h"
|
||||
|
||||
class HardwareFluxSource : public FluxSource
|
||||
{
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#include "fluxmap.h"
|
||||
#include "kryoflux.h"
|
||||
#include "protocol.h"
|
||||
#include "fmt/format.h"
|
||||
#include <fstream>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
@@ -17,17 +16,20 @@ static bool has_suffix(const std::string& haystack, const std::string& needle)
|
||||
{
|
||||
if (needle.length() > haystack.length())
|
||||
return false;
|
||||
|
||||
return haystack.compare(haystack.length() - needle.length(), needle.length(), needle) == 0;
|
||||
|
||||
return haystack.compare(haystack.length() - needle.length(),
|
||||
needle.length(),
|
||||
needle) == 0;
|
||||
}
|
||||
|
||||
std::unique_ptr<Fluxmap> readStream(const std::string& dir, unsigned track, unsigned side)
|
||||
std::unique_ptr<Fluxmap> readStream(
|
||||
const std::string& dir, unsigned track, unsigned side)
|
||||
{
|
||||
std::string suffix = fmt::format("{:02}.{}.raw", track, side);
|
||||
|
||||
DIR* dirp = opendir(dir.c_str());
|
||||
if (!dirp)
|
||||
Error() << fmt::format("cannot access path '{}'", dir);
|
||||
error("cannot access path '{}'", dir);
|
||||
|
||||
std::string filename;
|
||||
for (;;)
|
||||
@@ -35,18 +37,18 @@ std::unique_ptr<Fluxmap> readStream(const std::string& dir, unsigned track, unsi
|
||||
struct dirent* de = readdir(dirp);
|
||||
if (!de)
|
||||
break;
|
||||
|
||||
|
||||
if (has_suffix(de->d_name, suffix))
|
||||
{
|
||||
if (!filename.empty())
|
||||
Error() << fmt::format("data is ambiguous --- multiple files end in {}", suffix);
|
||||
error("data is ambiguous --- multiple files end in {}", suffix);
|
||||
filename = fmt::format("{}/{}", dir, de->d_name);
|
||||
}
|
||||
}
|
||||
closedir(dirp);
|
||||
|
||||
if (filename.empty())
|
||||
Error() << fmt::format("failed to find track {} side {} in {}", track, side, dir);
|
||||
error("failed to find track {} side {} in {}", track, side, dir);
|
||||
|
||||
return readStream(filename);
|
||||
}
|
||||
@@ -55,7 +57,7 @@ std::unique_ptr<Fluxmap> readStream(const std::string& filename)
|
||||
{
|
||||
std::ifstream f(filename, std::ios::in | std::ios::binary);
|
||||
if (!f.is_open())
|
||||
Error() << fmt::format("cannot open input file '{}'", filename);
|
||||
error("cannot open input file '{}'", filename);
|
||||
|
||||
Bytes bytes;
|
||||
ByteWriter bw(bytes);
|
||||
@@ -69,7 +71,7 @@ std::unique_ptr<Fluxmap> readStream(const Bytes& bytes)
|
||||
ByteReader br(bytes);
|
||||
|
||||
/* Pass 1: scan the stream looking for index marks. */
|
||||
|
||||
|
||||
std::set<uint32_t> indexmarks;
|
||||
br.seek(0);
|
||||
while (!br.eof())
|
||||
@@ -119,7 +121,8 @@ std::unique_ptr<Fluxmap> readStream(const Bytes& bytes)
|
||||
}
|
||||
else if (b == 0x0b)
|
||||
{
|
||||
/* Ovl16: the next block is 0x10000 sclks longer than normal. */
|
||||
/* Ovl16: the next block is 0x10000 sclks longer than
|
||||
* normal. */
|
||||
len = 0;
|
||||
}
|
||||
else if (b == 0x0c)
|
||||
@@ -133,8 +136,9 @@ std::unique_ptr<Fluxmap> readStream(const Bytes& bytes)
|
||||
len = 0;
|
||||
}
|
||||
else
|
||||
Error() << fmt::format(
|
||||
"unknown stream block byte 0x{:02x} at 0x{:08x}", b, (uint64_t)br.pos-1);
|
||||
error("unknown stream block byte 0x{:02x} at 0x{:08x}",
|
||||
b,
|
||||
(uint64_t)br.pos - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,7 +201,7 @@ finished_pass_1:
|
||||
if ((b >= 0x00) && (b <= 0x07))
|
||||
{
|
||||
/* Flux2: double byte value */
|
||||
b = (b<<8) | br.read_8();
|
||||
b = (b << 8) | br.read_8();
|
||||
writeFlux(extrasclks + b);
|
||||
extrasclks = 0;
|
||||
}
|
||||
@@ -217,7 +221,8 @@ finished_pass_1:
|
||||
}
|
||||
else if (b == 0x0b)
|
||||
{
|
||||
/* Ovl16: the next block is 0x10000 sclks longer than normal. */
|
||||
/* Ovl16: the next block is 0x10000 sclks longer than
|
||||
* normal. */
|
||||
extrasclks += 0x10000;
|
||||
}
|
||||
else if (b == 0x0c)
|
||||
@@ -234,14 +239,15 @@ finished_pass_1:
|
||||
extrasclks = 0;
|
||||
}
|
||||
else
|
||||
Error() << fmt::format(
|
||||
"unknown stream block byte 0x{:02x} at 0x{:08x}", b, (uint64_t)br.pos-1);
|
||||
error("unknown stream block byte 0x{:02x} at 0x{:08x}",
|
||||
b,
|
||||
(uint64_t)br.pos - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
finished_pass_2:
|
||||
if (!br.eof())
|
||||
Error() << "I/O error reading stream";
|
||||
error("I/O error reading stream");
|
||||
return fluxmap;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@ class KryofluxFluxSource : public TrivialFluxSource
|
||||
public:
|
||||
KryofluxFluxSource(const KryofluxFluxSourceProto& config):
|
||||
_path(config.directory())
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
std::unique_ptr<const Fluxmap> readSingleFlux(int track, int side) override
|
||||
@@ -23,7 +24,8 @@ private:
|
||||
const std::string _path;
|
||||
};
|
||||
|
||||
std::unique_ptr<FluxSource> FluxSource::createKryofluxFluxSource(const KryofluxFluxSourceProto& config)
|
||||
std::unique_ptr<FluxSource> FluxSource::createKryofluxFluxSource(
|
||||
const KryofluxFluxSourceProto& config)
|
||||
{
|
||||
return std::make_unique<KryofluxFluxSource>(config);
|
||||
}
|
||||
|
||||
@@ -4,47 +4,44 @@
|
||||
#include "lib/fluxsource/fluxsource.h"
|
||||
#include "lib/fluxmap.h"
|
||||
#include "lib/layout.h"
|
||||
#include <fmt/format.h>
|
||||
#include <fstream>
|
||||
|
||||
class MemoryFluxSourceIterator : public FluxSourceIterator
|
||||
{
|
||||
public:
|
||||
MemoryFluxSourceIterator(const TrackFlux& track):
|
||||
_track(track)
|
||||
{}
|
||||
MemoryFluxSourceIterator(const TrackFlux& track): _track(track) {}
|
||||
|
||||
bool hasNext() const override
|
||||
{
|
||||
return _count < _track.trackDatas.size();
|
||||
}
|
||||
bool hasNext() const override
|
||||
{
|
||||
return _count < _track.trackDatas.size();
|
||||
}
|
||||
|
||||
std::unique_ptr<const Fluxmap> next() override
|
||||
{
|
||||
auto bytes = _track.trackDatas[_count]->fluxmap->rawBytes();
|
||||
_count++;
|
||||
return std::make_unique<Fluxmap>(bytes);
|
||||
}
|
||||
std::unique_ptr<const Fluxmap> next() override
|
||||
{
|
||||
auto bytes = _track.trackDatas[_count]->fluxmap->rawBytes();
|
||||
_count++;
|
||||
return std::make_unique<Fluxmap>(bytes);
|
||||
}
|
||||
|
||||
private:
|
||||
const TrackFlux& _track;
|
||||
int _count = 0;
|
||||
const TrackFlux& _track;
|
||||
int _count = 0;
|
||||
};
|
||||
|
||||
class MemoryFluxSource : public FluxSource
|
||||
{
|
||||
public:
|
||||
MemoryFluxSource(const DiskFlux& flux): _flux(flux)
|
||||
{
|
||||
}
|
||||
MemoryFluxSource(const DiskFlux& flux): _flux(flux) {}
|
||||
|
||||
public:
|
||||
std::unique_ptr<FluxSourceIterator> readFlux(int physicalTrack, int physicalSide) override
|
||||
std::unique_ptr<FluxSourceIterator> readFlux(
|
||||
int physicalTrack, int physicalSide) override
|
||||
{
|
||||
for (const auto& trackFlux : _flux.tracks)
|
||||
{
|
||||
if ((trackFlux->trackInfo->physicalTrack == physicalTrack) && (trackFlux->trackInfo->physicalSide == physicalSide))
|
||||
return std::make_unique<MemoryFluxSourceIterator>(*trackFlux);
|
||||
if ((trackFlux->trackInfo->physicalTrack == physicalTrack) &&
|
||||
(trackFlux->trackInfo->physicalSide == physicalSide))
|
||||
return std::make_unique<MemoryFluxSourceIterator>(*trackFlux);
|
||||
}
|
||||
|
||||
return std::make_unique<EmptyFluxSourceIterator>();
|
||||
@@ -53,11 +50,11 @@ public:
|
||||
void recalibrate() {}
|
||||
|
||||
private:
|
||||
const DiskFlux& _flux;
|
||||
const DiskFlux& _flux;
|
||||
};
|
||||
|
||||
std::unique_ptr<FluxSource> FluxSource::createMemoryFluxSource(const DiskFlux& flux)
|
||||
std::unique_ptr<FluxSource> FluxSource::createMemoryFluxSource(
|
||||
const DiskFlux& flux)
|
||||
{
|
||||
return std::make_unique<MemoryFluxSource>(flux);
|
||||
return std::make_unique<MemoryFluxSource>(flux);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include "fluxsource/fluxsource.h"
|
||||
#include "scp.h"
|
||||
#include "proto.h"
|
||||
#include "fmt/format.h"
|
||||
#include <fstream>
|
||||
|
||||
static int trackno(int strack)
|
||||
@@ -31,7 +30,7 @@ public:
|
||||
{
|
||||
_if.open(_config.filename(), std::ios::in | std::ios::binary);
|
||||
if (!_if.is_open())
|
||||
Error() << fmt::format("cannot open input file '{}': {}",
|
||||
error("cannot open input file '{}': {}",
|
||||
_config.filename(),
|
||||
strerror(errno));
|
||||
|
||||
@@ -40,9 +39,9 @@ public:
|
||||
|
||||
if ((_header.file_id[0] != 'S') || (_header.file_id[1] != 'C') ||
|
||||
(_header.file_id[2] != 'P'))
|
||||
Error() << "input not a SCP file";
|
||||
error("input not a SCP file");
|
||||
|
||||
int tpi = (_header.flags & SCP_FLAG_96TPI) ? 96 : 48;
|
||||
int tpi = (_header.flags & SCP_FLAG_96TPI) ? 96 : 48;
|
||||
::config.set_tpi(tpi);
|
||||
|
||||
_resolution = 25 * (_header.resolution + 1);
|
||||
@@ -50,7 +49,7 @@ public:
|
||||
int endSide = (_header.heads == 1) ? 0 : 1;
|
||||
|
||||
if ((_header.cell_width != 0) && (_header.cell_width != 16))
|
||||
Error() << "currently only 16-bit cells in SCP files are supported";
|
||||
error("currently only 16-bit cells in SCP files are supported");
|
||||
|
||||
std::cout << fmt::format("SCP tracks {}-{}, heads {}-{}\n",
|
||||
trackno(_header.start_track),
|
||||
@@ -78,7 +77,7 @@ public:
|
||||
if ((trackheader.track_id[0] != 'T') ||
|
||||
(trackheader.track_id[1] != 'R') ||
|
||||
(trackheader.track_id[2] != 'K'))
|
||||
Error() << "corrupt SCP file";
|
||||
error("corrupt SCP file");
|
||||
|
||||
std::vector<ScpTrackRevolution> revs(_header.revolutions);
|
||||
for (int revolution = 0; revolution < _header.revolutions; revolution++)
|
||||
@@ -134,7 +133,7 @@ private:
|
||||
void check_for_error()
|
||||
{
|
||||
if (_if.fail())
|
||||
Error() << fmt::format("SCP read I/O error: {}", strerror(errno));
|
||||
error("SCP read I/O error: {}", strerror(errno));
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -2,40 +2,39 @@
|
||||
#include "fluxmap.h"
|
||||
#include "fluxsource/fluxsource.h"
|
||||
#include "lib/fluxsource/fluxsource.pb.h"
|
||||
#include "fmt/format.h"
|
||||
|
||||
class TestPatternFluxSource : public TrivialFluxSource
|
||||
{
|
||||
public:
|
||||
TestPatternFluxSource(const TestPatternFluxSourceProto& config):
|
||||
_config(config)
|
||||
{}
|
||||
_config(config)
|
||||
{
|
||||
}
|
||||
|
||||
~TestPatternFluxSource() {}
|
||||
|
||||
public:
|
||||
std::unique_ptr<const Fluxmap> readSingleFlux(int track, int side) override
|
||||
{
|
||||
auto fluxmap = std::make_unique<Fluxmap>();
|
||||
auto fluxmap = std::make_unique<Fluxmap>();
|
||||
|
||||
while (fluxmap->duration() < (_config.sequence_length_us()*1000000.0))
|
||||
{
|
||||
fluxmap->appendInterval(_config.interval_us());
|
||||
fluxmap->appendPulse();
|
||||
}
|
||||
while (fluxmap->duration() < (_config.sequence_length_us() * 1000000.0))
|
||||
{
|
||||
fluxmap->appendInterval(_config.interval_us());
|
||||
fluxmap->appendPulse();
|
||||
}
|
||||
|
||||
return fluxmap;
|
||||
return fluxmap;
|
||||
}
|
||||
|
||||
void recalibrate() {}
|
||||
|
||||
private:
|
||||
const TestPatternFluxSourceProto& _config;
|
||||
const TestPatternFluxSourceProto& _config;
|
||||
};
|
||||
|
||||
std::unique_ptr<FluxSource> FluxSource::createTestPatternFluxSource(const TestPatternFluxSourceProto& config)
|
||||
std::unique_ptr<FluxSource> FluxSource::createTestPatternFluxSource(
|
||||
const TestPatternFluxSourceProto& config)
|
||||
{
|
||||
return std::make_unique<TestPatternFluxSource>(config);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user