Make faup1090 write to stdout, not listen on port 10001.

This commit is contained in:
Oliver Jowett 2015-06-28 19:59:49 +01:00
parent c7722f2b97
commit 8f08c1b87f
3 changed files with 30 additions and 17 deletions

View file

@ -64,7 +64,6 @@ static void faupInitConfig(void) {
Modes.check_crc = 1; Modes.check_crc = 1;
Modes.net = 1; Modes.net = 1;
Modes.net_heartbeat_interval = MODES_NET_HEARTBEAT_INTERVAL; 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.maxRange = 1852 * 300; // 300NM default max range
Modes.quiet = 1; Modes.quiet = 1;
Modes.net_output_flush_size = MODES_OUT_FLUSH_SIZE; 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"; char *bo_connect_ipaddr = "127.0.0.1";
int bo_connect_port = MODES_NET_OUTPUT_BEAST_PORT; int bo_connect_port = MODES_NET_OUTPUT_BEAST_PORT;
struct client *c; struct client *c;
struct net_service *s; struct net_service *beast_input, *fatsv_output;
// Set sane defaults // Set sane defaults
faupInitConfig(); faupInitConfig();
@ -154,10 +153,6 @@ int main(int argc, char **argv) {
bo_connect_port = atoi(argv[++j]); bo_connect_port = atoi(argv[++j]);
} else if (!strcmp(argv[j],"--net-bo-ipaddr") && more) { } else if (!strcmp(argv[j],"--net-bo-ipaddr") && more) {
bo_connect_ipaddr = argv[++j]; 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) { } else if (!strcmp(argv[j],"--lat") && more) {
Modes.fUserLat = atof(argv[++j]); Modes.fUserLat = atof(argv[++j]);
} else if (!strcmp(argv[j],"--lon") && more) { } else if (!strcmp(argv[j],"--lon") && more) {
@ -180,9 +175,9 @@ int main(int argc, char **argv) {
faupInit(); faupInit();
modesInitNet(); modesInitNet();
// Set up connection // Set up input connection
s = makeBeastInputService(); beast_input = makeBeastInputService();
c = serviceConnect(s, bo_connect_ipaddr, bo_connect_port); c = serviceConnect(beast_input, bo_connect_ipaddr, bo_connect_port);
if (!c) { if (!c) {
fprintf (stderr, fprintf (stderr,
"faup1090: failed to connect to %s:%d (is dump1090 running?): %s\n", "faup1090: failed to connect to %s:%d (is dump1090 running?): %s\n",
@ -190,8 +185,12 @@ int main(int argc, char **argv) {
exit (1); exit (1);
} }
// Run it until we've lost the connection. // Set up output connection on stdout
while (!Modes.exit && s->connections) { 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(); backgroundTasks();
usleep(100000); usleep(100000);
} }

View file

@ -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 // 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; struct client *c;
@ -129,7 +136,6 @@ static struct client *createClient(struct net_service *service, int fd)
c->fd = fd; c->fd = fd;
c->buflen = 0; c->buflen = 0;
Modes.clients = c; Modes.clients = c;
anetSetSendBuffer(Modes.aneterr,fd, (MODES_NET_SNDBUF_SIZE << Modes.net_sndbuf_size));
++service->connections; ++service->connections;
if (service->writer && service->connections == 1) { 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) if (s == ANET_ERR)
return NULL; return NULL;
return createClient(service, s); return createSocketClient(service, s);
} }
// Set up the given service to listen on an address/port. // 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); 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) { void modesInitNet(void) {
struct net_service *s; struct net_service *s;
@ -202,7 +213,7 @@ void modesInitNet(void) {
} }
if (Modes.net_fatsv_port) { 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); 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) { for (s = Modes.services; s; s = s->next) {
if (s->listen_fd >= 0) { if (s->listen_fd >= 0) {
while ((fd = anetTcpAccept(Modes.aneterr, s->listen_fd, NULL, &port)) >= 0) { while ((fd = anetTcpAccept(Modes.aneterr, s->listen_fd, NULL, &port)) >= 0) {
createClient(s, fd); createSocketClient(s, fd);
} }
} }
} }

View file

@ -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 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); struct client *serviceConnect(struct net_service *service, char *addr, int port);
void serviceListen(struct net_service *service, char *bind_addr, int bind_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 *makeBeastInputService(void);
struct net_service *makeFatsvOutputService(void);
void modesInitNet(void); void modesInitNet(void);
void modesQueueOutput(struct modesMessage *mm); void modesQueueOutput(struct modesMessage *mm);