libhomeradareasy collect aircraft informations |
| ACARS DECODER Planespotting Network Kinetic Avionics AirNav Systems Airframes.org | |||
| Home Docu Examples Functions Downloads Database Search Online API Success Stories News Imprint / Contact | |||
![]() libhomeradar is an easy to use library for all type of programming language which can use libraries. libhomeradar can connect to different sources to collect aircraft informations arround the world with extended informations, powerful filtering and structured data access. libhomeradar is written in C and is available for Linux and Windows (2003, XP, NT, Vista). Currently libhomeradar works with the Kinetic Avionics SBS-1 base station and the Airnav Systems Radarbox. |
This short example will connect to an SBS1 host and to an RadarBox host. There will be a listener on port 10000 installed on which you can see all decoded messages (telnet localhost 10000).
/* System includes */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <windows.h>
/* libhomeradar header include */
#include "libhomeradar.h"
/* Global variable to libhomeradar */
LHR H = NULL;
/* Callback function to show aircraft informations */
void newcontact(void *handle,const int *id, LHR_CONTACT *C) {
LHR_AIRPORTS *P;
printf("%sContact: %s [%s]\nAirline: %s\nFlightnumber: %s Callsign: %s\nSquawk: %04d\n",
(C->newcontact)?"AIR":"",
C->icao24,(C->reg)?C->reg:"UNKNOWN",
(C->airline)?C->airline:"NULL",C->flightnum,C->callsign,C->squawk);
printf("Aircraft: %s %s [%s] cn:%s\n",C->manufacturer,C->model,C->details,C->cn);
printf("Routing: %s LAT: %0.5f LON: %0.5f\n",(C->route)?C->route:"UNKNOWN",C->lat,C->lon);
/* Get airport informations */
P = C->airports;
while (P) {
if (P->airport) {
printf("Airport [%s / %s] Name: %s, %s\n",
P->airport->iata,P->airport->icao,
P->airport->name,P->airport->country);
} else printf("Unresolveable: %s\n",P->apcode);
P = P->next;
}
/* Free LHR_CONTACT struct */
homeradar_freecontact(C);
}
/* Shutdown library and finish program */
void shutdownlib(int sig) {
printf("Shutdown system. Closing library handle...\n");
/* Close lib handle */
if (H) homeradar_destroy(H);
exit(0);
}
/* Show statistics for the given host */
void statistics(const LHR H, const char *host) {
LHR_STATS *S;
/* Get statistics from libhomeradar */
if ((S = homeradar_stats(H, homeradar_gethostbyname(H, host)))) {
/* Show statistics */
printf("\nStatistics on '%s'\n=====================================\n",host);
printf("You are currently %sCONNECTED to this host\n",(S->connected==0)?"NOT ":"");
if (S->connected == 1) printf("We are connected to this host since %ld seconds\n",S->online);
printf("%ld kilobytes read from this host\n",S->bytes);
printf("%ld messages read from this host\n",S->messages);
printf("%ld valid messages read from this host\n",S->validmsgs);
printf("%ld unique contacted aircrafts on this host\n",S->uniqueacs);
/* Free allocated memory */
free((char*)S);
}
}
/* Main program */
int main(int argc, char **argv) {
int e, i;
char *s;
/* Init global variable */
H = homeradar_init(16,LHR_AUTOCONNECT|LHR_LOOKUP_ALL,&e,NULL);
/* No error */
if (H == NULL) {
printf("Error initializing libhomeradar. Errorcode #%d\n",e);
return 255;
}
/* No dupecheck */
e = 0; (void)homeradar_config(H, LHR_DO_DUPECHECK, (void*)&e);
/* Catch SIGINT signals (CTRL-C) */
(void)signal(SIGINT, shutdownlib);
/* Load databases from disc
Files should be located within the current directory */
homeradar_load_databases(H, "./");
/* Set maximum connected clients to 16 */
e = 16; homeradar_config(H, LHR_LISTENER_MAX, (void*)&e);
/* Add host without event listener */
e = homeradar_addhost(H, "sbs1.libhomeradar.org", 33033, LHR_SBS1, 0, NULL);
/* Create listener for external socket connects */
if (!(homeradar_listener(H, LHR_ON|LHR_SBS1COMP, 10000, "localhost")))
printf("Unable to create listener on port 10000\n");
/* Setup the event listener for the LHR_ONCONTACT event */
if (homeradar_onhandler(H, LHR_ONCONTACT, e, newcontact)==0)
printf("Unable to add event listener (1)\n");
/* Add host without event listener */
e = homeradar_addhost(H, "radarbox.libhomeradar.org", 33333, LHR_RADARBOX, 0, NULL);
/* Setup the event listener for the LHR_ONCONTACT event */
if (homeradar_onhandler(H, LHR_ONCONTACT, e, newcontact)==0)
printf("Unable to add event listener (2)\n");
/* Do nothing - in this example - loop will be finished after 5 minutes
In your real program you can do now what you want */
sleep(300);
/* Get stats from listener */
if ((s = homeradar_listener_stats(H))) {
printf("%s",s); free(s);
}
/* Disable eventhandler for contacts */
(void)homeradar_onhandler(H, LHR_ONCONTACT, LHR_HOSTS_ALL, NULL);
/* Get stats */
statistics(H, "sbs1.libhomeradar.org"); statistics(H, "radarbox.libhomeradar.org");
/* Get all contacts from SBS1 server */
i = 0; e = homeradar_gethostbyname(H, "sbs1.libhomeradar.org");
while ((s = homeradar_unique_aircrafts(H, e, &i))) printf("%s\n",s);
/* Get all contacts from RadarBox server */
i = 0; e = homeradar_gethostbyname(H, "radarbox.libhomeradar.org");
while ((s = homeradar_unique_aircrafts(H, e, &i))) printf("%s\n",s);
/* Destroy lib handler */
homeradar_destroy(H);
/* Return success */
return 0;
}
|
||