kopia lustrzana https://github.com/OpenRTX/OpenRTX
Implementation of M17 code puncturing scheme
rodzic
d545071df6
commit
ee1b111fb7
|
|
@ -18,8 +18,8 @@
|
|||
* along with this program; if not, see <http://www.gnu.org/licenses/> *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef M17CALLSIGN_H
|
||||
#define M17CALLSIGN_H
|
||||
#ifndef M17_CALLSIGN_H
|
||||
#define M17_CALLSIGN_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error This header is C++ only!
|
||||
|
|
@ -52,4 +52,4 @@ bool encode_callsign(const std::string& callsign, call_t& encodedCall,
|
|||
*/
|
||||
std::string decode_callsign(const call_t& encodedCall);
|
||||
|
||||
#endif /* M17CALLSIGN_H */
|
||||
#endif /* M17_CALLSIGN_H */
|
||||
|
|
|
|||
|
|
@ -0,0 +1,90 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2021 by Federico Amedeo Izzo IU2NUO, *
|
||||
* Niccolò Izzo IU2KIN *
|
||||
* Frederik Saraci IU2NRO *
|
||||
* Silvano Seva IU2KWO *
|
||||
* *
|
||||
* Adapted from original code written by Rob Riggs, Mobilinkd LLC *
|
||||
* *
|
||||
* 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/> *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef M17_CODE_PUNCTURING_H
|
||||
#define M17_CODE_PUNCTURING_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error This header is C++ only!
|
||||
#endif
|
||||
|
||||
#include <experimental/array>
|
||||
#include "M17Utils.h"
|
||||
|
||||
|
||||
/**
|
||||
* Puncture matrix for linx setup frame.
|
||||
*/
|
||||
static constexpr auto LSF_puncture = std::experimental::make_array< uint8_t >
|
||||
(
|
||||
1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0,
|
||||
1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0,
|
||||
1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1,
|
||||
0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1,
|
||||
0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1,
|
||||
1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Puncture matrix for audio frames.
|
||||
*/
|
||||
static constexpr auto Audio_puncture = std::experimental::make_array< uint8_t >
|
||||
(
|
||||
1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 0
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Apply a given puncturing scheme to a byte array.
|
||||
*
|
||||
* \param input: input byte array.
|
||||
* \param output: output byte array, containing puntured data.
|
||||
* \param puncture: puncturing matrix, stored as an array of 8 bit values.
|
||||
* \return resulting bit count after punturing.
|
||||
*/
|
||||
template < size_t IN, size_t OUT, size_t P >
|
||||
size_t puncture(const std::array< uint8_t, IN >& input,
|
||||
std::array< uint8_t, OUT >& output,
|
||||
const std::array< uint8_t, P >& puncture)
|
||||
{
|
||||
size_t outIndex = 0;
|
||||
size_t punctIndex = 0;
|
||||
size_t bit_count = 0;
|
||||
|
||||
for(size_t i = 0; i < 8*IN && outIndex < 8*OUT; i++)
|
||||
{
|
||||
if(puncture[punctIndex++])
|
||||
{
|
||||
setBit(output, outIndex++, getBit(input, i));
|
||||
bit_count++;
|
||||
}
|
||||
|
||||
if(punctIndex == P) punctIndex = 0;
|
||||
}
|
||||
|
||||
return bit_count;
|
||||
}
|
||||
|
||||
|
||||
#endif /* M17_CODE_PUNCTURING_H */
|
||||
|
|
@ -20,8 +20,8 @@
|
|||
* along with this program; if not, see <http://www.gnu.org/licenses/> *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef M17CONVOLUTIONALENCODER_H
|
||||
#define M17CONVOLUTIONALENCODER_H
|
||||
#ifndef M17_CONVOLUTIONAL_ENCODER_H
|
||||
#define M17_CONVOLUTIONAL_ENCODER_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error This header is C++ only!
|
||||
|
|
@ -111,4 +111,4 @@ private:
|
|||
uint8_t memory = 0; ///< Convolutional encoder memory.
|
||||
};
|
||||
|
||||
#endif /* M17CONVOLUTIONALENCODER_H */
|
||||
#endif /* M17_CONVOLUTIONAL_ENCODER_H */
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@
|
|||
* along with this program; if not, see <http://www.gnu.org/licenses/> *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef M17DATATYPES_H
|
||||
#define M17DATATYPES_H
|
||||
#ifndef M17_DATATYPES_H
|
||||
#define M17_DATATYPES_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <array>
|
||||
|
|
@ -75,4 +75,4 @@ typedef struct
|
|||
}
|
||||
__attribute__((packed)) dataFrame_t;
|
||||
|
||||
#endif /* M17DATATYPES_H */
|
||||
#endif /* M17_DATATYPES_H */
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@
|
|||
* along with this program; if not, see <http://www.gnu.org/licenses/> *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef M17FRAME_H
|
||||
#define M17FRAME_H
|
||||
#ifndef M17_FRAME_H
|
||||
#define M17_FRAME_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error This header is C++ only!
|
||||
|
|
@ -115,4 +115,4 @@ private:
|
|||
dataFrame_t data; ///< Underlying frame data.
|
||||
};
|
||||
|
||||
#endif /* M17FRAME_H */
|
||||
#endif /* M17_FRAME_H */
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@
|
|||
* along with this program; if not, see <http://www.gnu.org/licenses/> *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef M17LINKSETUPFRAME_H
|
||||
#define M17LINKSETUPFRAME_H
|
||||
#ifndef M17_LINKSETUPFRAME_H
|
||||
#define M17_LINKSETUPFRAME_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error This header is C++ only!
|
||||
|
|
@ -125,4 +125,4 @@ private:
|
|||
lsf_t data; ///< Underlying frame data.
|
||||
};
|
||||
|
||||
#endif /* M17LINKSETUPFRAME_H */
|
||||
#endif /* M17_LINKSETUPFRAME_H */
|
||||
|
|
|
|||
|
|
@ -0,0 +1,70 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2021 by Federico Amedeo Izzo IU2NUO, *
|
||||
* Niccolò Izzo IU2KIN *
|
||||
* Frederik Saraci IU2NRO *
|
||||
* Silvano Seva IU2KWO *
|
||||
* *
|
||||
* *
|
||||
* 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/> *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef M17_UTILS_H
|
||||
#define M17_UTILS_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error This header is C++ only!
|
||||
#endif
|
||||
|
||||
#include <array>
|
||||
|
||||
|
||||
/**
|
||||
* Utility function allowing to retrieve the value of a single bit from an array
|
||||
* of bytes. Bits are counted scanning from left to right, thus bit number zero
|
||||
* is the leftmost bit of array[0].
|
||||
*
|
||||
* \param array: byte array.
|
||||
* \param pos: bit position inside the array.
|
||||
* \return value of the indexed bit, as boolean variable.
|
||||
*/
|
||||
template < size_t N >
|
||||
inline bool getBit(const std::array< uint8_t, N >& array, const size_t pos)
|
||||
{
|
||||
size_t i = pos / 8;
|
||||
size_t j = pos % 8;
|
||||
return (array[i] >> (7 - j)) & 0x01;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Utility function allowing to set the value of a single bit from an array
|
||||
* of bytes. Bits are counted scanning from left to right, thus bit number zero
|
||||
* is the leftmost bit of array[0].
|
||||
*
|
||||
* \param array: byte array.
|
||||
* \param pos: bit position inside the array.
|
||||
* \param bit: bit value to be set.
|
||||
*/
|
||||
template < size_t N >
|
||||
inline void setBit(std::array< uint8_t, N >& array, const size_t pos,
|
||||
const bool bit)
|
||||
{
|
||||
size_t i = pos / 8;
|
||||
size_t j = pos % 8;
|
||||
uint8_t mask = 1 << (7 - j);
|
||||
array[i] = (array[i] & ~mask) |
|
||||
(bit ? mask : 0x00);
|
||||
}
|
||||
|
||||
#endif /* M17_UTILS_H */
|
||||
Ładowanie…
Reference in New Issue