ads-b message decoding and beutification

bug_fixes_integration_tx
David Michaeli 2022-04-21 13:04:08 +03:00
rodzic 6a60ecbc31
commit ebdba93510
18 zmienionych plików z 1259 dodań i 576 usunięć

Wyświetl plik

@ -20,6 +20,7 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_executable(caribou_dump1090
dump1090.cpp
modes.c
cpr.c
)
target_link_libraries(caribou_dump1090 SoapySDR iir_static)

Wyświetl plik

@ -93,12 +93,12 @@ clean: CMakeFiles/caribou_dump1090.dir/clean
CMakeFiles/caribou_dump1090.dir/all:
$(MAKE) $(MAKESILENT) -f CMakeFiles/caribou_dump1090.dir/build.make CMakeFiles/caribou_dump1090.dir/depend
$(MAKE) $(MAKESILENT) -f CMakeFiles/caribou_dump1090.dir/build.make CMakeFiles/caribou_dump1090.dir/build
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --progress-dir=/home/pi/projects/cariboulite/examples/cpp/build/CMakeFiles --progress-num=1,2,3 "Built target caribou_dump1090"
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --progress-dir=/home/pi/projects/cariboulite/examples/cpp/build/CMakeFiles --progress-num=1,2,3,4 "Built target caribou_dump1090"
.PHONY : CMakeFiles/caribou_dump1090.dir/all
# Build rule for subdir invocation for target.
CMakeFiles/caribou_dump1090.dir/rule: cmake_check_build_system
$(CMAKE_COMMAND) -E cmake_progress_start /home/pi/projects/cariboulite/examples/cpp/build/CMakeFiles 3
$(CMAKE_COMMAND) -E cmake_progress_start /home/pi/projects/cariboulite/examples/cpp/build/CMakeFiles 4
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 CMakeFiles/caribou_dump1090.dir/all
$(CMAKE_COMMAND) -E cmake_progress_start /home/pi/projects/cariboulite/examples/cpp/build/CMakeFiles 0
.PHONY : CMakeFiles/caribou_dump1090.dir/rule

Wyświetl plik

@ -55,6 +55,6 @@ unistd.h
-
math.h
-
sys/time.h
time.h
-

Wyświetl plik

@ -5,6 +5,7 @@ set(CMAKE_DEPENDS_LANGUAGES
)
# The set of files for implicit dependencies of each language:
set(CMAKE_DEPENDS_CHECK_C
"/home/pi/projects/cariboulite/examples/cpp/cpr.c" "/home/pi/projects/cariboulite/examples/cpp/build/CMakeFiles/caribou_dump1090.dir/cpr.c.o"
"/home/pi/projects/cariboulite/examples/cpp/modes.c" "/home/pi/projects/cariboulite/examples/cpp/build/CMakeFiles/caribou_dump1090.dir/modes.c.o"
)
set(CMAKE_C_COMPILER_ID "GNU")

Wyświetl plik

