public void init(Module module) { ServiceDefinition positionDef = module.getServiceDefinition("position"); Data.Structure posStruct = (Data.Structure) positionDef.createData("thePosition"); }Note that this data is not linked in any way to the framework services. It may only be used to set and retrieve values.
public void init(Module module) { Type.Structure positionType = module.getType("positionType"); Data.Structure posStruct = (Data.Structure) positionType.createData(); }
Data.Structure struct = structType.getValueAsData(<my object>); Data.Array array = arrayType.getValueAsData(<my object>);
posStruct.setFieldFloatValue("x", 0.2f); posStruct.setFieldFloatValue("y", 0.2f);We could set the value of a Data for the Service using this "internal" Data. For example:
position.setDataValue("thePosition", posStruct); position.invoke();
<types> <simpleType name="float" baseType="float" /> <structType name="positionType"> <field name="x" type="float" /> <field name="y" type="float" /> </structType> <arrayType name="positionArrayType" type="positionType" /> </types>And the associated service:
<publish name="position" > <data name="positionArray" type="positionArrayType" /> </publish>Our array would be an array of the
positionType
structure:public void init(Module module) { ArrayType positionArrayType = (ArrayType)module.getType("positionArrayType"); Data.Array posArray = (Data.Array) positionArrayType.createData(); }Now we want to set the value for one of the array index. For example:
StructType positionType = (StructType)module.getType("positionType"); Data.Structure posStruct = (Data.Structure) positionType.createData(); posStruct.setFieldFloatValue("x", 0.2f); posStruct.setFieldFloatValue("y", 0.2f); posArray.setValue(posStruct, 1); // we set the value of the array for the index 1 positionService.setDataValue("positionArray", posArray); positionService.invoke();
position.setDataValue("thePosition", posStruct); position.invoke();However, this allows to perform this affectation at any level of a Data structure.
<types> <simpleType name="float" baseType="float" /> <structType name="position"> <field name="x" type="float" /> <field name="y" type="float" /> </structType> </types>And the following services definition:
<services> <event name="position"> <data name="thePosition" type="pos" /> </event> </services>We can for example use the following code to publish cyclically the position:
public class MyModule { private ServiceInstance position = null; private ServiceDefinition positionDef = null; public void init(Module module) { positionDef = module.getServiceDefinition("position"); position = module.getService("position"); } public void published(ServiceInstance service) { Data.Structure posStruct = (Data.Structure) positionDef.createData("thePosition"); posStruct.setFieldFloatValue("x", 0.2f); posStruct.setFieldFloatValue("y", 0.2f); position.setDataValue("thePosition", posStruct); position.invoke(); } }
<types> <simpleType name="float" baseType="float" /> <simpleType name="string" baseType="string" /> <structType name="waypoint"> <field name="name" type="string" /> <field name="position" type="position" /> </structType> <structType name="position"> <field name="latitude" type="float" /> <field name="lontitude" type="float" /> </structType> </types>And the following services definition:
<services> <event name="createWaypoint"> <data name="waypoint" type="waypoint" /> </event> </services>We can for example use the following code to create one Waypoint:
public class MyModule { private ServiceInstance createWaypoint = null; private StructType positionType = null; public void init(Module module) { createWaypoint = module.getService("createWaypoint"); positionType = (StructType)module.getType("position"); } public void subscribe(ServiceInstance service) { Data.Structure posStruct = (Data.Structure) positionType.createData(); posStruct.setFieldFloatValue("latitude", 0.2f); posStruct.setFieldFloatValue("lontitude", 0.2f); Data.Structure waypoint = (Data.Structure)createWaypoint.getData("waypoint"); waypoint.setFieldValue("position", posStruct); position.invoke(); } }
Copyright 2017-2020 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v3 licence