Files
fluxengine/lib/fluxmap.h
David Given f634988356 Add support for emitting index sync bytes to the Northstar encoder. This tells
the FluxEngine to wait for the next index pulse before continuing the write.
This also allows FluxEngine to decode its own encoded bytestreams, allowing
encodedecodetest to work.
2022-03-14 22:11:08 +01:00

99 lines
1.9 KiB
C++

#ifndef FLUXMAP_H
#define FLUXMAP_H
#include "bytes.h"
#include "protocol.h"
#include "fmt/format.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;
}
operator std::string()
{
return fmt::format("[b:{}, t:{}, z:{}]", bytes, ticks, zeroes);
}
};
public:
Fluxmap() {}
Fluxmap(const std::string& s)
{
appendBytes((const uint8_t*)s.c_str(), s.size());
}
Fluxmap(const Bytes& bytes)
{
appendBytes(bytes);
}
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& appendDesync();
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);
std::vector<std::unique_ptr<const Fluxmap>> split() const;
std::unique_ptr<const Fluxmap> rescale(double scale) const;
private:
uint8_t& findLastByte();
private:
nanoseconds_t _duration = 0;
int _ticks = 0;
Bytes _bytes;
};
#endif