Started close call dev

This commit is contained in:
furrtek
2016-05-11 12:45:03 +02:00
parent b4a113be59
commit fb21c1332e
22 changed files with 502 additions and 268 deletions
+30 -29
View File
@@ -150,39 +150,40 @@ CPPSRC = main.cpp \
audio.cpp \
lcd_ili9341.cpp \
ui.cpp \
ui_alphanum.cpp \
ui_handwrite.cpp \
ui_about.cpp \
ui_text.cpp \
ui_widget.cpp \
ui_painter.cpp \
ui_focus.cpp \
ui_navigation.cpp \
ui_menu.cpp \
ui_rssi.cpp \
ui_channel.cpp \
ui_audio.cpp \
ui_audiotx.cpp \
ui_soundboard.cpp \
ui_lcr.cpp \
ui_rds.cpp \
ui_jammer.cpp \
ui_font_fixed_8x16.cpp \
ui_setup.cpp \
ui_debug.cpp \
ui_baseband_stats_view.cpp \
ui_sd_card_status_view.cpp \
ui_sd_card_debug.cpp \
ui_console.cpp \
ui_receiver.cpp \
ui_record_view.cpp \
ui_spectrum.cpp \
ui_loadmodule.cpp \
ui_afskrx.cpp \
ui_afsksetup.cpp \
ui_sigfrx.cpp \
ui_xylos.cpp \
ui_audio.cpp \
ui_audiotx.cpp \
ui_alphanum.cpp \
ui_baseband_stats_view.cpp \
ui_channel.cpp \
ui_closecall.cpp \
ui_console.cpp \
ui_debug.cpp \
ui_focus.cpp \
ui_font_fixed_8x16.cpp \
ui_handwrite.cpp \
ui_jammer.cpp \
ui_lcr.cpp \
ui_loadmodule.cpp \
ui_menu.cpp \
ui_navigation.cpp \
ui_numbers.cpp \
ui_painter.cpp \
ui_rds.cpp \
ui_receiver.cpp \
ui_record_view.cpp \
ui_rssi.cpp \
ui_sd_card_debug.cpp \
ui_sd_card_status_view.cpp \
ui_setup.cpp \
ui_sigfrx.cpp \
ui_soundboard.cpp \
ui_spectrum.cpp \
ui_text.cpp \
ui_widget.cpp \
ui_xylos.cpp \
recent_entries.cpp \
receiver_model.cpp \
transmitter_model.cpp \
+1
View File
@@ -38,6 +38,7 @@ public:
WidebandFMAudio = 2,
SpectrumAnalysis = 4,
Capture = 7,
CloseCall = 10,
};
rf::Frequency tuning_frequency() const;
+1 -1
View File
@@ -34,7 +34,7 @@
#include "transmitter_model.hpp"
namespace ui {
class AudioTXView : public View {
public:
AudioTXView(NavigationView& nav);
+323
View File
@@ -0,0 +1,323 @@
/*
* Copyright (C) 2015 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 "ui_closecall.hpp"
#include "ui_receiver.hpp"
#include "ch.h"
#include "evtimer.h"
#include "event_m0.hpp"
#include "ff.h"
#include "hackrf_gpio.hpp"
#include "portapack.hpp"
#include "radio.hpp"
#include "baseband_api.hpp"
#include "string_format.hpp"
#include "hackrf_hal.hpp"
#include <cstring>
#include <stdio.h>
#include <algorithm>
using namespace portapack;
namespace ui {
void CloseCallView::focus() {
button_exit.focus();
}
CloseCallView::~CloseCallView() {
receiver_model.disable();
}
void CloseCallView::do_detection() {
uint8_t xmax = 0;
uint16_t imax = 0;
uint8_t threshold;
size_t i;
portapack::display.fill_rectangle({last_pos, 60, 1, 9}, Color::black());
mean /= (236 * (slices_max + 1));
for (i = 0; i < (slices_max + 1); i++) {
threshold = slicemax_db[i];
if (threshold >= 40) {
if (((uint8_t)(threshold - 40) > mean) && (threshold > xmax)) {
xmax = threshold;
imax = slicemax_idx[i] + (i * 236);
}
}
}
// Lock / release
if ((imax >= last_channel - 2) && (imax <= last_channel + 2)) {
if (detect_counter == 8) {
if (imax != last_channel) {
char finalstr[24] = {0};
// 236 steps = 10MHz
// Resolution = 42.4kHz
auto fstr = to_string_dec_int((slice_start + (42373 * (imax - 118))) / 1000);
strcat(finalstr, "Locked: ");
strcat(finalstr, fstr.c_str());
text_infos.set(finalstr);
}
locked = true;
release_counter = 0;
} else {
detect_counter++;
}
} else {
if (locked == true) {
if (release_counter == 8) {
detect_counter = 0;
locked = false;
text_infos.set("Lost ");
} else {
release_counter++;
}
}
}
last_channel = imax;
last_pos = (ui::Coord)(imax + 2);
portapack::display.fill_rectangle({last_pos, 60, 1, 9}, Color::red());
}
void CloseCallView::on_channel_spectrum(const ChannelSpectrum& spectrum) {
uint8_t xmax = 0;
uint16_t imax = 0;
uint8_t threshold;
size_t i;
if (!wait) {
// Spectrum line (for debug)
std::array<Color, 240> pixel_row;
for(i = 0; i < 118; i++) {
const auto pixel_color = spectrum_rgb3_lut[spectrum.db[256 - 120 + i]];
pixel_row[i + 2] = pixel_color;
}
for(i = 122; i < 240; i++) {
const auto pixel_color = spectrum_rgb3_lut[spectrum.db[i - 120]];
pixel_row[i - 2] = pixel_color;
}
display.draw_pixels(
{ { 0, 64 + slices_counter * 4 }, { pixel_row.size(), 1 } },
pixel_row
);
// Find max for this slice
for (i = 0; i < 118; i++) {
threshold = spectrum.db[256 - 120 + i];
if (threshold > xmax) {
xmax = threshold;
imax = i;
}
}
for (i = 122; i < 240; i++) {
threshold = spectrum.db[i - 120];
if (threshold > xmax) {
xmax = threshold;
imax = i - 4;
}
}
slicemax_db[slices_counter] = xmax;
slicemax_idx[slices_counter] = imax;
// Add to mean
for (i = 136; i < 254; i++)
mean += spectrum.db[i];
for (i = 2; i < 120; i++)
mean += spectrum.db[i];
// Slice update
if (slicing) {
if (slices_counter >= slices_max) {
do_detection();
mean = 0;
slices_counter = 0;
} else {
slices_counter++;
}
slice_frequency = slice_start + (slices_counter * CC_SLICE_WIDTH);
receiver_model.set_tuning_frequency(slice_frequency);
wait = 1;
} else {
do_detection();
}
} else {
wait--;
}
}
void CloseCallView::on_show() {
EventDispatcher::message_map().register_handler(Message::ID::ChannelSpectrumConfig,
[this](const Message* const p) {
const auto message = *reinterpret_cast<const ChannelSpectrumConfigMessage*>(p);
this->fifo = message.fifo;
}
);
EventDispatcher::message_map().register_handler(Message::ID::DisplayFrameSync,
[this](const Message* const) {
if( this->fifo ) {
ChannelSpectrum channel_spectrum;
while( fifo->out(channel_spectrum) ) {
this->on_channel_spectrum(channel_spectrum);
}
}
}
);
baseband::spectrum_streaming_start();
}
void CloseCallView::on_hide() {
baseband::spectrum_streaming_stop();
EventDispatcher::message_map().unregister_handler(Message::ID::DisplayFrameSync);
EventDispatcher::message_map().unregister_handler(Message::ID::ChannelSpectrumConfig);
}
void CloseCallView::on_range_changed() {
rf::Frequency f_min, f_max;
rf::Frequency slices_span;
int64_t offset;
f_max = field_frequency_max.value();
f_min = field_frequency_min.value();
scan_span = abs(f_max - f_min);
if (scan_span > CC_SLICE_WIDTH) {
// ex: 100~115 (15): 102.5(97.5~107.5) -> 112.5(107.5~117.5) = 2.5 lost left and right
slices_max = (scan_span + CC_SLICE_WIDTH - 1) / CC_SLICE_WIDTH;
// = 2
slices_span = slices_max * CC_SLICE_WIDTH;
// = 20000000
offset = (slices_span - scan_span) / 2;
// = (20000000 - 15000000) / 2 = 5000000 / 2 = 2500000
slice_start = std::min(f_min, f_max) + offset;
slices_max--;
slicing = true;
} else {
slice_frequency = (f_max + f_min) / 2;
//offset = (CC_SLICE_WIDTH - scan_span) / 2;
//slice_start = std::min(f_min, f_max) - offset;
slice_start = slice_frequency;
receiver_model.set_tuning_frequency(slice_frequency);
slices_max = 0;
slices_counter = 0;
slicing = false;
}
text_slice.set(to_string_dec_int(slices_max + 1));
slices_counter = 0;
}
CloseCallView::CloseCallView(
NavigationView& nav
)
{
add_children({ {
&field_frequency_min,
&field_frequency_max,
&text_slice,
&text_infos,
&button_exit
} });
field_frequency_min.set_value(receiver_model.tuning_frequency() - 2000000);
field_frequency_min.set_step(200000);
field_frequency_min.on_change = [this](rf::Frequency f) {
(void) f;
this->on_range_changed();
};
field_frequency_min.on_edit = [this, &nav]() {
auto new_view = nav.push<FrequencyKeypadView>(receiver_model.tuning_frequency());
new_view->on_changed = [this](rf::Frequency f) {
this->on_range_changed();
this->field_frequency_min.set_value(f);
};
};
field_frequency_max.set_value(receiver_model.tuning_frequency() + 2000000);
field_frequency_max.set_step(200000);
field_frequency_max.on_change = [this](rf::Frequency f) {
(void) f;
this->on_range_changed();
};
field_frequency_max.on_edit = [this, &nav]() {
auto new_view = nav.push<FrequencyKeypadView>(receiver_model.tuning_frequency());
new_view->on_changed = [this](rf::Frequency f) {
this->on_range_changed();
this->field_frequency_max.set_value(f);
};
};
on_range_changed();
button_exit.on_select = [&nav](Button&){
nav.pop();
};
/*field_lna.set_value(receiver_model.lna());
field_lna.on_change = [this](int32_t v) {
this->on_lna_changed(v);
};
field_lna.on_show_options = [this]() {
this->on_show_options_rf_gain();
};
field_vga.set_value(receiver_model.vga());
field_vga.on_change = [this](int32_t v_db) {
this->on_vga_changed(v_db);
};
field_vga.on_show_options = [this]() {
this->on_show_options_rf_gain();
};*/
//receiver_model.set_lna(0);
//receiver_model.set_vga(0);
//audio::output::mute();
receiver_model.set_baseband_configuration({
.mode = toUType(ReceiverModel::Mode::CloseCall),
.sampling_rate = CC_SLICE_WIDTH,
.decimation_factor = 1,
});
receiver_model.set_baseband_bandwidth(CC_SLICE_WIDTH);
receiver_model.enable();
//audio::output::unmute();
}
} /* namespace ui */
+102
View File
@@ -0,0 +1,102 @@
/*
* Copyright (C) 2015 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 "ui.hpp"
#include "ui_widget.hpp"
#include "ui_painter.hpp"
#include "ui_menu.hpp"
#include "ui_navigation.hpp"
#include "clock_manager.hpp"
#include "message.hpp"
#include "rf_path.hpp"
#include "volume.hpp"
#include "receiver_model.hpp"*/
#include "receiver_model.hpp"
#include "spectrum_color_lut.hpp"
#include "ui_receiver.hpp"
#include "ui_spectrum.hpp"
#include "ui_record_view.hpp"
#include "ui_font_fixed_8x16.hpp"
namespace ui {
#define CC_SLICE_WIDTH 10000000
class CloseCallView : public View {
public:
CloseCallView(NavigationView& nav);
~CloseCallView();
void on_show() override;
void on_hide() override;
void focus() override;
std::string title() const override { return "Close call"; };
private:
Coord last_pos = 0;
ChannelSpectrumFIFO* fifo { nullptr };
uint8_t detect_counter = 0, release_counter = 0;
uint8_t wait = 2;
uint32_t mean = 0;
rf::Frequency slice_start;
rf::Frequency slice_frequency;
uint8_t slices_max;
uint8_t slices_counter;
uint16_t last_channel;
rf::Frequency scan_span;
uint8_t slicemax_db[32]; // Todo: Cap max slices !
uint8_t slicemax_idx[32];
bool ignore = true;
bool slicing;
bool locked = false;
void on_channel_spectrum(const ChannelSpectrum& spectrum);
void on_range_changed();
void do_detection();
FrequencyField field_frequency_min {
{ 1 * 8, 0 * 16 },
};
FrequencyField field_frequency_max {
{ 12 * 8, 0 * 16 },
};
Text text_slice {
{ 23 * 8, 0 * 16, 2 * 8, 16 },
"--"
};
Text text_infos {
{ 1 * 8, 1 * 16, 18 * 8, 16 },
"..."
};
Button button_exit {
{ 92, 264, 56, 32 },
"Exit"
};
};
} /* namespace ui */
+14 -18
View File
@@ -38,6 +38,7 @@
#include "analog_audio_app.hpp"
#include "ui_soundboard.hpp"
#include "ui_debug.hpp"
#include "ui_closecall.hpp"
#include "ui_audiotx.hpp"
#include <cstring>
@@ -51,10 +52,6 @@ void LoadModuleView::focus() {
button_ok.focus();
}
void LoadModuleView::paint(Painter& painter) {
(void)painter;
}
void LoadModuleView::on_hide() {
EventDispatcher::message_map().unregister_handler(Message::ID::ReadyForSwitch);
EventDispatcher::message_map().unregister_handler(Message::ID::ModuleID);
@@ -152,12 +149,10 @@ void LoadModuleView::loadmodule() {
LoadModuleView::LoadModuleView(
NavigationView& nav,
const char * hash,
uint8_t ViewID,
bool loadplz
ViewID viewid
)
{
if (loadplz == false) nav.pop(); // Useless, remove !
add_children({ {
&text_info,
&text_infob,
@@ -165,17 +160,18 @@ LoadModuleView::LoadModuleView(
} });
_hash = hash;
button_ok.on_select = [this, &nav, ViewID](Button&){
button_ok.on_select = [this, &nav, viewid](Button&){
nav.pop();
if (_mod_loaded == true) {
if (ViewID == 0) nav.push<AudioTXView>(); //nav.push<RDSView>();
if (ViewID == 1) nav.push<XylosView>();
if (ViewID == 2) nav.push<LCRView>();
if (ViewID == 3) nav.push<SoundBoardView>();
if (ViewID == 10) nav.push<AnalogAudioView>();
} else {
nav.pop();
if (viewid == AudioTX) nav.push<AudioTXView>();
if (viewid == Xylos) nav.push<XylosView>();
if (viewid == LCR) nav.push<LCRView>();
if (viewid == SoundBoard) nav.push<SoundBoardView>();
if (viewid == AnalogAudio) nav.push<AnalogAudioView>();
if (viewid == RDS) nav.push<RDSView>();
if (viewid == CloseCall) nav.push<CloseCallView>();
if (viewid == Receiver) nav.push<ReceiverMenuView>();
}
};
}
+12 -2
View File
@@ -30,15 +30,25 @@
namespace ui {
enum ViewID {
Receiver,
AudioTX,
CloseCall,
Xylos,
LCR,
SoundBoard,
AnalogAudio,
RDS,
};
class LoadModuleView : public View {
public:
LoadModuleView(NavigationView& nav, const char * hash, uint8_t ViewID, bool loadplz);
LoadModuleView(NavigationView& nav, const char * hash, ViewID viewid);
void loadmodule();
void on_show() override;
void on_hide() override;
void focus() override;
void paint(Painter& painter) override;
private:
int load_image(void);
+11 -9
View File
@@ -173,7 +173,7 @@ TranspondersMenuView::TranspondersMenuView(NavigationView& nav) {
ReceiverMenuView::ReceiverMenuView(NavigationView& nav) {
add_items<2>({ {
{ "Audio", ui::Color::white(), [&nav](){ nav.push<LoadModuleView>(md5_baseband, 10, true); } },
{ "Audio", ui::Color::white(), [&nav](){ nav.push<AnalogAudioView>(); } },
{ "Transponders", ui::Color::white(), [&nav](){ nav.push<TranspondersMenuView>(); } },
} });
on_left = [&nav](){ nav.pop(); };
@@ -182,19 +182,21 @@ ReceiverMenuView::ReceiverMenuView(NavigationView& nav) {
/* SystemMenuView ********************************************************/
SystemMenuView::SystemMenuView(NavigationView& nav) {
add_items<10>({ {
add_items<12>({ {
{ "Play dead", ui::Color::red(), [&nav](){ nav.push<PlayDeadView>(false); } },
{ "Receiver RX", ui::Color::cyan(), [&nav](){ nav.push<ReceiverMenuView>(); } },
{ "Soundboard TX", ui::Color::orange(), [&nav](){ nav.push<LoadModuleView>(md5_baseband_tx, 3, true); } },
{ "Audio TX TX", ui::Color::yellow(), [&nav](){ nav.push<LoadModuleView>(md5_baseband_tx, 0, true); } },
{ "Xylos TX", ui::Color::yellow(), [&nav](){ nav.push<LoadModuleView>(md5_baseband_tx, 1, true); } },
{ "TEDI/LCR TX", ui::Color::yellow(), [&nav](){ nav.push<LoadModuleView>(md5_baseband_tx, 2, true); } },
{ "Receiver RX", ui::Color::cyan(), [&nav](){ nav.push<LoadModuleView>(md5_baseband, Receiver); } },
{ "Close Call RX", ui::Color::cyan(), [&nav](){ nav.push<LoadModuleView>(md5_baseband, CloseCall); } },
{ "Soundboard TX", ui::Color::yellow(), [&nav](){ nav.push<LoadModuleView>(md5_baseband_tx, SoundBoard); } },
{ "Audio TX", ui::Color::yellow(), [&nav](){ nav.push<LoadModuleView>(md5_baseband_tx, AudioTX); } },
{ "Xylos TX", ui::Color::orange(), [&nav](){ nav.push<LoadModuleView>(md5_baseband_tx, Xylos); } },
{ "TEDI/LCR TX", ui::Color::orange(), [&nav](){ nav.push<LoadModuleView>(md5_baseband_tx, LCR); } },
{ "RDS TX", ui::Color::yellow(), [&nav](){ nav.push<LoadModuleView>(md5_baseband_tx, RDS); } },
//{ "Capture", ui::Color::white(), [&nav](){ nav.push<NotImplementedView>(); } },
//{ "Analyze", ui::Color::white(), [&nav](){ nav.push<NotImplementedView>(); } },
{ "Setup", ui::Color::white(), [&nav](){ nav.push<SetupMenuView>(); } },
{ "About", ui::Color::white(), [&nav](){ nav.push<AboutView>(); } },
{ "Debug", ui::Color::white(), [&nav](){ nav.push<DebugMenuView>(); } },
{ "HackRF", ui::Color::white(), [&nav](){ nav.push<HackRFFirmwareView>(); } },
{ "About", ui::Color::white(), [&nav](){ nav.push<AboutView>(); } }
} });
//{ "Nordic/BTLE RX", ui::Color::cyan(), [&nav](){ nav.push(new NotImplementedView { nav }); } },
@@ -225,7 +227,7 @@ SystemView::SystemView(
{
set_style(&style_default);
char debugtxt[21]; // DEBUG
//char debugtxt[21]; // DEBUG
constexpr ui::Dim status_view_height = 16;
+1
View File
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2016 Furrtek
*
* This file is part of PortaPack.
*
+1
View File
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2016 Furrtek
*
* This file is part of PortaPack.
*