certi-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[certi-cvs] jcerti build.xml src_test/certi/UavReceive.java...


From: certi-cvs
Subject: [certi-cvs] jcerti build.xml src_test/certi/UavReceive.java...
Date: Mon, 22 Mar 2010 11:58:50 +0000

CVSROOT:        /sources/certi
Module name:    jcerti
Changes by:     Eric NOULARD <erk>      10/03/22 11:58:50

Modified files:
        .              : build.xml 
Added files:
        src_test/certi : UavReceive.java UavSend.java 

Log message:
        Add UAV Send/Receive tests applications

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/jcerti/build.xml?cvsroot=certi&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/jcerti/src_test/certi/UavReceive.java?cvsroot=certi&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/jcerti/src_test/certi/UavSend.java?cvsroot=certi&rev=1.1

Patches:
Index: build.xml
===================================================================
RCS file: /sources/certi/jcerti/build.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- build.xml   22 Mar 2010 11:47:53 -0000      1.1
+++ build.xml   22 Mar 2010 11:58:50 -0000      1.2
@@ -52,7 +52,7 @@
                                <include name="certi/communication/**/*" />
                                <include name="certi/logging/**/*" />
                                <include name="certi/rti/**/*" />               
                                                
-                               <include name="rti/hla/**/*" />                 
+                               <include name="hla/rti/**/*" />                 
                        </fileset>
                </jar>          
                <echo file="${jar.dir}/README">
@@ -117,18 +117,20 @@
        <property name="test.work.dir" value="${test.report.dir}/work" />
        <property name="test.html.dir" value="${test.report.dir}/html" />
 
-    <!--
        <target name="test" depends="create-jar, test-clean" description="o run 
JUnit tests">
                <mkdir dir="${test.class.dir}" />
-               <javac srcdir="${test.src.dir}" destdir="${test.class.dir}" 
target="1.4" source="1.4" deprecation="on">
-                       <classpath refid="jcerti-tools.classpath" />
+               <javac srcdir="${test.src.dir}" destdir="${test.class.dir}" 
target="1.5" source="1.5" deprecation="on">                 
                        <include name="**/*.java" />
+                       <classpath>
+                               <path refid="jcerti.classpath" />
+                       </classpath>
                </javac>
                <copy todir="${test.class.dir}">
                        <fileset dir="${test.src.dir}" includes="**/*.xml"/>
                </copy>
                <mkdir dir="${test.report.dir}" />
                <mkdir dir="${test.work.dir}" />
+               <!--
                <junit printsummary="withOutAndErr" fork="yes">
                        <jvmarg 
value="-Djavax.xml.parsers.SAXParserFactory=org.apache.crimson.jaxp.SAXParserFactoryImpl"/>
                        <formatter type="xml" />
@@ -140,8 +142,10 @@
                                <fileset dir="${test.class.dir}" 
includes="**/*Test.class" />
                        </batchtest>
                </junit>
+               -->
        </target>
 
+       <!--
        <target name="test-report" depends="test">
                <delete dir="${test.html.dir}" />
                <junitreport todir="${test.work.dir}">
@@ -152,12 +156,12 @@
                </junitreport>
                <echo>Test report generated at : ${test.html.dir}/index.html 
</echo>
        </target>
+    -->
 
        <target name="test-clean">
                <delete dir="${test.class.dir}" />
                <delete dir="${test.report.dir}" />
        </target>
-       -->
 
        <!-- help -->
 

