ADSB position decoding

Date and time string format function
Binary update
This commit is contained in:
furrtek 2017-08-17 12:56:47 +01:00
parent 9d902bc224
commit 2628f9c03d
15 changed files with 255 additions and 108 deletions

View file

@ -727,6 +727,28 @@ static constexpr Bitmap bitmap_icon_setup {
{ 16, 16 }, bitmap_icon_setup_data
};
static constexpr uint8_t bitmap_target_data[] = {
0x80, 0x00,
0x80, 0x00,
0xE0, 0x03,
0x90, 0x04,
0x88, 0x08,
0x04, 0x10,
0x04, 0x10,
0x1F, 0x7C,
0x04, 0x10,
0x04, 0x10,
0x88, 0x08,
0x90, 0x04,
0xE0, 0x03,
0x80, 0x00,
0x80, 0x00,
0x00, 0x00,
};
static constexpr Bitmap bitmap_target {
{ 16, 16 }, bitmap_target_data
};
static constexpr uint8_t bitmap_sig_saw_down_data[] = {
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,

View file

@ -157,7 +157,7 @@ void POCSAGAppView::on_packet(const POCSAGPacketMessage * message) {
std::string console_info;
console_info = "\n\x1B\x02" + to_string_time(message->packet.timestamp());
console_info = "\n" + to_string_datetime(message->packet.timestamp(), HM);
console_info += " " + pocsag::bitrate_str(message->packet.bitrate());
console_info += " ADDR:" + to_string_dec_uint(pocsag_state.address);
console_info += " F" + to_string_dec_uint(pocsag_state.function);

View file

@ -41,7 +41,7 @@ void RecentEntriesHeader::paint(Painter& painter) {
const Style style {
.font = parent_style.font,
.background = Color::dark_blue(),
.background = Color::blue(),
.foreground = parent_style.foreground,
};

View file

@ -144,18 +144,22 @@ std::string to_string_hex_array(uint8_t * const array, const int32_t l) {
return str_return;
}
std::string to_string_datetime(const rtc::RTC& value) {
return to_string_dec_uint(value.year(), 4, '0') + "/" +
to_string_dec_uint(value.month(), 2, '0') + "/" +
to_string_dec_uint(value.day(), 2, '0') + " " +
to_string_dec_uint(value.hour(), 2, '0') + ":" +
to_string_dec_uint(value.minute(), 2, '0') + ":" +
to_string_dec_uint(value.second(), 2, '0');
}
std::string to_string_time(const rtc::RTC& value) {
return to_string_dec_uint(value.hour(), 2, '0') + ":" +
to_string_dec_uint(value.minute(), 2, '0');
std::string to_string_datetime(const rtc::RTC& value, const TimeFormat format) {
std::string string { "" };
if (format == YMDHMS) {
string += to_string_dec_uint(value.year(), 4, '0') + "/" +
to_string_dec_uint(value.month(), 2, '0') + "/" +
to_string_dec_uint(value.day(), 2, '0') + " ";
}
string += to_string_dec_uint(value.hour(), 2, '0') + ":" +
string += to_string_dec_uint(value.minute(), 2, '0');
if ((format == YMDHMS) || (format == HMS))
string += ":" + to_string_dec_uint(value.second(), 2, '0');
return string;
}
std::string to_string_timestamp(const rtc::RTC& value) {

View file

@ -29,6 +29,12 @@
#include "lpc43xx_cpp.hpp"
using namespace lpc43xx;
enum TimeFormat {
YMDHMS = 0,
HMS = 1,
HM = 2
};
// TODO: Allow l=0 to not fill/justify? Already using this way in ui_spectrum.hpp...
std::string to_string_bin(const uint32_t n, const uint8_t l = 0);
std::string to_string_dec_uint(const uint32_t n, const int32_t l = 0, const char fill = 0);
@ -38,8 +44,7 @@ std::string to_string_hex_array(uint8_t * const array, const int32_t l = 0);
std::string to_string_short_freq(const uint64_t f);
std::string to_string_datetime(const rtc::RTC& value);
std::string to_string_time(const rtc::RTC& value);
std::string to_string_datetime(const rtc::RTC& value, const TimeFormat format = YMDHMS);
std::string to_string_timestamp(const rtc::RTC& value);
#endif/*__STRING_FORMAT_H__*/

View file

@ -24,7 +24,6 @@
#include "ui_alphanum.hpp"
#include "ui_geomap.hpp"
#include "adsb.hpp"
#include "string_format.hpp"
#include "portapack.hpp"
#include "baseband_api.hpp"
@ -33,13 +32,12 @@
#include <cstring>
#include <stdio.h>
using namespace adsb;
using namespace portapack;
namespace ui {
template<>
void RecentEntriesTable<ADSBRecentEntries>::draw(
void RecentEntriesTable<AircraftRecentEntries>::draw(
const Entry& entry,
const Rect& target_rect,
Painter& painter,
@ -48,9 +46,15 @@ void RecentEntriesTable<ADSBRecentEntries>::draw(
painter.draw_string(
target_rect.location(),
style,
to_string_hex(entry.ICAO_address, 6) + " " + entry.callsign + " " + (entry.hits <= 9999 ? to_string_dec_uint(entry.hits, 5) : "9999+") + " " + entry.time
//to_string_hex_array((uint8_t*)entry.raw_data, 10) + " " + entry.time
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
);
if (entry.pos.valid)
painter.draw_bitmap(target_rect.location() + Point(15 * 8, 0), bitmap_target, style.foreground, style.background);
}
void ADSBRxView::focus() {
@ -73,24 +77,35 @@ void ADSBRxView::on_frame(const ADSBFrameMessage * message) {
if (frame.check_CRC() && frame.get_ICAO_address()) {
frame.set_rx_timestamp(datetime.minute() * 60 + datetime.second());
auto& entry = ::on_packet(recent, ICAO_address);
rtcGetTime(&RTCD1, &datetime);
str_timestamp = to_string_dec_uint(datetime.hour(), 2, '0') + ":" +
to_string_dec_uint(datetime.minute(), 2, '0') + ":" +
to_string_dec_uint(datetime.second(), 2, '0');
str_timestamp = to_string_datetime(datetime, HMS);
entry.set_time_string(str_timestamp);
entry.set_time(str_timestamp);
entry.set_raw(frame.get_raw_data());
entry.inc_hit();
if (frame.get_DF() == DF_ADSB) {
if (frame.get_msg_type() == TC_IDENT) {
uint8_t msg_type = frame.get_msg_type();
uint8_t * raw_data = frame.get_raw_data();
if ((msg_type >= 1) && (msg_type <= 4)) {
callsign = decode_frame_id(frame);
entry.set_callsign(callsign);
} else if (frame.get_msg_type() == TC_AIRBORNE_POS) {
callsign = "Altitude: " + to_string_dec_uint(decode_frame_pos(frame)) + "ft";
entry.set_pos(callsign);
} 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);
}
}
}
@ -98,7 +113,7 @@ void ADSBRxView::on_frame(const ADSBFrameMessage * message) {
}
}
ADSBRxView::ADSBRxView(NavigationView& nav) {
ADSBRxView::ADSBRxView(NavigationView&) {
baseband::run_image(portapack::spi_flash::image_tag_adsb_rx);
add_children({
@ -113,8 +128,10 @@ ADSBRxView::ADSBRxView(NavigationView& nav) {
});
recent_entries_view.set_parent_rect({ 0, 64, 240, 224 });
recent_entries_view.on_select = [this](const ADSBRecentEntry& entry) {
text_debug_a.set(entry.geo_pos);
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));
};
baseband::set_adsb();

View file

@ -26,28 +26,30 @@
#include "ui_font_fixed_8x16.hpp"
#include "recent_entries.hpp"
#include "adsb.hpp"
#include "message.hpp"
using namespace adsb;
namespace ui {
struct ADSBRecentEntry {
struct AircraftRecentEntry {
using Key = uint32_t;
static constexpr Key invalid_key = 0xffffffff;
uint32_t ICAO_address { };
uint16_t hits { 0 };
uint8_t raw_data[14] { }; // 112 bits at most
std::string callsign { " " };
std::string time { "" };
std::string geo_pos { "" };
ADSBRecentEntry(
) : ADSBRecentEntry { 0 }
{
}
adsb_pos pos { false, 0, 0, 0 };
ADSBRecentEntry(
ADSBFrame frame_pos_even { };
ADSBFrame frame_pos_odd { };
std::string callsign { " " };
std::string time_string { "" };
std::string pos_string { "" };
AircraftRecentEntry(
const uint32_t ICAO_address
) : ICAO_address { ICAO_address }
{
@ -65,24 +67,32 @@ struct ADSBRecentEntry {
hits++;
}
void set_pos(std::string& new_pos) {
geo_pos = new_pos;
void set_frame_pos(ADSBFrame& frame, uint32_t parity) {
if (!parity)
frame_pos_even = frame;
else
frame_pos_odd = frame;
if (!frame_pos_even.empty() && !frame_pos_odd.empty()) {
if (abs(frame_pos_even.get_rx_timestamp() - frame_pos_odd.get_rx_timestamp()) < 20)
pos = decode_frame_pos(frame_pos_even, frame_pos_odd);
}
}
void set_time(std::string& new_time) {
time = new_time;
void set_pos_string(std::string& new_pos_string) {
pos_string = new_pos_string;
}
void set_raw(uint8_t * raw_ptr) {
memcpy(raw_data, raw_ptr, 14);
void set_time_string(std::string& new_time_string) {
time_string = new_time_string;
}
};
using ADSBRecentEntries = RecentEntries<ADSBRecentEntry>;
using AircraftRecentEntries = RecentEntries<AircraftRecentEntry>;
class ADSBRxView : public View {
public:
ADSBRxView(NavigationView& nav);
ADSBRxView(NavigationView&);
~ADSBRxView();
void focus() override;
@ -94,12 +104,12 @@ private:
const RecentEntriesColumns columns { {
{ "ICAO", 6 },
{ "Callsign", 8 },
{ "Hits", 5 },
{ "Callsign", 9 },
{ "Hits", 4 },
{ "Time", 8 }
} };
ADSBRecentEntries recent { };
RecentEntriesView<RecentEntries<ADSBRecentEntry>> recent_entries_view { columns, recent };
AircraftRecentEntries recent { };
RecentEntriesView<RecentEntries<AircraftRecentEntry>> recent_entries_view { columns, recent };
RSSI rssi {
{ 19 * 8, 4, 10 * 8, 8 },