1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Set data within definition

Discussion in 'SimConnect' started by MachTwo, 17/10/06.

  1. MachTwo

    MachTwo

    Joined:
    29/9/06
    Messages:
    8
    Country:
    unitedkingdom
    I’ve followed the SDK examples Request Data and SetData with success. I would now like to specify which data within a definition to write to – the example SetData writes to the whole definition.
    I believe I need to do something with Tagged Data to accomplish this? Might someone be able to explain what this flag does in layman’s terms?

    What I’m trying to do is read the values of all the fuel tanks within the aircraft and then write to specific tanks. Any help or suggestions would be greatly appreciated – I’ve not progressed with any of my attempts this afternoon.
  2. MachTwo

    MachTwo

    Joined:
    29/9/06
    Messages:
    8
    Country:
    unitedkingdom
    I appreciate everyone is busy. If anyone can spare 2 minutes to explain the reason for using Tagged Data in Sim Connect, I would be very grateful.
  3. Pete Dowson

    Pete Dowson

    Joined:
    25/9/06
    Messages:
    315
    Country:
    unitedkingdom
    I'll try. Sorry I speak C, so I hope you can follow:

    Take an example where one Data Definition contains three variables, added in this order:

    X a floating point 64 bit value
    Y a 32-bit integer
    Z a 32 byte string

    Without tagging the data exchanged, each time it needed to be (e.g. each time any of them changed), is done so in a block formed by this structure:

    struct {
    double X;
    int Y;
    char Z[32];
    } MyData;

    That's fine, and it is efficient enough for a small number of values, or if none of the values change very frequently, or all of them change frequently. This is because they ALL have to be present every time -- otherwise you or simconnect wouldn't be able to encode/decode the values.

    One alternative is to use a different data definition for each separate value. In fact I had to do this to Write SimVars in Betas1 and 2 of FSX because Tagged Data could only be used for Reads.

    With tagged data you don't have a fixed structure for all the variables in the data definition. You have the data supplied as needed, but each entry is preceded by its ID, as a 32-bit DWORD. Each variable is effecitvely structured separately, thus:

    struct {
    DWORD id;
    double X;
    } MyX;

    struct {
    DWORD id;
    int Y;
    } MyY;

    struct {
    DWORD id;
    char Z[32];
    } MyZ;

    Then, the data transferred in any one read or write could be a mix of these, or just one, all strung together.

    This way you only get or send the data items which have changed.

    So, it's horses for courses. you need to decide which is the best for your data -- and, don't forget, splitting your data into different Data Definitions any way. Some may be best tagged, others best untagged. It is very flexible.

    Hope this is understandable?

    [BTW my carefully tabbed text doesn't come out tabbed when posted. Anyone know how to make that happen? Even spaces at the start of the line are discarded!! :-(]

    Regards

    Pete
  4. MachTwo

    MachTwo

    Joined:
    29/9/06
    Messages:
    8
    Country:
    unitedkingdom
    Many thanks Pete for taking the time to answer.

    So if I understand correctly, I can make one call to SetDataOnSimObject specifying more than one ID to write to?

    Something like:

    Code:
     hr = SimConnect_SetDataOnSimObject(hSimConnect, DEFINITION_6, SIMCONNECT_OBJECT_ID_USER, DATA_VERTICAL_SPEED | DATA_PITOT_HEAT, 0, sizeof(Init), &Init );
    Although the struct Init in the above example will need to contain all the data variables that are within the two ID's, DATA_VERTICAL_SPEED and DATA_PITOT_HEAT respectively, is that correct? I can't find any examples in the SDK for setting tagged data.

    They should work within [ code][/ code] tags.
    Thanks again.

    Best Regards.
  5. Pete Dowson

    Pete Dowson

    Joined:
    25/9/06
    Messages:
    315
    Country:
    unitedkingdom
    The IDs are the tags in the data. You don't ever specify the specific data in the SetDataOnSimObject call. All the data for a data definition is defined by your sequence of AddToDataDefinition calls. Thats the ONLY place you actually refer to the data name!

    I'm afraid you misunderstood me 100% Sorry, I am not a good teacher. Whether the data is tagged or not is totally irrelevant to the capability of setting or reading more than one value at a time. It's just that without tags you have to read or write ALL the data ALL the time. With tags, since the tag identifies the data item, you only need send or receive the ones that matter at that time.

    No, nothing like that at all. How do you translate that 4th parameter, which says "Flags", into an 'or' of some arbitrary IDs like DATA_VERTICAL_SPEED | DATA_PITOT_HEAT? There's an impossible transition there. The only flags you can use are those specified in the Dox -- and the only one is the TAGGED flag!

    I'm sorry, I've exhausted my powers of explanation here. Please try re-reading my earlier explanation. if you still cannot make head or tail of it I will have to leave it to others. Sorry.

    Regards

    Pete
  6. MachTwo

    MachTwo

    Joined:
    29/9/06
    Messages:
    8
    Country:
    unitedkingdom
    Hi Pete,

    Actually this paragraph sums it up pretty well – thank you. I think for what I’m trying to do, I need to use multiple definitions as using the TAGGED flag on SetData will only set the values that have changed, if I understand correctly.

    Appreciate your time.
    Best Regards.
    Last edited: 19/10/06
  7. Pete Dowson

    Pete Dowson

    Joined:
    25/9/06
    Messages:
    315
    Country:
    unitedkingdom
    No, that's not true either. With tagged data you only RECEIVE the data that changes, whereas with with untagged you receive ALL of the data in a data definition even if only one item has changed.

    That's for Reads. For Writes it is similar but the other way round: With tagged data you only have to supply the data that you want to write, whereas with untagged data you have to supply ALL of the data in a definition even if you only want to change one item!

    You see, I think you have it all backwards somehow, and I can't understand why, reading what I wrote to you. :-(

    It should actually be blindingly obvious! Please stop, lean back, and think about it some. Tagged data is TAGGED -- in other words each item of data identifies itself with an ID. Untagged data is not self-identified.

    If data identifies itself you have the utmost flexibility in what you send and receive. Each item says what it is by its tag, its "label" if you prefer.

    If data is only identified by its position in a big block of data, as untagged data is, then that big block ALWAYS has to be supplied. Otherwise how can you tell what's what?

    Do you see now? I don't really know if I can think of any more ways to say the same thing! :-(

    Pete

Share This Page