• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

FSX better description for Token Variables

Messages
92
Country
poland
Hi!

I'm working on some c++ gauges for my glider but I have a problem:
I lack information on units used by Token Variables: https://msdn.microsoft.com/en-us/library/cc526959.aspx

Some of them act in a weird way, eg:
I was working on a communication radio and for unknown reason Token Variables "COM_FREQUENCY" and "COM_STBY_FREQUENCY" give me: 10288 and 10277

When in VR cockpit, "COM ACTIVE FREQUENCY:1" and "A:COM STANDBY FREQUENCY:1" give me: 128.30 and 128.25

Is there a place where I can find more detailed description on them?
 
They're being returned as binary coded decimals. The leading '1' is dropped; you'll see the remaining digits if you display the result as a hex number. If you search this sub-forum, I'm pretty sure you will find a discussion or two on how to convert the result to something useful.
I've always just used SimConnect or execute_calculator_code if I needed to retrieve a com frequency.

Doug
 
I've always just used SimConnect or execute_calculator_code if I needed to retrieve a com frequency.

Adding to Doug's comment I believe that, to retrieve simulation variables (AKA AVars), is much simpler to use aircrat_varget and associated functions instead of token vars, mostly because of the possibility to express their values in different units without having to write conversion formulas.

Tom
 
An example on what I use to retrieve AVars in C++ :

In a header (.h) file:

Code:
FLOAT64 AVar(PCSTRINGZ szName,UINT32 iIndex,PCSTRINGZ szUnits)
{
    return aircraft_varget( get_aircraft_var_enum(szName),
                get_units_enum(szUnits),iIndex);
}

And to get the value:

Code:
FLOAT64 fCom1Freq = AVar("COM ACTIVE FREQUENCY",1,"Mhz");

The second parameter is an index to engine, or radio unit (1,2,3,etc.). Vars that do not have an index must pass 0 here.

Tom
 
Let me know if I understand:

I put that first code to gauges header file (in case of SDK example it would be gauges.h file).
And then I use
Code:
AVar("COM ACTIVE FREQUENCY",1,"Mhz")
in callback code of a eg.: MAKE_STRING, like this:
Code:
FLOAT64 fCom1Freq = AVar("COM ACTIVE FREQUENCY", 1, "Mhz");

    return fCom1Freq;

Am I right?
 
I put that first code to gauges header file (in case of SDK example it would be gauges.h file).

Do not touch gauges.h. Instead, if you don't have a custom header file for that gauge, you can declare the function at the top of the code and write its content at the bottom for clarity:

Code:
....
extern PELEMENT_HEADER temperature_list;
extern MOUSERECT temperature_mouse_rect[];

FLOAT64 AVar(PCSTRINGZ szName,UINT32 iIndex,PCSTRINGZ szUnits);

GAUGE_HEADER_FS700(etc....);
...
....
FLOAT64 FSAPI Com1_string_cb( PELEMENT_STRING pelement )
{

    FLOAT64 fCom1Freq = AVar("COM ACTIVE FREQUENCY", 1, "Mhz");
    wsprintf(pelement->string, "%3.2f", fCom1Freq);   // format option
    return fCom1Freq;

}
...
MAKE_STRING(etc,etc)
...
.....
FLOAT64 AVar(PCSTRINGZ szName,UINT32 iIndex,PCSTRINGZ szUnits)
{
    return aircraft_varget( get_aircraft_var_enum(szName),get_units_enum(szUnits),iIndex);
}

Hope this helps.

Tom
 
Thank you for the tip!

Although I think I'm making some other mistakes.

When I load it, in cockpit view, string shows "F".

I deleted that (and only that) entery from gauges.h file, that I have put there for test.

Beginning of my gauge:
Code:
char radio_gauge_name[] = GAUGE_NAME;
extern PELEMENT_HEADER        radio_list;
extern MOUSERECT            radio_mouse_rect[];

FLOAT64 AVar(PCSTRINGZ szName, UINT32 iIndex, PCSTRINGZ szUnits);

GAUGE_HEADER_FS700(GAUGE_W, radio_gauge_name, &radio_list, \
    radio_mouse_rect, 0, 0, 0, 0);


#define RADIO_GAUGE_CHARSET                DEFAULT_CHARSET
#define RADIO_GAUGE_FONT_DEFAULT            "Quartz"
#define RADIO_GAUGE_WEIGHT_DEFAULT        FW_NORMAL

That string:
Code:
FLOAT64 FSAPI    radio_com_string_cb(PELEMENT_STRING pelement)
{
    FLOAT64 fCom1Freq = AVar("COM ACTIVE FREQUENCY", 1, "Mhz");
    wsprintf(pelement->string, "%3.2f", fCom1Freq);   // format option
    return fCom1Freq;
}

