• 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.

C to XML

Tom,

> return get_named_variable_typed_value(register_named_variable(szName),get_units_enum(szUnits));

I cannot deny it could look "comfortable" but isn't it inefficient "by nature", it the sense that every time to execute this line of code you're imposing the "gauge engine" to search within (I imagine) FSX internal defined LVARS array, if szName has already been defined (and so recycle its ID or define a new one)? And the larger the LVARS array becomes, the more time gets wasted?

> bool bValue = (bool)GetLVAR("CDU1_Key","number");

Also, another thing I don't understand, here you're just initializing bValue to the (casted bool) content of "CDU1_Key" LVAR.
You are NOT associating bValue to be automaGically updated as soon as "CDU1_Key" LVAR content changes right?
So to keep bValue aligned with "CDU1_Key" you'll have to (continuously) re-execute "bValue = (bool)GetLVAR("CDU1_Key","number");"
Is this correct?

Marco
 
I cannot deny it could look "comfortable" but isn't it inefficient "by nature", it the sense that every time to execute this line of code you're imposing the "gauge engine" to search within (I imagine) FSX internal defined LVARS array, if szName has already been defined (and so recycle its ID or define a new one)? And the larger the LVARS array becomes, the more time gets wasted?

Well, it has advantages and disadvantages as everything in programming, but for a small to regular number of LVars there should be no noticeable differences.

There are only two ways of assigning/retrieving an LVar value in C++: either by its known ID, or by its string name.

In the first case, you need to store the ID in another global var, therefore if you have hundreths of vars you'll need hundreths of extra globals. Unless you design an array to handle them, but even then you'll need an extra structure. Or you can build a class and manage all of the data with it, again using an extra structure.

Perhaps my method might not be the fastest, though I believe it is a good trade between "fast" and "comfortable" (== "efficient" to me :))

Also, another thing I don't understand, here you're just initializing bValue to the (casted bool) content of "CDU1_Key" LVAR.
You are NOT associating bValue to be automaGically updated as soon as "CDU1_Key" LVAR content changes right?
So to keep bValue aligned with "CDU1_Key" you'll have to (continuously) re-execute "bValue = (bool)GetLVAR("CDU1_Key","number");"
Is this correct?

The casting was only an example on how to convert C++ units before assigning the function's resultant value.
And, as I stated before, there is no automatic update between an LVar and its associated C variable.

If, for example, some XML gauge changes the value of "CDU1_Key", I need to use get_named_variable_typed_value or get_named_variable_value functions to obtain it in my C++ gauge.


Tom
 
I think I received enough information to start working on building a first primitive prototype.
Thanks a billion to all of you, Tom in particular, wasting some of your precious time to help me, much appreciated!
I'm sure I'll need tons of additional hints in the near future so...don't think you got rid of me so easily :)

Marco
 
...and here I am! :rotfl:
Question especially for Tom, as he implemented a triple INS....

If you have 3 Mode Select Unit (MSU) because you're dealing with 3 (almost) completely separate INS units, each MSU (MSU1, MSU2, MSU3) will have to be sensible to different LVARS.

Let's take for example the state of the BAT Light:

MSU1 will have to be sentible to an LVAR named L:Civa_Msu_Bat_1
MSU2 will have to be sentible to an LVAR named L:Civa_Msu_Bat_2
MSU3 will have to be sentible to an LVAR named L:Civa_Msu_Bat_3

Can this be done runtime and have only one "Msu.xml" or am I forced to create 3 xml gauge, one for each MSU?

As usual thank you very much in advance!
Marco
 
Marco,

There are two different roads to follow here:

1) Virtual Cockpit commands.
Here you have a single, big XML file called modeldef.xml, in where all of XML scripts for animations and commanded events are placed. If you include three MSU units, then there will be three different related "sections" in that file, and you will need to use three different var names to be linked with your internal code. And yes, you would have to define L:Civa_Msu_Bat_1 for unit #1, L:Civa_Msu_Bat_2 for #2 and so on.

2) 2D/Popup panels
In this case, you could well decide to include you current (C++) units (CDU1,CDU2,MSU1, etc), or let the XML developer include its own design of the CDUs and MSUs. In this case the developer can make use of the same LVars you defined for the Virtual Cockpit.

