mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
Merge branch 'eried:next' into next
This commit is contained in:
commit
05a09bc988
3
.gitignore
vendored
3
.gitignore
vendored
@ -63,4 +63,5 @@ CMakeFiles/
|
||||
|
||||
# Host OS leftovers
|
||||
.DS_Store
|
||||
/firmware/CMakeCache.txt
|
||||
/firmware/CMakeCache.txt
|
||||
*.bak
|
||||
|
@ -1,6 +1,6 @@
|
||||
# PortaPack Mayhem
|
||||
|
||||
[![Build Status](https://travis-ci.com/eried/portapack-mayhem.svg?branch=master)](https://travis-ci.com/eried/portapack-mayhem) [![buddy pipeline](https://app.buddy.works/eried/portapack/pipelines/pipeline/252276/badge.svg?token=48cd59d53de0589a8fbe26bc751d77a59a011cf72581da049343879402991c34 "buddy pipeline")](https://app.buddy.works/eried/portapack/pipelines/pipeline/252276) [![CodeScene Code Health](https://codescene.io/projects/8381/status-badges/code-health)](https://codescene.io/projects/8381) [![GitHub All Releases](https://img.shields.io/github/downloads/eried/portapack-mayhem/total)](https://github.com/eried/portapack-mayhem/releases) [![GitHub Releases](https://img.shields.io/github/downloads/eried/portapack-mayhem/latest/total)](https://github.com/eried/portapack-mayhem/releases/latest) [![Docker Hub Pulls](https://img.shields.io/docker/pulls/eried/portapack.svg)](https://hub.docker.com/r/eried/portapack) [![Discord Chat](https://img.shields.io/discord/719669764804444213.svg)](https://discord.gg/tuwVMv3) [![Check bounties!](https://img.shields.io/bountysource/team/portapack-mayhem/activity?color=%2333ccff&label=bountysource%20%28USD%29&style=plastic)](https://www.bountysource.com/teams/portapack-mayhem/issues)
|
||||
[![Build Status](https://travis-ci.com/eried/portapack-mayhem.svg?branch=master)](https://travis-ci.com/eried/portapack-mayhem) [![CodeScene Code Health](https://codescene.io/projects/8381/status-badges/code-health)](https://codescene.io/projects/8381) [![GitHub All Releases](https://img.shields.io/github/downloads/eried/portapack-mayhem/total)](https://github.com/eried/portapack-mayhem/releases) [![GitHub Releases](https://img.shields.io/github/downloads/eried/portapack-mayhem/latest/total)](https://github.com/eried/portapack-mayhem/releases/latest) [![Docker Hub Pulls](https://img.shields.io/docker/pulls/eried/portapack.svg)](https://hub.docker.com/r/eried/portapack) [![Discord Chat](https://img.shields.io/discord/719669764804444213.svg)](https://discord.gg/tuwVMv3) [![Check bounties!](https://img.shields.io/bountysource/team/portapack-mayhem/activity?color=%2333ccff&label=bountysource%20%28USD%29&style=plastic)](https://www.bountysource.com/teams/portapack-mayhem/issues)
|
||||
|
||||
This is a fork of the [Havoc](https://github.com/furrtek/portapack-havoc/) firmware, which itself was a fork of the [PortaPack](https://github.com/sharebrained/portapack-hackrf) firmware, an add-on for the [HackRF](http://greatscottgadgets.com/hackrf/). A fork is a derivate, in this case one that has extra features and fixes when compared to the older versions.
|
||||
|
||||
@ -26,7 +26,7 @@ To support the people behind the hardware, please buy a genuine [HackRF](https:/
|
||||
|
||||
## Where is the latest firmware?
|
||||
|
||||
The current stable release is on the [![GitHub release (latest by date)](https://img.shields.io/github/v/release/eried/portapack-mayhem?label=Releases&style=social)](https://github.com/eried/portapack-mayhem/releases/latest) page. Follow the instructions you can find in the release description. There is also [nightly builds](https://github.com/eried/portapack-mayhem/releases/tag/nightly) generated periodically, which include the latest commits, but they may contain incomplete or buggy functionality.
|
||||
The current stable release is on the [![GitHub release (latest by date)](https://img.shields.io/github/v/release/eried/portapack-mayhem?label=Releases&style=social)](https://github.com/eried/portapack-mayhem/releases/latest) page. Follow the instructions you can find in the release description.
|
||||
|
||||
## Is this the newest firmware for my PortaPack?
|
||||
Most probably: **YES**. *If you find new features somewhere else, please [suggest](https://github.com/eried/portapack-mayhem/issues/new/choose) them*.
|
||||
|
@ -74,17 +74,58 @@ CaptureAppView::CaptureAppView(NavigationView& nav) {
|
||||
|
||||
option_bandwidth.on_change = [this](size_t, uint32_t base_rate) {
|
||||
sampling_rate = 8 * base_rate; // Decimation by 8 done on baseband side
|
||||
|
||||
/* base_rate is used for FFT calculation and display LCD, and also in recording writing SD Card rate. */
|
||||
/* ex. sampling_rate values, 4Mhz, when recording 500 khz (BW) and fs 8 Mhz , when selected 1 Mhz BW ...*/
|
||||
/* ex. recording 500khz BW to .C16 file, base_rate clock 500khz x2(I,Q) x 2 bytes (int signed) =2MB/sec rate SD Card */
|
||||
|
||||
waterfall.on_hide();
|
||||
record_view.set_sampling_rate(sampling_rate);
|
||||
receiver_model.set_sampling_rate(sampling_rate);
|
||||
/* Set up proper anti aliasing BPF bandwith in MAX2837 before ADC sampling according to the new added BW Options . */
|
||||
|
||||
switch(sampling_rate) { // we use the var fs (sampling_rate) , to set up BPF aprox < fs_max/2 by Nyquist theorem.
|
||||
|
||||
case 0 ... 2000000: // BW Captured range (0 <= 250Khz max ) fs = 8 x 250 Khz
|
||||
anti_alias_baseband_bandwidth_filter = 1750000; // Minimum BPF MAX2837 for all those lower BW options.
|
||||
break;
|
||||
|
||||
case 4000000 ... 6000000: // BW capture range (500k ... 750Khz max ) fs_max = 8 x 750Khz = 6Mhz
|
||||
// BW 500k ... 750khz , ex. 500khz (fs = 8*BW = 4Mhz) , BW 600Khz (fs = 4,8Mhz) , BW 750 Khz (fs = 6Mhz)
|
||||
anti_alias_baseband_bandwidth_filter = 2500000; // in some IC MAX2837 appear 2250000 , but both works similar.
|
||||
break;
|
||||
|
||||
case 8800000: // BW capture 1,1Mhz fs = 8 x 1,1Mhz = 8,8Mhz . (1Mhz showed slightly higher noise background).
|
||||
anti_alias_baseband_bandwidth_filter = 3500000;
|
||||
break;
|
||||
|
||||
case 14000000: // BW capture 1,75Mhz , fs = 8 x 1,75Mhz = 14Mhz
|
||||
// good BPF ,good matching, but LCD making flicker , refresh rate should be < 20 Hz , but reasonable picture
|
||||
anti_alias_baseband_bandwidth_filter = 5000000;
|
||||
break;
|
||||
|
||||
case 16000000: // BW capture 2Mhz , fs = 8 x 2Mhz = 16Mhz
|
||||
// good BPF ,good matching, but LCD making flicker , refresh rate should be < 20 Hz , but reasonable picture
|
||||
anti_alias_baseband_bandwidth_filter = 6000000;
|
||||
break;
|
||||
|
||||
case 20000000: // BW capture 2,5Mhz , fs= 8 x 2,5 Mhz = 20Mhz
|
||||
// good BPF ,good matching, but LCD making flicker , refresh rate should be < 20 Hz , but reasonable picture
|
||||
anti_alias_baseband_bandwidth_filter = 7000000;
|
||||
break;
|
||||
|
||||
default: // BW capture 2,75Mhz, fs = 8 x 2,75Mhz= 22Mhz max ADC sampling) and others.
|
||||
// We tested also 9Mhz FPB stightly too much noise floor , better 8Mhz
|
||||
anti_alias_baseband_bandwidth_filter = 8000000;
|
||||
}
|
||||
receiver_model.set_baseband_bandwidth(anti_alias_baseband_bandwidth_filter);
|
||||
|
||||
|
||||
waterfall.on_show();
|
||||
};
|
||||
|
||||
option_bandwidth.set_selected_index(7); // 500k
|
||||
option_bandwidth.set_selected_index(7); // 500k, Preselected starting default option 500khz
|
||||
|
||||
receiver_model.set_modulation(ReceiverModel::Mode::Capture);
|
||||
receiver_model.set_baseband_bandwidth(baseband_bandwidth);
|
||||
receiver_model.enable();
|
||||
|
||||
record_view.on_error = [&nav](std::string message) {
|
||||
|
@ -48,7 +48,7 @@ private:
|
||||
static constexpr ui::Dim header_height = 3 * 16;
|
||||
|
||||
uint32_t sampling_rate = 0;
|
||||
static constexpr uint32_t baseband_bandwidth = 2500000;
|
||||
uint32_t anti_alias_baseband_bandwidth_filter = 2500000; // we rename the previous var , and change type static constexpr to normal var.
|
||||
|
||||
void on_tuning_frequency_changed(rf::Frequency f);
|
||||
|
||||
@ -95,7 +95,14 @@ private:
|
||||
{ " 50k ", 50000 },
|
||||
{ "100k ", 100000 },
|
||||
{ "250k ", 250000 },
|
||||
{ "500k ", 500000 }
|
||||
{ "500k ", 500000 }, // Previous Limit bandwith Option with perfect micro SD write .C16 format operaton.
|
||||
{ "600k ", 600000 }, // That extended option is still possible to record with FW version Mayhem v1.41 (< 2,5MB/sec)
|
||||
{ "750k ", 750000 }, // From that BW onwards, the LCD is ok, but the recorded file is auto decimated,(not real file size)
|
||||
{ "1100k", 1100000 },
|
||||
{ "1750k", 1750000 },
|
||||
{ "2000k", 2000000 },
|
||||
{ "2500k", 2500000 },
|
||||
{ "2750k", 2750000 } // That is our max Capture option , to keep using later / 8 decimation (22Mhz sampling ADC)
|
||||
}
|
||||
};
|
||||
|
||||
|
444
firmware/application/apps/dump1090.hpp
Normal file
444
firmware/application/apps/dump1090.hpp
Normal file
@ -0,0 +1,444 @@
|
||||
// Part of dump1090, a Mode S message decoder for RTLSDR devices.
|
||||
//
|
||||
// dump1090.h: main program header
|
||||
//
|
||||
// Copyright (c) 2014-2016 Oliver Jowett <oliver@mutability.co.uk>
|
||||
//
|
||||
// This file is free software: you may copy, redistribute and/or modify it
|
||||
// under the terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation, either version 2 of the License, or (at your
|
||||
// option) any later version.
|
||||
//
|
||||
// This file 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. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// This file incorporates work covered by the following copyright and
|
||||
// permission notice:
|
||||
//
|
||||
// Copyright (C) 2012 by Salvatore Sanfilippo <antirez@gmail.com>
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifndef __DUMP1090_H
|
||||
#define __DUMP1090_H
|
||||
|
||||
// Default version number, if not overriden by the Makefile
|
||||
#ifndef MODES_DUMP1090_VERSION
|
||||
# define MODES_DUMP1090_VERSION "unknown"
|
||||
#endif
|
||||
|
||||
#ifndef MODES_DUMP1090_VARIANT
|
||||
# define MODES_DUMP1090_VARIANT "dump1090-unknown"
|
||||
#endif
|
||||
|
||||
|
||||
#define MODES_DEFAULT_FREQ 1090000000
|
||||
#define MODES_DEFAULT_WIDTH 1000
|
||||
#define MODES_DEFAULT_HEIGHT 700
|
||||
#define MODES_RTL_BUFFERS 15 // Number of RTL buffers
|
||||
#define MODES_RTL_BUF_SIZE (16*16384) // 256k
|
||||
#define MODES_MAG_BUF_SAMPLES (MODES_RTL_BUF_SIZE / 2) // Each sample is 2 bytes
|
||||
#define MODES_MAG_BUFFERS 12 // Number of magnitude buffers (should be smaller than RTL_BUFFERS for flowcontrol to work)
|
||||
#define MODES_AUTO_GAIN -100 // Use automatic gain
|
||||
#define MODES_MAX_GAIN 999999 // Use max available gain
|
||||
#define MODES_MSG_SQUELCH_DB 4.0 // Minimum SNR, in dB
|
||||
#define MODES_MSG_ENCODER_ERRS 3 // Maximum number of encoding errors
|
||||
|
||||
#define MODEAC_MSG_SAMPLES (25 * 2) // include up to the SPI bit
|
||||
#define MODEAC_MSG_BYTES 2
|
||||
#define MODEAC_MSG_SQUELCH_LEVEL 0x07FF // Average signal strength limit
|
||||
|
||||
#define MODES_PREAMBLE_US 8 // microseconds = bits
|
||||
#define MODES_PREAMBLE_SAMPLES (MODES_PREAMBLE_US * 2)
|
||||
#define MODES_PREAMBLE_SIZE (MODES_PREAMBLE_SAMPLES * sizeof(uint16_t))
|
||||
#define MODES_LONG_MSG_BYTES 14
|
||||
#define MODES_SHORT_MSG_BYTES 7
|
||||
#define MODES_LONG_MSG_BITS (MODES_LONG_MSG_BYTES * 8)
|
||||
#define MODES_SHORT_MSG_BITS (MODES_SHORT_MSG_BYTES * 8)
|
||||
#define MODES_LONG_MSG_SAMPLES (MODES_LONG_MSG_BITS * 2)
|
||||
#define MODES_SHORT_MSG_SAMPLES (MODES_SHORT_MSG_BITS * 2)
|
||||
#define MODES_LONG_MSG_SIZE (MODES_LONG_MSG_SAMPLES * sizeof(uint16_t))
|
||||
#define MODES_SHORT_MSG_SIZE (MODES_SHORT_MSG_SAMPLES * sizeof(uint16_t))
|
||||
|
||||
#define MODES_OS_PREAMBLE_SAMPLES (20)
|
||||
#define MODES_OS_PREAMBLE_SIZE (MODES_OS_PREAMBLE_SAMPLES * sizeof(uint16_t))
|
||||
#define MODES_OS_LONG_MSG_SAMPLES (268)
|
||||
#define MODES_OS_SHORT_MSG_SAMPLES (135)
|
||||
#define MODES_OS_LONG_MSG_SIZE (MODES_LONG_MSG_SAMPLES * sizeof(uint16_t))
|
||||
#define MODES_OS_SHORT_MSG_SIZE (MODES_SHORT_MSG_SAMPLES * sizeof(uint16_t))
|
||||
|
||||
#define MODES_OUT_BUF_SIZE (1500)
|
||||
#define MODES_OUT_FLUSH_SIZE (MODES_OUT_BUF_SIZE - 256)
|
||||
#define MODES_OUT_FLUSH_INTERVAL (60000)
|
||||
|
||||
#define MODES_USER_LATLON_VALID (1<<0)
|
||||
|
||||
#define INVALID_ALTITUDE (-9999)
|
||||
|
||||
/* Where did a bit of data arrive from? In order of increasing priority */
|
||||
typedef enum {
|
||||
SOURCE_INVALID, /* data is not valid */
|
||||
SOURCE_MODE_AC, /* A/C message */
|
||||
SOURCE_MLAT, /* derived from mlat */
|
||||
SOURCE_MODE_S, /* data from a Mode S message, no full CRC */
|
||||
SOURCE_MODE_S_CHECKED, /* data from a Mode S message with full CRC */
|
||||
SOURCE_TISB, /* data from a TIS-B extended squitter message */
|
||||
SOURCE_ADSR, /* data from a ADS-R extended squitter message */
|
||||
SOURCE_ADSB, /* data from a ADS-B extended squitter message */
|
||||
} datasource_t;
|
||||
|
||||
/* What sort of address is this and who sent it?
|
||||
* (Earlier values are higher priority)
|
||||
*/
|
||||
typedef enum {
|
||||
ADDR_ADSB_ICAO, /* Mode S or ADS-B, ICAO address, transponder sourced */
|
||||
ADDR_ADSB_ICAO_NT, /* ADS-B, ICAO address, non-transponder */
|
||||
ADDR_ADSR_ICAO, /* ADS-R, ICAO address */
|
||||
ADDR_TISB_ICAO, /* TIS-B, ICAO address */
|
||||
|
||||
ADDR_ADSB_OTHER, /* ADS-B, other address format */
|
||||
ADDR_ADSR_OTHER, /* ADS-R, other address format */
|
||||
ADDR_TISB_TRACKFILE, /* TIS-B, Mode A code + track file number */
|
||||
ADDR_TISB_OTHER, /* TIS-B, other address format */
|
||||
|
||||
ADDR_MODE_A, /* Mode A */
|
||||
|
||||
ADDR_UNKNOWN /* unknown address format */
|
||||
} addrtype_t;
|
||||
|
||||
typedef enum {
|
||||
UNIT_FEET,
|
||||
UNIT_METERS
|
||||
} altitude_unit_t;
|
||||
|
||||
typedef enum {
|
||||
UNIT_NAUTICAL_MILES,
|
||||
UNIT_STATUTE_MILES,
|
||||
UNIT_KILOMETERS,
|
||||
} interactive_distance_unit_t;
|
||||
|
||||
typedef enum {
|
||||
ALTITUDE_BARO,
|
||||
ALTITUDE_GEOM
|
||||
} altitude_source_t;
|
||||
|
||||
typedef enum {
|
||||
AG_INVALID,
|
||||
AG_GROUND,
|
||||
AG_AIRBORNE,
|
||||
AG_UNCERTAIN
|
||||
} airground_t;
|
||||
|
||||
typedef enum {
|
||||
SIL_INVALID, SIL_UNKNOWN, SIL_PER_SAMPLE, SIL_PER_HOUR
|
||||
} sil_type_t;
|
||||
|
||||
typedef enum {
|
||||
CPR_SURFACE, CPR_AIRBORNE, CPR_COARSE
|
||||
} cpr_type_t;
|
||||
|
||||
typedef enum {
|
||||
HEADING_INVALID, // Not set
|
||||
HEADING_GROUND_TRACK, // Direction of track over ground, degrees clockwise from true north
|
||||
HEADING_TRUE, // Heading, degrees clockwise from true north
|
||||
HEADING_MAGNETIC, // Heading, degrees clockwise from magnetic north
|
||||
HEADING_MAGNETIC_OR_TRUE, // HEADING_MAGNETIC or HEADING_TRUE depending on the HRD bit in opstatus
|
||||
HEADING_TRACK_OR_HEADING // GROUND_TRACK / MAGNETIC / TRUE depending on the TAH bit in opstatus
|
||||
} heading_type_t;
|
||||
|
||||
typedef enum {
|
||||
COMMB_UNKNOWN,
|
||||
COMMB_AMBIGUOUS,
|
||||
COMMB_EMPTY_RESPONSE,
|
||||
COMMB_DATALINK_CAPS,
|
||||
COMMB_GICB_CAPS,
|
||||
COMMB_AIRCRAFT_IDENT,
|
||||
COMMB_ACAS_RA,
|
||||
COMMB_VERTICAL_INTENT,
|
||||
COMMB_TRACK_TURN,
|
||||
COMMB_HEADING_SPEED
|
||||
} commb_format_t;
|
||||
|
||||
typedef enum {
|
||||
NAV_MODE_AUTOPILOT = 1,
|
||||
NAV_MODE_VNAV = 2,
|
||||
NAV_MODE_ALT_HOLD = 4,
|
||||
NAV_MODE_APPROACH = 8,
|
||||
NAV_MODE_LNAV = 16,
|
||||
NAV_MODE_TCAS = 32
|
||||
} nav_modes_t;
|
||||
|
||||
// Matches encoding of the ES type 28/1 emergency/priority status subfield
|
||||
typedef enum {
|
||||
EMERGENCY_NONE = 0,
|
||||
EMERGENCY_GENERAL = 1,
|
||||
EMERGENCY_LIFEGUARD = 2,
|
||||
EMERGENCY_MINFUEL = 3,
|
||||
EMERGENCY_NORDO = 4,
|
||||
EMERGENCY_UNLAWFUL = 5,
|
||||
EMERGENCY_DOWNED = 6,
|
||||
EMERGENCY_RESERVED = 7
|
||||
} emergency_t;
|
||||
|
||||
typedef enum {
|
||||
NAV_ALT_INVALID, NAV_ALT_UNKNOWN, NAV_ALT_AIRCRAFT, NAV_ALT_MCP, NAV_ALT_FMS
|
||||
} nav_altitude_source_t;
|
||||
|
||||
#define MODES_NON_ICAO_ADDRESS (1<<24) // Set on addresses to indicate they are not ICAO addresses
|
||||
|
||||
#define MODES_INTERACTIVE_REFRESH_TIME 250 // Milliseconds
|
||||
#define MODES_INTERACTIVE_DISPLAY_TTL 60000 // Delete from display after 60 seconds
|
||||
|
||||
#define MODES_NET_HEARTBEAT_INTERVAL 60000 // milliseconds
|
||||
|
||||
#define MODES_CLIENT_BUF_SIZE 1024
|
||||
#define MODES_NET_SNDBUF_SIZE (1024*64)
|
||||
#define MODES_NET_SNDBUF_MAX (7)
|
||||
|
||||
#define HISTORY_SIZE 120
|
||||
#define HISTORY_INTERVAL 30000
|
||||
|
||||
#define MODES_NOTUSED(V) ((void) V)
|
||||
|
||||
#define MAX_AMPLITUDE 65535.0
|
||||
#define MAX_POWER (MAX_AMPLITUDE * MAX_AMPLITUDE)
|
||||
|
||||
#define FAUP_DEFAULT_RATE_MULTIPLIER 1.0 // FA Upload rate multiplier
|
||||
|
||||
|
||||
//======================== structure declarations =========================
|
||||
|
||||
typedef enum {
|
||||
SDR_NONE, SDR_IFILE, SDR_RTLSDR, SDR_BLADERF, SDR_HACKRF, SDR_LIMESDR
|
||||
} sdr_type_t;
|
||||
|
||||
|
||||
// The struct we use to store information about a decoded message.
|
||||
struct modesMessage {
|
||||
// Generic fields
|
||||
unsigned char msg[MODES_LONG_MSG_BYTES]; // Binary message.
|
||||
unsigned char verbatim[MODES_LONG_MSG_BYTES]; // Binary message, as originally received before correction
|
||||
int msgbits; // Number of bits in message
|
||||
int msgtype; // Downlink format #
|
||||
uint32_t crc; // Message CRC
|
||||
int correctedbits; // No. of bits corrected
|
||||
uint32_t addr; // Address Announced
|
||||
addrtype_t addrtype; // address format / source
|
||||
uint64_t timestampMsg; // Timestamp of the message (12MHz clock)
|
||||
uint64_t sysTimestampMsg; // Timestamp of the message (system time)
|
||||
int remote; // If set this message is from a remote station
|
||||
double signalLevel; // RSSI, in the range [0..1], as a fraction of full-scale power
|
||||
int score; // Scoring from scoreModesMessage, if used
|
||||
int reliable; // is this a "reliable" message (uncorrected DF11/DF17/DF18)?
|
||||
|
||||
datasource_t source; // Characterizes the overall message source
|
||||
|
||||
// Raw data, just extracted directly from the message
|
||||
// The names reflect the field names in Annex 4
|
||||
unsigned IID; // extracted from CRC of DF11s
|
||||
unsigned AA;
|
||||
unsigned AC;
|
||||
unsigned CA;
|
||||
unsigned CC;
|
||||
unsigned CF;
|
||||
unsigned DR;
|
||||
unsigned FS;
|
||||
unsigned ID;
|
||||
unsigned KE;
|
||||
unsigned ND;
|
||||
unsigned RI;
|
||||
unsigned SL;
|
||||
unsigned UM;
|
||||
unsigned VS;
|
||||
unsigned char MB[7];
|
||||
unsigned char MD[10];
|
||||
unsigned char ME[7];
|
||||
unsigned char MV[7];
|
||||
|
||||
// Decoded data
|
||||
unsigned altitude_baro_valid : 1;
|
||||
unsigned altitude_geom_valid : 1;
|
||||
unsigned track_valid : 1;
|
||||
unsigned track_rate_valid : 1;
|
||||
unsigned heading_valid : 1;
|
||||
unsigned roll_valid : 1;
|
||||
unsigned gs_valid : 1;
|
||||
unsigned ias_valid : 1;
|
||||
unsigned tas_valid : 1;
|
||||
unsigned mach_valid : 1;
|
||||
unsigned baro_rate_valid : 1;
|
||||
unsigned geom_rate_valid : 1;
|
||||
unsigned squawk_valid : 1;
|
||||
unsigned callsign_valid : 1;
|
||||
unsigned cpr_valid : 1;
|
||||
unsigned cpr_odd : 1;
|
||||
unsigned cpr_decoded : 1;
|
||||
unsigned cpr_relative : 1;
|
||||
unsigned category_valid : 1;
|
||||
unsigned geom_delta_valid : 1;
|
||||
unsigned from_mlat : 1;
|
||||
unsigned from_tisb : 1;
|
||||
unsigned spi_valid : 1;
|
||||
unsigned spi : 1;
|
||||
unsigned alert_valid : 1;
|
||||
unsigned alert : 1;
|
||||
unsigned emergency_valid : 1;
|
||||
|
||||
unsigned metype; // DF17/18 ME type
|
||||
unsigned mesub; // DF17/18 ME subtype
|
||||
|
||||
commb_format_t commb_format; // Inferred format of a comm-b message
|
||||
|
||||
// valid if altitude_baro_valid:
|
||||
int altitude_baro; // Altitude in either feet or meters
|
||||
altitude_unit_t altitude_baro_unit; // the unit used for altitude
|
||||
|
||||
// valid if altitude_geom_valid:
|
||||
int altitude_geom; // Altitude in either feet or meters
|
||||
altitude_unit_t altitude_geom_unit; // the unit used for altitude
|
||||
|
||||
// following fields are valid if the corresponding _valid field is set:
|
||||
int geom_delta; // Difference between geometric and baro alt
|
||||
float heading; // ground track or heading, degrees (0-359). Reported directly or computed from from EW and NS velocity
|
||||
heading_type_t heading_type;// how to interpret 'track_or_heading'
|
||||
float track_rate; // Rate of change of track, degrees/second
|
||||
float roll; // Roll, degrees, negative is left roll
|
||||
struct {
|
||||
// Groundspeed, kts, reported directly or computed from from EW and NS velocity
|
||||
// For surface movement, this has different interpretations for v0 and v2; both
|
||||
// fields are populated. The tracking layer will update "gs.selected".
|
||||
float v0;
|
||||
float v2;
|
||||
float selected;
|
||||
} gs;
|
||||
unsigned ias; // Indicated airspeed, kts
|
||||
unsigned tas; // True airspeed, kts
|
||||
double mach; // Mach number
|
||||
int baro_rate; // Rate of change of barometric altitude, feet/minute
|
||||
int geom_rate; // Rate of change of geometric (GNSS / INS) altitude, feet/minute
|
||||
unsigned squawk; // 13 bits identity (Squawk), encoded as 4 hex digits
|
||||
char callsign[9]; // 8 chars flight number, NUL-terminated
|
||||
unsigned category; // A0 - D7 encoded as a single hex byte
|
||||
emergency_t emergency; // emergency/priority status
|
||||
|
||||
// valid if cpr_valid
|
||||
cpr_type_t cpr_type; // The encoding type used (surface, airborne, coarse TIS-B)
|
||||
unsigned cpr_lat; // Non decoded latitude.
|
||||
unsigned cpr_lon; // Non decoded longitude.
|
||||
unsigned cpr_nucp; // NUCp/NIC value implied by message type
|
||||
|
||||
airground_t airground; // air/ground state
|
||||
|
||||
// valid if cpr_decoded:
|
||||
double decoded_lat;
|
||||
double decoded_lon;
|
||||
unsigned decoded_nic;
|
||||
unsigned decoded_rc;
|
||||
|
||||
// various integrity/accuracy things
|
||||
struct {
|
||||
unsigned nic_a_valid : 1;
|
||||
unsigned nic_b_valid : 1;
|
||||
unsigned nic_c_valid : 1;
|
||||
unsigned nic_baro_valid : 1;
|
||||
unsigned nac_p_valid : 1;
|
||||
unsigned nac_v_valid : 1;
|
||||
unsigned gva_valid : 1;
|
||||
unsigned sda_valid : 1;
|
||||
|
||||
unsigned nic_a : 1; // if nic_a_valid
|
||||
unsigned nic_b : 1; // if nic_b_valid
|
||||
unsigned nic_c : 1; // if nic_c_valid
|
||||
unsigned nic_baro : 1; // if nic_baro_valid
|
||||
|
||||
unsigned nac_p : 4; // if nac_p_valid
|
||||
unsigned nac_v : 3; // if nac_v_valid
|
||||
|
||||
unsigned sil : 2; // if sil_type != SIL_INVALID
|
||||
sil_type_t sil_type;
|
||||
|
||||
unsigned gva : 2; // if gva_valid
|
||||
|
||||
unsigned sda : 2; // if sda_valid
|
||||
} accuracy;
|
||||
|
||||
// Operational Status
|
||||
struct {
|
||||
unsigned valid : 1;
|
||||
unsigned version : 3;
|
||||
|
||||
unsigned om_acas_ra : 1;
|
||||
unsigned om_ident : 1;
|
||||
unsigned om_atc : 1;
|
||||
unsigned om_saf : 1;
|
||||
|
||||
unsigned cc_acas : 1;
|
||||
unsigned cc_cdti : 1;
|
||||
unsigned cc_1090_in : 1;
|
||||
unsigned cc_arv : 1;
|
||||
unsigned cc_ts : 1;
|
||||
unsigned cc_tc : 2;
|
||||
unsigned cc_uat_in : 1;
|
||||
unsigned cc_poa : 1;
|
||||
unsigned cc_b2_low : 1;
|
||||
unsigned cc_lw_valid : 1;
|
||||
|
||||
heading_type_t tah;
|
||||
heading_type_t hrd;
|
||||
|
||||
unsigned cc_lw;
|
||||
unsigned cc_antenna_offset;
|
||||
} opstatus;
|
||||
|
||||
// combined:
|
||||
// Target State & Status (ADS-B V2 only)
|
||||
// Comm-B BDS4,0 Vertical Intent
|
||||
struct {
|
||||
unsigned heading_valid : 1;
|
||||
unsigned fms_altitude_valid : 1;
|
||||
unsigned mcp_altitude_valid : 1;
|
||||
unsigned qnh_valid : 1;
|
||||
unsigned modes_valid : 1;
|
||||
|
||||
float heading; // heading, degrees (0-359) (could be magnetic or true heading; magnetic recommended)
|
||||
heading_type_t heading_type;
|
||||
unsigned fms_altitude; // FMS selected altitude
|
||||
unsigned mcp_altitude; // MCP/FCU selected altitude
|
||||
float qnh; // altimeter setting (QFE or QNH/QNE), millibars
|
||||
|
||||
nav_altitude_source_t altitude_source;
|
||||
|
||||
nav_modes_t modes;
|
||||
} nav;
|
||||
};
|
||||
|
||||
|
||||
#endif // __DUMP1090_H
|
@ -30,10 +30,11 @@ using namespace pocsag;
|
||||
|
||||
#include "string_format.hpp"
|
||||
#include "utility.hpp"
|
||||
#include "audio.hpp"
|
||||
|
||||
void POCSAGLogger::log_raw_data(const pocsag::POCSAGPacket& packet, const uint32_t frequency) {
|
||||
std::string entry = "Raw: F:" + to_string_dec_uint(frequency) + "Hz " +
|
||||
pocsag::bitrate_str(packet.bitrate()) + " Codewords:";
|
||||
to_string_dec_uint(packet.bitrate()) + " Codewords:";
|
||||
|
||||
// Raw hex dump of all the codewords
|
||||
for (size_t c = 0; c < 16; c++)
|
||||
@ -64,13 +65,13 @@ POCSAGAppView::POCSAGAppView(NavigationView& nav) {
|
||||
add_children({
|
||||
&rssi,
|
||||
&channel,
|
||||
&audio,
|
||||
&field_rf_amp,
|
||||
&field_lna,
|
||||
&field_vga,
|
||||
&field_frequency,
|
||||
&options_bitrate,
|
||||
&options_phase,
|
||||
&check_log,
|
||||
&field_volume,
|
||||
&check_ignore,
|
||||
&sym_ignore,
|
||||
&console
|
||||
@ -99,14 +100,11 @@ POCSAGAppView::POCSAGAppView(NavigationView& nav) {
|
||||
logging = v;
|
||||
};
|
||||
|
||||
options_bitrate.on_change = [this](size_t, OptionsField::value_t v) {
|
||||
on_config_changed(v, options_phase.selected_index_value());
|
||||
};
|
||||
options_bitrate.set_selected_index(1); // 1200bps
|
||||
|
||||
options_phase.on_change = [this](size_t, OptionsField::value_t v) {
|
||||
on_config_changed(options_bitrate.selected_index_value(),v);
|
||||
field_volume.set_value((receiver_model.headphone_volume() - audio::headphone::volume_range().max).decibel() + 99);
|
||||
field_volume.on_change = [this](int32_t v) {
|
||||
this->on_headphone_volume_changed(v);
|
||||
};
|
||||
|
||||
check_ignore.set_value(ignore);
|
||||
check_ignore.on_select = [this](Checkbox&, bool v) {
|
||||
ignore = v;
|
||||
@ -121,9 +119,16 @@ POCSAGAppView::POCSAGAppView(NavigationView& nav) {
|
||||
logger = std::make_unique<POCSAGLogger>();
|
||||
if (logger)
|
||||
logger->append("pocsag.txt");
|
||||
|
||||
audio::output::start();
|
||||
audio::output::unmute();
|
||||
|
||||
baseband::set_pocsag();
|
||||
}
|
||||
|
||||
POCSAGAppView::~POCSAGAppView() {
|
||||
audio::output::stop();
|
||||
|
||||
// Save ignored address
|
||||
persistent_memory::set_pocsag_ignore_address(sym_ignore.value_dec_u32());
|
||||
|
||||
@ -135,6 +140,12 @@ void POCSAGAppView::focus() {
|
||||
field_frequency.focus();
|
||||
}
|
||||
|
||||
void POCSAGAppView::on_headphone_volume_changed(int32_t v) {
|
||||
const auto new_volume = volume_t::decibel(v - 99) + audio::headphone::volume_range().max;
|
||||
receiver_model.set_headphone_volume(new_volume);
|
||||
}
|
||||
|
||||
|
||||
// Useless ?
|
||||
void POCSAGAppView::set_parent_rect(const Rect new_parent_rect) {
|
||||
View::set_parent_rect(new_parent_rect);
|
||||
@ -154,11 +165,17 @@ void POCSAGAppView::on_packet(const POCSAGPacketMessage * message) {
|
||||
// " Ignored address " + to_string_dec_uint(pocsag_state.address));
|
||||
return;
|
||||
}
|
||||
// Too many errors for reliable decode
|
||||
if ((ignore) && (pocsag_state.errors >= 3)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
std::string console_info;
|
||||
|
||||
const uint32_t roundVal = 50;
|
||||
const uint32_t bitrate = roundVal * ((message->packet.bitrate() + (roundVal/2))/roundVal);
|
||||
console_info = "\n" + to_string_datetime(message->packet.timestamp(), HM);
|
||||
console_info += " " + pocsag::bitrate_str(message->packet.bitrate());
|
||||
console_info += " " + to_string_dec_uint(bitrate);
|
||||
console_info += " ADDR:" + to_string_dec_uint(pocsag_state.address);
|
||||
console_info += " F" + to_string_dec_uint(pocsag_state.function);
|
||||
|
||||
@ -201,10 +218,6 @@ void POCSAGAppView::on_packet(const POCSAGPacketMessage * message) {
|
||||
logger->log_raw_data(message->packet, target_frequency());
|
||||
}
|
||||
|
||||
void POCSAGAppView::on_config_changed(const uint32_t new_bitrate, bool new_phase) {
|
||||
baseband::set_pocsag(pocsag_bitrates[new_bitrate], new_phase);
|
||||
}
|
||||
|
||||
void POCSAGAppView::set_target_frequency(const uint32_t new_value) {
|
||||
target_frequency_ = new_value;
|
||||
receiver_model.set_tuning_frequency(new_value);
|
||||
|
@ -61,7 +61,7 @@ private:
|
||||
static constexpr uint32_t initial_target_frequency = 466175000;
|
||||
|
||||
bool logging { true };
|
||||
bool ignore { false };
|
||||
bool ignore { true };
|
||||
uint32_t last_address = 0xFFFFFFFF;
|
||||
pocsag::POCSAGState pocsag_state { };
|
||||
|
||||
@ -80,49 +80,41 @@ private:
|
||||
Channel channel {
|
||||
{ 21 * 8, 5, 6 * 8, 4 },
|
||||
};
|
||||
Audio audio{
|
||||
{ 21 * 8, 10, 6 * 8, 4 },
|
||||
};
|
||||
|
||||
FrequencyField field_frequency {
|
||||
{ 0 * 8, 0 * 8 },
|
||||
};
|
||||
OptionsField options_bitrate {
|
||||
{ 12 * 8, 21 },
|
||||
7,
|
||||
{
|
||||
{ "512bps ", 0 },
|
||||
{ "1200bps", 1 },
|
||||
{ "2400bps", 2 },
|
||||
{ "3200bps", 3 }
|
||||
}
|
||||
};
|
||||
OptionsField options_phase {
|
||||
{ 6 * 8, 21 },
|
||||
1,
|
||||
{
|
||||
{ "P", 0 },
|
||||
{ "N", 1 },
|
||||
}
|
||||
};
|
||||
Checkbox check_log {
|
||||
{ 22 * 8, 21 },
|
||||
{ 24 * 8, 21 },
|
||||
3,
|
||||
"LOG",
|
||||
true
|
||||
};
|
||||
NumberField field_volume{
|
||||
{ 28 * 8, 0 * 16 },
|
||||
2,
|
||||
{ 0, 99 },
|
||||
1,
|
||||
' ',
|
||||
};
|
||||
|
||||
Checkbox check_ignore {
|
||||
{ 1 * 8, 40 },
|
||||
15,
|
||||
"Ignore address:",
|
||||
{ 1 * 8, 21 },
|
||||
12,
|
||||
"Ignore addr:",
|
||||
true
|
||||
};
|
||||
SymField sym_ignore {
|
||||
{ 19 * 8, 40 },
|
||||
{ 16 * 8, 21 },
|
||||
7,
|
||||
SymField::SYMFIELD_DEC
|
||||
};
|
||||
|
||||
Console console {
|
||||
{ 0, 4 * 16, 240, 240 }
|
||||
{ 0, 3 * 16, 240, 256 }
|
||||
};
|
||||
|
||||
std::unique_ptr<POCSAGLogger> logger { };
|
||||
@ -133,7 +125,7 @@ private:
|
||||
|
||||
void on_packet(const POCSAGPacketMessage * message);
|
||||
|
||||
void on_config_changed(const uint32_t new_bitrate, const bool phase);
|
||||
void on_headphone_volume_changed(int32_t v);
|
||||
|
||||
uint32_t target_frequency() const;
|
||||
void set_target_frequency(const uint32_t new_value);
|
||||
|
@ -34,6 +34,7 @@ namespace ui
|
||||
console.writeln("zhang00963,RedFox-Fr,aldude999");
|
||||
console.writeln("East2West,fossum,ArjanOnwezen");
|
||||
console.writeln("vXxOinvizioNxX,teixeluis");
|
||||
console.writeln("heurist1,intoxsick");
|
||||
console.writeln("");
|
||||
break;
|
||||
|
||||
|
@ -49,7 +49,7 @@ void RecentEntriesTable<AircraftRecentEntries>::draw(
|
||||
if (entry_age < ADSB_DECAY_A) {
|
||||
aged_color = 0x10;
|
||||
target_color = Color::green();
|
||||
} else if ((entry_age >= ADSB_DECAY_A) && (entry_age < ADSB_DECAY_B)) {
|
||||
} else if (entry_age < ADSB_DECAY_B) {
|
||||
aged_color = 0x07;
|
||||
target_color = Color::light_grey();
|
||||
} else {
|
||||
@ -59,10 +59,21 @@ void RecentEntriesTable<AircraftRecentEntries>::draw(
|
||||
|
||||
std::string entry_string = "\x1B";
|
||||
entry_string += aged_color;
|
||||
#if false
|
||||
entry_string += to_string_hex(entry.ICAO_address, 6) + " " +
|
||||
entry.callsign + " " +
|
||||
(entry.hits <= 999 ? to_string_dec_uint(entry.hits, 4) : "999+") + " " +
|
||||
entry.time_string;
|
||||
#else
|
||||
// SBT
|
||||
entry_string +=
|
||||
(entry.callsign[0]!=' ' ? entry.callsign + " " : to_string_hex(entry.ICAO_address, 6) + " ") +
|
||||
to_string_dec_uint((unsigned int)((entry.pos.altitude+50)/100),4) +
|
||||
to_string_dec_uint((unsigned int)entry.velo.speed,4) +
|
||||
to_string_dec_uint((unsigned int)(entry.amp>>9),4) + " " +
|
||||
(entry.hits <= 999 ? to_string_dec_uint(entry.hits, 3) + " " : "1k+ ") +
|
||||
to_string_dec_uint(entry.age, 3);
|
||||
#endif
|
||||
|
||||
painter.draw_string(
|
||||
target_rect.location(),
|
||||
@ -71,7 +82,7 @@ void RecentEntriesTable<AircraftRecentEntries>::draw(
|
||||
);
|
||||
|
||||
if (entry.pos.valid)
|
||||
painter.draw_bitmap(target_rect.location() + Point(15 * 8, 0), bitmap_target, target_color, style.background);
|
||||
painter.draw_bitmap(target_rect.location() + Point(8 * 8, 0), bitmap_target, target_color, style.background);
|
||||
}
|
||||
|
||||
void ADSBLogger::log_str(std::string& logline) {
|
||||
@ -119,6 +130,7 @@ ADSBRxDetailsView::ADSBRxDetailsView(
|
||||
{
|
||||
char file_buffer[32] { 0 };
|
||||
bool found = false;
|
||||
int number_of_airlines = 0;
|
||||
std::string airline_code;
|
||||
size_t c;
|
||||
|
||||
@ -142,7 +154,8 @@ ADSBRxDetailsView::ADSBRxDetailsView(
|
||||
// Try getting the airline's name from airlines.db
|
||||
auto result = db_file.open("ADSB/airlines.db");
|
||||
if (!result.is_valid()) {
|
||||
// Search for 3-letter code in 0x0000~0x2000
|
||||
// Search for 3-letter code
|
||||
number_of_airlines = (db_file.size() / 68); // determine number of airlines in file
|
||||
airline_code = entry_copy.callsign.substr(0, 3);
|
||||
c = 0;
|
||||
do {
|
||||
@ -153,10 +166,10 @@ ADSBRxDetailsView::ADSBRxDetailsView(
|
||||
found = true;
|
||||
else
|
||||
c++;
|
||||
} while (!found);
|
||||
} while (!found && (c < number_of_airlines));
|
||||
|
||||
if (found) {
|
||||
db_file.seek(0x2000 + (c << 6));
|
||||
db_file.seek((number_of_airlines * 4) + (c << 6)); // seek starting after index
|
||||
db_file.read(file_buffer, 32);
|
||||
text_airline.set(file_buffer);
|
||||
db_file.read(file_buffer, 32);
|
||||
@ -173,17 +186,19 @@ ADSBRxDetailsView::ADSBRxDetailsView(
|
||||
text_callsign.set(entry_copy.callsign);
|
||||
|
||||
button_see_map.on_select = [this, &nav](Button&) {
|
||||
geomap_view = nav.push<GeoMapView>(
|
||||
entry_copy.callsign,
|
||||
entry_copy.pos.altitude,
|
||||
GeoPos::alt_unit::FEET,
|
||||
entry_copy.pos.latitude,
|
||||
entry_copy.pos.longitude,
|
||||
entry_copy.velo.heading,
|
||||
[this]() {
|
||||
if (!send_updates) { // Prevent recursivley launching the map
|
||||
geomap_view = nav.push<GeoMapView>(
|
||||
entry_copy.callsign,
|
||||
entry_copy.pos.altitude,
|
||||
GeoPos::alt_unit::FEET,
|
||||
entry_copy.pos.latitude,
|
||||
entry_copy.pos.longitude,
|
||||
entry_copy.velo.heading,
|
||||
[this]() {
|
||||
send_updates = false;
|
||||
});
|
||||
send_updates = true;
|
||||
send_updates = true;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@ -192,11 +207,41 @@ void ADSBRxView::focus() {
|
||||
}
|
||||
|
||||
ADSBRxView::~ADSBRxView() {
|
||||
receiver_model.set_tuning_frequency(prevFreq);
|
||||
|
||||
rtc_time::signal_tick_second -= signal_token_tick_second;
|
||||
receiver_model.disable();
|
||||
baseband::shutdown();
|
||||
}
|
||||
|
||||
AircraftRecentEntry ADSBRxView::find_or_create_entry(uint32_t ICAO_address) {
|
||||
auto it = find(recent, ICAO_address);
|
||||
|
||||
// If not found
|
||||
if (it == std::end(recent)){
|
||||
recent.emplace_front(ICAO_address); // Add it
|
||||
truncate_entries(recent); // Truncate the list
|
||||
sort_entries_by_state();
|
||||
it = find(recent, ICAO_address); // Find it again
|
||||
}
|
||||
return *it;
|
||||
}
|
||||
|
||||
void ADSBRxView::replace_entry(AircraftRecentEntry & entry)
|
||||
{
|
||||
uint32_t ICAO_address = entry.ICAO_address;
|
||||
|
||||
std::replace_if( recent.begin(), recent.end(),
|
||||
[ICAO_address](const AircraftRecentEntry & compEntry) {return ICAO_address == compEntry.ICAO_address;},
|
||||
entry);
|
||||
}
|
||||
|
||||
void ADSBRxView::sort_entries_by_state()
|
||||
{
|
||||
// Sorting List pn age_state using lambda function as comparator
|
||||
recent.sort([](const AircraftRecentEntry & left, const AircraftRecentEntry & right){return (left.age_state < right.age_state); });
|
||||
}
|
||||
|
||||
void ADSBRxView::on_frame(const ADSBFrameMessage * message) {
|
||||
rtc::RTC datetime;
|
||||
std::string str_timestamp;
|
||||
@ -209,9 +254,15 @@ void ADSBRxView::on_frame(const ADSBFrameMessage * message) {
|
||||
|
||||
if (frame.check_CRC() && ICAO_address) {
|
||||
rtcGetTime(&RTCD1, &datetime);
|
||||
auto& entry = ::on_packet(recent, ICAO_address);
|
||||
auto entry = find_or_create_entry(ICAO_address);
|
||||
frame.set_rx_timestamp(datetime.minute() * 60 + datetime.second());
|
||||
entry.reset_age();
|
||||
if (entry.hits==0)
|
||||
{
|
||||
entry.amp = message->amp;
|
||||
} else {
|
||||
entry.amp = ((entry.amp*15)+message->amp)>>4;
|
||||
}
|
||||
str_timestamp = to_string_datetime(datetime, HMS);
|
||||
entry.set_time_string(str_timestamp);
|
||||
|
||||
@ -224,12 +275,16 @@ void ADSBRxView::on_frame(const ADSBFrameMessage * message) {
|
||||
uint8_t msg_sub = frame.get_msg_sub();
|
||||
uint8_t * raw_data = frame.get_raw_data();
|
||||
|
||||
// 4: // surveillance, altitude reply
|
||||
if ((msg_type >= AIRCRAFT_ID_L) && (msg_type <= AIRCRAFT_ID_H)) {
|
||||
callsign = decode_frame_id(frame);
|
||||
entry.set_callsign(callsign);
|
||||
logentry+=callsign+" ";
|
||||
}
|
||||
//
|
||||
// 9:
|
||||
// 18: { // Extended squitter/non-transponder
|
||||
// 21: // Comm-B, identity reply
|
||||
// 20: // Comm-B, altitude reply
|
||||
else if (((msg_type >= AIRBORNE_POS_BARO_L) && (msg_type <= AIRBORNE_POS_BARO_H)) ||
|
||||
((msg_type >= AIRBORNE_POS_GPS_L) && (msg_type <= AIRBORNE_POS_GPS_H))) {
|
||||
entry.set_frame_pos(frame, raw_data[6] & 4);
|
||||
@ -250,12 +305,6 @@ void ADSBRxView::on_frame(const ADSBFrameMessage * message) {
|
||||
entry.set_info_string(str_info);
|
||||
logentry+=log_info + " ";
|
||||
|
||||
// we only want to update the details view if the frame
|
||||
// we received has the same ICAO address, i.e. belongs to
|
||||
// the same aircraft:
|
||||
if(send_updates && details_view->get_current_entry().ICAO_address == ICAO_address) {
|
||||
details_view->update(entry);
|
||||
}
|
||||
}
|
||||
} else if(msg_type == AIRBORNE_VEL && msg_sub >= VEL_GND_SUBSONIC && msg_sub <= VEL_AIR_SUPERSONIC){
|
||||
entry.set_frame_velo(frame);
|
||||
@ -263,13 +312,10 @@ void ADSBRxView::on_frame(const ADSBFrameMessage * message) {
|
||||
" Hdg:" + to_string_dec_uint(entry.velo.heading) +
|
||||
" Spd: "+ to_string_dec_int(entry.velo.speed);
|
||||
|
||||
// same here:
|
||||
if (send_updates && details_view->get_current_entry().ICAO_address == ICAO_address) {
|
||||
details_view->update(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
recent_entries_view.set_dirty();
|
||||
|
||||
replace_entry(entry);
|
||||
|
||||
logger = std::make_unique<ADSBLogger>();
|
||||
if (logger) {
|
||||
@ -287,13 +333,16 @@ void ADSBRxView::on_tick_second() {
|
||||
entry.inc_age();
|
||||
|
||||
if (details_view) {
|
||||
if (send_updates && (entry.key() == detailed_entry_key))
|
||||
if (send_updates && (entry.key() == detailed_entry_key)) // Check if the ICAO address match
|
||||
details_view->update(entry);
|
||||
} else {
|
||||
if ((entry.age == ADSB_DECAY_A) || (entry.age == ADSB_DECAY_B))
|
||||
recent_entries_view.set_dirty();
|
||||
}
|
||||
}
|
||||
|
||||
// Sort the list if it is being displayed
|
||||
if (!send_updates) {
|
||||
sort_entries_by_state();
|
||||
recent_entries_view.set_dirty();
|
||||
}
|
||||
}
|
||||
|
||||
ADSBRxView::ADSBRxView(NavigationView& nav) {
|
||||
@ -322,6 +371,8 @@ ADSBRxView::ADSBRxView(NavigationView& nav) {
|
||||
on_tick_second();
|
||||
};
|
||||
|
||||
prevFreq = receiver_model.tuning_frequency();
|
||||
|
||||
baseband::set_adsb();
|
||||
|
||||
receiver_model.set_tuning_frequency(1090000000);
|
||||
|
@ -32,6 +32,8 @@
|
||||
#include "adsb.hpp"
|
||||
#include "message.hpp"
|
||||
|
||||
#include "crc.hpp"
|
||||
|
||||
using namespace adsb;
|
||||
|
||||
namespace ui {
|
||||
@ -71,7 +73,10 @@ struct AircraftRecentEntry {
|
||||
|
||||
uint32_t ICAO_address { };
|
||||
uint16_t hits { 0 };
|
||||
|
||||
uint16_t age_state { 1 };
|
||||
uint32_t age { 0 };
|
||||
uint32_t amp { 0 };
|
||||
adsb_pos pos { false, 0, 0, 0 };
|
||||
adsb_vel velo { false, 0, 999, 0 };
|
||||
ADSBFrame frame_pos_even { };
|
||||
@ -122,13 +127,21 @@ struct AircraftRecentEntry {
|
||||
void set_time_string(std::string& new_time_string) {
|
||||
time_string = new_time_string;
|
||||
}
|
||||
|
||||
|
||||
void reset_age() {
|
||||
age = 0;
|
||||
}
|
||||
|
||||
void inc_age() {
|
||||
age++;
|
||||
if (age < ADSB_DECAY_A)
|
||||
{
|
||||
age_state = pos.valid ? 0 : 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
age_state = (age < ADSB_DECAY_B) ? 2 : 3;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -239,16 +252,30 @@ public:
|
||||
|
||||
std::string title() const override { return "ADS-B receive"; };
|
||||
|
||||
void replace_entry(AircraftRecentEntry & entry);
|
||||
AircraftRecentEntry find_or_create_entry(uint32_t ICAO_address);
|
||||
void sort_entries_by_state();
|
||||
|
||||
private:
|
||||
rf::Frequency prevFreq;
|
||||
std::unique_ptr<ADSBLogger> logger { };
|
||||
void on_frame(const ADSBFrameMessage * message);
|
||||
void on_tick_second();
|
||||
|
||||
const RecentEntriesColumns columns { {
|
||||
#if false
|
||||
{ "ICAO", 6 },
|
||||
{ "Callsign", 9 },
|
||||
{ "Hits", 4 },
|
||||
{ "Time", 8 }
|
||||
#else
|
||||
{ "ICAO/Call", 9 },
|
||||
{ "Lvl", 3 },
|
||||
{ "Spd", 3 },
|
||||
{ "Amp", 3 },
|
||||
{ "Hit", 3 },
|
||||
{ "Age", 3 }
|
||||
#endif
|
||||
} };
|
||||
AircraftRecentEntries recent { };
|
||||
RecentEntriesView<RecentEntries<AircraftRecentEntry>> recent_entries_view { columns, recent };
|
||||
|
@ -236,11 +236,8 @@ void set_fsk_data(const uint32_t stream_length, const uint32_t samples_per_bit,
|
||||
send_message(&message);
|
||||
}
|
||||
|
||||
void set_pocsag(const pocsag::BitRate bitrate, bool phase) {
|
||||
const POCSAGConfigureMessage message {
|
||||
bitrate,
|
||||
phase
|
||||
};
|
||||
void set_pocsag() {
|
||||
const POCSAGConfigureMessage message {};
|
||||
send_message(&message);
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ void set_ook_data(const uint32_t stream_length, const uint32_t samples_per_bit,
|
||||
const uint32_t pause_symbols);
|
||||
void set_fsk_data(const uint32_t stream_length, const uint32_t samples_per_bit, const uint32_t shift,
|
||||
const uint32_t progress_notice);
|
||||
void set_pocsag(const pocsag::BitRate bitrate, bool phase);
|
||||
void set_pocsag();
|
||||
void set_adsb();
|
||||
void set_jammer(const bool run, const jammer::JammerType type, const uint32_t speed);
|
||||
void set_rds_data(const uint16_t message_length);
|
||||
|
@ -670,7 +670,8 @@ BMPView::BMPView(NavigationView& nav) {
|
||||
}
|
||||
|
||||
void BMPView::paint(Painter&) {
|
||||
portapack::display.drawBMP({(240 - 230) / 2, (320 - 50) / 2 - 10}, splash_bmp, false);
|
||||
if(!portapack::display.drawBMP2({ 0, 0 }, "splash.bmp"))
|
||||
portapack::display.drawBMP({(240 - 230) / 2, (320 - 50) / 2 - 10}, splash_bmp, false);
|
||||
}
|
||||
|
||||
/* NotImplementedView ****************************************************/
|
||||
|
@ -214,7 +214,7 @@ public:
|
||||
InformationView(NavigationView& nav);
|
||||
void refresh();
|
||||
private:
|
||||
static constexpr auto version_string = "v1.4.0";
|
||||
static constexpr auto version_string = "v1.4.2";
|
||||
NavigationView& nav_;
|
||||
|
||||
Rectangle backdrop {
|
||||
|
@ -32,115 +32,125 @@ using namespace adsb;
|
||||
|
||||
void ADSBRXProcessor::execute(const buffer_c8_t& buffer) {
|
||||
int8_t re, im;
|
||||
float mag;
|
||||
uint32_t mag;
|
||||
uint32_t c;
|
||||
uint8_t level, bit, byte { };
|
||||
//bool confidence;
|
||||
bool first_in_window, last_in_window;
|
||||
uint8_t bit, byte{};
|
||||
|
||||
// This is called at 2M/2048 = 977Hz
|
||||
// One pulse = 500ns = 2 samples
|
||||
// One bit = 2 pulses = 1us = 4 samples
|
||||
|
||||
|
||||
if (!configured) return;
|
||||
|
||||
for (size_t i = 0; i < buffer.count; i++) {
|
||||
|
||||
// Compute sample's magnitude
|
||||
re = buffer.p[i].real();
|
||||
im = buffer.p[i].imag();
|
||||
mag = __builtin_sqrtf((re * re) + (im * im)) * k;
|
||||
|
||||
// Only used for preamble detection and visualisation
|
||||
level = (mag < 0.3) ? 0 : // Blank weak signals
|
||||
(mag > prev_mag) ? 1 : 0;
|
||||
|
||||
re = (int32_t)buffer.p[i].real(); // make re float and scale it
|
||||
im = (int32_t)buffer.p[i].imag(); // make re float and scale it
|
||||
mag = ((uint32_t)(re*re) + (uint32_t)(im*im));
|
||||
|
||||
if (decoding) {
|
||||
// Decode
|
||||
|
||||
// 1 bit lasts 2 samples
|
||||
if (sample_count & 1) {
|
||||
if ((prev_mag < threshold_low) && (mag < threshold_low)) {
|
||||
// Both under window, silence.
|
||||
if (null_count > 3) {
|
||||
const ADSBFrameMessage message(frame);
|
||||
shared_memory.application_queue.push(message);
|
||||
|
||||
decoding = false;
|
||||
} else
|
||||
null_count++;
|
||||
|
||||
//confidence = false;
|
||||
if (prev_mag > mag)
|
||||
bit = 1;
|
||||
else
|
||||
bit = 0;
|
||||
|
||||
} else {
|
||||
|
||||
null_count = 0;
|
||||
|
||||
first_in_window = ((prev_mag >= threshold_low) && (prev_mag <= threshold_high));
|
||||
last_in_window = ((mag >= threshold_low) && (mag <= threshold_high));
|
||||
|
||||
if ((first_in_window && !last_in_window) || (!first_in_window && last_in_window)) {
|
||||
//confidence = true;
|
||||
if (prev_mag > mag)
|
||||
bit = 1;
|
||||
else
|
||||
bit = 0;
|
||||
} else {
|
||||
//confidence = false;
|
||||
if (prev_mag > mag)
|
||||
bit = 1;
|
||||
else
|
||||
bit = 0;
|
||||
}
|
||||
if (bit_count >= msgLen)
|
||||
{
|
||||
const ADSBFrameMessage message(frame, amp);
|
||||
shared_memory.application_queue.push(message);
|
||||
decoding = false;
|
||||
bit = (prev_mag > mag) ? 1 : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//confidence = true;
|
||||
bit = (prev_mag > mag) ? 1 : 0;
|
||||
}
|
||||
|
||||
byte = bit | (byte << 1);
|
||||
bit_count++;
|
||||
|
||||
// Perform checks at the end of the first byte
|
||||
if (!(bit_count & 7)) {
|
||||
// Got one byte
|
||||
|
||||
// Store the byte
|
||||
frame.push_byte(byte);
|
||||
}
|
||||
}
|
||||
|
||||
// Check at the end of the first byte of the message
|
||||
uint8_t df = (byte >> 3);
|
||||
if ( (bit_count == 8) && !(df & 0x10) ) {
|
||||
msgLen = 56; // DFs 16 or greater are long 112. DFs 15 or less are short 56.
|
||||
}
|
||||
|
||||
// Abondon all frames that arent DF17 or DF18 extended squitters
|
||||
if ( (bit_count == 8) && !((df == 17)||(df == 18)) ) {
|
||||
decoding = false;
|
||||
bit = (prev_mag > mag) ? 1 : 0;
|
||||
frame.clear();
|
||||
}
|
||||
} // last bit of a byte
|
||||
} // Second sample of each bit
|
||||
sample_count++;
|
||||
} else {
|
||||
// Look for preamble
|
||||
|
||||
// Shift
|
||||
for (c = 0; c < (ADSB_PREAMBLE_LENGTH - 1); c++)
|
||||
shifter[c] = shifter[c + 1];
|
||||
shifter[15] = std::make_pair(mag, level);
|
||||
|
||||
// Compare
|
||||
for (c = 0; c < ADSB_PREAMBLE_LENGTH; c++) {
|
||||
if (shifter[c].second != adsb_preamble[c])
|
||||
break;
|
||||
}
|
||||
|
||||
if (c == ADSB_PREAMBLE_LENGTH) {
|
||||
decoding = true;
|
||||
sample_count = 0;
|
||||
null_count = 0;
|
||||
bit_count = 0;
|
||||
frame.clear();
|
||||
|
||||
// Compute preamble pulses power to set thresholds
|
||||
threshold = (shifter[0].first + shifter[2].first + shifter[7].first + shifter[9].first) / 4;
|
||||
threshold_high = threshold * 1.414; // +3dB
|
||||
threshold_low = threshold * 0.707; // -3dB
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Continue looking for preamble even if in a packet
|
||||
// switch is new preamble id higher magnitude
|
||||
|
||||
// Shift the preamble
|
||||
for (c = 0; c < (ADSB_PREAMBLE_LENGTH ); c++) { shifter[c] = shifter[c + 1]; }
|
||||
shifter[ADSB_PREAMBLE_LENGTH] = mag;
|
||||
|
||||
// First check of relations between the first 10 samples
|
||||
// representing a valid preamble. We don't even investigate further
|
||||
// if this simple test is not passed
|
||||
if (shifter[0] < shifter[1] &&
|
||||
shifter[1] > shifter[2] &&
|
||||
shifter[2] < shifter[3] &&
|
||||
shifter[3] > shifter[4] &&
|
||||
shifter[4] < shifter[1] &&
|
||||
shifter[5] < shifter[1] &&
|
||||
shifter[6] < shifter[1] &&
|
||||
shifter[7] < shifter[1] &&
|
||||
shifter[8] > shifter[9] &&
|
||||
shifter[9] < shifter[10] &&
|
||||
shifter[10]> shifter[11] )
|
||||
{
|
||||
// The samples between the two spikes must be < than the average
|
||||
// of the high spikes level. We don't test bits too near to
|
||||
// the high levels as signals can be out of phase so part of the
|
||||
// energy can be in the near samples
|
||||
int32_t thisAmp = (shifter[1] + shifter[3] + shifter[8] + shifter[10]);
|
||||
int32_t high = thisAmp / 9;
|
||||
if (
|
||||
shifter[5] < high &&
|
||||
shifter[6] < high &&
|
||||
// Similarly samples in the range 11-13 must be low, as it is the
|
||||
// space between the preamble and real data. Again we don't test
|
||||
// bits too near to high levels, see above
|
||||
shifter[12] < high &&
|
||||
shifter[13] < high &&
|
||||
shifter[14] < high )
|
||||
{
|
||||
if ((decoding == false) || // New preamble
|
||||
((decoding == true) && (thisAmp > amp))) // Higher power than existing packet
|
||||
{
|
||||
decoding = true;
|
||||
msgLen = 112;
|
||||
amp = thisAmp;
|
||||
sample_count = 0;
|
||||
bit_count = 0;
|
||||
frame.clear();
|
||||
}
|
||||
} // 4 & 5 low and 11-14 low
|
||||
} // Check for preamble pattern
|
||||
|
||||
// Store mag for next time
|
||||
prev_mag = mag;
|
||||
}
|
||||
}
|
||||
|
||||
void ADSBRXProcessor::on_message(const Message* const message) {
|
||||
if (message->id == Message::ID::ADSBConfigure) {
|
||||
null_count = 0;
|
||||
bit_count = 0;
|
||||
sample_count = 0;
|
||||
decoding = false;
|
||||
@ -148,8 +158,10 @@ void ADSBRXProcessor::on_message(const Message* const message) {
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
int main() {
|
||||
EventDispatcher event_dispatcher { std::make_unique<ADSBRXProcessor>() };
|
||||
event_dispatcher.run();
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
@ -40,8 +40,6 @@ public:
|
||||
void on_message(const Message* const message) override;
|
||||
|
||||
private:
|
||||
static constexpr float k = 1.0f / 128.0f;
|
||||
|
||||
static constexpr size_t baseband_fs = 2000000;
|
||||
|
||||
BasebandThread baseband_thread { baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Receive };
|
||||
@ -49,16 +47,17 @@ private:
|
||||
|
||||
ADSBFrame frame { };
|
||||
bool configured { false };
|
||||
float prev_mag { 0 };
|
||||
float threshold { }, threshold_low { }, threshold_high { };
|
||||
size_t null_count { 0 }, bit_count { 0 }, sample_count { 0 };
|
||||
std::pair<float, uint8_t> shifter[ADSB_PREAMBLE_LENGTH];
|
||||
uint32_t prev_mag { 0 };
|
||||
size_t bit_count { 0 }, sample_count { 0 };
|
||||
size_t msgLen{ 112 };
|
||||
uint32_t shifter[ADSB_PREAMBLE_LENGTH+1];
|
||||
bool decoding { };
|
||||
bool preamble { }, active { };
|
||||
uint16_t bit_pos { 0 };
|
||||
uint8_t cur_bit { 0 };
|
||||
uint32_t sample { 0 };
|
||||
int8_t re { }, im { };
|
||||
int32_t re { }, im { };
|
||||
int32_t amp {0};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -28,6 +28,9 @@
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include <algorithm> // std::max
|
||||
#include <cmath>
|
||||
|
||||
|
||||
void POCSAGProcessor::execute(const buffer_c8_t& buffer) {
|
||||
// This is called at 1500Hz
|
||||
@ -39,114 +42,45 @@ void POCSAGProcessor::execute(const buffer_c8_t& buffer) {
|
||||
const auto decim_1_out = decim_1.execute(decim_0_out, dst_buffer);
|
||||
const auto channel_out = channel_filter.execute(decim_1_out, dst_buffer);
|
||||
auto audio = demod.execute(channel_out, audio_buffer);
|
||||
//audio_output.write(audio);
|
||||
smooth.Process(audio.p, audio.count); // Smooth the data to make decoding more accurate
|
||||
audio_output.write(audio);
|
||||
|
||||
for (uint32_t c = 0; c < 16; c++) {
|
||||
|
||||
const int32_t sample_int = audio.p[c] * 32768.0f;
|
||||
const int32_t audio_sample = __SSAT(sample_int, 16);
|
||||
|
||||
slicer_sr <<= 1;
|
||||
if (phase == 0)
|
||||
slicer_sr |= (audio_sample < 0); // Do we need hysteresis ?
|
||||
else
|
||||
slicer_sr |= !(audio_sample < 0);
|
||||
|
||||
// Detect transitions to adjust clock
|
||||
if ((slicer_sr ^ (slicer_sr >> 1)) & 1) {
|
||||
if (sphase < (0x8000u - sphase_delta_half))
|
||||
sphase += sphase_delta_eighth;
|
||||
else
|
||||
sphase -= sphase_delta_eighth;
|
||||
}
|
||||
|
||||
sphase += sphase_delta;
|
||||
|
||||
// Symbol time elapsed
|
||||
if (sphase >= 0x10000u) {
|
||||
sphase &= 0xFFFFu;
|
||||
|
||||
rx_data <<= 1;
|
||||
rx_data |= (slicer_sr & 1);
|
||||
|
||||
switch (rx_state) {
|
||||
|
||||
case WAITING:
|
||||
if (rx_data == 0xAAAAAAAA) {
|
||||
rx_state = PREAMBLE;
|
||||
sync_timeout = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case PREAMBLE:
|
||||
if (sync_timeout < POCSAG_TIMEOUT) {
|
||||
sync_timeout++;
|
||||
processDemodulatedSamples(audio.p, 16);
|
||||
extractFrames();
|
||||
|
||||
if (rx_data == POCSAG_SYNCWORD) {
|
||||
packet.clear();
|
||||
codeword_count = 0;
|
||||
rx_bit = 0;
|
||||
msg_timeout = 0;
|
||||
rx_state = SYNC;
|
||||
}
|
||||
|
||||
} else {
|
||||
// Timeout here is normal (end of message)
|
||||
rx_state = WAITING;
|
||||
//push_packet(pocsag::PacketFlag::TIMED_OUT);
|
||||
}
|
||||
break;
|
||||
|
||||
case SYNC:
|
||||
if (msg_timeout < POCSAG_BATCH_LENGTH) {
|
||||
msg_timeout++;
|
||||
rx_bit++;
|
||||
|
||||
if (rx_bit >= 32) {
|
||||
rx_bit = 0;
|
||||
|
||||
// Got a complete codeword
|
||||
|
||||
//pocsag_brute_repair(&s->l2.pocsag, &rx_data);
|
||||
|
||||
packet.set(codeword_count, rx_data);
|
||||
|
||||
if (codeword_count < 15) {
|
||||
codeword_count++;
|
||||
} else {
|
||||
push_packet(pocsag::PacketFlag::NORMAL);
|
||||
rx_state = PREAMBLE;
|
||||
sync_timeout = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
packet.set(0, codeword_count); // Replace first codeword with count, for debug
|
||||
push_packet(pocsag::PacketFlag::TIMED_OUT);
|
||||
rx_state = WAITING;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void POCSAGProcessor::push_packet(pocsag::PacketFlag flag) {
|
||||
packet.set_bitrate(bitrate);
|
||||
packet.set_flag(flag);
|
||||
packet.set_timestamp(Timestamp::now());
|
||||
const POCSAGPacketMessage message(packet);
|
||||
shared_memory.application_queue.push(message);
|
||||
// ====================================================================
|
||||
//
|
||||
// ====================================================================
|
||||
int POCSAGProcessor::OnDataWord(uint32_t word, int pos)
|
||||
{
|
||||
packet.set(pos, word);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
//
|
||||
// ====================================================================
|
||||
int POCSAGProcessor::OnDataFrame(int len, int baud)
|
||||
{
|
||||
if (len > 0)
|
||||
{
|
||||
packet.set_bitrate(baud);
|
||||
packet.set_flag(pocsag::PacketFlag::NORMAL);
|
||||
packet.set_timestamp(Timestamp::now());
|
||||
const POCSAGPacketMessage message(packet);
|
||||
shared_memory.application_queue.push(message);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void POCSAGProcessor::on_message(const Message* const message) {
|
||||
if (message->id == Message::ID::POCSAGConfigure)
|
||||
configure(*reinterpret_cast<const POCSAGConfigureMessage*>(message));
|
||||
configure();
|
||||
}
|
||||
|
||||
void POCSAGProcessor::configure(const POCSAGConfigureMessage& message) {
|
||||
void POCSAGProcessor::configure() {
|
||||
constexpr size_t decim_0_input_fs = baseband_fs;
|
||||
constexpr size_t decim_0_output_fs = decim_0_input_fs / decim_0.decimation_factor;
|
||||
|
||||
@ -162,18 +96,442 @@ void POCSAGProcessor::configure(const POCSAGConfigureMessage& message) {
|
||||
decim_1.configure(taps_11k0_decim_1.taps, 131072);
|
||||
channel_filter.configure(taps_11k0_channel.taps, 2);
|
||||
demod.configure(demod_input_fs, 4500);
|
||||
//audio_output.configure(false);
|
||||
// Smoothing should be roughly sample rate over max baud
|
||||
// 24k / 3.2k is 7.5
|
||||
smooth.SetSize(8);
|
||||
audio_output.configure(false);
|
||||
|
||||
bitrate = message.bitrate;
|
||||
phase = message.phase;
|
||||
sphase_delta = 0x10000u * bitrate / POCSAG_AUDIO_RATE;
|
||||
sphase_delta_half = sphase_delta / 2; // Just for speed
|
||||
sphase_delta_eighth = sphase_delta / 8;
|
||||
|
||||
rx_state = WAITING;
|
||||
// Set up the frame extraction, limits of baud
|
||||
setFrameExtractParams(demod_input_fs, 4000, 300, 32);
|
||||
|
||||
// Mark the class as ready to accept data
|
||||
configured = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// -----------------------------
|
||||
// Frame extractraction methods
|
||||
// -----------------------------
|
||||
#define BAUD_STABLE (104)
|
||||
#define MAX_CONSEC_SAME (32)
|
||||
#define MAX_WITHOUT_SINGLE (64)
|
||||
#define MAX_BAD_TRANS (10)
|
||||
|
||||
#define M_SYNC (0x7cd215d8)
|
||||
#define M_NOTSYNC (0x832dea27)
|
||||
|
||||
#define M_IDLE (0x7a89c197)
|
||||
|
||||
// ====================================================================
|
||||
//
|
||||
// ====================================================================
|
||||
inline int bitsDiff(unsigned long left, unsigned long right)
|
||||
{
|
||||
unsigned long xord = left ^ right;
|
||||
int count = 0;
|
||||
for (int i = 0; i < 32; i++)
|
||||
{
|
||||
if ((xord & 0x01) != 0) ++count;
|
||||
xord = xord >> 1;
|
||||
}
|
||||
return(count);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// ====================================================================
|
||||
//
|
||||
// ====================================================================
|
||||
void POCSAGProcessor::initFrameExtraction()
|
||||
{
|
||||
m_averageSymbolLen_1024 = m_maxSymSamples_1024;
|
||||
m_lastStableSymbolLen_1024 = m_minSymSamples_1024;
|
||||
|
||||
m_badTransitions = 0;
|
||||
m_bitsStart = 0;
|
||||
m_bitsEnd = 0;
|
||||
m_inverted = false;
|
||||
|
||||
resetVals();
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
//
|
||||
// ====================================================================
|
||||
void POCSAGProcessor::resetVals()
|
||||
{
|
||||
// Reset the parameters
|
||||
// --------------------
|
||||
m_goodTransitions = 0;
|
||||
m_badTransitions = 0;
|
||||
m_averageSymbolLen_1024 = m_maxSymSamples_1024;
|
||||
m_shortestGoodTrans_1024 = m_maxSymSamples_1024;
|
||||
m_valMid = 0;
|
||||
|
||||
// And reset the counts
|
||||
// --------------------
|
||||
m_lastTransPos_1024 = 0;
|
||||
m_lastBitPos_1024 = 0;
|
||||
m_lastSample = 0;
|
||||
m_sampleNo = 0;
|
||||
m_nextBitPos_1024 = m_maxSymSamples_1024;
|
||||
m_nextBitPosInt = (long)m_nextBitPos_1024;
|
||||
|
||||
// Extraction
|
||||
m_fifo.numBits = 0;
|
||||
m_gotSync = false;
|
||||
m_numCode = 0;
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
//
|
||||
// ====================================================================
|
||||
void POCSAGProcessor::setFrameExtractParams(long a_samplesPerSec, long a_maxBaud, long a_minBaud, long maxRunOfSameValue)
|
||||
{
|
||||
m_samplesPerSec = a_samplesPerSec;
|
||||
m_minSymSamples_1024 = (uint32_t)(1024.0f * (float)a_samplesPerSec / (float)a_maxBaud);
|
||||
m_maxSymSamples_1024 = (uint32_t)(1024.0f*(float)a_samplesPerSec / (float)a_minBaud);
|
||||
m_maxRunOfSameValue = maxRunOfSameValue;
|
||||
|
||||
m_shortestGoodTrans_1024 = m_maxSymSamples_1024;
|
||||
m_averageSymbolLen_1024 = m_maxSymSamples_1024;
|
||||
m_lastStableSymbolLen_1024 = m_minSymSamples_1024;
|
||||
|
||||
m_nextBitPos_1024 = m_averageSymbolLen_1024 / 2;
|
||||
m_nextBitPosInt = m_nextBitPos_1024 >> 10;
|
||||
|
||||
initFrameExtraction();
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
//
|
||||
// ====================================================================
|
||||
int POCSAGProcessor::processDemodulatedSamples(float * sampleBuff, int noOfSamples)
|
||||
{
|
||||
bool transition = false;
|
||||
uint32_t samplePos_1024 = 0;
|
||||
uint32_t len_1024 = 0;
|
||||
|
||||
// Loop through the block of data
|
||||
// ------------------------------
|
||||
for (int pos = 0; pos < noOfSamples; ++pos)
|
||||
{
|
||||
m_sample = sampleBuff[pos];
|
||||
m_valMid += (m_sample - m_valMid) / 1024.0f;
|
||||
|
||||
++m_sampleNo;
|
||||
|
||||
// Detect Transition
|
||||
// -----------------
|
||||
transition = ! ((m_lastSample < m_valMid) ^ (m_sample >= m_valMid)); // use XOR for speed
|
||||
|
||||
// If this is a transition
|
||||
// -----------------------
|
||||
if (transition)
|
||||
{
|
||||
// Calculate samples since last trans
|
||||
// ----------------------------------
|
||||
int32_t fractional_1024 = (int32_t)(((m_sample - m_valMid)*1024) / (m_sample - m_lastSample));
|
||||
if (fractional_1024 < 0) { fractional_1024 = -fractional_1024; }
|
||||
|
||||
samplePos_1024 = (m_sampleNo<<10)-fractional_1024;
|
||||
len_1024 = samplePos_1024 - m_lastTransPos_1024;
|
||||
m_lastTransPos_1024 = samplePos_1024;
|
||||
|
||||
// If symbol is large enough to be valid
|
||||
// -------------------------------------
|
||||
if (len_1024 > m_minSymSamples_1024)
|
||||
{
|
||||
// Check for shortest good transition
|
||||
// ----------------------------------
|
||||
if ((len_1024 < m_shortestGoodTrans_1024) &&
|
||||
(m_goodTransitions < BAUD_STABLE)) // detect change of symbol size
|
||||
{
|
||||
int32_t fractionOfShortest_1024 = (len_1024<<10) / m_shortestGoodTrans_1024;
|
||||
|
||||
// If currently at half the baud rate
|
||||
// ----------------------------------
|
||||
if ((fractionOfShortest_1024 > 410) && (fractionOfShortest_1024 < 614)) // 0.4 and 0.6
|
||||
{
|
||||
m_averageSymbolLen_1024 /= 2;
|
||||
m_shortestGoodTrans_1024 = len_1024;
|
||||
}
|
||||
// If currently at the wrong baud rate
|
||||
// -----------------------------------
|
||||
else if (fractionOfShortest_1024 < 768) // 0.75
|
||||
{
|
||||
m_averageSymbolLen_1024 = len_1024;
|
||||
m_shortestGoodTrans_1024 = len_1024;
|
||||
m_goodTransitions = 0;
|
||||
m_lastSingleBitPos_1024 = samplePos_1024 - len_1024;
|
||||
}
|
||||
}
|
||||
|
||||
// Calc the number of bits since events
|
||||
// ------------------------------------
|
||||
int32_t halfSymbol_1024 = m_averageSymbolLen_1024 / 2;
|
||||
int bitsSinceLastTrans = max((uint32_t)1, (len_1024+halfSymbol_1024) / m_averageSymbolLen_1024 );
|
||||
int bitsSinceLastSingle = (((m_sampleNo<<10)-m_lastSingleBitPos_1024) + halfSymbol_1024) / m_averageSymbolLen_1024;
|
||||
|
||||
// Check for single bit
|
||||
// --------------------
|
||||
if (bitsSinceLastTrans == 1)
|
||||
{
|
||||
m_lastSingleBitPos_1024 = samplePos_1024;
|
||||
}
|
||||
|
||||
// If too long since last transition
|
||||
// ---------------------------------
|
||||
if (bitsSinceLastTrans > MAX_CONSEC_SAME)
|
||||
{
|
||||
resetVals();
|
||||
}
|
||||
// If too long sice last single bit
|
||||
// --------------------------------
|
||||
else if (bitsSinceLastSingle > MAX_WITHOUT_SINGLE)
|
||||
{
|
||||
resetVals();
|
||||
}
|
||||
else
|
||||
{
|
||||
// If this is a good transition
|
||||
// ----------------------------
|
||||
int32_t offsetFromExtectedTransition_1024 = len_1024 - (bitsSinceLastTrans*m_averageSymbolLen_1024);
|
||||
if (offsetFromExtectedTransition_1024 < 0) { offsetFromExtectedTransition_1024 = -offsetFromExtectedTransition_1024; }
|
||||
if (offsetFromExtectedTransition_1024 < ((int32_t)m_averageSymbolLen_1024 / 4)) // Has to be within 1/4 of symbol to be good
|
||||
{
|
||||
++m_goodTransitions;
|
||||
uint32_t bitsCount = min((uint32_t)BAUD_STABLE, m_goodTransitions);
|
||||
|
||||
uint32_t propFromPrevious = m_averageSymbolLen_1024*bitsCount;
|
||||
uint32_t propFromCurrent = (len_1024 / bitsSinceLastTrans);
|
||||
m_averageSymbolLen_1024 = (propFromPrevious + propFromCurrent) / (bitsCount + 1);
|
||||
m_badTransitions = 0;
|
||||
//if ( len < m_shortestGoodTrans ){m_shortestGoodTrans = len;}
|
||||
// Store the old symbol size
|
||||
if (m_goodTransitions >= BAUD_STABLE)
|
||||
{
|
||||
m_lastStableSymbolLen_1024 = m_averageSymbolLen_1024;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set the point of the last bit if not yet stable
|
||||
// -----------------------------------------------
|
||||
if ((m_goodTransitions < BAUD_STABLE) || (m_badTransitions > 0))
|
||||
{
|
||||
m_lastBitPos_1024 = samplePos_1024 - (m_averageSymbolLen_1024 / 2);
|
||||
}
|
||||
|
||||
// Calculate the exact positiom of the next bit
|
||||
// --------------------------------------------
|
||||
int32_t thisPlusHalfsymbol_1024 = samplePos_1024 + (m_averageSymbolLen_1024/2);
|
||||
int32_t lastPlusSymbol = m_lastBitPos_1024 + m_averageSymbolLen_1024;
|
||||
m_nextBitPos_1024 = lastPlusSymbol + ((thisPlusHalfsymbol_1024 - lastPlusSymbol) / 16);
|
||||
|
||||
// Check for bad pos error
|
||||
// -----------------------
|
||||
if (m_nextBitPos_1024 < samplePos_1024) m_nextBitPos_1024 += m_averageSymbolLen_1024;
|
||||
|
||||
// Calculate integer sample after next bit
|
||||
// ---------------------------------------
|
||||
m_nextBitPosInt = (m_nextBitPos_1024>>10) + 1;
|
||||
|
||||
} // symbol is large enough to be valid
|
||||
else
|
||||
{
|
||||
// Bad transition, so reset the counts
|
||||
// -----------------------------------
|
||||
++m_badTransitions;
|
||||
if (m_badTransitions > MAX_BAD_TRANS)
|
||||
{
|
||||
resetVals();
|
||||
}
|
||||
}
|
||||
} // end of if transition
|
||||
|
||||
// Reached the point of the next bit
|
||||
// ---------------------------------
|
||||
if (m_sampleNo >= m_nextBitPosInt)
|
||||
{
|
||||
// Everything is good so extract a bit
|
||||
// -----------------------------------
|
||||
if (m_goodTransitions > 20)
|
||||
{
|
||||
// Store value at the center of bit
|
||||
// --------------------------------
|
||||
storeBit();
|
||||
}
|
||||
// Check for long 1 or zero
|
||||
// ------------------------
|
||||
uint32_t bitsSinceLastTrans = ((m_sampleNo<<10) - m_lastTransPos_1024) / m_averageSymbolLen_1024;
|
||||
if (bitsSinceLastTrans > m_maxRunOfSameValue)
|
||||
{
|
||||
resetVals();
|
||||
}
|
||||
|
||||
// Store the point of the last bit
|
||||
// -------------------------------
|
||||
m_lastBitPos_1024 = m_nextBitPos_1024;
|
||||
|
||||
// Calculate the exact point of the next bit
|
||||
// -----------------------------------------
|
||||
m_nextBitPos_1024 += m_averageSymbolLen_1024;
|
||||
|
||||
// Look for the bit after the next bit pos
|
||||
// ---------------------------------------
|
||||
m_nextBitPosInt = (m_nextBitPos_1024>>10) + 1;
|
||||
|
||||
} // Reached the point of the next bit
|
||||
|
||||
m_lastSample = m_sample;
|
||||
|
||||
} // Loop through the block of data
|
||||
|
||||
return getNoOfBits();
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
//
|
||||
// ====================================================================
|
||||
void POCSAGProcessor::storeBit()
|
||||
{
|
||||
if (++m_bitsStart >= BIT_BUF_SIZE) { m_bitsStart = 0; }
|
||||
|
||||
// Calculate the bit value
|
||||
float sample = (m_sample + m_lastSample) / 2;
|
||||
//int32_t sample_1024 = m_sample_1024;
|
||||
bool bit = sample > m_valMid;
|
||||
|
||||
// If buffer not full
|
||||
if (m_bitsStart != m_bitsEnd)
|
||||
{
|
||||
// Decide on output val
|
||||
if (bit)
|
||||
{
|
||||
m_bits[m_bitsStart] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_bits[m_bitsStart] = 1;
|
||||
}
|
||||
}
|
||||
// Throw away bits if the buffer is full
|
||||
else
|
||||
{
|
||||
if (--m_bitsStart <= -1)
|
||||
{
|
||||
m_bitsStart = BIT_BUF_SIZE - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
//
|
||||
// ====================================================================
|
||||
int POCSAGProcessor::extractFrames()
|
||||
{
|
||||
int msgCnt = 0;
|
||||
// While there is unread data in the bits buffer
|
||||
//----------------------------------------------
|
||||
while (getNoOfBits() > 0)
|
||||
{
|
||||
m_fifo.codeword = (m_fifo.codeword << 1) + getBit();
|
||||
m_fifo.numBits++;
|
||||
|
||||
// If number of bits in fifo equals 32
|
||||
//------------------------------------
|
||||
if (m_fifo.numBits >= 32)
|
||||
{
|
||||
// Not got sync
|
||||
// ------------
|
||||
if (!m_gotSync)
|
||||
{
|
||||
if (bitsDiff(m_fifo.codeword, M_SYNC) <= 2)
|
||||
{
|
||||
m_inverted = false;
|
||||
m_gotSync = true;
|
||||
m_numCode = -1;
|
||||
m_fifo.numBits = 0;
|
||||
}
|
||||
else if (bitsDiff(m_fifo.codeword, M_NOTSYNC) <= 2)
|
||||
{
|
||||
m_inverted = true;
|
||||
m_gotSync = true;
|
||||
m_numCode = -1;
|
||||
m_fifo.numBits = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Cause it to load one more bit
|
||||
m_fifo.numBits = 31;
|
||||
}
|
||||
} // Not got sync
|
||||
else
|
||||
{
|
||||
// Increment the word count
|
||||
// ------------------------
|
||||
++m_numCode; // It got set to -1 when a sync was found, now count the 16 words
|
||||
uint32_t val = m_inverted ? ~m_fifo.codeword : m_fifo.codeword;
|
||||
OnDataWord(val, m_numCode);
|
||||
|
||||
// If at the end of a 16 word block
|
||||
// --------------------------------
|
||||
if (m_numCode >= 15)
|
||||
{
|
||||
msgCnt += OnDataFrame(m_numCode+1, (m_samplesPerSec<<10) / m_lastStableSymbolLen_1024);
|
||||
m_gotSync = false;
|
||||
m_numCode = -1;
|
||||
}
|
||||
m_fifo.numBits = 0;
|
||||
}
|
||||
} // If number of bits in fifo equals 32
|
||||
} // While there is unread data in the bits buffer
|
||||
return msgCnt;
|
||||
} // extractFrames
|
||||
|
||||
// ====================================================================
|
||||
//
|
||||
// ====================================================================
|
||||
short POCSAGProcessor::getBit()
|
||||
{
|
||||
if (m_bitsEnd != m_bitsStart)
|
||||
{
|
||||
if (++m_bitsEnd >= BIT_BUF_SIZE)
|
||||
{
|
||||
m_bitsEnd = 0;
|
||||
}
|
||||
return m_bits[m_bitsEnd];
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
//
|
||||
// ====================================================================
|
||||
int POCSAGProcessor::getNoOfBits()
|
||||
{
|
||||
int bits = m_bitsEnd - m_bitsStart;
|
||||
if (bits < 0) { bits += BIT_BUF_SIZE; }
|
||||
return bits;
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
//
|
||||
// ====================================================================
|
||||
uint32_t POCSAGProcessor::getRate()
|
||||
{
|
||||
return ((m_samplesPerSec<<10)+512) / m_lastStableSymbolLen_1024;
|
||||
}
|
||||
|
||||
|
||||
// ====================================================================
|
||||
//
|
||||
// ====================================================================
|
||||
int main() {
|
||||
EventDispatcher event_dispatcher { std::make_unique<POCSAGProcessor>() };
|
||||
event_dispatcher.run();
|
||||
|
@ -40,25 +40,100 @@
|
||||
#include "portapack_shared_memory.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <bitset>
|
||||
using namespace std;
|
||||
|
||||
// Class used to smooth demodulated waveform prior to decoding
|
||||
// -----------------------------------------------------------
|
||||
template <class ValType, class CalcType>
|
||||
class SmoothVals
|
||||
{
|
||||
protected:
|
||||
ValType * m_lastVals; // Previoius N values
|
||||
int m_size; // The size N
|
||||
CalcType m_sumVal; // Running sum of lastVals
|
||||
int m_pos; // Current position in last vals ring buffer
|
||||
int m_count; //
|
||||
|
||||
class POCSAGProcessor : public BasebandProcessor {
|
||||
public:
|
||||
SmoothVals() : m_lastVals(NULL), m_size(1), m_sumVal(0), m_pos(0), m_count(0)
|
||||
{
|
||||
m_lastVals = new ValType[m_size];
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
// --------------------------------------------------
|
||||
virtual ~SmoothVals()
|
||||
{
|
||||
delete[] m_lastVals;
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
// Set size of smoothing
|
||||
// --------------------------------------------------
|
||||
void SetSize(int size)
|
||||
{
|
||||
m_size = std::max(size, 1);
|
||||
m_pos = 0;
|
||||
delete[] m_lastVals;
|
||||
m_lastVals = new ValType[m_size];
|
||||
m_sumVal = 0;
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
// Get size of smoothing
|
||||
// --------------------------------------------------
|
||||
int Size() { return m_size; }
|
||||
|
||||
// --------------------------------------------------
|
||||
// In place processing
|
||||
// --------------------------------------------------
|
||||
void Process(ValType * valBuff, int numVals)
|
||||
{
|
||||
ValType tmpVal;
|
||||
|
||||
if (m_count > (1024*10))
|
||||
{
|
||||
// Recalculate the sum value occasionaly, stops accumulated errors when using float
|
||||
m_count = 0;
|
||||
m_sumVal = 0;
|
||||
for (int i = 0; i < m_size; ++i) { m_sumVal += (CalcType)m_lastVals[i]; }
|
||||
}
|
||||
|
||||
// Use a rolling smoothed value while processing the buffer
|
||||
for (int buffPos = 0; buffPos < numVals; ++buffPos)
|
||||
{
|
||||
m_pos = (m_pos + 1); // Increment the position in the stored values
|
||||
if (m_pos >= m_size) { m_pos = 0; } // loop if reached the end of the stored values
|
||||
|
||||
m_sumVal -= (CalcType)m_lastVals[m_pos]; // Subtract the oldest value
|
||||
m_lastVals[m_pos] = valBuff[buffPos]; // Store the new value
|
||||
m_sumVal += (CalcType)m_lastVals[m_pos]; // Add on the new value
|
||||
|
||||
tmpVal = (ValType)(m_sumVal / m_size); // Scale by number of values smoothed
|
||||
valBuff[buffPos] = tmpVal;
|
||||
}
|
||||
|
||||
m_count += numVals;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------------
|
||||
// Class to process base band data to pocsag frames
|
||||
// --------------------------------------------------
|
||||
class POCSAGProcessor : public BasebandProcessor{
|
||||
public:
|
||||
|
||||
void execute(const buffer_c8_t& buffer) override;
|
||||
|
||||
void on_message(const Message* const message) override;
|
||||
|
||||
private:
|
||||
enum rx_states {
|
||||
WAITING = 0,
|
||||
PREAMBLE = 32,
|
||||
SYNC = 64,
|
||||
//LOSING_SYNC = 65,
|
||||
//LOST_SYNC = 66,
|
||||
//ADDRESS = 67,
|
||||
//MESSAGE = 68,
|
||||
//END_OF_MESSAGE = 69
|
||||
};
|
||||
int OnDataFrame(int len, int baud);
|
||||
int OnDataWord(uint32_t word, int pos);
|
||||
|
||||
private:
|
||||
static constexpr size_t baseband_fs = 3072000;
|
||||
|
||||
BasebandThread baseband_thread { baseband_fs, this, NORMALPRIO + 20, baseband::Direction::Receive };
|
||||
@ -79,28 +154,71 @@ private:
|
||||
dsp::decimate::FIRC16xR16x32Decim8 decim_1 { };
|
||||
dsp::decimate::FIRAndDecimateComplex channel_filter { };
|
||||
dsp::demodulate::FM demod { };
|
||||
SmoothVals<float, float> smooth;
|
||||
|
||||
//AudioOutput audio_output { };
|
||||
AudioOutput audio_output { };
|
||||
|
||||
uint32_t sync_timeout { 0 };
|
||||
uint32_t msg_timeout { 0 };
|
||||
|
||||
uint32_t slicer_sr { 0 };
|
||||
uint32_t sphase { 0 };
|
||||
uint32_t sphase_delta { 0 };
|
||||
uint32_t sphase_delta_half { 0 };
|
||||
uint32_t sphase_delta_eighth { 0 };
|
||||
uint32_t rx_data { 0 };
|
||||
uint32_t rx_bit { 0 };
|
||||
bool configured = false;
|
||||
rx_states rx_state { WAITING };
|
||||
pocsag::BitRate bitrate { pocsag::BitRate::FSK1200 };
|
||||
bool phase = false ;
|
||||
uint32_t codeword_count { 0 };
|
||||
pocsag::POCSAGPacket packet { };
|
||||
|
||||
void push_packet(pocsag::PacketFlag flag);
|
||||
void configure(const POCSAGConfigureMessage& message);
|
||||
|
||||
void configure();
|
||||
|
||||
// ----------------------------------------
|
||||
// Frame extractraction methods and members
|
||||
// ----------------------------------------
|
||||
private:
|
||||
void initFrameExtraction();
|
||||
struct FIFOStruct {
|
||||
unsigned long codeword;
|
||||
int numBits;
|
||||
};
|
||||
|
||||
#define BIT_BUF_SIZE (64)
|
||||
|
||||
void resetVals();
|
||||
void setFrameExtractParams(long a_samplesPerSec, long a_maxBaud = 8000, long a_minBaud = 200, long maxRunOfSameValue = 32);
|
||||
|
||||
int processDemodulatedSamples(float * sampleBuff, int noOfSamples);
|
||||
int extractFrames();
|
||||
|
||||
void storeBit();
|
||||
short getBit();
|
||||
|
||||
int getNoOfBits();
|
||||
uint32_t getRate();
|
||||
|
||||
uint32_t m_averageSymbolLen_1024{0};
|
||||
uint32_t m_lastStableSymbolLen_1024{0};
|
||||
|
||||
uint32_t m_samplesPerSec{0};
|
||||
uint32_t m_goodTransitions{0};
|
||||
uint32_t m_badTransitions{0};
|
||||
|
||||
uint32_t m_sampleNo{0};
|
||||
float m_sample{0};
|
||||
float m_valMid{0.0f};
|
||||
float m_lastSample{0.0f};
|
||||
|
||||
uint32_t m_lastTransPos_1024{0};
|
||||
uint32_t m_lastSingleBitPos_1024{0};
|
||||
|
||||
uint32_t m_nextBitPosInt{0}; // Integer rounded up version to save on ops
|
||||
uint32_t m_nextBitPos_1024{0};
|
||||
uint32_t m_lastBitPos_1024{0};
|
||||
|
||||
uint32_t m_shortestGoodTrans_1024{0};
|
||||
uint32_t m_minSymSamples_1024{0};
|
||||
uint32_t m_maxSymSamples_1024{0};
|
||||
uint32_t m_maxRunOfSameValue{0};
|
||||
|
||||
bitset<(size_t)BIT_BUF_SIZE> m_bits{0};
|
||||
long m_bitsStart{0};
|
||||
long m_bitsEnd{0};
|
||||
|
||||
FIFOStruct m_fifo{0,0};
|
||||
bool m_gotSync{false};
|
||||
int m_numCode{0};
|
||||
bool m_inverted{false};
|
||||
|
||||
};
|
||||
|
||||
|
@ -30,8 +30,13 @@ using namespace portapack;
|
||||
|
||||
#include "ch.h"
|
||||
|
||||
#include "file.hpp"
|
||||
|
||||
#include <complex>
|
||||
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
namespace lcd {
|
||||
|
||||
namespace {
|
||||
@ -416,6 +421,113 @@ void ILI9341::drawBMP(const ui::Point p, const uint8_t * bitmap, const bool tran
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Draw BMP from SD card.
|
||||
Currently supported formats:
|
||||
16bpp ARGB, RGB565
|
||||
24bpp RGB
|
||||
32bpp ARGB
|
||||
*/
|
||||
bool ILI9341::drawBMP2(const ui::Point p, const std::string file) {
|
||||
File bmpimage;
|
||||
size_t file_pos = 0;
|
||||
uint16_t pointer = 0;
|
||||
int16_t px = 0, py, width, height;
|
||||
bmp_header_t bmp_header;
|
||||
uint8_t type = 0;
|
||||
char buffer[257];
|
||||
ui::Color line_buffer[240];
|
||||
|
||||
auto result = bmpimage.open(file);
|
||||
if(result.is_valid())
|
||||
return false;
|
||||
|
||||
bmpimage.seek(file_pos);
|
||||
auto read_size = bmpimage.read(&bmp_header, sizeof(bmp_header));
|
||||
if (!((bmp_header.signature == 0x4D42) && // "BM" Signature
|
||||
(bmp_header.planes == 1) && // Seems always to be 1
|
||||
(bmp_header.compression == 0 || bmp_header.compression == 3 ))) { // No compression
|
||||
return false;
|
||||
}
|
||||
|
||||
switch(bmp_header.bpp) {
|
||||
case 16:
|
||||
file_pos = 0x36;
|
||||
memset(buffer, 0, 16);
|
||||
bmpimage.read(buffer, 16);
|
||||
if(buffer[1] == 0x7C)
|
||||
type = 3; // A1R5G5B5
|
||||
else
|
||||
type = 0; // R5G6B5
|
||||
break;
|
||||
case 24:
|
||||
type = 1;
|
||||
break;
|
||||
case 32:
|
||||
default:
|
||||
type = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
width = bmp_header.width;
|
||||
height = bmp_header.height;
|
||||
|
||||
file_pos = bmp_header.image_data;
|
||||
|
||||
py = height + 16;
|
||||
|
||||
while(1) {
|
||||
while(px < width) {
|
||||
bmpimage.seek(file_pos);
|
||||
memset(buffer, 0, 257);
|
||||
read_size = bmpimage.read(buffer, 256);
|
||||
if (read_size.is_error())
|
||||
return false; // Read error
|
||||
|
||||
pointer = 0;
|
||||
while(pointer < 256) {
|
||||
if(pointer + 4 > 256)
|
||||
break;
|
||||
switch(type) {
|
||||
case 0:
|
||||
case 3:
|
||||
if(!type)
|
||||
line_buffer[px] = ui::Color((uint16_t)buffer[pointer] | ((uint16_t)buffer[pointer + 1] << 8));
|
||||
else
|
||||
line_buffer[px] = ui::Color(((uint16_t)buffer[pointer] & 0x1F) | ((uint16_t)buffer[pointer] & 0xE0) << 1 | ((uint16_t)buffer[pointer + 1] & 0x7F) << 9);
|
||||
pointer += 2;
|
||||
file_pos += 2;
|
||||
break;
|
||||
case 1:
|
||||
default:
|
||||
line_buffer[px] = ui::Color(buffer[pointer + 2], buffer[pointer + 1], buffer[pointer]);
|
||||
pointer += 3;
|
||||
file_pos += 3;
|
||||
break;
|
||||
case 2:
|
||||
line_buffer[px] = ui::Color(buffer[pointer + 2], buffer[pointer + 1], buffer[pointer]);
|
||||
pointer += 4;
|
||||
file_pos += 4;
|
||||
break;
|
||||
}
|
||||
px++;
|
||||
if(px >= width) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(read_size.value() != 256)
|
||||
break;
|
||||
}
|
||||
render_line({ p.x(), p.y() + py }, px, line_buffer);
|
||||
px = 0;
|
||||
py--;
|
||||
|
||||
if(read_size.value() < 256 || py < 0)
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ILI9341::draw_line(const ui::Point start, const ui::Point end, const ui::Color color) {
|
||||
int x0 = start.x();
|
||||
int y0 = start.y();
|
||||
|
@ -60,6 +60,7 @@ public:
|
||||
|
||||
void draw_pixel(const ui::Point p, const ui::Color color);
|
||||
void drawBMP(const ui::Point p, const uint8_t * bitmap, const bool transparency);
|
||||
bool drawBMP2(const ui::Point p, const std::string file);
|
||||
void render_line(const ui::Point p, const uint8_t count, const ui::Color* line_buffer);
|
||||
void render_box(const ui::Point p, const ui::Size s, const ui::Color* line_buffer);
|
||||
|
||||
|
@ -376,13 +376,16 @@ public:
|
||||
class ADSBFrameMessage : public Message {
|
||||
public:
|
||||
constexpr ADSBFrameMessage(
|
||||
const adsb::ADSBFrame& frame
|
||||
const adsb::ADSBFrame& frame,
|
||||
const uint32_t amp
|
||||
) : Message { ID::ADSBFrame },
|
||||
frame { frame }
|
||||
frame { frame },
|
||||
amp(amp)
|
||||
{
|
||||
}
|
||||
|
||||
adsb::ADSBFrame frame;
|
||||
uint32_t amp;
|
||||
};
|
||||
|
||||
class AFSKDataMessage : public Message {
|
||||
@ -1016,17 +1019,10 @@ public:
|
||||
|
||||
class POCSAGConfigureMessage : public Message {
|
||||
public:
|
||||
constexpr POCSAGConfigureMessage(
|
||||
const pocsag::BitRate bitrate,
|
||||
const bool phase
|
||||
) : Message { ID::POCSAGConfigure },
|
||||
bitrate(bitrate),
|
||||
phase(phase)
|
||||
constexpr POCSAGConfigureMessage()
|
||||
: Message { ID::POCSAGConfigure }
|
||||
{
|
||||
}
|
||||
|
||||
const pocsag::BitRate bitrate;
|
||||
const bool phase;
|
||||
};
|
||||
|
||||
class APRSPacketMessage : public Message {
|
||||
|
@ -36,6 +36,7 @@ std::string bitrate_str(BitRate bitrate) {
|
||||
case BitRate::FSK512: return "512bps ";
|
||||
case BitRate::FSK1200: return "1200bps";
|
||||
case BitRate::FSK2400: return "2400bps";
|
||||
case BitRate::FSK3200: return "3200bps";
|
||||
default: return "????";
|
||||
}
|
||||
}
|
||||
@ -219,7 +220,176 @@ void pocsag_encode(const MessageType type, BCHCode& BCH_code, const uint32_t fun
|
||||
} while (char_idx < message_size);
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
// -------------------------------------------------------------------------------
|
||||
inline int bitsDiff(unsigned long left, unsigned long right)
|
||||
{
|
||||
unsigned long xord = left ^ right;
|
||||
int count = 0;
|
||||
for (int i = 0; i<32; i++)
|
||||
{
|
||||
if ((xord & 0x01) != 0) ++count;
|
||||
xord = xord >> 1;
|
||||
}
|
||||
return(count);
|
||||
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
// -------------------------------------------------------------------------------
|
||||
static uint32_t ecs[32]; /* error correction sequence */
|
||||
static uint32_t bch[1025];
|
||||
static int eccSetup = 0;
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
// -------------------------------------------------------------------------------
|
||||
void setupecc()
|
||||
{
|
||||
unsigned int srr = 0x3b4;
|
||||
unsigned int i, n, j, k;
|
||||
|
||||
/* calculate all information needed to implement error correction */
|
||||
// Note : this is only for 31,21 code used in pocsag & flex
|
||||
// one should probably also make use of 32nd parity bit
|
||||
for (i = 0; i <= 20; i++)
|
||||
{
|
||||
ecs[i] = srr;
|
||||
if ((srr & 0x01) != 0) srr = (srr >> 1) ^ 0x3B4; else srr = srr >> 1;
|
||||
}
|
||||
|
||||
/* bch holds a syndrome look-up table telling which bits to correct */
|
||||
// first 5 bits hold location of first error; next 5 bits hold location
|
||||
// of second error; bits 12 & 13 tell how many bits are bad
|
||||
for (i = 0; i<1024; i++) bch[i] = 0;
|
||||
|
||||
/* two errors in data */
|
||||
for (n = 0; n <= 20; n++)
|
||||
{
|
||||
for (i = 0; i <= 20; i++)
|
||||
{
|
||||
j = (i << 5) + n;
|
||||
k = ecs[n] ^ ecs[i];
|
||||
bch[k] = j + 0x2000;
|
||||
}
|
||||
}
|
||||
|
||||
/* one error in data */
|
||||
for (n = 0; n <= 20; n++)
|
||||
{
|
||||
k = ecs[n];
|
||||
j = n + (0x1f << 5);
|
||||
bch[k] = j + 0x1000;
|
||||
}
|
||||
|
||||
/* one error in data and one error in ecc portion */
|
||||
for (n = 0; n <= 20; n++)
|
||||
{
|
||||
for (i = 0; i<10; i++) /* ecc screwed up bit */
|
||||
{
|
||||
k = ecs[n] ^ (1 << i);
|
||||
j = n + (0x1f << 5);
|
||||
bch[k] = j + 0x2000;
|
||||
}
|
||||
}
|
||||
|
||||
/* one error in ecc */
|
||||
for (n = 0; n<10; n++)
|
||||
{
|
||||
k = 1 << n;
|
||||
bch[k] = 0x3ff + 0x1000;
|
||||
}
|
||||
|
||||
/* two errors in ecc */
|
||||
for (n = 0; n<10; n++)
|
||||
{
|
||||
for (i = 0; i<10; i++)
|
||||
{
|
||||
if (i != n)
|
||||
{
|
||||
k = (1 << n) ^ (1 << i);
|
||||
bch[k] = 0x3ff + 0x2000;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
// -------------------------------------------------------------------------------
|
||||
inline int errorCorrection(uint32_t * val)
|
||||
{
|
||||
// Set up the tables the first time
|
||||
if (eccSetup == 0)
|
||||
{
|
||||
setupecc();
|
||||
eccSetup = 1;
|
||||
}
|
||||
|
||||
int i, synd, errl, acc, pari, ecc, b1, b2;
|
||||
|
||||
errl = 0;
|
||||
pari = 0;
|
||||
|
||||
/* run through error detection and correction routine */
|
||||
|
||||
// for (i=0; i<=20; i++)
|
||||
ecc = 0;
|
||||
for (i = 31; i >= 11; --i)
|
||||
{
|
||||
if ((*val&(1 << i))) { ecc = ecc ^ ecs[31 - i]; pari = pari ^ 0x01; }
|
||||
}
|
||||
|
||||
// for (i=21; i<=30; i++)
|
||||
acc = 0;
|
||||
for (i = 10; i >= 1; --i)
|
||||
{
|
||||
acc = acc << 1;
|
||||
if ((*val&(1 << i))) { acc = acc ^ 0x01; }
|
||||
}
|
||||
|
||||
synd = ecc ^ acc;
|
||||
|
||||
errl = 0;
|
||||
|
||||
if (synd != 0) /* if nonzero syndrome we have error */
|
||||
{
|
||||
|
||||
if (bch[synd] != 0) /* check for correctable error */
|
||||
{
|
||||
b1 = bch[synd] & 0x1f;
|
||||
b2 = bch[synd] >> 5;
|
||||
b2 = b2 & 0x1f;
|
||||
|
||||
if (b2 != 0x1f)
|
||||
{
|
||||
*val ^= 0x01 << (31 - b2);
|
||||
ecc = ecc ^ ecs[b2];
|
||||
}
|
||||
|
||||
if (b1 != 0x1f)
|
||||
{
|
||||
*val ^= 0x01 << (31 - b1);
|
||||
ecc = ecc ^ ecs[b1];
|
||||
}
|
||||
|
||||
errl = bch[synd] >> 12;
|
||||
}
|
||||
else
|
||||
{
|
||||
errl = 3;
|
||||
}
|
||||
|
||||
if (errl == 1) pari = pari ^ 0x01;
|
||||
}
|
||||
|
||||
if (errl == 4) errl = 3;
|
||||
|
||||
return errl;
|
||||
}
|
||||
|
||||
|
||||
void pocsag_decode_batch(const POCSAGPacket& batch, POCSAGState * const state) {
|
||||
int errors = 0;
|
||||
uint32_t codeword;
|
||||
char ascii_char;
|
||||
std::string output_text = "";
|
||||
@ -230,15 +400,21 @@ void pocsag_decode_batch(const POCSAGPacket& batch, POCSAGState * const state) {
|
||||
for (size_t i = 0; i < 16; i++) {
|
||||
codeword = batch[i];
|
||||
|
||||
errorCorrection(&codeword);
|
||||
errors = errorCorrection(&codeword);
|
||||
|
||||
if (!(codeword & 0x80000000U)) {
|
||||
// Address codeword
|
||||
if (state->mode == STATE_CLEAR) {
|
||||
if (codeword != POCSAG_IDLEWORD) {
|
||||
//if (codeword != POCSAG_IDLEWORD) {
|
||||
if (! (bitsDiff(codeword, POCSAG_IDLEWORD) < 1)){
|
||||
|
||||
state->function = (codeword >> 11) & 3;
|
||||
state->address = (codeword >> 10) & 0x1FFFF8U; // 18 MSBs are transmitted
|
||||
state->mode = STATE_HAVE_ADDRESS;
|
||||
state->out_type = ADDRESS;
|
||||
|
||||
state->errors = errors;
|
||||
|
||||
state->ascii_idx = 0;
|
||||
state->ascii_data = 0;
|
||||
}
|
||||
@ -246,6 +422,7 @@ void pocsag_decode_batch(const POCSAGPacket& batch, POCSAGState * const state) {
|
||||
state->mode = STATE_CLEAR; // New address = new message
|
||||
}
|
||||
} else {
|
||||
state->errors += errors;
|
||||
// Message codeword
|
||||
if (state->mode == STATE_HAVE_ADDRESS) {
|
||||
// First message codeword: complete address
|
||||
@ -270,7 +447,10 @@ void pocsag_decode_batch(const POCSAGPacket& batch, POCSAGState * const state) {
|
||||
|
||||
// Translate non-printable chars
|
||||
if ((ascii_char < 32) || (ascii_char > 126))
|
||||
output_text += "[" + to_string_dec_uint(ascii_char) + "]";
|
||||
{
|
||||
//output_text += "[" + to_string_dec_uint(ascii_char) + "]";
|
||||
output_text += ".";
|
||||
}
|
||||
else
|
||||
output_text += ascii_char;
|
||||
}
|
||||
|
@ -62,6 +62,7 @@ struct POCSAGState {
|
||||
OutputType out_type = EMPTY;
|
||||
uint32_t ascii_data;
|
||||
uint32_t ascii_idx;
|
||||
uint32_t errors;
|
||||
std::string output;
|
||||
};
|
||||
|
||||
|
@ -63,11 +63,11 @@ public:
|
||||
return (index < 16) ? codewords[index] : 0;
|
||||
}
|
||||
|
||||
void set_bitrate(const BitRate bitrate) {
|
||||
void set_bitrate(const uint16_t bitrate) {
|
||||
bitrate_ = bitrate;
|
||||
}
|
||||
|
||||
BitRate bitrate() const {
|
||||
uint16_t bitrate() const {
|
||||
return bitrate_;
|
||||
}
|
||||
|
||||
@ -81,12 +81,12 @@ public:
|
||||
|
||||
void clear() {
|
||||
codewords.fill(0);
|
||||
bitrate_ = UNKNOWN;
|
||||
bitrate_ = 0u;
|
||||
flag_ = NORMAL;
|
||||
}
|
||||
|
||||
private:
|
||||
BitRate bitrate_ { UNKNOWN };
|
||||
uint16_t bitrate_ { 0 };
|
||||
PacketFlag flag_ { NORMAL };
|
||||
std::array <uint32_t, 16> codewords { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 };
|
||||
Timestamp timestamp_ { };
|
||||
|
@ -1,42 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Copyright (C) 2017 Furrtek
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
import sys
|
||||
import struct
|
||||
|
||||
outfile = open("airlines.db", "w")
|
||||
|
||||
# Download airlines.txt from http://xdeco.org/?page_id=30
|
||||
lines = [line.rstrip('\n') for line in open('../../sdcard/ADSB/airlines.txt', 'r')]
|
||||
n = 0
|
||||
|
||||
for line in lines:
|
||||
if line:
|
||||
nd = line.find('(')
|
||||
if (nd == -1):
|
||||
nd = None
|
||||
else:
|
||||
nd -= 1
|
||||
nline = line[4:7] + '\0' + line[10:nd] + '\0'
|
||||
print nline
|
||||
b = bytearray(nline)
|
||||
pad_len = 32 - len(b)
|
||||
b += "\0" * pad_len
|
||||
outfile.write(b)
|
7
firmware/tools/make_airlines_db/README.md
Normal file
7
firmware/tools/make_airlines_db/README.md
Normal file
@ -0,0 +1,7 @@
|
||||
# Make airlines.db
|
||||
|
||||
Licensed under GNU GPL v3 (license)[../../../LICENSE]
|
||||
|
||||
USAGE:
|
||||
- Copy file from: https://raw.githubusercontent.com/kx1t/planefence-airlinecodes/main/airlinecodes.txt
|
||||
- Run Python 3 script: `./make_airlines_db.py`
|
5531
firmware/tools/make_airlines_db/airlinecodes.txt
Executable file
5531
firmware/tools/make_airlines_db/airlinecodes.txt
Executable file
File diff suppressed because it is too large
Load Diff
54
firmware/tools/make_airlines_db/make_airlines_db.py
Executable file
54
firmware/tools/make_airlines_db/make_airlines_db.py
Executable file
@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright (C) 2021 ArjanOnwezen
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
# -------------------------------------------------------------------------------------
|
||||
# Create airline.db, used for ADS-B receiver application, using
|
||||
# https://raw.githubusercontent.com/kx1t/planefence-airlinecodes/main/airlinecodes.txt
|
||||
# as a source.
|
||||
# -------------------------------------------------------------------------------------
|
||||
import csv
|
||||
import unicodedata
|
||||
icao_codes=bytearray()
|
||||
airlines_countries=bytearray()
|
||||
row_count=0
|
||||
|
||||
database=open("airlines.db", "wb")
|
||||
|
||||
with open('airlinecodes.txt', 'rt') as csv_file:
|
||||
sorted_lines=sorted(csv_file.readlines())
|
||||
|
||||
for row in csv.reader(sorted_lines, quotechar='"', delimiter=',', quoting=csv.QUOTE_ALL, skipinitialspace=True):
|
||||
icao_code=row[0]
|
||||
# Normalize some unicode characters
|
||||
airline=unicodedata.normalize('NFKD', row[1][:32]).encode('ascii', 'ignore')
|
||||
country=unicodedata.normalize('NFKD', row[3][:32]).encode('ascii', 'ignore')
|
||||
if len(icao_code) == 3 :
|
||||
airline_padding=bytearray()
|
||||
country_padding=bytearray()
|
||||
print(icao_code,' - ', airline,' - ', country)
|
||||
icao_codes=icao_codes+bytearray(icao_code+'\0', encoding='ascii')
|
||||
airline_padding=bytearray('\0' * (32 - len(airline)), encoding='ascii')
|
||||
country_padding=bytearray('\0' * (32 - len(country)), encoding='ascii')
|
||||
airlines_countries=airlines_countries+bytearray(airline+airline_padding+country+country_padding)
|
||||
row_count+=1
|
||||
|
||||
database.write(icao_codes+airlines_countries)
|
||||
print("Total of", row_count, "ICAO codes stored in database")
|
||||
|
BIN
sdcard/ADSB/airlines.db
Normal file → Executable file
BIN
sdcard/ADSB/airlines.db
Normal file → Executable file
Binary file not shown.
Loading…
Reference in New Issue
Block a user