Files
fluxengine/lib/fluxsource/flx.cc
dg 466c3c34e5 Replace the Error() object with an error() function which takes fmt
formatspecs, making for much cleaner code. Reformatted everything.

This actually happened in multiple steps but then I corrupted my local
repository and I had to recover from the working tree.
2023-05-09 20:59:44 +00:00

50 lines
1.0 KiB
C++

#include "globals.h"
#include "fluxmap.h"
#include "kryoflux.h"
#include "protocol.h"
#include "lib/fluxsource/flx.h"
std::unique_ptr<Fluxmap> readFlxBytes(const Bytes& bytes)
{
ByteReader br(bytes);
/* Skip header. */
for (;;)
{
if (br.eof())
error("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("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;
}