In both situations, all you have to do is publish the name of the LVARS in a reference table, something like:

Code:
MSU unit #1
============
(L:MSU1_Switch,enum)  ---> Rotary switch  0 = Off 1 = Stdby 2 = Align 3 = Nav  4 = Att
(L:MSU1_Battery,bool)   ---> Battery Light   0 = Off  1 = On
etc..

MSU unit #2
============
(L:MSU2_Switch,enum)  ---> Rotary switch  0 = Off 1 = Stdby 2 = Align 3 = Nav  4 = Att
(L:MSU2_Battery,bool)   ---> Battery Light   0 = Off  1 = On
etc..

CDU  unit #1
============
(L:CDU1_DataSelector,enum) ---> Data Selector 0 =TK/GS  1 =HDG/DA  2 =XTK/TKE  etc
(L:CDU1_Key_1,bool) ---> Key #1  1 = Pressed  0 = Released
etc

Shouldn't be difficult to implement for any enthusiastic XML developer.

OR, if you prefer to reduce the number of LVars and expect a good understanding from your potential "customers":

Code:
(L:CIVA1_Master,enum)  ---> Master Variable for INS #1 (CDU and MSU)
Values 100 to 104 for MSU Rotary switch 100=OFF 101=StdBy 102=Align etc
Values 200 to 207 for CDU Data Selector  200=TK/GS 201=HDG/DA etc
Values 300 to 309 for CDU Numeric Keypad 300=Key #0 301=Key #1 etc
etc..

(L:CIVA2_Master,enum)  ---> Master Variable for INS #2 (CDU and MSU)
Values 100 to 104 for MSU Rotary switch 100=OFF 101=StdBy 102=Align etc
Values 200 to 207 for CDU Data Selector  200=TK/GS 201=HDG/DA etc
Values 300 to 309 for CDU Numeric Keypad 300=Key #0 301=Key #1 etc
etc..

Tom
 
Tom,

your hints are always very clear and welcome but (and I am sorry for it) my ignorance in this specific area is so evident I'm not even able to ask questions in a way they could be comprehensible :( On top English is not my native language (I'm Italian) making things even harder for me, again sorry for that.

Let me briefly describe what I'm trying to do.

