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

Developing a Scripted UA



This article explains how to develop a scripted User Application usable in the UA application built-in plugin. The UA must be coded using the Groovy scripting language. Groovy modules can have the same syntax as the Java language.

Content

Methods

A scripted UA is a groovy script file wich can have the following methods (all optional):
  • public void init(): called when the UA Application is initialized
  • public void start(): called when the UA Application is started
  • public void subscribe(ServiceInstance): called when the UA Application is notified from one of the Services on which the UA is subscribed to
  • public void push(ServiceInstance): called when the UA Application is called automatically for a cyclic invocation[1]
    It is the case when a publish Service is called cyclically for the UA Application, for example: <cyclic service="position" frequency="100ms" />
The interface for the Script is Script.

Members

The script has three default members[2]
They do not need to be declared in the script
:

Script context

The script context is an instance of the UAScriptContext class.

The Script context allows to:

Script helper

Several methods are provided in the UAScriptHelper class to get the values of the datas in the Service:
  • Some methods do not take as argument the service name, and they will look for a Data in any Service
  • Some methods take as argument the service name, those will look for values for the service which is explictly specified

Detecting if a data value has changed

There are two methods to detect if a Data value has changed:

Getting a data value

Main Article: Data manipulation

There are two sets of methods to get the value of a Data:
  • The getxxxValue(String) methods return the value of a Data in a specified type, if there is only one Service which has a Data with this name[3]
    This will not work correctly if two Services have two different Datas of the same name
  • The getxxxValue(String, String) methods return the value of a Data in a specified type for the a specified Service


For example:

Setting a data value

Main Article: Data manipulation

To set the value for a Data, you should first get the Data of a specified name:

Then you can set the value of this Data through the Data class. For example to set the value of a Data as a float:

Examples

For the defaultSubscribeService:
      public void subscribe(ServiceInstance service) {
        if (helper.hasChanged("value")) {
          String value = helper.getStringValue("value");
          api.setWidgetParameter(LAYER, LABEL, ARINC661.A661_STRING, value);
          api.sendAll();
        }
      }
For a specified service:
      public void subscribe(ServiceInstance service) {
        if (helper.hasChanged("publishedService", "value")) {
          String value = helper.getStringValue("publishedService", "value");
          api.setWidgetParameter(LAYER, LABEL, ARINC661.A661_STRING, value);
          api.sendAll();
        }
      }

Invoking Services

It is possible to invoke Services using the ServiceInstance.invoke() method.

For example:
      service.setDataBooleanValue("event", isSelected);
      service.invoke();

Comparison with Java User Applications

The content of a Groovy Script is very close to what you would write in a Java User Application. The main differences are:
  • The logger is accessed through the script context. For example, the following code: logger.error(message) should be replaced by context.error(message)
  • The methods in the AbstractFunctionalUA class are replaced by the equivalent methods in the UAScriptHelper class. For example, the following code:getStringValue("value"); should be replaced by helper.getStringValue("value");

Example

      int LAYER = 1;
      int TOGGLE_BUTTON = 1;
      int LABEL = 2;
      SendEventServiceInstance eventService = null;

      public void init() {
        this.eventService = (SendEventServiceInstance) context.getModule().getService("event");
        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();
        }
      }

Notes

  1. ^ It is the case when a publish Service is called cyclically for the UA Application, for example: <cyclic service="position" frequency="100ms" />
  2. ^ They do not need to be declared in the script
  3. ^ [1] [2] [3] [4] This will not work correctly if two Services have two different Datas of the same name

See also


Categories: builtin-applis | uaappli

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