mirror of
https://github.com/OpenRTX/OpenRTX
synced 2026-08-08 12:29:06 -04:00
M17 protocol code is already namespaced in M17, so it's redundant to name every class M17*. This change removes the leading M17 from all of the namespaced things. Co-authored-by: GitHub Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Ryan Turner <ryan@turnrye.com>
67 lines
1.8 KiB
C++
67 lines
1.8 KiB
C++
/*
|
|
* SPDX-FileCopyrightText: Copyright 2020-2026 OpenRTX Contributors
|
|
*
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
*/
|
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
#include <cstdint>
|
|
#include <random>
|
|
#include <array>
|
|
#include "protocols/M17/ConvolutionalEncoder.hpp"
|
|
#include "protocols/M17/CodePuncturing.hpp"
|
|
#include "protocols/M17/Viterbi.hpp"
|
|
#include "protocols/M17/Utils.hpp"
|
|
|
|
using namespace std;
|
|
|
|
static default_random_engine rng;
|
|
|
|
/**
|
|
* Insert random bit flips in input data.
|
|
*/
|
|
template <size_t N> static void generateErrors(array<uint8_t, N> &data)
|
|
{
|
|
uniform_int_distribution<uint8_t> numErrs(0, 4);
|
|
uniform_int_distribution<uint8_t> errPos(0, N);
|
|
|
|
for (uint8_t i = 0; i < numErrs(rng); i++) {
|
|
uint8_t pos = errPos(rng);
|
|
bool bit = M17::getBit(data, pos);
|
|
M17::setBit(data, pos, !bit);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("Viterbi decode recovers punctured convolutional encoding",
|
|
"[m17][viterbi]")
|
|
{
|
|
uniform_int_distribution<uint8_t> rndValue(0, 255);
|
|
|
|
array<uint8_t, 18> source;
|
|
|
|
for (auto &byte : source) {
|
|
byte = rndValue(rng);
|
|
}
|
|
|
|
array<uint8_t, 37> encoded;
|
|
M17::ConvolutionalEncoder encoder;
|
|
encoder.reset();
|
|
encoder.encode(source.data(), encoded.data(), source.size());
|
|
encoded[36] = encoder.flush();
|
|
|
|
array<uint8_t, 34> punctured;
|
|
M17::puncture(encoded, punctured, M17::DATA_PUNCTURE);
|
|
|
|
generateErrors(punctured);
|
|
|
|
array<uint8_t, 18> result;
|
|
M17::HardViterbi decoder;
|
|
decoder.decodePunctured(punctured, result, M17::DATA_PUNCTURE);
|
|
|
|
for (size_t i = 0; i < result.size(); i++) {
|
|
INFO("Position " << i << ": got 0x" << hex
|
|
<< static_cast<int>(result[i]) << " expected 0x"
|
|
<< static_cast<int>(source[i]));
|
|
REQUIRE(source[i] == result[i]);
|
|
}
|
|
}
|