My phase zero, given my zero knowledge with XML gauges, is to build something simple, basic, but something I can achieve.
Final target is to build both CDU and MSU, identical to C++ ones, but coded in XML, to be included in the CIVA SDK as reference.
So phase zero means building a CIVA MSU gauge, written i XML, to be used in a 2D panel (I cannot afford working on a VC, no knowledge, I'm alone, limited time...no way).

I want it to be identical (in terms of look [as I already have the bmps, and sub-bmps coordinates, mouse areas coordinates etc] and functionality) to the one implemented in C.
I believe this, appearing as trivial to experts like you, would already be a major step for me, major but not impossible because, as I wrote, I want it to be achievable.

So here is what I'm doing (NOTE: This is a prototype, nothing "final" here!):

I created a new xml file, named MSU_1.xml where I will have to deal with the BAT and NAV READY lights plus the Mode Selector Knob Position, for MSU belonging to INS #1.

BAT and NAV READY lights will be "read only" (from XML point of view), ModeSel position will be "read/write".

So, relatively to INS#1, I'l have to be sentible to/acting on L:Civa1_MsuBatLight, L:Civa1_MsuNavLight, and L:Civa1_MsuKnobPos variables (actual variable names still to be decided).

My original question was:

Can I avoid writing 3 xml files, one for MSU#1, one for MSU#2 and one for MSU#3, and have, instead, just one, generic MSU.xml which, SOMEHOW, is able to get # on CIVA unit it is going to act on, by taking it for example (talking C/C++ here) by the fifth argument specified in the gaugeXX syntax in panel.cfg?

So, is it possible to build a variable name at runtime making possible to build a "generic" MSU.xml acting on INS#1, 2 or 3 depending on the passed parameter?

Once again thank you so much,
Marco
 
Marco,

Please enlighten me: Do you want to rebuild your (current C++) INS system (at least the CDUs and MSUs) in XML, or you want other XML developers be able to operate it using XML code??

Tom
 
Tom,

my goal is to build up to 3 MSUs and a CDUs "front end"s, written in XML, relying to the C++ INS "engine", to FIRST test the L:VARS mechanism (if everything works and has been made available) and second to include it in the (free) SDK, as reference.

If I'll be not able tot to "drive and be driven" by the existing C++ INS engine from an XML gauge "layer" how could I "pretend" other will be able to? Also I don't want to release something incomplete/unstable and then being submerged by bugs/enhancements requests...

Yes, I'm willing to allow third parties to build XML based CDUs and MSUs, using the C/C++ "engine", but before releasing it I'd like to try to use it myself, to make sure it is actually usable by others...

So, to answer your original question: I want both, being myself the first "other XML developer" having to deal with what I'm going to release :-)

Marco
 
Ok.

Still I believe you don't need to build a single line of XML code. All that you need to do is reprogram the C++ core of the INS system, making one that has no visual display at all, but can receive data sent by XML scripts either in VC MDL file or popup panel gauges, through the LVar system.

Let me give you a raw example:

Suppose that one XML developer designs a 3D CDU to be included in a VC:

INS.jpg



Let's pretend the above is a VC unit (forgive the image!), and every key and dial is animated.
The XML developer wants that, when he press a key -ie the #1 outlined in red-, the core of your INS system detects it and behaves as expected.

Supposing you release an SDK for XML developers, and define that, when the #1 key is pressed, you need to read 1 in (L:CDU1_Key1,bool).
Then in modeldef.xml, the XML developer will code:

Code:
<PartInfo>
    <Name>CDU1_Key1</Name>
    <AnimLength>5</AnimLength>
    <Animation>
      <Parameter>
        <Code>
          (L:CDU1_Key1,bool) 5 *
        </Code>
      </Parameter>
    </Animation>
    <MouseRect>
      <Cursor>Hand</Cursor>
      <MouseFlags>LeftSingle</MouseFlags>
      <CallbackCode>
          (M:Event) 'LeftSingle' scmp 0 == if{ 1 (>L:CDU1_Key1,bool) }
      </CallbackCode>
    </MouseRect>
  </PartInfo>

And you, in your C++ core gauge must capture that:

Code:
ID32 idCDU1Input = GetLVAR("CDU1_Key1","bool");
if( dCDU1Input != 0 )
{
    DoAnAction(idCDU1Input);
   SetLVAR(0,"CDU1_Key1","bool");  // remove the flag and return back to the XML side
}

Get the idea?

So what you need to do is define the group of LVars to be used in data exchange. Something almost identical to what you did for C++ developers in CIVA SDK.

And, if you need to test those LVars exchanging values, I for you would code a C++ gauge with a CDU background outlined, with all the keys and dials receiving input in their corresponding LVars.
I bet you'll make that gauge in less time than it will take you to learn XML up to a level needed for what you want to do.

Again, forgive me for the very basic example.

Tom
 
> you don't need to build a single line of XML code. All that you need to do is reprogram the C++ core of the INS system,
> making one that has no visual display at all, but can receive data sent by XML scripts either in VC MDL file or popup panel
> gauges, through the LVar system.

CIVA INS has been designed and implemented like you are saying.
There is ONE gauge acting as a sort of "server" (simulating the INU) and providing all INS functionalities. Then there are "satellite" gauges implementing MSUs and CDUs and containing no, or very minor, logic.
I did it so because it resembles how the real unit works, having the INU doing all the job and CDUs/MSUs being only the human interface to the INU. So from this point of view I have nothing, or almost nothing, to do.

Actually satellite gauges do not communicate with the INU through "variables" but instead they use a sort of "events".
For this reason I'm willing to develop an additional gauge acting as a bridge between LVARS and "events", so that (a) I don't need to touch the INU gauge and (b) the bridging gauge could be used only when needed.

I already have something like that, bridging the INU gauge with a primitive, Arduino based, hardware MSU/CDU, which is working nicely. Unfortunately it's not a gauge, it's a separate EXE, but it will not cost much to convert it to an FS gauge and to substitute Arduino I/O interface with LVARS handling.

> So what you need to do is define the group of LVars to be used in data exchange

This is clear and I'm already building the list.

> And, if you need to test those LVars exchanging values, I for you would code a C++ gauge with a CDU background
> outlined, with all the keys and dials receiving input in their corresponding LVars.
> I bet you'll make that gauge in less time than it will take you to learn XML up to a level needed for what you want to do.

You're very probably right but then I'd not have an XML example to include in the SDK. I'll try to do that, if I'll see it would cost me too much time then I'll surely revert back to your suggested solution!

Marco
 
CIVA INS has been designed and implemented like you are saying.

I did the same for my INS system, having a master, "server" gauge and other small ones for each CDU/MSU unit (all XML code).

I've checked your INS SDK and found that this function :

int InsEcsPostCommand ( enum INSUNIT iUnitId, int iCommand )

is the core of the external data exchange. By the way it is implemented (constant IDs), I believe the best approach would be to assign sort of "constant" values to a single, master CDU unit LVar that you could check against your internal set of constants (ie ECS_0, ECS_1, etc).

You're very probably right but then I'd not have an XML example to include in the SDK. I'll try to do that, if I'll see it would cost me too much time then I'll surely revert back to your suggested solution!

Right. Anyway I think your XML interface would be most useful to Virtual Cockpit developers, which currently don't have a simple option to link the 3D animated parts with the INS core unless they code another "bridge" C++ gauge using the C++ SDK. Perhaps a basic example gauge, displaying a CDU background and including mouse areas for each key would be sufficient, and probably you would be able to build it fast, considering you have great expertise in gauge programming.

As your INS systems is beyond excelence, I have no doubts that your XML interface will be the same.

Tom

PS: Honestly, I never liked that your INS depens on the autopilot heading hold mode to follow a track. Instead, I developed a custom PID which commands ailerons to maintain a crosstrack error of zero degrees, leaving the AP HDG mode free to the pilot, like the rest of AP commands. Just an idea ;)
 
