Beta scanner app

ADSB TX frame index bugfix (OOB)
This commit is contained in:
furrtek 2018-04-19 20:50:32 +01:00
parent 5636764226
commit 3ddc6553ac
5 changed files with 213 additions and 28 deletions

View File

@ -103,7 +103,7 @@ AnalogAudioView::AnalogAudioView(
&waterfall,
});
exit_on_squelch = eos;
//exit_on_squelch = eos;
field_frequency.set_value(receiver_model.tuning_frequency());
field_frequency.set_step(receiver_model.frequency_step());
@ -332,9 +332,9 @@ void AnalogAudioView::update_modulation(const ReceiverModel::Mode modulation) {
}
}
void AnalogAudioView::squelched() {
/*void AnalogAudioView::squelched() {
if (exit_on_squelch) nav_.pop();
}
}*/
void AnalogAudioView::handle_coded_squelch(const uint32_t value) {
float diff, min_diff = value;

View File

@ -113,7 +113,7 @@ private:
const Rect nbfm_view_rect { 0 * 8, 1 * 16, 18 * 8, 1 * 16 };
NavigationView& nav_;
bool exit_on_squelch { false };
//bool exit_on_squelch { false };
RSSI rssi {
{ 21 * 8, 0, 6 * 8, 4 },
@ -188,16 +188,16 @@ private:
void update_modulation(const ReceiverModel::Mode modulation);
void squelched();
//void squelched();
void handle_coded_squelch(const uint32_t value);
MessageHandlerRegistration message_handler_squelch_signal {
/*MessageHandlerRegistration message_handler_squelch_signal {
Message::ID::RequestSignal,
[this](const Message* const p) {
(void)p;
this->squelched();
}
};
};*/
MessageHandlerRegistration message_handler_coded_squelch {
Message::ID::CodedSquelch,

View File

@ -270,12 +270,11 @@ void ADSBTXThread::run() {
chThdSleepMilliseconds(50);
if (frame_index == frames_.size()) {
frame_index++;
if (frame_index >= frames_.size()) {
frame_index = 0;
//if (regen)
// regen--;
} else {
frame_index++;
}
}
}

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2016 Furrtek
* Copyright (C) 2018 Furrtek
*
* This file is part of PortaPack.
*
@ -24,34 +24,144 @@
#include "baseband_api.hpp"
#include "string_format.hpp"
#include "audio.hpp"
using namespace portapack;
namespace ui {
ScannerThread::ScannerThread(
std::vector<rf::Frequency> frequency_list
) : frequency_list_ { std::move(frequency_list) }
{
thread = chThdCreateFromHeap(NULL, 1024, NORMALPRIO + 10, ScannerThread::static_fn, this);
}
ScannerThread::~ScannerThread() {
if( thread ) {
chThdTerminate(thread);
chThdWait(thread);
thread = nullptr;
}
}
void ScannerThread::set_scanning(const bool v) {
_scanning = v;
}
msg_t ScannerThread::static_fn(void* arg) {
auto obj = static_cast<ScannerThread*>(arg);
obj->run();
return 0;
}
void ScannerThread::run() {
RetuneMessage message { };
uint32_t frequency_index = 0;
while( !chThdShouldTerminate() ) {
if (_scanning) {
// Retune
receiver_model.set_tuning_frequency(frequency_list_[frequency_index]);
message.range = frequency_index;
EventDispatcher::send_message(message);
frequency_index++;
if (frequency_index >= frequency_list_.size())
frequency_index = 0;
}
chThdSleepMilliseconds(50);
}
}
void ScannerView::handle_retune(uint32_t i) {
text_cycle.set(to_string_dec_uint(i) + "/" + to_string_dec_uint(frequency_list.size()));
}
void ScannerView::focus() {
button.focus();
field_lna.focus();
}
ScannerView::~ScannerView() {
//receiver_model.disable();
//baseband::shutdown();
audio::output::stop();
receiver_model.disable();
baseband::shutdown();
}
ScannerView::ScannerView(
NavigationView& nav
NavigationView&
)
{
//baseband::run_image(portapack::spi_flash::image_tag_wideband_spectrum);
add_children({
&labels,
&button
&field_lna,
&field_vga,
&field_rf_amp,
&field_volume,
&field_squelch,
//&record_view,
&text_cycle,
//&waterfall,
});
button.on_select = [this, &nav](Button&) {
nav.pop();
// DEBUG
frequency_list.push_back(466025000);
frequency_list.push_back(466050000);
frequency_list.push_back(466075000);
frequency_list.push_back(466175000);
frequency_list.push_back(466206250);
frequency_list.push_back(466231250);
field_squelch.on_change = [this](int32_t v) {
squelch = v;
};
field_squelch.set_value(30);
field_volume.set_value((receiver_model.headphone_volume() - audio::headphone::volume_range().max).decibel() + 99);
field_volume.on_change = [this](int32_t v) {
this->on_headphone_volume_changed(v);
};
audio::output::start();
audio::output::mute();
baseband::run_image(portapack::spi_flash::image_tag_nfm_audio);
receiver_model.set_modulation(ReceiverModel::Mode::NarrowbandFMAudio);
receiver_model.set_sampling_rate(3072000);
receiver_model.set_baseband_bandwidth(1750000);
receiver_model.enable();
receiver_model.set_squelch_level(0);
receiver_model.set_nbfm_configuration(2); // 16k
audio::output::unmute();
// TODO: Scanning thread here
scan_thread = std::make_unique<ScannerThread>(frequency_list);
}
void ScannerView::on_statistics_update(const ChannelStatistics& statistics) {
int32_t max_db = statistics.max_db;
if (timer < 6)
timer++;
if (max_db < -squelch) {
if (timer == 5) {
//audio::output::stop();
scan_thread->set_scanning(true);
}
} else {
//audio::output::start();
scan_thread->set_scanning(false);
timer = 0;
}
}
void ScannerView::on_headphone_volume_changed(int32_t v) {
const auto new_volume = volume_t::decibel(v - 99) + audio::headphone::volume_range().max;
receiver_model.set_headphone_volume(new_volume);
}
} /* namespace ui */

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2016 Furrtek
* Copyright (C) 2018 Furrtek
*
* This file is part of PortaPack.
*
@ -22,16 +22,37 @@
#include "receiver_model.hpp"
#include "spectrum_color_lut.hpp"
#include "ui_receiver.hpp"
#include "ui_font_fixed_8x16.hpp"
namespace ui {
class ScannerThread {
public:
ScannerThread(std::vector<rf::Frequency> frequency_list);
~ScannerThread();
void set_scanning(const bool v);
ScannerThread(const ScannerThread&) = delete;
ScannerThread(ScannerThread&&) = delete;
ScannerThread& operator=(const ScannerThread&) = delete;
ScannerThread& operator=(ScannerThread&&) = delete;
private:
std::vector<rf::Frequency> frequency_list_ { };
Thread* thread { nullptr };
bool _scanning { true };
static msg_t static_fn(void* arg);
void run();
};
class ScannerView : public View {
public:
ScannerView(NavigationView& nav);
ScannerView(NavigationView&);
~ScannerView();
void focus() override;
@ -39,13 +60,68 @@ public:
std::string title() const override { return "Scanner"; };
private:
void on_statistics_update(const ChannelStatistics& statistics);
void on_headphone_volume_changed(int32_t v);
void handle_retune(uint32_t i);
std::vector<rf::Frequency> frequency_list { };
int32_t squelch { 0 };
uint32_t timer { 0 };
Labels labels {
{ { 1 * 8, 0 }, "Work in progress...", Color::light_grey() }
{ { 0 * 8, 0 * 16 }, "LNA: VGA: AMP: VOL:", Color::light_grey() },
{ { 0 * 8, 1 * 16 }, "SQUELCH: /99", Color::light_grey() },
{ { 0 * 8, 3 * 16 }, "Work in progress...", Color::light_grey() }
};
Button button {
{ 60, 64, 120, 32 },
"Exit"
LNAGainField field_lna {
{ 4 * 8, 0 * 16 }
};
VGAGainField field_vga {
{ 11 * 8, 0 * 16 }
};
RFAmpField field_rf_amp {
{ 18 * 8, 0 * 16 }
};
NumberField field_volume {
{ 24 * 8, 0 * 16 },
2,
{ 0, 99 },
1,
' ',
};
NumberField field_squelch {
{ 8 * 8, 1 * 16 },
2,
{ 0, 99 },
1,
' ',
};
Text text_cycle {
{ 0, 5 * 16, 240, 16 },
"--/--"
};
std::unique_ptr<ScannerThread> scan_thread { };
MessageHandlerRegistration message_handler_retune {
Message::ID::Retune,
[this](const Message* const p) {
const auto message = *reinterpret_cast<const RetuneMessage*>(p);
this->handle_retune(message.range);
}
};
MessageHandlerRegistration message_handler_stats {
Message::ID::ChannelStatistics,
[this](const Message* const p) {
this->on_statistics_update(static_cast<const ChannelStatisticsMessage*>(p)->statistics);
}
};
};