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.
|
|
|
|
*/
|
|
|
|
|
2017-07-14 09:02:21 +00:00
|
|
|
#include "ui_adsb_tx.hpp"
|
2016-11-30 06:41:55 +00:00
|
|
|
#include "ui_alphanum.hpp"
|
|
|
|
|
2017-07-25 07:30:12 +00:00
|
|
|
#include "manchester.hpp"
|
2016-11-30 06:41:55 +00:00
|
|
|
#include "string_format.hpp"
|
|
|
|
#include "portapack.hpp"
|
|
|
|
#include "baseband_api.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 {
|
|
|
|
|
2017-07-25 07:30:12 +00:00
|
|
|
Compass::Compass(
|
|
|
|
const Point parent_pos
|
|
|
|
) : Widget { { parent_pos, { 64, 64 } } }
|
|
|
|
{
|
2017-07-30 08:39:01 +00:00
|
|
|
}
|
|
|
|
|
2017-07-25 07:30:12 +00:00
|
|
|
void Compass::set_value(uint32_t new_value) {
|
|
|
|
Point center = screen_pos() + Point(32, 32);
|
|
|
|
|
2017-07-30 13:46:42 +00:00
|
|
|
new_value = range.clip(new_value);
|
2017-07-25 07:30:12 +00:00
|
|
|
|
|
|
|
display.draw_line(
|
|
|
|
center,
|
2017-07-30 08:39:01 +00:00
|
|
|
center + polar_to_point(value_, 28),
|
2017-07-25 07:30:12 +00:00
|
|
|
Color::dark_grey()
|
|
|
|
);
|
|
|
|
|
|
|
|
display.draw_line(
|
|
|
|
center,
|
2017-07-30 08:39:01 +00:00
|
|
|
center + polar_to_point(new_value, 28),
|
2017-07-25 07:30:12 +00:00
|
|
|
Color::green()
|
|
|
|
);
|
|
|
|
|
|
|
|
value_ = new_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Compass::paint(Painter&) {
|
|
|
|
display.fill_circle(screen_pos() + Point(32, 32), 32, Color::dark_grey(), Color::black());
|
2017-07-30 08:39:01 +00:00
|
|
|
|
2017-07-25 07:30:12 +00:00
|
|
|
display.fill_rectangle({ screen_pos() + Point(32 - 2, 0), { 4, 4 } }, Color::black()); // N
|
|
|
|
display.fill_rectangle({ screen_pos() + Point(32 - 2, 64 - 4), { 4, 4 } }, Color::black()); // S
|
|
|
|
display.fill_rectangle({ screen_pos() + Point(0, 32 - 2), { 4, 4 } }, Color::black()); // W
|
|
|
|
display.fill_rectangle({ screen_pos() + Point(64 - 4, 32 - 2), { 4, 4 } }, Color::black()); // E
|
|
|
|
|
|
|
|
set_value(value_);
|
|
|
|
}
|
|
|
|
|
2017-07-30 13:46:42 +00:00
|
|
|
ADSBView::ADSBView() {
|
|
|
|
add_child(&check_enable);
|
|
|
|
hidden(true);
|
|
|
|
|
|
|
|
check_enable.on_select = [this](Checkbox&, bool value) {
|
|
|
|
enabled = value;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void ADSBView::set_enabled(bool value) {
|
|
|
|
check_enable.set_value(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ADSBView::set_type(std::string type) {
|
|
|
|
check_enable.set_text("Transmit " + type);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ADSBView::focus() {
|
|
|
|
check_enable.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
ADSBPositionView::ADSBPositionView(NavigationView& nav) {
|
|
|
|
set_type("position");
|
|
|
|
|
|
|
|
add_children({
|
2017-08-03 18:06:59 +00:00
|
|
|
&geopos,
|
2017-07-30 13:46:42 +00:00
|
|
|
&button_set_map
|
|
|
|
});
|
|
|
|
|
2017-08-03 18:06:59 +00:00
|
|
|
geopos.set_altitude(36000);
|
2017-07-30 13:46:42 +00:00
|
|
|
|
|
|
|
button_set_map.on_select = [this, &nav](Button&) {
|
2017-08-03 18:06:59 +00:00
|
|
|
nav.push<GeoMapView>(
|
|
|
|
geopos.altitude(),
|
|
|
|
geopos.lat(),
|
|
|
|
geopos.lon(),
|
|
|
|
[this](int32_t altitude, float lat, float lon) {
|
|
|
|
geopos.set_altitude(altitude);
|
|
|
|
geopos.set_lat(lat);
|
|
|
|
geopos.set_lon(lon);
|
|
|
|
});
|
2017-07-30 13:46:42 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void ADSBPositionView::collect_frames(const uint32_t ICAO_address, std::vector<ADSBFrame>& frame_list) {
|
|
|
|
ADSBFrame temp_frame;
|
|
|
|
|
2017-08-03 18:06:59 +00:00
|
|
|
encode_frame_pos(temp_frame, ICAO_address, geopos.altitude(),
|
|
|
|
geopos.lat(), geopos.lon(), 0);
|
2017-07-30 13:46:42 +00:00
|
|
|
|
|
|
|
frame_list.emplace_back(temp_frame);
|
|
|
|
|
2017-08-03 18:06:59 +00:00
|
|
|
encode_frame_pos(temp_frame, ICAO_address, geopos.altitude(),
|
|
|
|
geopos.lat(), geopos.lon(), 1);
|
2017-07-30 13:46:42 +00:00
|
|
|
|
|
|
|
frame_list.emplace_back(temp_frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
ADSBCallsignView::ADSBCallsignView(NavigationView& nav) {
|
|
|
|
set_type("callsign");
|
|
|
|
|
|
|
|
add_children({
|
|
|
|
&labels_callsign,
|
|
|
|
&button_callsign
|
|
|
|
});
|
|
|
|
|
|
|
|
set_enabled(true);
|
|
|
|
|
|
|
|
button_callsign.set_text(callsign);
|
|
|
|
|
|
|
|
button_callsign.on_select = [this, &nav](Button&) {
|
|
|
|
text_prompt(nav, &callsign, 8);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void ADSBCallsignView::collect_frames(const uint32_t ICAO_address, std::vector<ADSBFrame>& frame_list) {
|
|
|
|
ADSBFrame temp_frame;
|
|
|
|
|
|
|
|
encode_frame_id(temp_frame, ICAO_address, callsign);
|
|
|
|
|
|
|
|
frame_list.emplace_back(temp_frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
ADSBSpeedView::ADSBSpeedView() {
|
|
|
|
set_type("speed");
|
|
|
|
|
|
|
|
add_children({
|
|
|
|
&labels_speed,
|
|
|
|
&compass,
|
|
|
|
&field_angle,
|
|
|
|
&field_speed
|
|
|
|
});
|
|
|
|
|
|
|
|
field_angle.set_value(0);
|
|
|
|
field_speed.set_value(400);
|
|
|
|
|
|
|
|
field_angle.on_change = [this](int32_t v) {
|
|
|
|
compass.set_value(v);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void ADSBSpeedView::collect_frames(const uint32_t ICAO_address, std::vector<ADSBFrame>& frame_list) {
|
|
|
|
ADSBFrame temp_frame;
|
|
|
|
|
|
|
|
encode_frame_velo(temp_frame, ICAO_address, field_speed.value(),
|
|
|
|
field_angle.value(), 0); // TODO: v_rate
|
|
|
|
|
|
|
|
frame_list.emplace_back(temp_frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
ADSBSquawkView::ADSBSquawkView() {
|
|
|
|
set_type("squawk");
|
|
|
|
|
|
|
|
add_children({
|
|
|
|
&labels_squawk,
|
|
|
|
&field_squawk
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void ADSBSquawkView::collect_frames(const uint32_t ICAO_address, std::vector<ADSBFrame>& frame_list) {
|
|
|
|
ADSBFrame temp_frame;
|
|
|
|
(void)ICAO_address;
|
|
|
|
|
|
|
|
encode_frame_squawk(temp_frame, field_squawk.value_dec_u32());
|
|
|
|
|
|
|
|
frame_list.emplace_back(temp_frame);
|
2017-07-25 07:30:12 +00:00
|
|
|
}
|
|
|
|
|
2016-11-30 06:41:55 +00:00
|
|
|
void ADSBTxView::focus() {
|
2017-07-30 13:46:42 +00:00
|
|
|
tab_view.focus();
|
2016-11-30 06:41:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ADSBTxView::~ADSBTxView() {
|
|
|
|
transmitter_model.disable();
|
|
|
|
baseband::shutdown();
|
|
|
|
}
|
|
|
|
|
2017-07-25 07:30:12 +00:00
|
|
|
void ADSBTxView::generate_frames() {
|
2017-07-30 13:46:42 +00:00
|
|
|
const uint32_t ICAO_address = sym_icao.value_hex_u64();
|
2016-11-30 06:41:55 +00:00
|
|
|
|
2017-08-03 18:06:59 +00:00
|
|
|
/* This scheme kinda sucks. Each "tab"'s collect_frames method
|
|
|
|
* is called to generate its related frame(s). Getting values
|
|
|
|
* from each widget of each tab would be better ?
|
|
|
|
* */
|
2017-07-30 13:46:42 +00:00
|
|
|
view_position.collect_frames(ICAO_address, frames);
|
|
|
|
view_callsign.collect_frames(ICAO_address, frames);
|
|
|
|
view_speed.collect_frames(ICAO_address, frames);
|
|
|
|
view_squawk.collect_frames(ICAO_address, frames);
|
2017-08-03 18:06:59 +00:00
|
|
|
|
|
|
|
// DEBUG: Show how many frames were generated
|
|
|
|
text_frame.set(to_string_dec_uint(frames.size()) + " frame(s).");
|
2016-12-05 11:56:41 +00:00
|
|
|
|
2017-07-30 13:46:42 +00:00
|
|
|
//memset(bin_ptr, 0, 240);
|
2016-12-05 11:56:41 +00:00
|
|
|
|
2017-07-30 13:46:42 +00:00
|
|
|
//auto raw_ptr = frames[0].get_raw_data();
|
2017-07-23 11:20:32 +00:00
|
|
|
|
2017-07-25 07:30:12 +00:00
|
|
|
// The preamble isn't manchester encoded
|
2017-07-30 13:46:42 +00:00
|
|
|
//memcpy(bin_ptr, adsb_preamble, 16);
|
2017-07-23 11:20:32 +00:00
|
|
|
|
2017-07-25 07:30:12 +00:00
|
|
|
// Convert to binary with manchester encoding (1 byte per bit, faster for baseband code)
|
|
|
|
/*for (c = 0; c < 112; c++) {
|
2017-07-23 11:20:32 +00:00
|
|
|
if ((raw_ptr[c >> 3] << (c & 7)) & 0x80) {
|
|
|
|
bin_ptr[(c * 2) + 16] = 1;
|
|
|
|
bin_ptr[(c * 2) + 16 + 1] = 0;
|
|
|
|
} else {
|
|
|
|
bin_ptr[(c * 2) + 16] = 0;
|
|
|
|
bin_ptr[(c * 2) + 16 + 1] = 1;
|
|
|
|
}
|
2017-07-25 07:30:12 +00:00
|
|
|
}*/
|
|
|
|
|
2017-07-30 13:46:42 +00:00
|
|
|
/*manchester_encode(bin_ptr + 16, raw_ptr, 112, 0);
|
2016-11-30 06:41:55 +00:00
|
|
|
|
2017-05-01 09:42:09 +00:00
|
|
|
// Display in hex for debug
|
2017-07-25 07:30:12 +00:00
|
|
|
text_frame.set(to_string_hex_array(frames[0].get_raw_data(), 14));
|
2016-12-01 05:58:47 +00:00
|
|
|
|
2017-07-30 13:46:42 +00:00
|
|
|
button_callsign.set_text(callsign);*/
|
2016-11-30 06:41:55 +00:00
|
|
|
}
|
|
|
|
|
2017-07-25 07:30:12 +00:00
|
|
|
void ADSBTxView::start_tx() {
|
|
|
|
generate_frames();
|
2017-02-12 04:05:21 +00:00
|
|
|
|
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);
|
2017-07-23 11:20:32 +00:00
|
|
|
transmitter_model.set_baseband_bandwidth(10000000);
|
2016-11-30 06:41:55 +00:00
|
|
|
transmitter_model.enable();
|
|
|
|
|
2017-07-23 11:20:32 +00:00
|
|
|
baseband::set_adsb();
|
2016-11-30 06:41:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 09:42:09 +00:00
|
|
|
void ADSBTxView::on_txdone(const bool v) {
|
2017-07-30 13:46:42 +00:00
|
|
|
(void)v;
|
2017-07-30 08:39:01 +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);
|
2017-07-30 08:39:01 +00:00
|
|
|
}*/
|
2017-07-23 11:20:32 +00:00
|
|
|
}
|
|
|
|
|
2017-07-30 13:46:42 +00:00
|
|
|
void ADSBTxView::rotate_frames() {
|
2017-07-23 11:20:32 +00:00
|
|
|
uint8_t * bin_ptr = shared_memory.bb_data.data;
|
|
|
|
uint8_t * raw_ptr;
|
2017-07-30 13:46:42 +00:00
|
|
|
uint32_t frame_index = 0; //, plane_index = 0;
|
|
|
|
uint32_t c; //, regen = 0;
|
|
|
|
//float offs = 0;
|
2017-07-23 11:20:32 +00:00
|
|
|
|
|
|
|
for (;;) {
|
2017-07-30 13:46:42 +00:00
|
|
|
/*if (!regen) {
|
2017-07-23 11:20:32 +00:00
|
|
|
regen = 10;
|
|
|
|
|
2017-07-25 07:30:12 +00:00
|
|
|
encode_frame_id(frames[0], plane_index, "DEMO" + to_string_dec_uint(plane_index));
|
|
|
|
encode_frame_pos(frames[1], plane_index, 5000, plane_lats[plane_index]/8 + offs + 38.5, plane_lons[plane_index]/8 + 125.8, 0);
|
|
|
|
encode_frame_pos(frames[2], plane_index, 5000, plane_lats[plane_index]/8 + offs + 38.5, plane_lons[plane_index]/8 + 125.8, 1);
|
|
|
|
encode_frame_identity(frames[3], plane_index, 1337);
|
2017-07-23 11:20:32 +00:00
|
|
|
|
|
|
|
if (plane_index == 11)
|
|
|
|
plane_index = 0;
|
|
|
|
else
|
|
|
|
plane_index++;
|
|
|
|
|
|
|
|
offs += 0.001;
|
2017-07-30 13:46:42 +00:00
|
|
|
}*/
|
2017-07-23 11:20:32 +00:00
|
|
|
|
|
|
|
memset(bin_ptr, 0, 240);
|
|
|
|
|
|
|
|
raw_ptr = frames[frame_index].get_raw_data();
|
|
|
|
|
|
|
|
memcpy(bin_ptr, adsb_preamble, 16);
|
|
|
|
|
|
|
|
// Convert to binary (1 byte per bit, faster for baseband code)
|
|
|
|
for (c = 0; c < 112; c++) {
|
|
|
|
if ((raw_ptr[c >> 3] << (c & 7)) & 0x80) {
|
|
|
|
bin_ptr[(c * 2) + 16] = 1;
|
|
|
|
bin_ptr[(c * 2) + 16 + 1] = 0;
|
|
|
|
} else {
|
|
|
|
bin_ptr[(c * 2) + 16] = 0;
|
|
|
|
bin_ptr[(c * 2) + 16 + 1] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
baseband::set_adsb();
|
|
|
|
|
2017-07-30 13:46:42 +00:00
|
|
|
chThdSleepMilliseconds(50);
|
2017-07-23 11:20:32 +00:00
|
|
|
|
2017-07-30 13:46:42 +00:00
|
|
|
if (frame_index == frames.size()) {
|
2017-07-23 11:20:32 +00:00
|
|
|
frame_index = 0;
|
2017-07-30 13:46:42 +00:00
|
|
|
//if (regen)
|
|
|
|
// regen--;
|
2017-07-23 11:20:32 +00:00
|
|
|
} else {
|
|
|
|
frame_index++;
|
|
|
|
}
|
2016-11-30 06:41:55 +00:00
|
|
|
}
|
2017-07-30 13:46:42 +00:00
|
|
|
}
|
2016-11-30 06:41:55 +00:00
|
|
|
|
2017-07-30 13:46:42 +00:00
|
|
|
ADSBTxView::ADSBTxView(
|
|
|
|
NavigationView& nav
|
|
|
|
) : nav_ { nav }
|
|
|
|
{
|
|
|
|
Rect view_rect = { 0, 7 * 8, 240, 192 };
|
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-07-30 08:39:01 +00:00
|
|
|
&tab_view,
|
2017-07-30 13:46:42 +00:00
|
|
|
&labels,
|
2016-12-05 11:56:41 +00:00
|
|
|
&sym_icao,
|
2017-07-30 13:46:42 +00:00
|
|
|
&view_position,
|
|
|
|
&view_callsign,
|
|
|
|
&view_speed,
|
|
|
|
&view_squawk,
|
2017-07-25 07:30:12 +00:00
|
|
|
&text_frame,
|
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
|
|
|
|
2017-07-30 13:46:42 +00:00
|
|
|
view_position.set_parent_rect(view_rect);
|
|
|
|
view_callsign.set_parent_rect(view_rect);
|
|
|
|
view_speed.set_parent_rect(view_rect);
|
|
|
|
view_squawk.set_parent_rect(view_rect);
|
2017-07-25 07:30:12 +00:00
|
|
|
|
2017-02-12 04:05:21 +00:00
|
|
|
tx_view.on_start = [this]() {
|
2017-07-25 07:30:12 +00:00
|
|
|
start_tx();
|
|
|
|
tx_view.set_transmitting(true);
|
2017-08-03 18:06:59 +00:00
|
|
|
// Disable for DEBUG
|
|
|
|
//rotate_frames();
|
2017-02-12 04:05:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
tx_view.on_stop = [this]() {
|
|
|
|
tx_view.set_transmitting(false);
|
|
|
|
transmitter_model.disable();
|
2016-11-30 06:41:55 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace ui */
|