/
M17Framer.h
63 lines (52 loc) · 1.17 KB
/
M17Framer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2020 Mobilinkd LLC.
#pragma once
#include <array>
#include <cstddef>
#include <cstdint>
#include <tuple>
namespace mobilinkd
{
template <size_t N = 368>
struct M17Framer
{
using buffer_t = std::array<int8_t, N>;
alignas(4) buffer_t buffer_;
size_t index_ = 0;
M17Framer()
{
reset();
}
static constexpr size_t size() { return N; }
// Expects data in lower two bits of dibit.
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_.begin();
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_.begin();
return N;
}
return 0;
}
void reset()
{
buffer_.fill(0);
index_ = 0;
}
};
} // mobilinkd