Started work on ADS-B TX baseband processor

This commit is contained in:
furrtek 2016-12-01 06:58:47 +01:00
parent 596071e8f8
commit ef0feae62b
15 changed files with 413 additions and 82 deletions

View file

@ -1,5 +1,6 @@
/*
* Copyright (C) 2016 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2016 Furrtek
*
* This file is part of PortaPack.
*
@ -143,6 +144,13 @@ void set_pocsag() {
send_message(&message);
}
void set_adsb() {
const ADSBConfigureMessage message {
1
};
send_message(&message);
}
void set_dtmf_data(const uint32_t bw, const uint32_t tone_length, const uint32_t pause_length) {
const DTMFTXConfigMessage message {
bw,

View file

@ -1,5 +1,6 @@
/*
* Copyright (C) 2016 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2016 Furrtek
*
* This file is part of PortaPack.
*
@ -61,6 +62,7 @@ void set_afsk_data(const uint32_t afsk_samples_per_bit, const uint32_t afsk_phas
void set_ook_data(const uint32_t stream_length, const uint32_t samples_per_bit, const uint8_t repeat,
const uint32_t pause_symbols);
void set_pocsag();
void set_adsb();
void set_dtmf_data(const uint32_t bw, const uint32_t tone_length, const uint32_t pause_length);
void run_image(const portapack::spi_flash::image_tag_t image_tag);

View file

@ -48,13 +48,92 @@ void ADSBTxView::paint(Painter& painter) {
button_callsign.set_text(callsign);
}
void ADSBTxView::generate_frame() {
void ADSBTxView::generate_frame_pos() {
uint8_t b, c, s, time_parity, bitn;
char ch;
std::string str_debug;
uint16_t altitude_coded = (38000 + 1000) / 25;
uint32_t LAT, LON;
float delta_lat, yz, rlat, delta_lon, xz;
uint8_t adsb_crc[14]; // Temp buffer
uint32_t crc_poly = 0x1205FFF;
LAT = 0;
adsb_frame[0] = (options_format.selected_index_value() << 3) | 5; // DF and CA
adsb_frame[1] = 0x48; // ICAO24
adsb_frame[2] = 0x40;
adsb_frame[3] = 0xD6;
adsb_frame[4] = 0x58; // TC, SS and NICsb
// altitude = (feet + 1000) / 25
// LAT:
// index j = floor(59*latcprE-60*latcprO+0.50)
// latE = DlatE*(mod(j,60)+latcprE)
// latO = DlatO*(mod(j,59)+latcprO)
// if latE >= 270 -> latE -= 360
// if latO >= 270 -> latO -= 360
//time_parity = 0; // 0~1
//delta_lat = 90.0 / (60.0 - (time_parity / 4.0));
//yz = 524288.0 * (mod(lat, delta_lat) / delta_lat); // Round to int !
//rlat = delta_lat * ((yz / 524288.0) + int(lat / delta_lat));
//delta_lon = 360.0 / (NL(rlat) - time_parity);
//xz = 524288.0 * (mod(lon, delta_lon) / delta_lon); // Round to int !
/*if (time_parity) {
A = sign(rlat0)[NL(rlat0) - NL(rlat1)];
}*/
// int xz and yz, then:
// xz >>= 2;
// yz >>= 2;
// To get 17 bits
// aaaaaaa Q bbbb
adsb_frame[5] = ((altitude_coded & 0x7F0) >> 3) | 1;
adsb_frame[6] = ((altitude_coded & 0x00F) << 4) | (LAT >> 15); // Then 0, even/odd, and the 2 LAT-CPR MSBs
adsb_frame[11] = 0x00; // Clear CRC
adsb_frame[12] = 0x00;
adsb_frame[13] = 0x00;
// Compute CRC
memcpy(adsb_crc, adsb_frame, 14);
for (c = 0; c < 11; c++) {
for (b = 0; b < 8; b++) {
if ((adsb_crc[c] << b) & 0x80) {
for (s = 0; s < 25; s++) {
bitn = (c * 8) + b + s;
if ((crc_poly >> s) & 1) adsb_crc[bitn >> 3] ^= (0x80 >> (bitn & 7));
}
}
}
}
// Insert CRC in frame
for (c = 0; c < 3; c++)
adsb_frame[c + 11] = adsb_crc[c + 11];
// Convert to binary
for (c = 0; c < 112; c++)
adsb_bin[c] = (adsb_frame[c >> 3] >> (7 - (c & 7))) & 1;
// 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);
}
void ADSBTxView::generate_frame_id() {
uint8_t b, c, s, bitn;
char ch;
std::string str_debug;
std::string callsign_formatted(8, '_');
uint64_t callsign_coded = 0;
uint8_t adsb_crc[14]; // Temp buffer
// 1 00100000 01011111 11111111
uint32_t crc_poly = 0x1205FFF;
// Init frame
@ -91,7 +170,7 @@ void ADSBTxView::generate_frame() {
adsb_frame[c + 5] = (callsign_coded >> ((5 - c) * 8)) & 0xFF;
// Compute CRC
memcpy(adsb_crc, adsb_frames, 14);
memcpy(adsb_crc, adsb_frame, 14);
for (c = 0; c < 11; c++) {
for (b = 0; b < 8; b++) {
if ((adsb_crc[c] << b) & 0x80) {
@ -106,18 +185,28 @@ void ADSBTxView::generate_frame() {
for (c = 0; c < 3; c++)
adsb_frame[c + 11] = adsb_crc[c + 11];
// Display as text
text_message.set(to_string_hex((adsb_frame[11] << 16) + (adsb_frame[12] << 8) + adsb_frame[13], 6));
//text_message.set(callsign_formatted);
// Convert to binary
for (c = 0; c < 112; c++)
adsb_bin[c] = (adsb_frame[c >> 3] >> (7 - (c & 7))) & 1;
//ascii_to_ccir(ccir_message);
// 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);
text_message.set(callsign_formatted);
}
void ADSBTxView::start_tx() {
transmitter_model.set_tuning_frequency(450000000); // FOR TESTING - DEBUG
transmitter_model.set_tuning_frequency(452000000); // FOR TESTING - DEBUG
transmitter_model.set_baseband_configuration({
.mode = 0,
.sampling_rate = 1536000U, // CHANGE !
.sampling_rate = 2000000U, // Good ?
.decimation_factor = 1,
});
transmitter_model.set_rf_amp(true);
@ -126,23 +215,8 @@ void ADSBTxView::start_tx() {
transmitter_model.set_baseband_bandwidth(1750000);
transmitter_model.enable();
//memcpy(shared_memory.tx_data, adsb_frame, 112);
//baseband::set_adsb_data(1);
}
// ASCII to frequency LUT index
void ADSBTxView::ascii_to_ccir(char *ascii) {
uint8_t c;
for (c = 0; c < 20; c++) {
if (ascii[c] > '9')
ascii[c] -= 0x37;
else
ascii[c] -= 0x30;
}
// EOM code for baseband
ascii[20] = 0xFF;
memcpy(shared_memory.tx_data, adsb_bin, 112);
baseband::set_adsb();
}
void ADSBTxView::on_txdone(const int n) {
@ -163,7 +237,9 @@ void ADSBTxView::on_txdone(const int n) {
ADSBTxView::ADSBTxView(NavigationView& nav) {
(void)nav;
baseband::run_image(portapack::spi_flash::image_tag_xylos);
baseband::run_image(portapack::spi_flash::image_tag_adsb_tx);
// http://openflights.org
add_children({ {
&text_format,
@ -172,6 +248,8 @@ ADSBTxView::ADSBTxView(NavigationView& nav) {
&button_icao,
&text_callsign,
&button_callsign,
&text_frame_a,
&text_frame_b,
&progress,
&text_message,
&button_transmit
@ -184,7 +262,7 @@ ADSBTxView::ADSBTxView(NavigationView& nav) {
options_format.on_change = [this](size_t i, int32_t v) {
(void)i;
(void)v;
generate_frame();
generate_frame_id();
};
button_callsign.on_select = [this, &nav](Button&) {
textentry(nav, callsign, 9);
@ -192,15 +270,15 @@ ADSBTxView::ADSBTxView(NavigationView& nav) {
button_transmit.set_style(&style_val);
generate_frame();
generate_frame_id();
// Single transmit
button_transmit.on_select = [this,&nav](Button&) {
button_transmit.on_select = [this, &nav](Button&) {
if (tx_mode == IDLE) {
tx_mode = SINGLE;
button_transmit.set_style(&style_cancel);
button_transmit.set_text("Wait");
generate_frame();
generate_frame_id();
start_tx();
}
};

View file

@ -55,12 +55,13 @@ private:
char callsign[9] = "KLM1023 ";
uint8_t adsb_frame[14]; // 112 bit data block as 14 bytes
uint8_t adsb_bin[112]; // 112 bit data block
const char icao_id_lut[65] = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ##### ###############0123456789######";
void ascii_to_ccir(char *ascii);
void start_tx();
void generate_frame();
void generate_frame_id();
void generate_frame_pos();
void on_txdone(const int n);
const Style style_val {
@ -111,6 +112,15 @@ private:
"" // "KOR151 "
};
Text text_frame_a {
{ 4 * 8, 10 * 16, 14 * 8, 16 },
"-"
};
Text text_frame_b {
{ 4 * 8, 11 * 16, 14 * 8, 16 },
"-"
};
ProgressBar progress {
{ 5 * 8, 13 * 16, 20 * 8, 16 },
};

View file

@ -1,5 +1,6 @@
/*
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2016 Furrtek
*
* This file is part of PortaPack.
*
@ -22,17 +23,11 @@
#include "ui_jammer.hpp"
#include "ui_receiver.hpp"
#include "ch.h"
#include "evtimer.h"
//#include "ch.h"
//#include "evtimer.h"
#include "baseband_api.hpp"
#include "ff.h"
#include "hackrf_gpio.hpp"
#include "portapack.hpp"
#include "radio.hpp"
#include "string_format.hpp"
#include "event_m0.hpp"
#include "hackrf_hal.hpp"
#include "portapack_shared_memory.hpp"
#include "portapack_persistent_memory.hpp"
@ -48,7 +43,7 @@ void JammerView::focus() {
}
JammerView::~JammerView() {
radio::disable();
transmitter_model.disable();
baseband::shutdown();
}
@ -321,24 +316,26 @@ JammerView::JammerView(NavigationView& nav) {
jamming = true;
button_transmit.set_style(&style_cancel);
button_transmit.set_text("STOP");
radio::disable();
/*baseband::set_jammer_data(
);*/
//transmitter_model.set_tuning_frequency(433920000); // TODO
transmitter_model.set_baseband_configuration({
.mode = 0,
.sampling_rate = 1536000U,
.decimation_factor = 1,
});
transmitter_model.set_rf_amp(true);
transmitter_model.set_baseband_bandwidth(1750000);
transmitter_model.enable();
}
};
button_exit.on_select = [&nav](Button&){
nav.pop();
};
radio::enable({
shared_memory.jammer_ranges[0].center,
1536000, // ?
2500000, // ?
rf::Direction::Transmit,
true,
static_cast<int8_t>(receiver_model.lna()),
static_cast<int8_t>(receiver_model.vga()),
1,
});
}
} /* namespace ui */

View file

@ -1,5 +1,6 @@
/*
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2016 Furrtek
*
* This file is part of PortaPack.
*
@ -21,15 +22,10 @@
#include "ui.hpp"
#include "ui_widget.hpp"
#include "ui_painter.hpp"
#include "ui_menu.hpp"
#include "ui_navigation.hpp"
#include "ui_font_fixed_8x16.hpp"
#include "clock_manager.hpp"
#include "ui_navigation.hpp"
#include "message.hpp"
#include "rf_path.hpp"
#include "max2837.hpp"
#include "volume.hpp"
#include "transmitter_model.hpp"
namespace ui {
@ -66,7 +62,7 @@ private:
rf::Frequency max;
} rangepreset;
const rangepreset range_presets[9][3] = {
const rangepreset range_presets[10][3] = {
// Orange
{{ true, 935000000, 945000000 }, // GSM 900
{ true, 1808000000, 1832000000 }, // GSM 1800
@ -93,14 +89,14 @@ private:
{ false, 0, 0 }}, // UMTS
// TODO: TDD UMTS, voir doc Arcep
// TODO: Wi-FI, BT: 2 400 et 2 483,5 MHz
// TODO: Wifi, BT: 2 400 et 2 483,5 MHz
// DECT
{{ true, 1880000000, 1900000000 }, // BW: 20MHz
{ false, 0, 0 },
{ false, 0, 0 }},
// Optifib, lol
// PMV AFSK
{{ true, 162930000, 162970000 }, // BW: 40kHz
{ false, 0, 0 },
{ false, 0, 0 }},
@ -110,6 +106,11 @@ private:
{ false, 0, 0 },
{ false, 0, 0 }},
// Sigfox
{{ true, 868150000, 868250000 }, // BW: 40kHz (50kHz)
{ false, 0, 0 },
{ false, 0, 0 }},
// GPS L1 & L2
{{ true, 1575420000 - 50000, 1575420000 + 50000}, // BW: 100kHz
{ true, 1227600000 - 50000, 1227600000 + 50000 }, // BW: 100kHz
@ -177,7 +178,7 @@ private:
};
OptionsField options_preset {
{ 10 * 8, 3 * 16 },
9,
8,
{
{ "Orange ", 0 },
{ "SFR ", 1 },
@ -187,7 +188,8 @@ private:
{ "DECT ", 5 },
{ "Optifib ", 6 },
{ "ISM 433 ", 7 },
{ "GPS ", 8 },
{ "Sigfox ", 8 },
{ "GPS ", 9 }
}
};
@ -262,7 +264,7 @@ private:
const auto message = static_cast<const RetuneMessage*>(p);
this->on_retune(message->freq);
}
};
};
};
} /* namespace ui */