Commit replay stuff before sync

This commit is contained in:
furrtek
2017-01-10 19:45:40 +00:00
parent 3ec725c172
commit 12aeae3a82
19 changed files with 1210 additions and 22 deletions

View File

@@ -114,6 +114,7 @@ set(CPPSRC
matched_filter.cpp
spectrum_collector.cpp
stream_input.cpp
stream_output.cpp
dsp_squelch.cpp
clock_recovery.cpp
packet_builder.cpp
@@ -368,12 +369,12 @@ set(MODE_CPPSRC
)
DeclareTargets(PAFS afsk)
### Epar
### Replay
#set(MODE_CPPSRC
# proc_epar.cpp
#)
#DeclareTargets(PEPR epar)
set(MODE_CPPSRC
proc_replay.cpp
)
DeclareTargets(PREP replay)
### Tones

View File

@@ -0,0 +1,84 @@
/*
* Copyright (C) 2016 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2016 Furrtek
*
* 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_replay.hpp"
//#include "dsp_fir_taps.hpp"
#include "event_m4.hpp"
#include "utility.hpp"
ReplayProcessor::ReplayProcessor() {
}
void ReplayProcessor::execute(const buffer_c8_t& buffer) {
/* 2.4576MHz, 2048 samples */
const auto decim_0_out = decim_0.execute(buffer, dst_buffer);
const auto decim_1_out = decim_1.execute(decim_0_out, dst_buffer);
const auto& decimator_out = decim_1_out;
const auto& channel = decimator_out;
if( stream ) {
const size_t bytes_to_write = sizeof(*decimator_out.p) * decimator_out.count;
const auto result = stream->write(decimator_out.p, bytes_to_write);
}
feed_channel_stats(channel);
/*spectrum_samples += channel.count;
if( spectrum_samples >= spectrum_interval_samples ) {
spectrum_samples -= spectrum_interval_samples;
channel_spectrum.feed(channel, channel_filter_pass_f, channel_filter_stop_f);
}*/
}
void ReplayProcessor::on_message(const Message* const message) {
switch(message->id) {
/*case Message::ID::UpdateSpectrum:
case Message::ID::SpectrumStreamingConfig:
channel_spectrum.on_message(message);
break;*/
case Message::ID::ReplayConfig:
replay_config(*reinterpret_cast<const ReplayConfigMessage*>(message));
break;
default:
break;
}
}
void ReplayProcessor::replay_config(const ReplayConfigMessage& message) {
if( message.config ) {
stream = std::make_unique<StreamOutput>(message.config);
} else {
stream.reset();
}
}
int main() {
EventDispatcher event_dispatcher { std::make_unique<ReplayProcessor>() };
event_dispatcher.run();
return 0;
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright (C) 2016 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2016 Furrtek
*
* 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_REPLAY_HPP__
#define __PROC_REPLAY_HPP__
#include "baseband_processor.hpp"
#include "baseband_thread.hpp"
//#include "rssi_thread.hpp"
//#include "dsp_decimate.hpp"
//#include "spectrum_collector.hpp"
#include "stream_output.hpp"
#include <array>
#include <memory>
class ReplayProcessor : public BasebandProcessor {
public:
ReplayProcessor();
void execute(const buffer_c8_t& buffer) override;
void on_message(const Message* const message) override;
private:
// TODO: Repeated value needs to be transmitted from application side.
static constexpr size_t baseband_fs = 4000000;
//static constexpr auto spectrum_rate_hz = 50.0f;
BasebandThread baseband_thread { baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Transmit };
//RSSIThread rssi_thread { NORMALPRIO + 10 };
std::array<complex16_t, 512> dst;
const buffer_c16_t dst_buffer {
dst.data(),
dst.size()
};
std::unique_ptr<StreamOutput> stream;
/*SpectrumCollector channel_spectrum;
size_t spectrum_interval_samples = 0;
size_t spectrum_samples = 0;*/
void replay_config(const ReplayConfigMessage& message);
};
#endif/*__PROC_REPLAY_HPP__*/

View File

@@ -0,0 +1,76 @@
/*
* Copyright (C) 2016 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2016 Furrtek
*
* 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 "stream_output.hpp"
#include "lpc43xx_cpp.hpp"
using namespace lpc43xx;
StreamOutput::StreamOutput(ReplayConfig* const config) :
fifo_buffers_empty { buffers_empty.data(), buffer_count_max_log2 },
fifo_buffers_full { buffers_full.data(), buffer_count_max_log2 },
config { config },
data { std::make_unique<uint8_t[]>(config->read_size * config->buffer_count) }
{
config->fifo_buffers_empty = &fifo_buffers_empty;
config->fifo_buffers_full = &fifo_buffers_full;
for(size_t i=0; i<config->buffer_count; i++) {
buffers[i] = { &(data.get()[i * config->read_size]), config->read_size };
fifo_buffers_empty.in(&buffers[i]);
}
}
size_t StreamOutput::write(const void* const data, const size_t length) {
const uint8_t* p = static_cast<const uint8_t*>(data);
size_t written = 0;
while( written < length ) {
if( !active_buffer ) {
// We need an empty buffer...
if( !fifo_buffers_empty.out(active_buffer) ) {
// ...but none are available. Samples were dropped.
break;
}
}
const auto remaining = length - written;
written += active_buffer->write(&p[written], remaining);
if( active_buffer->is_full() ) {
if( !fifo_buffers_full.in(active_buffer) ) {
// FIFO is fuil of buffers, there's no place for this one.
// Bail out of the loop, and try submitting the buffer in the
// next pass.
// This should never happen if the number of buffers is less
// than the capacity of the FIFO.
break;
}
active_buffer = nullptr;
creg::m4txevent::assert();
}
}
config->baseband_bytes_sent += length;
return written;
}

View File

@@ -0,0 +1,54 @@
/*
* Copyright (C) 2016 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2016 Furrtek
*
* 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 __STREAM_OUTPUT_H__
#define __STREAM_OUTPUT_H__
#include "message.hpp"
#include "fifo.hpp"
#include <cstdint>
#include <cstddef>
#include <array>
#include <memory>
class StreamOutput {
public:
StreamOutput(ReplayConfig* const config);
size_t write(const void* const data, const size_t length);
private:
static constexpr size_t buffer_count_max_log2 = 3;
static constexpr size_t buffer_count_max = 1U << buffer_count_max_log2;
FIFO<StreamBuffer*> fifo_buffers_empty;
FIFO<StreamBuffer*> fifo_buffers_full;
std::array<StreamBuffer, buffer_count_max> buffers;
std::array<StreamBuffer*, buffer_count_max> buffers_empty;
std::array<StreamBuffer*, buffer_count_max> buffers_full;
StreamBuffer* active_buffer { nullptr };
ReplayConfig* const config { nullptr };
std::unique_ptr<uint8_t[]> data;
};
#endif/*__STREAM_OUTPUT_H__*/