]> rtime.felk.cvut.cz Git - orte.git/blob - orte/java/src/org/ocera/orte/examples/robot/RoboPublisher.java
ROBOT_DEMO: add robot demo for Android
[orte.git] / orte / java / src / org / ocera / orte / examples / robot / RoboPublisher.java
1 /* Publisher.java */
2
3 /**
4  * Class Publisher provides methods for creating and working
5  * with the ORTE publisher.
6  *
7  * @author Lukas Pokorny (lukas_pokorny@centrum.cz)
8  * @author CTU FEE Prague - Department of Control Engineering (dce.felk.cvut.cz)
9  * @author Project ORTE - OCERA Real Time Ethernet (www.ocera.org)
10  * @author dedication to Kj
11  * @version 0.1
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  */
24
25 import org.ocera.orte.*;
26 import org.ocera.orte.types.*;
27
28
29 public class RoboPublisher {
30
31    // load native library 'libjorte.so'
32    static 
33    {
34          System.loadLibrary("jorte");      
35    }
36
37   public static void main(String[] args)
38   {
39     int alive = 0;
40
41     System.out.println(":j: * ********************************************* *"); 
42     System.out.println(":j: *         JORTE Publisher is starting..         *");
43     System.out.println(":j: * ********************************************* *");
44         
45         // set publisher's parameters
46     NtpTime persistence = new NtpTime(3);
47     int strength = 1;
48     // 
49     RoboEvents events = new RoboEvents();
50     
51     /**
52      *  Create a new Application Domain for a Publisher.
53      * (Constructor without arguments creates the default Application Domain.)
54      */ 
55      // creates default app domain
56      //DomainApp appDomain = new DomainApp();
57      // creates user defined app domain
58           
59     DomainApp appDomain = new DomainApp(ORTEConstant.ORTE_DEFAULT_DOMAIN,
60                                         DomainProp.defaultPropsCreate(),
61                                         events,
62                                         false); 
63     if (appDomain == null)
64         {
65       System.out.println(":!j: cannot create default domain!");
66       return;
67         }
68     
69     // create a HelloMessage instance 
70         RoboMsg hellomsg = new RoboMsg(appDomain,"motion_speed");
71     
72     // set basic subscription properties
73     PublProp publProp = new PublProp(hellomsg.getTopic(),
74                                          "motion_speed",                                
75                                      persistence,
76                                                                          strength);
77     
78     System.out.println(":j: set publication properties..");             
79
80     /* set verbosity mode - just uncomment the line bellow */
81     // JOrte.verbositySetOptions("ALL:10");
82
83         // create a publication    
84     Publication pub = appDomain.createPublication(publProp,
85                                                       hellomsg);                
86     if (pub == null)
87     {
88       System.out.println(":j!: publisher not created!");
89       return;
90     }
91     System.out.println(":j: publisher created!");
92     System.out.println(":j: * ********************************************* *");        
93     System.out.println(":j: start sending data:");
94     System.out.println(":j: * ********************************************* *");
95     
96     while(alive < 20)
97         {
98           pub.send(hellomsg); 
99           System.out.println("<<  data to send: " + hellomsg);
100           JOrte.sleepMs(100);
101           System.out.println(" ");
102           alive++;
103         }
104
105     pub = null;
106     System.gc();
107   } 
108
109 }