From c648ffe377948e4700e64e3d83e35dbb77947452 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Izzo?= Date: Sat, 6 Nov 2021 12:31:08 +0100 Subject: [PATCH] Add draft of M17Demodulator class --- .../include/protocols/M17/M17Demodulator.h | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 openrtx/include/protocols/M17/M17Demodulator.h diff --git a/openrtx/include/protocols/M17/M17Demodulator.h b/openrtx/include/protocols/M17/M17Demodulator.h new file mode 100644 index 00000000..d20e438c --- /dev/null +++ b/openrtx/include/protocols/M17/M17Demodulator.h @@ -0,0 +1,98 @@ +/*************************************************************************** + * Copyright (C) 2021 by Federico Amedeo Izzo IU2NUO, * + * Niccolò Izzo IU2KIN * + * Wojciech Kaczmarski SP5WWP * + * 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 * + ***************************************************************************/ + +#ifndef M17_DEMODULATOR_H +#define M17_DEMODULATOR_H + +#ifndef __cplusplus +#error This header is C++ only! +#endif + +namespace M17 +{ + +class M17Demodulator +{ +public: + + /** + * Constructor. + */ + M17Demodulator(); + + /** + * Destructor. + */ + ~M17Demodulator(); + + /** + * Allocate buffers for baseband signal sampling and initialise demodulator. + */ + void init(); + + /** + * Shutdown modulator and deallocate data buffers. + */ + void terminate(); + + /** + * Starts the sampling of the baseband signal in a double buffer. + */ + void startBasebandSampling(); + + /** + * Stops the sampling of the baseband signal in a double buffer. + */ + void stopBasebandSampling(); + + /** + * Returns the next frame decoded from the baseband signal + */ + const std::array& nextFrame(); + +}; + +private: + + /** + * M17 syncword symbols after RRC sampled at 5 samples per symbol; + */ + uint8_t syncword[] = { }; + + using dataBuffer_t = std::array< int16_t, M17_FRAME_SAMPLES >; + using dataFrame_t = std::array< int8_t, M17_FRAME_SYMBOLS >; + + int16_t *baseband_buffer; ///< Buffer for baseband audio handling. + dataBuffer_t *activeBuffer; ///< Half baseband buffer, in reception. + dataBuffer_t *idleBuffer; ///< Half baseband buffer, to be processed. + dataFrame_t *activeFrame; ///< Half frame, in demodulation. + dataFrame_t *idleFrame; ///< Half frame, free to be processed. + + /** + * Finds the index of the next syncword in the baseband stream. + * + * @param baseband: buffer containing the sampled baseband signal + * @param offset: offset of the buffer after which syncword are searched + * @return uint16_t index of the first syncword in the buffer after the offset + */ uint16_t nextSyncWord(int16_t *baseband); + +#endif /* M17_DEMODULATOR_H */