MAKE_STRING
(
    radio_com_string,
    NULL,
    radio_fail,
    IMAGE_USE_ERASE | IMAGE_USE_BRIGHT | IMAGE_USE_TRANSPARENCY,
    0,
    103, 61,
    60, 20,
    10,
    COM_FREQUENCY,
    DISPLAY_UNITS,
    MODULE_VAR_NONE,
    RGB(255, 255, 255),
    RGB(0, 0, 0),
    RGB(92, 92, 92),
    RADIO_GAUGE_FONT_DEFAULT,
    RADIO_GAUGE_WEIGHT_DEFAULT,
    RADIO_GAUGE_CHARSET,
    0,
    DT_CENTER | DT_VCENTER | DT_SINGLELINE,
    NULL,
    radio_com_string_cb
)

and the end:
Code:
MOUSE_END


//test XML value
FLOAT64 AVar(PCSTRINGZ szName, UINT32 iIndex, PCSTRINGZ szUnits)
{
    return aircraft_varget(get_aircraft_var_enum(szName), get_units_enum(szUnits), iIndex);
}
/////////////////////////////////////////////////////////////////////////////
#undef GAUGE_NAME
#undef GAUGEHDR_VAR_NAME
#undef GAUGE_W

Maybe I should put C"NULL," instead of "COM_FREQUENCY," in the MAKE_STRING?
 
Make the 3 var lines as MODULE_VAR_NONE, then try this format for the callback:

Code:
FLOAT64 FSAPI radio_com_string_cb(PELEMENT_STRING pelement)
{
   FLOAT64 val=pelement->source_var[0].var_value.n;
   val = !val;
  
   FLOAT64 fCom1Freq = AVar("COM ACTIVE FREQUENCY", 1, "Mhz");
   wsprintf(pelement->string, "%3.2f", fCom1Freq); // format option
  
   return val;
}

Should work now, or almost.

Tom
 
No effect.
I have changed font for Arial and it is not "F" but "f".

Current code:
Code:
FLOAT64 FSAPI    radio_com_string_cb(PELEMENT_STRING pelement)
{
    FLOAT64 val = pelement->source_var[0].var_value.n;
    val = !val;

    FLOAT64 fCom1Freq = AVar("COM ACTIVE FREQUENCY", 1, "Mhz");
    wsprintf(pelement->string, "%3.2f", fCom1Freq); // format option

    return val;
}

MAKE_STRING
(
    radio_com_string,
    NULL,
    radio_fail,
    IMAGE_USE_ERASE | IMAGE_USE_BRIGHT | IMAGE_USE_TRANSPARENCY,
    0,
    103, 61,
    60, 20,
    10,
    MODULE_VAR_NONE,
    MODULE_VAR_NONE,
    MODULE_VAR_NONE,
    //COM_FREQUENCY,
    //DISPLAY_UNITS,
    //MODULE_VAR_NONE,
    RGB(255, 255, 255),
    RGB(0, 0, 0),
    RGB(92, 92, 92),
    RADIO_GAUGE_FONT_DEFAULT,
    RADIO_GAUGE_WEIGHT_DEFAULT,
    RADIO_GAUGE_CHARSET,
    0,
    DT_CENTER | DT_VCENTER | DT_SINGLELINE,
    NULL,
    radio_com_string_cb
)
 
Thanks for a tip.

I'm sorry but I'm apartamenty dumb.
I changed the callback code to:
Code:
FLOAT64 FSAPI    radio_com_string_cb(PELEMENT_STRING pelement)
{
    FLOAT64 val = pelement->source_var[0].var_value.n;
    val = !val;

    FLOAT64 fCom1Freq = AVar("COM ACTIVE FREQUENCY", 1, "Mhz");
    char buffer[200];
    sprintf(buffer, "%d", fCom1Freq);

    return val;
}
and now it won't even build.

Someone please tell me how dumb I am and what have I done wrong here.
 
Try:
FLOAT64 FSAPI radio_com_string_cb(PELEMENT_STRING pelement)
{


FLOAT64 fCom1Freq = AVar("COM ACTIVE FREQUENCY", 1, "Mhz");
sprintf(pelement->string, "%3.2f", fCom1Freq); // format option

return 0.;
}
 
OMG!!!!
It worked!

Thank you ddawson so much.

My thanks go also to any and all people who helped my with it!
 
A problem (not related to coding but understanding value of variables):
XML tooltip "TOOLTIPTEXT_XPNDR_REPORTED_FLT_LVL" gives me code "FL004" from:
Code:
FL%( (A:PLANE ALTITUDE,feet) 1000 / (A:SEA LEVEL PRESSURE,inHg) - 29.92 + 10 * )%!03d!

I tried to recreate that code in callback code:
Code:
FLOAT64 ftransponser1 = AVar("PLANE ALTITUDE", 0, "feet") / 1000;
    ftransponser1 = ftransponser1 - AVar("SEA LEVEL PRESSURE", 0, "inHg");
    ftransponser1 = ftransponser1 + 29.92;
    ftransponser1 = ftransponser1 * 10;
    sprintf(pelement->string, "FL%3f", ftransponser1);

but it gives me "FL3.65".

Any ideas?
 
Check formatting tags. To mimic the tooltip text, try:

sprintf(pelement->string, "FL%03d", (UINT32)ftransponser1);

Tom
 
Much better.
It gives me "FL003", but original XML still gives "FL004".
Maybe it's a problem with shortening of number.
 
Back
Top