Open ThyMYthOS opened 1 year ago
By using the modulo operation in the conditions of the type refinements, the workaround that you described might work:
type HDLC_Frame is
message
-- ...
Virtual_Control : Control;
Control : Opaque
with First => Virtual_Control'First, Size => 8;
-- ...
end message;
for HDLC_Frame use (Control => I_Frame_Control)
if Virtual_Control mod 2 = 0;
for HDLC_Frame use (Control => S_Frame_Control)
if Virtual_Control mod 4 = 1;
for HDLC_Frame use (Control => U_Frame_Control)
if Virtual_Control mod 4 = 3;
I also think that for a reasonable specification, the bit order must be configurable. The mechanisms discussed in #1254 could probably be used to specify the type
field in the U-frame, but #1254 is still in the design stage.
Here are the problems I stumbled into, trying to implement a real world example: HDLC. For those who need a refresher what HDLC is, see Wikipedia and these lecture slides.
The main issue is the control field. It looks different, depending on the type of frame:
type
field is split into two parts.I tried to solve this, by duplicating the
Control
field: first as 8-bit integer and then asOpaque
field using theFirst
attribute to overlay both. TheOpaque
field would then have a type refinement forI_Frame_Control
,S_Frame_Control
andU_Frame_Control
. But it's not possible to actually write the type refinement, since the condition cannot do any bit operations on the 8-bit integer value.I think this could be solved with two additional features in RecordFlux:
If you have other ideas how to write a specification for HDLC please feel free to comment.