6 * @author Lukas Pokorny (lukas_pokorny@centrum.cz)
7 * @author CTU FEE Prague - Department of Control Engineering (dce.felk.cvut.cz)
8 * @author Project ORTE - OCERA Real Time Ethernet (www.ocera.org)
9 * @author dedication to Kj
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
24 package org.ocera.orte.types;
26 import java.nio.ByteBuffer;
27 import java.nio.ByteOrder;
32 private ByteBuffer info_buffer;
34 /* Helper buffer structure (all 32-bit integers):
35 * [0] sizeof(ORTERecvInfo),
36 * [1] sizeof(ORTERecvStatus),
38 * [3] offsetof(ORTERecvInfo,status),
39 * [4] offsetof(ORTERecvInfo,topic),
40 * [5] offsetof(ORTERecvInfo,type),
41 * [6] offsetof(ORTERecvInfo,senderGUID),
42 * [7] offsetof(ORTERecvInfo,localTimeReceived),
43 * [8] offsetof(ORTERecvInfo,remoteTimePublished),
44 * [9] offsetof(ORTERecvInfo,sn),
45 * [10] offsetof(GUID_RTPS,hid),
46 * [11] offsetof(GUID_RTPS,aid),
47 * [12] offsetof(GUID_RTPS,oid),
48 * [13] offsetof(NtpTime,seconds),
49 * [14] offsetof(NtpTime,fraction),
50 * [15] offsetof(SequenceNumber,high),
51 * [16] offsetof(SequenceNumber,low)
53 static ByteBuffer helper_buffer;
56 helper_buffer = ByteBuffer.allocateDirect(17*Integer.SIZE/8);
57 helper_buffer.order(ByteOrder.nativeOrder());
58 c_helper(helper_buffer);
63 //System.out.println(":j: instance of RecvInfo created..");
64 this.info_buffer = ByteBuffer.allocateDirect(helper_buffer.getInt(0));
65 this.info_buffer.order(ByteOrder.nativeOrder());
69 public byte getRecvStatus()
73 switch(helper_buffer.getInt(Integer.SIZE/8)) {
75 ret_val = (byte) info_buffer.getInt(helper_buffer.getInt(Integer.SIZE*3/8));
78 ret_val = info_buffer.get(helper_buffer.getInt(Integer.SIZE*3/8));
81 ret_val = (byte) info_buffer.getShort(helper_buffer.getInt(Integer.SIZE*3/8));
84 ret_val = (byte) info_buffer.getLong(helper_buffer.getInt(Integer.SIZE*3/8));
87 System.out.println("j: ORTERecvStatus of unknown size!");
94 public String getTopic()
96 return getString(Integer.SIZE*4/8);
99 public String getTypeName()
101 return getString(Integer.SIZE*5/8);
104 public GUID_RTPS getSenderGuid()
106 long hostId = info_buffer.getInt(helper_buffer.getInt(Integer.SIZE*6/8)+helper_buffer.getInt(Integer.SIZE*10/8)) & 0xffffffffL;
107 long appId = info_buffer.getInt(helper_buffer.getInt(Integer.SIZE*6/8)+helper_buffer.getInt(Integer.SIZE*11/8)) & 0xffffffffL;
108 long objectId = info_buffer.getInt(helper_buffer.getInt(Integer.SIZE*6/8)+helper_buffer.getInt(Integer.SIZE*12/8)) & 0xffffffffL;
111 return new GUID_RTPS(hostId, appId, objectId);
114 public NtpTime getLocalTimeRecv()
116 int seconds = info_buffer.getInt(helper_buffer.getInt(Integer.SIZE*7/8)+helper_buffer.getInt(Integer.SIZE*13/8));
117 long fraction = info_buffer.getInt(helper_buffer.getInt(Integer.SIZE*7/8)+helper_buffer.getInt(Integer.SIZE*14/8)) & 0xffffffffL;
119 return new NtpTime(seconds, fraction);
122 public NtpTime getRemoteTimePub()
124 int seconds = info_buffer.getInt(helper_buffer.getInt(Integer.SIZE*8/8)+helper_buffer.getInt(Integer.SIZE*13/8));
125 long fraction = info_buffer.getInt(helper_buffer.getInt(Integer.SIZE*8/8)+helper_buffer.getInt(Integer.SIZE*14/8)) & 0xffffffffL;
127 return new NtpTime(seconds, fraction);
130 public SequenceNumber getSeqNumber()
132 int high = info_buffer.getInt(helper_buffer.getInt(Integer.SIZE*9/8)+helper_buffer.getInt(Integer.SIZE*15/8));
133 long low = info_buffer.getInt(helper_buffer.getInt(Integer.SIZE*9/8)+helper_buffer.getInt(Integer.SIZE*16/8));
135 return new SequenceNumber(high, low);
138 /** only for test purposes */
141 System.out.println(":j: RecvInfo:");
142 System.out.println(":j: recvStatus: " + this.getRecvStatus());
143 System.out.println(":j: topic: " + this.getTopic());
144 System.out.println(":j: type: " + this.getTypeName());
145 System.out.println(":j: senderGuid: " + this.getSenderGuid());
146 System.out.println(":j: localTimerecv: " + this.getLocalTimeRecv());
147 System.out.println(":j: remoteTimePub: " + this.getRemoteTimePub());
148 System.out.println(":j: seqNr: " + this.getSeqNumber().getDecimal());
151 public ByteBuffer getBuffer()
153 return this.info_buffer;
156 private String getString(int offset) {
159 switch(helper_buffer.getInt(Integer.SIZE*2/8)) {
161 string_pointer = info_buffer.getInt(helper_buffer.getInt(offset));
164 string_pointer = info_buffer.getLong(helper_buffer.getInt(offset));
167 string_pointer = info_buffer.get(helper_buffer.getInt(offset));
170 string_pointer = info_buffer.getShort(helper_buffer.getInt(offset));
174 return get_string(string_pointer);
177 /* NATIVE FUNCTIONS */
179 static native String get_string(long string_pointer);
180 static native void c_helper(ByteBuffer buffer);