2016-11-30 06:41:55 +00:00
|
|
|
/*
|
|
|
|
* 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_adsbtx.hpp"
|
|
|
|
#include "ui_alphanum.hpp"
|
|
|
|
|
2016-12-05 11:56:41 +00:00
|
|
|
#include "adsb.hpp"
|
2016-11-30 06:41:55 +00:00
|
|
|
#include "string_format.hpp"
|
|
|
|
#include "portapack.hpp"
|
|
|
|
#include "baseband_api.hpp"
|
|
|
|
#include "portapack_persistent_memory.hpp"
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2016-12-05 11:56:41 +00:00
|
|
|
using namespace adsb;
|
2016-11-30 06:41:55 +00:00
|
|
|
using namespace portapack;
|
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
void ADSBTxView::focus() {
|
2017-05-01 09:42:09 +00:00
|
|
|
//sym_icao.focus();
|
|
|
|
tx_view.focus();
|
2016-11-30 06:41:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ADSBTxView::~ADSBTxView() {
|
|
|
|
transmitter_model.disable();
|
|
|
|
baseband::shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ADSBTxView::paint(Painter& painter) {
|
2016-12-05 11:56:41 +00:00
|
|
|
(void)painter;
|
2016-11-30 06:41:55 +00:00
|
|
|
button_callsign.set_text(callsign);
|
|
|
|
}
|
|
|
|
|
2016-12-05 11:56:41 +00:00
|
|
|
void ADSBTxView::generate_frame() {
|
2017-02-01 00:21:13 +00:00
|
|
|
uint32_t c;
|
2016-12-01 05:58:47 +00:00
|
|
|
std::string str_debug;
|
2016-11-30 06:41:55 +00:00
|
|
|
|
2016-12-05 11:56:41 +00:00
|
|
|
generate_frame_id(adsb_frame, sym_icao.value_hex_u64(), callsign);
|
|
|
|
|
|
|
|
memset(adsb_bin, 0, 112);
|
|
|
|
|
2017-05-01 09:42:09 +00:00
|
|
|
// Convert to binary (1 byte per bit, faster for baseband code)
|
2016-12-05 11:56:41 +00:00
|
|
|
for (c = 0; c < 112; c++) {
|
2017-02-01 00:21:13 +00:00
|
|
|
if ((adsb_frame[c >> 3] << (c & 7)) & 0x80)
|
2017-05-01 09:42:09 +00:00
|
|
|
adsb_bin[c] = 1;
|
2016-11-30 06:41:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 09:42:09 +00:00
|
|
|
// Display in hex for debug
|
|
|
|
text_frame_a.set(to_string_hex_array(&adsb_frame[0], 7));
|
|
|
|
text_frame_b.set(to_string_hex_array(&adsb_frame[7], 7));
|
2016-12-01 05:58:47 +00:00
|
|
|
|
2017-02-01 00:21:13 +00:00
|
|
|
button_callsign.set_text(callsign);
|
2016-11-30 06:41:55 +00:00
|
|
|
}
|
|
|
|
|
2017-02-12 04:05:21 +00:00
|
|
|
bool ADSBTxView::start_tx() {
|
|
|
|
generate_frame();
|
|
|
|
|
2017-05-01 09:42:09 +00:00
|
|
|
memcpy(shared_memory.bb_data.data, adsb_bin, 112);
|
|
|
|
baseband::set_adsb();
|
|
|
|
|
2017-02-01 00:21:13 +00:00
|
|
|
transmitter_model.set_tuning_frequency(434000000); // FOR TESTING - DEBUG
|
2017-05-01 09:42:09 +00:00
|
|
|
transmitter_model.set_sampling_rate(4000000U);
|
2016-11-30 06:41:55 +00:00
|
|
|
transmitter_model.set_rf_amp(true);
|
|
|
|
transmitter_model.set_vga(40);
|
2017-05-01 09:42:09 +00:00
|
|
|
transmitter_model.set_baseband_bandwidth(2500000);
|
2016-11-30 06:41:55 +00:00
|
|
|
transmitter_model.enable();
|
|
|
|
|
2017-02-12 04:05:21 +00:00
|
|
|
return false; // DEBUG
|
2016-11-30 06:41:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 09:42:09 +00:00
|
|
|
void ADSBTxView::on_txdone(const bool v) {
|
2017-02-01 00:21:13 +00:00
|
|
|
//size_t sr;
|
2016-11-30 06:41:55 +00:00
|
|
|
|
2017-05-01 09:42:09 +00:00
|
|
|
if (v) {
|
2016-11-30 06:41:55 +00:00
|
|
|
transmitter_model.disable();
|
2017-05-01 09:42:09 +00:00
|
|
|
tx_view.set_transmitting(false);
|
2016-12-05 11:56:41 +00:00
|
|
|
//progress.set_value(0);
|
2016-11-30 06:41:55 +00:00
|
|
|
} else {
|
2016-12-05 11:56:41 +00:00
|
|
|
//progress.set_value(n);
|
2016-11-30 06:41:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ADSBTxView::ADSBTxView(NavigationView& nav) {
|
2017-02-01 00:21:13 +00:00
|
|
|
uint32_t c;
|
2016-11-30 06:41:55 +00:00
|
|
|
|
2016-12-01 05:58:47 +00:00
|
|
|
baseband::run_image(portapack::spi_flash::image_tag_adsb_tx);
|
|
|
|
|
2017-01-16 03:45:44 +00:00
|
|
|
add_children({
|
2017-02-13 05:35:13 +00:00
|
|
|
&labels,
|
2016-11-30 06:41:55 +00:00
|
|
|
&options_format,
|
2016-12-05 11:56:41 +00:00
|
|
|
&sym_icao,
|
2016-11-30 06:41:55 +00:00
|
|
|
&button_callsign,
|
2016-12-05 11:56:41 +00:00
|
|
|
&field_altitude,
|
|
|
|
&field_lat_degrees,
|
|
|
|
&field_lat_minutes,
|
|
|
|
&field_lat_seconds,
|
|
|
|
&field_lon_degrees,
|
|
|
|
&field_lon_minutes,
|
|
|
|
&field_lon_seconds,
|
2017-02-01 00:21:13 +00:00
|
|
|
&check_emergency,
|
|
|
|
&field_squawk,
|
2016-12-01 05:58:47 +00:00
|
|
|
&text_frame_a,
|
|
|
|
&text_frame_b,
|
2017-02-12 04:05:21 +00:00
|
|
|
&tx_view
|
2017-01-16 03:45:44 +00:00
|
|
|
});
|
2016-11-30 06:41:55 +00:00
|
|
|
|
|
|
|
options_format.set_by_value(17); // Mode S
|
|
|
|
|
|
|
|
options_format.on_change = [this](size_t i, int32_t v) {
|
|
|
|
(void)i;
|
|
|
|
(void)v;
|
2016-12-05 11:56:41 +00:00
|
|
|
generate_frame();
|
|
|
|
};
|
|
|
|
sym_icao.on_change = [this]() {
|
|
|
|
generate_frame();
|
2016-11-30 06:41:55 +00:00
|
|
|
};
|
|
|
|
button_callsign.on_select = [this, &nav](Button&) {
|
2017-04-18 17:12:32 +00:00
|
|
|
text_entry(nav, callsign, 9);
|
2016-11-30 06:41:55 +00:00
|
|
|
};
|
|
|
|
|
2016-12-05 11:56:41 +00:00
|
|
|
field_altitude.set_value(11000);
|
|
|
|
field_lat_degrees.set_value(0);
|
|
|
|
field_lat_minutes.set_value(0);
|
|
|
|
field_lat_seconds.set_value(0);
|
|
|
|
field_lon_degrees.set_value(0);
|
|
|
|
field_lon_minutes.set_value(0);
|
|
|
|
field_lon_seconds.set_value(0);
|
|
|
|
|
2017-02-01 00:21:13 +00:00
|
|
|
for (c = 0; c < 4; c++)
|
2017-03-13 04:09:21 +00:00
|
|
|
field_squawk.set_sym(c, 0);
|
2017-02-01 00:21:13 +00:00
|
|
|
|
2016-12-05 11:56:41 +00:00
|
|
|
generate_frame();
|
2017-02-12 04:05:21 +00:00
|
|
|
|
|
|
|
tx_view.on_edit_frequency = [this, &nav]() {
|
|
|
|
// Shouldn't be able to edit frequency
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
|
|
|
tx_view.on_start = [this]() {
|
|
|
|
if (start_tx())
|
|
|
|
tx_view.set_transmitting(true);
|
|
|
|
};
|
|
|
|
|
|
|
|
tx_view.on_stop = [this]() {
|
|
|
|
tx_view.set_transmitting(false);
|
|
|
|
transmitter_model.disable();
|
2016-11-30 06:41:55 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace ui */
|