示例#1
0
  public static VehicleType showVehicleDialog(
      Vector<VehicleType> forbiddenVehicles,
      VehicleType initialSelection,
      Component parentComponent) {
    List<String> vehicles = new ArrayList<>();
    if (forbiddenVehicles == null) forbiddenVehicles = new Vector<>();

    for (Entry<String, VehicleType> entry : VehiclesHolder.getVehiclesList().entrySet()) {
      if (!forbiddenVehicles.contains(entry.getValue())) vehicles.add(entry.getKey());
    }

    if (vehicles.isEmpty()) return null;

    Collections.sort(vehicles);
    Object ret =
        JOptionPane.showInputDialog(
            parentComponent,
            I18n.text("Select vehicle"),
            I18n.text("Select vehicle"),
            JOptionPane.QUESTION_MESSAGE,
            null,
            vehicles.toArray(new String[0]),
            initialSelection != null ? initialSelection.getId() : vehicles.iterator().next());
    if (ret == null) return null;
    return VehiclesHolder.getVehicleById("" + ret);
  }
  @Override
  public void sendMessage(IridiumMessage msg) throws Exception {
    VehicleType vt = VehiclesHolder.getVehicleWithImc(new ImcId16(msg.getDestination()));
    if (vt == null) {
      throw new Exception("Cannot send message to an unknown destination");
    }
    IridiumArgs args = (IridiumArgs) vt.getProtocolsArgs().get("iridium");
    if (askRockBlockPassword || rockBlockPassword == null || rockBlockUsername == null) {
      Pair<String, String> credentials =
          GuiUtils.askCredentials(
              ConfigFetch.getSuperParentFrame(),
              "Enter RockBlock Credentials",
              getRockBlockUsername(),
              getRockBlockPassword());
      if (credentials == null) return;
      setRockBlockUsername(credentials.first());
      setRockBlockPassword(credentials.second());
      PluginUtils.saveProperties("conf/rockblock.props", this);
      askRockBlockPassword = false;
    }

    String result =
        sendToRockBlockHttp(
            args.getImei(), getRockBlockUsername(), getRockBlockPassword(), msg.serialize());

    if (result != null) {
      if (!result.split(",")[0].equals("OK")) {
        throw new Exception("RockBlock server failed to deliver the message: '" + result + "'");
      }
    }
  }
  @Override
  protected boolean initSystemComms() {
    VehicleType vehicleaux = VehiclesHolder.getVehicleWithImc(getSystemCommId());

    ImcSystem resSys = ImcSystemsHolder.lookupSystem(getSystemCommId());
    if (resSys == null) {
      if (vehicleaux != null) {
        resSys = new ImcSystem(vehicleaux);
        ImcSystemsHolder.registerSystem(resSys);
      }
    }

    if (resSys == null) {
      NeptusLog.pub()
          .error("Error creating private sending transports for " + getSystemCommId() + ".");
      return false;
    }

    // CommMean commMean = CommUtil.getActiveCommMeanForProtocol(
    // vehicleaux, "imc");

    CommMean commMean = resSys.commsInfo;
    if (commMean == null) {
      NeptusLog.pub()
          .error("Error creating private sending transports for " + getSystemCommId() + ".");
      return false;
    }

    this.ipAddress = commMean.getHostAddress();
    this.ipRemotePort = ((IMCArgs) (commMean.getProtocolsArgs().get(CommMean.IMC))).getPort();

    return true;
  }