mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-23 14:57:29 +00:00
Add basic ERT (OOK) utility meter reception.
Extracted the Manchester formatting function for use in ERT, now also returns an indication of bits in error.
This commit is contained in:
@@ -140,6 +140,7 @@ CPPSRC = main.cpp \
|
||||
proc_ais.cpp \
|
||||
proc_wideband_spectrum.cpp \
|
||||
proc_tpms.cpp \
|
||||
proc_ert.cpp \
|
||||
dsp_squelch.cpp \
|
||||
clock_recovery.cpp \
|
||||
packet_builder.cpp \
|
||||
|
@@ -58,6 +58,7 @@
|
||||
#include "proc_ais.hpp"
|
||||
#include "proc_wideband_spectrum.hpp"
|
||||
#include "proc_tpms.hpp"
|
||||
#include "proc_ert.hpp"
|
||||
|
||||
#include "clock_recovery.hpp"
|
||||
#include "packet_builder.hpp"
|
||||
@@ -370,6 +371,10 @@ int main(void) {
|
||||
baseband_thread.baseband_processor = new TPMSProcessor();
|
||||
break;
|
||||
|
||||
case 6:
|
||||
baseband_thread.baseband_processor = new ERTProcessor();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
117
firmware/baseband/proc_ert.cpp
Normal file
117
firmware/baseband/proc_ert.cpp
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "proc_ert.hpp"
|
||||
|
||||
#include "portapack_shared_memory.hpp"
|
||||
|
||||
#include "i2s.hpp"
|
||||
using namespace lpc43xx;
|
||||
|
||||
float ERTProcessor::abs(const complex8_t& v) {
|
||||
// const int16_t r = v.real() - offset_i;
|
||||
// const int16_t i = v.imag() - offset_q;
|
||||
// const uint32_t r2 = r * r;
|
||||
// const uint32_t i2 = i * i;
|
||||
// const uint32_t r2_i2 = r2 + i2;
|
||||
// return std::sqrt(static_cast<float>(r2_i2));
|
||||
const float r = static_cast<float>(v.real()) - offset_i;
|
||||
const float i = static_cast<float>(v.imag()) - offset_q;
|
||||
const float r2 = r * r;
|
||||
const float i2 = i * i;
|
||||
const float r2_i2 = r2 + i2;
|
||||
return std::sqrt(r2_i2);
|
||||
}
|
||||
|
||||
void ERTProcessor::execute(buffer_c8_t buffer) {
|
||||
/* 4.194304MHz, 2048 samples */
|
||||
// auto decimator_out = decimator.execute(buffer);
|
||||
|
||||
const complex8_t* src = &buffer.p[0];
|
||||
const complex8_t* const src_end = &buffer.p[buffer.count];
|
||||
|
||||
average_i += src->real();
|
||||
average_q += src->imag();
|
||||
average_count++;
|
||||
if( average_count == 2048 ) {
|
||||
offset_i = static_cast<float>(average_i) / 2048.0f;
|
||||
offset_q = static_cast<float>(average_q) / 2048.0f;
|
||||
average_i = 0;
|
||||
average_q = 0;
|
||||
average_count = 0;
|
||||
}
|
||||
|
||||
const float gain = 128 * samples_per_symbol;
|
||||
const float k = 1.0f / gain;
|
||||
|
||||
while(src < src_end) {
|
||||
float sum = 0.0f;
|
||||
for(size_t i=0; i<(samples_per_symbol / 2); i++) {
|
||||
sum += abs(*(src++));
|
||||
}
|
||||
sum_half_period[1] = sum_half_period[0];
|
||||
sum_half_period[0] = sum;
|
||||
|
||||
sum_period[2] = sum_period[1];
|
||||
sum_period[1] = sum_period[0];
|
||||
sum_period[0] = (sum_half_period[0] + sum_half_period[1]) * k;
|
||||
|
||||
manchester[2] = manchester[1];
|
||||
manchester[1] = manchester[0];
|
||||
manchester[0] = sum_period[2] - sum_period[0];
|
||||
|
||||
const auto data = manchester[0] - manchester[2];
|
||||
|
||||
clock_recovery(data);
|
||||
}
|
||||
|
||||
i2s::i2s0::tx_mute();
|
||||
}
|
||||
|
||||
void ERTProcessor::consume_symbol(
|
||||
const float raw_symbol
|
||||
) {
|
||||
const uint_fast8_t sliced_symbol = (raw_symbol >= 0.0f) ? 1 : 0;
|
||||
scm_builder.execute(sliced_symbol);
|
||||
idm_builder.execute(sliced_symbol);
|
||||
}
|
||||
|
||||
void ERTProcessor::scm_handler(
|
||||
const std::bitset<1024>& payload,
|
||||
const size_t bits_received
|
||||
) {
|
||||
ERTPacketMessage message;
|
||||
message.packet.preamble = 0x1f2a60;
|
||||
message.packet.payload = payload;
|
||||
message.packet.bits_received = bits_received;
|
||||
shared_memory.application_queue.push(message);
|
||||
}
|
||||
|
||||
void ERTProcessor::idm_handler(
|
||||
const std::bitset<1024>& payload,
|
||||
const size_t bits_received
|
||||
) {
|
||||
ERTPacketMessage message;
|
||||
message.packet.preamble = 0x555516a3;
|
||||
message.packet.payload = payload;
|
||||
message.packet.bits_received = bits_received;
|
||||
shared_memory.application_queue.push(message);
|
||||
}
|
108
firmware/baseband/proc_ert.hpp
Normal file
108
firmware/baseband/proc_ert.hpp
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
||||
*
|
||||
* 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"
|
||||
|
||||
#include "channel_decimator.hpp"
|
||||
|
||||
#include "clock_recovery.hpp"
|
||||
#include "symbol_coding.hpp"
|
||||
#include "packet_builder.hpp"
|
||||
|
||||
#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))])
|
||||
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 };
|
||||
|
||||
// ''.join(['%d%d' % (c, 1-c) for c in map(int, bin(0x555516a3)[2:].zfill(32))])
|
||||
constexpr uint64_t idm_preamble_and_sync_manchester { 0b0110011001100110011001100110011001010110011010011001100101011010 };
|
||||
constexpr size_t idm_preamble_and_sync_length { 64 - 16 };
|
||||
|
||||
// TODO: Should be 1408, but need to widen pathway to application processor...
|
||||
constexpr size_t idm_payload_length_max { 960 };
|
||||
|
||||
class ERTProcessor : public BasebandProcessor {
|
||||
public:
|
||||
using payload_t = std::bitset<1024>;
|
||||
|
||||
void execute(buffer_c8_t buffer) override;
|
||||
|
||||
private:
|
||||
const uint32_t baseband_sampling_rate = 4194304;
|
||||
const size_t decimation = 1;
|
||||
const uint32_t 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 uint32_t clock_recovery_rate = symbol_rate * 2;
|
||||
|
||||
// ChannelDecimator decimator { ChannelDecimator::DecimationFactor::By2, false };
|
||||
|
||||
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 payload_t& payload, const size_t bits_received) {
|
||||
this->scm_handler(payload, bits_received);
|
||||
}
|
||||
};
|
||||
|
||||
PacketBuilder<BitPattern, NeverMatch, FixedLength> idm_builder {
|
||||
{ idm_preamble_and_sync_manchester, idm_preamble_and_sync_length, 1 },
|
||||
{ },
|
||||
{ idm_payload_length_max },
|
||||
[this](const payload_t& payload, const size_t bits_received) {
|
||||
this->idm_handler(payload, bits_received);
|
||||
}
|
||||
};
|
||||
|
||||
void consume_symbol(const float symbol);
|
||||
void scm_handler(const payload_t& payload, const size_t bits_received);
|
||||
void idm_handler(const payload_t& payload, const size_t bits_received);
|
||||
|
||||
float sum_half_period[2];
|
||||
float sum_period[3];
|
||||
float manchester[3];
|
||||
|
||||
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 };
|
||||
|
||||
float abs(const complex8_t& v);
|
||||
};
|
||||
|
||||
#endif/*__PROC_ERT_H__*/
|
Reference in New Issue
Block a user