3 import java.nio.ByteBuffer;
7 import com.kuka.task.ITaskLogger;
17 ZMQ.Context context = null;
18 ZMQ.Socket subscriber = null;
20 String _ZMQ_MASTER_URI;
23 long message_counter = 0;
24 long noMessageCounter = 0;
25 long noMessageCounterLimit = 9999999;
35 long lastMessageStartTime;
36 long lastMessageElapsedTime;
37 long lastMessageTimeoutMilliseconds = 1000;
39 int retriesAllowed = 3;
40 int retriesAttempted = 0;
42 public ZMQManager(String ZMQ_MASTER_URI, ITaskLogger errorlogger) {
44 this.logger = errorlogger;
45 _ZMQ_MASTER_URI = ZMQ_MASTER_URI;
55 logger.info(
"Waiting for ZMQ connection initialization...");
56 this.context = ZMQ.context(1);
57 subscriber = context.socket(ZMQ.DEALER);
58 subscriber.connect(_ZMQ_MASTER_URI);
59 subscriber.setRcvHWM(100000);
60 startTime = System.currentTimeMillis();
63 int newStatesLength = 0;
65 while(newStatesLength<1 && newKUKAiiwaStates == null){
66 if((data = subscriber.recv(ZMQ.DONTWAIT))!=null){
67 bb = ByteBuffer.wrap(data);
74 logger.info(
"Stopping program.");
79 _currentKUKAiiwaStates = newKUKAiiwaStates;
80 statesLength = newStatesLength;
82 logger.info(
"States initialized...");
84 startTime = System.currentTimeMillis();
85 lastMessageStartTime = startTime;
86 lastMessageElapsedTime = System.currentTimeMillis() - lastMessageStartTime;
98 logger.info(
"Disconnecting...");
107 boolean haveNextMessage =
false;
108 while(!stop && !haveNextMessage) {
135 if((data = subscriber.recv(ZMQ.DONTWAIT))!=null){
139 bb = ByteBuffer.wrap(data);
143 if(_currentKUKAiiwaStates.statesLength()>0) {
146 if (tmp == null || tmp.armControlState() == null) {
147 noMessageCounter +=1;
148 if (message_counter % 100 == 0) {
149 logger.warn(
"NULL ArmControlState message, main ZMQ message is arriving but doesn't contain any data/commands!");
153 _previousKUKAiiwaState = _currentKUKAiiwaState;
154 _currentKUKAiiwaState = tmp;
157 if (_currentKUKAiiwaState == null) {
159 logger.error(
"Missing current state message!");
163 haveNextMessage=
true;
164 noMessageCounter = 0;
165 lastMessageStartTime = System.currentTimeMillis();
167 logger.error(
"got a ZMQ message but it isn't a valid message, this is an unexpected state that shouldn't occur. please debug me.");
173 return _currentKUKAiiwaState;
177 return _currentKUKAiiwaState;
181 return _previousKUKAiiwaState;
grl.flatbuffer.KUKAiiwaState waitForNextMessage()
void setStop(boolean stop)
grl.flatbuffer.KUKAiiwaState getCurrentMessage()
static KUKAiiwaStates getRootAsKUKAiiwaStates(ByteBuffer _bb)
ZMQManager(String ZMQ_MASTER_URI, ITaskLogger errorlogger)
grl.flatbuffer.KUKAiiwaState getPrevMessage()
ZMQManager Handles the ZeroMQ/JeroMQ loading in flatbuffer data.