Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

Commit

Permalink
POCSAG address filter now ignores alpha messages
Browse files Browse the repository at this point in the history
Experimenting with FIFOs for replay...
  • Loading branch information
furrtek authored and furrtek committed Apr 19, 2017
1 parent a053c0e commit 40b49e2
Show file tree
Hide file tree
Showing 20 changed files with 120 additions and 69 deletions.
6 changes: 3 additions & 3 deletions firmware/application/baseband_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,13 @@ void capture_stop() {
send_message(&message);
}

void replay_start(CaptureConfig* const config) {
CaptureConfigMessage message { config };
void replay_start(ReplayConfig* const config) {
ReplayConfigMessage message { config };
send_message(&message);
}

void replay_stop() {
CaptureConfigMessage message { nullptr };
ReplayConfigMessage message { nullptr };
send_message(&message);
}

Expand Down
2 changes: 1 addition & 1 deletion firmware/application/baseband_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void spectrum_streaming_stop();

void capture_start(CaptureConfig* const config);
void capture_stop();
void replay_start(CaptureConfig* const config);
void replay_start(ReplayConfig* const config);
void replay_stop();

} /* namespace baseband */
Expand Down
1 change: 1 addition & 0 deletions firmware/application/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
// Color bitmaps generated with:
// Gimp image > indexed colors (16), then "xxd -i *.bmp"

