Wednesday, 30 December 2009

An ARINC 661 tutorial: Hello World

After the general overview and an architecture presentation, this is the third post about the ARINC 661 standard.

Let's continue by a little Hello World. Following the tradition, we will want to show a "Hello World!" label. But to make this example a little more interesting, we will put it in a container.

You should remember that all graphic stuff in ARINC 661 is performed in the CDS side (the ARINC 661 Server). Also the definition of the GUI is stored in a Definition File (DF) which is used by the CDS at initialization. There are two "flavors" of DFs: The binary version (which was the only one which was defined at the beginning of the standard), and the XML version, which was mainly devised to simplify Definition File editing (but as all the informations provided in the binary DFs are also there in the XML DFs, nothing prevent to use them also in a ARINC 661 Server).

We will probably cover binary DFs in another part of this tutorial, but for now, we will use XML Definition Files to explain how the standard works.

So are you ready. Let's dive into our first ARINC 661 Definition File guys!

It's a simple Hello World so we will only define one very simple DF. OK, let's go:

<?xml version="1.0"?>
<!DOCTYPE a661_df SYSTEM "a661.dtd">
<a661_df library_version="0" supp_version="2">
<model>
<prop name="ApplicationId" value="1"/>
</model>
<a661_layer>
<model>
<prop name="LayerId" value="5"/>
<prop name="ContextNumber" value="0"/>
<prop name="Height" value="10000"/>
<prop name="Width" value="10000"/>
</model>
<a661_widget name="SamplePanel" type="A661_PANEL">
<model>
<prop name="WidgetIdent" value="1"/>
<prop name="Enable" value="A661_TRUE"/>
<prop name="Visible" value="A661_TRUE"/>
<prop name="PosX" value="0"/>
<prop name="PosY" value="0"/>
<prop name="SizeX" value="10000"/>
<prop name="SizeY" value="10000"/>
<prop name="StyleSet" value="STYLESET_DEFAULT"/>
</model>
<a661_widget name="Hello World Label" type="A661_LABEL">
<model>
<prop name="WidgetIdent" value="2"/>
<prop name="Anonymous" value="A661_FALSE"/>
<prop name="Visible" value="A661_TRUE"/>
<prop name="PosX" value="5000" />
<prop name="PosY" value="5000" />
<prop name="SizeX" value="1500" />
<prop name="SizeY" value="1000" />
<prop name="StyleSet" value="STYLESET_DEFAULT" />
<prop name="MaxStringLength" value="20" />
<prop name="Alignment" value="A661_CENTER" />
<prop name="LabelString" value="Hello World!" />
<prop name="ColorIndex" value="black" />
<prop name="RotationAngle" value="0.0" />
<prop name="MotionAllowed" value="A661_TRUE" />
</model>
</a661_widget>
</a661_widget>
</a661_layer>
</a661_df>

OK, now lets go to the details.

<?xml version="1.0"?>
<!DOCTYPE a661_df SYSTEM "a661.dtd">

Well like all XML documents, it begins with the declaration of the DTD for ARINC 661. Nothing much to say here. Here the DTD is assumed to be in the file system, but there's nothing particular about the DTD declaration in the standard.

<a661_df library_version="0" supp_version="2">

The supplement (or release) version of the standard. Tne standard is currently at supplement 3. This allows to define for which version the DF was defined.

<model>
<prop name="ApplicationId" value="1"/>
</model>

The first interesting thing here. The ARINC 661 standard defines a concept of Applications, or User Applications (see the previous post). A User Application can send or receive messages to/from the Server. And there is a gold rule: Each Definition File defines widgets (I will explain how later in this post), but the widgets defined in this Definition File are managed by one Application only. That way, we are sure that will be no resource conflicts on who is able to change the state of a widget. This is an important feature which may simplify certification of an ARINC 661 Cockpit Display System, but also allows ARINC 661 implementation to live peacefully in the context of Integrated Modular Avionics (such as ARINC 653). So here we define the identification of the Application which will manage this Definition File content (of course an Application can manage more than one DF).

