Skip to content

Commit

Permalink
Merge pull request #145 from davidgiven/writereport
Browse files Browse the repository at this point in the history
Add a machine readable read report.
  • Loading branch information
davidgiven authored Mar 31, 2020
2 parents a401173 + cd19fcd commit e6da85b
Show file tree
Hide file tree
Showing 35 changed files with 80 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
with:
fetch-depth: 1
- name: apt
run: sudo apt install libusb-1.0-0-dev libsqlite3-dev ninja-build
run: sudo apt update && sudo apt install libusb-1.0-0-dev libsqlite3-dev ninja-build
- name: make
run: make

Expand Down
3 changes: 2 additions & 1 deletion doc/using.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ directory.
These all take an optional `--write-flux` option which will cause the raw
flux to be written to the specified file as well as the normal decode.
There are various `--dump` options for showing raw data during the decode
process.
process, and `--write-csv` will write a copious CSV report of the state of
every sector in the file in machine-readable format.

- `fluxengine write *`: writes various formats of disk. Again, see the
per-format documentation [in the index page](../README.md).
Expand Down
25 changes: 0 additions & 25 deletions lib/image.cc

This file was deleted.

14 changes: 0 additions & 14 deletions lib/image.h

This file was deleted.

1 change: 0 additions & 1 deletion lib/imagereader/imagereader.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "globals.h"
#include "image.h"
#include "flags.h"
#include "dataspec.h"
#include "sector.h"
Expand Down
1 change: 0 additions & 1 deletion lib/imagereader/imgimagereader.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "globals.h"
#include "image.h"
#include "flags.h"
#include "dataspec.h"
#include "sector.h"
Expand Down
1 change: 0 additions & 1 deletion lib/imagewriter/d64imagewriter.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "globals.h"
#include "image.h"
#include "flags.h"
#include "dataspec.h"
#include "sector.h"
Expand Down
53 changes: 52 additions & 1 deletion lib/imagewriter/imagewriter.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include "globals.h"
#include "image.h"
#include "flags.h"
#include "dataspec.h"
#include "sector.h"
#include "sectorset.h"
#include "imagewriter/imagewriter.h"
#include "fmt/format.h"
#include <iostream>
#include <fstream>

std::map<std::string, ImageWriter::Constructor> ImageWriter::formats =
{
Expand Down Expand Up @@ -63,6 +64,56 @@ void ImageWriter::adjustGeometry()
}
}

void ImageWriter::writeCsv(const std::string& filename)
{
std::ofstream f(filename, std::ios::out);
if (!f.is_open())
Error() << "cannot open CSV report file";

f << "\"Physical track\","
"\"Physical side\","
"\"Logical track\","
"\"Logical side\","
"\"Logical sector\","
"\"Clock (ns)\","
"\"Header start (ns)\","
"\"Header end (ns)\","
"\"Data start (ns)\","
"\"Data end (ns)\","
"\"Raw data address (bytes)\","
"\"User payload length (bytes)\","
"\"Status\""
"\n";

for (int track = 0; track < spec.cylinders; track++)
{
for (int head = 0; head < spec.heads; head++)
{
for (int sectorId = 0; sectorId < spec.sectors; sectorId++)
{
f << fmt::format("{},{},", track, head);
const auto& sector = sectors.get(track, head, sectorId);
if (!sector)
f << fmt::format(",,{},,,,,,,,MISSING\n", sectorId);
else
f << fmt::format("{},{},{},{},{},{},{},{},{},{},{}\n",
sector->logicalTrack,
sector->logicalSide,
sector->logicalSector,
sector->clock,
sector->headerStartTime,
sector->headerEndTime,
sector->dataStartTime,
sector->dataEndTime,
sector->position.bytes,
sector->data.size(),
Sector::statusToString(sector->status)
);
}
}
}
}

