FMS module sending a flightplan service which contains an array of waypoints. Each waypoint is a structure with a latitude and longitude.flightplan service, each one of them will have to decode the content of the data structure upon notification:
flightplan service is the following:<event name="flightplan"> <data name="flightplan" type="waypointArray" /> </event>The types used by this service are:
<simpleType name="float" baseType="float" /> <arrayType name="waypointArray" type="waypoint" /> <structType name="waypoint"> <field name="latitude" type="float" /> <field name="longitude" type="float" /> </structType>
<application name="Aircraft"> <deployment> <lib url="FMS.jar" /> <lib url="Systems.jar" /> </deployment> <modules> <module name="FMS" > <implementation path="org.da.aircraft.FMS" > <initEntryPoint method="init" /> <startEntryPoint method="start" /> <defaultSendEntryPoint method="send" /> </implementation> <interfaces> <eventSend service="flightplan" /> </interfaces> </module> <module name="userModule1" > <implementation path="org.da.aircraft.userModule1" > <initEntryPoint method="init" /> <startEntryPoint method="start" /> <defaultReceiveEntryPoint method="receive" /> </implementation> <interfaces> <eventReceived service="flightplan" /> </interfaces> </module> <module name="userModule2" > <implementation path="org.da.aircraft.userModule2" > <initEntryPoint method="init" /> <startEntryPoint method="start" /> <defaultReceiveEntryPoint method="receive" /> </implementation> <interfaces> <eventReceived service="flightplan" /> </interfaces> </module> </modules> </application>
flightplan service data:public void receive(ServiceInstance service) { Data<ArrayType> fpData = (Data<ArrayType>) service.getData("flightplan"); StructType wptType = (StructType) fpData.getType().getType(); List<Waypoint> wpts = new ArrayList<> List<Object> array = fpData.getValueAsArray(); Iterator<Object> it = array.iterator(); while (it.hasNext()) { Object o = it.next(); float latitude = wptType.getFieldValueAsFloat("latitude", o, Units.DEG); float longitude = wptType.getFieldValueAsFloat("longitude", o, Units.DEG); Waypoint wpt = new Waypoint(); wpt.setPosition(latitude, longitude); wpts.add(wpt); } }Where the
Waypoint class has the following definition:public class Waypoint { public float latitude = 0f; public float longitude = 0f; public Waypoint() { } public void setPosition(float latitude, float longitude) { this.latitude = latitude; this.longitude = longitude; } }
WaypointsConverter module which will be notified from the waypoints service, will decode the array of waypoints, and send a flightplanObject service which will not contain an array of waypoints but a Waypoints Java object.flightplanObject service reception, and will only have to get the Waypoints object from the received data rather than having to make the decoding.
flightplanObject service is the following:<event name="flightplanObject"> <data name="waypoints" type="waypointsObject" /> </event>The types used by this service are:
<objectType name="waypointsObject" class="org.da.Waypoints" />
<application name="Aircraft"> <deployment> <lib url="FMS.jar" /> <lib url="Systems.jar" /> </deployment> <modules> <module name="FMS" > <implementation path="org.da.aircraft.FMS" > <initEntryPoint method="init" /> <startEntryPoint method="start" /> </implementation> <interfaces> <eventSend service="flightplan" /> </interfaces> </module> <module name="WaypointsConverter" > <implementation path="org.da.aircraft.WaypointsConverter" > <initEntryPoint method="init" /> <startEntryPoint method="start" /> <defaultReceiveEntryPoint method="receive" /> </implementation> <interfaces> <eventReceived service="flightplan" /> <eventSend service="flightplanObject" /> </interfaces> </module> <module name="userModule1" > <implementation path="org.da.aircraft.userModule1" > <initEntryPoint method="init" /> <startEntryPoint method="start" /> <defaultReceiveEntryPoint method="receive" /> </implementation> <interfaces> <eventReceived service="flightplanObject" /> </interfaces> </module> <module name="userModule2" > <implementation path="org.da.aircraft.userModule2" > <initEntryPoint method="init" /> <startEntryPoint method="start" /> <defaultReceiveEntryPoint method="receive" /> </implementation> <interfaces> <eventReceived service="flightplanObject" /> </interfaces> </module> </modules> </application>
Flightplan class with the following definition:public class Flightplan { public List<Waypoint> wpts = new ArrayList<>(); public Flightplan() { } public List<Waypoint> getWaypoints() { return wpts; } }In our case, we will decode the
flightplan service data in the WaypointsConverter module, and send the Waypoints class as an object. The code is exactly the same as the one shown before, except that we will invoke the flightplanObject service after the decoding:public void init(Module module) { flightplan = new Flightplan(); } public void receive(ServiceInstance service) { flightplan.getWaypoints().clear(); Data<ArrayType> fpData = (Data<ArrayType>) service.getData("flightplan"); ... List<Object> array = fpData.getValueAsArray(); Iterator<lt;Object> it = array.iterator(); while (it.hasNext()) { Object o = it.next(); float latitude = wptType.getFieldValueAsFloat("latitude", o, Units.DEG); float longitude = wptType.getFieldValueAsFloat("longitude", o, Units.DEG); Waypoint wpt = new Waypoint(); wpt.setPosition(latitude, longitude); flightplan.getWaypoints().add(wpt); } flightplanObject.getData("waypoints").setValue(flightplan); }
flightplanObject service data in the user modules is now much more simple:public void receive(ServiceInstance service) { Data fpData = service.getData("waypoints"); Flightplan fp = fpData.getValue(); }
Copyright 2017-2020 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v3 licence