FlatBuffer_Send.java
Go to the documentation of this file.
1 package grl.flatBufferTesting;
2 
3 import java.nio.ByteBuffer;
4 import java.util.Arrays;
5 
6 import org.zeromq.ZMQ;
7 
8 import com.google.flatbuffers.FlatBufferBuilder;
10 import grl.flatbuffer.Vector3d;
11 
12 public class FlatBuffer_Send {
13  static final String ADDRESS = "tcp://127.0.0.1:5563";
14  static final int NUM_MSG = 10;
15  public static void main(String[] args) throws Exception {
16 
17  // Prepare our context and publisher
18  ZMQ.Context context = ZMQ.context(1);
19  ZMQ.Socket publisher = context.socket(ZMQ.DEALER);
20  publisher.bind(ADDRESS);
21  publisher.setHWM(1000000);
22  publisher.setSndHWM(1000000);
23 
24  // Create a Flat Buffer
25  FlatBufferBuilder fbb = new FlatBufferBuilder(1);
27  VrepControlPoint.addPosition(fbb, Vector3d.createVector3d(fbb, 0.0, 1.0, 2.0));
28  VrepControlPoint.addRotation(fbb, Vector3d.createVector3d(fbb, 3.0, 4.0, 5.0));
32 
33  // Output Flat Buffer for Testing
34  byte [] sendByteArray = fbb.sizedByteArray();
35  System.out.println(sendByteArray);
36  ByteBuffer bb = ByteBuffer.wrap(sendByteArray);
38  // Vector3d position = controlpoint.position();
39  // EulerXYZd rotation = controlpoint.rotation();
40  double [] position = {controlpoint.position().x(), controlpoint.position().y(), controlpoint.position().z()};
41  double [] rotation = {controlpoint.rotation().rx(), controlpoint.rotation().ry(), controlpoint.rotation().rz()};
42  double vel_rel = controlpoint.relativeVelocity();
43  System.out.println(Arrays.toString(position));
44  System.out.println(Arrays.toString(rotation));
45  System.out.println(vel_rel);
46 
47  // Send Flat Buffer
48  int c = 0;
49  while (c < NUM_MSG) {
50  c++;
51  publisher.send(sendByteArray,0);
52  }
53  Thread.sleep(2000);
54  publisher.close();
55  context.term();
56  System.exit(1);
57  }
58 }
static void addPosition(FlatBufferBuilder builder, int positionOffset)
static void addRelativeVelocity(FlatBufferBuilder builder, double relativeVelocity)
static int createVector3d(FlatBufferBuilder builder, double x, double y, double z)
static void addRotation(FlatBufferBuilder builder, int rotationOffset)
static void finishVrepControlPointBuffer(FlatBufferBuilder builder, int offset)