Ejemplo n.º 1
0
int GetClosestAirportId(char *id, int index)
{    
    XPLMNavRef waypoint;
    float lat = 0.f, lon = 0.f;
    XPLMGetFMSEntryInfo(index, NULL, NULL, &waypoint, NULL, &lat, &lon);
    
    if (lat == 0.f || lon == 0.f)
        return 0;
    
    XPLMNavRef airport = XPLMFindNavAid(NULL, NULL, &lat, &lon, NULL, xplm_Nav_Airport);
    XPLMGetNavAidInfo(airport, NULL, NULL, NULL, NULL, NULL, NULL, id, NULL, NULL);
    
    return 1;
}
Ejemplo n.º 2
0
Archivo: fix.cpp Proyecto: samcrow/PPL
XPLMNavRef Fix::findNavRef(const std::string& id) {
    return XPLMFindNavAid(nullptr, id.data(), nullptr, nullptr, nullptr, xplm_Nav_Fix);
}
Ejemplo n.º 3
0
void sendRepositionedAtAirport() {
	XPLMDebugString("XData: sendRepositionedAtAirport called.\n");
	
	// where are we?
	float inLat;
	float inLon;
	
	XPLMDataRef dataref_latitude = XPLMFindDataRef("sim/flightmodel/position/latitude");
	inLat = XPLMGetDataf(dataref_latitude);
	
	XPLMDataRef dataref_longitude = XPLMFindDataRef("sim/flightmodel/position/longitude");
	inLon = XPLMGetDataf(dataref_longitude);
	
	
	XPLMNavRef navref = XPLMFindNavAid(
                                   NULL,
                                   NULL,
                                   &inLat,
                                   &inLon,
                                   NULL,
                                   xplm_Nav_Airport);
	
	float apt_lat;
	float apt_lon;
	float apt_height;
	char apt_id[32];
	char apt_name[256];
	
	XPLMGetNavAidInfo( navref,
					   NULL,
					   &apt_lat,
					   &apt_lon,
					   &apt_height,
					   NULL,
					   NULL,
					   &apt_id,
					   &apt_name,
					   NULL);
					   
	int i;
	int res;	
	char msg[256];
	
	sprintf(msg, "Repositioned at airport: %s (name: %s) height=%f lat=%f lon=%f\n", apt_id, apt_name, apt_height, apt_lat, apt_lon);
	XPLMDebugString(msg);
	
	// make endian corrections
	// COMMENTED OUT - THIS CRASHES X-PLANE.  WHY?
//	apt_lat = custom_htonf(apt_lat);
//	apt_lon = custom_htonf(apt_lon);
//	apt_height = custom_htonf(apt_height);
	
	strncpy(airport_packet.apt_id, apt_id, 32);
	strncpy(airport_packet.apt_name, apt_name, 256);
	airport_packet.apt_height = apt_height;
	airport_packet.apt_lat = apt_lat;
	airport_packet.apt_lon = apt_lon;
	

	
	if (xdata_plugin_enabled && xdata_send_enabled && xdata_socket_open) {
		strncpy(airport_packet.packet_id, "RAPT", 4);
		for (i=0; i<NUM_DEST; i++) {
			if (dest_enable[i]) {
				res = sendto(sockfd, (const char*)&airport_packet, sizeof(airport_packet), 0, (struct sockaddr *)&dest_sockaddr[i], sizeof(struct sockaddr));
#if IBM
				if ( res == SOCKET_ERROR ) {
					XPLMDebugString("XData: caught error while sending RAPT packet! (");
                    sprintf(msg, "%d", WSAGetLastError());
					XPLMDebugString(msg);
					XPLMDebugString(")\n");
				}
#else
				if ( res < 0 ) {
					XPLMDebugString("XData: caught error while sending RAPT packet! (");
					XPLMDebugString((char * const) strerror(GET_ERRNO));
					XPLMDebugString(")\n");
				}
#endif
			}
		}	
	}
	
}
Ejemplo n.º 4
0
XPLMNavRef Localizer::findNavRef(const std::string& id) {
    return XPLMFindNavAid(nullptr, id.data(), nullptr, nullptr, nullptr, xplm_Nav_Localizer);
}