Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional condition doesnt work with ref field #1

Closed
mathisloge opened this issue Aug 2, 2019 · 8 comments
Closed

Optional condition doesnt work with ref field #1

mathisloge opened this issue Aug 2, 2019 · 8 comments
Labels
bug Something isn't working

Comments

@mathisloge
Copy link
Contributor

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
Copy link
Member

arobenko commented Aug 2, 2019

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

@arobenko
Copy link
Member

arobenko commented Aug 3, 2019

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
Copy link
Contributor Author

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
Copy link
Member

arobenko commented Aug 3, 2019

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 added a commit that referenced this issue Aug 5, 2019
@arobenko
Copy link
Member

arobenko commented Aug 5, 2019

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

@mathisloge
Copy link
Contributor Author

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
Copy link
Member

arobenko commented Aug 5, 2019

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 arobenko added the bug Something isn't working label Aug 10, 2019
@arobenko
Copy link
Member

Fixed in v2.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants