Ejemplo n.º 1
0
  @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;
  }