From ed41bc013fcd8fa6f3e9d1a5597c7742bf001a98 Mon Sep 17 00:00:00 2001 From: David Given Date: Tue, 1 Jan 2019 20:04:04 +0100 Subject: [PATCH] More refactoring. --- lib/decoders.h | 2 -- lib/decoders/decoders.cc | 8 ++++---- lib/fluxmap.h | 1 + meson.build | 16 +++++++++++++--- src/fe-inspect.cc | 2 +- src/fe-readbrother.cc | 2 +- src/fe-readibm.cc | 2 +- src/fe-writebrother.cc | 4 ++++ 8 files changed, 25 insertions(+), 12 deletions(-) diff --git a/lib/decoders.h b/lib/decoders.h index 7b46d2c1..704ebbd0 100644 --- a/lib/decoders.h +++ b/lib/decoders.h @@ -26,8 +26,6 @@ struct IbmIdam class Sector; class Fluxmap; -extern std::vector decodeFluxmapToBits(const Fluxmap& fluxmap, nanoseconds_t clock_period); - extern std::vector> decodeBitsToRecordsMfm(const std::vector& bitmap); extern std::vector> parseRecordsToSectorsIbm(const std::vector>& records); diff --git a/lib/decoders/decoders.cc b/lib/decoders/decoders.cc index 5f80f33d..3203dfc0 100644 --- a/lib/decoders/decoders.cc +++ b/lib/decoders/decoders.cc @@ -56,9 +56,9 @@ nanoseconds_t Fluxmap::guessClock() const } /* Decodes a fluxmap into a nice aligned array of bits. */ -std::vector decodeFluxmapToBits(const Fluxmap& fluxmap, nanoseconds_t clockPeriod) +std::vector Fluxmap::decodeToBits(nanoseconds_t clockPeriod) const { - int pulses = fluxmap.duration() / clockPeriod; + int pulses = duration() / clockPeriod; nanoseconds_t lowerThreshold = clockPeriod * clockDecodeThreshold; std::vector bitmap(pulses); @@ -69,9 +69,9 @@ std::vector decodeFluxmapToBits(const Fluxmap& fluxmap, nanoseconds_t cloc { while (timestamp < lowerThreshold) { - if (cursor >= fluxmap.bytes()) + if (cursor >= bytes()) goto abort; - uint8_t interval = fluxmap[cursor++]; + uint8_t interval = (*this)[cursor++]; timestamp += interval * NS_PER_TICK; } diff --git a/lib/fluxmap.h b/lib/fluxmap.h index 7b044bcc..c36f5a3a 100644 --- a/lib/fluxmap.h +++ b/lib/fluxmap.h @@ -23,6 +23,7 @@ public: Fluxmap& appendIntervals(const uint8_t* ptr, size_t len); nanoseconds_t guessClock() const; + std::vector decodeToBits(nanoseconds_t clock_period) const; private: nanoseconds_t _duration = 0; diff --git a/meson.build b/meson.build index f5097750..5e241284 100644 --- a/meson.build +++ b/meson.build @@ -48,8 +48,18 @@ felib = shared_library('felib', ) feinc = include_directories('lib') -sqllib = shared_library('sqllib', ['lib/sql.cc'], link_with: [felib], dependencies: [sqlite]) -readerlib = shared_library('readerlib', ['lib/reader.cc'], include_directories: [fmtinc], link_with: [felib, sqllib, fmtlib]) +sqllib = shared_library('sqllib', + ['lib/sql.cc'], + link_with: [felib], + dependencies: [sqlite]) +readerlib = shared_library('readerlib', + ['lib/reader.cc'], + include_directories: [fmtinc], + link_with: [felib, sqllib, fmtlib]) +writerlib = shared_library('writerlib', + ['lib/writer.cc'], + include_directories: [fmtinc], + link_with: [felib, sqllib, fmtlib]) decoderlib = shared_library('decoderlib', [ @@ -77,6 +87,6 @@ executable('fe-seek', ['src/fe-seek.cc'], include_dire executable('fe-testbulktransport', ['src/fe-testbulktransport.cc'], include_directories: [feinc], link_with: [felib]) executable('fe-readibm', ['src/fe-readibm.cc'], include_directories: [feinc, fmtinc, decoderinc], link_with: [felib, readerlib, decoderlib, fmtlib]) executable('fe-readbrother', ['src/fe-readbrother.cc'], include_directories: [feinc, fmtinc, decoderinc, brotherinc], link_with: [felib, readerlib, decoderlib, brotherlib, fmtlib]) -executable('fe-writebrother', ['src/fe-writebrother.cc'], include_directories: [feinc, fmtinc, decoderinc, brotherinc], link_with: [felib, readerlib, decoderlib, brotherlib, fmtlib]) +executable('fe-writebrother', ['src/fe-writebrother.cc'], include_directories: [feinc, fmtinc, decoderinc, brotherinc], link_with: [felib, writerlib, decoderlib, brotherlib, fmtlib]) executable('fe-inspect', ['src/fe-inspect.cc'], include_directories: [feinc, fmtinc, decoderinc], link_with: [felib, readerlib, decoderlib, fmtlib]) diff --git a/src/fe-inspect.cc b/src/fe-inspect.cc index 6e2c383c..423f7fa8 100644 --- a/src/fe-inspect.cc +++ b/src/fe-inspect.cc @@ -50,7 +50,7 @@ int main(int argc, const char* argv[]) nanoseconds_t clockPeriod = fluxmap.guessClock(); std::cout << fmt::format(" {:.1f} us clock; ", (double)clockPeriod/1000.0) << std::flush; - auto bitmap = decodeFluxmapToBits(fluxmap, clockPeriod*clockScaleFlag); + auto bitmap = fluxmap.decodeToBits(clockPeriod*clockScaleFlag); std::cout << fmt::format("{} bytes encoded.", bitmap.size()/8) << std::endl; if (dumpFluxFlag) diff --git a/src/fe-readbrother.cc b/src/fe-readbrother.cc index d7ab7ce3..5452ff63 100644 --- a/src/fe-readbrother.cc +++ b/src/fe-readbrother.cc @@ -44,7 +44,7 @@ int main(int argc, const char* argv[]) nanoseconds_t clockPeriod = fluxmap.guessClock(); std::cout << fmt::format(" {:.1f} us clock; ", (double)clockPeriod/1000.0) << std::flush; - auto bitmap = decodeFluxmapToBits(fluxmap, clockPeriod); + auto bitmap = fluxmap.decodeToBits(clockPeriod); std::cout << fmt::format("{} bytes encoded; ", bitmap.size()/8) << std::flush; auto records = decodeBitsToRecordsBrother(bitmap); diff --git a/src/fe-readibm.cc b/src/fe-readibm.cc index 21d1567c..b1509ad7 100644 --- a/src/fe-readibm.cc +++ b/src/fe-readibm.cc @@ -32,7 +32,7 @@ int main(int argc, const char* argv[]) std::cout << fmt::format(" {:.1f} us clock; ", (double)clockPeriod/1000.0) << std::flush; /* For MFM, the bit clock is half the detected clock. */ - auto bitmap = decodeFluxmapToBits(fluxmap, clockPeriod/2); + auto bitmap = fluxmap.decodeToBits(clockPeriod/2); std::cout << fmt::format("{} bytes encoded; ", bitmap.size()/8) << std::flush; auto records = decodeBitsToRecordsMfm(bitmap); diff --git a/src/fe-writebrother.cc b/src/fe-writebrother.cc index 3eb8f9f7..6b4a365a 100644 --- a/src/fe-writebrother.cc +++ b/src/fe-writebrother.cc @@ -23,6 +23,10 @@ int main(int argc, const char* argv[]) Geometry geometry = {78, 1, 12, 256}; readSectorsFromFile(allSectors, geometry, inputFilename); + for (int track=0; track