int InsEcsPostCommand ( enum INSUNIT iUnitId, int iCommand )

That is a very initial design which, BTW, in currently available CIVA version...does NOT work :D

Honestly, I never liked that your INS depens on the autopilot heading hold mode to follow a track. Instead, I developed a custom PID which commands ailerons to maintain a crosstrack error of zero degrees, leaving the AP HDG mode free to the pilot, like the rest of AP commands. Just an idea

I agree with you, and I already thought about that. The problem is that it is VERY difficult to design a PID so generic and "self adjusting" to work well on "any" aircraft where CIVA gets installed. If you're working for a single target you could then tune the PID for the specific flight model of one aircraft. Still not easy (PID tuning is not a game) but achievable...

Marco
 
That is a very initial design which, BTW, in currently available CIVA version...does NOT work :D

OOps...LOL! But the idea still remains, uh?

The problem is that it is VERY difficult to design a PID so generic and "self adjusting" to work well on "any" aircraft where CIVA gets installed

Good point. My INS was first installed in a 747-200 many years ago (2007/2008). Now it is being included in a DC-8 50, which you know of, and I didn't need to adjust any of the PID parameters. Luck, perhaps? or maybe because some of their flight characteristics are similar? I don't have a right answer for that.

Tom
 
OOps...LOL! But the idea still remains, uh?

Yes, in the new version I'm currently working on, ECS has been extended plus, as a bonus, it also works! :wizard:

Luck, perhaps? or maybe because some of their flight characteristics are similar? I don't have a right answer for that.

Me neither but surely they are more "similar" than let's say LearJet (I use it for testing in single INS config) vs Concorde.

Marco
 
Uh...I got stuck...

void set_named_variable_typed_value(
ID
id,
FLOAT64
value,
ENUM
units
);