<a661_layer>
<model>
<prop name="LayerId" value="5"/>
<prop name="ContextNumber" value="0"/>
<prop name="Height" value="10000"/>
<prop name="Width" value="10000"/>
</model>

Here we have the declaration of a Layer, which is the top-most element in the ARINC 661 widget hierarchy. A Definition File contains one or more Layers, but a Layer is not a widget, which means that it is not possible to include a layer as a child of another. hmm almost but we will look after that later (in another post).
Height and Width are optional, because a Layer being not a Widget, defining its size is just a hint (in the XML File, it may be used by for editors). The ContextNumber is something used in runtime, we will also left it in another post.

<a661_widget name="SamplePanel" type="A661_PANEL">
<model>
<prop name="WidgetIdent" value="1"/>
<prop name="Enable" value="A661_TRUE"/>
<prop name="Visible" value="A661_TRUE"/>
<prop name="PosX" value="0"/>
<prop name="PosY" value="0"/>
<prop name="SizeX" value="10000"/>
<prop name="SizeY" value="10000"/>
<prop name="StyleSet" value="STYLESET_DEFAULT"/>
</model>

Our top-most widget in the Layer (we also can have more than one top-most elements in a Layer, we just chose here to have only one of them). For each widget declaration we have its name and most importantly, its type, here A661_PANEL. The widget type just points on one fixed widget type defined in the ARINC 661 Standard. A661_PANEL is a container which can have a Look and Feel. In fact it's exactly the ARINC 661 definition of a Panel.
Another very important part of each widget identify is its WidgetId, which must be unique for each Layer. Apart from this identification, our panel has a position and a Size
I know what question you will ask: all of this is very good, but were is its background color, its border color and all this stuff? Well Look and Feel is not in the Definition of the GUI, as in all well-defined widget toolkits. Unfortunately the standard does not standardize the Look and Feel definition itself.
Not completely. It allows to define the style of the widget, using a keyword or a number. That way, if you have defined elsewhere several styles for your widget, you can point to it in your Definition File, by using the property StyleSet.

<a661_widget name="Hello World Label" type="A661_LABEL">
<model>
<prop name="WidgetIdent" value="2"/>
<prop name="Anonymous" value="A661_FALSE"/>
<prop name="Visible" value="A661_TRUE"/>
<prop name="PosX" value="5000" />
<prop name="PosY" value="5000" />
<prop name="SizeX" value="1500" />
<prop name="SizeY" value="1000" />
<prop name="StyleSet" value="STYLESET_DEFAULT" />
<prop name="MaxStringLength" value="20" />
<prop name="Alignment" value="A661_CENTER" />
<prop name="LabelString" value="Hello World!" />
<prop name="ColorIndex" value="black" />
<prop name="RotationAngle" value="0.0" />
<prop name="MotionAllowed" value="A661_TRUE" />
</model>
</a661_widget>

After that it is very simple. You understand that the label (type: A661_LABEL of course) is a child of the A661_PANEL container. As was already the case for the StyleSet, the Font used to draw the label is a pointer to a Font resource defined elsewhere. The Alignment of the label use one of several already fixed enumeration values, but this should be straithforward. And MaxStringLength is something that will be useful at runtime. It defines the maximum number of characters that the label can accept (if modified by the User Application), and it ensures that no memory allocation will be necessary after the Server initialization (something not allowed in certified environments). ColorIndex and RotationAngle and MotionAllowed are also easy to understand.

Two last things to know: In ARINC 661, the reference point is at the bottom left corner, rather than at the two left as in other widget toolkits (or in OpenGL). So the Y axis goes up and not down. And all lengths are defined in 100th of millimeters rather than in pixels, which ensures that the definition will look the same on different monitors. Which is why you can see in this example rather big values for Widths and Heights.
And now a screen shot of the result with a Java-like Look & Feel for the panel:

1 comment:

Hana Hime said...

Hi, there's a typo. It should be "top left" instead of "two left".