SDK Question Trying to find Nav Transmitter - ILS source

JMW

Aspiring Addon Developer
Joined
Aug 5, 2008
Messages
611
Reaction score
52
Points
43
Location
Happy Wherever
:hmm:Trying to use GetNavSource () to get currently tuned radio (ILS) for an Autopilot.

DWORD padNo;
VESSEL3 *vessel;
presently under
Code:
// ==============================================================
// Some vessel parameters
// ==============================================================
heading.

Code I'm trying is:

PHP:
bool InputTarget(void *id, char *bstr, void *user_data)
{
	oapiSetHUDMode (HUD_SURFACE);

OBJHANDLE hPlanet = oapiGetGbodyByName("Earth");//GetSurfaceRef();//
OBJHANDLE hBase = oapiGetBaseByName(hPlanet, bstr);
if (hBase == NULL) return false;

			int nBase=oapiGetBaseCount(hPlanet);

			for (int i=0; i< nBase; i++) {
			
				base = bstr;
							}
if (hBase != NULL) 

[B]NAVHANDLE nv = NULL;
NAVHANDLE nv = vessel->GetNavSource (0);
if (nv)
{
	nvtype = oapiGetNavType(nv);
if (nvtype != TRANSMITTER_VOR && nvtype != TRANSMITTER_ILS)
			nv = NULL;
if (nvtype == TRANSMITTER_ILS)
		{

	sprintf(oapiDebugString(),"ILS FOUND %02.2f ",nvtype);//Just to show something's happened
		}
}

else[/B]

{
	int status = 1;
			
		DWORD padcount = oapiGetBasePadCount(hBase); 
		NAVHANDLE hNav = NULL;
		for (DWORD i = 0; i < padcount && status >0; i++) {
			
			oapiGetBasePadStatus(hBase, i, &status);
			
				Nav = 1;
//{sprintf(oapiDebugString(),"Pad No %02.2f ", status);}
			hNav = oapiGetBasePadNav(hBase, i);
	
		padNo = i+1;

			if (hNav != NULL) 
			
				navtype = oapiGetNavType(hNav);
			
				//if (navtype == TRANSMITTER_VTOL)
					
				{
				
			oapiGetBasePadEquPos(hBase, i, &tgtlng, &tgtlat, &tgtrad);
//sprintf(oapiDebugString(),"Target VTOL long %01.08f : lat %01.08f : Base %01.08f : Pad %01.03f", tgtlng, tgtlat, str, i+1);
			Nav = 1; 
				}			
						}
}
OBJHANDLE hRef = hBase;

 return true;
}

VTOL section works fine (that is without bold section ) -
but get ctd when section added.
Not sure of my use of "vessel->" - this is where my coding 'skills' get hazy ...

Can anyone help?
 
Last edited:

Mythos

Addon Developer
Addon Developer
Donator
Joined
Apr 28, 2012
Messages
103
Reaction score
7
Points
33
Location
Kiel
I'll give it a try...

First: It's hard to read that code. Try that "PHP" button instead of "CODE" this will do some painting. Then align your coding blocks, I can't see which "{" belongs to what "}". For better readability (not scolling so far to right), I always replace my tabs with one or two spaces, that enough to see the logical indent.

Second: Coding skills. You can't say
PHP:
NAVHANDLE nv = NULL;
NAVHANDLE nv = vessel->GetNavSource (0);
This would make another variable with the name "nv" that's already used, although it's the same type here. It doesn't make any sense at all to give it the value NULL first and then put some result of GetNavSource into it :huh:

PHP:
if (nvtype != TRANSMITTER_VOR && nvtype != TRANSMITTER_ILS)
 nv = NULL; 
if (nvtype == TRANSMITTER_ILS) ...
This also looks like double checking. And why setting nv to NULL if it's not used after that check?

I did getting NAV signal this way:
PHP:
bool vessel_nav1_ok;
VECTOR3 vessel_nav1_v; // long, rad, lat
OBJHANDLE vessel_surface;
VECTOR3 v;
NAVHANDLE n;
vessel_surface = vessel->GetSurfaceRef();
int vessel_nav_count = vessel->GetNavCount();
if(vessel_nav_count > 0)
{
  n = vessel->GetNavSource(0);
  vessel_nav1_ok = n != NULL;
  if(vessel_nav1_ok)
  {
    oapiGetNavPos(n, &v);
    oapiGlobalToEqu(vessel_surface, v, 
      &vessel_nav1_v.x, &vessel_nav1_v.z, &vessel_nav1_v.y);
    ...
    sprintf(oapiDebugString(), "Long: %.2f Lat: %.2f", 
      vessel_nav1_v.x, vessel_nav1_v.z);
    ...
  }
  else
  {
    vessel_nav1_v = _V(0.0, 0.0, 0.0);
  }
}

I didn't care about type of the signal here, but that shouldn't be the problem.
 
Top