Made the FLX reader work.

This commit is contained in:
dg
2022-11-29 20:17:24 +00:00
parent d26940304b
commit 5136dda598
7 changed files with 126 additions and 29 deletions

View File

@@ -22,6 +22,7 @@ LIBFLUXENGINE_SRCS = \
lib/fluxsource/erasefluxsource.cc \
lib/fluxsource/fl2fluxsource.cc \
lib/fluxsource/fluxsource.cc \
lib/fluxsource/flx.cc \
lib/fluxsource/flxfluxsource.cc \
lib/fluxsource/hardwarefluxsource.cc \
lib/fluxsource/kryoflux.cc \

50
lib/fluxsource/flx.cc Normal file
View File

@@ -0,0 +1,50 @@
#include "globals.h"
#include "fluxmap.h"
#include "kryoflux.h"
#include "protocol.h"
#include "lib/fluxsource/flx.h"
#include "fmt/format.h"
std::unique_ptr<Fluxmap> readFlxBytes(const Bytes& bytes)
{
ByteReader br(bytes);
/* Skip header. */
for (;;)
{
if (br.eof())
Error() << fmt::format("malformed FLX stream");
uint8_t b = br.read_8();
if (b == 0)
break;
}
auto fluxmap = std::make_unique<Fluxmap>();
while (!br.eof())
{
uint8_t b = br.read_8();
switch (b)
{
case FLX_INDEX:
fluxmap->appendIndex();
continue;
case FLX_STOP:
goto stop;
default:
{
if (b < 32)
Error() << fmt::format("unknown FLX opcode 0x{:2x}", b);
nanoseconds_t interval = b * FLX_TICK_NS;
fluxmap->appendInterval(interval / NS_PER_TICK);
fluxmap->appendPulse();
break;
}
}
}
stop:
return fluxmap;
}

16
lib/fluxsource/flx.h Normal file
View File

@@ -0,0 +1,16 @@
#ifndef FLX_H
#define FLX_H
#define FLX_TICK_NS 50 /* ns per tick */
/* Special FLX opcodes */
enum
{
FLX_INDEX = 0x08,
FLX_STOP = 0x0d
};
extern std::unique_ptr<Fluxmap> readFlxBytes(const Bytes& bytes);
#endif

View File

@@ -1,8 +1,8 @@
#include "globals.h"
#include "fluxmap.h"
#include "lib/globals.h"
#include "lib/fluxmap.h"
#include "lib/fluxsource/fluxsource.pb.h"
#include "fluxsource/fluxsource.h"
#include <fstream>
#include "lib/fluxsource/fluxsource.h"
#include "lib/fluxsource/flx.h"
class FlxFluxSource : public TrivialFluxSource
{
@@ -14,34 +14,13 @@ public:
public:
std::unique_ptr<const Fluxmap> readSingleFlux(int track, int side) override
{
std::string path = fmt::format("{}/@TR{:02}S{}.FLX", _path, track, side + 1);
std::ifstream is(path);
if (!is.good())
Error() << fmt::format("cannot access path '{}'", _path);
return convertStream(is);
std::string path =
fmt::format("{}/@TR{:02}S{}@.FLX", _path, track, side + 1);
return readFlxBytes(Bytes::readFromFile(path));
}
void recalibrate() {}
private:
std::unique_ptr<const Fluxmap> convertStream(std::ifstream& is)
{
/* Skip header. */
for (;;)
{
int c = is.get();
if (!c)
break;
if (is.eof())
Error() << fmt::format("malformed FLX stream");
}
return nullptr;
}
private:
const std::string _path;
};