Add a --write-csv=X option to the reader to dump the sector status map as a

machine-readable file.
This commit is contained in:
David Given
2020-03-14 14:35:19 +00:00
parent a401173f6d
commit 37aa8b62b0
2 changed files with 54 additions and 1 deletions

View File

@@ -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).

View File

@@ -18,6 +18,8 @@
#include "track.h"
#include "imagewriter/imagewriter.h"
#include "fmt/format.h"
#include <iostream>
#include <fstream>
FlagGroup readerFlags
{
@@ -47,6 +49,11 @@ static StringFlag visualise(
"write a visualisation of the disk to this file",
"");
static StringFlag csvFile(
{ "--write-csv" },
"write a CSV report of the disk state",
"");
static SettableFlag justRead(
{ "--just-read" },
"just read the disk and do no further processing");
@@ -133,6 +140,48 @@ std::vector<std::unique_ptr<Track>> readTracks()
return tracks;
}
static void writeCsv(const SectorSet& sectors, 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 (const auto& e : sectors.get())
{
const auto& sector = e.second;
f << fmt::format("{},{},{},{},{},{},{},{},{},{},{},{},{}\n",
sector->physicalTrack,
sector->physicalSide,
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)
);
}
}
static bool conflictable(Sector::Status status)
{
return (status == Sector::OK) || (status == Sector::CONFLICT);
@@ -280,6 +329,9 @@ void readDiskCommand(AbstractDecoder& decoder)
if (!visualise.get().empty())
visualiseSectorsToFile(allSectors, visualise.get());
if (!csvFile.get().empty())
writeCsv(allSectors, csvFile.get());
writeSectorsToFile(allSectors, outputSpec);
if (failures)