diff --git a/faup1090.c b/faup1090.c index 0750471..67a3fb7 100644 --- a/faup1090.c +++ b/faup1090.c @@ -64,7 +64,6 @@ static void faupInitConfig(void) { Modes.check_crc = 1; Modes.net = 1; Modes.net_heartbeat_interval = MODES_NET_HEARTBEAT_INTERVAL; - Modes.net_fatsv_port = MODES_NET_OUTPUT_FA_TSV_PORT; Modes.maxRange = 1852 * 300; // 300NM default max range Modes.quiet = 1; Modes.net_output_flush_size = MODES_OUT_FLUSH_SIZE; @@ -141,7 +140,7 @@ int main(int argc, char **argv) { char *bo_connect_ipaddr = "127.0.0.1"; int bo_connect_port = MODES_NET_OUTPUT_BEAST_PORT; struct client *c; - struct net_service *s; + struct net_service *beast_input, *fatsv_output; // Set sane defaults faupInitConfig(); @@ -154,10 +153,6 @@ int main(int argc, char **argv) { bo_connect_port = atoi(argv[++j]); } else if (!strcmp(argv[j],"--net-bo-ipaddr") && more) { bo_connect_ipaddr = argv[++j]; - } else if (!strcmp(argv[j],"--net-bind-address") && more) { - Modes.net_bind_address = strdup(argv[++j]); - } else if (!strcmp(argv[j],"--net-fatsv-port") && more) { - Modes.net_fatsv_port = atoi(argv[++j]); } else if (!strcmp(argv[j],"--lat") && more) { Modes.fUserLat = atof(argv[++j]); } else if (!strcmp(argv[j],"--lon") && more) { @@ -180,9 +175,9 @@ int main(int argc, char **argv) { faupInit(); modesInitNet(); - // Set up connection - s = makeBeastInputService(); - c = serviceConnect(s, bo_connect_ipaddr, bo_connect_port); + // Set up input connection + beast_input = makeBeastInputService(); + c = serviceConnect(beast_input, bo_connect_ipaddr, bo_connect_port); if (!c) { fprintf (stderr, "faup1090: failed to connect to %s:%d (is dump1090 running?): %s\n", @@ -190,8 +185,12 @@ int main(int argc, char **argv) { exit (1); } - // Run it until we've lost the connection. - while (!Modes.exit && s->connections) { + // Set up output connection on stdout + fatsv_output = makeFatsvOutputService(); + createGenericClient(fatsv_output, STDOUT_FILENO); + + // Run it until we've lost either connection + while (!Modes.exit && beast_input->connections && fatsv_output->connections) { backgroundTasks(); usleep(100000); } diff --git a/net_io.c b/net_io.c index 9f334dc..85c0dac 100644 --- a/net_io.c +++ b/net_io.c @@ -113,7 +113,14 @@ struct net_service *serviceInit(const char *descr, struct net_writer *writer, co } // Create a client attached to the given service using the provided socket FD -static struct client *createClient(struct net_service *service, int fd) +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) { struct client *c; @@ -129,7 +136,6 @@ static struct client *createClient(struct net_service *service, int fd) c->fd = fd; c->buflen = 0; Modes.clients = c; - anetSetSendBuffer(Modes.aneterr,fd, (MODES_NET_SNDBUF_SIZE << Modes.net_sndbuf_size)); ++service->connections; if (service->writer && service->connections == 1) { @@ -147,7 +153,7 @@ struct client *serviceConnect(struct net_service *service, char *addr, int port) if (s == ANET_ERR) return NULL; - return createClient(service, s); + return createSocketClient(service, s); } // Set up the given service to listen on an address/port. @@ -177,6 +183,11 @@ struct net_service *makeBeastInputService(void) return serviceInit("Beast TCP input", NULL, NULL, decodeBinMessage); } +struct net_service *makeFatsvOutputService(void) +{ + return serviceInit("FATSV TCP output", &Modes.fatsv_out, NULL, NULL); +} + void modesInitNet(void) { struct net_service *s; @@ -202,7 +213,7 @@ void modesInitNet(void) { } if (Modes.net_fatsv_port) { - s = serviceInit("FATSV TCP output", &Modes.fatsv_out, NULL, NULL); + s = makeFatsvOutputService(); serviceListen(s, Modes.net_bind_address, Modes.net_fatsv_port); } @@ -234,7 +245,7 @@ static struct client * modesAcceptClients(void) { for (s = Modes.services; s; s = s->next) { if (s->listen_fd >= 0) { while ((fd = anetTcpAccept(Modes.aneterr, s->listen_fd, NULL, &port)) >= 0) { - createClient(s, fd); + createSocketClient(s, fd); } } } diff --git a/net_io.h b/net_io.h index b184f3a..53bc675 100644 --- a/net_io.h +++ b/net_io.h @@ -60,9 +60,12 @@ struct net_writer { struct net_service *serviceInit(const char *descr, struct net_writer *writer, const char *sep, read_handler handler); struct client *serviceConnect(struct net_service *service, char *addr, int port); void serviceListen(struct net_service *service, char *bind_addr, int bind_port); +struct client *createSocketClient(struct net_service *service, int fd); +struct client *createGenericClient(struct net_service *service, int fd); -// view1090 / faup1090 want to create this themselves: +// view1090 / faup1090 want to create these themselves: struct net_service *makeBeastInputService(void); +struct net_service *makeFatsvOutputService(void); void modesInitNet(void); void modesQueueOutput(struct modesMessage *mm);