From 5371081cc0b6b73c7011136e5ef420fd520da9f5 Mon Sep 17 00:00:00 2001 From: stevie Date: Tue, 7 Jul 2009 21:47:54 +0000 Subject: [PATCH] First cut on Golay decoding of HDU. More to follow git-svn-id: http://op25.osmocom.org/svn/trunk@153 65a5c917-d112-43f1-993d-58c26a4786be --- decoder/src/lib/Makefile.am | 3 +- decoder/src/lib/abstract_data_unit.h | 7 + decoder/src/lib/data_unit.cc | 3 +- decoder/src/lib/data_unit.h | 1 - decoder/src/lib/egolay.cc | 141 +++++++++++++++++++ decoder/src/lib/egolay.h | 83 ++++++++++++ decoder/src/lib/hdu.cc | 171 +++++++++++++----------- decoder/src/lib/hdu.h | 14 -- decoder/src/lib/offline_imbe_decoder.cc | 4 +- decoder/src/lib/op25.i | 2 +- decoder/src/lib/op25_decoder_ff.cc | 8 +- decoder/src/lib/snapshot_du_handler.cc | 1 + decoder/src/lib/sniffer_du_handler.cc | 8 +- decoder/src/lib/tdu.cc | 2 +- decoder/src/lib/value_string.cc | 2 +- decoder/src/lib/vc55_imbe_decoder.cc | 8 +- decoder/src/lib/{swab.h => yank.h} | 19 +-- 17 files changed, 355 insertions(+), 122 deletions(-) create mode 100644 decoder/src/lib/egolay.cc create mode 100644 decoder/src/lib/egolay.h rename decoder/src/lib/{swab.h => yank.h} (86%) diff --git a/decoder/src/lib/Makefile.am b/decoder/src/lib/Makefile.am index 5d88401..2de7f72 100644 --- a/decoder/src/lib/Makefile.am +++ b/decoder/src/lib/Makefile.am @@ -77,7 +77,8 @@ _op25_la_SOURCES = \ op25.cc \ op25_decoder_ff.cc \ vc55_imbe_decoder.cc \ - value_string.cc + value_string.cc \ + egolay.cc # magic flags diff --git a/decoder/src/lib/abstract_data_unit.h b/decoder/src/lib/abstract_data_unit.h index 899ebc5..97adda5 100644 --- a/decoder/src/lib/abstract_data_unit.h +++ b/decoder/src/lib/abstract_data_unit.h @@ -27,6 +27,13 @@ #include #include #include +#include + +#include +#include + +typedef std::vector bit_vector; +typedef const std::vector const_bit_vector; /** * Abstract P25 data unit. diff --git a/decoder/src/lib/data_unit.cc b/decoder/src/lib/data_unit.cc index 57e7301..5c37ee5 100644 --- a/decoder/src/lib/data_unit.cc +++ b/decoder/src/lib/data_unit.cc @@ -26,10 +26,9 @@ #include #include #include -#include #include +#include -#include using namespace std; data_unit_sptr diff --git a/decoder/src/lib/data_unit.h b/decoder/src/lib/data_unit.h index da81555..000c91c 100644 --- a/decoder/src/lib/data_unit.h +++ b/decoder/src/lib/data_unit.h @@ -30,7 +30,6 @@ #include #include #include -#include typedef std::deque bit_queue; typedef const std::deque const_bit_queue; diff --git a/decoder/src/lib/egolay.cc b/decoder/src/lib/egolay.cc new file mode 100644 index 0000000..919c154 --- /dev/null +++ b/decoder/src/lib/egolay.cc @@ -0,0 +1,141 @@ +/*! + * \file + * \brief Implementation of the Extended Golay Code (24, 12, 8) + * \author Tony Ottosson + * + * ------------------------------------------------------------------------- + * + * IT++ - C++ library of mathematical, signal processing, speech processing, + * and communications classes and functions + * + * Copyright (C) 1995-2008 (see AUTHORS file for a list of contributors) + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * ------------------------------------------------------------------------- + */ + +//#include +#include +#include +#include +#include + +namespace itpp { + + My_Extended_Golay::My_Extended_Golay(void) + { +// B="0 1 1 1 1 1 1 1 1 1 1 1;1 1 1 0 1 1 1 0 0 0 1 0;1 1 0 1 1 1 0 0 0 1 0 1;1 0 1 1 1 0 0 0 1 0 1 1;1 1 1 1 0 0 0 1 0 1 1 0;1 1 1 0 0 0 1 0 1 1 0 1;1 1 0 0 0 1 0 1 1 0 1 1;1 0 0 0 1 0 1 1 0 1 1 1;1 0 0 1 0 1 1 0 1 1 1 0;1 0 1 0 1 1 0 1 1 1 0 0;1 1 0 1 1 0 1 1 1 0 0 0;1 0 1 1 0 1 1 1 0 0 0 1"; + + B="1 1 0 0 0 1 1 1 0 1 0 1;0 1 1 0 0 0 1 1 1 0 1 1;1 1 1 1 0 1 1 0 1 0 0 0;0 1 1 1 1 0 1 1 0 1 0 0;0 0 1 1 1 1 0 1 1 0 1 0;1 1 0 1 1 0 0 1 1 0 0 1;0 1 1 0 1 1 0 0 1 1 0 1;0 0 1 1 0 1 1 0 0 1 1 1;1 1 0 1 1 1 0 0 0 1 1 0;1 0 1 0 1 0 0 1 0 1 1 1;1 0 0 1 0 0 1 1 1 1 1 0;1 0 0 0 1 1 1 0 1 0 1 1"; + + G = concat_horizontal(eye_b(12), B); + } + + void My_Extended_Golay::encode(const bvec &uncoded_bits, bvec &coded_bits) + { + int no_bits = uncoded_bits.length(); + int no_blocks = floor_i(no_bits / 12.0); + + coded_bits.set_size(24*no_blocks, false); + bmat Gt = G.T(); + int i; + + for (i=0; i +#include +#include + + +namespace itpp { + + /*! + \ingroup fec + \brief Extended Golay code (24,12,8). + \author Tony Ottosson + + The code is given in systematic form with the information bits + first, followed by the parity check bits. The decoder uses the + arithmetic decoding algorithm that is for example described in + Wicker "Error Control Systems for Digital Communication and + Storage", Prentice Hall, 1995 (page 143). + */ + class My_Extended_Golay : public Channel_Code { + public: + //! Constructor + My_Extended_Golay(); + //! Destructor + virtual ~My_Extended_Golay(){ } + + //! Encoder. Will truncate some bits if not \a length = \c integer * 12 + virtual void encode(const bvec &uncoded_bits, bvec &coded_bits); + //! Encoder. Will truncate some bits if not \a length = \c integer * 12 + virtual bvec encode(const bvec &uncoded_bits); + + //! Decoder. Will truncate some bits if not \a length = \c integer * 24 + virtual void decode(const bvec &coded_bits, bvec &decoded_bits); + //! Decoder. Will truncate some bits if not \a length = \c integer * 24 + virtual bvec decode(const bvec &coded_bits); + + // Soft-decision decoding is not implemented + virtual void decode(const vec &received_signal, bvec &output); + virtual bvec decode(const vec &received_signal); + + //! Get the code rate + virtual double get_rate() const { return 0.5; }; + + //! Gets the generator matrix for the code (also the parity check matrix) + bmat get_G() const { return G; } + private: + bmat B,G; + }; + +} // namespace itpp + +#endif // #ifndef EGOLAY_H diff --git a/decoder/src/lib/hdu.cc b/decoder/src/lib/hdu.cc index 2b79115..1a86d3d 100644 --- a/decoder/src/lib/hdu.cc +++ b/decoder/src/lib/hdu.cc @@ -21,15 +21,17 @@ * 02110-1301, USA. */ +#include #include #include -#include +#include +#include +// #include #include #include -#include #include +#include -#include using namespace std; hdu::hdu(const_bit_queue& frame_body) : @@ -70,18 +72,6 @@ hdu::snapshot() const os << "p" << n++ << endl; os << "S'" << nac_str() << "'" << endl; - // Source - os << "p" << n++ << endl; - os << "sS'source'" << endl; - os << "p" << n++ << endl; - os << "S'" << src_str() << "'" << endl; - - // Dest - os << "p" << n++ << endl; - os << "sS'dest'" << endl; - os << "p" << n++ << endl; - os << "S'" << dest_str() << "'" << endl; - // MFID os << "p" << n++ << endl; os << "sS'mfid'" << endl; @@ -129,52 +119,64 @@ hdu::correct_errors(bit_vector& frame) void hdu::apply_golay_correction(bit_vector& frame) { -#if 0 - static itpp::Extended_Golay golay; - static const size_t NOF_GOLAY_CODEWORDS = 36, GOLAY_CODEWORD_SZ = 18; - static const size_t GOLAY_CODEWORDS[nof_golay_codewords][golay_codeword_sz] = { - { 119, 118, 117, 116, 115, 114, 131, 130, 129, 128, 127, 126, 125, 124, 123, 122, 121, 120 }, - { 137, 136, 135, 134, 133, 132, 151, 150, 149, 148, 147, 146, 145, 144, 141, 140, 139, 138 }, - { 157, 156, 155, 154, 153, 152, 169, 168, 167, 166, 165, 164, 163, 162, 161, 160, 159, 158 }, - { 175, 174, 173, 172, 171, 170, 187, 186, 185, 184, 183, 182, 181, 180, 179, 178, 177, 176 }, - { 193, 192, 191, 190, 189, 188, 205, 204, 203, 202, 201, 200, 199, 198, 197, 196, 195, 194 }, - { 211, 210, 209, 208, 207, 206, 225, 224, 223, 222, 221, 220, 219, 218, 217, 216, 213, 212 }, - { 231, 230, 229, 228, 227, 226, 243, 242, 241, 240, 239, 238, 237, 236, 235, 234, 233, 232 }, - { 249, 248, 247, 246, 245, 244, 261, 260, 259, 258, 257, 256, 255, 254, 253, 252, 251, 250 }, - { 267, 266, 265, 264, 263, 262, 279, 278, 277, 276, 275, 274, 273, 272, 271, 270, 269, 268 }, - { 285, 284, 283, 282, 281, 280, 299, 298, 297, 296, 295, 294, 293, 292, 291, 290, 289, 288 }, - { 305, 304, 303, 302, 301, 300, 317, 316, 315, 314, 313, 312, 311, 310, 309, 308, 307, 306 }, - { 323, 322, 321, 320, 319, 318, 335, 334, 333, 332, 331, 330, 329, 328, 327, 326, 325, 324 }, - { 341, 340, 339, 338, 337, 336, 353, 352, 351, 350, 349, 348, 347, 346, 345, 344, 343, 342 }, - { 361, 360, 357, 356, 355, 354, 373, 372, 371, 370, 369, 368, 367, 366, 365, 364, 363, 362 }, - { 379, 378, 377, 376, 375, 374, 391, 390, 389, 388, 387, 386, 385, 384, 383, 382, 381, 380 }, - { 397, 396, 395, 394, 393, 392, 409, 408, 407, 406, 405, 404, 403, 402, 401, 400, 399, 398 }, - { 415, 414, 413, 412, 411, 410, 427, 426, 425, 424, 423, 422, 421, 420, 419, 418, 417, 416 }, - { 435, 434, 433, 432, 429, 428, 447, 446, 445, 444, 443, 442, 441, 440, 439, 438, 437, 436 }, - { 453, 452, 451, 450, 449, 448, 465, 464, 463, 462, 461, 460, 459, 458, 457, 456, 455, 454 }, - { 471, 470, 469, 468, 467, 466, 483, 482, 481, 480, 479, 478, 477, 476, 475, 474, 473, 472 }, - { 489, 488, 487, 486, 485, 484, 501, 500, 499, 498, 497, 496, 495, 494, 493, 492, 491, 490 }, - { 509, 508, 507, 506, 505, 504, 521, 520, 519, 518, 517, 516, 515, 514, 513, 512, 511, 510 }, - { 527, 526, 525, 524, 523, 522, 539, 538, 537, 536, 535, 534, 533, 532, 531, 530, 529, 528 }, - { 545, 544, 543, 542, 541, 540, 557, 556, 555, 554, 553, 552, 551, 550, 549, 548, 547, 546 }, - { 563, 562, 561, 560, 559, 558, 577, 576, 573, 572, 571, 570, 569, 568, 567, 566, 565, 564 }, - { 583, 582, 581, 580, 579, 578, 595, 594, 593, 592, 591, 590, 589, 588, 587, 586, 585, 584 }, - { 601, 600, 599, 598, 597, 596, 613, 612, 611, 610, 609, 608, 607, 606, 605, 604, 603, 602 }, - { 619, 618, 617, 616, 615, 614, 631, 630, 629, 628, 627, 626, 625, 624, 623, 622, 621, 620 }, - { 637, 636, 635, 634, 633, 632, 651, 650, 649, 648, 645, 644, 643, 642, 641, 640, 639, 638 }, - { 657, 656, 655, 654, 653, 652, 669, 668, 667, 666, 665, 664, 663, 662, 661, 660, 659, 658 }, - { 675, 674, 673, 672, 671, 670, 687, 686, 685, 684, 683, 682, 681, 680, 679, 678, 677, 676 }, - { 693, 692, 691, 690, 689, 688, 705, 704, 703, 702, 701, 700, 699, 698, 697, 696, 695, 694 }, - { 711, 710, 709, 708, 707, 706, 725, 724, 723, 722, 721, 720, 717, 716, 715, 714, 713, 712 }, - { 731, 730, 729, 728, 727, 726, 743, 742, 741, 740, 739, 738, 737, 736, 735, 734, 733, 732 }, - { 749, 748, 747, 746, 745, 744, 761, 760, 759, 758, 757, 756, 755, 754, 753, 752, 751, 750 }, - { 767, 766, 765, 764, 763, 762, 779, 778, 777, 776, 775, 774, 773, 772, 771, 770, 769, 768 } - }; - - for(size_t i = 0; i < NOF_GOLAY_CODEWORDS; ++i) { - // ToDo: - } + static itpp::My_Extended_Golay golay; + static const size_t NOF_GOLAY_CODEWORDS = 2, GOLAY_DATA_SZ = 6, GOLAY_CODEWORD_SZ = 18; +// static const size_t NOF_GOLAY_CODEWORDS = 36, GOLAY_DATA_SZ = 6, GOLAY_CODEWORD_SZ = 18; + static const size_t GOLAY_CODEWORDS[NOF_GOLAY_CODEWORDS][GOLAY_CODEWORD_SZ] = { +#if 1 + { 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131 }, + { 131, 130, 129, 128, 127, 126, 125, 124, 123, 122, 121, 120, 119, 118, 117, 116, 115, 114 } +#else + { 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131 }, + { 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 144, 145, 146, 147, 148, 149, 150, 151 }, + { 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169 }, + { 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187 }, + { 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205 }, + { 206, 207, 208, 209, 210, 211, 212, 213, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225 }, + { 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243 }, + { 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261 }, + { 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279 }, + { 280, 281, 282, 283, 284, 285, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299 }, + { 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317 }, + { 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335 }, + { 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353 }, + { 354, 355, 356, 357, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373 }, + { 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391 }, + { 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409 }, + { 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427 }, + { 428, 429, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447 }, + { 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465 }, + { 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483 }, + { 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, 501 }, + { 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, 521 }, + { 522, 523, 524, 525, 526, 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539 }, + { 540, 541, 542, 543, 544, 545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557 }, + { 558, 559, 560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 576, 577 }, + { 578, 579, 580, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590, 591, 592, 593, 594, 595 }, + { 596, 597, 598, 599, 600, 601, 602, 603, 604, 605, 606, 607, 608, 609, 610, 611, 612, 613 }, + { 614, 615, 616, 617, 618, 619, 620, 621, 622, 623, 624, 625, 626, 627, 628, 629, 630, 631 }, + { 632, 633, 634, 635, 636, 637, 638, 639, 640, 641, 642, 643, 644, 645, 648, 649, 650, 651 }, + { 652, 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663, 664, 665, 666, 667, 668, 669 }, + { 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, 680, 681, 682, 683, 684, 685, 686, 687 }, + { 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, 699, 700, 701, 702, 703, 704, 705 }, + { 706, 707, 708, 709, 710, 711, 712, 713, 714, 715, 716, 717, 720, 721, 722, 723, 724, 725 }, + { 726, 727, 728, 729, 730, 731, 732, 733, 734, 735, 736, 737, 738, 739, 740, 741, 742, 743 }, + { 744, 745, 746, 747, 748, 749, 750, 751, 752, 753, 754, 755, 756, 757, 758, 759, 760, 761 }, + { 762, 763, 764, 765, 766, 767, 768, 769, 770, 771, 772, 773, 774, 775, 776, 777, 778, 779 } #endif + }; + for(size_t i = 0; i < NOF_GOLAY_CODEWORDS; ++i) { + const size_t PAD_SZ = 6; + itpp::bvec b(PAD_SZ + GOLAY_CODEWORD_SZ); + b.zeros(); + yank(frame, GOLAY_CODEWORDS[i], GOLAY_CODEWORD_SZ, b, PAD_SZ); + itpp::bvec d(golay.decode(b)); +// yank_back(d, PAD_SZ, frame, GOLAY_CODEWORDS[i], GOLAY_DATA_SZ); + + clog << " IN:" << b << endl; + clog << "OUT:" << d << endl; + clog << endl; + } } void @@ -207,16 +209,18 @@ hdu::algid_str() const return lookup(algid, ALGIDS, ALGIDS_SZ); } -string -hdu::dest_str() const -{ - return "ToDo"; -} - string hdu::kid_str() const { - return "ToDo"; + const size_t KID_BITS[] = { + 378, 379, 392, 393, 394, 395, 396, 397, + 410, 411, 412, 413, 414, 415, 428, 429 + }; + const size_t KID_BITS_SZ = sizeof(KID_BITS) / sizeof(KID_BITS[0]); + uint16_t kid = extract(frame_body(), KID_BITS, KID_BITS_SZ); + ostringstream os; + os << hex << showbase << setfill('0') << setw(4) << kid; + return os.str(); } std::string @@ -238,12 +242,13 @@ hdu::mi_str() const uint8_t mi[9]; extract(frame_body(), MI_BITS, MI_BITS_SZ, mi); ostringstream os; + os << "0x"; for(size_t i = 0; i < (sizeof(mi) / sizeof(mi[0])); ++i) { uint16_t octet = mi[i]; os << hex << setfill('0') << setw(2) << octet; } - clog << os.str() << endl; + clog << os.str() << endl; // diagnostix return os.str(); } @@ -270,14 +275,30 @@ hdu::nac_str() const return lookup(nac, NACS, NACS_SZ); } -string -hdu::src_str() const -{ - return "ToDo"; -} - string hdu::tgid_str() const { - return "ToDo"; + const size_t TGID_BITS[] = { + 432, + 433, + 434, + 435, + 448, + 449, + 450, + 451, + 452, + 453, + 466, + 467, + 468, + 469, + 470, + 471 + }; + const size_t TGID_BITS_SZ = sizeof(TGID_BITS) / sizeof(TGID_BITS[0]); + const uint16_t tgid = extract(frame_body(), TGID_BITS, TGID_BITS_SZ); + ostringstream os; + os << hex << showbase << setfill('0') << setw(4) << tgid; + return os.str(); } diff --git a/decoder/src/lib/hdu.h b/decoder/src/lib/hdu.h index 82d5576..a93fc7d 100644 --- a/decoder/src/lib/hdu.h +++ b/decoder/src/lib/hdu.h @@ -105,13 +105,6 @@ private: */ std::string algid_str() const; - /** - * Returns a string describing the message destination. - * - * \return A string identifying the source. - */ - virtual std::string dest_str() const; - /** * Returns a string describing the key id (KID). * @@ -140,13 +133,6 @@ private: */ virtual std::string nac_str() const; - /** - * Returns a string describing the message source. - * - * \return A string identifying the source. - */ - virtual std::string src_str() const; - /** * Returns a string describing the talk group id (TGID). * diff --git a/decoder/src/lib/offline_imbe_decoder.cc b/decoder/src/lib/offline_imbe_decoder.cc index cc25a7d..3b137ea 100644 --- a/decoder/src/lib/offline_imbe_decoder.cc +++ b/decoder/src/lib/offline_imbe_decoder.cc @@ -22,9 +22,9 @@ */ #include -#include -#include #include +#include +#include using namespace std; diff --git a/decoder/src/lib/op25.i b/decoder/src/lib/op25.i index e5ef824..9d9886f 100644 --- a/decoder/src/lib/op25.i +++ b/decoder/src/lib/op25.i @@ -26,7 +26,7 @@ GR_SWIG_BLOCK_MAGIC(op25, decoder_ff); op25_decoder_ff_sptr op25_make_decoder_ff(gr_msg_queue_sptr msgq); /* - * The actual op25_decoder block. + * The op25_decoder block. */ class op25_decoder_ff : public gr_block { diff --git a/decoder/src/lib/op25_decoder_ff.cc b/decoder/src/lib/op25_decoder_ff.cc index 743ad7f..319075a 100644 --- a/decoder/src/lib/op25_decoder_ff.cc +++ b/decoder/src/lib/op25_decoder_ff.cc @@ -32,6 +32,7 @@ #include #include #include +#include using namespace std; @@ -122,7 +123,7 @@ op25_decoder_ff::correlated() ++errs; } } - return (errs <= 6); + return (errs <= 4); } bool @@ -142,12 +143,12 @@ op25_decoder_ff::identified() itpp::bvec b(63), zeroes(16); itpp::BCH bch(63, 16, 11,"6 3 3 1 1 4 1 3 6 7 2 3 5 4 5 3", true); - swab(d_frame_hdr, NID, NID_SZ, b, 0); + yank(d_frame_hdr, NID, NID_SZ, b, 0); b = bch.decode(b); bool identified(b != zeroes); if(identified) { b = bch.encode(b); - unswab(b, 0, d_frame_hdr, NID, NID_SZ); + yank_back(b, 0, d_frame_hdr, NID, NID_SZ); d_data_unit = data_unit::make_data_unit(d_frame_hdr); } else { data_unit_sptr null; @@ -184,6 +185,7 @@ op25_decoder_ff::receive_symbol(dibit d) case READING: d_data_unit->extend(d); if(d_data_unit->is_complete()) { + d_data_unit->correct_errors(); d_data_unit_handler->handle(d_data_unit); data_unit_sptr null; d_data_unit = null; diff --git a/decoder/src/lib/snapshot_du_handler.cc b/decoder/src/lib/snapshot_du_handler.cc index f531cd5..a2e1399 100644 --- a/decoder/src/lib/snapshot_du_handler.cc +++ b/decoder/src/lib/snapshot_du_handler.cc @@ -21,6 +21,7 @@ * 02110-1301, USA. */ +#include #include #include diff --git a/decoder/src/lib/sniffer_du_handler.cc b/decoder/src/lib/sniffer_du_handler.cc index 6a5b087..37cf61f 100644 --- a/decoder/src/lib/sniffer_du_handler.cc +++ b/decoder/src/lib/sniffer_du_handler.cc @@ -21,13 +21,13 @@ * 02110-1301, USA. */ -#include "sniffer_du_handler.h" - -#include +#include +#include #include +#include +#include #include #include -#include sniffer_du_handler::sniffer_du_handler(data_unit_handler_sptr next) : data_unit_handler(next), diff --git a/decoder/src/lib/tdu.cc b/decoder/src/lib/tdu.cc index 733d1f6..d63a229 100644 --- a/decoder/src/lib/tdu.cc +++ b/decoder/src/lib/tdu.cc @@ -24,8 +24,8 @@ #include #include #include -#include #include +#include using std::string; diff --git a/decoder/src/lib/value_string.cc b/decoder/src/lib/value_string.cc index fed7927..7673d85 100644 --- a/decoder/src/lib/value_string.cc +++ b/decoder/src/lib/value_string.cc @@ -41,7 +41,7 @@ lookup(uint16_t value, const value_string mappings[], size_t mappings_sz) } } ostringstream os; - os << "Unknown (" << hex << value << ")"; + os << "Unknown (" << hex << showbase << value << ")"; return os.str(); } diff --git a/decoder/src/lib/vc55_imbe_decoder.cc b/decoder/src/lib/vc55_imbe_decoder.cc index 07c155c..c7d6ae0 100644 --- a/decoder/src/lib/vc55_imbe_decoder.cc +++ b/decoder/src/lib/vc55_imbe_decoder.cc @@ -21,15 +21,15 @@ * 02110-1301, USA. */ -#include #include -#include +#include +#include #include +#include #include #include -#include -#include #include +#include #include #include diff --git a/decoder/src/lib/swab.h b/decoder/src/lib/yank.h similarity index 86% rename from decoder/src/lib/swab.h rename to decoder/src/lib/yank.h index ad07a0f..2836e83 100644 --- a/decoder/src/lib/swab.h +++ b/decoder/src/lib/yank.h @@ -1,15 +1,8 @@ #ifndef INCLUDED_SWAB_H #define INCLUDED_SWAB_H -#include -#include -#include - -typedef std::vector bit_vector; -typedef const std::vector const_bit_vector; - /** - * Swab in[bits[0)..bits[bits_sz)) to out[where..where+bits_sz). + * Yank in[bits[0]..bits[bits_sz]) to out[where,where+bits_sz). * * \param in A const reference to the source. * \param bits An array specifying the ordinals of the bits to copy. @@ -18,7 +11,7 @@ typedef const std::vector const_bit_vector; * \param where The offset of the first bit to write. */ template -void swab(const X& in, const size_t bits[], size_t bits_sz, Y& out, size_t where) +void yank(const X& in, const size_t bits[], size_t bits_sz, Y& out, size_t where) { for(size_t i = 0; i < bits_sz; ++i) { out[where+i] = in[bits[i]]; @@ -26,7 +19,7 @@ void swab(const X& in, const size_t bits[], size_t bits_sz, Y& out, size_t where } /** - * Swab from in[0..bits_sz) to out[bits[0)..bits[bits_sz)). + * Yank back from in[where,where+bits_sz) to out[bits[0]..bits[bits_sz]). * * \param in A const reference to the source. * \param where The offset of the first bit to read. @@ -35,7 +28,7 @@ void swab(const X& in, const size_t bits[], size_t bits_sz, Y& out, size_t where * \param bits_sz The size of the bits array. */ template -void unswab(const X& in, size_t where, Y& out, const size_t bits[], size_t bits_sz) +void yank_back(const X& in, size_t where, Y& out, const size_t bits[], size_t bits_sz) { for(size_t i = 0; i < bits_sz; ++i) { out[bits[i]] = in[where+i]; @@ -55,7 +48,7 @@ template size_t extract(const X& in, int begin, int end, uint8_t *out) { const size_t out_sz = (7 + end - begin) / 8; - memset(out, 0, out_sz); + std::fill(out, out + out_sz, 0); for(int i = begin, j = 0; i < end; ++i, ++j) { out[j / 8] ^= in[i] << (7 - (j % 8)); } @@ -75,7 +68,7 @@ template size_t extract(const X& in, const size_t bits[], size_t bits_sz, uint8_t *out) { const size_t out_sz = (7 + bits_sz) / 8; - memset(out, 0, out_sz); + std::fill(out, out + out_sz, 0); for(size_t i = 0; i < bits_sz; ++i) { out[i / 8] ^= in[bits[i]] << (7 - (i % 8)); }