public List<ControllerConfiguration> parse(InputStream is) throws RobotCoreException {
   this.parser = null;
   try {
     XmlPullParserFactory newInstance = XmlPullParserFactory.newInstance();
     newInstance.setNamespaceAware(true);
     this.parser = newInstance.newPullParser();
     this.parser.setInput(is, null);
     int next = this.parser.getEventType();
     while (next != XmlPullParser.END_DOCUMENT) {
       ConfigurationType type = getConfigurationType(this.parser.getName());
       if (next == XmlPullParser.START_TAG) {
         if (type == ConfigurationType.MOTOR_CONTROLLER) {
           this.controllerConfigurations.add(parseMotorController(true));
         }
         if (type == ConfigurationType.SERVO_CONTROLLER) {
           this.controllerConfigurations.add(parseServoController(true));
         }
         if (type == ConfigurationType.LEGACY_MODULE_CONTROLLER) {
           this.controllerConfigurations.add(parseLegacyModuleController());
         }
         if (type == ConfigurationType.DEVICE_INTERFACE_MODULE) {
           this.controllerConfigurations.add(parseDeviceInterfaceModule());
         }
       }
       next = this.parser.next();
     }
   } catch (XmlPullParserException e) {
     RobotLog.w("XmlPullParserException");
     e.printStackTrace();
   } catch (IOException e2) {
     RobotLog.w("IOException");
     e2.printStackTrace();
   }
   return this.controllerConfigurations;
 }
    public void run() {
      while (!Thread.interrupted()) {
        Iterator iterator = EventLoopManager.this.commandsToSend.iterator();

        while (iterator.hasNext()) {
          Command command = (Command) iterator.next();
          if (command.getAttempts() > 10) {
            RobotLog.w("Failed to send command, too many attempts: " + command.toString());
            this.completedCommands.add(command);
          } else if (command.isAcknowledged()) {
            RobotLog.v("Command " + command.getName() + " has been acknowledged by remote device");
            this.completedCommands.add(command);
          } else {
            try {
              RobotLog.v(
                  "Sending command: " + command.getName() + ", attempt " + command.getAttempts());
              EventLoopManager.this.socket.send(new RobocolDatagram(command.toByteArray()));
            } catch (RobotCoreException e) {
              RobotLog.w("Failed to send command " + command.getName());
              RobotLog.logStacktrace(e);
            }
          }
        }

        EventLoopManager.this.commandsToSend.removeAll(this.completedCommands);
        this.completedCommands.clear();

        try {
          Thread.sleep(100L);
        } catch (InterruptedException e) {
          return;
        }
      }
    }
  /**
   * Writes a warning message to the respective loggers.
   *
   * @param tag the log tag
   * @param mess the message to send
   * @see RobotLog#w(String)
   * @see RobotStatus#log(Level, String, String)
   * @see Level#WARNING
   */
  public static synchronized void w(String tag, String mess) {
    tag = checkNotNull(tag);
    mess = checkNotNull(mess);

    RobotLog.w(mess);
    getInstance().context.status().log(Level.WARNING, tag, mess);
  }
  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();
  }
  /**
   * observation: this is may be thread-safe; it could be called concurrently (with different
   * telemetry objects). The core remaining issue is concurrent use of socket.send(). You would have
   * thought that that would have been thread-safe, but I forgot it's a local thing here not a
   * system thing.
   */
  public void sendTelemetryData(Telemetry telemetry) {
    try {
      this.socket.send(new RobocolDatagram(telemetry.toByteArray()));
    } catch (RobotCoreException var3) {
      RobotLog.w("Failed to send telemetry data");
      RobotLog.logStacktrace(var3);
    }

    telemetry.clearData();
  }
    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());
          }
        }
      }
    }
示例#7
0
 public static void logAndThrow(String errMsg) throws RobotCoreException {
   w(errMsg);
   throw new RobotCoreException(errMsg);
 }
    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");
    }
 public void processCommand(Command command) {
   RobotLog.w("Dropping command " + command.getName() + ", no active event loop");
 }
 private void onUnknownDatagram(RobocolDatagram var1) {
   RobotLog.w("RobotCore event loop received unknown event type: " + var1.getMsgType().name());
 }