Is it possible to use set_named_variable_typed_value() to "publish" a string?
If yes, what am I supposed to pass as value, the address of the string (I tried with no success but maybe I'm doing something wrong...)?
If no :( then how can I set an L:VAR having string type?

Thanks a billion in advance!
Marco
 
Ok...I searched deeper and found there is no way of having a string type L:VAR except using "tricks" as explained here -> http://www.fsdeveloper.com/forum/threads/storing-string-data.94088/

Fortunately (well....I don't know yet actually) for the INS the longest string I have to handle is 6 characters long, which would theoretically fit a C++ float type variable.

I have seen and checked the XML macros included in the thread above but...since I'm really limited in understanding XML...I'd have few questions:

- Why those macros have a '4', like "Read4", "Read4Str"? Are they able to handle 4 characters long strings (only)?

- I'm unable to understand how I would have to prepare a double type value in C++ in order to make it "edible" by that kind of macros. I really can't understand syntax like:

Code:
(@1_4, number) 7 &lt;&lt; 0xFFFFFFF &amp; (@1_3, number) 21 >> 0x7F &amp; | (>@1_4, number)

I understand there is bit shifting involved, and as far as I'm able to decipher...and I suspect characters are considered to be 7 bits wide...is this correct? Why not 8 bits?

- All of the strings I have to handle through LVARS are "read only" in the sense that I have to set the variable from the C++ side, and read them from XML. I'll need to handle 3 strings with length equal to 2, 5 and 6 characters, would I have to use 3 different sets of macros?

Any help would be much appreciated!
Thank you
Marco
 
Hello Tom!

your contribution is as usual priceless and most welcome but...in my total ignorance, what's XML tools?
I mean is that a module (or whatever) to be installed within FS/P3D?
I guess that a gauge relying on XMLTOOLS would then require "its" presence on the target system.
If so then how can I check if it is already installed?
Or, if not, how could I install it?
Or, do I simply have to state, in the manuals, "XMLTOOLS has to be installed first"?

BTW in the meantime I had some kind of success encoding a 2 chars string into a "number" (C++ side) and decoding and displaying it, as a string, on the XML side (excuse the very dirty code style but I'm just experimenting):

Code:
C++ Side:

typedef union {
 
   unsigned long ulVal;
   char cStr [ 4 ];
 
} DSTR, * PDSTR;

double str2d ( char * pszStr )
{
   DSTR tDs;
 
   tDs.ulVal = 0;

   // Little endian :-) 
   tDs.cStr [ 3 ] = pszStr [ 0 ];
   tDs.cStr [ 2 ] = pszStr [ 1 ];
   tDs.cStr [ 1 ] = 0;
   tDs.cStr [ 0 ] = 0;
 
   return ( ( double ) tDs.ulVal );
}

static void CduFromToDisplay ( PXVAR ptXv )
{
  char  szFtD [ 3 ] = "\x20\x20\x00";
  double dVal;

  if ( ptInuState->tCdu.tFromToDisplay.bBlinkingOn == FALSE )
  {
     strncpy ( szFtD, ptInuState->tCdu.tFromToDisplay.szString, 3 );
  }

  dVal = d2str ( szFtD );
  ptXv->dPrevValue = dVal;

  set_named_variable_typed_value ( ptXv->iVarId,
                                                     ( FLOAT64 ) ptXv->dPrevValue,
                                                     ptXv->iUnitId );
  
  return;
}


On the XML side:

<Macro Name="FtdString">
      (@1, number) 24 >> 0xFF &amp; chr
      (@1, number) 16 >> 0xFF &amp; chr scat
</Macro>

Then within an "Element" I use:

<String>%(@FtdString(L:CivaCduFromToDisplay:1, number))%!s!</String>

Thank you!
Marco
 
Marco,

XMLTools is indeed a module (dll) that must be present in FSX/P3D folder, and also referenced in DLL.XML file.

One of its classes, XMLVARS, supports variables of string and number type. They support array management as well, something not possible with standard XML vars.

You can include the module with your product - it has its own installer - or you can advice the user to download and install it on its own. And the installer detects whether a copy of XMLTools is already present in FSX/P3D folder, you don't have to worry about that.

All this said, I believe you don't need to use XML string vars neither for the ToFrom data nor the left and right data displays. All can be done using XML standard LVars.
I can give you some hints on this if you are interested, just let me know.

Tom
 
I believe you don't need to use XML string vars neither for the ToFrom data nor the left and right data displays. All can be done using XML standard LVars.
I can give you some hints on this if you are interested, just let me know.

I am definitely interested Tom, especially if this does not imply rewriting a major pat of the (existing) INS code!
 
Back
Top