2016-11-30 01:41:55 -05: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 06:56:41 -05:00
|
|
|
#include "adsb.hpp"
|
2016-11-30 01:41:55 -05: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 06:56:41 -05:00
|
|
|
using namespace adsb;
|
2016-11-30 01:41:55 -05:00
|
|
|
using namespace portapack;
|
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
void ADSBTxView::focus() {
|
|
|
|
button_transmit.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
ADSBTxView::~ADSBTxView() {
|
|
|
|
transmitter_model.disable();
|
|
|
|
baseband::shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ADSBTxView::paint(Painter& painter) {
|
2016-12-05 06:56:41 -05:00
|
|
|
(void)painter;
|
2016-11-30 01:41:55 -05:00
|
|
|
button_callsign.set_text(callsign);
|
|
|
|
}
|
|
|
|
|
2016-12-05 06:56:41 -05:00
|
|
|
void ADSBTxView::generate_frame() {
|
|
|
|
uint8_t c;
|
2016-12-01 00:58:47 -05:00
|
|
|
std::string str_debug;
|
|
|
|
|
2016-12-05 06:56:41 -05:00
|
|
|
if (options_format.selected_index() == 2)
|
|
|
|
button_transmit.hidden(true);
|
2016-11-30 01:41:55 -05:00
|
|
|
|
2016-12-05 06:56:41 -05:00
|
|
|
generate_frame_id(adsb_frame, sym_icao.value_hex_u64(), callsign);
|
|
|
|
|
|
|
|
memset(adsb_bin, 0, 112);
|
|
|
|
|
|
|
|
// Convert to binary (1 bit per byte, faster for baseband code)
|
|
|
|
for (c = 0; c < 112; c++) {
|
|
|
|
if ((adsb_frame[c >> 3] << (c & 7)) & 0x80) {
|
|
|
|
adsb_bin[c] = 0xFF;
|
2016-11-30 01:41:55 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-01 00:58:47 -05:00
|
|
|
// Display for debug
|
|
|
|
str_debug = "";
|
|
|
|
for (c = 0; c < 7; c++)
|
|
|
|
str_debug += to_string_hex(adsb_frame[c], 2);
|
|
|
|
text_frame_a.set(str_debug);
|
|
|
|
str_debug = "";
|
|
|
|
for (c = 0; c < 7; c++)
|
|
|
|
str_debug += to_string_hex(adsb_frame[c + 7], 2);
|
|
|
|
text_frame_b.set(str_debug);
|
|
|
|
|
2016-12-05 06:56:41 -05:00
|
|
|
//text_message.set(callsign_formatted);
|
2016-11-30 01:41:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void ADSBTxView::start_tx() {
|
2016-12-01 00:58:47 -05:00
|
|
|
transmitter_model.set_tuning_frequency(452000000); // FOR TESTING - DEBUG
|
2016-11-30 01:41:55 -05:00
|
|
|
transmitter_model.set_baseband_configuration({
|
|
|
|
.mode = 0,
|
2016-12-01 00:58:47 -05:00
|
|
|
.sampling_rate = 2000000U, // Good ?
|
2016-11-30 01:41:55 -05:00
|
|
|
.decimation_factor = 1,
|
|
|
|
});
|
|
|
|
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();
|
|
|
|
|
2016-12-09 12:21:47 -05:00
|
|
|
memcpy(shared_memory.bb_data.data, adsb_bin, 112);
|
2016-12-01 00:58:47 -05:00
|
|
|
baseband::set_adsb();
|
2016-11-30 01:41:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void ADSBTxView::on_txdone(const int n) {
|
|
|
|
size_t sr;
|
|
|
|
|
|
|
|
if (n == 200) {
|
|
|
|
transmitter_model.disable();
|
2016-12-05 06:56:41 -05:00
|
|
|
//progress.set_value(0);
|
2016-11-30 01:41:55 -05:00
|
|
|
|
|
|
|
tx_mode = IDLE;
|
|
|
|
button_transmit.set_style(&style_val);
|
|
|
|
button_transmit.set_text("START");
|
|
|
|
} else {
|
2016-12-05 06:56:41 -05:00
|
|
|
//progress.set_value(n);
|
2016-11-30 01:41:55 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ADSBTxView::ADSBTxView(NavigationView& nav) {
|
|
|
|
(void)nav;
|
|
|
|
|
2016-12-01 00:58:47 -05:00
|
|
|
baseband::run_image(portapack::spi_flash::image_tag_adsb_tx);
|
|
|
|
|
|
|
|
// http://openflights.org
|
2016-11-30 01:41:55 -05:00
|
|
|
|
|
|
|
add_children({ {
|
|
|
|
&text_format,
|
|
|
|
&options_format,
|
|
|
|
&text_icaolabel,
|
2016-12-05 06:56:41 -05:00
|
|
|
&sym_icao,
|
2016-11-30 01:41:55 -05:00
|
|
|
&text_callsign,
|
|
|
|
&button_callsign,
|
2016-12-05 06:56:41 -05:00
|
|
|
&text_altitude,
|
|
|
|
&field_altitude,
|
|
|
|
&text_latitude,
|
|
|
|
&field_lat_degrees,
|
|
|
|
&field_lat_minutes,
|
|
|
|
&field_lat_seconds,
|
|
|
|
&text_longitude,
|
|
|
|
&field_lon_degrees,
|
|
|
|
&field_lon_minutes,
|
|
|
|
&field_lon_seconds,
|
2016-12-01 00:58:47 -05:00
|
|
|
&text_frame_a,
|
|
|
|
&text_frame_b,
|
2016-11-30 01:41:55 -05:00
|
|
|
&button_transmit
|
|
|
|
} });
|
|
|
|
|
|
|
|
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 06:56:41 -05:00
|
|
|
generate_frame();
|
|
|
|
};
|
|
|
|
sym_icao.on_change = [this]() {
|
|
|
|
generate_frame();
|
2016-11-30 01:41:55 -05:00
|
|
|
};
|
|
|
|
button_callsign.on_select = [this, &nav](Button&) {
|
|
|
|
textentry(nav, callsign, 9);
|
|
|
|
};
|
|
|
|
|
2016-12-05 06:56:41 -05: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);
|
|
|
|
|
2016-11-30 01:41:55 -05:00
|
|
|
button_transmit.set_style(&style_val);
|
|
|
|
|
2016-12-05 06:56:41 -05:00
|
|
|
generate_frame();
|
2016-11-30 01:41:55 -05:00
|
|
|
|
|
|
|
// Single transmit
|
2016-12-01 00:58:47 -05:00
|
|
|
button_transmit.on_select = [this, &nav](Button&) {
|
2016-11-30 01:41:55 -05:00
|
|
|
if (tx_mode == IDLE) {
|
|
|
|
tx_mode = SINGLE;
|
|
|
|
button_transmit.set_style(&style_cancel);
|
|
|
|
button_transmit.set_text("Wait");
|
2016-12-05 06:56:41 -05:00
|
|
|
generate_frame();
|
2016-11-30 01:41:55 -05:00
|
|
|
start_tx();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace ui */
|