Added velocity/bearing ADS-B frame for tx

Added compass widget
Manchester encoder
This commit is contained in:
furrtek
2017-07-25 08:30:12 +01:00
parent c2a9ed7d9b
commit 0cbf9cd386
9 changed files with 290 additions and 121 deletions

View File

@@ -23,7 +23,7 @@
// Color bitmaps generated with:
// Gimp image > indexed colors (16), then "xxd -i *.bmp"
//TODO: De bruijn sequence scanner for encoders
//TEST: ADS-B tx manchester encoder, velocity and squawk frames
//TEST: Mic tx
//TEST: Menuview refresh, seems to blink a lot
//TEST: Check AFSK transmit end, skips last bits ?
@@ -37,6 +37,7 @@
//BUG: REPLAY freezes when SD card not present
//BUG: RDS doesn't stop baseband when stopping tx ?
//TODO: De bruijn sequence scanner for encoders
//TODO: Make freqman refresh simpler (use previous black rectangle method)
//TODO: Merge AFSK and TONES procs ?
//TODO: NFM RX mode: nav.pop on squelch

View File

@@ -279,9 +279,9 @@ bool init() {
return false;
}
/*if( !hackrf::cpld::load_sram() ) {
if( !hackrf::cpld::load_sram() ) {
chSysHalt();
}*/
}
portapack::io.init();

View File

