View1090 WinXP bugfix
Updated the way socket handles are used in View1090 to maintain compatibility between UNIX and Windows. Added the initial attempt at a Planeplotter uploader
This commit is contained in:
parent
a968f03c3a
commit
5b5424df3b
7
Makefile
7
Makefile
|
@ -15,7 +15,7 @@ LIBS=`pkg-config --libs librtlsdr` -lpthread -lm
|
|||
CC=gcc
|
||||
|
||||
|
||||
all: dump1090 view1090
|
||||
all: dump1090 view1090 ppup1090
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) $(EXTRACFLAGS) -c $<
|
||||
|
@ -26,5 +26,8 @@ dump1090: dump1090.o anet.o interactive.o mode_ac.o mode_s.o net_io.o
|
|||
view1090: view1090.o anet.o interactive.o mode_ac.o mode_s.o net_io.o
|
||||
$(CC) -g -o view1090 view1090.o anet.o interactive.o mode_ac.o mode_s.o net_io.o $(LIBS)
|
||||
|
||||
ppup1090: ppup1090.o anet.o interactive.o mode_ac.o mode_s.o net_io.o
|
||||
$(CC) -g -o ppup1090 ppup1090.o anet.o interactive.o mode_ac.o mode_s.o net_io.o coaa1090.obj $(LIBS)
|
||||
|
||||
clean:
|
||||
rm -f *.o dump1090 view1090
|
||||
rm -f *.o dump1090 view1090 ppup1090
|
||||
|
|
Binary file not shown.
6
coaa.h
Normal file
6
coaa.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
// coaa.h configuration file for Plane Plotter Uploader
|
||||
//
|
||||
// You MUST apply via the COAA website for your own personal version of this file
|
||||
// Do not disclose the contents of this file to anyone thereafter as it uniquely
|
||||
// identifies you to the PlanePlotter system
|
||||
//
|
BIN
coaa1090.obj
Normal file
BIN
coaa1090.obj
Normal file
Binary file not shown.
|
@ -37,7 +37,7 @@
|
|||
// MinorVer changes when additional features are added, but not for bug fixes (range 00-99)
|
||||
// DayDate & Year changes for all changes, including for bug fixes. It represent the release date of the update
|
||||
//
|
||||
#define MODES_DUMP1090_VERSION "1.07.2609.13"
|
||||
#define MODES_DUMP1090_VERSION "1.07.2709.13"
|
||||
|
||||
// ============================= Include files ==========================
|
||||
|
||||
|
|
|
@ -41,40 +41,6 @@ static uint64_t mstime(void) {
|
|||
mst += tv.tv_usec/1000;
|
||||
return mst;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
// Standard error macro for reporting API errors
|
||||
#define PERR(bSuccess, api){if(!(bSuccess)) printf("%s:Error %d from %s on line %d\n", __FILE__, GetLastError(), api, __LINE__);}
|
||||
|
||||
void cls( HANDLE hConsole ) {
|
||||
COORD coordScreen = { 0, 0 }; // here's where we'll home the cursor
|
||||
BOOL bSuccess;
|
||||
DWORD cCharsWritten;
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi; // to get buffer info
|
||||
DWORD dwConSize; // number of character cells in the current buffer
|
||||
|
||||
// get the number of character cells in the current buffer
|
||||
bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
|
||||
PERR( bSuccess, "GetConsoleScreenBufferInfo" );
|
||||
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
|
||||
|
||||
// fill the entire screen with blanks
|
||||
bSuccess = FillConsoleOutputCharacter( hConsole, (TCHAR) ' ', dwConSize, coordScreen, &cCharsWritten );
|
||||
PERR( bSuccess, "FillConsoleOutputCharacter" );
|
||||
|
||||
// get the current text attribute
|
||||
bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
|
||||
PERR( bSuccess, "ConsoleScreenBufferInfo" );
|
||||
|
||||
// now set the buffer's attributes accordingly
|
||||
bSuccess = FillConsoleOutputAttribute( hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten );
|
||||
PERR( bSuccess, "FillConsoleOutputAttribute" );
|
||||
|
||||
// put the cursor at (0, 0)
|
||||
bSuccess = SetConsoleCursorPosition( hConsole, coordScreen );
|
||||
PERR( bSuccess, "SetConsoleCursorPosition" );
|
||||
}
|
||||
#endif
|
||||
//
|
||||
//========================= Interactive mode ===============================
|
||||
//
|
||||
|
@ -376,7 +342,7 @@ void interactiveShowData(void) {
|
|||
#ifndef _WIN32
|
||||
printf("\x1b[H\x1b[2J"); // Clear the screen
|
||||
#else
|
||||
cls(GetStdHandle(STD_OUTPUT_HANDLE));
|
||||
cls();
|
||||
#endif
|
||||
|
||||
if (Modes.interactive_rtl1090 == 0) {
|
||||
|
|
9
mode_s.c
9
mode_s.c
|
@ -1816,13 +1816,8 @@ void detectModeS(uint16_t *m, uint32_t mlen) {
|
|||
void useModesMessage(struct modesMessage *mm) {
|
||||
if ((Modes.check_crc == 0) || (mm->crcok) || (mm->correctedbits)) { // not checking, ok or fixed
|
||||
|
||||
// Track aircrafts if...
|
||||
if ( (Modes.interactive) // in interactive mode
|
||||
|| (Modes.stat_http_requests) // or if the HTTP interface is enabled
|
||||
|| (Modes.stat_sbs_connections) // or if sbs connections are established
|
||||
|| (Modes.mode_ac) ) { // or if mode A/C decoding is enabled
|
||||
interactiveReceiveData(mm);
|
||||
}
|
||||
// Always track aircraft
|
||||
interactiveReceiveData(mm);
|
||||
|
||||
// In non-interactive non-quiet mode, display messages on standard output
|
||||
if (!Modes.interactive && !Modes.quiet) {
|
||||
|
|
214
ppup1090.c
Normal file
214
ppup1090.c
Normal file
|
@ -0,0 +1,214 @@
|
|||
// ppup1090, a Mode S PlanePlotter Uploader for dump1090 devices.
|
||||
//
|
||||
// Copyright (C) 2013 by Malcolm Robb <Support@ATTAvionics.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 "coaa.h"
|
||||
#include "ppup1090.h"
|
||||
//
|
||||
// ============================= Utility functions ==========================
|
||||
//
|
||||
void sigintHandler(int dummy) {
|
||||
NOTUSED(dummy);
|
||||
signal(SIGINT, SIG_DFL); // reset signal handler - bit extra safety
|
||||
Modes.exit = 1; // Signal to threads that we are done
|
||||
}
|
||||
//
|
||||
// =============================== Initialization ===========================
|
||||
//
|
||||
void ppup1090InitConfig(void) {
|
||||
|
||||
int iErr;
|
||||
|
||||
// Default everything to zero/NULL
|
||||
memset(&Modes, 0, sizeof(Modes));
|
||||
memset(&ppup1090, 0, sizeof(ppup1090));
|
||||
|
||||
// Now initialise things that should not be 0/NULL to their defaults
|
||||
Modes.check_crc = 1;
|
||||
Modes.quiet = 1;
|
||||
strcpy(ppup1090.net_input_beast_ipaddr,PPUP1090_NET_OUTPUT_IP_ADDRESS);
|
||||
Modes.net_input_beast_port = MODES_NET_OUTPUT_BEAST_PORT;
|
||||
Modes.interactive_delete_ttl = MODES_INTERACTIVE_DELETE_TTL;
|
||||
Modes.interactive_display_ttl = MODES_INTERACTIVE_DISPLAY_TTL;
|
||||
Modes.fUserLat = MODES_USER_LATITUDE_DFLT;
|
||||
Modes.fUserLon = MODES_USER_LONGITUDE_DFLT;
|
||||
|
||||
if ((iErr = openCOAA()))
|
||||
{
|
||||
fprintf(stderr, "Error 0x%X initialising uploader\n", iErr);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
//
|
||||
//=========================================================================
|
||||
//
|
||||
void ppup1090Init(void) {
|
||||
|
||||
int iErr;
|
||||
|
||||
// Allocate the various buffers used by Modes
|
||||
if ( NULL == (Modes.icao_cache = (uint32_t *) malloc(sizeof(uint32_t) * MODES_ICAO_CACHE_LEN * 2)))
|
||||
{
|
||||
fprintf(stderr, "Out of memory allocating data buffer.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Clear the buffers that have just been allocated, just in-case
|
||||
memset(Modes.icao_cache, 0, sizeof(uint32_t) * MODES_ICAO_CACHE_LEN * 2);
|
||||
|
||||
// Validate the users Lat/Lon home location inputs
|
||||
if ( (Modes.fUserLat > 90.0) // Latitude must be -90 to +90
|
||||
|| (Modes.fUserLat < -90.0) // and
|
||||
|| (Modes.fUserLon > 360.0) // Longitude must be -180 to +360
|
||||
|| (Modes.fUserLon < -180.0) ) {
|
||||
Modes.fUserLat = Modes.fUserLon = 0.0;
|
||||
} else if (Modes.fUserLon > 180.0) { // If Longitude is +180 to +360, make it -180 to 0
|
||||
Modes.fUserLon -= 360.0;
|
||||
}
|
||||
// If both Lat and Lon are 0.0 then the users location is either invalid/not-set, or (s)he's in the
|
||||
// Atlantic ocean off the west coast of Africa. This is unlikely to be correct.
|
||||
// Set the user LatLon valid flag only if either Lat or Lon are non zero. Note the Greenwich meridian
|
||||
// is at 0.0 Lon,so we must check for either fLat or fLon being non zero not both.
|
||||
// Testing the flag at runtime will be much quicker than ((fLon != 0.0) || (fLat != 0.0))
|
||||
Modes.bUserFlags &= ~MODES_USER_LATLON_VALID;
|
||||
if ((Modes.fUserLat != 0.0) || (Modes.fUserLon != 0.0)) {
|
||||
Modes.bUserFlags |= MODES_USER_LATLON_VALID;
|
||||
}
|
||||
|
||||
// Prepare error correction tables
|
||||
modesInitErrorInfo();
|
||||
|
||||
// Setup the uploader - read the user paramaters from the coaa.h header file
|
||||
coaa1090.fUserLat = USER_LATITUDE;
|
||||
coaa1090.fUserLon = USER_LONGITUDE;
|
||||
strcpy(coaa1090.strAuthCode,STR(USER_AUTHCODE));
|
||||
strcpy(coaa1090.strRegNo, STR(USER_REGNO));
|
||||
|
||||
if ((iErr = initCOAA (coaa1090)))
|
||||
{
|
||||
fprintf(stderr, "Error 0x%X initialising uploader\n", iErr);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
//
|
||||
// ================================ Main ====================================
|
||||
//
|
||||
void showHelp(void) {
|
||||
printf(
|
||||
"-----------------------------------------------------------------------------\n"
|
||||
"| ppup1090 dump1090 Uploader Ver : "MODES_DUMP1090_VERSION " |\n"
|
||||
"-----------------------------------------------------------------------------\n"
|
||||
"--net-bo-ipaddr <IPv4> TCP Beast output listen IPv4 (default: 127.0.0.1)\n"
|
||||
"--net-bo-port <port> TCP Beast output listen port (default: 30005)\n"
|
||||
"--quiet Disable output to stdout. Use for daemon applications\n"
|
||||
"--help Show this help\n"
|
||||
);
|
||||
}
|
||||
//
|
||||
//=========================================================================
|
||||
//
|
||||
int main(int argc, char **argv) {
|
||||
int j, fd;
|
||||
struct client *c;
|
||||
|
||||
// Set sane defaults
|
||||
|
||||
ppup1090InitConfig();
|
||||
signal(SIGINT, sigintHandler); // Define Ctrl/C handler (exit program)
|
||||
|
||||
// Parse the command line options
|
||||
for (j = 1; j < argc; j++) {
|
||||
int more = ((j + 1) < argc); // There are more arguments
|
||||
|
||||
if (!strcmp(argv[j],"--net-bo-port") && more) {
|
||||
Modes.net_input_beast_port = atoi(argv[++j]);
|
||||
} else if (!strcmp(argv[j],"--net-bo-ipaddr") && more) {
|
||||
strcpy(ppup1090.net_input_beast_ipaddr, argv[++j]);
|
||||
} else if (!strcmp(argv[j],"--quiet")) {
|
||||
ppup1090.quiet = 1;
|
||||
} else if (!strcmp(argv[j],"--help")) {
|
||||
showHelp();
|
||||
exit(0);
|
||||
} else {
|
||||
fprintf(stderr, "Unknown or not enough arguments for option '%s'.\n\n", argv[j]);
|
||||
showHelp();
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Initialization
|
||||
ppup1090Init();
|
||||
|
||||
// Try to connect to the selected ip address and port. We only support *ONE* input connection which we initiate.here.
|
||||
if ((fd = anetTcpConnect(Modes.aneterr, ppup1090.net_input_beast_ipaddr, Modes.net_input_beast_port)) == ANET_ERR) {
|
||||
fprintf(stderr, "Failed to connect to %s:%d\n", ppup1090.net_input_beast_ipaddr, Modes.net_input_beast_port);
|
||||
exit(1);
|
||||
}
|
||||
//
|
||||
// Setup a service callback client structure for a beast binary input (from dump1090)
|
||||
// This is a bit dodgy under Windows. The fd parameter is a handle to the internet
|
||||
// socket on which we are receiving data. Under Linux, these seem to start at 0 and
|
||||
// count upwards. However, Windows uses "HANDLES" and these don't nececeriy start at 0.
|
||||
// dump1090 limits fd to values less than 1024, and then uses the fd parameter to
|
||||
// index into an array of clients. This is ok-ish if handles are allocated up from 0.
|
||||
// However, there is no gaurantee that Windows will behave like this, and if Windows
|
||||
// allocates a handle greater than 1024, then dump1090 won't like it. On my test machine,
|
||||
// the first Windows handle is usually in the 0x54 (84 decimal) region.
|
||||
|
||||
if (fd >= MODES_NET_MAX_FD) { // Max number of clients reached
|
||||
close(fd);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
c = (struct client *) malloc(sizeof(*c));
|
||||
c->buflen = 0;
|
||||
c->fd =
|
||||
c->service =
|
||||
Modes.bis = fd;
|
||||
Modes.clients[fd] = c;
|
||||
if (Modes.maxfd < fd) {
|
||||
Modes.maxfd = fd;
|
||||
}
|
||||
|
||||
// Keep going till the user does something that stops us
|
||||
while (!Modes.exit) {
|
||||
modesReadFromClient(c,"",decodeBinMessage);
|
||||
interactiveRemoveStaleAircrafts();
|
||||
postCOAA ();
|
||||
}
|
||||
|
||||
// The user has stopped us, so close any socket we opened
|
||||
if (fd != ANET_ERR)
|
||||
{close(fd);}
|
||||
|
||||
closeCOAA ();
|
||||
pthread_exit(0);
|
||||
}
|
||||
//
|
||||
//=========================================================================
|
||||
//
|
104
ppup1090.h
Normal file
104
ppup1090.h
Normal file
|
@ -0,0 +1,104 @@
|
|||
// ppup1090, a Mode S PlanePlotter Uploader for dump1090 devices.
|
||||
//
|
||||
// Copyright (C) 2013 by Malcolm Robb <Support@ATTAvionics.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 __PPUP1090_H
|
||||
#define __PPUP1090_H
|
||||
|
||||
// ============================= Include files ==========================
|
||||
|
||||
#include "dump1090.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
#include <stdint.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <math.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/timeb.h>
|
||||
#include <signal.h>
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/stat.h>
|
||||
#include "rtl-sdr.h"
|
||||
#include "anet.h"
|
||||
#include <netdb.h>
|
||||
#else
|
||||
#include "winstubs.h" //Put everything Windows specific in here
|
||||
#endif
|
||||
|
||||
// ============================= #defines ===============================
|
||||
|
||||
#define PPUP1090_NET_OUTPUT_IP_ADDRESS "127.0.0.1"
|
||||
|
||||
#define NOTUSED(V) ((void) V)
|
||||
|
||||
#define STR_HELPER(x) #x
|
||||
#define STR(x) STR_HELPER(x)
|
||||
|
||||
// ======================== structure declarations ========================
|
||||
|
||||
// Program global state
|
||||
struct { // Internal state
|
||||
int quiet;
|
||||
// Networking
|
||||
char net_input_beast_ipaddr[32]; // IPv4 address or network name of server/RPi
|
||||
} ppup1090;
|
||||
|
||||
|
||||
// COAA Initialisation structure
|
||||
struct _coaa1090 {
|
||||
double fUserLat;
|
||||
double fUserLon;
|
||||
char strAuthCode[16];
|
||||
char strRegNo[16];
|
||||
} coaa1090;
|
||||
|
||||
// ======================== function declarations =========================
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//
|
||||
// Functions exported from coaa1090.c
|
||||
//
|
||||
int openCOAA (void);
|
||||
int closeCOAA (void);
|
||||
int initCOAA (struct _coaa1090 coaa1090);
|
||||
void postCOAA (void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __PPUP1090_H
|
Loading…
Reference in a new issue