Home
Categories
Dictionary
Glossary
Download
Project Details
Changes Log
What Links Here
FAQ
License

Multiple UAs Groovy tutorial



In this tutorial, we will learn about developing User Applications using the uaConfig property. We will reuse the Scripted UA tutorial, and replace the unique script used for the eventAppli by two different scripts.

Overview

UA Application tutorial architecture

The Scripted UA tutorial defined two services:
  • One Service published a value
  • Another Service published the state of a toggle button in case of a click event


And two applications:
  • The first PublishModule had no graphical interface and:
    • Incremented or decremented the value
    • Published cyclically the value
    • Listened to the toggle event to set if the value should increment or decrement
  • A User Application, embedded in a built-in UA application, which will:
    • Subscribe to the published value and show this value on an ARINC 661 Layer
    • Show a ToggleButton on the ARINC 661 Layer and sends an event when the user clicks on this toggle

uatutorial
tuto1archi

Multiple UAs tutorial architecture

We will split the Scripted User Application in two scripted User Applications:
  • The first script will subscribe to the published value and show this value on the ARINC 661 Layer
  • The second script will show a ToggleButton on the same ARINC 661 Layer and sends an event when the user clicks on this toggle


The new architecture is:
multipleuastutorialarchi

Keeping the configuration

We will keep:
  • The types.xml
  • The services.xml
  • The applications.xml, because we will keep the same UA Application. It's only the configuration of the UA Application itself which will change


We will also keep:

Developing the User Applications

Our two User Application will now be coded in Groovy.

Developing the first User Application

The first script subscribe to the published value and show this value on the ARINC 661 Layer:
  • The subscribe(ServiceInstance) method will be fired when the User Application module is notified from the publish Service
      int LAYER = 1;
      int LABEL = 2;

      public void subscribe(ServiceInstance service) {
        if (helper.hasChanged("value")) {
          String value = helper.getStringValue("value");
          api.setWidgetParameter(LAYER, LABEL, ARINC661.A661_STRING, value);
          api.sendAll();
        }
      }

Developing the second User Application

The second script show a ToggleButton on the same ARINC 661 Layer and sends an event when the user clicks on this toggle:
  • The init() method will be used to add the listener which will listen to the click on the ToggleButton and invoke the event Service
      int LAYER = 1;
      int TOGGLE_BUTTON = 1;
      SendEventServiceInstance eventService = null;

      public void init() {
        this.eventService = (SendEventServiceInstance) context.getModule().getService("event");
        // listen to widgets events
        api.addWidgetEventListener(LAYER, TOGGLE_BUTTON, new ARINCEventListener() {
          public void eventReceived(ARINCEvent evt) {
            WidgetEvent widgetEvt = (WidgetEvent) evt;
            try {
              boolean isSelected = ((Boolean) widgetEvt.getValues().get(0));
              eventService.setDataBooleanValue("event", isSelected);
              eventService.invoke();
            } catch (ARINCRuntimeException ex) {
              context.error(ex.getMessage());
            }
          }
        });
      }

Setting the User Applications configuration

Now we will need to specify the properties of the UA application:
      <properties>
         <application name="uaappli" >
            <module name="uaappli" >
               <moduleProperty key="uaConfig" value="uaTutorial.xml"  />
               <moduleProperty key="a661Config" value="a661/tutorial.properties" />
               <moduleProperty key="includeServer" value="true" />
            </module>
         </application>
      </properties>
The "uaTutorial.xml" specifies the two UA Applications, each coded as a Groovy script:
      <uas>
         <script url="button.groovy" />
         <script url="label.groovy" defaultSubscribeService="published">
            <subscribe service="published" />
         </script>
      </uas>

See also


Categories: builtin-applis | tutorials | uaappli

Copyright 2017-2020 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v3 licence