Index: src_test/certi/UavReceive.java
===================================================================
RCS file: src_test/certi/UavReceive.java
diff -N src_test/certi/UavReceive.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src_test/certi/UavReceive.java      22 Mar 2010 11:58:50 -0000      1.1
@@ -0,0 +1,141 @@
+// ----------------------------------------------------------------------------
+// CERTI - HLA Run Time Infrastructure
+// Copyright (C) 2009-2010 Andrej Pancik
+//
+// This program is free software ; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation ; either version 2 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY ; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this program ; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// ----------------------------------------------------------------------------
+package certi;
+
+import certi.rti.impl.CertiRtiAmbassador;
+import hla.rti.*;
+import hla.rti.jlc.*;
+import java.io.File;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class UavReceive {
+
+    private final static Logger LOGGER = 
Logger.getLogger(UavReceive.class.getName());
+    private int textAttributeHandle;
+    private int fomAttributeHandle;
+    private AttributeHandleSet attributes;
+
+    public void runFederate() throws Exception {
+        /////////////////
+        // UAV-RECEIVE //
+        /////////////////
+        LOGGER.info("        UAV-RECEIVE");
+        LOGGER.info("     1. Get a link to the RTI");
+        RtiFactory factory = RtiFactoryFactory.getRtiFactory();
+        RTIambassador rtia = factory.createRtiAmbassador();
+
+        LOGGER.info("     2. Create federation - nofail");
+        try {
+            File fom = new File("uav.fed");
+            rtia.createFederationExecution("uav", fom.toURI().toURL());
+        } catch (FederationExecutionAlreadyExists ex) {
+            LOGGER.warning("Federation already exists.");
+        }
+
+        LOGGER.info("     3. Join federation");
+        FederateAmbassador mya = new MyFederateAmbassador();
+        rtia.joinFederationExecution("uav-receive", "uav", mya);
+
+        LOGGER.info("     4. Initialize Federate Ambassador");
+        ((MyFederateAmbassador) mya).initialize(rtia);
+
+        LOGGER.info("     5 Initiate main loop");
+        int i = 20;
+        while (i-- > 0) {
+            ((CertiRtiAmbassador) rtia).tick(1.0, 1.0);
+        }
+
+        LOGGER.info("     7 Resign federation execution");
+        
rtia.resignFederationExecution(ResignAction.DELETE_OBJECTS_AND_RELEASE_ATTRIBUTES);
+
+        LOGGER.info("     8 Destroy federation execution - nofail");
+        try {
+            rtia.destroyFederationExecution("uav");
+        } catch (FederatesCurrentlyJoined ex) {
+            LOGGER.warning("Federates currently joined - can't destroy the 
execution.");
+        } catch (FederationExecutionDoesNotExist ex) {
+            LOGGER.warning("Federation execution does not exists - can't 
destroy the execution.");
+        }
+    }
+
+    public static void main(String[] args) throws Exception {
+        new UavReceive().runFederate();
+    }
+
+    private class MyFederateAmbassador extends NullFederateAmbassador {
+
+        private RTIambassador rtia;
+
+        public void initialize(RTIambassador rtia) throws NameNotFound, 
ObjectClassNotDefined, FederateNotExecutionMember, RTIinternalError, 
AttributeNotDefined, SaveInProgress, RestoreInProgress, 
ConcurrentAccessAttempted {
+            this.rtia = rtia;
+            int classHandle = rtia.getObjectClassHandle("SampleClass");
+
+            textAttributeHandle = rtia.getAttributeHandle("TextAttribute", 
classHandle);
+            fomAttributeHandle = rtia.getAttributeHandle("FOMAttribute", 
classHandle);
+
+            attributes = 
RtiFactoryFactory.getRtiFactory().createAttributeHandleSet();
+            attributes.add(textAttributeHandle);
+            attributes.add(fomAttributeHandle);
+
+            rtia.subscribeObjectClassAttributes(classHandle, attributes);
+        }
+
+        @Override
+        public void discoverObjectInstance(int theObject, int theObjectClass, 
String objectName) throws CouldNotDiscover, ObjectClassNotKnown, 
FederateInternalError {
+            try {
+                System.out.println("Discover: " + objectName);
+                rtia.requestObjectAttributeValueUpdate(theObject, attributes);
+            } catch (ObjectNotKnown ex) {
+                LOGGER.log(Level.SEVERE, "Exception:", ex);
+            } catch (AttributeNotDefined ex) {
+                LOGGER.log(Level.SEVERE, "Exception:", ex);
+            } catch (FederateNotExecutionMember ex) {
+                LOGGER.log(Level.SEVERE, "Exception:", ex);
+            } catch (SaveInProgress ex) {
+                LOGGER.log(Level.SEVERE, "Exception:", ex);
+            } catch (RestoreInProgress ex) {
+                LOGGER.log(Level.SEVERE, "Exception:", ex);
+            } catch (RTIinternalError ex) {
+                LOGGER.log(Level.SEVERE, "Exception:", ex);
+            } catch (ConcurrentAccessAttempted ex) {
+                LOGGER.log(Level.SEVERE, "Exception:", ex);
+            }
+        }
+
+        @Override
+        public void reflectAttributeValues(int theObject, ReflectedAttributes 
theAttributes, byte[] userSuppliedTag) throws ObjectNotKnown, 
AttributeNotKnown, FederateOwnsAttributes, FederateInternalError {
+            try {
+                for (int i = 0; i < theAttributes.size(); i++) {
+                    if (theAttributes.getAttributeHandle(i) == 
textAttributeHandle) {
+                        System.out.println("Reflect: " + 
EncodingHelpers.decodeString(theAttributes.getValue(i)));
+                    }
+                    if (theAttributes.getAttributeHandle(i) == 
fomAttributeHandle) {
+                        System.out.println("Reflect: " + 
EncodingHelpers.decodeFloat(theAttributes.getValue(i)));
+                    }
+                }
+
+
+            } catch (ArrayIndexOutOfBounds ex) {
+                LOGGER.log(Level.SEVERE, "Exception:", ex);
+            }
+        }
+    }
+}

Index: src_test/certi/UavSend.java
===================================================================
RCS file: src_test/certi/UavSend.java
diff -N src_test/certi/UavSend.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src_test/certi/UavSend.java 22 Mar 2010 11:58:50 -0000      1.1
@@ -0,0 +1,123 @@
+package certi;
+
+import certi.rti.impl.CertiRtiAmbassador;
+import hla.rti.*;
+import hla.rti.jlc.*;
+import java.io.File;
+import java.util.logging.Logger;
+
+public class UavSend {
+
+    private final static Logger LOGGER = 
Logger.getLogger(UavSend.class.getName());
+    private int myObject;
+    private int textAttributeHandle;
+    private int fomAttributeHandle;
+
+    public void runFederate() throws Exception {
+        //////////////
+        // UAV-SEND //
+        //////////////
+        LOGGER.info("        UAV-SEND");
+        LOGGER.info("     1. Get a link to the RTI");
+        RtiFactory factory = RtiFactoryFactory.getRtiFactory();
+        RTIambassador rtia = factory.createRtiAmbassador();
+
+        LOGGER.info("     2. Create federation - nofail");
+        try {
+            File fom = new File("uav.fed");
+            rtia.createFederationExecution("uav", fom.toURI().toURL());
+        } catch (FederationExecutionAlreadyExists ex) {
+            LOGGER.warning("Can't create federation. It already exists.");
+        }
+
+        LOGGER.info("     3. Join federation");
+        FederateAmbassador mya = new MyFederateAmbassador();
+        rtia.joinFederationExecution("uav-send", "uav", mya);
+
+        LOGGER.info("     4. Initialize Federate Ambassador");
+        ((MyFederateAmbassador) mya).initialize(rtia);
+
+
+        LOGGER.info("     5 Initiate main loop");
+        int i = 20;
+
+        while (i-- > 0) {
+            LOGGER.info("     6 Loop");
+            SuppliedAttributes attributes = 
RtiFactoryFactory.getRtiFactory().createSuppliedAttributes();
+
+            byte[] textAttribute = EncodingHelpers.encodeString("text " + i);
+            byte[] fomAttribute = EncodingHelpers.encodeFloat((float) Math.PI);
+
+            attributes.add(textAttributeHandle, textAttribute);
+            attributes.add(fomAttributeHandle, fomAttribute);
+
+            byte[] tag = EncodingHelpers.encodeString("update");
+
+            LOGGER.info("     6.1 Update Attributes");
+            rtia.updateAttributeValues(myObject, attributes, tag);
+
+            LOGGER.info("     6.2 Tick");
+            ((CertiRtiAmbassador) rtia).tick(1.0, 1.0);
+
+            Thread.sleep(1000);
+        }
+
+        LOGGER.info("     7 Resign federation execution");
+        
rtia.resignFederationExecution(ResignAction.DELETE_OBJECTS_AND_RELEASE_ATTRIBUTES);
+
+        LOGGER.info("     8 Destroy federation execution - nofail");
+        try {
+            rtia.destroyFederationExecution("uav");
+        } catch (FederatesCurrentlyJoined ex) {
+            LOGGER.warning("Federates currently joined - can't destroy the 
execution.");
+        } catch (FederationExecutionDoesNotExist ex) {
+            LOGGER.warning("Federation execution does not exists - can't 
destroy the execution.");
+        }
+    }
+
+    public static void main(String[] args) throws Exception {
+        new UavSend().runFederate();
+    }
+
+    private class MyFederateAmbassador extends NullFederateAmbassador {
+
+        public void initialize(RTIambassador rtia) throws NameNotFound, 
FederateNotExecutionMember, RTIinternalError, ObjectClassNotDefined, 
AttributeNotDefined, OwnershipAcquisitionPending, SaveInProgress, 
RestoreInProgress, ConcurrentAccessAttempted, ObjectClassNotPublished, 
ObjectAlreadyRegistered {
+            LOGGER.info("     4.1 Get object class handle");
+            int classHandle = rtia.getObjectClassHandle("SampleClass");
+
+            LOGGER.info("     4.2 Get atribute handles");
+            textAttributeHandle = rtia.getAttributeHandle("TextAttribute", 
classHandle);
+            fomAttributeHandle = rtia.getAttributeHandle("FOMAttribute", 
classHandle);
+
+            AttributeHandleSet attributes = 
RtiFactoryFactory.getRtiFactory().createAttributeHandleSet();
+            attributes.add(textAttributeHandle);
+            attributes.add(fomAttributeHandle);
+
+            LOGGER.info("     4.3 Publish object");
+            rtia.publishObjectClass(classHandle, attributes);
+
+            LOGGER.info("     4.4 Register object instance");
+            myObject = rtia.registerObjectInstance(classHandle, "HAF");
+        }
+
+        @Override
+        public void startRegistrationForObjectClass(int theClass) throws 
ObjectClassNotPublished, FederateInternalError {
+            super.startRegistrationForObjectClass(theClass);
+
+            System.out.println("Object class: " + theClass);
+        }
+
+        @Override
+        public void provideAttributeValueUpdate(int theObject, 
AttributeHandleSet theAttributes) throws ObjectNotKnown, AttributeNotKnown, 
AttributeNotOwned, FederateInternalError {
+            super.provideAttributeValueUpdate(theObject, theAttributes);
+
+            System.out.println("Object handle: " + theObject);
+            System.out.print("Attributes:");
+            HandleIterator iterator = theAttributes.handles();
+            for (int i = 1; i < theAttributes.size(); i++) {
+                System.out.print(iterator.next());
+            }
+            System.out.println();
+        }
+    }
+}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]