2017-07-14 09:02:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
|
|
|
* Copyright (C) 2017 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_adsb_rx.hpp"
|
|
|
|
#include "ui_alphanum.hpp"
|
2017-07-22 18:30:20 +00:00
|
|
|
#include "ui_geomap.hpp"
|
2017-07-14 09:02:21 +00:00
|
|
|
|
|
|
|
#include "string_format.hpp"
|
|
|
|
#include "portapack.hpp"
|
|
|
|
#include "baseband_api.hpp"
|
|
|
|
#include "portapack_persistent_memory.hpp"
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
using namespace portapack;
|
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
2017-07-23 11:20:32 +00:00
|
|
|
template<>
|
2017-08-17 11:56:47 +00:00
|
|
|
void RecentEntriesTable<AircraftRecentEntries>::draw(
|
2017-07-23 11:20:32 +00:00
|
|
|
const Entry& entry,
|
|
|
|
const Rect& target_rect,
|
|
|
|
Painter& painter,
|
|
|
|
const Style& style
|
|
|
|
) {
|
2017-08-16 09:02:57 +00:00
|
|
|
painter.draw_string(
|
|
|
|
target_rect.location(),
|
|
|
|
style,
|
2017-08-17 11:56:47 +00:00
|
|
|
to_string_hex(entry.ICAO_address, 6) +
|
|
|
|
(entry.pos.valid ? " \x1B\x02" : " ") +
|
|
|
|
entry.callsign + " \x1B\x00" +
|
|
|
|
(entry.hits <= 999 ? to_string_dec_uint(entry.hits, 4) : "999+") + " " +
|
|
|
|
entry.time_string
|
2017-08-16 09:02:57 +00:00
|
|
|
);
|
2017-08-17 11:56:47 +00:00
|
|
|
|
|
|
|
if (entry.pos.valid)
|
|
|
|
painter.draw_bitmap(target_rect.location() + Point(15 * 8, 0), bitmap_target, style.foreground, style.background);
|
2017-07-23 11:20:32 +00:00
|
|
|
}
|
|
|
|
|
2017-07-14 09:02:21 +00:00
|
|
|
void ADSBRxView::focus() {
|
2017-08-16 09:02:57 +00:00
|
|
|
field_lna.focus();
|
2017-07-14 09:02:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ADSBRxView::~ADSBRxView() {
|
2017-07-23 11:20:32 +00:00
|
|
|
receiver_model.disable();
|
|
|
|
baseband::shutdown();
|
2017-07-14 09:02:21 +00:00
|
|
|
}
|
|
|
|
|
2017-08-16 09:02:57 +00:00
|
|
|
void ADSBRxView::on_frame(const ADSBFrameMessage * message) {
|
|
|
|
rtc::RTC datetime;
|
|
|
|
std::string str_timestamp;
|
|
|
|
std::string callsign;
|
2017-07-14 09:02:21 +00:00
|
|
|
|
2017-08-16 09:02:57 +00:00
|
|
|
auto frame = message->frame;
|
2017-07-14 09:02:21 +00:00
|
|
|
|
2017-08-16 09:02:57 +00:00
|
|
|
uint32_t ICAO_address = frame.get_ICAO_address();
|
|
|
|
|
|
|
|
|
|
|
|
if (frame.check_CRC() && frame.get_ICAO_address()) {
|
2017-08-17 11:56:47 +00:00
|
|
|
frame.set_rx_timestamp(datetime.minute() * 60 + datetime.second());
|
|
|
|
|
2017-08-16 09:02:57 +00:00
|
|
|
auto& entry = ::on_packet(recent, ICAO_address);
|
2017-07-14 09:02:21 +00:00
|
|
|
|
2017-08-16 09:02:57 +00:00
|
|
|
rtcGetTime(&RTCD1, &datetime);
|
2017-08-17 11:56:47 +00:00
|
|
|
str_timestamp = to_string_datetime(datetime, HMS);
|
|
|
|
entry.set_time_string(str_timestamp);
|
2017-07-14 09:02:21 +00:00
|
|
|
|
2017-08-16 09:02:57 +00:00
|
|
|
entry.inc_hit();
|
2017-07-14 09:02:21 +00:00
|
|
|
|
2017-08-16 09:02:57 +00:00
|
|
|
if (frame.get_DF() == DF_ADSB) {
|
2017-08-17 11:56:47 +00:00
|
|
|
uint8_t msg_type = frame.get_msg_type();
|
|
|
|
uint8_t * raw_data = frame.get_raw_data();
|
|
|
|
|
|
|
|
if ((msg_type >= 1) && (msg_type <= 4)) {
|
2017-08-16 09:02:57 +00:00
|
|
|
callsign = decode_frame_id(frame);
|
|
|
|
entry.set_callsign(callsign);
|
2017-08-17 11:56:47 +00:00
|
|
|
} else if ((msg_type >= 9) && (msg_type <= 18)) {
|
|
|
|
entry.set_frame_pos(frame, raw_data[6] & 4);
|
|
|
|
|
|
|
|
if (entry.pos.valid) {
|
|
|
|
callsign = "Alt:" + to_string_dec_uint(entry.pos.altitude) +
|
|
|
|
" Lat" + to_string_dec_int(entry.pos.latitude) +
|
|
|
|
"." + to_string_dec_int((int)(entry.pos.latitude * 1000) % 100) +
|
|
|
|
" Lon" + to_string_dec_int(entry.pos.longitude) +
|
|
|
|
"." + to_string_dec_int((int)(entry.pos.longitude * 1000) % 100);
|
|
|
|
|
|
|
|
entry.set_pos_string(callsign);
|
|
|
|
}
|
2017-07-14 09:02:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-16 09:02:57 +00:00
|
|
|
recent_entries_view.set_dirty();
|
2017-07-14 09:02:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-17 11:56:47 +00:00
|
|
|
ADSBRxView::ADSBRxView(NavigationView&) {
|
2017-07-23 11:20:32 +00:00
|
|
|
baseband::run_image(portapack::spi_flash::image_tag_adsb_rx);
|
2017-07-14 09:02:21 +00:00
|
|
|
|
|
|
|
add_children({
|
2017-08-16 09:02:57 +00:00
|
|
|
&labels,
|
|
|
|
&rssi,
|
|
|
|
&field_lna,
|
|
|
|
&field_vga,
|
2017-07-14 09:02:21 +00:00
|
|
|
&text_debug_a,
|
|
|
|
&text_debug_b,
|
|
|
|
&text_debug_c,
|
2017-07-23 11:20:32 +00:00
|
|
|
&recent_entries_view
|
2017-07-14 09:02:21 +00:00
|
|
|
});
|
|
|
|
|
2017-07-23 11:20:32 +00:00
|
|
|
recent_entries_view.set_parent_rect({ 0, 64, 240, 224 });
|
2017-08-17 11:56:47 +00:00
|
|
|
recent_entries_view.on_select = [this](const AircraftRecentEntry& entry) {
|
|
|
|
text_debug_a.set(entry.pos_string);
|
|
|
|
text_debug_b.set(to_string_hex_array(entry.frame_pos_even.get_raw_data(), 14));
|
|
|
|
text_debug_c.set(to_string_hex_array(entry.frame_pos_odd.get_raw_data(), 14));
|
2017-08-16 09:02:57 +00:00
|
|
|
};
|
2017-07-23 11:20:32 +00:00
|
|
|
|
|
|
|
baseband::set_adsb();
|
|
|
|
|
|
|
|
receiver_model.set_tuning_frequency(1090000000);
|
2017-08-16 09:02:57 +00:00
|
|
|
receiver_model.set_rf_amp(true);
|
|
|
|
field_lna.set_value(40);
|
|
|
|
field_vga.set_value(40);
|
2017-07-23 11:20:32 +00:00
|
|
|
receiver_model.set_modulation(ReceiverModel::Mode::SpectrumAnalysis);
|
|
|
|
receiver_model.set_sampling_rate(2000000);
|
|
|
|
receiver_model.set_baseband_bandwidth(2500000);
|
|
|
|
receiver_model.enable();
|
2017-07-14 09:02:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace ui */
|