libhomeradareasy collect aircraft information |
20,414,316 registered contacts 173296 unique aircraft records, 7.15% unresolved records |
| ACARS DECODER Planespotting Network Kinetic Avionics AirNav Systems Airframes.org | |||
| Home Docu Examples Functions Downloads Database Search API Success Stories News Personal Pages | |||
![]() 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.
|
Connecting to 2 hosts and show all contacts
This example will connect to two SBS-1 hosts and will show all the contacted aircrafts on stdout. The library will be initialized with the LHR_AUTOCONNECT flag to immediatly connect to added hosts. New contacted aircrafts will also be written to stdout with a special marker.
/* System includes */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
/* libhomeradar header include */
#include "libhomeradar.h"
/* Show new contacted aircrafts */
void onair(LHR handle,const int *id, LHR_CONTACT *C) {
char tstr[64];
printf("*** NEW CONTACT ***\n===================\n");
if (id != NULL) printf("[%s]\n",homeradar_gethostbyid(handle,*(id)));
printf("Contact: %s [%s]\n",
C->icao24,(C->reg)?C->reg:"UNKNOWN - Lookup not enabled?!");
strftime(tstr,sizeof(tstr),"%d %m %Y %H:%M:%S",localtime(&C->contacted));
printf("Date: %s\n===================\n",tstr);
/* Free used memory */
homeradar_freecontact(C);
}
/* Callback function to show aircraft informations */
void newcontact(void *handle,const int *id, LHR_CONTACT *C) {
/* Show icao24 code */
printf("Contact: %s [%s]\n",C->icao24,
(C->reg)?C->reg:"UNKNOWN - Lookup not enabled?!");
/* Free LHR_CONTACT struct */
homeradar_freecontact(C);
}
/* Main program */
int main(int argc, char **argv) {
int e;
LHR H = homeradar_init(16,LHR_AUTOCONNECT,&e,NULL);
/* No error */
if (H == NULL) {
printf("Error initializing libhomeradar. Errorcode #%d\n",e);
return 255;
}
/* Add host */
e = homeradar_addhost(H, "sbs1.libhomeradar.org", 33033, LHR_SBS1, LHR_ONAIRCONTACT, onair);
/* Setup the event listener for the LHR_ONCONTACT event */
if (homeradar_onhandler(H, LHR_ONCONTACT, e, newcontact)==0) {
printf("Unable to add event listener\n");
}
/* Add a second host */
e = homeradar_addhost(H, "sbs2.libhomeradar.org", 0, LHR_SBS1, LHR_ONAIRCONTACT, onair);
/* Setup the event listener for the LHR_ONCONTACT event */
if (homeradar_onhandler(H, LHR_ONCONTACT, e, newcontact)==0) {
printf("Unable to add event listener\n");
}
/* Do nothing - in this example - loop will be finished after 120 seconds
In your real program you can do now what you want */
e = 20;
while (e--) sleep(6);
/* Shutdown libhomeradar and free all alocated memory */
printf("Shutdown libhomeradar...\n");
homeradar_destroy(H);
/* Return success */
return 0;
}
|
||