2020-03-08 02:22:20 +01:00
|
|
|
#include "AircraftData.h"
|
|
|
|
|
|
|
|
//
|
|
|
|
//carried over from view1090.c
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
int AircraftData::setupConnection(struct client *c) {
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
// Try to connect to the selected ip address and port. We only support *ONE* input connection which we initiate.here.
|
2020-03-11 00:56:59 +01:00
|
|
|
if ((fd = anetTcpConnect(modes.aneterr, server, modes.net_input_beast_port)) != ANET_ERR) {
|
2020-03-08 02:22:20 +01:00
|
|
|
anetNonBlock(modes.aneterr, fd);
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
c->next = NULL;
|
|
|
|
c->buflen = 0;
|
|
|
|
c->fd =
|
|
|
|
c->service =
|
|
|
|
modes.bis = fd;
|
|
|
|
modes.clients = c;
|
|
|
|
}
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// end view1090.c
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
void AircraftData::initialize() {
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
// Prepare error correction tables
|
|
|
|
modesInitErrorInfo(&(modes));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AircraftData::connect() {
|
|
|
|
// Try to connect to the selected ip address and port. We only support *ONE* input connection which we initiate.here.
|
|
|
|
c = (struct client *) malloc(sizeof(*c));
|
|
|
|
while(1) {
|
|
|
|
if ((fd = setupConnection(c)) == ANET_ERR) {
|
2020-03-11 00:56:59 +01:00
|
|
|
fprintf(stderr, "Waiting on %s:%d\n", server, modes.net_input_beast_port);
|
2020-03-08 02:22:20 +01:00
|
|
|
sleep(1);
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AircraftData::disconnect() {
|
|
|
|
if (fd != ANET_ERR)
|
|
|
|
{close(fd);}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AircraftData::update() {
|
|
|
|
if ((fd == ANET_ERR) || (recv(c->fd, pk_buf, sizeof(pk_buf), MSG_PEEK | MSG_DONTWAIT) == 0)) {
|
|
|
|
free(c);
|
|
|
|
usleep(1000000);
|
|
|
|
c = (struct client *) malloc(sizeof(*c));
|
|
|
|
fd = setupConnection(c);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
modesReadFromClient(&modes, c,"",decodeBinMessage);
|
|
|
|
|
|
|
|
interactiveRemoveStaleAircrafts(&modes);
|
|
|
|
|
2020-03-08 05:28:55 +01:00
|
|
|
aircraftList.update(&modes);
|
2020-03-08 02:22:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
AircraftData::AircraftData(){
|
|
|
|
// Default everything to zero/NULL
|
|
|
|
memset(&modes, 0, sizeof(Modes));
|
|
|
|
|
|
|
|
// Now initialise things that should not be 0/NULL to their defaults
|
|
|
|
modes.check_crc = 1;
|
2020-03-11 00:56:59 +01:00
|
|
|
strcpy(server,VIEW1090_NET_OUTPUT_IP_ADDRESS);
|
2020-03-08 02:22:20 +01:00
|
|
|
modes.net_input_beast_port = MODES_NET_OUTPUT_BEAST_PORT;
|
|
|
|
modes.interactive_rows = MODES_INTERACTIVE_ROWS;
|
|
|
|
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;
|
|
|
|
|
|
|
|
modes.interactive = 0;
|
|
|
|
modes.quiet = 1;
|
|
|
|
|
|
|
|
// Map options
|
|
|
|
appData.maxDist = 25.0;
|
|
|
|
appData.centerLon = modes.fUserLon;
|
|
|
|
appData.centerLat = modes.fUserLat;
|
|
|
|
|
|
|
|
// Display options
|
|
|
|
appData.screen_uiscale = 1;
|
|
|
|
appData.screen_width = 0;
|
|
|
|
appData.screen_height = 0;
|
|
|
|
appData.screen_depth = 32;
|
|
|
|
appData.fullscreen = 0;
|
2020-03-12 20:46:26 +01:00
|
|
|
appData.screen_index = 0;
|
2020-03-08 02:22:20 +01:00
|
|
|
|
|
|
|
// Initialize status
|
|
|
|
Status.msgRate = 0;
|
|
|
|
Status.avgSig = 0;
|
|
|
|
Status.numPlanes = 0;
|
|
|
|
Status.numVisiblePlanes = 0;
|
|
|
|
Status.maxDist = 0;
|
|
|
|
|
|
|
|
selectedAircraft = NULL;
|
|
|
|
}
|
|
|
|
|