@@ -23,6 +23,7 @@
#include "ui_adsb_tx.hpp"
#include "ui_alphanum.hpp"
#include "manchester.hpp"
#include "string_format.hpp"
#include "portapack.hpp"
#include "baseband_api.hpp"
@@ -35,6 +36,47 @@ using namespace portapack;
namespace ui {
Compass::Compass(
const Point parent_pos
) : Widget { { parent_pos, { 64, 64 } } }
{
set_focusable(false); // Useless ?
}
void Compass::set_value(uint32_t new_value) {
Point center = screen_pos() + Point(32, 32);
new_value = clamp_value(new_value);
display.draw_line(
center,
center + Point(sin_f32(DEG_TO_RAD(value_) + (pi / 2)) * 28, -sin_f32(DEG_TO_RAD(value_)) * 28),
Color::dark_grey()
);
display.draw_line(
center,
center + Point(sin_f32(DEG_TO_RAD(new_value) + (pi / 2)) * 28, -sin_f32(DEG_TO_RAD(new_value)) * 28),
Color::green()
);
value_ = new_value;
}
void Compass::paint(Painter&) {
display.fill_circle(screen_pos() + Point(32, 32), 32, Color::dark_grey(), Color::black());
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_);
}
uint32_t Compass::clamp_value(uint32_t value) {
return range.clip(value);
}
void ADSBTxView::focus() {
tx_view.focus();
}
@@ -48,22 +90,25 @@ void ADSBTxView::paint(Painter&) {
button_callsign.set_text(callsign);
}
void ADSBTxView::generate_frame() {
uint32_t c;
void ADSBTxView::generate_frames() {
uint8_t * bin_ptr = shared_memory.bb_data.data;
generate_frame_id(frames[0], sym_icao.value_hex_u64(), callsign);
generate_frame_pos(frames[1], sym_icao.value_hex_u64(), 5000, field_lat_degrees.value(), field_lon_degrees.value(), 0);
generate_frame_pos(frames[2], sym_icao.value_hex_u64(), 5000, field_lat_degrees.value(), field_lon_degrees.value(), 1);
encode_frame_id(frames[0], sym_icao.value_hex_u64(), callsign);
encode_frame_pos(frames[1], sym_icao.value_hex_u64(), field_altitude.value(),
field_lat_degrees.value(), field_lon_degrees.value(), 0);
encode_frame_pos(frames[2], sym_icao.value_hex_u64(), field_altitude.value(),
field_lat_degrees.value(), field_lon_degrees.value(), 1);
memset(bin_ptr, 0, 240);
auto raw_ptr = frames[0].get_raw_data();
// The preamble isn't manchester encoded
memcpy(bin_ptr, adsb_preamble, 16);
// Convert to binary (1 byte per bit, faster for baseband code)
for (c = 0; c < 112; c++) {
// Convert to binary with manchester encoding (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;
@@ -71,19 +116,20 @@ void ADSBTxView::generate_frame() {
bin_ptr[(c * 2) + 16] = 0;
bin_ptr[(c * 2) + 16 + 1] = 1;
}
}
}*/
manchester_encode(bin_ptr + 16, raw_ptr, 112, 0);
// Display in hex for debug
text_frame_a.set(to_string_hex_array(frames[0].get_raw_data(), 7));
text_frame_b.set(to_string_hex_array(frames[0].get_raw_data() + 7, 7));
text_frame.set(to_string_hex_array(frames[0].get_raw_data(), 14));
button_callsign.set_text(callsign);
}
bool ADSBTxView::start_tx() {
generate_frame();
void ADSBTxView::start_tx() {
generate_frames();
transmitter_model.set_tuning_frequency(434000000);
transmitter_model.set_tuning_frequency(434000000); // DEBUG
transmitter_model.set_sampling_rate(4000000U);
transmitter_model.set_rf_amp(true);
transmitter_model.set_vga(40);
@@ -91,8 +137,6 @@ bool ADSBTxView::start_tx() {
transmitter_model.enable();
baseband::set_adsb();
return true;
}
void ADSBTxView::on_txdone(const bool v) {
@@ -102,7 +146,7 @@ void ADSBTxView::on_txdone(const bool v) {
}
}
void ADSBTxView::rotate_frames() {
/*void ADSBTxView::rotate_frames() {
// DEBUG
uint8_t * bin_ptr = shared_memory.bb_data.data;
uint8_t * raw_ptr;
@@ -114,10 +158,10 @@ void ADSBTxView::rotate_frames() {
if (!regen) {
regen = 10;
generate_frame_id(frames[0], plane_index, "DEMO" + to_string_dec_uint(plane_index));
generate_frame_pos(frames[1], plane_index, 5000, plane_lats[plane_index]/8 + offs + 38.5, plane_lons[plane_index]/8 + 125.8, 0);
generate_frame_pos(frames[2], plane_index, 5000, plane_lats[plane_index]/8 + offs + 38.5, plane_lons[plane_index]/8 + 125.8, 1);
generate_frame_identity(frames[3], plane_index, 1337);
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);
if (plane_index == 11)
plane_index = 0;
@@ -156,7 +200,7 @@ void ADSBTxView::rotate_frames() {
frame_index++;
}
}
}
}*/
ADSBTxView::ADSBTxView(NavigationView& nav) {
uint32_t c;
@@ -165,7 +209,7 @@ ADSBTxView::ADSBTxView(NavigationView& nav) {
add_children({
&labels,
&options_format,
//&options_format,
&sym_icao,
&button_callsign,
&field_altitude,
@@ -175,50 +219,67 @@ ADSBTxView::ADSBTxView(NavigationView& nav) {
&field_lon_degrees,
&field_lon_minutes,
&field_lon_seconds,
&compass,
&field_angle,
&field_speed,
&check_emergency,
&field_squawk,
&text_frame_a,
&text_frame_b,
&text_frame,
&tx_view
});
options_format.set_by_value(17); // Mode S
/*options_format.set_by_value(17); // Mode S
options_format.on_change = [this](size_t, int32_t) {
generate_frame();
};
generate_frames();
};*/
sym_icao.on_change = [this]() {
generate_frame();
generate_frames();
};
button_callsign.on_select = [this, &nav](Button&) {
text_prompt(nav, &callsign, 8);
};
field_altitude.set_value(11000);
field_altitude.set_value(36000);
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);
field_angle.set_value(0);
field_speed.set_value(0);
field_altitude.on_change = [this](int32_t) {
generate_frames();
};
field_lat_degrees.on_change = [this](int32_t) {
generate_frame();
generate_frames();
};
field_lon_degrees.on_change = [this](int32_t) {
generate_frame();
generate_frames();
};
field_angle.on_change = [this](int32_t v) {
compass.set_value(v);
generate_frames();
};
field_speed.on_change = [this](int32_t) {
generate_frames();
};
for (c = 0; c < 4; c++)
field_squawk.set_sym(c, 0);
generate_frame();
generate_frames();
receiver_model.set_tuning_frequency(434000000); // DEBUG
tx_view.on_start = [this]() {
if (start_tx())
tx_view.set_transmitting(true);
start_tx();
tx_view.set_transmitting(true);
//rotate_frames();
};

View File

@@ -22,10 +22,11 @@
#include "ui.hpp"
#include "adsb.hpp"
#include "utility.hpp"
#include "sine_table.hpp"
#include "ui_textentry.hpp"
#include "ui_widget.hpp"
#include "ui_navigation.hpp"
#include "ui_font_fixed_8x16.hpp"
#include "ui_transmitter.hpp"
#include "message.hpp"
@@ -36,6 +37,21 @@ using namespace adsb;
namespace ui {
class Compass : public Widget {
public:
Compass(const Point parent_pos);
void set_value(uint32_t new_value);
void paint(Painter&) override;
private:
const range_t<uint32_t> range { 0, 359 };
uint32_t value_ { 0 };
uint32_t clamp_value(uint32_t value);
};
class ADSBTxView : public View {
public:
ADSBTxView(NavigationView& nav);
@@ -85,37 +101,28 @@ private:
tx_modes tx_mode = IDLE;
std::string callsign = "PORTAPAC";
std::string callsign = "TEST1234";
ADSBFrame frames[4] { };
bool start_tx();
void generate_frame();
void rotate_frames();
void start_tx();
void generate_frames();
//void rotate_frames();
void on_txdone(const bool v);
const Style style_val {
.font = font::fixed_8x16,
.background = Color::black(),
.foreground = Color::green(),
};
const Style style_cancel {
.font = font::fixed_8x16,
.background = Color::black(),
.foreground = Color::red(),
};
Labels labels {
{ { 2 * 8, 2 * 8 }, "Format:", Color::light_grey() },
{ { 2 * 8, 2 * 8 }, "Format: 17 (ADS-B)", Color::light_grey() },
{ { 2 * 8, 4 * 8 }, "ICAO24:", Color::light_grey() },
{ { 2 * 8, 7 * 8 }, "ID:", Color::light_grey() },
{ { 2 * 8, 10 * 8 }, "Altitude: feet", Color::light_grey() },
{ { 2 * 8, 12 * 8 }, "Latitude: * ' \"", Color::light_grey() }, // No ° symbol in 8x16 font
{ { 2 * 8, 14 * 8 }, "Longitude: * ' \"", Color::light_grey() }, // No ° symbol in 8x16 font
{ { 15 * 8, 18 * 8 }, "Squawk", Color::light_grey() }
{ { 2 * 8, 7 * 8 }, "Callsign:", Color::light_grey() },
{ { 1 * 8, 11 * 8 }, "Alt: feet", Color::light_grey() },
{ { 1 * 8, 13 * 8 }, "Lat: * ' \"", Color::light_grey() }, // No ° symbol in 8x16 font
{ { 1 * 8, 15 * 8 }, "Lon: * ' \"", Color::light_grey() },
{ { 1 * 8, 18 * 8 }, "Speed: kn Bearing: *", Color::light_grey() },
{ { 16 * 8, 22 * 8 }, "Squawk:", Color::light_grey() }
};
OptionsField options_format {
// Only ADS-B is implemented right now
/*OptionsField options_format {
{ 10 * 8, 1 * 16 },
9,
{
@@ -123,7 +130,7 @@ private:
{ "18: TIS-B", 18 },
{ "19: MIL ", 19 },
}
};
};*/
SymField sym_icao {
{ 10 * 8, 2 * 16 },
@@ -132,12 +139,12 @@ private:
};
Button button_callsign {
{ 6 * 8, 3 * 16 + 4, 10 * 8, 24 },
{ 12 * 8, 3 * 16 + 4, 10 * 8, 24 },
""
};
NumberField field_altitude {
{ 12 * 8, 5 * 16 },
{ 6 * 8, 11 * 8 },
5,
{ -1000, 50000 },
250,
@@ -145,44 +152,50 @@ private:
};
NumberField field_lat_degrees {
{ 12 * 8, 6 * 16 }, 4, { -90, 90 }, 1, ' '
{ 6 * 8, 13 * 8 }, 4, { -90, 90 }, 1, ' '
};
NumberField field_lat_minutes {
{ 17 * 8, 6 * 16 }, 2, { 0, 59 }, 1, ' '
{ 11 * 8, 13 * 8 }, 2, { 0, 59 }, 1, ' '
};
NumberField field_lat_seconds {
{ 20 * 8, 6 * 16 }, 2, { 0, 59 }, 1, ' '
{ 14 * 8, 13 * 8 }, 2, { 0, 59 }, 1, ' '
};
NumberField field_lon_degrees {
{ 12 * 8, 7 * 16 }, 4, { -180, 180 }, 1, ' '
{ 6 * 8, 15 * 8 }, 4, { -180, 180 }, 1, ' '
};
NumberField field_lon_minutes {
{ 17 * 8, 7 * 16 }, 2, { 0, 59 }, 1, ' '
{ 11 * 8, 15 * 8 }, 2, { 0, 59 }, 1, ' '
};
NumberField field_lon_seconds {
{ 20 * 8, 7 * 16 }, 2, { 0, 59 }, 1, ' '
{ 14 * 8, 15 * 8 }, 2, { 0, 59 }, 1, ' '
};
Compass compass {
{ 21 * 8, 5 * 16 }
};
NumberField field_angle {
{ 21 * 8 + 20, 9 * 16 }, 3, { 0, 359 }, 1, ' '
};
NumberField field_speed {
{ 8 * 8, 18 * 8 }, 3, { 0, 999 }, 5, ' '
};
Checkbox check_emergency {
{ 2 * 8, 9 * 16 - 4 },
{ 2 * 8, 11 * 16 - 4 },
9,
"Emergency",
false
};
SymField field_squawk {
{ 22 * 8, 9 * 16 },
{ 24 * 8, 11 * 16 },
4,
SymField::SYMFIELD_OCT
};
Text text_frame_a {
{ 2 * 8, 13 * 16, 14 * 8, 16 },
"-"
};
Text text_frame_b {
{ 2 * 8, 14 * 16, 14 * 8, 16 },
Text text_frame {
{ 1 * 8, 29 * 8, 14 * 8, 16 },
"-"
};