@ -102,19 +102,34 @@ CMakeFiles/caribou_dump1090.dir/modes.c.s: cmake_force
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Compiling C source to assembly CMakeFiles/caribou_dump1090.dir/modes.c.s"
/usr/bin/cc $(C_DEFINES) $(C_INCLUDES) $(C_FLAGS) -S /home/pi/projects/cariboulite/examples/cpp/modes.c -o CMakeFiles/caribou_dump1090.dir/modes.c.s
CMakeFiles/caribou_dump1090.dir/cpr.c.o: CMakeFiles/caribou_dump1090.dir/flags.make
CMakeFiles/caribou_dump1090.dir/cpr.c.o: ../cpr.c
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --progress-dir=/home/pi/projects/cariboulite/examples/cpp/build/CMakeFiles --progress-num=$(CMAKE_PROGRESS_3) "Building C object CMakeFiles/caribou_dump1090.dir/cpr.c.o"
/usr/bin/cc $(C_DEFINES) $(C_INCLUDES) $(C_FLAGS) -o CMakeFiles/caribou_dump1090.dir/cpr.c.o -c /home/pi/projects/cariboulite/examples/cpp/cpr.c
CMakeFiles/caribou_dump1090.dir/cpr.c.i: cmake_force
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Preprocessing C source to CMakeFiles/caribou_dump1090.dir/cpr.c.i"
/usr/bin/cc $(C_DEFINES) $(C_INCLUDES) $(C_FLAGS) -E /home/pi/projects/cariboulite/examples/cpp/cpr.c > CMakeFiles/caribou_dump1090.dir/cpr.c.i
CMakeFiles/caribou_dump1090.dir/cpr.c.s: cmake_force
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Compiling C source to assembly CMakeFiles/caribou_dump1090.dir/cpr.c.s"
/usr/bin/cc $(C_DEFINES) $(C_INCLUDES) $(C_FLAGS) -S /home/pi/projects/cariboulite/examples/cpp/cpr.c -o CMakeFiles/caribou_dump1090.dir/cpr.c.s
# Object files for target caribou_dump1090
caribou_dump1090_OBJECTS = \
"CMakeFiles/caribou_dump1090.dir/dump1090.cpp.o" \
"CMakeFiles/caribou_dump1090.dir/modes.c.o"
"CMakeFiles/caribou_dump1090.dir/modes.c.o" \
"CMakeFiles/caribou_dump1090.dir/cpr.c.o"
# External object files for target caribou_dump1090
caribou_dump1090_EXTERNAL_OBJECTS =
caribou_dump1090: CMakeFiles/caribou_dump1090.dir/dump1090.cpp.o
caribou_dump1090: CMakeFiles/caribou_dump1090.dir/modes.c.o
caribou_dump1090: CMakeFiles/caribou_dump1090.dir/cpr.c.o
caribou_dump1090: CMakeFiles/caribou_dump1090.dir/build.make
caribou_dump1090: CMakeFiles/caribou_dump1090.dir/link.txt
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --bold --progress-dir=/home/pi/projects/cariboulite/examples/cpp/build/CMakeFiles --progress-num=$(CMAKE_PROGRESS_3) "Linking CXX executable caribou_dump1090"
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --bold --progress-dir=/home/pi/projects/cariboulite/examples/cpp/build/CMakeFiles --progress-num=$(CMAKE_PROGRESS_4) "Linking CXX executable caribou_dump1090"
$(CMAKE_COMMAND) -E cmake_link_script CMakeFiles/caribou_dump1090.dir/link.txt --verbose=$(VERBOSE)
# Rule to build all files generated by this target.

Wyświetl plik

