commschamp / commsdsl

DSL schemas parser and code generators for CommsChampion Ecosystem
https://commschamp.github.io
Apache License 2.0
20 stars 9 forks source link

Optional condition doesnt work with ref field #1

Closed mathisloge closed 5 years ago

mathisloge commented 5 years ago

Optional condition doesnt work, if the reference field is of type ref which points to a set.

Example:

<fields>

<set name="InfoTypes" length="8">

<bit name="TransponderPosition" idx="0" />

<bit name="GPSPos" idx="1" />

  </set>

</fields>

<message …>

<fields>

 <ref field="InfoTypes"/>

<optional name="TransponderPosition" defaultMode="exists" cond="$InfoTypes.TransponderPosition">

<ref field="PositionCoords"/>

</optional>

</fields>

  </message>
arobenko commented 5 years ago

Thanks for the report, I'll try to evaluate it and introduce a fix during the weekend

arobenko commented 5 years ago

The problem is reproduced and acknowledged. I'll try to introduce a fix during the next week. In the meantime I recommend using a workaround with reuse property. It will just duplicate the code of the field definition instead of creating alias to it.

<message ...>
    <set reuse="InfoTypes" />
    ...
</message>

As the side note, the length of the <set> field is in bytes not in bits. I don't know whether it is your intention, but it's worth mentioning that usage of length="8" property on the set with create a set of 64 bits (8 bytes).

Also note, that the default construction of your InfoTypes bitset should correspond to the default existence mode of your optional field. If you want the optional field to exist by default, then your TransponderPosition bit should be default constructed to be true.

mathisloge commented 5 years ago

Thanks for the info. I also noticed the length attribute.

Just to clarify the second part: What are you meaning by the terms of

default construction of your InfoTypes

If I have the following consturcts:

<set name="InfoTypes" length="1">
            <bit name="Bit1" idx="0" />
        <bit name="Bit2" idx="1" />
 </set>
<optional name="OptField1" defaultMode="exists" cond="$InfoTypes.Bit1">
       <int name="WrappedField1" type="uint8" />
 </optional>
<optional name="OptField2" defaultMode="missing" cond="$InfoTypes.Bit2">
       <int name="WrappedField2" type="uint8" />
</optional>

Then OptField1 with defaultMode="exists" exists always? and OptField2 with defaultMode="missing" cond="$InfoTypes.Bit2" exists only if the cond is true?

arobenko commented 5 years ago

If I understand your definition correctly you want InfoTypes.Bit1 to be an indication of whether OptField1 field exists (being serialized) and InfoTypes.Bit2 is an indicator of whether OptField2 field exists. The way you defined it, the values of your InfoTypes bitset is all zeroes (when default constructed), which indicates that all the subsequent optional fields are missing, but you defined OptField1 to be existing by default.

In other words, when you default construct your message object the values of your fields are in an inconsistent state, and if you send it like this over the I/O link, the other end will read the value of InfoTypes and discard subsequent value of OptField1 because it is marked as missing.

What I'm saying is that if you want the OptField1 to really exist when message object is default constructed, you should have InfoTypes.Bit1 to be initialized to true when constructed.

<set name="InfoTypes" length="1">
        <bit name="Bit1" idx="0" defaultValue="true" />
    <bit name="Bit2" idx="1" />
 </set>
arobenko commented 5 years ago

The fix was introduced to "develop" branch, will be merged to "master" in upcoming release.

mathisloge commented 5 years ago

Thanks for this clarification.

One more thing: How do i specify the some fields in only bits? Especially the size layer? Is it valid to take a set and specify the size in the inner fields?

The RCTM Protocol got some odd design.

grafik

arobenko commented 5 years ago

Unfortunately RTCM protocol is too exotic for both "commsdsl" protocol generator and "COMMS" library. It specifies fields in bits (not bytes) and any message and/or field can end up in the middle of the byte. My work supports combining several bit-length fields into a single field, called "bitfield", but the total length of its inner members mustn't exceed 64 bits and must be dividable by 8, i.e. to end in the boundaries of bytes. You don't have any other choice but to manually implement RTCM protocol if you need one. There should be plenty third party libraries that do it for you.

arobenko commented 5 years ago

Fixed in v2.2.