2015-12-01 14:24:48 -05:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
2024-02-10 10:56:50 -05:00
|
|
|
* Copyright (C) 2023 Mark Thompson
|
2015-12-01 14:24:48 -05:00
|
|
|
*
|
|
|
|
* This file is part of PortaPack.
|
|
|
|
*
|
|
|
|
* 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, 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; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __PROC_ERT_H__
|
|
|
|
#define __PROC_ERT_H__
|
|
|
|
|
|
|
|
#include "baseband_processor.hpp"
|
2016-06-25 14:11:37 -04:00
|
|
|
#include "baseband_thread.hpp"
|
2016-07-25 19:12:13 -04:00
|
|
|
#include "rssi_thread.hpp"
|
2015-12-01 14:24:48 -05:00
|
|
|
|
|
|
|
#include "channel_decimator.hpp"
|
|
|
|
|
|
|
|
#include "clock_recovery.hpp"
|
|
|
|
#include "symbol_coding.hpp"
|
|
|
|
#include "packet_builder.hpp"
|
2015-12-08 18:15:51 -05:00
|
|
|
#include "baseband_packet.hpp"
|
2015-12-01 14:24:48 -05:00
|
|
|
|
|
|
|
#include "message.hpp"
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <bitset>
|
|
|
|
|
|
|
|
// ''.join(['%d%d' % (c, 1-c) for c in map(int, bin(0x1f2a60)[2:].zfill(21))])
|
2023-05-18 16:16:05 -04:00
|
|
|
constexpr uint64_t scm_preamble_and_sync_manchester{0b101010101001011001100110010110100101010101};
|
|
|
|
constexpr size_t scm_preamble_and_sync_length{42 - 10};
|
|
|
|
constexpr size_t scm_payload_length_max{150};
|
2015-12-01 14:24:48 -05:00
|
|
|
|
2023-04-23 02:34:56 -04:00
|
|
|
// ''.join(['%d%d' % (c, 1-c) for c in map(int, bin(0x16a3)[2:].zfill(16))])
|
2023-05-18 16:16:05 -04:00
|
|
|
constexpr uint64_t scmplus_preamble_and_sync_manchester{0b01010110011010011001100101011010};
|
|
|
|
constexpr size_t scmplus_preamble_and_sync_length{32 - 0};
|
|
|
|
constexpr size_t scmplus_payload_length_max{224};
|
2023-04-23 02:34:56 -04:00
|
|
|
|
2015-12-01 14:24:48 -05:00
|
|
|
// ''.join(['%d%d' % (c, 1-c) for c in map(int, bin(0x555516a3)[2:].zfill(32))])
|
2023-05-18 16:16:05 -04:00
|
|
|
constexpr uint64_t idm_preamble_and_sync_manchester{0b0110011001100110011001100110011001010110011010011001100101011010};
|
|
|
|
constexpr size_t idm_preamble_and_sync_length{64 - 16};
|
|
|
|
constexpr size_t idm_payload_length_max{1408};
|
2015-12-01 14:24:48 -05:00
|
|
|
|
|
|
|
class ERTProcessor : public BasebandProcessor {
|
2023-05-18 16:16:05 -04:00
|
|
|
public:
|
|
|
|
void execute(const buffer_c8_t& buffer) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const uint32_t baseband_sampling_rate = 4194304;
|
|
|
|
const size_t decimation = 1;
|
|
|
|
const float symbol_rate = 32768;
|
|
|
|
|
|
|
|
const uint32_t channel_sampling_rate = baseband_sampling_rate / decimation;
|
|
|
|
const size_t samples_per_symbol = channel_sampling_rate / symbol_rate;
|
|
|
|
const float clock_recovery_rate = symbol_rate * 2;
|
|
|
|
|
|
|
|
clock_recovery::ClockRecovery<clock_recovery::FixedErrorFilter> clock_recovery{
|
|
|
|
clock_recovery_rate,
|
|
|
|
symbol_rate,
|
|
|
|
{1.0f / 18.0f},
|
|
|
|
[this](const float symbol) { this->consume_symbol(symbol); }};
|
|
|
|
|
|
|
|
PacketBuilder<BitPattern, NeverMatch, FixedLength> scm_builder{
|
|
|
|
{scm_preamble_and_sync_manchester, scm_preamble_and_sync_length, 1},
|
|
|
|
{},
|
|
|
|
{scm_payload_length_max},
|
|
|
|
[this](const baseband::Packet& packet) {
|
|
|
|
this->scm_handler(packet);
|
|
|
|
}};
|
|
|
|
|
|
|
|
PacketBuilder<BitPattern, NeverMatch, FixedLength> scmplus_builder{
|
|
|
|
{scmplus_preamble_and_sync_manchester, scmplus_preamble_and_sync_length, 1},
|
|
|
|
{},
|
|
|
|
{scmplus_payload_length_max},
|
|
|
|
[this](const baseband::Packet& packet) {
|
|
|
|
this->scmplus_handler(packet);
|
|
|
|
}};
|
|
|
|
|
|
|
|
PacketBuilder<BitPattern, NeverMatch, FixedLength> idm_builder{
|
|
|
|
{idm_preamble_and_sync_manchester, idm_preamble_and_sync_length, 1},
|
|
|
|
{},
|
|
|
|
{idm_payload_length_max},
|
|
|
|
[this](const baseband::Packet& packet) {
|
|
|
|
this->idm_handler(packet);
|
|
|
|
}};
|
|
|
|
|
|
|
|
void consume_symbol(const float symbol);
|
|
|
|
void scm_handler(const baseband::Packet& packet);
|
|
|
|
void scmplus_handler(const baseband::Packet& packet);
|
|
|
|
void idm_handler(const baseband::Packet& packet);
|
|
|
|
|
|
|
|
float sum_half_period[2];
|
|
|
|
float sum_period[3];
|
|
|
|
float manchester[3];
|
|
|
|
|
|
|
|
const size_t average_window{2048};
|
|
|
|
int32_t average_i{0};
|
|
|
|
int32_t average_q{0};
|
|
|
|
size_t average_count{0};
|
|
|
|
float offset_i{0.0f};
|
|
|
|
float offset_q{0.0f};
|
|
|
|
|
2023-07-23 02:54:17 -04:00
|
|
|
/* NB: Threads should be the last members in the class definition. */
|
|
|
|
BasebandThread baseband_thread{baseband_sampling_rate, this, baseband::Direction::Receive};
|
|
|
|
RSSIThread rssi_thread{};
|
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
float abs(const complex8_t& v);
|
2015-12-01 14:24:48 -05:00
|
|
|
};
|
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
#endif /*__PROC_ERT_H__*/
|