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

Scripted UA tutorial



In this tutorial, we will learn about developing a Scripted UA. We will reuse the UA tutorial, and replace the Java User application which replaced the eventAppli of the first tutorial by a Groovy Script.

For this tutorial, you should have already mastered the previous tutorial about developing a Java-coded UA.

Overview

UA Application tutorial architecture

The 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

Scripted UA Application tutorial architecture

We will replace the Java-coded User Application by a Groovy script.

The new architecture is:
uascripttutorialarchi

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 Application

Our User Application will now be coded in Groovy: Now we will develop our User Application:
  • The init() method will be used to add the listener which will listen to the click on the ToggleButton and invoke the event Service
  • The subscribe(ServiceInstance) method will be fired when the User Application module is notified from the publish Service
      int LAYER = 1;
      int TOGGLE_BUTTON = 1;
      int LABEL = 2;
      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());
            }
          }
        });
      }

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

Setting the User Application configuration

Now we will need to specify the properties of the UA application:
      <properties>
         <application name="uaappli" >
            <module name="uaappli" >
               <moduleProperty key="script" value="uaScript.groovy"  />
               <moduleProperty key="a661Config" value="a661/tutorial.properties" />
               <moduleProperty key="includeServer" value="true" />
            </module>
         </application>
      </properties>

See also


Categories: builtin-applis | tutorials | uaappli

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