From bdeab6428b6e34a8cfdd592af90973411a7d5978 Mon Sep 17 00:00:00 2001 From: Erwin Ried <1091420+eried@users.noreply.github.com> Date: Wed, 20 May 2020 12:32:42 +0200 Subject: [PATCH 1/2] Update capture_app.cpp (#356) --- firmware/application/apps/capture_app.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/firmware/application/apps/capture_app.cpp b/firmware/application/apps/capture_app.cpp index 3e9bf862..a0965d2d 100644 --- a/firmware/application/apps/capture_app.cpp +++ b/firmware/application/apps/capture_app.cpp @@ -46,6 +46,12 @@ CaptureAppView::CaptureAppView(NavigationView& nav) { &waterfall, }); + // Hack for initialization + // TODO: This should be included in a more global section so apps dont need to do it + receiver_model.set_sampling_rate(3072000); + receiver_model.set_baseband_bandwidth(1750000); + //------------------- + field_frequency.set_value(receiver_model.tuning_frequency()); field_frequency.set_step(receiver_model.frequency_step()); field_frequency.on_change = [this](rf::Frequency f) { @@ -87,6 +93,14 @@ CaptureAppView::CaptureAppView(NavigationView& nav) { } CaptureAppView::~CaptureAppView() { + + // Hack for preventing halting other apps + // TODO: This should be also part of something global + receiver_model.set_sampling_rate(3072000); + receiver_model.set_baseband_bandwidth(1750000); + receiver_model.set_modulation(ReceiverModel::Mode::WidebandFMAudio); + // ---------------------------- + receiver_model.disable(); baseband::shutdown(); } From 739218116dbe322e6fc7e1ef6e62ed4293db66c6 Mon Sep 17 00:00:00 2001 From: Erwin Ried <1091420+eried@users.noreply.github.com> Date: Wed, 20 May 2020 12:34:20 +0200 Subject: [PATCH 2/2] Adding phase field (extracted from @jamesshao8 repo) (#357) --- firmware/application/apps/pocsag_app.cpp | 10 +++++++--- firmware/application/apps/pocsag_app.hpp | 10 +++++++++- firmware/application/apps/ui_pocsag_tx.cpp | 9 +++++++++ firmware/application/apps/ui_pocsag_tx.hpp | 10 ++++++++++ firmware/application/baseband_api.cpp | 5 +++-- firmware/application/baseband_api.hpp | 2 +- firmware/baseband/proc_pocsag.cpp | 8 ++++++-- firmware/baseband/proc_pocsag.hpp | 1 + firmware/common/message.hpp | 7 +++++-- 9 files changed, 51 insertions(+), 11 deletions(-) diff --git a/firmware/application/apps/pocsag_app.cpp b/firmware/application/apps/pocsag_app.cpp index f0385d2d..bf9d88d8 100644 --- a/firmware/application/apps/pocsag_app.cpp +++ b/firmware/application/apps/pocsag_app.cpp @@ -69,6 +69,7 @@ POCSAGAppView::POCSAGAppView(NavigationView& nav) { &field_vga, &field_frequency, &options_bitrate, + &options_phase, &check_log, &check_ignore, &sym_ignore, @@ -99,10 +100,13 @@ POCSAGAppView::POCSAGAppView(NavigationView& nav) { }; options_bitrate.on_change = [this](size_t, OptionsField::value_t v) { - on_bitrate_changed(v); + on_config_changed(v, options_phase.selected_index_value()); }; options_bitrate.set_selected_index(1); // 1200bps + options_phase.on_change = [this](size_t, OptionsField::value_t v) { + on_config_changed(options_bitrate.selected_index_value(),v); + }; check_ignore.set_value(ignore); check_ignore.on_select = [this](Checkbox&, bool v) { ignore = v; @@ -197,8 +201,8 @@ void POCSAGAppView::on_packet(const POCSAGPacketMessage * message) { logger->log_raw_data(message->packet, target_frequency()); } -void POCSAGAppView::on_bitrate_changed(const uint32_t new_bitrate) { - baseband::set_pocsag(pocsag_bitrates[new_bitrate]); +void POCSAGAppView::on_config_changed(const uint32_t new_bitrate, bool new_phase) { + baseband::set_pocsag(pocsag_bitrates[new_bitrate], new_phase); } void POCSAGAppView::set_target_frequency(const uint32_t new_value) { diff --git a/firmware/application/apps/pocsag_app.hpp b/firmware/application/apps/pocsag_app.hpp index ace892d0..58fef242 100644 --- a/firmware/application/apps/pocsag_app.hpp +++ b/firmware/application/apps/pocsag_app.hpp @@ -93,6 +93,14 @@ private: { "2400bps", 2 } } }; + OptionsField options_phase { + { 6 * 8, 21 }, + 1, + { + { "P", 0 }, + { "N", 1 }, + } + }; Checkbox check_log { { 22 * 8, 21 }, 3, @@ -124,7 +132,7 @@ private: void on_packet(const POCSAGPacketMessage * message); - void on_bitrate_changed(const uint32_t new_bitrate); + void on_config_changed(const uint32_t new_bitrate, const bool phase); uint32_t target_frequency() const; void set_target_frequency(const uint32_t new_value); diff --git a/firmware/application/apps/ui_pocsag_tx.cpp b/firmware/application/apps/ui_pocsag_tx.cpp index 316cf17d..56ced719 100644 --- a/firmware/application/apps/ui_pocsag_tx.cpp +++ b/firmware/application/apps/ui_pocsag_tx.cpp @@ -71,6 +71,7 @@ bool POCSAGTXView::start_tx() { return false; } } + MessageType phase = (MessageType)options_phase.selected_index_value(); pocsag_encode(type, BCH_code, options_function.selected_index_value(), message, address, codewords); @@ -79,6 +80,9 @@ bool POCSAGTXView::start_tx() { progressbar.set_max(total_frames); transmitter_model.set_sampling_rate(2280000); + transmitter_model.set_rf_amp(true); + transmitter_model.set_lna(40); + transmitter_model.set_vga(40); transmitter_model.set_baseband_bandwidth(1750000); transmitter_model.enable(); @@ -86,7 +90,11 @@ bool POCSAGTXView::start_tx() { bi = 0; for (i = 0; i < codewords.size(); i++) { + if (phase == 0) + codeword = ~(codewords[i]); + else codeword = codewords[i]; + data_ptr[bi++] = (codeword >> 24) & 0xFF; data_ptr[bi++] = (codeword >> 16) & 0xFF; data_ptr[bi++] = (codeword >> 8) & 0xFF; @@ -126,6 +134,7 @@ POCSAGTXView::POCSAGTXView( &field_address, &options_type, &options_function, + &options_phase, &text_message, &button_message, &progressbar, diff --git a/firmware/application/apps/ui_pocsag_tx.hpp b/firmware/application/apps/ui_pocsag_tx.hpp index 60c3aeb9..0dfbc30a 100644 --- a/firmware/application/apps/ui_pocsag_tx.hpp +++ b/firmware/application/apps/ui_pocsag_tx.hpp @@ -71,6 +71,7 @@ private: { { 3 * 8, 6 * 8 }, "Address:", Color::light_grey() }, { { 6 * 8, 8 * 8 }, "Type:", Color::light_grey() }, { { 2 * 8, 10 * 8 }, "Function:", Color::light_grey() }, + { { 5 * 8, 12 * 8 }, "Phase:", Color::light_grey() }, { { 0 * 8, 14 * 8 }, "Message:", Color::light_grey() } }; @@ -110,6 +111,15 @@ private: { "D", 3 } } }; + + OptionsField options_phase { + { 11 * 8, 12 * 8 }, + 1, + { + { "P", 0 }, + { "N", 1 }, + } + }; Text text_message { { 0 * 8, 16 * 8, 16 * 8, 16 }, diff --git a/firmware/application/baseband_api.cpp b/firmware/application/baseband_api.cpp index 502047d2..3cad9825 100644 --- a/firmware/application/baseband_api.cpp +++ b/firmware/application/baseband_api.cpp @@ -224,9 +224,10 @@ void set_fsk_data(const uint32_t stream_length, const uint32_t samples_per_bit, send_message(&message); } -void set_pocsag(const pocsag::BitRate bitrate) { +void set_pocsag(const pocsag::BitRate bitrate, bool phase) { const POCSAGConfigureMessage message { - bitrate + bitrate, + phase }; send_message(&message); } diff --git a/firmware/application/baseband_api.hpp b/firmware/application/baseband_api.hpp index 9592f8ca..43d0eebe 100644 --- a/firmware/application/baseband_api.hpp +++ b/firmware/application/baseband_api.hpp @@ -77,7 +77,7 @@ void set_ook_data(const uint32_t stream_length, const uint32_t samples_per_bit, const uint32_t pause_symbols); void set_fsk_data(const uint32_t stream_length, const uint32_t samples_per_bit, const uint32_t shift, const uint32_t progress_notice); -void set_pocsag(const pocsag::BitRate bitrate); +void set_pocsag(const pocsag::BitRate bitrate, bool phase); void set_adsb(); void set_jammer(const bool run, const jammer::JammerType type, const uint32_t speed); void set_rds_data(const uint16_t message_length); diff --git a/firmware/baseband/proc_pocsag.cpp b/firmware/baseband/proc_pocsag.cpp index 4b5ee69b..a1854286 100644 --- a/firmware/baseband/proc_pocsag.cpp +++ b/firmware/baseband/proc_pocsag.cpp @@ -47,8 +47,11 @@ void POCSAGProcessor::execute(const buffer_c8_t& buffer) { const int32_t audio_sample = __SSAT(sample_int, 16); slicer_sr <<= 1; - slicer_sr |= (audio_sample < 0); // Do we need hysteresis ? - + if (phase == 0) + slicer_sr |= (audio_sample < 0); // Do we need hysteresis ? + else + slicer_sr |= !(audio_sample < 0); + // Detect transitions to adjust clock if ((slicer_sr ^ (slicer_sr >> 1)) & 1) { if (sphase < (0x8000u - sphase_delta_half)) @@ -162,6 +165,7 @@ void POCSAGProcessor::configure(const POCSAGConfigureMessage& message) { //audio_output.configure(false); bitrate = message.bitrate; + phase = message.phase; sphase_delta = 0x10000u * bitrate / POCSAG_AUDIO_RATE; sphase_delta_half = sphase_delta / 2; // Just for speed sphase_delta_eighth = sphase_delta / 8; diff --git a/firmware/baseband/proc_pocsag.hpp b/firmware/baseband/proc_pocsag.hpp index 79218daf..2f907b5e 100644 --- a/firmware/baseband/proc_pocsag.hpp +++ b/firmware/baseband/proc_pocsag.hpp @@ -95,6 +95,7 @@ private: bool configured = false; rx_states rx_state { WAITING }; pocsag::BitRate bitrate { pocsag::BitRate::FSK1200 }; + bool phase; uint32_t codeword_count { 0 }; pocsag::POCSAGPacket packet { }; diff --git a/firmware/common/message.hpp b/firmware/common/message.hpp index 4ca93da9..eeecc9d0 100644 --- a/firmware/common/message.hpp +++ b/firmware/common/message.hpp @@ -989,13 +989,16 @@ public: class POCSAGConfigureMessage : public Message { public: constexpr POCSAGConfigureMessage( - const pocsag::BitRate bitrate + const pocsag::BitRate bitrate, + const bool phase ) : Message { ID::POCSAGConfigure }, - bitrate(bitrate) + bitrate(bitrate), + phase(phase) { } const pocsag::BitRate bitrate; + const bool phase; }; class ADSBConfigureMessage : public Message {