private void startEventLoopThread() throws RobotCoreException { try { this.reportRobotStatus(RobotState.INIT); this.eventLoop.init(this); Iterator var1 = this.syncdDevices.iterator(); while (var1.hasNext()) { SyncdDevice var2 = (SyncdDevice) var1.next(); var2.startBlockingWork(); } } catch (Exception var3) { RobotLog.w("Caught exception during looper init: " + var3.toString()); RobotLog.logStacktrace(var3); this.reportRobotStatus(RobotState.EMERGENCY_STOP); if (RobotLog.hasGlobalErrorMsg()) { this.buildAndSendTelemetry("SYSTEM_TELEMETRY", RobotLog.getGlobalErrorMsg()); } throw new RobotCoreException("Robot failed to start: " + var3.getMessage()); } this.elapsedSinceHeartbeatReceived = new ElapsedTime(0L); this.reportRobotStatus(RobotState.RUNNING); this.eventLoopThread = new Thread(new EventLoopRunnable((EventLoopManager.SyntheticClass_1) null), "Event Loop"); this.eventLoopThread.start(); }
public void run() { while (true) { RobocolDatagram datagram = EventLoopManager.this.socket.recv(); // what's the timeout? if (EventLoopManager.this.receivingProhibited || EventLoopManager.this.socket.isClosed()) { return; } if (datagram == null) { Thread.yield(); } else { if (RobotLog.hasGlobalErrorMsg()) { EventLoopManager.this.buildAndSendTelemetry( "SYSTEM_TELEMETRY", RobotLog.getGlobalErrorMsg()); } try { switch (EventLoopManager.SyntheticClass_1.a[datagram.getMsgType().ordinal()]) { case 1: EventLoopManager.this.onGamepadDatagram(datagram); break; case 2: EventLoopManager.this.onHeartbeatDatagramReceived(datagram); break; case 3: EventLoopManager.this.onConnectionDatagram(datagram); break; case 4: EventLoopManager.this.onCommandDatagram(datagram); break; case 5: EventLoopManager.this.onEmptyDatagram(); break; default: EventLoopManager.this.onUnknownDatagram(datagram); } } catch (RobotCoreException var3) { RobotLog.w("RobotCore event loop cannot process event: " + var3.toString()); } } } }
public void run() { RobotLog.v("EventLoopRunnable has started"); try { ElapsedTime elapsedEventLoop = new ElapsedTime(); double sMinLoopInterval = 0.001D; long msLoopIntervalStep = 5L; while (!Thread.interrupted()) { while (elapsedEventLoop.time() < sMinLoopInterval) { Thread.sleep(msLoopIntervalStep); } elapsedEventLoop.reset(); if (RobotLog.hasGlobalErrorMsg()) { EventLoopManager.this.buildAndSendTelemetry( "SYSTEM_TELEMETRY", RobotLog.getGlobalErrorMsg()); } if (EventLoopManager.this.elapsedSinceHeartbeatReceived.startTime() == 0.0D) { Thread.sleep(500L); } else if (EventLoopManager.this.elapsedSinceHeartbeatReceived.time() > 2.0D) { EventLoopManager.this.handleDroppedConnection(); EventLoopManager.this.currentPeerAddressAndPort = null; EventLoopManager.this.elapsedSinceHeartbeatReceived = new ElapsedTime(0L); } Iterator syncdDeviceIterator = EventLoopManager.this.syncdDevices.iterator(); SyncdDevice syncdDevice; while (syncdDeviceIterator.hasNext()) { syncdDevice = (SyncdDevice) syncdDeviceIterator.next(); syncdDevice.blockUntilReady(); } boolean unblockOnException = false; try { unblockOnException = true; EventLoopManager.this.eventLoop.loop(); unblockOnException = false; } catch (Exception e) { RobotLog.e("Event loop threw an exception"); RobotLog.logStacktrace(e); String exceptionMessage = e.getClass().getSimpleName() + (e.getMessage() != null ? " - " + e.getMessage() : ""); RobotLog.setGlobalErrorMsg( "User code threw an uncaught exception: " + exceptionMessage); EventLoopManager.this.buildAndSendTelemetry( "SYSTEM_TELEMETRY", RobotLog.getGlobalErrorMsg()); throw new RobotCoreException("EventLoop Exception in loop()"); } finally { if (unblockOnException) { Iterator var9 = EventLoopManager.this.syncdDevices.iterator(); while (var9.hasNext()) { SyncdDevice var10 = (SyncdDevice) var9.next(); var10.startBlockingWork(); } } } syncdDeviceIterator = EventLoopManager.this.syncdDevices.iterator(); while (syncdDeviceIterator.hasNext()) { syncdDevice = (SyncdDevice) syncdDeviceIterator.next(); syncdDevice.startBlockingWork(); } } } catch (InterruptedException var20) { RobotLog.v("EventLoopRunnable interrupted"); EventLoopManager.this.reportRobotStatus(RobotState.STOPPED); } catch (RobotCoreException var21) { RobotLog.v("RobotCoreException in EventLoopManager: " + var21.getMessage()); EventLoopManager.this.reportRobotStatus(RobotState.EMERGENCY_STOP); EventLoopManager.this.buildAndSendTelemetry( "SYSTEM_TELEMETRY", RobotLog.getGlobalErrorMsg()); } try { EventLoopManager.this.eventLoop.teardown(); } catch (Exception var17) { RobotLog.w("Caught exception during looper teardown: " + var17.toString()); RobotLog.logStacktrace(var17); if (RobotLog.hasGlobalErrorMsg()) { EventLoopManager.this.buildAndSendTelemetry( "SYSTEM_TELEMETRY", RobotLog.getGlobalErrorMsg()); } } RobotLog.v("EventLoopRunnable has exited"); }