@ -1,4 +1,5 @@
file(REMOVE_RECURSE
"CMakeFiles/caribou_dump1090.dir/cpr.c.o"
"CMakeFiles/caribou_dump1090.dir/dump1090.cpp.o"
"CMakeFiles/caribou_dump1090.dir/modes.c.o"
"caribou_dump1090"

Wyświetl plik

@ -1,6 +1,9 @@
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.18
CMakeFiles/caribou_dump1090.dir/cpr.c.o
/home/pi/projects/cariboulite/examples/cpp/cpr.c
/home/pi/projects/cariboulite/examples/cpp/cpr.h
CMakeFiles/caribou_dump1090.dir/modes.c.o
/home/pi/projects/cariboulite/examples/cpp/modes.c
/home/pi/projects/cariboulite/examples/cpp/modes.h

Wyświetl plik

@ -1,6 +1,9 @@
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.18
CMakeFiles/caribou_dump1090.dir/cpr.c.o: ../cpr.c
CMakeFiles/caribou_dump1090.dir/cpr.c.o: ../cpr.h
CMakeFiles/caribou_dump1090.dir/modes.c.o: ../modes.c
CMakeFiles/caribou_dump1090.dir/modes.c.o: ../modes.h

Wyświetl plik

@ -1 +1 @@
/usr/bin/c++ -O3 -DNDEBUG CMakeFiles/caribou_dump1090.dir/dump1090.cpp.o CMakeFiles/caribou_dump1090.dir/modes.c.o -o caribou_dump1090 -lSoapySDR -liir_static
/usr/bin/c++ -O3 -DNDEBUG CMakeFiles/caribou_dump1090.dir/dump1090.cpp.o CMakeFiles/caribou_dump1090.dir/modes.c.o CMakeFiles/caribou_dump1090.dir/cpr.c.o -o caribou_dump1090 -lSoapySDR -liir_static

Wyświetl plik

@ -1,4 +1,5 @@
CMAKE_PROGRESS_1 = 1
CMAKE_PROGRESS_2 = 2
CMAKE_PROGRESS_3 = 3
CMAKE_PROGRESS_4 = 4

Wyświetl plik

@ -142,6 +142,33 @@ caribou_dump1090/fast:
$(MAKE) $(MAKESILENT) -f CMakeFiles/caribou_dump1090.dir/build.make CMakeFiles/caribou_dump1090.dir/build
.PHONY : caribou_dump1090/fast
cpr.o: cpr.c.o
.PHONY : cpr.o
# target to build an object file
cpr.c.o:
$(MAKE) $(MAKESILENT) -f CMakeFiles/caribou_dump1090.dir/build.make CMakeFiles/caribou_dump1090.dir/cpr.c.o
.PHONY : cpr.c.o
cpr.i: cpr.c.i
.PHONY : cpr.i
# target to preprocess a source file
cpr.c.i:
$(MAKE) $(MAKESILENT) -f CMakeFiles/caribou_dump1090.dir/build.make CMakeFiles/caribou_dump1090.dir/cpr.c.i
.PHONY : cpr.c.i
cpr.s: cpr.c.s
.PHONY : cpr.s
# target to generate assembly for a file
cpr.c.s:
$(MAKE) $(MAKESILENT) -f CMakeFiles/caribou_dump1090.dir/build.make CMakeFiles/caribou_dump1090.dir/cpr.c.s
.PHONY : cpr.c.s
dump1090.o: dump1090.cpp.o
.PHONY : dump1090.o
@ -205,6 +232,9 @@ help:
@echo "... edit_cache"
@echo "... rebuild_cache"
@echo "... caribou_dump1090"
@echo "... cpr.o"
@echo "... cpr.i"
@echo "... cpr.s"
@echo "... dump1090.o"
@echo "... dump1090.i"
@echo "... dump1090.s"

Plik binarny nie jest wyświetlany.

369
examples/cpp/cpr.c 100644
Wyświetl plik

@ -0,0 +1,369 @@
// Part of dump1090, a Mode S message decoder for RTLSDR devices.
//
// cpr.c - Compact Position Reporting decoder and tests
//
// Copyright (c) 2014,2015 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.
#include "cpr.h"
#include <math.h>
#include <stdio.h>
//
//=========================================================================
//
// Always positive MOD operation, used for CPR decoding.
//
static int cprModInt(int a, int b) {
int res = a % b;
if (res < 0) res += b;
return res;
}
static double cprModDouble(double a, double b) {
double res = fmod(a, b);
if (res < 0) res += b;
return res;
}
//
//=========================================================================
//
// The NL function uses the precomputed table from 1090-WP-9-14
//
static int cprNLFunction(double lat) {
if (lat < 0) lat = -lat; // Table is simmetric about the equator
if (lat < 10.47047130) return 59;
if (lat < 14.82817437) return 58;
if (lat < 18.18626357) return 57;
if (lat < 21.02939493) return 56;
if (lat < 23.54504487) return 55;
if (lat < 25.82924707) return 54;
if (lat < 27.93898710) return 53;
if (lat < 29.91135686) return 52;
if (lat < 31.77209708) return 51;
if (lat < 33.53993436) return 50;
if (lat < 35.22899598) return 49;
if (lat < 36.85025108) return 48;
if (lat < 38.41241892) return 47;
if (lat < 39.92256684) return 46;
if (lat < 41.38651832) return 45;
if (lat < 42.80914012) return 44;
if (lat < 44.19454951) return 43;
if (lat < 45.54626723) return 42;
if (lat < 46.86733252) return 41;
if (lat < 48.16039128) return 40;
if (lat < 49.42776439) return 39;
if (lat < 50.67150166) return 38;
if (lat < 51.89342469) return 37;
if (lat < 53.09516153) return 36;
if (lat < 54.27817472) return 35;
if (lat < 55.44378444) return 34;
if (lat < 56.59318756) return 33;
if (lat < 57.72747354) return 32;
if (lat < 58.84763776) return 31;
if (lat < 59.95459277) return 30;
if (lat < 61.04917774) return 29;
if (lat < 62.13216659) return 28;
if (lat < 63.20427479) return 27;
if (lat < 64.26616523) return 26;
if (lat < 65.31845310) return 25;
if (lat < 66.36171008) return 24;
if (lat < 67.39646774) return 23;
if (lat < 68.42322022) return 22;
if (lat < 69.44242631) return 21;
if (lat < 70.45451075) return 20;
if (lat < 71.45986473) return 19;
if (lat < 72.45884545) return 18;
if (lat < 73.45177442) return 17;
if (lat < 74.43893416) return 16;
if (lat < 75.42056257) return 15;
if (lat < 76.39684391) return 14;
if (lat < 77.36789461) return 13;
if (lat < 78.33374083) return 12;
if (lat < 79.29428225) return 11;
if (lat < 80.24923213) return 10;
if (lat < 81.19801349) return 9;
if (lat < 82.13956981) return 8;
if (lat < 83.07199445) return 7;
if (lat < 83.99173563) return 6;
if (lat < 84.89166191) return 5;
if (lat < 85.75541621) return 4;
if (lat < 86.53536998) return 3;
if (lat < 87.00000000) return 2;
else return 1;
}
//
//=========================================================================
//
static int cprNFunction(double lat, int fflag) {
int nl = cprNLFunction(lat) - (fflag ? 1 : 0);
if (nl < 1) nl = 1;
return nl;
}
//
//=========================================================================
//
static double cprDlonFunction(double lat, int fflag, int surface) {
return (surface ? 90.0 : 360.0) / cprNFunction(lat, fflag);
}
//
//=========================================================================
//
// This algorithm comes from:
// http://www.lll.lu/~edward/edward/adsb/DecodingADSBposition.html.
//
// A few remarks:
// 1) 131072 is 2^17 since CPR latitude and longitude are encoded in 17 bits.
//
int decodeCPRairborne(int even_cprlat, int even_cprlon,
int odd_cprlat, int odd_cprlon,
int fflag,
double *out_lat, double *out_lon)
{
double AirDlat0 = 360.0 / 60.0;
double AirDlat1 = 360.0 / 59.0;
double lat0 = even_cprlat;
double lat1 = odd_cprlat;
double lon0 = even_cprlon;
double lon1 = odd_cprlon;
double rlat, rlon;
// Compute the Latitude Index "j"
int j = (int) floor(((59*lat0 - 60*lat1) / 131072) + 0.5);
double rlat0 = AirDlat0 * (cprModInt(j,60) + lat0 / 131072);
double rlat1 = AirDlat1 * (cprModInt(j,59) + lat1 / 131072);
if (rlat0 >= 270) rlat0 -= 360;
if (rlat1 >= 270) rlat1 -= 360;
// Check to see that the latitude is in range: -90 .. +90
if (rlat0 < -90 || rlat0 > 90 || rlat1 < -90 || rlat1 > 90)
return (-2); // bad data
// Check that both are in the same latitude zone, or abort.
if (cprNLFunction(rlat0) != cprNLFunction(rlat1))
return (-1); // positions crossed a latitude zone, try again later
// Compute ni and the Longitude Index "m"
if (fflag) { // Use odd packet.
int ni = cprNFunction(rlat1,1);
int m = (int) floor((((lon0 * (cprNLFunction(rlat1)-1)) -
(lon1 * cprNLFunction(rlat1))) / 131072.0) + 0.5);
rlon = cprDlonFunction(rlat1, 1, 0) * (cprModInt(m, ni)+lon1/131072);
rlat = rlat1;
} else { // Use even packet.
int ni = cprNFunction(rlat0,0);
int m = (int) floor((((lon0 * (cprNLFunction(rlat0)-1)) -
(lon1 * cprNLFunction(rlat0))) / 131072) + 0.5);
rlon = cprDlonFunction(rlat0, 0, 0) * (cprModInt(m, ni)+lon0/131072);
rlat = rlat0;
}
// Renormalize to -180 .. +180
rlon -= floor( (rlon + 180) / 360 ) * 360;
*out_lat = rlat;
*out_lon = rlon;
return 0;
}
int decodeCPRsurface(double reflat, double reflon,
int even_cprlat, int even_cprlon,
int odd_cprlat, int odd_cprlon,
int fflag,
double *out_lat, double *out_lon)
{
double AirDlat0 = 90.0 / 60.0;
double AirDlat1 = 90.0 / 59.0;
double lat0 = even_cprlat;
double lat1 = odd_cprlat;
double lon0 = even_cprlon;
double lon1 = odd_cprlon;
double rlon, rlat;
// Compute the Latitude Index "j"
int j = (int) floor(((59*lat0 - 60*lat1) / 131072) + 0.5);
double rlat0 = AirDlat0 * (cprModInt(j,60) + lat0 / 131072);
double rlat1 = AirDlat1 * (cprModInt(j,59) + lat1 / 131072);
// Pick the quadrant that's closest to the reference location -
// this is not necessarily the same quadrant that contains the
// reference location.
//
// There are also only two valid quadrants: -90..0 and 0..90;
// no correct message would try to encoding a latitude in the
// ranges -180..-90 and 90..180.
//
// If the computed latitude is more than 45 degrees north of
// the reference latitude (using the northern hemisphere
// solution), then the southern hemisphere solution will be
// closer to the refernce latitude.
//
// e.g. reflat=0, rlat=44, use rlat=44
// reflat=0, rlat=46, use rlat=46-90 = -44
// reflat=40, rlat=84, use rlat=84
// reflat=40, rlat=86, use rlat=86-90 = -4
// reflat=-40, rlat=4, use rlat=4
// reflat=-40, rlat=6, use rlat=6-90 = -84
// As a special case, -90, 0 and +90 all encode to zero, so
// there's a little extra work to do there.
if (rlat0 == 0) {
if (reflat < -45)
rlat0 = -90;
else if (reflat > 45)
rlat0 = 90;
} else if ((rlat0 - reflat) > 45) {
rlat0 -= 90;
}
if (rlat1 == 0) {
if (reflat < -45)
rlat1 = -90;
else if (reflat > 45)
rlat1 = 90;
} else if ((rlat1 - reflat) > 45) {
rlat1 -= 90;
}
// Check to see that the latitude is in range: -90 .. +90
if (rlat0 < -90 || rlat0 > 90 || rlat1 < -90 || rlat1 > 90)
return (-2); // bad data
// Check that both are in the same latitude zone, or abort.
if (cprNLFunction(rlat0) != cprNLFunction(rlat1))
return (-1); // positions crossed a latitude zone, try again later
// Compute ni and the Longitude Index "m"
if (fflag) { // Use odd packet.
int ni = cprNFunction(rlat1,1);
int m = (int) floor((((lon0 * (cprNLFunction(rlat1)-1)) -
(lon1 * cprNLFunction(rlat1))) / 131072.0) + 0.5);
rlon = cprDlonFunction(rlat1, 1, 1) * (cprModInt(m, ni)+lon1/131072);
rlat = rlat1;
} else { // Use even packet.
int ni = cprNFunction(rlat0,0);
int m = (int) floor((((lon0 * (cprNLFunction(rlat0)-1)) -
(lon1 * cprNLFunction(rlat0))) / 131072) + 0.5);
rlon = cprDlonFunction(rlat0, 0, 1) * (cprModInt(m, ni)+lon0/131072);
rlat = rlat0;
}
// Pick the quadrant that's closest to the reference location -
// this is not necessarily the same quadrant that contains the
// reference location. Unlike the latitude case, all four
// quadrants are valid.
// if reflon is more than 45 degrees away, move some multiple of 90 degrees towards it
rlon += floor( (reflon - rlon + 45) / 90 ) * 90; // this might move us outside (-180..+180), we fix this below
// Renormalize to -180 .. +180
rlon -= floor( (rlon + 180) / 360 ) * 360;
*out_lat = rlat;
*out_lon = rlon;
return 0;
}
//
//=========================================================================
//
// This algorithm comes from:
// 1090-WP29-07-Draft_CPR101 (which also defines decodeCPR() )
//
// Despite what the earlier comment here said, we should *not* be using trunc().
// See Figure 5-5 / 5-6 and note that floor is applied to (0.5 + fRP - fEP), not
// directly to (fRP - fEP). Eq 38 is correct.
//
int decodeCPRrelative(double reflat, double reflon,
int cprlat, int cprlon,
int fflag, int surface,
double *out_lat, double *out_lon)
{
double AirDlat;
double AirDlon;
double fractional_lat = cprlat / 131072.0;
double fractional_lon = cprlon / 131072.0;
double rlon, rlat;
int j,m;
AirDlat = (surface ? 90.0 : 360.0) / (fflag ? 59.0 : 60.0);
// Compute the Latitude Index "j"
j = (int) (floor(reflat/AirDlat) +
floor(0.5 + cprModDouble(reflat, AirDlat)/AirDlat - fractional_lat));
rlat = AirDlat * (j + fractional_lat);
if (rlat >= 270) rlat -= 360;
// Check to see that the latitude is in range: -90 .. +90
if (rlat < -90 || rlat > 90) {
return (-1); // Time to give up - Latitude error
}
// Check to see that answer is reasonable - ie no more than 1/2 cell away
if (fabs(rlat - reflat) > (AirDlat/2)) {
return (-1); // Time to give up - Latitude error
}
// Compute the Longitude Index "m"
AirDlon = cprDlonFunction(rlat, fflag, surface);
m = (int) (floor(reflon/AirDlon) +
floor(0.5 + cprModDouble(reflon, AirDlon)/AirDlon - fractional_lon));
rlon = AirDlon * (m + fractional_lon);
if (rlon > 180) rlon -= 360;
// Check to see that answer is reasonable - ie no more than 1/2 cell away
if (fabs(rlon - reflon) > (AirDlon/2))
return (-1); // Time to give up - Longitude error
*out_lat = rlat;
*out_lon = rlon;
return (0);
}

39
examples/cpp/cpr.h 100644
Wyświetl plik

@ -0,0 +1,39 @@
// Part of dump1090, a Mode S message decoder for RTLSDR devices.
//
// cpr.h - Compact Position Reporting prototypes
//
// Copyright (c) 2014,2015 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/>.
#ifndef DUMP1090_CPR_H
#define DUMP1090_CPR_H
int decodeCPRairborne(int even_cprlat, int even_cprlon,
int odd_cprlat, int odd_cprlon,
int fflag,
double *out_lat, double *out_lon);
int decodeCPRsurface(double reflat, double reflon,
int even_cprlat, int even_cprlon,
int odd_cprlat, int odd_cprlon,
int fflag,
double *out_lat, double *out_lon);
int decodeCPRrelative(double reflat, double reflon,
int cprlat, int cprlon,
int fflag, int surface,
double *out_lat, double *out_lon);
#endif

Wyświetl plik

@ -19,9 +19,7 @@
#include "modes.h"
/***********************************************************************
* Print the banner
**********************************************************************/
//=================================================================================
static void printBanner(void)
{
std::cout << "######################################################" << std::endl;
@ -30,86 +28,21 @@ static void printBanner(void)
std::cout << std::endl;
}
/***********************************************************************
* Find devices and print args
**********************************************************************/
static int findDevices(const std::string &argStr)
{
const auto results = SoapySDR::Device::enumerate(argStr);
std::cout << "Found " << results.size() << " devices" << std::endl;
for (size_t i = 0; i < results.size(); i++)
{
std::cout << "Found device " << i << std::endl;
for (const auto &it : results[i])
{
std::cout << " " << it.first << " = " << it.second << std::endl;
}
std::cout << std::endl;
}
if (results.empty()) std::cerr << "No devices found! " << argStr << std::endl;
else std::cout << std::endl;
return results.empty()?EXIT_FAILURE:EXIT_SUCCESS;
}
/***********************************************************************
* Run the stream function
**********************************************************************/
//=================================================================================
static sig_atomic_t loopDone = false;
static void sigIntHandler(const int)
{
loopDone = true;
}
//=================================================================================
void onModeSMessage(mode_s_t *self, struct mode_s_msg *mm)
{
printf("Got message from flight %s\n", mm->flight);
printf(" HEADER: #Bits: %d, Type: %d, CRCOK: %d, ECC: %d, ICAO_ADDR:%02X%02X%02X, PHC: %d, CAP: %08X\n",
mm->msgbits, // Number of bits in message
mm->msgtype, // Downlink format #
mm->crcok, // True if CRC was valid
mm->errorbit, // Bit corrected. -1 if no bit corrected.
mm->aa1, mm->aa2, mm->aa3, // ICAO Address bytes 1 2 and 3
mm->phase_corrected, // True if phase correction was applied.
mm->ca); // Responder capabilities.
printf(" DATA1: MsgTp: %d, MsgSTp: %d, HdVld: %d, Hd: %d, AirCftTp:%d, FFlg: %d, UtcSync: %d, Lat: %d, Lon: %d, Dir W/S: %d/%d\n"
" DATA2: Vel (W/S): %d/%d, Vel: %d, VertRt (Src/Sgn/Rt): %d/%d/%d, Alt: %d, Stat: %d, Id: %08X, Unt: %d\n\n",
mm->metype, // Extended squitter message type.
mm->mesub, // Extended squitter message subtype.
mm->heading_is_valid, // heading_is_valid
mm->heading, // heading
mm->aircraft_type, // aircraft_type
mm->fflag, // 1 = Odd, 0 = Even CPR message.
mm->tflag, // UTC synchronized?
mm->raw_latitude, // Non decoded latitude
mm->raw_longitude, // Non decoded raw_longitude
mm->ew_dir, // 0 = East, 1 = West.
mm->ns_dir, // 0 = North, 1 = South.
mm->ew_velocity, // E/W velocity.
mm->ns_velocity, // N/S velocity.
mm->velocity,
mm->vert_rate_source, // Vertical rate source.
mm->vert_rate_sign, // Vertical rate sign.
mm->vert_rate, // // Vertical rate.
mm->altitude,
mm->fs, // Flight status for DF4,5,20,21
mm->identity, // 13 bits identity (Squawk).
mm->unit);
}
#define FILT_ORDER 6
Iir::Butterworth::LowPass<FILT_ORDER> filt;
void makeFilter(double fs, double cutoff)
{
try {filt.setup(fs, cutoff);}
catch (...) {printf("Filter Setup Exception!\n");}
mode_s_display_message(mm);
printf("\n");
}
//=================================================================================
// Turn I/Q samples pointed by `data` into the magnitude vector pointed by `mag`
void MagnitudeVectorDownSample(short *data, uint16_t *mag, uint32_t size)
{
@ -126,50 +59,50 @@ void MagnitudeVectorDownSample(short *data, uint16_t *mag, uint32_t size)
}
}
void runSoapyProcess(
SoapySDR::Device *device,
SoapySDR::Stream *stream,
const int direction,
const size_t numChans,
const size_t elemSize)
//=================================================================================
void runSoapyProcess( SoapySDR::Device *device,
SoapySDR::Stream *stream,
const size_t elemSize)
{
//allocate buffers for the stream read/write
// allocate buffers for the stream read/write
const size_t numElems = device->getStreamMTU(stream);
int16_t* buff = (int16_t*)malloc (2*sizeof(int16_t)*numElems); // complex 16 bit samples
int16_t* buff = (int16_t*)malloc(2*sizeof(int16_t)*numElems); // complex 16 bit samples
uint16_t* mag = (uint16_t*)malloc(sizeof(uint16_t)*numElems);
// MODE-S Stuff
// MODE-S
mode_s_t state;
mode_s_init(&state);
makeFilter(4e6, 50e3);
std::cout << "Starting stream loop, press Ctrl+C to exit..." << std::endl;
device->activateStream(stream);
signal(SIGINT, sigIntHandler);
// Main Processing Loop
while (not loopDone)
{
int ret = 0;
int flags = 0;
long long timeUS = numElems;
ret = device->readStream(stream, (void* const*)&buff, numElems, flags, timeUS);
if (ret == SOAPY_SDR_TIMEOUT) continue;
if (ret == SOAPY_SDR_OVERFLOW)
{
//overflows++;
continue;
}
if (ret == SOAPY_SDR_UNDERFLOW)
{
//underflows++;
continue;
}
if (ret < 0)
int flags = 0;
int ret = device->readStream(stream, (void* const*)&buff, numElems, flags, timeUS);
if (ret < 0)
{
std::cerr << "Unexpected stream error " << ret << std::endl;
break;
}
switch (ret)
{
case SOAPY_SDR_TIMEOUT: continue;
case SOAPY_SDR_OVERFLOW:
//overflows++;
continue;
case SOAPY_SDR_UNDERFLOW:
//underflows++;
continue;
default:
break;
}
// All is good - proceed to DSP
// compute the magnitude of the signal
MagnitudeVectorDownSample(buff, mag, ret);
@ -178,6 +111,10 @@ void runSoapyProcess(
}
device->deactivateStream(stream);
// free memory
free(buff);
free(mag);
}
@ -187,40 +124,37 @@ void runSoapyProcess(
int main(int argc, char *argv[])
{
SoapySDR::ModuleManager mm(false);
SoapySDR::Device *device(nullptr);
std::vector<size_t> channels;
std::string argStr = "driver=Cariboulite,channel=HiF";
double fullScale = 0.0;
double freq = 1090.0e6;
//double freq = 1090e6;
printBanner();
try
{
device = SoapySDR::Device::make(argStr);
channels.push_back(0);
// set the sample rate
device->setSampleRate(SOAPY_SDR_RX, channels[0], 4e6);
device->setBandwidth(SOAPY_SDR_RX, channels[0], 2500e5);
device->setGainMode(SOAPY_SDR_RX, channels[0], false);
device->setGain(SOAPY_SDR_RX, channels[0], 50);
device->setFrequency(SOAPY_SDR_RX, channels[0], freq);
// set the sample rate, frequency, ...
device->setSampleRate(SOAPY_SDR_RX, 0, 4e6);
device->setBandwidth(SOAPY_SDR_RX, 0, 100e5);
device->setGainMode(SOAPY_SDR_RX, 0, false);
device->setGain(SOAPY_SDR_RX, 0, 50);
device->setFrequency(SOAPY_SDR_RX, 0, 1090e6);
//create the stream, use the native format
const auto format = device->getNativeStreamFormat(SOAPY_SDR_RX, channels.front(), fullScale);
// create the stream, use the native format
const auto format = device->getNativeStreamFormat(SOAPY_SDR_RX, 0, fullScale);
const size_t elemSize = SoapySDR::formatToSize(format);
auto stream = device->setupStream(SOAPY_SDR_RX, format, channels);
//run the rate test one setup is complete
std::cout << "Stream format: " << format << std::endl;
std::cout << "Num channels: " << channels.size() << std::endl;
std::cout << "Element size: " << elemSize << " bytes" << std::endl;
runSoapyProcess(device, stream, SOAPY_SDR_RX, channels.size(), elemSize);
// run the rate test one setup is complete
std::cout << "Running Soapy process with CaribouLite Config:" << std::endl;
std::cout << " Stream format: " << format << std::endl;
std::cout << " Channel: HiF" << std::endl;
std::cout << " Sample size: " << elemSize << " bytes" << std::endl;
runSoapyProcess(device, stream, elemSize);
//cleanup stream and device
// cleanup stream and device
device->closeStream(stream);
SoapySDR::Device::unmake(device);
}
@ -232,6 +166,5 @@ int main(int argc, char *argv[])
}
std::cout << std::endl;
return 0;
}

Plik diff jest za duży Load Diff

Wyświetl plik

@ -1,4 +1,5 @@
/*
* Modified source file by David Michaeli @ CaribouLabs Ltd. Apr. 2022
* Source of file: https://github.com/watson/libmodes
* Author: Thomas Watson (@watson)
* Contact: w@tson.dk / https://twitter.com/wa7son
@ -16,7 +17,7 @@ extern "C" {
#include <stdint.h>
#include <unistd.h>
#include <math.h>
#include <sys/time.h>
#include <time.h>
#define MODE_S_ICAO_CACHE_LEN 1024 // Power of two required
#define MODE_S_LONG_MSG_BYTES (112/8)
@ -26,8 +27,8 @@ extern "C" {
// Program state
typedef struct
{
// Internal state
uint32_t icao_cache[sizeof(uint32_t)*MODE_S_ICAO_CACHE_LEN*2]; // Recently seen ICAO addresses cache
// Internal state - recently seen ICAO addresses cache
uint32_t icao_cache[sizeof(uint32_t)*MODE_S_ICAO_CACHE_LEN*2];
// Configuration
int fix_errors; // Single bit error correction if true
@ -38,7 +39,7 @@ typedef struct
// The struct we use to store information about a decoded message
struct mode_s_msg
{
// Generic fields
// ------ Generic fields ------------
unsigned char msg[MODE_S_LONG_MSG_BYTES]; // Binary message
int msgbits; // Number of bits in message
int msgtype; // Downlink format #
@ -48,10 +49,10 @@ struct mode_s_msg
int aa1, aa2, aa3; // ICAO Address bytes 1 2 and 3
int phase_corrected; // True if phase correction was applied.
// DF 11
// ------ DF 11 ---------------------
int ca; // Responder capabilities.
// DF 17
// ------ DF 17 ---------------------
int metype; // Extended squitter message type.
int mesub; // Extended squitter message subtype.
int heading_is_valid;
@ -71,7 +72,7 @@ struct mode_s_msg
int vert_rate; // Vertical rate.
int velocity; // Computed from EW and NS velocity.
// DF4, DF5, DF20, DF21
// ------ DF4, DF5, DF20, DF21 -------
int fs; // Flight status for DF4,5,20,21
int dr; // Request extraction of downlink request.
int um; // Request extraction of downlink request.
@ -86,6 +87,7 @@ typedef void (*mode_s_callback_t)(mode_s_t *self, struct mode_s_msg *mm);
void mode_s_init(mode_s_t *self);
void mode_s_detect(mode_s_t *self, uint16_t *mag, uint32_t maglen, mode_s_callback_t);
void mode_s_decode(mode_s_t *self, struct mode_s_msg *mm, unsigned char *msg);
void mode_s_display_message(struct mode_s_msg *mm);
#ifdef __cplusplus
}