2022-07-20 03:07:00 -04:00
|
|
|
// Copyright 2020 Mobilinkd LLC.
|
2022-06-06 21:22:18 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <tuple>
|
|
|
|
|
2022-07-04 17:03:07 -04:00
|
|
|
namespace modemm17
|
2022-06-06 21:22:18 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
template <size_t N = 368>
|
|
|
|
struct M17Framer
|
|
|
|
{
|
|
|
|
M17Framer()
|
|
|
|
{
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr size_t size() { return N; }
|
|
|
|
|
|
|
|
size_t operator()(int dibit, int8_t** result)
|
|
|
|
{
|
|
|
|
buffer_[index_++] = (dibit >> 1) ? 1 : -1;
|
|
|
|
buffer_[index_++] = (dibit & 1) ? 1 : -1;
|
|
|
|
if (index_ == N)
|
|
|
|
{
|
|
|
|
index_ = 0;
|
|
|
|
*result = buffer_.data();
|
|
|
|
return N;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// LLR mode
|
|
|
|
size_t operator()(std::tuple<int8_t, int8_t> symbol, int8_t** result)
|
|
|
|
{
|
|
|
|
buffer_[index_++] = std::get<0>(symbol);
|
|
|
|
buffer_[index_++] = std::get<1>(symbol);
|
|
|
|
if (index_ == N)
|
|
|
|
{
|
|
|
|
index_ = 0;
|
|
|
|
*result = buffer_.data();
|
|
|
|
return N;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2022-07-04 17:03:07 -04:00
|
|
|
|
2022-06-06 21:22:18 -04:00
|
|
|
void reset()
|
2022-07-04 17:03:07 -04:00
|
|
|
{
|
2022-06-06 21:22:18 -04:00
|
|
|
buffer_.fill(0);
|
|
|
|
index_ = 0;
|
|
|
|
}
|
2022-07-27 17:38:35 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
alignas(16) std::array<int8_t, N> buffer_;
|
|
|
|
size_t index_ = 0;
|
2022-06-06 21:22:18 -04:00
|
|
|
};
|
|
|
|
|
2022-07-04 17:03:07 -04:00
|
|
|
} // modemm17
|