void ImageWriter::printMap()
{
int badSectors = 0;
Expand Down
1 change: 1 addition & 0 deletions lib/imagewriter/imagewriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ImageWriter
public:
virtual void adjustGeometry();
void printMap();
void writeCsv(const std::string& filename);
virtual void writeImage() = 0;

protected:
Expand Down
1 change: 0 additions & 1 deletion lib/imagewriter/imgimagewriter.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "globals.h"
#include "image.h"
#include "flags.h"
#include "dataspec.h"
#include "sector.h"
Expand Down
1 change: 0 additions & 1 deletion lib/imagewriter/ldbsimagewriter.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "globals.h"
#include "image.h"
#include "flags.h"
#include "dataspec.h"
#include "sector.h"
Expand Down
20 changes: 18 additions & 2 deletions lib/reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
#include "sectorset.h"
#include "visualiser.h"
#include "record.h"
#include "image.h"
#include "bytes.h"
#include "decoders/rawbits.h"
#include "track.h"
#include "imagewriter/imagewriter.h"
#include "fmt/format.h"
#include <iostream>
#include <fstream>

FlagGroup readerFlags
{
Expand Down Expand Up @@ -68,6 +69,11 @@ static SettableFlag highDensityFlag(
{ "--high-density", "--hd" },
"set the drive to high density mode");

static StringFlag csvFile(
{ "--write-csv" },
"write a CSV report of the disk state",
"");

static std::unique_ptr<FluxSink> outputFluxSink;

void setReaderDefaultSource(const std::string& source)
Expand All @@ -85,6 +91,16 @@ void setReaderRevolutions(int revolutions)
setHardwareFluxSourceRevolutions(revolutions);
}

static void writeSectorsToFile(const SectorSet& sectors, const ImageSpec& spec)
{
std::unique_ptr<ImageWriter> writer(ImageWriter::create(sectors, spec));
writer->adjustGeometry();
writer->printMap();
if (!csvFile.get().empty())
writer->writeCsv(csvFile.get());
writer->writeImage();
}

void Track::readFluxmap()
{
std::cout << fmt::format("{0:>3}.{1}: ", physicalTrack, physicalSide) << std::flush;
Expand Down Expand Up @@ -280,7 +296,7 @@ void readDiskCommand(AbstractDecoder& decoder)

if (!visualise.get().empty())
visualiseSectorsToFile(allSectors, visualise.get());

writeSectorsToFile(allSectors, outputSpec);
if (failures)
std::cerr << "Warning: some sectors could not be decoded." << std::endl;
Expand Down
1 change: 0 additions & 1 deletion lib/sectorset.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "globals.h"
#include "image.h"
#include "sector.h"
#include "sectorset.h"

Expand Down
1 change: 0 additions & 1 deletion lib/visualiser.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#define _USE_MATH_DEFINES
#include "globals.h"
#include "image.h"
#include "sector.h"
#include "sectorset.h"
#include "visualiser.h"
Expand Down
7 changes: 6 additions & 1 deletion lib/writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include "encoders/encoders.h"
#include "fluxsource/fluxsource.h"
#include "fluxsink/fluxsink.h"
#include "imagereader/imagereader.h"
#include "fmt/format.h"
#include "record.h"
#include "image.h"
#include "sector.h"
#include "sectorset.h"

Expand Down Expand Up @@ -43,6 +43,11 @@ void setWriterDefaultInput(const std::string& input)
::input.set(input);
}

static SectorSet readSectorsFromFile(const ImageSpec& spec)
{
return ImageReader::create(spec)->readImage();
}

void writeTracks(
const std::function<std::unique_ptr<Fluxmap>(int track, int side)> producer)
{
Expand Down
1 change: 0 additions & 1 deletion mkninja.sh
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ buildlibrary libbackend.a \
lib/fluxsource/streamfluxsource.cc \
lib/globals.cc \
lib/hexdump.cc \
lib/image.cc \
lib/ldbs.cc \
lib/reader.cc \
lib/sector.cc \
Expand Down
1 change: 0 additions & 1 deletion src/fe-inspect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "fluxmap.h"
#include "decoders/fluxmapreader.h"
#include "decoders/decoders.h"
#include "image.h"
#include "protocol.h"
#include "decoders/rawbits.h"
#include "record.h"
Expand Down
1 change: 0 additions & 1 deletion src/fe-readadfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "reader.h"
#include "fluxmap.h"
#include "decoders/decoders.h"
#include "image.h"
#include "sector.h"
#include "sectorset.h"
#include "record.h"
Expand Down
1 change: 0 additions & 1 deletion src/fe-readaeslanier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "reader.h"
#include "fluxmap.h"
#include "decoders/decoders.h"
#include "image.h"
#include "sector.h"
#include "sectorset.h"
#include "record.h"
Expand Down
1 change: 0 additions & 1 deletion src/fe-readamiga.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "amiga/amiga.h"
#include "sector.h"
#include "sectorset.h"
#include "image.h"
#include "record.h"
#include "fmt/format.h"
#include <fstream>
Expand Down
1 change: 0 additions & 1 deletion src/fe-readampro.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "reader.h"
#include "fluxmap.h"
#include "decoders/decoders.h"
#include "image.h"
#include "sector.h"
#include "sectorset.h"
#include "record.h"
Expand Down
1 change: 0 additions & 1 deletion src/fe-readapple2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "apple2/apple2.h"
#include "sector.h"
#include "sectorset.h"
#include "image.h"
#include "record.h"
#include "fmt/format.h"
#include <fstream>
Expand Down
1 change: 0 additions & 1 deletion src/fe-readbrother.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "brother/brother.h"
#include "sector.h"
#include "sectorset.h"
#include "image.h"
#include "record.h"
#include "fmt/format.h"
#include <fstream>
Expand Down
1 change: 0 additions & 1 deletion src/fe-readc64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "c64/c64.h"
#include "sector.h"
#include "sectorset.h"
#include "image.h"
#include "record.h"
#include "fmt/format.h"
#include <fstream>
Expand Down
1 change: 0 additions & 1 deletion src/fe-readdfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "reader.h"
#include "fluxmap.h"
#include "decoders/decoders.h"
#include "image.h"
#include "sector.h"
#include "sectorset.h"
#include "record.h"
Expand Down
1 change: 0 additions & 1 deletion src/fe-readf85.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "f85/f85.h"
#include "sector.h"
#include "sectorset.h"
#include "image.h"
#include "record.h"
#include "fmt/format.h"
#include <fstream>
Expand Down
1 change: 0 additions & 1 deletion src/fe-readfb100.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "reader.h"
#include "fluxmap.h"
#include "decoders/decoders.h"
#include "image.h"
#include "sector.h"
#include "sectorset.h"
#include "record.h"
Expand Down
1 change: 0 additions & 1 deletion src/fe-readibm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "reader.h"
#include "fluxmap.h"
#include "decoders/decoders.h"
#include "image.h"
#include "sector.h"
#include "sectorset.h"
#include "record.h"
Expand Down
1 change: 0 additions & 1 deletion src/fe-readmac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "macintosh/macintosh.h"
#include "sector.h"
#include "sectorset.h"
#include "image.h"
#include "record.h"
#include "fmt/format.h"
#include <fstream>
Expand Down
1 change: 0 additions & 1 deletion src/fe-readmx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "fluxmap.h"
#include "decoders/decoders.h"
#include "mx/mx.h"
#include "image.h"
#include "sector.h"
#include "sectorset.h"
#include "record.h"
Expand Down
1 change: 0 additions & 1 deletion src/fe-readvictor9k.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "victor9k/victor9k.h"
#include "sector.h"
#include "sectorset.h"
#include "image.h"
#include "record.h"
#include "fmt/format.h"
#include <fstream>
Expand Down
1 change: 0 additions & 1 deletion src/fe-readzilogmcz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "reader.h"
#include "fluxmap.h"
#include "decoders/decoders.h"
#include "image.h"
#include "sector.h"
#include "sectorset.h"
#include "record.h"
Expand Down
Loading

0 comments on commit e6da85b

Please sign in to comment.