aboutsummaryrefslogtreecommitdiffstats
path: root/src/rsdecoder.cpp
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2016-09-02 17:43:32 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2016-09-07 21:20:24 +0200
commit4809f3c042a99a639542b1e6cd22657871113260 (patch)
treedc0ec0f256eaceb79d63daa09591d4a6ef08cb73 /src/rsdecoder.cpp
parent5542c8ecff635f9abc05b6b2ff255db02c2c9c46 (diff)
downloadetisnoop-4809f3c042a99a639542b1e6cd22657871113260.tar.gz
etisnoop-4809f3c042a99a639542b1e6cd22657871113260.tar.bz2
etisnoop-4809f3c042a99a639542b1e6cd22657871113260.zip
Move all sources to src/
Diffstat (limited to 'src/rsdecoder.cpp')
-rw-r--r--src/rsdecoder.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/rsdecoder.cpp b/src/rsdecoder.cpp
new file mode 100644
index 0000000..98ccd39
--- /dev/null
+++ b/src/rsdecoder.cpp
@@ -0,0 +1,83 @@
+/*
+ Copyright (C) 2015 Stefan Pöschel
+
+ Copyright (C) 2015 Matthias P. Braendli (http://www.opendigitalradio.org)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdexcept>
+#include "rsdecoder.hpp"
+
+RSDecoder::RSDecoder()
+{
+ rs_handle = init_rs_char(8, 0x11D, 0, 1, 10, 135);
+ if(!rs_handle)
+ throw std::runtime_error("RSDecoder: error while init_rs_char");
+}
+
+RSDecoder::~RSDecoder()
+{
+ free_rs_char(rs_handle);
+}
+
+int RSDecoder::DecodeSuperframe(std::vector<uint8_t> &sf, int subch_index)
+{
+ int total_corr_count = 0;
+ bool uncorr_errors = false;
+
+ std::vector<int> errors_per_index(subch_index);
+
+ // process all RS packets
+ for(int i = 0; i < subch_index; i++) {
+ for(int pos = 0; pos < 120; pos++)
+ rs_packet[pos] = sf[pos * subch_index + i];
+
+ // detect errors
+ int corr_count = decode_rs_char(rs_handle, rs_packet, corr_pos, 0);
+ errors_per_index[i] = corr_count;
+
+ if(corr_count == -1) {
+ uncorr_errors = true;
+ }
+ else {
+ total_corr_count += corr_count;
+ }
+
+ // correct errors
+ for(int j = 0; j < corr_count; j++) {
+
+ int pos = corr_pos[j] - 135;
+ if(pos < 0)
+ continue;
+
+ // fprintf(stderr, "j: %d, pos: %d, sf-index: %d\n", j, pos, pos * subch_index + i);
+ sf[pos * subch_index + i] = rs_packet[pos];
+ }
+ }
+
+ // output statistics
+ if (total_corr_count || uncorr_errors) {
+ printf("RS uncorrected errors:\n");
+ for (size_t i = 0; i < errors_per_index.size(); i++) {
+ int e = errors_per_index[i];
+ printf(" (%zu: %d)", i, e);
+ }
+ printf("\n");
+ }
+
+ return uncorr_errors ? -1 : total_corr_count;
+}
+
+