]> rtime.felk.cvut.cz Git - orte.git/blob - orte/Robot_Demo/src/org/ocera/orte/demo/HelloMsg.java
26d067341d6840b88a3e4993f6202b2a35fe6503
[orte.git] / orte / Robot_Demo / src / org / ocera / orte / demo / HelloMsg.java
1 package org.ocera.orte.demo;
2
3 /* HelloMsg.java */
4
5 /* ********************************************************* *
6  *                                                           *
7  *                Will be Generated by IDL                   *
8  *                                                           *
9  * ********************************************************* */
10
11 import java.nio.ByteOrder;
12
13 import org.ocera.orte.*;
14 import org.ocera.orte.types.*;
15
16
17 public class HelloMsg extends MessageData
18 {
19    private int counter = 0;
20    public int count_read = 0; // pro testovaci ucely!!
21
22 /* ************************************** * 
23  *               data to send             *
24  * ************************************** */
25
26    public  short          left;
27    public  short          right;   
28    
29 /* ************************************** */
30
31    
32   /* constructor  */
33   public HelloMsg(DomainApp domainApp, String newTopic)
34   {
35     super();
36     buffer.order(ByteOrder.LITTLE_ENDIAN);
37  
38     // typeName registration
39         if(counter == 0)
40     {
41              boolean b;
42                  
43              counter++;
44          this.setTopic(newTopic); // set the topic of a publication 
45          // register new data typeName     
46          b = domainApp.regNewDataType("motion_speed",getMaxDataLength()); 
47              if (b == false) 
48              {
49                System.out.println(":j!: cannot register data type!");    
50              }
51
52            }
53         // init
54             left = 0;
55         right = 0;  
56         //System.out.println(":j: instance of HelloMsg created..");     
57   }
58       
59
60   /**
61    * Serializetaion method. Put all of data fields and write them into a buffer. 
62    * @return True - if write successful, False - write failed (IndexOutOfBoundsException or ReadOnlyBufferException).  
63    */
64   /* TODO osetrit vyjimky - mozna pak bude vracet typ boolean 
65    * IndexOutOfBoundsException - If index is negative or not smaller than the buffer's limit 
66    * ReadOnlyBufferException - If this buffer is read-only
67    */ 
68   public void write()
69   {
70         /* TODO - control setting fields !!*/
71         //
72         buffer.rewind(); // set offset to 0
73         buffer.putShort(this.left);
74         buffer.putShort(this.right);    
75   }
76  
77   /**
78    * Serializetaion method. Put all of data fields and write them into a buffer. 
79    * @return True - if write successful, False - write failed (IndexOutOfBoundsException or ReadOnlyBufferException).  
80    */
81   /* TODO 'BufferUnderflowException' - osetrit vyjimky - mozna pak bude vracet typ boolean 
82
83    */ 
84   public void read()
85   {
86         buffer.rewind(); // set offset to 0
87         this.left = buffer.getShort();                          
88         this.right = buffer.getShort();
89   }
90
91   /**
92    * Return maximum buffer's length according to its data fields.
93    * @return Length of buffer.
94    **/  
95   public int getMaxDataLength()
96   {
97         int len=0;
98         len += ORTEConstant.SHORT_FIELD_SIZE;
99         len += ORTEConstant.SHORT_FIELD_SIZE;
100     return len;
101   }
102
103   public String toString()
104   {
105     String data = new String();
106     
107     data += (" left = " + left); 
108     data += (" right = " + right);      
109         return data;      
110   }
111   
112 }