Rework the writer to use a fluxsink rather than just writing stuff directly.

This commit is contained in:
David Given
2020-03-29 15:08:45 +02:00
parent 00087cbb6b
commit b1ea5a9a35
2 changed files with 11 additions and 38 deletions

View File

@@ -160,7 +160,7 @@ static int large_bulk_transfer(int ep, Bytes& bytes)
int len;
int i = libusb_bulk_transfer(device, ep, bytes.begin(), bytes.size(), &len, TIMEOUT);
if (i < 0)
Error() << "data transfer failed: " << usberror(i);
Error() << fmt::format("data transfer failed at {} bytes: {}", len, usberror(i));
return len;
}
@@ -279,7 +279,6 @@ void usbWrite(int side, const Bytes& bytes)
((uint8_t*)&f.bytes_to_write)[3] = safelen >> 24;
usb_cmd_send(&f, f.f.size);
large_bulk_transfer(FLUXENGINE_DATA_OUT_EP, safeBytes);
await_reply<struct any_frame>(F_FRAME_WRITE_REPLY);

View File

@@ -53,19 +53,7 @@ void writeTracks(
setHardwareFluxSourceDensity(highDensityFlag);
setHardwareFluxSinkDensity(highDensityFlag);
if (!spec.filename.empty())
{
outdb = sqlOpen(spec.filename, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
sqlPrepareFlux(outdb);
sqlStmt(outdb, "BEGIN;");
sqlWriteIntProperty(outdb, "version", FLUX_VERSION_CURRENT);
atexit([]()
{
sqlStmt(outdb, "COMMIT;");
sqlClose(outdb);
}
);
}
std::shared_ptr<FluxSink> fluxSink = FluxSink::create(spec);
for (const auto& location : spec.locations)
{
@@ -73,30 +61,16 @@ void writeTracks(
std::unique_ptr<Fluxmap> fluxmap = producer(location.track, location.side);
if (!fluxmap)
{
if (!outdb)
{
std::cout << "erasing\n";
usbSeek(location.track);
usbErase(location.side);
}
else
std::cout << "skipping\n";
}
else
{
/* Precompensation actually seems to make things worse, so let's leave
* it disabled for now. */
//fluxmap->precompensate(PRECOMPENSATION_THRESHOLD_TICKS, 2);
if (outdb)
sqlWriteFlux(outdb, location.track, location.side, *fluxmap);
else
{
usbSeek(location.track);
usbWrite(location.side, fluxmap->rawBytes());
}
std::cout << fmt::format(
"{0} ms in {1} bytes", int(fluxmap->duration()/1e6), fluxmap->bytes()) << std::endl;
/* Create an empty fluxmap for writing. */
fluxmap.reset(new Fluxmap());
}
/* Precompensation actually seems to make things worse, so let's leave
* it disabled for now. */
//fluxmap->precompensate(PRECOMPENSATION_THRESHOLD_TICKS, 2);
fluxSink->writeFlux(location.track, location.side, *fluxmap);
std::cout << fmt::format(
"{0} ms in {1} bytes", int(fluxmap->duration()/1e6), fluxmap->bytes()) << std::endl;
}
}