mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
Made the FLX reader work.
This commit is contained in:
@@ -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
50
lib/fluxsource/flx.cc
Normal 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
16
lib/fluxsource/flx.h
Normal 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
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user