Files
fluxengine/lib/fluxmap.h
David Given fc2655ecd6 Rework the bytecode format to use a much simplified setup: a six-bit timer with
the top two bits reserved for pulse and index state. This is actually smaller,
bandwidth-wise, than the old version, and may be smaller than the crunched
version.
2020-03-14 18:58:43 +00:00

61 lines
1.2 KiB
C++

#ifndef FLUXMAP_H
#define FLUXMAP_H
#include "bytes.h"
#include "protocol.h"
class RawBits;
class Fluxmap
{
public:
struct Position
{
unsigned bytes = 0;
unsigned ticks = 0;
unsigned zeroes = 0;
nanoseconds_t ns() const
{ return ticks * NS_PER_TICK; }
};
public:
nanoseconds_t duration() const { return _duration; }
unsigned ticks() const { return _ticks; }
size_t bytes() const { return _bytes.size(); }
const Bytes& rawBytes() const { return _bytes; }
const uint8_t* ptr() const
{
if (!_bytes.empty())
return &_bytes[0];
return NULL;
}
Fluxmap& appendInterval(uint32_t ticks);
Fluxmap& appendPulse();
Fluxmap& appendIndex();
Fluxmap& appendBytes(const Bytes& bytes);
Fluxmap& appendBytes(const uint8_t* ptr, size_t len);
Fluxmap& appendByte(uint8_t byte)
{
return appendBytes(&byte, 1);
}
Fluxmap& appendBits(const std::vector<bool>& bits, nanoseconds_t clock);
void precompensate(int threshold_ticks, int amount_ticks);
private:
uint8_t& findLastByte();
private:
nanoseconds_t _duration = 0;
int _ticks = 0;
Bytes _bytes;
};
#endif