2015-01-20 17:49:01 +01:00
// Part of dump1090, a Mode S message decoder for RTLSDR devices.
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
//
2015-01-20 17:49:01 +01:00
// net_io.c: network handling.
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
//
2016-08-27 15:34:14 +02:00
// Copyright (c) 2014-2016 Oliver Jowett <oliver@mutability.co.uk>
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
//
2017-06-15 19:16:51 +02:00
// This file is free software: you may copy, redistribute and/or modify it
2015-01-20 17:49:01 +01:00
// under the terms of the GNU General Public License as published by the
2017-06-15 19:16:51 +02:00
// Free Software Foundation, either version 2 of the License, or (at your
// option) any later version.
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
//
2017-06-15 19:16:51 +02:00
// 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
2015-01-20 17:49:01 +01:00
// General Public License for more details.
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
//
2017-06-15 19:16:51 +02:00
// You should have received a copy of the GNU General Public License
2015-01-20 17:49:01 +01:00
// along with this program. If not, see <http://www.gnu.org/licenses/>.
2017-06-15 19:16:51 +02:00
// This file incorporates work covered by the following copyright and
2015-01-20 17:49:01 +01:00
// 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.
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
//
2015-01-20 17:49:01 +01:00
// * 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.
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
//
2015-01-20 17:49:01 +01:00
// 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.
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
# include "dump1090.h"
2015-01-20 18:16:35 +01:00
2015-04-18 12:20:16 +02:00
/* for PRIX64 */
2015-04-18 12:05:12 +02:00
# include <inttypes.h>
2015-01-20 18:16:35 +01:00
# include <assert.h>
2017-12-02 18:38:33 +01:00
# include <stdarg.h>
2015-01-20 18:16:35 +01:00
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
//
// ============================= Networking =============================
//
// Note: here we disregard any kind of good coding practice in favor of
// extreme simplicity, that is:
//
// 1) We only rely on the kernel buffers for our I/O without any kind of
// user space buffering.
// 2) We don't register any kind of event handler, from time to time a
// function gets called and we accept new connections. All the rest is
// handled via non-blocking I/O and manually polling clients to see if
// they have something new to share with us when reading is needed.
2015-06-26 18:50:51 +02:00
2016-12-29 18:55:56 +01:00
static int handleBeastCommand ( struct client * c , char * p ) ;
2015-06-26 18:50:51 +02:00
static int decodeBinMessage ( struct client * c , char * p ) ;
static int decodeHexMessage ( struct client * c , char * hex ) ;
2015-06-29 11:06:13 +02:00
static void send_raw_heartbeat ( struct net_service * service ) ;
static void send_beast_heartbeat ( struct net_service * service ) ;
static void send_sbs_heartbeat ( struct net_service * service ) ;
2016-08-28 02:29:37 +02:00
static void writeFATSVEvent ( struct modesMessage * mm , struct aircraft * a ) ;
2016-12-27 20:07:10 +01:00
static void writeFATSVPositionUpdate ( float lat , float lon , float alt ) ;
2016-08-28 02:29:37 +02:00
2016-12-29 18:56:32 +01:00
static void autoset_modeac ( ) ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
//
//=========================================================================
//
// Networking "stack" initialization
//
2014-06-25 05:58:46 +02:00
2015-06-26 18:50:51 +02:00
// Init a service with the given read/write characteristics, return the new service.
// Doesn't arrange for the service to listen or connect
2016-12-29 18:54:53 +01:00
struct net_service * serviceInit ( const char * descr , struct net_writer * writer , heartbeat_fn hb , read_mode_t mode , const char * sep , read_fn handler )
2015-06-26 18:50:51 +02:00
{
struct net_service * service ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
2015-06-26 18:50:51 +02:00
if ( ! ( service = calloc ( sizeof ( * service ) , 1 ) ) ) {
fprintf ( stderr , " Out of memory allocating service %s \n " , descr ) ;
exit ( 1 ) ;
}
2014-06-25 05:58:46 +02:00
2015-06-26 18:50:51 +02:00
service - > next = Modes . services ;
Modes . services = service ;
2014-06-25 05:58:46 +02:00
2015-06-26 18:50:51 +02:00
service - > descr = descr ;
2016-01-24 19:45:35 +01:00
service - > listener_count = 0 ;
2015-06-26 18:50:51 +02:00
service - > connections = 0 ;
service - > writer = writer ;
service - > read_sep = sep ;
2016-12-29 18:54:53 +01:00
service - > read_mode = mode ;
2015-06-26 18:50:51 +02:00
service - > read_handler = handler ;
2014-04-25 15:48:14 +02:00
2015-06-26 18:50:51 +02:00
if ( service - > writer ) {
if ( ! ( service - > writer - > data = malloc ( MODES_OUT_BUF_SIZE ) ) ) {
fprintf ( stderr , " Out of memory allocating output buffer for service %s \n " , descr ) ;
exit ( 1 ) ;
2014-04-25 15:48:14 +02:00
}
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
2015-06-26 18:50:51 +02:00
service - > writer - > service = service ;
service - > writer - > dataUsed = 0 ;
service - > writer - > lastWrite = mstime ( ) ;
2015-06-29 11:06:13 +02:00
service - > writer - > send_heartbeat = hb ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
}
2015-06-26 18:50:51 +02:00
return service ;
}
// Create a client attached to the given service using the provided socket FD
2015-06-28 20:59:49 +02:00
struct client * createSocketClient ( struct net_service * service , int fd )
{
anetSetSendBuffer ( Modes . aneterr , fd , ( MODES_NET_SNDBUF_SIZE < < Modes . net_sndbuf_size ) ) ;
return createGenericClient ( service , fd ) ;
}
// Create a client attached to the given service using the provided FD (might not be a socket!)
struct client * createGenericClient ( struct net_service * service , int fd )
2015-06-26 18:50:51 +02:00
{
struct client * c ;
anetNonBlock ( Modes . aneterr , fd ) ;
if ( ! ( c = ( struct client * ) malloc ( sizeof ( * c ) ) ) ) {
fprintf ( stderr , " Out of memory allocating a new %s network client \n " , service - > descr ) ;
exit ( 1 ) ;
}
c - > service = service ;
c - > next = Modes . clients ;
c - > fd = fd ;
c - > buflen = 0 ;
2016-12-29 18:55:56 +01:00
c - > modeac_requested = 0 ;
2015-06-26 18:50:51 +02:00
Modes . clients = c ;
+ + service - > connections ;
if ( service - > writer & & service - > connections = = 1 ) {
service - > writer - > lastWrite = mstime ( ) ; // suppress heartbeat initially
}
return c ;
}
// Initiate an outgoing connection which will use the given service.
// Return the new client or NULL if the connection failed
struct client * serviceConnect ( struct net_service * service , char * addr , int port )
{
2016-02-16 14:00:55 +01:00
int s ;
char buf [ 20 ] ;
// Bleh.
snprintf ( buf , 20 , " %d " , port ) ;
s = anetTcpConnect ( Modes . aneterr , addr , buf ) ;
2015-06-26 18:50:51 +02:00
if ( s = = ANET_ERR )
return NULL ;
2015-06-28 20:59:49 +02:00
return createSocketClient ( service , s ) ;
2015-06-26 18:50:51 +02:00
}
// Set up the given service to listen on an address/port.
// _exits_ on failure!
2016-01-24 19:45:35 +01:00
void serviceListen ( struct net_service * service , char * bind_addr , char * bind_ports )
2015-06-26 18:50:51 +02:00
{
2016-01-24 19:45:35 +01:00
int * fds = NULL ;
int n = 0 ;
char * p , * end ;
2016-02-16 14:00:55 +01:00
char buf [ 128 ] ;
2015-06-26 18:50:51 +02:00
2016-01-24 19:45:35 +01:00
if ( service - > listener_count > 0 ) {
2015-06-26 18:50:51 +02:00
fprintf ( stderr , " Tried to set up the service %s twice! \n " , service - > descr ) ;
exit ( 1 ) ;
}
2016-01-24 19:45:35 +01:00
if ( ! bind_ports | | ! strcmp ( bind_ports , " " ) | | ! strcmp ( bind_ports , " 0 " ) )
return ;
p = bind_ports ;
2016-02-16 14:00:55 +01:00
while ( p & & * p ) {
int newfds [ 16 ] ;
int nfds , i ;
end = strpbrk ( p , " , " ) ;
if ( ! end ) {
strncpy ( buf , p , sizeof ( buf ) ) ;
2016-02-16 14:05:03 +01:00
buf [ sizeof ( buf ) - 1 ] = 0 ;
2016-02-16 14:00:55 +01:00
p = NULL ;
} else {
size_t len = end - p ;
2016-02-16 14:05:03 +01:00
if ( len > = sizeof ( buf ) )
len = sizeof ( buf ) - 1 ;
2016-02-16 14:00:55 +01:00
memcpy ( buf , p , len ) ;
2016-02-16 14:05:03 +01:00
buf [ len ] = 0 ;
2016-02-16 14:00:55 +01:00
p = end + 1 ;
2016-01-24 19:45:35 +01:00
}
2016-02-16 14:00:55 +01:00
nfds = anetTcpServer ( Modes . aneterr , buf , bind_addr , newfds , sizeof ( newfds ) ) ;
if ( nfds = = ANET_ERR ) {
fprintf ( stderr , " Error opening the listening port %s (%s): %s \n " ,
buf , service - > descr , Modes . aneterr ) ;
2016-01-24 19:45:35 +01:00
exit ( 1 ) ;
}
2016-02-16 14:00:55 +01:00
fds = realloc ( fds , ( n + nfds ) * sizeof ( int ) ) ;
2016-01-24 19:45:35 +01:00
if ( ! fds ) {
fprintf ( stderr , " out of memory \n " ) ;
exit ( 1 ) ;
}
2016-02-16 14:00:55 +01:00
for ( i = 0 ; i < nfds ; + + i ) {
anetNonBlock ( Modes . aneterr , newfds [ i ] ) ;
fds [ n + + ] = newfds [ i ] ;
}
2015-06-26 18:50:51 +02:00
}
2016-01-24 19:45:35 +01:00
service - > listener_count = n ;
service - > listener_fds = fds ;
2015-06-26 18:50:51 +02:00
}
struct net_service * makeBeastInputService ( void )
{
2016-12-29 18:54:53 +01:00
return serviceInit ( " Beast TCP input " , NULL , NULL , READ_MODE_BEAST , NULL , decodeBinMessage ) ;
2015-06-26 18:50:51 +02:00
}
2015-06-28 20:59:49 +02:00
struct net_service * makeFatsvOutputService ( void )
{
2016-12-29 18:54:53 +01:00
return serviceInit ( " FATSV TCP output " , & Modes . fatsv_out , NULL , READ_MODE_IGNORE , NULL , NULL ) ;
2015-06-28 20:59:49 +02:00
}
2015-06-26 18:50:51 +02:00
void modesInitNet ( void ) {
struct net_service * s ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
signal ( SIGPIPE , SIG_IGN ) ;
2015-06-26 18:50:51 +02:00
Modes . clients = NULL ;
Modes . services = NULL ;
// set up listeners
2016-12-29 18:54:53 +01:00
s = serviceInit ( " Raw TCP output " , & Modes . raw_out , send_raw_heartbeat , READ_MODE_IGNORE , NULL , NULL ) ;
2016-01-24 19:45:35 +01:00
serviceListen ( s , Modes . net_bind_address , Modes . net_output_raw_ports ) ;
2015-06-26 18:50:51 +02:00
2016-12-29 18:55:56 +01:00
s = serviceInit ( " Beast TCP output " , & Modes . beast_out , send_beast_heartbeat , READ_MODE_BEAST_COMMAND , NULL , handleBeastCommand ) ;
2016-01-24 19:45:35 +01:00
serviceListen ( s , Modes . net_bind_address , Modes . net_output_beast_ports ) ;
2015-06-26 18:50:51 +02:00
2016-12-29 18:54:53 +01:00
s = serviceInit ( " Basestation TCP output " , & Modes . sbs_out , send_sbs_heartbeat , READ_MODE_IGNORE , NULL , NULL ) ;
2016-01-24 19:45:35 +01:00
serviceListen ( s , Modes . net_bind_address , Modes . net_output_sbs_ports ) ;
2015-06-26 18:50:51 +02:00
2016-12-29 18:54:53 +01:00
s = serviceInit ( " Raw TCP input " , NULL , NULL , READ_MODE_ASCII , " \n " , decodeHexMessage ) ;
2016-01-24 19:45:35 +01:00
serviceListen ( s , Modes . net_bind_address , Modes . net_input_raw_ports ) ;
2015-06-26 18:50:51 +02:00
2016-01-24 19:45:35 +01:00
s = makeBeastInputService ( ) ;
serviceListen ( s , Modes . net_bind_address , Modes . net_input_beast_ports ) ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
}
//
//=========================================================================
//
// This function gets called from time to time when the decoding thread is
// awakened by new data arriving. This usually happens a few times every second
//
2015-06-26 18:50:51 +02:00
static struct client * modesAcceptClients ( void ) {
2016-02-16 14:00:55 +01:00
int fd ;
2015-06-26 18:50:51 +02:00
struct net_service * s ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
2015-06-26 18:50:51 +02:00
for ( s = Modes . services ; s ; s = s - > next ) {
2016-01-24 19:45:35 +01:00
int i ;
for ( i = 0 ; i < s - > listener_count ; + + i ) {
2016-02-16 14:00:55 +01:00
while ( ( fd = anetTcpAccept ( Modes . aneterr , s - > listener_fds [ i ] ) ) > = 0 ) {
2015-06-28 20:59:49 +02:00
createSocketClient ( s , fd ) ;
2015-06-26 18:50:51 +02:00
}
}
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
}
2015-06-26 18:50:51 +02:00
2014-04-25 15:48:14 +02:00
return Modes . clients ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
}
//
//=========================================================================
//
// On error free the client, collect the structure, adjust maxfd if needed.
//
2015-06-26 18:50:51 +02:00
static void modesCloseClient ( struct client * c ) {
if ( ! c - > service ) {
fprintf ( stderr , " warning: double close of net client \n " ) ;
return ;
}
2014-10-03 23:55:21 +02:00
2014-10-02 22:06:10 +02:00
// Clean up, but defer removing from the list until modesNetCleanup().
// This is because there may be stackframes still pointing at this
// client (unpredictably: reading from client A may cause client B to
// be freed)
2014-04-25 15:48:14 +02:00
close ( c - > fd ) ;
2015-06-26 18:50:51 +02:00
c - > service - > connections - - ;
2014-04-25 15:48:14 +02:00
2014-10-02 22:06:10 +02:00
// mark it as inactive and ready to be freed
c - > fd = - 1 ;
2015-06-26 18:50:51 +02:00
c - > service = NULL ;
2016-12-29 18:55:56 +01:00
c - > modeac_requested = 0 ;
2016-12-29 18:56:32 +01:00
autoset_modeac ( ) ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
}
//
//=========================================================================
//
2014-10-03 23:55:21 +02:00
// Send the write buffer for the specified writer to all connected clients
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
//
2014-10-03 23:55:21 +02:00
static void flushWrites ( struct net_writer * writer ) {
2014-10-02 22:06:10 +02:00
struct client * c ;
2014-04-25 18:00:58 +02:00
2014-10-02 22:06:10 +02:00
for ( c = Modes . clients ; c ; c = c - > next ) {
2015-06-26 22:29:54 +02:00
if ( ! c - > service )
continue ;
2015-06-26 18:50:51 +02:00
if ( c - > service = = writer - > service ) {
2014-04-25 15:48:14 +02:00
# ifndef _WIN32
2014-10-03 23:55:21 +02:00
int nwritten = write ( c - > fd , writer - > data , writer - > dataUsed ) ;
2014-04-25 15:48:14 +02:00
# else
2014-10-03 23:55:21 +02:00
int nwritten = send ( c - > fd , writer - > data , writer - > dataUsed , 0 ) ;
2014-04-25 15:48:14 +02:00
# endif
2014-10-03 23:55:21 +02:00
if ( nwritten ! = writer - > dataUsed ) {
2014-10-31 18:58:03 +01:00
modesCloseClient ( c ) ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
}
}
}
2014-10-03 23:55:21 +02:00
writer - > dataUsed = 0 ;
2015-02-10 23:24:22 +01:00
writer - > lastWrite = mstime ( ) ;
2014-10-03 23:55:21 +02:00
}
// Prepare to write up to 'len' bytes to the given net_writer.
// Returns a pointer to write to, or NULL to skip this write.
static void * prepareWrite ( struct net_writer * writer , int len ) {
2015-06-26 18:50:51 +02:00
if ( ! writer | |
! writer - > service | |
! writer - > service - > connections | |
! writer - > data )
return NULL ;
2014-10-03 23:55:21 +02:00
2015-06-26 18:50:51 +02:00
if ( len > MODES_OUT_BUF_SIZE )
return NULL ;
2014-10-03 23:55:21 +02:00
2015-06-26 18:50:51 +02:00
if ( writer - > dataUsed + len > = MODES_OUT_BUF_SIZE ) {
// Flush now to free some space
flushWrites ( writer ) ;
}
2014-10-03 23:55:21 +02:00
2015-06-26 18:50:51 +02:00
return writer - > data + writer - > dataUsed ;
2014-10-03 23:55:21 +02:00
}
// Complete a write previously begun by prepareWrite.
// endptr should point one byte past the last byte written
// to the buffer returned from prepareWrite.
static void completeWrite ( struct net_writer * writer , void * endptr ) {
2015-06-26 18:50:51 +02:00
writer - > dataUsed = endptr - writer - > data ;
2014-10-03 23:55:21 +02:00
2015-06-26 18:50:51 +02:00
if ( writer - > dataUsed > = Modes . net_output_flush_size ) {
flushWrites ( writer ) ;
}
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
}
2014-10-03 23:55:21 +02:00
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
//
//=========================================================================
//
// Write raw output in Beast Binary format with Timestamp to TCP clients
//
2015-06-26 18:50:51 +02:00
static void modesSendBeastOutput ( struct modesMessage * mm ) {
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
int msgLen = mm - > msgbits / 8 ;
2014-10-03 23:55:21 +02:00
char * p = prepareWrite ( & Modes . beast_out , 2 + 2 * ( 7 + msgLen ) ) ;
2014-02-23 02:55:34 +01:00
char ch ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
int j ;
2016-02-24 12:51:45 +01:00
int sig ;
2015-01-22 20:56:38 +01:00
unsigned char * msg = ( Modes . net_verbatim ? mm - > verbatim : mm - > msg ) ;
2014-10-03 23:55:21 +02:00
if ( ! p )
return ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
* p + + = 0x1a ;
if ( msgLen = = MODES_SHORT_MSG_BYTES )
{ * p + + = ' 2 ' ; }
else if ( msgLen = = MODES_LONG_MSG_BYTES )
{ * p + + = ' 3 ' ; }
else if ( msgLen = = MODEAC_MSG_BYTES )
{ * p + + = ' 1 ' ; }
else
{ return ; }
2015-04-18 12:05:12 +02:00
/* timestamp, big-endian */
* p + + = ( ch = ( mm - > timestampMsg > > 40 ) ) ;
if ( 0x1A = = ch ) { * p + + = ch ; }
* p + + = ( ch = ( mm - > timestampMsg > > 32 ) ) ;
if ( 0x1A = = ch ) { * p + + = ch ; }
* p + + = ( ch = ( mm - > timestampMsg > > 24 ) ) ;
if ( 0x1A = = ch ) { * p + + = ch ; }
* p + + = ( ch = ( mm - > timestampMsg > > 16 ) ) ;
if ( 0x1A = = ch ) { * p + + = ch ; }
* p + + = ( ch = ( mm - > timestampMsg > > 8 ) ) ;
if ( 0x1A = = ch ) { * p + + = ch ; }
* p + + = ( ch = ( mm - > timestampMsg ) ) ;
if ( 0x1A = = ch ) { * p + + = ch ; }
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
2016-02-24 12:51:45 +01:00
sig = round ( sqrt ( mm - > signalLevel ) * 255 ) ;
if ( mm - > signalLevel > 0 & & sig < 1 )
sig = 1 ;
if ( sig > 255 )
sig = 255 ;
* p + + = ch = ( char ) sig ;
2014-10-03 23:55:21 +02:00
if ( 0x1A = = ch ) { * p + + = ch ; }
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
2014-02-23 02:55:34 +01:00
for ( j = 0 ; j < msgLen ; j + + ) {
2015-01-22 20:56:38 +01:00
* p + + = ( ch = msg [ j ] ) ;
2014-10-03 23:55:21 +02:00
if ( 0x1A = = ch ) { * p + + = ch ; }
2014-02-23 02:55:34 +01:00
}
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
2014-10-03 23:55:21 +02:00
completeWrite ( & Modes . beast_out , p ) ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
}
2014-10-03 23:55:21 +02:00
2015-06-29 11:06:13 +02:00
static void send_beast_heartbeat ( struct net_service * service )
{
static char heartbeat_message [ ] = { 0x1a , ' 1 ' , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ;
char * data ;
if ( ! service - > writer )
return ;
data = prepareWrite ( service - > writer , sizeof ( heartbeat_message ) ) ;
if ( ! data )
return ;
memcpy ( data , heartbeat_message , sizeof ( heartbeat_message ) ) ;
completeWrite ( service - > writer , data + sizeof ( heartbeat_message ) ) ;
}
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
//
//=========================================================================
//
// Write raw output to TCP clients
//
2015-06-26 18:50:51 +02:00
static void modesSendRawOutput ( struct modesMessage * mm ) {
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
int msgLen = mm - > msgbits / 8 ;
2014-10-03 23:55:21 +02:00
char * p = prepareWrite ( & Modes . raw_out , msgLen * 2 + 15 ) ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
int j ;
2015-01-22 20:56:38 +01:00
unsigned char * msg = ( Modes . net_verbatim ? mm - > verbatim : mm - > msg ) ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
2014-10-03 23:55:21 +02:00
if ( ! p )
return ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
if ( Modes . mlat & & mm - > timestampMsg ) {
2015-04-18 12:05:12 +02:00
/* timestamp, big-endian */
2015-04-18 12:20:16 +02:00
sprintf ( p , " @%012 " PRIX64 ,
2015-04-18 12:05:12 +02:00
mm - > timestampMsg ) ;
p + = 13 ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
} else
* p + + = ' * ' ;
for ( j = 0 ; j < msgLen ; j + + ) {
2015-01-22 20:56:38 +01:00
sprintf ( p , " %02X " , msg [ j ] ) ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
p + = 2 ;
}
* p + + = ' ; ' ;
* p + + = ' \n ' ;
2014-10-03 23:55:21 +02:00
completeWrite ( & Modes . raw_out , p ) ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
}
2015-06-29 11:06:13 +02:00
static void send_raw_heartbeat ( struct net_service * service )
{
static char * heartbeat_message = " *0000; \n " ;
char * data ;
int len = strlen ( heartbeat_message ) ;
if ( ! service - > writer )
return ;
data = prepareWrite ( service - > writer , len ) ;
if ( ! data )
return ;
memcpy ( data , heartbeat_message , len ) ;
completeWrite ( service - > writer , data + len ) ;
}
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
//
//=========================================================================
//
// Write SBS output to TCP clients
//
2016-01-01 16:15:28 +01:00
static void modesSendSBSOutput ( struct modesMessage * mm , struct aircraft * a ) {
2015-02-08 18:46:01 +01:00
char * p ;
struct timespec now ;
2014-10-02 13:20:37 +02:00
struct tm stTime_receive , stTime_now ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
int msgType ;
2015-02-08 15:30:10 +01:00
// For now, suppress non-ICAO addresses
if ( mm - > addr & MODES_NON_ICAO_ADDRESS )
return ;
2015-02-08 18:46:01 +01:00
p = prepareWrite ( & Modes . sbs_out , 200 ) ;
if ( ! p )
return ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
//
// SBS BS style output checked against the following reference
// http://www.homepages.mcb.net/bones/SBS/Article/Barebones42_Socket_Data.htm - seems comprehensive
//
// Decide on the basic SBS Message Type
2016-08-27 15:34:14 +02:00
switch ( mm - > msgtype ) {
case 4 :
case 20 :
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
msgType = 5 ;
2016-08-27 15:34:14 +02:00
break ;
break ;
case 5 :
case 21 :
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
msgType = 6 ;
2016-08-27 15:34:14 +02:00
break ;
case 0 :
case 16 :
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
msgType = 7 ;
2016-08-27 15:34:14 +02:00
break ;
case 11 :
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
msgType = 8 ;
2016-08-27 15:34:14 +02:00
break ;
case 17 :
case 18 :
if ( mm - > metype > = 1 & & mm - > metype < = 4 ) {
msgType = 1 ;
} else if ( mm - > metype > = 5 & & mm - > metype < = 8 ) {
msgType = 2 ;
} else if ( mm - > metype > = 9 & & mm - > metype < = 18 ) {
msgType = 3 ;
} else if ( mm - > metype = = 19 ) {
msgType = 4 ;
} else {
return ;
}
break ;
default :
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
return ;
}
// Fields 1 to 6 : SBS message type and ICAO address of the aircraft and some other stuff
2016-08-27 15:34:14 +02:00
p + = sprintf ( p , " MSG,%d,1,1,%06X,1, " , msgType , mm - > addr ) ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
2014-10-02 13:20:37 +02:00
// Find current system time
2015-09-14 20:03:19 +02:00
clock_gettime ( CLOCK_REALTIME , & now ) ;
2015-02-08 18:46:01 +01:00
localtime_r ( & now . tv_sec , & stTime_now ) ;
2014-10-02 13:20:37 +02:00
// Find message reception time
2017-12-02 18:38:33 +01:00
time_t received = ( time_t ) ( mm - > sysTimestampMsg / 1000 ) ;
localtime_r ( & received , & stTime_receive ) ;
2014-10-02 13:20:37 +02:00
// Fields 7 & 8 are the message reception time and date
p + = sprintf ( p , " %04d/%02d/%02d, " , ( stTime_receive . tm_year + 1900 ) , ( stTime_receive . tm_mon + 1 ) , stTime_receive . tm_mday ) ;
2018-08-01 00:49:05 +02:00
p + = sprintf ( p , " %02d:%02d:%02d.%03u, " , stTime_receive . tm_hour , stTime_receive . tm_min , stTime_receive . tm_sec , ( unsigned ) ( mm - > sysTimestampMsg % 1000 ) ) ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
// Fields 9 & 10 are the current time and date
2014-10-02 13:20:37 +02:00
p + = sprintf ( p , " %04d/%02d/%02d, " , ( stTime_now . tm_year + 1900 ) , ( stTime_now . tm_mon + 1 ) , stTime_now . tm_mday ) ;
2015-02-08 18:46:01 +01:00
p + = sprintf ( p , " %02d:%02d:%02d.%03u " , stTime_now . tm_hour , stTime_now . tm_min , stTime_now . tm_sec , ( unsigned ) ( now . tv_nsec / 1000000U ) ) ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
// Field 11 is the callsign (if we have it)
2016-08-27 15:34:14 +02:00
if ( mm - > callsign_valid ) { p + = sprintf ( p , " ,%s " , mm - > callsign ) ; }
else { p + = sprintf ( p , " , " ) ; }
// Field 12 is the altitude (if we have it)
2017-12-07 17:34:08 +01:00
if ( Modes . use_gnss ) {
if ( mm - > altitude_geom_valid ) {
p + = sprintf ( p , " ,%dH " , mm - > altitude_geom ) ;
} else if ( mm - > altitude_baro_valid & & trackDataValid ( & a - > geom_delta_valid ) ) {
p + = sprintf ( p , " ,%dH " , mm - > altitude_baro + a - > geom_delta ) ;
} else if ( mm - > altitude_baro_valid ) {
p + = sprintf ( p , " ,%d " , mm - > altitude_baro ) ;
2016-01-01 16:15:28 +01:00
} else {
2017-12-07 17:34:08 +01:00
p + = sprintf ( p , " , " ) ;
2016-01-01 16:15:28 +01:00
}
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
} else {
2017-12-07 17:34:08 +01:00
if ( mm - > altitude_baro_valid ) {
p + = sprintf ( p , " ,%d " , mm - > altitude_baro ) ;
} else if ( mm - > altitude_geom_valid & & trackDataValid ( & a - > geom_delta_valid ) ) {
p + = sprintf ( p , " ,%d " , mm - > altitude_geom - a - > geom_delta ) ;
} else {
p + = sprintf ( p , " , " ) ;
}
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
}
2014-08-06 16:21:50 +02:00
// Field 13 is the ground Speed (if we have it)
2017-06-15 19:07:40 +02:00
if ( mm - > gs_valid ) {
2017-12-07 17:34:08 +01:00
p + = sprintf ( p , " ,%.0f " , mm - > gs . selected ) ;
2014-08-06 16:21:50 +02:00
} else {
2017-06-15 19:16:51 +02:00
p + = sprintf ( p , " , " ) ;
2014-08-06 16:21:50 +02:00
}
2017-06-15 19:07:40 +02:00
// Field 14 is the ground Heading (if we have it)
2017-06-15 22:07:53 +02:00
if ( mm - > heading_valid & & mm - > heading_type = = HEADING_GROUND_TRACK ) {
p + = sprintf ( p , " ,%.0f " , mm - > heading ) ;
2014-08-06 16:21:50 +02:00
} else {
p + = sprintf ( p , " , " ) ;
}
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
// Fields 15 and 16 are the Lat/Lon (if we have it)
2016-08-27 15:34:14 +02:00
if ( mm - > cpr_decoded ) {
p + = sprintf ( p , " ,%1.5f,%1.5f " , mm - > decoded_lat , mm - > decoded_lon ) ;
} else {
p + = sprintf ( p , " ,, " ) ;
}
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
// Field 17 is the VerticalRate (if we have it)
2017-06-15 19:07:40 +02:00
if ( Modes . use_gnss ) {
if ( mm - > geom_rate_valid ) {
p + = sprintf ( p , " ,%dH " , mm - > geom_rate ) ;
} else if ( mm - > baro_rate_valid ) {
p + = sprintf ( p , " ,%d " , mm - > baro_rate ) ;
} else {
p + = sprintf ( p , " , " ) ;
}
2016-08-27 15:34:14 +02:00
} else {
2017-06-15 19:07:40 +02:00
if ( mm - > baro_rate_valid ) {
p + = sprintf ( p , " ,%d " , mm - > baro_rate ) ;
} else if ( mm - > geom_rate_valid ) {
p + = sprintf ( p , " ,%d " , mm - > geom_rate ) ;
} else {
p + = sprintf ( p , " , " ) ;
}
2016-08-27 15:34:14 +02:00
}
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
// Field 18 is the Squawk (if we have it)
2016-08-27 15:34:14 +02:00
if ( mm - > squawk_valid ) {
p + = sprintf ( p , " ,%04x " , mm - > squawk ) ;
} else {
p + = sprintf ( p , " , " ) ;
}
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
// Field 19 is the Squawk Changing Alert flag (if we have it)
2016-08-27 15:34:14 +02:00
if ( mm - > alert_valid ) {
if ( mm - > alert ) {
2014-02-24 11:28:35 +01:00
p + = sprintf ( p , " ,-1 " ) ;
} else {
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
p + = sprintf ( p , " ,0 " ) ;
2014-02-24 11:28:35 +01:00
}
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
} else {
p + = sprintf ( p , " , " ) ;
}
// Field 20 is the Squawk Emergency flag (if we have it)
2016-08-27 15:34:14 +02:00
if ( mm - > squawk_valid ) {
if ( ( mm - > squawk = = 0x7500 ) | | ( mm - > squawk = = 0x7600 ) | | ( mm - > squawk = = 0x7700 ) ) {
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
p + = sprintf ( p , " ,-1 " ) ;
2014-02-24 11:28:35 +01:00
} else {
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
p + = sprintf ( p , " ,0 " ) ;
}
} else {
p + = sprintf ( p , " , " ) ;
}
// Field 21 is the Squawk Ident flag (if we have it)
2016-08-27 15:34:14 +02:00
if ( mm - > spi_valid ) {
if ( mm - > spi ) {
2014-02-24 11:28:35 +01:00
p + = sprintf ( p , " ,-1 " ) ;
} else {
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
p + = sprintf ( p , " ,0 " ) ;
2014-02-24 11:28:35 +01:00
}
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
} else {
p + = sprintf ( p , " , " ) ;
}
// Field 22 is the OnTheGround flag (if we have it)
2016-08-27 15:34:14 +02:00
switch ( mm - > airground ) {
case AG_GROUND :
p + = sprintf ( p , " ,-1 " ) ;
break ;
case AG_AIRBORNE :
p + = sprintf ( p , " ,0 " ) ;
break ;
default :
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
p + = sprintf ( p , " , " ) ;
2016-08-27 15:34:14 +02:00
break ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
}
p + = sprintf ( p , " \r \n " ) ;
2014-10-03 23:55:21 +02:00
completeWrite ( & Modes . sbs_out , p ) ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
}
2015-06-29 11:06:13 +02:00
static void send_sbs_heartbeat ( struct net_service * service )
{
static char * heartbeat_message = " \r \n " ; // is there a better one?
char * data ;
int len = strlen ( heartbeat_message ) ;
if ( ! service - > writer )
return ;
data = prepareWrite ( service - > writer , len ) ;
if ( ! data )
return ;
memcpy ( data , heartbeat_message , len ) ;
completeWrite ( service - > writer , data + len ) ;
}
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
//
//=========================================================================
//
2016-01-01 16:15:28 +01:00
void modesQueueOutput ( struct modesMessage * mm , struct aircraft * a ) {
2016-08-27 15:34:14 +02:00
int is_mlat = ( mm - > source = = SOURCE_MLAT ) ;
2016-01-21 18:48:06 +01:00
2016-10-11 19:00:11 +02:00
if ( a & & ! is_mlat & & mm - > correctedbits < 2 ) {
2016-03-03 13:39:01 +01:00
// Don't ever forward 2-bit-corrected messages via SBS output.
// Don't ever forward mlat messages via SBS output.
2016-01-21 18:48:06 +01:00
modesSendSBSOutput ( mm , a ) ;
2016-03-03 13:39:01 +01:00
}
if ( ! is_mlat & & ( Modes . net_verbatim | | mm - > correctedbits < 2 ) ) {
// Forward 2-bit-corrected messages via raw output only if --net-verbatim is set
// Don't ever forward mlat messages via raw output.
2016-01-21 18:48:06 +01:00
modesSendRawOutput ( mm ) ;
}
2015-07-03 22:56:23 +02:00
2016-03-03 13:39:01 +01:00
if ( ( ! is_mlat | | Modes . forward_mlat ) & & ( Modes . net_verbatim | | mm - > correctedbits < 2 ) ) {
// Forward 2-bit-corrected messages via beast output only if --net-verbatim is set
// Forward mlat messages via beast output only if --forward-mlat is set
2016-01-21 18:48:06 +01:00
modesSendBeastOutput ( mm ) ;
}
2016-08-28 02:29:37 +02:00
2016-10-11 19:00:11 +02:00
if ( a & & ! is_mlat ) {
2016-08-28 02:29:37 +02:00
writeFATSVEvent ( mm , a ) ;
}
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
}
2016-12-27 20:07:10 +01:00
// Decode a little-endian IEEE754 float (binary32)
float ieee754_binary32_le_to_float ( uint8_t * data )
{
double sign = ( data [ 3 ] & 0x80 ) ? - 1.0 : 1.0 ;
int16_t raw_exponent = ( ( data [ 3 ] & 0x7f ) < < 1 ) | ( ( data [ 2 ] & 0x80 ) > > 7 ) ;
uint32_t raw_significand = ( ( data [ 2 ] & 0x7f ) < < 16 ) | ( data [ 1 ] < < 8 ) | data [ 0 ] ;
if ( raw_exponent = = 0 ) {
if ( raw_significand = = 0 ) {
/* -0 is treated like +0 */
return 0 ;
} else {
/* denormal */
return ldexp ( sign * raw_significand , - 126 - 23 ) ;
}
}
if ( raw_exponent = = 255 ) {
if ( raw_significand = = 0 ) {
/* +/-infinity */
return sign < 0 ? - INFINITY : INFINITY ;
} else {
/* NaN */
# ifdef NAN
return NAN ;
# else
return 0.0f ;
# endif
}
}
/* normalized value */
2016-12-27 20:14:20 +01:00
return ldexp ( sign * ( ( 1 < < 23 ) | raw_significand ) , raw_exponent - 127 - 23 ) ;
2016-12-27 20:07:10 +01:00
}
static void handle_radarcape_position ( float lat , float lon , float alt )
{
if ( ! isfinite ( lat ) | | lat < - 90 | | lat > 90 | | ! isfinite ( lon ) | | lon < - 180 | | lon > 180 | | ! isfinite ( alt ) )
return ;
writeFATSVPositionUpdate ( lat , lon , alt ) ;
if ( ! ( Modes . bUserFlags & MODES_USER_LATLON_VALID ) ) {
Modes . fUserLat = lat ;
Modes . fUserLon = lon ;
Modes . bUserFlags | = MODES_USER_LATLON_VALID ;
receiverPositionChanged ( lat , lon , alt ) ;
}
}
2016-12-29 18:56:32 +01:00
// recompute global Mode A/C setting
static void autoset_modeac ( ) {
struct client * c ;
if ( ! Modes . mode_ac_auto )
return ;
Modes . mode_ac = 0 ;
for ( c = Modes . clients ; c ; c = c - > next ) {
if ( c - > modeac_requested ) {
Modes . mode_ac = 1 ;
break ;
}
}
}
2016-12-29 18:53:04 +01:00
// Send some Beast settings commands to a client
void sendBeastSettings ( struct client * c , const char * settings )
{
int len ;
char * buf , * p ;
len = strlen ( settings ) * 3 ;
buf = p = alloca ( len ) ;
while ( * settings ) {
* p + + = 0x1a ;
* p + + = ' 1 ' ;
* p + + = * settings + + ;
}
anetWrite ( c - > fd , buf , len ) ;
}
2016-12-29 18:55:56 +01:00
//
// Handle a Beast command message.
// Currently, we just look for the Mode A/C command message
// and ignore everything else.
//
static int handleBeastCommand ( struct client * c , char * p ) {
if ( p [ 0 ] ! = ' 1 ' ) {
// huh?
return 0 ;
}
switch ( p [ 1 ] ) {
case ' j ' :
c - > modeac_requested = 0 ;
break ;
case ' J ' :
c - > modeac_requested = 1 ;
break ;
}
2016-12-29 18:56:32 +01:00
autoset_modeac ( ) ;
2016-12-29 18:55:56 +01:00
return 0 ;
}
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
//
//=========================================================================
//
// This function decodes a Beast binary format message
2014-02-24 11:28:35 +01:00
//
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
// The message is passed to the higher level layers, so it feeds
// the selected screen output, the network output and so forth.
2014-02-24 11:28:35 +01:00
//
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
// If the message looks invalid it is silently discarded.
//
2014-02-24 11:28:35 +01:00
// The function always returns 0 (success) to the caller as there is no
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
// case where we want broken messages here to close the client connection.
//
2015-06-26 18:50:51 +02:00
static int decodeBinMessage ( struct client * c , char * p ) {
2014-02-24 11:28:35 +01:00
int msgLen = 0 ;
2014-02-23 02:55:34 +01:00
int j ;
char ch ;
2016-12-27 20:07:10 +01:00
unsigned char msg [ MODES_LONG_MSG_BYTES + 7 ] ;
2016-08-26 22:39:39 +02:00
static struct modesMessage zeroMessage ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
struct modesMessage mm ;
MODES_NOTUSED ( c ) ;
memset ( & mm , 0 , sizeof ( mm ) ) ;
2014-07-10 19:11:13 +02:00
ch = * p + + ; /// Get the message type
2016-12-29 18:57:53 +01:00
if ( ch = = ' 1 ' & & Modes . mode_ac ) {
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
msgLen = MODEAC_MSG_BYTES ;
2014-07-10 19:11:13 +02:00
} else if ( ch = = ' 2 ' ) {
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
msgLen = MODES_SHORT_MSG_BYTES ;
2014-07-10 19:11:13 +02:00
} else if ( ch = = ' 3 ' ) {
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
msgLen = MODES_LONG_MSG_BYTES ;
2016-12-27 20:07:10 +01:00
} else if ( ch = = ' 5 ' ) {
// Special case for Radarcape position messages.
float lat , lon , alt ;
for ( j = 0 ; j < 21 ; j + + ) { // and the data
msg [ j ] = ch = * p + + ;
if ( 0x1A = = ch ) { p + + ; }
}
lat = ieee754_binary32_le_to_float ( msg + 4 ) ;
lon = ieee754_binary32_le_to_float ( msg + 8 ) ;
alt = ieee754_binary32_le_to_float ( msg + 12 ) ;
handle_radarcape_position ( lat , lon , alt ) ;
} else {
// Ignore this.
return 0 ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
}
if ( msgLen ) {
2016-08-26 22:39:39 +02:00
mm = zeroMessage ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
// Mark messages received over the internet as remote so that we don't try to
// pass them off as being received by this instance when forwarding them
mm . remote = 1 ;
2014-07-10 19:11:13 +02:00
2015-04-18 12:05:12 +02:00
// Grab the timestamp (big endian format)
mm . timestampMsg = 0 ;
for ( j = 0 ; j < 6 ; j + + ) {
ch = * p + + ;
mm . timestampMsg = mm . timestampMsg < < 8 | ( ch & 255 ) ;
2014-02-24 11:28:35 +01:00
if ( 0x1A = = ch ) { p + + ; }
}
2015-02-08 18:46:01 +01:00
// record reception time as the time we read it.
2017-12-02 18:38:33 +01:00
mm . sysTimestampMsg = mstime ( ) ;
2015-02-08 18:46:01 +01:00
2015-01-22 02:01:39 +01:00
ch = * p + + ; // Grab the signal level
2016-02-24 12:51:45 +01:00
mm . signalLevel = ( ( unsigned char ) ch / 255.0 ) ;
mm . signalLevel = mm . signalLevel * mm . signalLevel ;
2014-02-23 02:55:34 +01:00
if ( 0x1A = = ch ) { p + + ; }
for ( j = 0 ; j < msgLen ; j + + ) { // and the data
2014-02-24 11:28:35 +01:00
msg [ j ] = ch = * p + + ;
if ( 0x1A = = ch ) { p + + ; }
}
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
if ( msgLen = = MODEAC_MSG_BYTES ) { // ModeA or ModeC
2015-01-22 20:49:19 +01:00
Modes . stats_current . remote_received_modeac + + ;
2014-02-24 11:28:35 +01:00
decodeModeAMessage ( & mm , ( ( msg [ 0 ] < < 8 ) | msg [ 1 ] ) ) ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
} else {
2015-01-22 20:49:19 +01:00
int result ;
Modes . stats_current . remote_received_modes + + ;
result = decodeModesMessage ( & mm , msg ) ;
if ( result < 0 ) {
if ( result = = - 1 )
Modes . stats_current . remote_rejected_unknown_icao + + ;
else
Modes . stats_current . remote_rejected_bad + + ;
2015-01-21 01:23:48 +01:00
return 0 ;
} else {
2015-01-22 20:49:19 +01:00
Modes . stats_current . remote_accepted [ mm . correctedbits ] + + ;
2015-01-21 01:23:48 +01:00
}
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
}
2014-02-24 11:28:35 +01:00
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
useModesMessage ( & mm ) ;
}
return ( 0 ) ;
}
//
//=========================================================================
//
// Turn an hex digit into its 4 bit decimal value.
// Returns -1 if the digit is not in the 0-F range.
//
2015-06-26 18:50:51 +02:00
static int hexDigitVal ( int c ) {
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
c = tolower ( c ) ;
if ( c > = ' 0 ' & & c < = ' 9 ' ) return c - ' 0 ' ;
else if ( c > = ' a ' & & c < = ' f ' ) return c - ' a ' + 10 ;
else return - 1 ;
}
//
//=========================================================================
//
// This function decodes a string representing message in raw hex format
// like: *8D4B969699155600E87406F5B69F; The string is null-terminated.
2017-06-15 19:16:51 +02:00
//
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
// The message is passed to the higher level layers, so it feeds
// the selected screen output, the network output and so forth.
2017-06-15 19:16:51 +02:00
//
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
// If the message looks invalid it is silently discarded.
//
2017-06-15 19:16:51 +02:00
// The function always returns 0 (success) to the caller as there is no
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
// case where we want broken messages here to close the client connection.
//
2015-06-26 18:50:51 +02:00
static int decodeHexMessage ( struct client * c , char * hex ) {
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
int l = strlen ( hex ) , j ;
unsigned char msg [ MODES_LONG_MSG_BYTES ] ;
struct modesMessage mm ;
2016-08-26 22:39:39 +02:00
static struct modesMessage zeroMessage ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
MODES_NOTUSED ( c ) ;
2016-08-26 22:39:39 +02:00
mm = zeroMessage ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
// Mark messages received over the internet as remote so that we don't try to
// pass them off as being received by this instance when forwarding them
mm . remote = 1 ;
2016-02-24 12:51:45 +01:00
mm . signalLevel = 0 ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
// Remove spaces on the left and on the right
while ( l & & isspace ( hex [ l - 1 ] ) ) {
hex [ l - 1 ] = ' \0 ' ; l - - ;
}
while ( isspace ( * hex ) ) {
hex + + ; l - - ;
}
// Turn the message into binary.
// Accept *-AVR raw @-AVR/BEAST timeS+raw %-AVR timeS+raw (CRC good) <-BEAST timeS+sigL+raw
// and some AVR records that we can understand
if ( hex [ l - 1 ] ! = ' ; ' ) { return ( 0 ) ; } // not complete - abort
switch ( hex [ 0 ] ) {
case ' < ' : {
2016-02-24 12:51:45 +01:00
mm . signalLevel = ( ( hexDigitVal ( hex [ 13 ] ) < < 4 ) | hexDigitVal ( hex [ 14 ] ) ) / 255.0 ;
mm . signalLevel = mm . signalLevel * mm . signalLevel ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
hex + = 15 ; l - = 16 ; // Skip <, timestamp and siglevel, and ;
break ; }
case ' @ ' : // No CRC check
case ' % ' : { // CRC is OK
hex + = 13 ; l - = 14 ; // Skip @,%, and timestamp, and ;
break ; }
case ' * ' :
case ' : ' : {
hex + + ; l - = 2 ; // Skip * and ;
break ; }
default : {
return ( 0 ) ; // We don't know what this is, so abort
break ; }
}
2017-06-15 19:16:51 +02:00
if ( ( l ! = ( MODEAC_MSG_BYTES * 2 ) )
& & ( l ! = ( MODES_SHORT_MSG_BYTES * 2 ) )
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
& & ( l ! = ( MODES_LONG_MSG_BYTES * 2 ) ) )
{ return ( 0 ) ; } // Too short or long message... broken
2017-06-15 19:16:51 +02:00
if ( ( 0 = = Modes . mode_ac )
& & ( l = = ( MODEAC_MSG_BYTES * 2 ) ) )
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
{ return ( 0 ) ; } // Right length for ModeA/C, but not enabled
for ( j = 0 ; j < l ; j + = 2 ) {
int high = hexDigitVal ( hex [ j ] ) ;
int low = hexDigitVal ( hex [ j + 1 ] ) ;
if ( high = = - 1 | | low = = - 1 ) return 0 ;
msg [ j / 2 ] = ( high < < 4 ) | low ;
}
2015-02-08 18:46:01 +01:00
// record reception time as the time we read it.
2017-12-02 18:38:33 +01:00
mm . sysTimestampMsg = mstime ( ) ;
2015-02-08 18:46:01 +01:00
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
if ( l = = ( MODEAC_MSG_BYTES * 2 ) ) { // ModeA or ModeC
2015-01-22 20:49:19 +01:00
Modes . stats_current . remote_received_modeac + + ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
decodeModeAMessage ( & mm , ( ( msg [ 0 ] < < 8 ) | msg [ 1 ] ) ) ;
} else { // Assume ModeS
2015-01-22 20:49:19 +01:00
int result ;
Modes . stats_current . remote_received_modes + + ;
result = decodeModesMessage ( & mm , msg ) ;
if ( result < 0 ) {
if ( result = = - 1 )
Modes . stats_current . remote_rejected_unknown_icao + + ;
else
Modes . stats_current . remote_rejected_bad + + ;
2015-01-21 01:23:48 +01:00
return 0 ;
} else {
2015-01-22 20:49:19 +01:00
Modes . stats_current . remote_accepted [ mm . correctedbits ] + + ;
2015-01-21 01:23:48 +01:00
}
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
}
useModesMessage ( & mm ) ;
return ( 0 ) ;
}
2018-03-07 21:09:23 +01:00
__attribute__ ( ( format ( printf , 3 , 0 ) ) ) static char * safe_vsnprintf ( char * p , char * end , const char * format , va_list ap )
{
p + = vsnprintf ( p < end ? p : NULL , p < end ? ( size_t ) ( end - p ) : 0 , format , ap ) ;
return p ;
}
__attribute__ ( ( format ( printf , 3 , 4 ) ) ) static char * safe_snprintf ( char * p , char * end , const char * format , . . . )
{
va_list ap ;
va_start ( ap , format ) ;
p + = vsnprintf ( p < end ? p : NULL , p < end ? ( size_t ) ( end - p ) : 0 , format , ap ) ;
va_end ( ap ) ;
return p ;
}
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
//
//=========================================================================
//
// Return a description of planes in json. No metric conversion
//
2015-01-21 12:56:27 +01:00
// usual caveats about function-returning-pointer-to-static-buffer apply
static const char * jsonEscapeString ( const char * str ) {
static char buf [ 1024 ] ;
const char * in = str ;
char * out = buf , * end = buf + sizeof ( buf ) - 10 ;
for ( ; * in & & out < end ; + + in ) {
unsigned char ch = * in ;
if ( ch = = ' " ' | | ch = = ' \\ ' ) {
* out + + = ' \\ ' ;
* out + + = ch ;
} else if ( ch < 32 | | ch > 127 ) {
2018-03-07 21:10:50 +01:00
out = safe_snprintf ( out , end , " \\ u%04x " , ch ) ;
2015-01-21 12:56:27 +01:00
} else {
* out + + = ch ;
}
}
* out + + = 0 ;
return buf ;
}
2016-08-27 15:34:14 +02:00
static char * append_flags ( char * p , char * end , struct aircraft * a , datasource_t source )
2016-01-21 20:42:37 +01:00
{
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " [ " ) ;
char * start = p ;
2016-08-27 15:34:14 +02:00
if ( a - > callsign_valid . source = = source )
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " \" callsign \" , " ) ;
2017-12-07 17:34:08 +01:00
if ( a - > altitude_baro_valid . source = = source )
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " \" altitude \" , " ) ;
2017-12-07 17:34:08 +01:00
if ( a - > altitude_geom_valid . source = = source )
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " \" alt_geom \" , " ) ;
2017-06-15 19:07:40 +02:00
if ( a - > gs_valid . source = = source )
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " \" gs \" , " ) ;
2017-06-15 23:36:23 +02:00
if ( a - > ias_valid . source = = source )
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " \" ias \" , " ) ;
2017-06-15 23:36:23 +02:00
if ( a - > tas_valid . source = = source )
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " \" tas \" , " ) ;
if ( a - > mach_valid . source = = source )
p = safe_snprintf ( p , end , " \" mach \" , " ) ;
if ( a - > track_valid . source = = source )
p = safe_snprintf ( p , end , " \" track \" , " ) ;
if ( a - > track_rate_valid . source = = source )
p = safe_snprintf ( p , end , " \" track_rate \" , " ) ;
if ( a - > roll_valid . source = = source )
p = safe_snprintf ( p , end , " \" roll \" , " ) ;
if ( a - > mag_heading_valid . source = = source )
p = safe_snprintf ( p , end , " \" mag_heading \" , " ) ;
if ( a - > true_heading_valid . source = = source )
p = safe_snprintf ( p , end , " \" true_heading \" , " ) ;
2017-06-15 19:07:40 +02:00
if ( a - > baro_rate_valid . source = = source )
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " \" baro_rate \" , " ) ;
2017-06-15 19:07:40 +02:00
if ( a - > geom_rate_valid . source = = source )
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " \" geom_rate \" , " ) ;
if ( a - > squawk_valid . source = = source )
p = safe_snprintf ( p , end , " \" squawk \" , " ) ;
if ( a - > emergency_valid . source = = source )
p = safe_snprintf ( p , end , " \" emergency \" , " ) ;
if ( a - > nav_qnh_valid . source = = source )
p = safe_snprintf ( p , end , " \" nav_qnh \" , " ) ;
2019-03-19 19:44:09 +01:00
if ( a - > nav_altitude_mcp_valid . source = = source )
p = safe_snprintf ( p , end , " \" nav_altitude_mcp \" , " ) ;
if ( a - > nav_altitude_fms_valid . source = = source )
p = safe_snprintf ( p , end , " \" nav_altitude_fms \" , " ) ;
2018-03-07 21:10:50 +01:00
if ( a - > nav_heading_valid . source = = source )
p = safe_snprintf ( p , end , " \" nav_heading \" , " ) ;
if ( a - > nav_modes_valid . source = = source )
p = safe_snprintf ( p , end , " \" nav_modes \" , " ) ;
if ( a - > position_valid . source = = source )
p = safe_snprintf ( p , end , " \" lat \" , \" lon \" , \" nic \" , \" rc \" , " ) ;
if ( a - > nic_baro_valid . source = = source )
p = safe_snprintf ( p , end , " \" nic_baro \" , " ) ;
if ( a - > nac_p_valid . source = = source )
p = safe_snprintf ( p , end , " \" nac_p \" , " ) ;
if ( a - > nac_v_valid . source = = source )
p = safe_snprintf ( p , end , " \" nac_v \" , " ) ;
if ( a - > sil_valid . source = = source )
p = safe_snprintf ( p , end , " \" sil \" , \" sil_type \" , " ) ;
if ( a - > gva_valid . source = = source )
p = safe_snprintf ( p , end , " \" gva \" , " ) ;
if ( a - > sda_valid . source = = source )
p = safe_snprintf ( p , end , " \" sda \" , " ) ;
2018-03-08 22:15:41 +01:00
if ( p ! = start )
2016-01-21 20:42:37 +01:00
- - p ;
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " ] " ) ;
2016-01-21 20:42:37 +01:00
return p ;
}
2017-06-16 11:39:01 +02:00
static struct {
2017-12-07 17:34:08 +01:00
nav_modes_t flag ;
2017-06-16 11:39:01 +02:00
const char * name ;
2017-12-07 17:34:08 +01:00
} nav_modes_names [ ] = {
{ NAV_MODE_AUTOPILOT , " autopilot " } ,
{ NAV_MODE_VNAV , " vnav " } ,
{ NAV_MODE_ALT_HOLD , " althold " } ,
{ NAV_MODE_APPROACH , " approach " } ,
{ NAV_MODE_LNAV , " lnav " } ,
{ NAV_MODE_TCAS , " tcas " } ,
2017-06-16 11:39:01 +02:00
{ 0 , NULL }
} ;
2017-12-07 17:34:08 +01:00
static char * append_nav_modes ( char * p , char * end , nav_modes_t flags , const char * quote , const char * sep )
2017-06-16 11:39:01 +02:00
{
int first = 1 ;
2017-12-07 17:34:08 +01:00
for ( int i = 0 ; nav_modes_names [ i ] . name ; + + i ) {
if ( ! ( flags & nav_modes_names [ i ] . flag ) ) {
2017-06-16 11:39:01 +02:00
continue ;
}
if ( ! first ) {
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " %s " , sep ) ;
2017-06-16 11:39:01 +02:00
}
first = 0 ;
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " %s%s%s " , quote , nav_modes_names [ i ] . name , quote ) ;
2017-06-16 11:39:01 +02:00
}
return p ;
}
2018-01-09 15:45:18 +01:00
static const char * nav_modes_flags_string ( nav_modes_t flags ) {
2017-12-02 18:38:33 +01:00
static char buf [ 256 ] ;
buf [ 0 ] = 0 ;
2017-12-07 17:34:08 +01:00
append_nav_modes ( buf , buf + sizeof ( buf ) , flags , " " , " " ) ;
2017-12-02 18:38:33 +01:00
return buf ;
}
2018-01-09 15:45:18 +01:00
static const char * addrtype_enum_string ( addrtype_t type ) {
2016-09-14 18:01:07 +02:00
switch ( type ) {
case ADDR_ADSB_ICAO :
return " adsb_icao " ;
case ADDR_ADSB_ICAO_NT :
return " adsb_icao_nt " ;
case ADDR_ADSR_ICAO :
return " adsr_icao " ;
2016-09-15 16:30:34 +02:00
case ADDR_TISB_ICAO :
return " tisb_icao " ;
case ADDR_ADSB_OTHER :
return " adsb_other " ;
2016-09-14 18:01:07 +02:00
case ADDR_ADSR_OTHER :
return " adsr_other " ;
2016-09-15 16:30:34 +02:00
case ADDR_TISB_OTHER :
return " tisb_other " ;
case ADDR_TISB_TRACKFILE :
return " tisb_trackfile " ;
2016-09-14 18:01:07 +02:00
default :
return " unknown " ;
}
}
2018-03-07 21:09:23 +01:00
static const char * emergency_enum_string ( emergency_t emergency )
{
switch ( emergency ) {
case EMERGENCY_NONE : return " none " ;
case EMERGENCY_GENERAL : return " general " ;
case EMERGENCY_LIFEGUARD : return " lifeguard " ;
case EMERGENCY_MINFUEL : return " minfuel " ;
case EMERGENCY_NORDO : return " nordo " ;
case EMERGENCY_UNLAWFUL : return " unlawful " ;
case EMERGENCY_DOWNED : return " downed " ;
default : return " reserved " ;
}
}
static const char * sil_type_enum_string ( sil_type_t type )
{
switch ( type ) {
case SIL_UNKNOWN : return " unknown " ;
case SIL_PER_HOUR : return " perhour " ;
case SIL_PER_SAMPLE : return " persample " ;
default : return " invalid " ;
}
}
2019-03-19 19:44:09 +01:00
static const char * nav_altitude_source_enum_string ( nav_altitude_source_t src )
{
switch ( src ) {
case NAV_ALT_INVALID : return " invalid " ;
case NAV_ALT_UNKNOWN : return " unknown " ;
case NAV_ALT_AIRCRAFT : return " aircraft " ;
case NAV_ALT_MCP : return " mcp " ;
case NAV_ALT_FMS : return " fms " ;
default : return " invalid " ;
}
}
2015-01-15 21:54:22 +01:00
char * generateAircraftJson ( const char * url_path , int * len ) {
2015-02-10 22:49:37 +01:00
uint64_t now = mstime ( ) ;
2015-01-22 14:22:16 +01:00
struct aircraft * a ;
2018-03-07 21:10:50 +01:00
int buflen = 32768 ; // The initial buffer is resized as needed
2015-01-06 00:20:03 +01:00
char * buf = ( char * ) malloc ( buflen ) , * p = buf , * end = buf + buflen ;
2018-03-07 21:10:50 +01:00
char * line_start ;
2015-01-06 00:20:03 +01:00
int first = 1 ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
2015-01-21 12:54:55 +01:00
MODES_NOTUSED ( url_path ) ;
2015-01-15 21:54:22 +01:00
2018-03-07 21:10:50 +01:00
_messageNow = now ;
p = safe_snprintf ( p , end ,
" { \" now \" : %.1f, \n "
" \" messages \" : %u, \n "
" \" aircraft \" : [ " ,
now / 1000.0 ,
Modes . stats_current . messages_total + Modes . stats_alltime . messages_total ) ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
2015-01-22 14:22:16 +01:00
for ( a = Modes . aircrafts ; a ; a = a - > next ) {
2015-01-22 14:29:13 +01:00
if ( a - > messages < 2 ) { // basic filter for bad decodes
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
continue ;
}
2017-06-15 19:16:51 +02:00
if ( first )
2015-01-06 00:20:03 +01:00
first = 0 ;
else
* p + + = ' , ' ;
2017-06-15 19:16:51 +02:00
2018-03-07 21:10:50 +01:00
retry :
line_start = p ;
p = safe_snprintf ( p , end , " \n { \" hex \" : \" %s%06x \" " , ( a - > addr & MODES_NON_ICAO_ADDRESS ) ? " ~ " : " " , a - > addr & 0xFFFFFF ) ;
2016-09-14 18:01:07 +02:00
if ( a - > addrtype ! = ADDR_ADSB_ICAO )
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " , \" type \" : \" %s \" " , addrtype_enum_string ( a - > addrtype ) ) ;
2016-08-27 15:34:14 +02:00
if ( trackDataValid ( & a - > callsign_valid ) )
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " , \" flight \" : \" %s \" " , jsonEscapeString ( a - > callsign ) ) ;
2016-08-27 15:34:14 +02:00
if ( trackDataValid ( & a - > airground_valid ) & & a - > airground_valid . source > = SOURCE_MODE_S_CHECKED & & a - > airground = = AG_GROUND )
2018-03-08 18:34:34 +01:00
p = safe_snprintf ( p , end , " , \" alt_baro \" : \" ground \" " ) ;
2017-06-15 19:07:40 +02:00
else {
2017-12-07 17:34:08 +01:00
if ( trackDataValid ( & a - > altitude_baro_valid ) )
2018-03-08 18:34:34 +01:00
p = safe_snprintf ( p , end , " , \" alt_baro \" :%d " , a - > altitude_baro ) ;
2017-06-15 19:07:40 +02:00
if ( trackDataValid ( & a - > altitude_geom_valid ) )
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " , \" alt_geom \" :%d " , a - > altitude_geom ) ;
2017-06-15 19:07:40 +02:00
}
if ( trackDataValid ( & a - > gs_valid ) )
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " , \" gs \" :%.1f " , a - > gs ) ;
2017-06-15 19:07:40 +02:00
if ( trackDataValid ( & a - > ias_valid ) )
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " , \" ias \" :%u " , a - > ias ) ;
2017-06-15 19:07:40 +02:00
if ( trackDataValid ( & a - > tas_valid ) )
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " , \" tas \" :%u " , a - > tas ) ;
2017-06-15 19:07:40 +02:00
if ( trackDataValid ( & a - > mach_valid ) )
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " , \" mach \" :%.3f " , a - > mach ) ;
if ( trackDataValid ( & a - > track_valid ) )
p = safe_snprintf ( p , end , " , \" track \" :%.1f " , a - > track ) ;
if ( trackDataValid ( & a - > track_rate_valid ) )
p = safe_snprintf ( p , end , " , \" track_rate \" :%.2f " , a - > track_rate ) ;
2017-06-15 19:07:40 +02:00
if ( trackDataValid ( & a - > roll_valid ) )
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " , \" roll \" :%.1f " , a - > roll ) ;
if ( trackDataValid ( & a - > mag_heading_valid ) )
p = safe_snprintf ( p , end , " , \" mag_heading \" :%.1f " , a - > mag_heading ) ;
if ( trackDataValid ( & a - > true_heading_valid ) )
p = safe_snprintf ( p , end , " , \" true_heading \" :%.1f " , a - > true_heading ) ;
if ( trackDataValid ( & a - > baro_rate_valid ) )
p = safe_snprintf ( p , end , " , \" baro_rate \" :%d " , a - > baro_rate ) ;
if ( trackDataValid ( & a - > geom_rate_valid ) )
p = safe_snprintf ( p , end , " , \" geom_rate \" :%d " , a - > geom_rate ) ;
if ( trackDataValid ( & a - > squawk_valid ) )
p = safe_snprintf ( p , end , " , \" squawk \" : \" %04x \" " , a - > squawk ) ;
if ( trackDataValid ( & a - > emergency_valid ) )
p = safe_snprintf ( p , end , " , \" emergency \" : \" %s \" " , emergency_enum_string ( a - > emergency ) ) ;
2017-12-07 17:34:08 +01:00
if ( a - > category ! = 0 )
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " , \" category \" : \" %02X \" " , a - > category ) ;
if ( trackDataValid ( & a - > nav_qnh_valid ) )
p = safe_snprintf ( p , end , " , \" nav_qnh \" :%.1f " , a - > nav_qnh ) ;
2019-03-19 19:44:09 +01:00
if ( trackDataValid ( & a - > nav_altitude_mcp_valid ) )
p = safe_snprintf ( p , end , " , \" nav_altitude_mcp \" :%d " , a - > nav_altitude_mcp ) ;
if ( trackDataValid ( & a - > nav_altitude_fms_valid ) )
p = safe_snprintf ( p , end , " , \" nav_altitude_fms \" :%d " , a - > nav_altitude_fms ) ;
2017-12-07 17:34:08 +01:00
if ( trackDataValid ( & a - > nav_heading_valid ) )
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " , \" nav_heading \" :%.1f " , a - > nav_heading ) ;
2017-12-07 17:34:08 +01:00
if ( trackDataValid ( & a - > nav_modes_valid ) ) {
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " , \" nav_modes \" :[ " ) ;
2017-12-07 17:34:08 +01:00
p = append_nav_modes ( p , end , a - > nav_modes , " \" " , " , " ) ;
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " ] " ) ;
2017-06-16 11:39:01 +02:00
}
2018-03-07 21:10:50 +01:00
if ( trackDataValid ( & a - > position_valid ) )
p = safe_snprintf ( p , end , " , \" lat \" :%f, \" lon \" :%f, \" nic \" :%u, \" rc \" :%u, \" seen_pos \" :%.1f " , a - > lat , a - > lon , a - > pos_nic , a - > pos_rc , ( now - a - > position_valid . updated ) / 1000.0 ) ;
if ( a - > adsb_version > = 0 )
p = safe_snprintf ( p , end , " , \" version \" :%d " , a - > adsb_version ) ;
if ( trackDataValid ( & a - > nic_baro_valid ) )
p = safe_snprintf ( p , end , " , \" nic_baro \" :%u " , a - > nic_baro ) ;
if ( trackDataValid ( & a - > nac_p_valid ) )
p = safe_snprintf ( p , end , " , \" nac_p \" :%u " , a - > nac_p ) ;
if ( trackDataValid ( & a - > nac_v_valid ) )
p = safe_snprintf ( p , end , " , \" nac_v \" :%u " , a - > nac_v ) ;
if ( trackDataValid ( & a - > sil_valid ) )
p = safe_snprintf ( p , end , " , \" sil \" :%u " , a - > sil ) ;
if ( a - > sil_type ! = SIL_INVALID )
p = safe_snprintf ( p , end , " , \" sil_type \" : \" %s \" " , sil_type_enum_string ( a - > sil_type ) ) ;
if ( trackDataValid ( & a - > gva_valid ) )
p = safe_snprintf ( p , end , " , \" gva \" :%u " , a - > gva ) ;
if ( trackDataValid ( & a - > sda_valid ) )
p = safe_snprintf ( p , end , " , \" sda \" :%u " , a - > sda ) ;
p = safe_snprintf ( p , end , " , \" mlat \" : " ) ;
2016-08-27 15:34:14 +02:00
p = append_flags ( p , end , a , SOURCE_MLAT ) ;
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " , \" tisb \" : " ) ;
2016-08-27 15:34:14 +02:00
p = append_flags ( p , end , a , SOURCE_TISB ) ;
2015-01-06 00:20:03 +01:00
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " , \" messages \" :%ld, \" seen \" :%.1f, \" rssi \" :%.1f} " ,
2015-02-10 22:49:37 +01:00
a - > messages , ( now - a - > seen ) / 1000.0 ,
2015-01-22 16:30:34 +01:00
10 * log10 ( ( a - > signalLevel [ 0 ] + a - > signalLevel [ 1 ] + a - > signalLevel [ 2 ] + a - > signalLevel [ 3 ] +
a - > signalLevel [ 4 ] + a - > signalLevel [ 5 ] + a - > signalLevel [ 6 ] + a - > signalLevel [ 7 ] + 1e-5 ) / 8 ) ) ;
2017-06-15 19:16:51 +02:00
2018-12-31 12:17:28 +01:00
if ( ( p + 10 ) > = end ) { // +10 to leave some space for the final line
2018-03-07 21:10:50 +01:00
// overran the buffer
int used = line_start - buf ;
2015-01-06 00:20:03 +01:00
buflen * = 2 ;
buf = ( char * ) realloc ( buf , buflen ) ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
p = buf + used ;
2015-01-06 00:20:03 +01:00
end = buf + buflen ;
2018-03-07 21:10:50 +01:00
goto retry ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
}
}
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " \n ] \n } \n " ) ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
* len = p - buf ;
return buf ;
}
2014-11-23 17:02:11 +01:00
2015-01-20 18:16:35 +01:00
static char * appendStatsJson ( char * p ,
char * end ,
struct stats * st ,
const char * key )
{
2015-01-22 21:18:51 +01:00
int i ;
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end ,
" \" %s \" :{ \" start \" :%.1f, \" end \" :%.1f " ,
key ,
st - > start / 1000.0 ,
st - > end / 1000.0 ) ;
2015-01-22 21:18:51 +01:00
if ( ! Modes . net_only ) {
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end ,
" , \" local \" :{ \" samples_processed \" :%llu "
" , \" samples_dropped \" :%llu "
" , \" modeac \" :%u "
" , \" modes \" :%u "
" , \" bad \" :%u "
" , \" unknown_icao \" :%u " ,
( unsigned long long ) st - > samples_processed ,
( unsigned long long ) st - > samples_dropped ,
st - > demod_modeac ,
st - > demod_preambles ,
st - > demod_rejected_bad ,
st - > demod_rejected_unknown_icao ) ;
2015-01-22 21:18:51 +01:00
for ( i = 0 ; i < = Modes . nfix_crc ; + + i ) {
2018-03-07 21:10:50 +01:00
if ( i = = 0 ) p = safe_snprintf ( p , end , " , \" accepted \" :[%u " , st - > demod_accepted [ i ] ) ;
else p = safe_snprintf ( p , end , " ,%u " , st - > demod_accepted [ i ] ) ;
2015-01-22 21:18:51 +01:00
}
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " ] " ) ;
2015-01-22 21:18:51 +01:00
2015-06-16 11:13:25 +02:00
if ( st - > signal_power_sum > 0 & & st - > signal_power_count > 0 )
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " , \" signal \" :%.1f " , 10 * log10 ( st - > signal_power_sum / st - > signal_power_count ) ) ;
2015-06-16 11:13:25 +02:00
if ( st - > noise_power_sum > 0 & & st - > noise_power_count > 0 )
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " , \" noise \" :%.1f " , 10 * log10 ( st - > noise_power_sum / st - > noise_power_count ) ) ;
2015-01-22 21:18:51 +01:00
if ( st - > peak_signal_power > 0 )
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " , \" peak_signal \" :%.1f " , 10 * log10 ( st - > peak_signal_power ) ) ;
2015-01-22 21:18:51 +01:00
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " , \" strong_signals \" :%d} " , st - > strong_signal_count ) ;
2015-01-22 21:18:51 +01:00
}
2015-01-20 18:16:35 +01:00
2015-01-22 21:18:51 +01:00
if ( Modes . net ) {
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end ,
" , \" remote \" :{ \" modeac \" :%u "
" , \" modes \" :%u "
" , \" bad \" :%u "
" , \" unknown_icao \" :%u " ,
st - > remote_received_modeac ,
st - > remote_received_modes ,
st - > remote_rejected_bad ,
st - > remote_rejected_unknown_icao ) ;
2015-01-22 21:18:51 +01:00
for ( i = 0 ; i < = Modes . nfix_crc ; + + i ) {
2018-03-07 21:10:50 +01:00
if ( i = = 0 ) p = safe_snprintf ( p , end , " , \" accepted \" :[%u " , st - > remote_accepted [ i ] ) ;
else p = safe_snprintf ( p , end , " ,%u " , st - > remote_accepted [ i ] ) ;
2015-01-22 21:18:51 +01:00
}
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " ]} " ) ;
2015-01-22 21:18:51 +01:00
}
2015-01-23 03:03:57 +01:00
{
uint64_t demod_cpu_millis = ( uint64_t ) st - > demod_cpu . tv_sec * 1000UL + st - > demod_cpu . tv_nsec / 1000000UL ;
uint64_t reader_cpu_millis = ( uint64_t ) st - > reader_cpu . tv_sec * 1000UL + st - > reader_cpu . tv_nsec / 1000000UL ;
uint64_t background_cpu_millis = ( uint64_t ) st - > background_cpu . tv_sec * 1000UL + st - > background_cpu . tv_nsec / 1000000UL ;
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end ,
" , \" cpr \" :{ \" surface \" :%u "
" , \" airborne \" :%u "
" , \" global_ok \" :%u "
" , \" global_bad \" :%u "
" , \" global_range \" :%u "
" , \" global_speed \" :%u "
" , \" global_skipped \" :%u "
" , \" local_ok \" :%u "
" , \" local_aircraft_relative \" :%u "
" , \" local_receiver_relative \" :%u "
" , \" local_skipped \" :%u "
" , \" local_range \" :%u "
" , \" local_speed \" :%u "
" , \" filtered \" :%u} "
" , \" altitude_suppressed \" :%u "
" , \" cpu \" :{ \" demod \" :%llu, \" reader \" :%llu, \" background \" :%llu} "
" , \" tracks \" :{ \" all \" :%u "
" , \" single_message \" :%u} "
" , \" messages \" :%u} " ,
st - > cpr_surface ,
st - > cpr_airborne ,
st - > cpr_global_ok ,
st - > cpr_global_bad ,
st - > cpr_global_range_checks ,
st - > cpr_global_speed_checks ,
st - > cpr_global_skipped ,
st - > cpr_local_ok ,
st - > cpr_local_aircraft_relative ,
st - > cpr_local_receiver_relative ,
st - > cpr_local_skipped ,
st - > cpr_local_range_checks ,
st - > cpr_local_speed_checks ,
st - > cpr_filtered ,
st - > suppressed_altitude_messages ,
( unsigned long long ) demod_cpu_millis ,
( unsigned long long ) reader_cpu_millis ,
( unsigned long long ) background_cpu_millis ,
st - > unique_aircraft ,
st - > single_message_aircraft ,
st - > messages_total ) ;
2015-01-23 03:11:44 +01:00
}
2015-01-22 02:21:53 +01:00
2015-01-20 18:16:35 +01:00
return p ;
}
2017-06-15 19:16:51 +02:00
2015-01-20 18:16:35 +01:00
char * generateStatsJson ( const char * url_path , int * len ) {
struct stats add ;
2015-01-22 21:18:51 +01:00
char * buf = ( char * ) malloc ( 4096 ) , * p = buf , * end = buf + 4096 ;
2015-01-20 18:16:35 +01:00
MODES_NOTUSED ( url_path ) ;
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " { \n " ) ;
2015-01-20 18:16:35 +01:00
p = appendStatsJson ( p , end , & Modes . stats_current , " latest " ) ;
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " , \n " ) ;
2015-01-20 18:16:35 +01:00
2015-01-22 21:45:53 +01:00
p = appendStatsJson ( p , end , & Modes . stats_1min [ Modes . stats_latest_1min ] , " last1min " ) ;
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " , \n " ) ;
2015-01-20 18:16:35 +01:00
2015-01-22 21:45:53 +01:00
p = appendStatsJson ( p , end , & Modes . stats_5min , " last5min " ) ;
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " , \n " ) ;
2015-01-20 18:16:35 +01:00
2015-01-22 21:45:53 +01:00
p = appendStatsJson ( p , end , & Modes . stats_15min , " last15min " ) ;
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " , \n " ) ;
2015-01-20 18:16:35 +01:00
add_stats ( & Modes . stats_alltime , & Modes . stats_current , & add ) ;
p = appendStatsJson ( p , end , & add , " total " ) ;
2018-03-07 21:10:50 +01:00
p = safe_snprintf ( p , end , " \n } \n " ) ;
2015-01-20 18:16:35 +01:00
assert ( p < = end ) ;
* len = p - buf ;
return buf ;
}
2014-12-10 18:05:22 +01:00
//
// Return a description of the receiver in json.
//
2015-01-15 21:54:22 +01:00
char * generateReceiverJson ( const char * url_path , int * len )
2014-12-10 18:05:22 +01:00
{
char * buf = ( char * ) malloc ( 1024 ) , * p = buf ;
2015-01-15 23:23:53 +01:00
int history_size ;
2014-12-10 18:05:22 +01:00
2015-01-21 12:54:55 +01:00
MODES_NOTUSED ( url_path ) ;
2015-01-15 21:54:22 +01:00
2015-01-15 23:23:53 +01:00
// work out number of valid history entries
if ( Modes . json_aircraft_history [ HISTORY_SIZE - 1 ] . content = = NULL )
history_size = Modes . json_aircraft_history_next ;
else
history_size = HISTORY_SIZE ;
2014-12-10 18:05:22 +01:00
p + = sprintf ( p , " { " \
" \" version \" : \" %s \" , "
2015-02-10 23:24:22 +01:00
" \" refresh \" : %.0f, "
2015-01-15 21:55:55 +01:00
" \" history \" : %d " ,
2015-02-10 23:24:22 +01:00
MODES_DUMP1090_VERSION , 1.0 * Modes . json_interval , history_size ) ;
2014-12-10 18:05:22 +01:00
2014-12-27 21:52:56 +01:00
if ( Modes . json_location_accuracy & & ( Modes . fUserLat ! = 0.0 | | Modes . fUserLon ! = 0.0 ) ) {
if ( Modes . json_location_accuracy = = 1 ) {
p + = sprintf ( p , " , " \
" \" lat \" : %.2f, "
" \" lon \" : %.2f " ,
Modes . fUserLat , Modes . fUserLon ) ; // round to 2dp - about 0.5-1km accuracy - for privacy reasons
} else {
p + = sprintf ( p , " , " \
" \" lat \" : %.6f, "
" \" lon \" : %.6f " ,
Modes . fUserLat , Modes . fUserLon ) ; // exact location
}
2014-12-10 18:05:22 +01:00
}
p + = sprintf ( p , " } \n " ) ;
* len = ( p - buf ) ;
return buf ;
}
2015-01-15 21:55:55 +01:00
char * generateHistoryJson ( const char * url_path , int * len )
{
int history_index = - 1 ;
if ( sscanf ( url_path , " /data/history_%d.json " , & history_index ) ! = 1 )
return NULL ;
if ( history_index < 0 | | history_index > = HISTORY_SIZE )
return NULL ;
if ( ! Modes . json_aircraft_history [ history_index ] . content )
return NULL ;
* len = Modes . json_aircraft_history [ history_index ] . clen ;
return strdup ( Modes . json_aircraft_history [ history_index ] . content ) ;
}
2014-12-10 18:05:22 +01:00
// Write JSON to file
2015-01-15 21:54:22 +01:00
void writeJsonToFile ( const char * file , char * ( * generator ) ( const char * , int * ) )
2014-11-23 17:02:11 +01:00
{
# ifndef _WIN32
2015-01-15 21:54:22 +01:00
char pathbuf [ PATH_MAX ] ;
2014-11-23 17:02:11 +01:00
char tmppath [ PATH_MAX ] ;
int fd ;
int len = 0 ;
2014-11-23 17:32:45 +01:00
mode_t mask ;
2014-12-10 18:05:22 +01:00
char * content ;
2014-11-23 17:02:11 +01:00
2015-01-15 21:54:22 +01:00
if ( ! Modes . json_dir )
return ;
snprintf ( tmppath , PATH_MAX , " %s/%s.XXXXXX " , Modes . json_dir , file ) ;
2014-11-23 17:02:11 +01:00
tmppath [ PATH_MAX - 1 ] = 0 ;
fd = mkstemp ( tmppath ) ;
if ( fd < 0 )
return ;
2017-06-15 19:16:51 +02:00
2014-11-23 17:32:45 +01:00
mask = umask ( 0 ) ;
umask ( mask ) ;
fchmod ( fd , 0644 & ~ mask ) ;
2015-01-15 21:54:22 +01:00
snprintf ( pathbuf , PATH_MAX , " /data/%s " , file ) ;
pathbuf [ PATH_MAX - 1 ] = 0 ;
content = generator ( pathbuf , & len ) ;
2014-12-10 18:05:22 +01:00
2014-11-23 17:02:11 +01:00
if ( write ( fd , content , len ) ! = len )
goto error_1 ;
if ( close ( fd ) < 0 )
goto error_2 ;
2015-01-15 21:54:22 +01:00
snprintf ( pathbuf , PATH_MAX , " %s/%s " , Modes . json_dir , file ) ;
pathbuf [ PATH_MAX - 1 ] = 0 ;
rename ( tmppath , pathbuf ) ;
2014-12-10 18:05:22 +01:00
free ( content ) ;
2014-11-23 17:02:11 +01:00
return ;
error_1 :
close ( fd ) ;
error_2 :
unlink ( tmppath ) ;
2014-12-10 18:05:22 +01:00
free ( content ) ;
2014-11-23 17:02:11 +01:00
return ;
# endif
}
2014-12-10 18:05:22 +01:00
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
//
//=========================================================================
//
// This function polls the clients using read() in order to receive new
// messages from the net.
//
// The message is supposed to be separated from the next message by the
// separator 'sep', which is a null-terminated C string.
//
// Every full message received is decoded and passed to the higher layers
// calling the function's 'handler'.
//
// The handler returns 0 on success, or 1 to signal this function we should
// close the connection with the client in case of non-recoverable errors.
//
2015-06-26 18:50:51 +02:00
static void modesReadFromClient ( struct client * c ) {
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
int left ;
int nread ;
2013-09-20 17:48:15 +02:00
int bContinue = 1 ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
2016-12-29 18:54:53 +01:00
while ( bContinue ) {
left = MODES_CLIENT_BUF_SIZE - c - > buflen - 1 ; // leave 1 extra byte for NUL termination in the ASCII case
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
// If our buffer is full discard it, this is some badly formatted shit
2013-09-20 17:48:15 +02:00
if ( left < = 0 ) {
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
c - > buflen = 0 ;
left = MODES_CLIENT_BUF_SIZE ;
// If there is garbage, read more to discard it ASAP
}
2014-04-25 15:48:14 +02:00
# ifndef _WIN32
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
nread = read ( c - > fd , c - > buf + c - > buflen , left ) ;
2014-04-25 15:48:14 +02:00
# else
nread = recv ( c - > fd , c - > buf + c - > buflen , left , 0 ) ;
if ( nread < 0 ) { errno = WSAGetLastError ( ) ; }
# endif
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
2013-09-20 17:48:15 +02:00
// If we didn't get all the data we asked for, then return once we've processed what we did get.
if ( nread ! = left ) {
bContinue = 0 ;
}
2014-10-31 18:58:03 +01:00
if ( nread = = 0 ) { // End of file
modesCloseClient ( c ) ;
return ;
}
2014-05-10 00:44:11 +02:00
# ifndef _WIN32
2016-08-27 15:34:14 +02:00
if ( nread < 0 & & ( errno = = EAGAIN | | errno = = EWOULDBLOCK ) ) // No data available (not really an error)
2014-05-10 00:44:11 +02:00
# else
2016-08-27 15:34:14 +02:00
if ( nread < 0 & & errno = = EWOULDBLOCK ) // No data available (not really an error)
2014-05-10 00:44:11 +02:00
# endif
2016-08-27 15:34:14 +02:00
{
2014-10-01 13:29:16 +02:00
return ;
2013-09-20 17:48:15 +02:00
}
2014-10-31 18:58:03 +01:00
if ( nread < 0 ) { // Other errors
modesCloseClient ( c ) ;
return ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
}
2014-10-31 18:58:03 +01:00
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
c - > buflen + = nread ;
2016-12-29 18:54:53 +01:00
char * som = c - > buf ; // first byte of next message
char * eod = som + c - > buflen ; // one byte past end of data
char * p ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
2016-12-29 18:54:53 +01:00
switch ( c - > service - > read_mode ) {
case READ_MODE_IGNORE :
// drop the bytes on the floor
som = eod ;
break ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
2016-12-29 18:54:53 +01:00
case READ_MODE_BEAST :
2013-09-20 17:48:15 +02:00
// This is the Beast Binary scanning case.
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
// If there is a complete message still in the buffer, there must be the separator 'sep'
// in the buffer, note that we full-scan the buffer at every read for simplicity.
2016-12-29 18:54:53 +01:00
while ( som < eod & & ( ( p = memchr ( som , ( char ) 0x1a , eod - som ) ) ! = NULL ) ) { // The first byte of buffer 'should' be 0x1a
som = p ; // consume garbage up to the 0x1a
+ + p ; // skip 0x1a
if ( p > = eod ) {
// Incomplete message in buffer, retry later
break ;
}
char * eom ; // one byte past end of message
if ( * p = = ' 1 ' ) {
eom = p + MODEAC_MSG_BYTES + 8 ; // point past remainder of message
} else if ( * p = = ' 2 ' ) {
eom = p + MODES_SHORT_MSG_BYTES + 8 ;
} else if ( * p = = ' 3 ' ) {
eom = p + MODES_LONG_MSG_BYTES + 8 ;
} else if ( * p = = ' 4 ' ) {
eom = p + MODES_LONG_MSG_BYTES + 8 ;
} else if ( * p = = ' 5 ' ) {
eom = p + MODES_LONG_MSG_BYTES + 8 ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
} else {
2016-12-29 18:54:53 +01:00
// Not a valid beast message, skip 0x1a and try again
+ + som ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
continue ;
}
2016-12-29 18:54:53 +01:00
2014-02-23 02:55:34 +01:00
// we need to be careful of double escape characters in the message body
2016-12-29 18:54:53 +01:00
for ( p = som + 1 ; p < eod & & p < eom ; p + + ) {
2014-02-23 02:55:34 +01:00
if ( 0x1A = = * p ) {
2016-12-29 18:54:53 +01:00
p + + ;
eom + + ;
2014-02-23 02:55:34 +01:00
}
}
2016-12-29 18:54:53 +01:00
if ( eom > eod ) { // Incomplete message in buffer, retry later
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
break ;
}
2016-12-29 18:54:53 +01:00
2016-12-27 20:07:10 +01:00
// Have a 0x1a followed by 1/2/3/4/5 - pass message to handler.
2016-12-29 18:54:53 +01:00
if ( c - > service - > read_handler ( c , som + 1 ) ) {
2014-08-15 10:39:35 +02:00
modesCloseClient ( c ) ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
return ;
}
2016-12-29 18:54:53 +01:00
// advance to next message
som = eom ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
}
2016-12-29 18:55:56 +01:00
break ;
case READ_MODE_BEAST_COMMAND :
while ( som < eod & & ( ( p = memchr ( som , ( char ) 0x1a , eod - som ) ) ! = NULL ) ) { // The first byte of buffer 'should' be 0x1a
char * eom ; // one byte past end of message
som = p ; // consume garbage up to the 0x1a
+ + p ; // skip 0x1a
if ( p > = eod ) {
// Incomplete message in buffer, retry later
break ;
}
if ( * p = = ' 1 ' ) {
eom = p + 2 ;
} else {
// Not a valid beast command, skip 0x1a and try again
+ + som ;
continue ;
}
// we need to be careful of double escape characters in the message body
for ( p = som + 1 ; p < eod & & p < eom ; p + + ) {
if ( 0x1A = = * p ) {
p + + ;
eom + + ;
}
}
if ( eom > eod ) { // Incomplete message in buffer, retry later
break ;
}
// Have a 0x1a followed by 1 - pass message to handler.
if ( c - > service - > read_handler ( c , som + 1 ) ) {
modesCloseClient ( c ) ;
return ;
}
// advance to next message
som = eom ;
}
2016-12-29 18:54:53 +01:00
break ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
2016-12-29 18:54:53 +01:00
case READ_MODE_ASCII :
2013-09-20 17:48:15 +02:00
//
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
// This is the ASCII scanning case, AVR RAW or HTTP at present
// If there is a complete message still in the buffer, there must be the separator 'sep'
// in the buffer, note that we full-scan the buffer at every read for simplicity.
2016-12-29 18:54:53 +01:00
// Always NUL-terminate so we are free to use strstr()
// nb: we never fill the last byte of the buffer with read data (see above) so this is safe
* eod = ' \0 ' ;
while ( som < eod & & ( p = strstr ( som , c - > service - > read_sep ) ) ! = NULL ) { // end of first message if found
* p = ' \0 ' ; // The handler expects null terminated strings
if ( c - > service - > read_handler ( c , som ) ) { // Pass message to handler.
2014-08-15 10:39:35 +02:00
modesCloseClient ( c ) ; // Handler returns 1 on error to signal we .
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
return ; // should close the client connection
}
2016-12-29 18:54:53 +01:00
som = p + strlen ( c - > service - > read_sep ) ; // Move to start of next message
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
}
2016-12-29 18:54:53 +01:00
break ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
}
2014-02-24 11:28:35 +01:00
2016-12-29 18:54:53 +01:00
if ( som > c - > buf ) { // We processed something - so
c - > buflen = eod - som ; // Update the unprocessed buffer length
memmove ( c - > buf , som , c - > buflen ) ; // Move what's remaining to the start of the buffer
2013-09-20 17:48:15 +02:00
} else { // If no message was decoded process the next client
2014-10-31 18:58:03 +01:00
return ;
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
}
}
}
2014-10-03 23:55:21 +02:00
2017-12-07 17:34:08 +01:00
__attribute__ ( ( format ( printf , 4 , 5 ) ) ) static char * appendFATSV ( char * p , char * end , const char * field , const char * format , . . . )
2017-12-02 18:38:33 +01:00
{
va_list ap ;
va_start ( ap , format ) ;
p = safe_snprintf ( p , end , " %s \t " , field ) ;
p = safe_vsnprintf ( p , end , format , ap ) ;
p = safe_snprintf ( p , end , " \t " ) ;
2018-01-09 18:13:34 +01:00
va_end ( ap ) ;
2017-12-02 18:38:33 +01:00
return p ;
}
2018-02-22 08:42:04 +01:00
# define TSV_MAX_PACKET_SIZE 600
2019-03-19 19:10:38 +01:00
# define TSV_VERSION "4E"
2014-12-08 20:56:45 +01:00
2016-12-27 20:07:10 +01:00
static void writeFATSVPositionUpdate ( float lat , float lon , float alt )
{
static float last_lat , last_lon , last_alt ;
if ( lat = = last_lat & & lon = = last_lon & & alt = = last_alt )
return ;
last_lat = lat ;
last_lon = lon ;
last_alt = alt ;
char * p = prepareWrite ( & Modes . fatsv_out , TSV_MAX_PACKET_SIZE ) ;
if ( ! p )
return ;
char * end = p + TSV_MAX_PACKET_SIZE ;
2019-03-19 19:10:38 +01:00
p = appendFATSV ( p , end , " _v " , " %s " , TSV_VERSION ) ;
2017-12-02 18:38:33 +01:00
p = appendFATSV ( p , end , " clock " , " % " PRIu64 , messageNow ( ) / 1000 ) ;
p = appendFATSV ( p , end , " type " , " %s " , " location_update " ) ;
p = appendFATSV ( p , end , " lat " , " %.5f " , lat ) ;
p = appendFATSV ( p , end , " lon " , " %.5f " , lon ) ;
p = appendFATSV ( p , end , " alt " , " %.0f " , alt ) ;
p = appendFATSV ( p , end , " altref " , " %s " , " egm96_meters " ) ;
- - p ; // remove last tab
p = safe_snprintf ( p , end , " \n " ) ;
2016-12-27 20:07:10 +01:00
if ( p < = end )
completeWrite ( & Modes . fatsv_out , p ) ;
else
fprintf ( stderr , " fatsv: output too large (max %d, overran by %d) \n " , TSV_MAX_PACKET_SIZE , ( int ) ( p - end ) ) ;
}
2016-08-28 02:29:37 +02:00
static void writeFATSVEventMessage ( struct modesMessage * mm , const char * datafield , unsigned char * data , size_t len )
{
char * p = prepareWrite ( & Modes . fatsv_out , TSV_MAX_PACKET_SIZE ) ;
if ( ! p )
return ;
char * end = p + TSV_MAX_PACKET_SIZE ;
2016-09-14 18:02:23 +02:00
2019-03-19 19:10:38 +01:00
p = appendFATSV ( p , end , " _v " , " %s " , TSV_VERSION ) ;
2017-12-02 18:38:33 +01:00
p = appendFATSV ( p , end , " clock " , " % " PRIu64 , messageNow ( ) / 1000 ) ;
p = appendFATSV ( p , end , ( mm - > addr & MODES_NON_ICAO_ADDRESS ) ? " otherid " : " hexid " , " %06X " , mm - > addr & 0xFFFFFF ) ;
2016-09-14 18:02:23 +02:00
if ( mm - > addrtype ! = ADDR_ADSB_ICAO ) {
2018-01-09 15:45:18 +01:00
p = appendFATSV ( p , end , " addrtype " , " %s " , addrtype_enum_string ( mm - > addrtype ) ) ;
2016-09-14 18:02:23 +02:00
}
2017-12-02 18:38:33 +01:00
p = safe_snprintf ( p , end , " %s \t " , datafield ) ;
2016-08-28 02:29:37 +02:00
for ( size_t i = 0 ; i < len ; + + i ) {
2017-12-02 18:38:33 +01:00
p = safe_snprintf ( p , end , " %02X " , data [ i ] ) ;
2016-08-28 02:29:37 +02:00
}
2017-12-02 18:38:33 +01:00
p = safe_snprintf ( p , end , " \n " ) ;
2016-08-28 02:29:37 +02:00
if ( p < = end )
completeWrite ( & Modes . fatsv_out , p ) ;
else
fprintf ( stderr , " fatsv: output too large (max %d, overran by %d) \n " , TSV_MAX_PACKET_SIZE , ( int ) ( p - end ) ) ;
# undef bufsize
}
static void writeFATSVEvent ( struct modesMessage * mm , struct aircraft * a )
{
// Write event records for a couple of message types.
if ( ! Modes . fatsv_out . service | | ! Modes . fatsv_out . service - > connections ) {
return ; // not enabled or no active connections
}
if ( a - > messages < 2 ) // basic filter for bad decodes
return ;
switch ( mm - > msgtype ) {
case 20 :
case 21 :
// DF 20/21: Comm-B: emit if they've changed since we last sent them
2017-06-15 19:07:40 +02:00
switch ( mm - > commb_format ) {
case COMMB_DATALINK_CAPS :
// BDS 1,0: data link capability report
if ( memcmp ( mm - > MB , a - > fatsv_emitted_bds_10 , 7 ) ! = 0 ) {
memcpy ( a - > fatsv_emitted_bds_10 , mm - > MB , 7 ) ;
writeFATSVEventMessage ( mm , " datalink_caps " , mm - > MB , 7 ) ;
}
break ;
2016-08-28 02:29:37 +02:00
2017-06-15 19:07:40 +02:00
case COMMB_ACAS_RA :
// BDS 3,0: ACAS RA report
if ( memcmp ( mm - > MB , a - > fatsv_emitted_bds_30 , 7 ) ! = 0 ) {
memcpy ( a - > fatsv_emitted_bds_30 , mm - > MB , 7 ) ;
writeFATSVEventMessage ( mm , " commb_acas_ra " , mm - > MB , 7 ) ;
}
break ;
2016-08-28 02:29:37 +02:00
2017-06-15 19:07:40 +02:00
default :
// nothing
break ;
}
2016-08-28 02:29:37 +02:00
break ;
case 17 :
2016-09-15 15:59:04 +02:00
case 18 :
// DF 17/18: extended squitter
2016-09-24 17:09:38 +02:00
if ( mm - > metype = = 28 & & mm - > mesub = = 2 & & memcmp ( mm - > ME , & a - > fatsv_emitted_es_acas_ra , 7 ) ! = 0 ) {
2016-09-15 15:59:04 +02:00
// type 28 subtype 2: ACAS RA report
// first byte has the type/subtype, remaining bytes match the BDS 3,0 format
2016-09-24 17:09:38 +02:00
memcpy ( a - > fatsv_emitted_es_acas_ra , mm - > ME , 7 ) ;
2016-08-28 13:51:03 +02:00
writeFATSVEventMessage ( mm , " es_acas_ra " , mm - > ME , 7 ) ;
2016-08-28 02:29:37 +02:00
} else if ( mm - > metype = = 31 & & ( mm - > mesub = = 0 | | mm - > mesub = = 1 ) & & memcmp ( mm - > ME , a - > fatsv_emitted_es_status , 7 ) ! = 0 ) {
2016-09-15 15:59:04 +02:00
// aircraft operational status
2016-08-28 02:29:37 +02:00
memcpy ( a - > fatsv_emitted_es_status , mm - > ME , 7 ) ;
writeFATSVEventMessage ( mm , " es_op_status " , mm - > ME , 7 ) ;
}
break ;
}
}
2016-09-26 23:00:52 +02:00
static inline unsigned unsigned_difference ( unsigned v1 , unsigned v2 )
{
return ( v1 > v2 ) ? ( v1 - v2 ) : ( v2 - v1 ) ;
}
2017-06-15 19:07:40 +02:00
static inline float heading_difference ( float h1 , float h2 )
2016-09-26 23:00:52 +02:00
{
2017-06-15 19:07:40 +02:00
float d = fabs ( h1 - h2 ) ;
2016-09-26 23:00:52 +02:00
return ( d < 180 ) ? d : ( 360 - d ) ;
}
2017-12-07 17:34:08 +01:00
__attribute__ ( ( format ( printf , 6 , 7 ) ) ) static char * appendFATSVMeta ( char * p , char * end , const char * field , struct aircraft * a , const data_validity * source , const char * format , . . . )
2017-12-02 18:38:33 +01:00
{
const char * sourcetype ;
switch ( source - > source ) {
case SOURCE_MODE_S :
sourcetype = " U " ;
break ;
case SOURCE_MODE_S_CHECKED :
sourcetype = " S " ;
break ;
case SOURCE_TISB :
sourcetype = " T " ;
break ;
case SOURCE_ADSB :
sourcetype = " A " ;
break ;
default :
// don't want to forward data sourced from these
return p ;
}
if ( ! trackDataValid ( source ) ) {
// expired data
return p ;
}
2018-01-09 18:13:34 +01:00
2017-12-02 18:38:33 +01:00
if ( source - > updated > messageNow ( ) ) {
// data in the future
return p ;
}
2018-01-09 18:13:34 +01:00
2017-12-02 18:38:33 +01:00
if ( source - > updated < a - > fatsv_last_emitted ) {
// not updated since last time
return p ;
}
2018-01-09 18:13:34 +01:00
2017-12-02 18:38:33 +01:00
uint64_t age = ( messageNow ( ) - source - > updated ) / 1000 ;
if ( age > 255 ) {
// too old
return p ;
}
p = safe_snprintf ( p , end , " %s \t " , field ) ;
va_list ap ;
va_start ( ap , format ) ;
p = safe_vsnprintf ( p , end , format , ap ) ;
va_end ( ap ) ;
p = safe_snprintf ( p , end , " % " PRIu64 " %s \t " , age , sourcetype ) ;
return p ;
}
2018-01-09 15:45:18 +01:00
static const char * airground_enum_string ( airground_t ag )
2017-12-07 17:34:08 +01:00
{
switch ( ag ) {
case AG_AIRBORNE :
return " A+ " ;
case AG_GROUND :
return " G+ " ;
default :
return " ? " ;
}
}
2015-06-26 18:50:51 +02:00
static void writeFATSV ( )
{
2014-12-08 20:56:45 +01:00
struct aircraft * a ;
2015-02-10 22:49:37 +01:00
static uint64_t next_update ;
2014-12-08 20:56:45 +01:00
2015-06-26 18:50:51 +02:00
if ( ! Modes . fatsv_out . service | | ! Modes . fatsv_out . service - > connections ) {
return ; // not enabled or no active connections
2014-12-08 20:56:45 +01:00
}
2017-12-02 18:38:33 +01:00
uint64_t now = mstime ( ) ;
2015-02-10 22:49:37 +01:00
if ( now < next_update ) {
2014-12-08 20:56:45 +01:00
return ;
}
2015-02-10 22:49:37 +01:00
// scan once a second at most
next_update = now + 1000 ;
2014-12-08 20:56:45 +01:00
for ( a = Modes . aircrafts ; a ; a = a - > next ) {
2015-01-22 14:29:13 +01:00
if ( a - > messages < 2 ) // basic filter for bad decodes
2015-01-22 14:22:16 +01:00
continue ;
2014-12-08 20:56:45 +01:00
// don't emit if it hasn't updated since last time
if ( a - > seen < a - > fatsv_last_emitted ) {
continue ;
}
2015-01-22 13:30:12 +01:00
2018-02-22 08:42:22 +01:00
// Pretend we are "processing a message" so the validity checks work as expected
_messageNow = a - > seen ;
2017-12-02 18:38:33 +01:00
// some special cases:
2017-12-07 17:34:08 +01:00
int altValid = trackDataValid ( & a - > altitude_baro_valid ) ;
2018-01-09 18:13:34 +01:00
int airgroundValid = trackDataValid ( & a - > airground_valid ) & & a - > airground_valid . source > = SOURCE_MODE_S_CHECKED ; // for non-ADS-B transponders, only trust DF11 CA field
2017-12-02 18:38:33 +01:00
int gsValid = trackDataValid ( & a - > gs_valid ) ;
2017-12-07 17:34:08 +01:00
int squawkValid = trackDataValid ( & a - > squawk_valid ) ;
2017-12-02 18:38:33 +01:00
int callsignValid = trackDataValid ( & a - > callsign_valid ) & & strcmp ( a - > callsign , " " ) ! = 0 ;
int positionValid = trackDataValid ( & a - > position_valid ) ;
2016-08-27 15:34:14 +02:00
// If we are definitely on the ground, suppress any unreliable altitude info.
// When on the ground, ADS-B transponders don't emit an ADS-B message that includes
// altitude, so a corrupted Mode S altitude response from some other in-the-air AC
// might be taken as the "best available altitude" and produce e.g. "airGround G+ alt 31000".
2017-12-07 17:34:08 +01:00
if ( airgroundValid & & a - > airground = = AG_GROUND & & a - > altitude_baro_valid . source < SOURCE_MODE_S_CHECKED )
2016-08-27 15:34:14 +02:00
altValid = 0 ;
2014-12-08 20:56:45 +01:00
2015-06-16 00:13:04 +02:00
// if it hasn't changed altitude, heading, or speed much,
// don't update so often
2017-12-02 18:38:33 +01:00
int changed =
2017-12-07 17:34:08 +01:00
( altValid & & abs ( a - > altitude_baro - a - > fatsv_emitted_altitude_baro ) > = 50 ) | |
( trackDataValid ( & a - > altitude_geom_valid ) & & abs ( a - > altitude_geom - a - > fatsv_emitted_altitude_geom ) > = 50 ) | |
2017-12-02 18:38:33 +01:00
( trackDataValid ( & a - > baro_rate_valid ) & & abs ( a - > baro_rate - a - > fatsv_emitted_baro_rate ) > 500 ) | |
( trackDataValid ( & a - > geom_rate_valid ) & & abs ( a - > geom_rate - a - > fatsv_emitted_geom_rate ) > 500 ) | |
( trackDataValid ( & a - > track_valid ) & & heading_difference ( a - > track , a - > fatsv_emitted_track ) > = 2 ) | |
( trackDataValid ( & a - > track_rate_valid ) & & fabs ( a - > track_rate - a - > fatsv_emitted_track_rate ) > = 0.5 ) | |
( trackDataValid ( & a - > roll_valid ) & & fabs ( a - > roll - a - > fatsv_emitted_roll ) > = 5.0 ) | |
( trackDataValid ( & a - > mag_heading_valid ) & & heading_difference ( a - > mag_heading , a - > fatsv_emitted_mag_heading ) > = 2 ) | |
( trackDataValid ( & a - > true_heading_valid ) & & heading_difference ( a - > true_heading , a - > fatsv_emitted_true_heading ) > = 2 ) | |
2017-12-07 17:34:08 +01:00
( gsValid & & fabs ( a - > gs - a - > fatsv_emitted_gs ) > = 25 ) | |
( trackDataValid ( & a - > ias_valid ) & & unsigned_difference ( a - > ias , a - > fatsv_emitted_ias ) > = 25 ) | |
( trackDataValid ( & a - > tas_valid ) & & unsigned_difference ( a - > tas , a - > fatsv_emitted_tas ) > = 25 ) | |
2017-12-02 18:38:33 +01:00
( trackDataValid ( & a - > mach_valid ) & & fabs ( a - > mach - a - > fatsv_emitted_mach ) > = 0.02 ) ;
int immediate =
2019-03-19 19:44:09 +01:00
( trackDataValid ( & a - > nav_altitude_mcp_valid ) & & unsigned_difference ( a - > nav_altitude_mcp , a - > fatsv_emitted_nav_altitude_mcp ) > 50 ) | |
( trackDataValid ( & a - > nav_altitude_fms_valid ) & & unsigned_difference ( a - > nav_altitude_fms , a - > fatsv_emitted_nav_altitude_fms ) > 50 ) | |
( trackDataValid ( & a - > nav_altitude_src_valid ) & & a - > nav_altitude_src ! = a - > fatsv_emitted_nav_altitude_src ) | |
2017-12-07 17:34:08 +01:00
( trackDataValid ( & a - > nav_heading_valid ) & & heading_difference ( a - > nav_heading , a - > fatsv_emitted_nav_heading ) > 2 ) | |
( trackDataValid ( & a - > nav_modes_valid ) & & a - > nav_modes ! = a - > fatsv_emitted_nav_modes ) | |
( trackDataValid ( & a - > nav_qnh_valid ) & & fabs ( a - > nav_qnh - a - > fatsv_emitted_nav_qnh ) > 0.8 ) | | // 0.8 is the ES message resolution
2017-12-02 18:38:33 +01:00
( callsignValid & & strcmp ( a - > callsign , a - > fatsv_emitted_callsign ) ! = 0 ) | |
( airgroundValid & & a - > airground = = AG_AIRBORNE & & a - > fatsv_emitted_airground = = AG_GROUND ) | |
2017-12-07 17:34:08 +01:00
( airgroundValid & & a - > airground = = AG_GROUND & & a - > fatsv_emitted_airground = = AG_AIRBORNE ) | |
2018-02-19 12:25:49 +01:00
( squawkValid & & a - > squawk ! = a - > fatsv_emitted_squawk ) | |
( trackDataValid ( & a - > emergency_valid ) & & a - > emergency ! = a - > fatsv_emitted_emergency ) ;
2017-06-15 19:30:12 +02:00
2017-12-02 18:38:33 +01:00
uint64_t minAge ;
2017-06-15 19:30:12 +02:00
if ( immediate ) {
// a change we want to emit right away
2016-08-27 15:34:14 +02:00
minAge = 0 ;
} else if ( ! positionValid ) {
// don't send mode S very often
minAge = 30000 ;
} else if ( ( airgroundValid & & a - > airground = = AG_GROUND ) | |
2017-12-07 17:34:08 +01:00
( altValid & & a - > altitude_baro < 500 & & ( ! gsValid | | a - > gs < 200 ) ) | |
( gsValid & & a - > gs < 100 & & ( ! altValid | | a - > altitude_baro < 1000 ) ) ) {
2016-08-27 15:34:14 +02:00
// we are probably on the ground, increase the update rate
minAge = 1000 ;
2017-12-07 17:34:08 +01:00
} else if ( ! altValid | | a - > altitude_baro < 10000 ) {
2015-06-16 00:13:04 +02:00
// Below 10000 feet, emit up to every 5s when changing, 10s otherwise
2016-08-27 15:34:14 +02:00
minAge = ( changed ? 5000 : 10000 ) ;
2014-12-08 20:56:45 +01:00
} else {
2015-06-16 00:13:04 +02:00
// Above 10000 feet, emit up to every 10s when changing, 30s otherwise
2016-08-27 15:34:14 +02:00
minAge = ( changed ? 10000 : 30000 ) ;
2014-12-08 20:56:45 +01:00
}
2016-08-27 15:34:14 +02:00
if ( ( now - a - > fatsv_last_emitted ) < minAge )
continue ;
2017-12-02 18:38:33 +01:00
char * p = prepareWrite ( & Modes . fatsv_out , TSV_MAX_PACKET_SIZE ) ;
2014-12-08 20:56:45 +01:00
if ( ! p )
return ;
2017-12-02 18:38:33 +01:00
char * end = p + TSV_MAX_PACKET_SIZE ;
2014-12-08 20:56:45 +01:00
2019-03-19 19:10:38 +01:00
p = appendFATSV ( p , end , " _v " , " %s " , TSV_VERSION ) ;
2017-12-02 18:38:33 +01:00
p = appendFATSV ( p , end , " clock " , " % " PRIu64 , messageNow ( ) / 1000 ) ;
p = appendFATSV ( p , end , ( a - > addr & MODES_NON_ICAO_ADDRESS ) ? " otherid " : " hexid " , " %06X " , a - > addr & 0xFFFFFF ) ;
2016-09-14 18:02:23 +02:00
2017-12-07 17:34:08 +01:00
// for fields we only emit on change,
// occasionally re-emit them all
int forceEmit = ( now - a - > fatsv_last_force_emit ) > 600000 ;
// these don't change often / at all, only emit when they change
if ( forceEmit | | a - > addrtype ! = a - > fatsv_emitted_addrtype ) {
2018-01-09 15:45:18 +01:00
p = appendFATSV ( p , end , " addrtype " , " %s " , addrtype_enum_string ( a - > addrtype ) ) ;
2016-09-14 18:02:23 +02:00
}
2017-12-07 17:34:08 +01:00
if ( forceEmit | | a - > adsb_version ! = a - > fatsv_emitted_adsb_version ) {
2018-02-19 12:26:16 +01:00
p = appendFATSV ( p , end , " adsb_version " , " %d " , a - > adsb_version ) ;
2014-12-08 20:56:45 +01:00
}
2017-12-07 17:34:08 +01:00
if ( forceEmit | | a - > category ! = a - > fatsv_emitted_category ) {
p = appendFATSV ( p , end , " category " , " %02X " , a - > category ) ;
}
2018-01-09 15:46:33 +01:00
if ( trackDataValid ( & a - > nac_p_valid ) & & ( forceEmit | | a - > nac_p ! = a - > fatsv_emitted_nac_p ) ) {
p = appendFATSVMeta ( p , end , " nac_p " , a , & a - > nac_p_valid , " %u " , a - > nac_p ) ;
}
if ( trackDataValid ( & a - > nac_v_valid ) & & ( forceEmit | | a - > nac_v ! = a - > fatsv_emitted_nac_v ) ) {
p = appendFATSVMeta ( p , end , " nac_v " , a , & a - > nac_v_valid , " %u " , a - > nac_v ) ;
}
2018-02-22 08:45:32 +01:00
if ( trackDataValid ( & a - > sil_valid ) & & ( forceEmit | | a - > sil ! = a - > fatsv_emitted_sil ) ) {
p = appendFATSVMeta ( p , end , " sil " , a , & a - > sil_valid , " %u " , a - > sil ) ;
}
if ( trackDataValid ( & a - > sil_valid ) & & ( forceEmit | | a - > sil_type ! = a - > fatsv_emitted_sil_type ) ) {
p = appendFATSVMeta ( p , end , " sil_type " , a , & a - > sil_valid , " %s " , sil_type_enum_string ( a - > sil_type ) ) ;
2018-01-09 15:46:33 +01:00
}
if ( trackDataValid ( & a - > nic_baro_valid ) & & ( forceEmit | | a - > nic_baro ! = a - > fatsv_emitted_nic_baro ) ) {
p = appendFATSVMeta ( p , end , " nic_baro " , a , & a - > nic_baro_valid , " %u " , a - > nic_baro ) ;
}
2014-12-08 20:56:45 +01:00
2017-06-15 19:07:40 +02:00
// only emit alt, speed, latlon, track etc if they have been received since the last time
2015-06-16 02:38:44 +02:00
// and are not stale
2015-06-16 00:13:04 +02:00
2017-12-02 18:38:33 +01:00
char * dataStart = p ;
// special cases
if ( airgroundValid )
2018-01-09 15:45:18 +01:00
p = appendFATSVMeta ( p , end , " airGround " , a , & a - > airground_valid , " %s " , airground_enum_string ( a - > airground ) ) ;
2017-12-07 17:34:08 +01:00
if ( squawkValid )
p = appendFATSVMeta ( p , end , " squawk " , a , & a - > squawk_valid , " %04x " , a - > squawk ) ;
if ( callsignValid )
2017-12-02 18:38:33 +01:00
p = appendFATSVMeta ( p , end , " ident " , a , & a - > callsign_valid , " {%s} " , a - > callsign ) ;
2017-12-07 17:34:08 +01:00
if ( altValid )
p = appendFATSVMeta ( p , end , " alt " , a , & a - > altitude_baro_valid , " %d " , a - > altitude_baro ) ;
if ( positionValid ) {
p = appendFATSVMeta ( p , end , " position " , a , & a - > position_valid , " {%.5f %.5f %u %u} " , a - > lat , a - > lon , a - > pos_nic , a - > pos_rc ) ;
}
p = appendFATSVMeta ( p , end , " alt_gnss " , a , & a - > altitude_geom_valid , " %d " , a - > altitude_geom ) ;
p = appendFATSVMeta ( p , end , " vrate " , a , & a - > baro_rate_valid , " %d " , a - > baro_rate ) ;
p = appendFATSVMeta ( p , end , " vrate_geom " , a , & a - > geom_rate_valid , " %d " , a - > geom_rate ) ;
p = appendFATSVMeta ( p , end , " speed " , a , & a - > gs_valid , " %.1f " , a - > gs ) ;
p = appendFATSVMeta ( p , end , " speed_ias " , a , & a - > ias_valid , " %u " , a - > ias ) ;
p = appendFATSVMeta ( p , end , " speed_tas " , a , & a - > tas_valid , " %u " , a - > tas ) ;
p = appendFATSVMeta ( p , end , " mach " , a , & a - > mach_valid , " %.3f " , a - > mach ) ;
p = appendFATSVMeta ( p , end , " track " , a , & a - > track_valid , " %.1f " , a - > track ) ;
p = appendFATSVMeta ( p , end , " track_rate " , a , & a - > track_rate_valid , " %.2f " , a - > track_rate ) ;
p = appendFATSVMeta ( p , end , " roll " , a , & a - > roll_valid , " %.1f " , a - > roll ) ;
p = appendFATSVMeta ( p , end , " heading_magnetic " , a , & a - > mag_heading_valid , " %.1f " , a - > mag_heading ) ;
2019-03-19 19:44:09 +01:00
p = appendFATSVMeta ( p , end , " heading_true " , a , & a - > true_heading_valid , " %.1f " , a - > true_heading ) ;
p = appendFATSVMeta ( p , end , " nav_alt_mcp " , a , & a - > nav_altitude_mcp_valid , " %u " , a - > nav_altitude_mcp ) ;
p = appendFATSVMeta ( p , end , " nav_alt_fms " , a , & a - > nav_altitude_fms_valid , " %u " , a - > nav_altitude_fms ) ;
p = appendFATSVMeta ( p , end , " nav_alt_src " , a , & a - > nav_altitude_src_valid , " %s " , nav_altitude_source_enum_string ( a - > nav_altitude_src ) ) ;
2017-12-07 17:34:08 +01:00
p = appendFATSVMeta ( p , end , " nav_heading " , a , & a - > nav_heading_valid , " %.1f " , a - > nav_heading ) ;
2018-01-09 15:45:18 +01:00
p = appendFATSVMeta ( p , end , " nav_modes " , a , & a - > nav_modes_valid , " {%s} " , nav_modes_flags_string ( a - > nav_modes ) ) ;
2017-12-07 17:34:08 +01:00
p = appendFATSVMeta ( p , end , " nav_qnh " , a , & a - > nav_qnh_valid , " %.1f " , a - > nav_qnh ) ;
2018-01-09 15:43:58 +01:00
p = appendFATSVMeta ( p , end , " emergency " , a , & a - > emergency_valid , " %s " , emergency_enum_string ( a - > emergency ) ) ;
2017-06-15 19:07:40 +02:00
2016-09-15 16:08:50 +02:00
// if we didn't get anything interesting, bail out.
// We don't need to do anything special to unwind prepareWrite().
2017-12-02 18:38:33 +01:00
if ( p = = dataStart ) {
2014-12-08 20:56:45 +01:00
continue ;
}
2017-12-02 18:38:33 +01:00
- - p ; // remove last tab
p = safe_snprintf ( p , end , " \n " ) ;
2014-12-08 21:17:48 +01:00
if ( p < = end )
completeWrite ( & Modes . fatsv_out , p ) ;
else
fprintf ( stderr , " fatsv: output too large (max %d, overran by %d) \n " , TSV_MAX_PACKET_SIZE , ( int ) ( p - end ) ) ;
2014-12-08 20:56:45 +01:00
2017-12-07 17:34:08 +01:00
a - > fatsv_emitted_altitude_baro = a - > altitude_baro ;
a - > fatsv_emitted_altitude_geom = a - > altitude_geom ;
2017-12-02 18:38:33 +01:00
a - > fatsv_emitted_baro_rate = a - > baro_rate ;
a - > fatsv_emitted_geom_rate = a - > geom_rate ;
2017-12-07 17:34:08 +01:00
a - > fatsv_emitted_gs = a - > gs ;
a - > fatsv_emitted_ias = a - > ias ;
a - > fatsv_emitted_tas = a - > tas ;
2017-12-02 18:38:33 +01:00
a - > fatsv_emitted_mach = a - > mach ;
a - > fatsv_emitted_track = a - > track ;
a - > fatsv_emitted_track_rate = a - > track_rate ;
a - > fatsv_emitted_roll = a - > roll ;
a - > fatsv_emitted_mag_heading = a - > mag_heading ;
a - > fatsv_emitted_true_heading = a - > true_heading ;
a - > fatsv_emitted_airground = a - > airground ;
2019-03-19 19:44:09 +01:00
a - > fatsv_emitted_nav_altitude_mcp = a - > nav_altitude_mcp ;
a - > fatsv_emitted_nav_altitude_fms = a - > nav_altitude_fms ;
a - > fatsv_emitted_nav_altitude_src = a - > nav_altitude_src ;
2017-12-07 17:34:08 +01:00
a - > fatsv_emitted_nav_heading = a - > nav_heading ;
a - > fatsv_emitted_nav_modes = a - > nav_modes ;
a - > fatsv_emitted_nav_qnh = a - > nav_qnh ;
2017-12-02 18:38:33 +01:00
memcpy ( a - > fatsv_emitted_callsign , a - > callsign , sizeof ( a - > fatsv_emitted_callsign ) ) ;
2017-12-07 17:34:08 +01:00
a - > fatsv_emitted_addrtype = a - > addrtype ;
a - > fatsv_emitted_adsb_version = a - > adsb_version ;
a - > fatsv_emitted_category = a - > category ;
a - > fatsv_emitted_squawk = a - > squawk ;
2018-01-09 15:46:33 +01:00
a - > fatsv_emitted_nac_p = a - > nac_p ;
a - > fatsv_emitted_nac_v = a - > nac_v ;
a - > fatsv_emitted_sil = a - > sil ;
a - > fatsv_emitted_sil_type = a - > sil_type ;
a - > fatsv_emitted_nic_baro = a - > nic_baro ;
2018-02-19 12:25:49 +01:00
a - > fatsv_emitted_emergency = a - > emergency ;
2014-12-08 20:56:45 +01:00
a - > fatsv_last_emitted = now ;
2017-12-07 17:34:08 +01:00
if ( forceEmit ) {
a - > fatsv_last_force_emit = now ;
}
2014-12-08 20:56:45 +01:00
}
}
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
//
2014-10-03 23:55:21 +02:00
// Perform periodic network work
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
//
2014-10-03 23:55:21 +02:00
void modesNetPeriodicWork ( void ) {
2015-06-26 18:50:51 +02:00
struct client * c , * * prev ;
struct net_service * s ;
uint64_t now = mstime ( ) ;
2015-06-29 11:06:13 +02:00
int need_flush = 0 ;
2015-06-26 18:50:51 +02:00
2016-08-27 15:34:14 +02:00
// Accept new connections
2015-06-26 18:50:51 +02:00
modesAcceptClients ( ) ;
// Read from clients
for ( c = Modes . clients ; c ; c = c - > next ) {
2015-06-26 22:29:54 +02:00
if ( ! c - > service )
continue ;
2015-06-26 18:50:51 +02:00
if ( c - > service - > read_handler )
modesReadFromClient ( c ) ;
}
// Generate FATSV output
writeFATSV ( ) ;
2015-06-29 11:06:13 +02:00
// If we have generated no messages for a while, send
// a heartbeat
2015-06-26 18:50:51 +02:00
if ( Modes . net_heartbeat_interval ) {
for ( s = Modes . services ; s ; s = s - > next ) {
if ( s - > writer & &
s - > connections & &
2015-06-29 11:06:13 +02:00
s - > writer - > send_heartbeat & &
2015-06-26 18:50:51 +02:00
( s - > writer - > lastWrite + Modes . net_heartbeat_interval ) < = now ) {
2015-06-29 11:06:13 +02:00
s - > writer - > send_heartbeat ( s ) ;
2015-06-26 18:50:51 +02:00
}
2014-04-25 15:48:14 +02:00
}
2015-06-26 18:50:51 +02:00
}
2014-10-02 22:06:10 +02:00
2015-06-26 18:50:51 +02:00
// If we have data that has been waiting to be written for a while,
// write it now.
for ( s = Modes . services ; s ; s = s - > next ) {
if ( s - > writer & &
s - > writer - > dataUsed & &
( need_flush | | ( s - > writer - > lastWrite + Modes . net_output_flush_interval ) < = now ) ) {
flushWrites ( s - > writer ) ;
2014-10-03 23:55:21 +02:00
}
2015-06-26 18:50:51 +02:00
}
2014-10-02 22:06:10 +02:00
2015-06-26 18:50:51 +02:00
// Unlink and free closed clients
for ( prev = & Modes . clients , c = * prev ; c ; c = * prev ) {
if ( c - > fd = = - 1 ) {
// Recently closed, prune from list
* prev = c - > next ;
free ( c ) ;
} else {
prev = & c - > next ;
}
}
2014-10-03 23:55:21 +02:00
}
2014-10-02 22:06:10 +02:00
Split into separate module files
Ok - this is likely to upset some people. Up until now, the vast
majority of the code has been in just one file - dump1090.c. This file
has grown so that it was approaching of 5000 lines long, and it was
becoming unmanagable. So I've split the file into several modules,
hopefully along fairly logical boundaries. The files are :
1) dump1090.c : Basically just the main() entry function, the help
function, the RTL dongle hardware interface, and a few orphan functions
that don't really fit anywhere else.
2) mode_s.c : This contains all the mode S / ADSB decoding functions.
3) mode_ac.c : This contains all the mode A & C decoding functions
4) interactive.c : This contains all the functions to maintain an
internal list of aircraft seen over the last period, and functions to
print them out to the local console.
5) net_io.c : This contains all the network input/output functions
allowing data to be passed in/out to/from other receivers, in formats
such as SBS-1/3, Beast, AVR and JavaScript.
Hopefully this should provide an easier way forward if/when more
functions are added.
2013-08-19 19:57:03 +02:00
//
// =============================== Network IO ===========================
//