//BUG: Replay freezes when SD card not present
//TODO: CTCSS detector
//BUG: RDS doesn't stop baseband when stopping tx ?
//BUG: Check AFSK transmit end, skips last bits ?
Expand Down
8 changes: 3 additions & 5 deletions firmware/application/pocsag_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ void POCSAGAppView::on_packet(const POCSAGPacketMessage * message) {
else {
pocsag_decode_batch(message->packet, &pocsag_state);

if ((ignore) && (pocsag_state.out_type == ADDRESS) && (pocsag_state.address == sym_ignore.value_dec_u32())) {
if ((ignore) && (pocsag_state.address == sym_ignore.value_dec_u32())) {
// Ignore (inform, but no log)
console.write("\n\x1B\x03" + to_string_time(message->packet.timestamp()) +
" Ignored address " + to_string_dec_uint(pocsag_state.address));
//console.write("\n\x1B\x03" + to_string_time(message->packet.timestamp()) +
// " Ignored address " + to_string_dec_uint(pocsag_state.address));
return;
}

Expand Down Expand Up @@ -179,9 +179,7 @@ void POCSAGAppView::on_packet(const POCSAGPacketMessage * message) {
} else if (pocsag_state.out_type == MESSAGE) {
if (pocsag_state.address != last_address) {
// New message

console.writeln(console_info);

console.write(pocsag_state.output);

last_address = pocsag_state.address;
Expand Down
12 changes: 6 additions & 6 deletions firmware/application/replay_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
using namespace portapack;

#include "portapack_persistent_memory.hpp"
using namespace portapack;

namespace ui {

Expand All @@ -46,14 +45,14 @@ ReplayAppView::ReplayAppView(
return;
}

//baseband::run_image(portapack::spi_flash::image_tag_replay);
baseband::run_image(portapack::spi_flash::image_tag_replay);

add_children({
&field_frequency,
&field_frequency_step,
&field_rf_amp,
&replay_view,
&waterfall,
//&waterfall,
});

replay_view.set_file_list(file_list);
Expand Down Expand Up @@ -91,16 +90,17 @@ ReplayAppView::~ReplayAppView() {
void ReplayAppView::on_hide() {
// TODO: Terrible kludge because widget system doesn't notify Waterfall that
// it's being shown or hidden.
waterfall.on_hide();

//waterfall.on_hide();
View::on_hide();
}

void ReplayAppView::set_parent_rect(const Rect new_parent_rect) {
/*void ReplayAppView::set_parent_rect(const Rect new_parent_rect) {
View::set_parent_rect(new_parent_rect);
const ui::Rect waterfall_rect { 0, header_height, new_parent_rect.width(), static_cast<ui::Dim>(new_parent_rect.height() - header_height) };
waterfall.set_parent_rect(waterfall_rect);
}
}*/

void ReplayAppView::focus() {
field_frequency.focus();
Expand Down
6 changes: 3 additions & 3 deletions firmware/application/replay_app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ class ReplayAppView : public View {

void on_hide() override;

void set_parent_rect(const Rect new_parent_rect) override;
//void set_parent_rect(const Rect new_parent_rect) override;

void focus() override;

std::string title() const override { return "Replay (beta)"; };
std::string title() const override { return "Replay (broken)"; };

private:
NavigationView& nav_;
Expand Down Expand Up @@ -79,7 +79,7 @@ class ReplayAppView : public View {
16384, 3
};

spectrum::WaterfallWidget waterfall { };
//spectrum::WaterfallWidget waterfall { };
};

} /* namespace ui */
Expand Down
19 changes: 13 additions & 6 deletions firmware/application/replay_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@
#include "baseband_api.hpp"
#include "buffer_exchange.hpp"

// DEBUG:
#include "hackrf_gpio.hpp"
using namespace hackrf::one;

struct BasebandReplay {
BasebandReplay(CaptureConfig* const config) {
BasebandReplay(ReplayConfig* const config) {
baseband::replay_start(config);
}

Expand Down Expand Up @@ -63,13 +67,13 @@ ReplayThread::~ReplayThread() {
msg_t ReplayThread::static_fn(void* arg) {
auto obj = static_cast<ReplayThread*>(arg);
const auto error = obj->run();
if( error.is_valid() && obj->error_callback ) {
/*if( error.is_valid() && obj->error_callback ) {
obj->error_callback(error.value());
} else {
if( obj->success_callback ) {
obj->success_callback();
}
}
}*/
return 0;
}

Expand All @@ -78,12 +82,15 @@ Optional<File::Error> ReplayThread::run() {
BufferExchange buffers { &config };

while( !chThdShouldTerminate() ) {
auto buffer = buffers.get();
auto read_result = reader->read(buffer->data(), buffer->size());
//auto buffer = buffers.get();
buffers.get();
/*auto read_result = reader->read(buffer->data(), buffer->size());
if( read_result.is_error() ) {
return read_result.error();
}
buffers.put(buffer);
buffers.put(buffer);*/
chThdSleep(50);
//led_tx.toggle();
}

return { };
Expand Down
4 changes: 2 additions & 2 deletions firmware/application/replay_thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ class ReplayThread {
ReplayThread& operator=(const ReplayThread&) = delete;
ReplayThread& operator=(ReplayThread&&) = delete;

const CaptureConfig& state() const {
const ReplayConfig& state() const {
return config;
}

private:
CaptureConfig config;
ReplayConfig config;
std::unique_ptr<stream::Reader> reader;
std::function<void()> success_callback;
std::function<void(File::Error)> error_callback;
Expand Down
2 changes: 1 addition & 1 deletion firmware/application/ui_navigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ SystemMenuView::SystemMenuView(NavigationView& nav) {
{ "Play dead", ui::Color::red(), &bitmap_icon_playdead, [&nav](){ nav.push<PlayDeadView>(); } },
{ "Receivers", ui::Color::cyan(), &bitmap_icon_receivers, [&nav](){ nav.push<ReceiverMenuView>(); } },
{ "Capture", ui::Color::blue(), &bitmap_icon_capture, [&nav](){ nav.push<CaptureAppView>(); } },
{ "Replay", ui::Color::grey(), &bitmap_icon_replay, [&nav](){ nav.push<NotImplementedView>(); } }, // ReplayAppView
{ "Replay", ui::Color::blue(), &bitmap_icon_replay, [&nav](){ nav.push<ReplayAppView>(); } }, // ReplayAppView
{ "Audio transmitters", ui::Color::green(), &bitmap_icon_audiotx, [&nav](){ nav.push<TransmitterAudioMenuView>(); } },
{ "Code transmitters", ui::Color::green(), &bitmap_icon_codetx, [&nav](){ nav.push<TransmitterCodedMenuView>(); } },
{ "SSTV transmitter", ui::Color::dark_green(), &bitmap_icon_sstv, [&nav](){ nav.push<SSTVTXView>(); } },
Expand Down
11 changes: 5 additions & 6 deletions firmware/application/ui_replay_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ ReplayView::ReplayView(
this->toggle();
};

signal_token_tick_second = rtc_time::signal_tick_second += [this]() {
/*signal_token_tick_second = rtc_time::signal_tick_second += [this]() {
this->on_tick_second();
};
};*/
}

ReplayView::~ReplayView() {
rtc_time::signal_tick_second -= signal_token_tick_second;
//rtc_time::signal_tick_second -= signal_token_tick_second;
}

void ReplayView::focus() {
Expand All @@ -97,7 +97,6 @@ void ReplayView::set_file_list(const std::vector<std::filesystem::path>& file_li
options_files.set_options(file_options);
options_files.set_selected_index(0); // First file
on_file_changed(file_options[0].second);

}

bool ReplayView::is_active() const {
Expand Down Expand Up @@ -136,8 +135,8 @@ void ReplayView::start() {
update_status_display();

radio::enable({
460000000, //target_frequency(),
4000000, //sampling_rate,
434000000, //target_frequency(),
sampling_rate,
2500000, //baseband_bandwidth,
rf::Direction::Transmit,
receiver_model.rf_amp(),
Expand Down
4 changes: 2 additions & 2 deletions firmware/application/ui_replay_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ReplayView : public View {
using option_t = std::pair<std::string, int32_t>;
using options_t = std::vector<option_t>;

static constexpr uint32_t sampling_rate = 4000000;
static constexpr uint32_t sampling_rate = 500000;

void toggle();

Expand All @@ -72,7 +72,7 @@ class ReplayView : public View {

const size_t read_size;
const size_t buffer_count;
SignalToken signal_token_tick_second { };
//SignalToken signal_token_tick_second { };
options_t file_options { };

Rectangle rect_background {
Expand Down
22 changes: 14 additions & 8 deletions firmware/baseband/proc_replay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,21 @@ void ReplayProcessor::execute(const buffer_c8_t& buffer) {
//const auto& decimator_out = decim_1_out;
//const auto& channel = decimator_out;

if( stream ) {
const size_t bytes_to_read = buffer.count; // ?
const auto result = stream->read(iq_buffer.p, bytes_to_read);
}

//feed_channel_stats(channel);
size_t pos = 0;

for (size_t i = 0; i < buffer.count; i++) {
buffer.p[i] = { iq_buffer.p[i].real() >> 8, iq_buffer.p[i].imag() >> 8};
for (size_t c = 0; c < 4; c++) {
if( stream ) {
const size_t bytes_to_read = sizeof(*buffer.p) * buffer.count / 4; // ?
const auto result = stream->read(iq_buffer.p, bytes_to_read);
}

//feed_channel_stats(channel);

for (size_t i = 0; i < (buffer.count / 4); i++) {
buffer.p[pos] = { iq_buffer.p[i].real() >> 8, iq_buffer.p[i].imag() >> 8 };
pos++;
//buffer.p[i] = { iq_buffer.p[i].real(), iq_buffer.p[i].imag() };
}
}

/*spectrum_samples += channel.count;
Expand Down
4 changes: 2 additions & 2 deletions firmware/baseband/proc_replay.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ class ReplayProcessor : public BasebandProcessor {

private:
// TODO: Repeated value needs to be transmitted from application side.
static constexpr size_t baseband_fs = 4000000;
static constexpr size_t baseband_fs = 500000;
//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, 2048> iq { };
std::array<complex16_t, 512> iq { }; // 2048
const buffer_c16_t iq_buffer {
iq.data(),
iq.size()
Expand Down
2 changes: 1 addition & 1 deletion firmware/baseband/stream_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ size_t StreamInput::write(const void* const data, const size_t length) {

if( active_buffer->is_full() ) {
if( !fifo_buffers_full.in(active_buffer) ) {
// FIFO is fuil of buffers, there's no place for this one.
// FIFO is full 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
Expand Down
33 changes: 17 additions & 16 deletions firmware/baseband/stream_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,38 @@ StreamOutput::StreamOutput(ReplayConfig* const config) :
}
}

size_t StreamOutput::read(const void* const data, const size_t length) {
const uint8_t* p = static_cast<const uint8_t*>(data);
size_t written = 0;
size_t StreamOutput::read(void* const data, const size_t length) {
uint8_t* p = static_cast<uint8_t*>(data);
size_t read = 0;

while( written < length ) {
while( read < length ) {
if( !active_buffer ) {
// We need an empty buffer...
if( !fifo_buffers_empty.out(active_buffer) ) {
// We need a full buffer...
if( !fifo_buffers_full.out(active_buffer) ) {
// ...but none are available. Samples were dropped.
//active_buffer = nullptr; // Testing ! Jumpstart
creg::m4txevent::assert();
break;
}
}

const auto remaining = length - written;
written += active_buffer->write(&p[written], remaining);
const auto remaining = length - read;
read += active_buffer->read(&p[read], remaining);
//buffer->empty();

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
if( active_buffer->is_empty() ) {
if( !fifo_buffers_empty.in(active_buffer) ) {
// FIFO is completly empty.
// Bail out of the loop, and try retrieving 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;
config->baseband_bytes_received += length;

return written;
return read;
}
2 changes: 1 addition & 1 deletion firmware/baseband/stream_output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class StreamOutput {
StreamOutput& operator=(const StreamOutput&) = delete;
StreamOutput& operator=(StreamOutput&&) = delete;

size_t read(const void* const data, const size_t length);
size_t read(void* const data, const size_t length);

private:
static constexpr size_t buffer_count_max_log2 = 3;
Expand Down
Loading

0 comments on commit 40b49e2

Please sign in to comment.